/************************************************************************* * *N strcompare * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function compares two strings with the given logical operator. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * val1 <input>==(char *) first buffer to compare. * val2 <input>==(char *) second buffer to compare. * op <input>==(char) logical operator. * return <output>==(int) TRUE or FALSE. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F * None *E *************************************************************************/ static int strcompare( char *val1, char *val2, char op ) { int result; char str1[300], str2[300]; strcpy(str1,val1); rightjust(str1); strcpy(str2,val2); rightjust(val2); result = rspf_strcasecmp(str1,str2); switch (op) { case EQ: result = !result; break; case NE: break; case LT: if (result < 0) result = TRUE; else result = FALSE; break; case LE: if (result <= 0) result = TRUE; else result = FALSE; break; case GT: if (result > 0) result = TRUE; else result = FALSE; break; case GE: if (result >= 0) result = TRUE; else result = FALSE; break; default: printf("Invalid logical operator (%d)\n",op); result = FALSE; break; } return result; }
/************************************************************************** * *N display_library_contents * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * List the tables in the Library level directory and display their * contents if selected. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * library <input> == (library_type) VPF library structure. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ void display_library_contents( library_type library ) { char *filename, *libpath, *path, *libstr; libstr = (char *)vpfmalloc(128); libpath = (char *)vpfmalloc(255); filename = (char *)vpfmalloc(128); path = (char *)vpfmalloc(255); strcpy( libstr, "Library: " ); strcat( libstr, library.name ); strcpy(libpath,library.path); strcat(libpath,"*.*"); do { strcpy(filename,pickfile(libpath,0,libstr)); if (strcmp(filename,"")==0) break; strcpy( path, library.path ); strcat( path, filename ); rightjust(path); leftjust(path); strlwr(path); if (is_vpf_table(path)) { strlwr(path); if (strstr(path,".doc")) vpf_dump_doc_table(path,"temp.out"); else vpf_dump_table(path,"temp.out"); viewfile("temp.out", getmaxy()/3); unlink("temp.out"); } else { not_a_vpf_table(path); } } while (strcmp(filename,"") != 0); free(path); free(filename); free(libpath); free(libstr); }
/************************************************************************** * *N display_database_contents * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * List the tables in the Database level directory and display their * contents if selected. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * database <input> == (database_type) VPF database. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ void display_database_contents( database_type database ) { char *filename, *dbpath, *path, *dbstr; dbstr = (char *)vpfmalloc(128); dbpath = (char *)vpfmalloc(255); filename = (char *)vpfmalloc(128); path = (char *)vpfmalloc(255); strcpy( dbstr, "Database: " ); strcat( dbstr, database.name ); strcpy(dbpath,database.path); strcat(dbpath,"*.*"); do { strcpy(filename,pickfile(dbpath,0,dbstr)); if (strcmp(filename,"")==0) break; strcpy( path, database.path ); strcat( path, filename ); rightjust(path); strlwr(path); if (is_vpf_table(path)) { if (strstr(path,".doc")) vpf_dump_doc_table(path,"temp.out"); else vpf_dump_table(path,"temp.out"); viewfile("temp.out", getmaxy()/3); unlink("temp.out"); } else { not_a_vpf_table(path); } } while (strcmp(filename,"") != 0); free(path); free(filename); free(dbpath); free(dbstr); }
/************************************************************************* * *N get_token * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function gets the first token, token type, and token value of * the expression string, and then advances the expression string * past the token. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * expression <input>==(char *) selection expression string. * token <output>==(char *) first token in the string. * token_type <output>==(int *) token type. * token_value <output>==(int *) token_value. * return <output>==(char *) new selection expression. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F * static void return_token( char *expr, char *token ) VPFQUERY.C *E *************************************************************************/ static char *get_token( char *expression, char *token, int *token_type, int *token_value ) { register int i, stopflag; *token_type = 0; if (*expression == '\0') { *token_type = FINISHED; *token_value = 0; return expression; } if (*expression=='\r') { /* crlf */ ++expression; ++expression; *token = '\r'; token[1] = '\n'; token[2] = 0; *token_type = DELIMETER; } stopflag = 0; while ((expression[0] == '\"') || (expression[0] == ' ')) { for (i=0;i<ndelim;i++) if (rspf_strncasecmp(expression,delimstr[i],(unsigned int)strlen(delimstr[i]))==0) { stopflag=1; break; } if (stopflag) break; expression++; } return_token( expression, token ); expression += strlen(token); if (*token == '\0') { *token_type = FINISHED; *expression = '\0'; return expression; } leftjust(token); rightjust(token); if (rspf_strcasecmp(token,"AND")==0) { strupr(token); *token_type = JOIN; *token_value = AND; while ((expression[0] == '\"') || (expression[0] == ' ')) expression++; return expression; } if (rspf_strcasecmp(token,"OR")==0) { strupr(token); *token_type = JOIN; *token_value = OR; while ((expression[0] == '\"') || (expression[0] == ' ')) expression++; return expression; } if (token[0] == '"') { /* quoted string */ if (*expression) expression++; i = 0; while (*expression != '"') { token[i] = *expression; i++; expression++; if (*expression == '\0') { *token_type = ERROR; *token_value = ERROR; return expression; } } while ((expression[0] == '\"') || (expression[0] == ' ')) expression++; token[i] = '\0'; *token_type = STRING; *token_value = (int)strlen(token); return expression; } for (i=0;i<ndelim;i++) { if (rspf_strcasecmp(token,delimstr[i])==0) { *token_type = LOP; *token_value = i; return expression; } } for (i=0;i<nfields;i++) { if (rspf_strcasecmp(token,fieldname[i])==0) { strupr(token); *token_type = FIELD; *token_value = i; return expression; } } *token_type = VALUE; *token_value = 0; return expression; }
/************************************************************************* * *N vpf_open_table * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function opens a vpf table and either loads it into RAM or sets * up the structure to read off of disk. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * tablename <input> == (const char *) file name of the table. * storage <input> == (storage_type) table storage mode - * either ram or disk. * mode <input> == (const char *) file mode for opening the table - * same as fopen() mode in C. * defstr <input> == (char *) table definition string used for * creating a writable table. * vpf_open_table <output> == (vpf_table_type) VPF table structure. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels April 1991 DOS Turbo C * Dave Flinn July 1991 UNIX compatable *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Portability: *O * This module should be ANSI C compatible. *E *************************************************************************/ vpf_table_type vpf_open_table( const char * tablename, storage_type storage , const char * mode, char * defstr ) { vpf_table_type table; char tablepath[255], * idxname; ossim_int32 i, j; ossim_int32 tablesize, idxsize, memsize; ossim_uint32 ulval; char * diskname = "VPF data disc"; strcpy(tablepath,tablename); rightjust(tablepath); /* Parse out name and path */ j = -1; i=(long)strlen(tablepath); while (i>0) { #ifdef __MSDOS__ if (tablepath[i] == '\\') { #else if (tablepath[i] == '/') { #endif j = i; break; } i--; } strncpy(table.name,&(tablepath[j+1]),12); rightjust(table.name); strupr(table.name); table.path = (char *)vpfmalloc(((unsigned long)strlen(tablepath)+5)*(unsigned long)sizeof(char)); strcpy(table.path, tablepath); table.path[j+1] = '\0'; /* Establish a read or write table operation */ if ( mode[0] == 'r' ) table.mode = Read ; else table.mode = Write ; /*fprintf(stderr, "vpf_open_table opening %s\n", tablepath);*/ table.fp = vpfopencheck(tablepath,mode,diskname); if (table.fp == NULL) { perror(tablepath); /* #if __MSDOS__ perror(tablepath); getch(); if (getgraphmode() >= 0) closegraph(); exit(0); #endif */ free(table.path); if (table.fp) { fclose(table.fp); table.fp = NULL; } return table; } /* If file is to be created, copy the def string ptr into header for now */ if ( table.mode == Write ) table.defstr = defstr ; #ifdef __MSDOS__ tablesize = (filelength(fileno(table.fp))); #else { /* UNIX doesn't have a filelength function, so this is the best */ struct stat statbuf ; if ( stat ( tablepath, &statbuf ) < 0 ) { fprintf (stderr, "vpf_open_table: can't stat file\n" ) ; free(table.path); fclose(table.fp); table.fp = NULL; return table; } tablesize = statbuf.st_size ; } #endif /* Populate table structure with correct data, either for read or write */ table.reclen = parse_data_def(&table); if ( table.mode == Write ) { /* write out header */ rewind ( table.fp ) ; Write_Vpf_Int ( &table.ddlen, table.fp, 1 ) ; Write_Vpf_Char ( table.defstr, table.fp, table.ddlen ) ; free ( table.defstr ) ; table.defstr = (char *) NULL ; table.nrows = 0 ; } if (table.reclen > 0) { /* Index file */ table.xstorage = (storage_type)COMPUTE; if (table.mode != Write) table.nrows = (tablesize - table.ddlen)/table.reclen; table.xfp = (FILE *) NULL ; } else { idxname = strdup( tablepath ); #ifdef __MSDOS__ idxname[strlen(tablepath)-1] = 'x'; #else if (idxname[strlen(tablepath)-1] == '.') idxname[strlen(tablepath)-2] = 'x'; else idxname[strlen(tablepath)-1] = 'x'; #endif table.xfp = fopen(idxname, mode); if ((!table.xfp) && (table.mode == Read)) { perror(idxname); fprintf(stderr, "hit RETURN to continue..."); i=getc(stdin); free(idxname); for (i = 0; i < table.nfields; i++) free(table.header[i].name); free(table.header); free(table.path); fclose(table.fp); table.fp = NULL; return table; } free(idxname); /*#ifdef __MSDOS__*/ table.xstorage = (storage_type)DISK; /* Worst case default */ /*#endif*/ /* Only read in index if file is read only */ if (table.xfp && ( table.mode == Read ) ) { Read_Vpf_Int (&(table.nrows), table.xfp, 1 ) ; Read_Vpf_Int (&ulval, table.xfp, 1 ) ; idxsize = table.nrows*sizeof(index_cell) + 10L; #ifdef __MSDOS__ if ( (idxsize < (farcoreleft()/2)) && (idxsize < __64K) ) #else if (0) #endif { table.xstorage = (storage_type)RAM; table.index = (index_type)vpfmalloc(idxsize); for (i=0;i<table.nrows;i++) { Read_Vpf_Int (&(table.index[i].pos), table.xfp, 1) ; Read_Vpf_Int (&(table.index[i].length),table.xfp,1 ) ; } fclose(table.xfp); } } else if (table.mode == Write) { /* Write out dummy header record for index file. vpf_close_table finishes the job. */ Write_Vpf_Int ( &(table.ddlen), table.xfp, 1 ) ; Write_Vpf_Int ( &(table.ddlen), table.xfp, 1 ) ; table.xstorage = (storage_type)DISK; table.index = (index_type) NULL ; } } /* end of if table .reclen */ table.storage = (storage_type)DISK; #ifdef __MSDOS__ memsize = (ossim_int32)min(farcoreleft(),__64K); #else memsize = MAXINT; #endif if ( (storage != disk) && ( table.mode == Read ) ) { if (tablesize + table.nrows * table.nfields * HEAP_OVERHEAD < memsize) { fseek(table.fp,index_pos(1,table),SEEK_SET); table.row = (row_type *)vpfmalloc((table.nrows+1)*sizeof(row_type)); for (i=0;i<table.nrows;i++) { table.row[i] = read_next_row(table); } fclose(table.fp); table.storage = (storage_type)RAM; } } table.status = OPENED; return table; } /************************************************************************* * *N vpf_close_table * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function frees an entire table from memory. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * table <inout> == (vpf_table_type) VPF table structure. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Portability: *O * This module should be ANSI C compatible. *E *************************************************************************/ void vpf_close_table( vpf_table_type *table ) { register ossim_int32 i; if (table->status != OPENED) { return; } /*fprintf(stderr, "vpf_close_table closing %s%s\n", table->path, table->name);*/ /* If the table is writable, write out the final record count */ if ( table->mode == Write && table->xfp ) { rewind ( table->xfp ) ; Write_Vpf_Int ( &table->nrows, table->xfp, 1 ) ; Write_Vpf_Int ( &table->ddlen, table->xfp, 1 ) ; } for (i=0;i<table->nfields;i++) { free(table->header[i].name); /* free up null text string */ if ( table->header[i].type == 'T') free(table->header[i].nullval.Char); /* free up index file string */ if (table->header[i].tdx!=(char *)NULL) free ( table->header[i].tdx ) ; /* free up narrative table string */ if (table->header[i].narrative!=(char *)NULL) { free ( table->header[i].narrative ) ; } } free(table->header); switch (table->storage) { case RAM: for (i=0;i<table->nrows;i++) free_row(table->row[i],*table); free(table->row); break; case DISK: fclose(table->fp); break; default: printf("%s%s: unknown storage flag: %d\n",table->path,table->name, table->storage); break; } switch (table->xstorage) { case RAM: free(table->index); break; case DISK: fclose(table->xfp); break; case COMPUTE: break; default: printf("%s%s: unknown index storage flag: %d\n", table->path,table->name,table->storage); break; } table->nfields = 0; free(table->path); table->status = CLOSED; } ossim_int32 is_vpf_table( const char *fname ) { FILE *fp; ossim_int32 n, ok; fp = fopen( fname, "rb" ); if (!fp) { return FALSE; } Read_Vpf_Int ( &n, fp, 1 ) ; fseek( fp, n-1, SEEK_CUR ); if (fgetc(fp) == ';') ok = TRUE; else ok = FALSE; fclose(fp); return ok; }
/************************************************************************* * *N parse_data_def * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function parses a table's data definition and creates a header * in memory that is associated with the table. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * table <inout> == (vpf_table_type *) vpf table structure. * ddlen <input> == (ossim_int32) length of the table's data definition. * * return value is the record length if all items are fixed length, or * -1 if the record contains variable length items *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels April 1991 DOS Turbo C * Mody Buchbinder May 1991 - Modified for new table header. * Dave Flinn July 1991 - updated for UNIX *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F * void *vpfmalloc() VPFMISC.C *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Portability: *O * This module should be ANSI C compatible. *E *************************************************************************/ ossim_int32 parse_data_def( vpf_table_type *table ) { register ossim_int32 n,i; ossim_int32 p, k; char *buf,*des,*nar,*vdt, *tdx, *doc, byte ;/*temporary storage */ char end_of_rec; int status; ossim_int32 ddlen; ossim_int32 reclen = 0; #if UNIX /* just for backward compat check */ ossim_int32 bkcompat = 1 ; #endif if ( table->mode == Read ) { fread(&ddlen,sizeof(ddlen),1,table->fp); /* Check the next byte to see if the byte order is specified */ fread(&byte,1,1,table->fp); p=0; table->byte_order = LEAST_SIGNIFICANT; /* default */ switch (toupper(byte)) { case 'L': p++; break; case 'M': table->byte_order = MOST_SIGNIFICANT; p++; break; } if (MACHINE_BYTE_ORDER != table->byte_order) { k = ddlen; swap_four((char *)&k,(char *)&ddlen); } if ( ddlen < 0 ) { return (ossim_int32)0 ; } STORAGE_BYTE_ORDER = table->byte_order; /* header without first 4 bytes */ table->ddlen = ddlen + sizeof (ossim_int32) ; buf = (char *)vpfmalloc((ddlen+3)*sizeof(char)); buf[0] = byte; /* already have the first byte of the buffer */ Read_Vpf_Char(&buf[1],table->fp,ddlen-1) ; } else { table->ddlen = (long)strlen ( table->defstr ) ; ddlen = table->ddlen ; buf = (char *)vpfmalloc((ddlen+3)*sizeof(char)); strncpy ( buf, table->defstr, ddlen ) ; p=0; table->byte_order = LEAST_SIGNIFICANT; /* default */ byte = buf[0]; switch (toupper(byte)) { case 'L': p++; break; case 'M': table->byte_order = MOST_SIGNIFICANT; p++; break; } STORAGE_BYTE_ORDER = table->byte_order; } buf[ddlen-1] = '\0'; /* mark end of string for reading functions */ if ( buf[p] == ';' ) p++; /* buf[p] is semi-colon */ des = get_string(&p,buf,COMPONENT_SEPERATOR ); strncpy(table->description,des,80); free(des); nar = get_string(&p,buf,COMPONENT_SEPERATOR ); strncpy(table->narrative ,nar,12); free(nar); n = 0 ; /* get number of fields */ for (i=p; i < ddlen;i++) if ( buf[i] == LINE_CONTINUE ) i++ ; /* skip past line continue, and next character */ else if (buf[i] == END_OF_FIELD ) /* Found end of field */ n++; /* increment nfields */ else if (buf[i] == COMMENT ) /* skip past comments */ while ( buf[i] != LINE_CONTINUE && buf[i] != END_OF_FIELD && buf[i] != '\0') i++ ; /* increment i */ table->nfields = n ; table->header = (header_type)vpfmalloc((n+1)*sizeof(header_cell)); for(i=0;i<n;i++) { end_of_rec = FALSE; table->header[i].name = get_string(&p,buf, FIELD_COUNT); /*****/ rightjust(table->header[i].name); table->header[i].type = toupper(vpf_get_char (&p,buf)); table->header[i].count = get_number(&p,buf,FIELD_SEPERATOR ); if ( i == 0 ) if ( ossim_strcasecmp ( table->header[0].name, "ID" ) ) { free(buf); return (ossim_int32)0 ; } if(table->header[i].count == -1) reclen = -1; /* set reclen to variable len flag */ /* Now set null values and add up record length, if fixed length */ status = 0; switch (table->header[i].type) { case 'I': if ( reclen >= 0 ) reclen += (sizeof(ossim_int32)*table->header[i].count); table->header[i].nullval.Int = NULLINT ; break; case 'S': if ( reclen >= 0 ) reclen += (sizeof(short int)*table->header[i].count); table->header[i].nullval.Short = NULLSHORT ; break; case 'F': if ( reclen >= 0 ) reclen += (sizeof(float)*table->header[i].count); table->header[i].nullval.Float = NULLFLOAT ; break; case 'R': if ( reclen >= 0 ) reclen += (sizeof(double)*table->header[i].count); table->header[i].nullval.Double = NULLDOUBLE ; break; case 'T': if ( reclen >= 0 ) { /* if fixed length */ reclen += (sizeof(char)*table->header[i].count); table->header[i].nullval.Char = (char *) vpfmalloc ( table->header[i].count + 1 ) ; for ( k=0; k < table->header[i].count; k++ ) table->header[i].nullval.Char[k] = NULLCHAR ; table->header[i].nullval.Char[k] = '\0'; } else { /* variable length */ table->header[i].nullval.Char = (char *) vpfmalloc ( VARIABLE_STRING_NULL_LENGTH + 1 ) ; for ( k=0; k < VARIABLE_STRING_NULL_LENGTH ; k++ ) table->header[i].nullval.Char[k] = NULLCHAR ; table->header[i].nullval.Char[k] = '\0'; } break; case 'C': if ( reclen >= 0 ) reclen += (sizeof(coordinate_type)*table->header[i].count); table->header[i].nullval.Other = '\0'; break; case 'Z': if ( reclen >= 0 ) reclen += (sizeof(tri_coordinate_type)*table->header[i].count); table->header[i].nullval.Other = '\0' ; break; case 'B': if ( reclen >= 0 ) reclen += (sizeof(double_coordinate_type)*table->header[i].count); table->header[i].nullval.Other = '\0' ; break; case 'Y': if ( reclen >= 0 ) reclen += (sizeof(double_tri_coordinate_type)*table->header[i].count); table->header[i].nullval.Other ='\0'; break; case 'D': if ( reclen >= 0 ) reclen += ((sizeof(date_type)-1)*table->header[i].count); strcpy ( table->header[i].nullval.Date, NULLDATE ) ; break; case 'K': reclen = -1; table->header[i].nullval.Other = '\0' ; break; case 'X': /* do nothing */ table->header[i].nullval.Other = '\0' ; break ; default: status = 1; break ; } /** switch type **/ if (status) { free(buf); return (ossim_int32)0; } table->header[i].keytype = vpf_get_char (&p,buf); des = get_string(&p,buf, FIELD_SEPERATOR ); rightjust(des); strncpy(table->header[i].description,des,80); free(des); vdt = get_string(&p,buf, FIELD_SEPERATOR ); strncpy(table->header[i].vdt,vdt,12); free(vdt); #if UNIX /* This is for backward compatability qc checking */ if ( bkcompat && buf[p] == END_OF_FIELD ) { bkcompat= 0 ; } #endif tdx = get_string(&p,buf, FIELD_SEPERATOR ) ; if ( ! strcmp ( tdx, "" ) ) { table->header[i].tdx = (char *) NULL ; if (buf[p] == ':') end_of_rec = TRUE; } else { if (strcmp(tdx,"-") != 0) { table->header[i].tdx =(char*) vpfmalloc ( (unsigned long)strlen ( tdx ) +1 ) ; strcpy (table->header[i].tdx, tdx ); } else table->header[i].tdx = (char *)NULL; } free(tdx); if (!end_of_rec) { doc = get_string(&p,buf, FIELD_SEPERATOR ) ; if ( ! strcmp ( doc, "" ) ) { table->header[i].narrative = (char *) NULL ; end_of_rec = TRUE; } else { if (strcmp(doc,"-") != 0) { table->header[i].narrative = (char*)vpfmalloc ( (unsigned long)strlen(doc) +1) ; strcpy (table->header[i].narrative, doc ); } else table->header[i].narrative = (char *)NULL; } free(doc); } else table->header[i].narrative = (char *)NULL; p += 1; /** eat semicolon **/ } free(buf); return reclen; }
/************************************************************************** * *N select_feature_class_relate * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * Set up the relationships between features and primitives or between * primitives and features (one way only) for a specified feature class. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ fcrel_type select_feature_class_relate( int fcnum, library_type *library, char *start_table, char *end_table ) { int storage, cov; vpf_table_type fcs; long int i; char path[255], covpath[255]; position_type p; vpf_relate_struct rcell; fcrel_type fcrel; fcrel.nchain = 0; fcrel.table = NULL; fcrel.relate_list = NULL; cov = library->fc[fcnum].coverage; strcpy(covpath,library->cover[cov].path); rightjust(covpath); sprintf( path, "%sfcs", covpath ); /* Feature Class Schema table */ fcs = vpf_open_table( path, disk, "rb", NULL ); fcrel.relate_list = fcs_relate_list( library->fc[fcnum].name, start_table,end_table, fcs ); if (ll_empty(fcrel.relate_list)) { ll_reset(fcrel.relate_list); displaymessage("ERROR in feature class relationship!", start_table,end_table,NULL); return fcrel; } /* Find the number of tables in the relate chain */ p = ll_first(fcrel.relate_list); fcrel.nchain = 0; while (!ll_end(p)) { fcrel.nchain++; p = ll_next(p); } /* Allow for last table2 */ fcrel.nchain++; fcrel.table = (vpf_table_type *) vpfmalloc((fcrel.nchain+1)* sizeof(vpf_table_type)); for (i=0;i<fcrel.nchain+1;i++) vpf_nullify_table( &(fcrel.table[i]) ); p = ll_first(fcrel.relate_list); for (i=0;i<fcrel.nchain-1;i++) { ll_element(p,&rcell); /** Can't open primitive table - may be several under tile **/ /** directories. Open all others **/ if (!is_primitive(rcell.table1)) { sprintf(path,"%s%s",covpath,rcell.table1); if (is_join(rcell.table1)) storage = ram; else storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } if (!ll_end(p)) p = ll_next(p); } /* End of relate chain */ i = fcrel.nchain-1; if (!is_primitive(rcell.table2)) { sprintf(path,"%s%s",covpath,rcell.table2); storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } vpf_close_table( &fcs ); return fcrel; }
/************************************************************************** * *N fcs_relate_list * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * Read the feature class schema table and create the list of * tables to chain through. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * fcname <input> == (char *) feature class name. * start_table <input> == (char *) table to start from. * end_table <input> == (char *) table to end with. * fcs <input> == (vpf_table_type) feature class schema table. * fcs_relate_list <output> == (linked_list_type) list of tables to * chain through. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ linked_list_type fcs_relate_list( char *fcname, char *start_table, char *end_table, vpf_table_type fcs ) { linked_list_type rlist; vpf_relate_struct rstruct; set_type fcset, set1, set2; char tablename[255], *buf, expr[255]; row_type row; long int rownum,n; int TABLE1_, KEY1_, TABLE2_, KEY2_; rlist = ll_init(); sprintf(expr,"FEATURE_CLASS = %s",fcname); fcset = query_table(expr,fcs); if (set_empty(fcset)) { set_nuke(&fcset); return rlist; } TABLE1_ = table_pos("TABLE1",fcs); KEY1_ = table_pos("FOREIGN_KEY",fcs); if (KEY1_ < 0) KEY1_ = table_pos("TABLE1_KEY",fcs); TABLE2_ = table_pos("TABLE2",fcs); KEY2_ = table_pos("PRIMARY_KEY",fcs); if (KEY2_ < 0) KEY2_ = table_pos("TABLE2_KEY",fcs); strcpy( tablename, start_table ); while (1) { sprintf(expr,"TABLE1 = %s",tablename); set1 = query_table(expr,fcs); set2 = set_intersection(set1,fcset); set_nuke(&set1); if (set_empty(set2)) { set_nuke(&fcset); set_nuke(&set2); return rlist; } rownum = set_min(set2); set_nuke(&set2); row = get_row(rownum,fcs); buf = (char *)get_table_element(TABLE1_,row,fcs,NULL,&n); strcpy(rstruct.table1,buf); rightjust(rstruct.table1); free(buf); buf = (char *)get_table_element(KEY1_,row,fcs,NULL,&n); strcpy(rstruct.key1,buf); rightjust(rstruct.key1); free(buf); buf = (char *)get_table_element(TABLE2_,row,fcs,NULL,&n); strcpy(rstruct.table2,buf); rightjust(rstruct.table2); free(buf); buf = (char *)get_table_element(KEY2_,row,fcs,NULL,&n); strcpy(rstruct.key2,buf); rightjust(rstruct.key2); free(buf); rstruct.degree = R_ONE; /* Default */ free_row( row, fcs ); if (table_in_list(rstruct.table1, rlist)) break; ll_insert( &rstruct, sizeof(rstruct), ll_last(rlist) ); strcpy( tablename, rstruct.table2 ); if (ossim_strcasecmp(tablename,end_table)==0) break; } set_nuke(&fcset); return rlist; }
/************************************************************************* * *N get_selected_primitives * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function determines all of the selected primitive rows from * the selected features. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * view <input> == (view_type *) view structure. * themenum <input> == (int) theme number. * library <input> == (library_type *) VPF library structure. * mapenv <input> == (map_environment_type *) map environment. * status <output> == (int *) status of the function: * 1 if completed, 0 if user escape. * get_selected_primitives <output> == (set_type *) array of sets, each position * representing the set of primitives for the * corresponding tile in the tileref.aft table. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *************************************************************************/ set_type *get_selected_primitives( view_type *view, int themenum, library_type *library, map_environment_type *mapenv, int *status ) { int fcnum, finished, found, cov, tilecover, TILEPATH_, degree; int feature, prim; vpf_table_type tile_table; row_type row; char *ptable[] = {"","edg","fac","txt","end","cnd"}; char *spxname[] = {"","esi","fsi","tsi","nsi","csi"}; char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"}; set_type feature_rows, primitive_rows, tile_features; set_type *primitives; rspf_int32 prim_rownum, count, tile; register rspf_int32 i,j, pclass, start,end; char path[255], covpath[255], tiledir[255], *buf, str[255]; fcrel_type fcrel; linked_list_type primlist; position_type p; vpf_relate_struct rcell; ThematicIndex idx; primitives = (set_type *)vpfmalloc((library->ntiles+1)*sizeof(set_type)); for (i=0;i<=library->ntiles;i++) { primitives[i].size = 0; primitives[i].buf = NULL; } fcnum = view->theme[themenum].fcnum; feature_rows = get_selected_features( view, themenum, *library ); /* Open the tile reference table, if present */ sprintf(path,"%stileref\\tileref.aft",library->path); if (access(path,0) != 0) { tilecover = FALSE; } else { tile_table = vpf_open_table(path,disk,"rb",NULL); TILEPATH_ = table_pos("TILE_NAME",tile_table); tilecover = TRUE; } for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) { if ((pclass != library->fc[fcnum].primclass) && (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue; /* Set up the feature class table relate chain. */ /* The feature table is fcrel.table[0]. */ /* The primitive table is the last table in the chain: */ /* fcrel.table[ fcrel.nchain-1 ]. */ j = 0; for (i=0;i<strlen(library->fc[fcnum].table);i++) if (library->fc[fcnum].table[i] == '\\') j = i+1; strcpy( str, &(library->fc[fcnum].table[j])); fcrel = select_feature_class_relate(fcnum, library, str, ptable[pclass]); feature = 0; prim = fcrel.nchain-1; p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list); ll_element(p,&rcell); degree = rcell.degree; /*** 'Tile' number 1 is the universe polygon for the tileref cover ***/ for (tile = 2; tile <= library->ntiles; tile++ ) { if (!set_member(tile,library->tile_set)) continue; if (tilecover) { row = get_row(tile,tile_table); buf = (char *)get_table_element(TILEPATH_,row,tile_table, NULL,&count); free_row(row,tile_table); strcpy(tiledir,buf); rightjust(tiledir); strcat(tiledir,"\\"); free(buf); } else { strcpy(tiledir,""); } cov = library->fc[fcnum].coverage; strcpy( covpath, library->cover[cov].path ); finished = 1; found = 0; /* Open primitive table in tile */ sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]); if (access(path,0) != 0) continue; found = 1; fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL); if (primitives[tile].size > 0) { printf("Oops! size = %ld\n",primitives[tile].size); exit(1); } primitives[tile] = set_init(fcrel.table[prim].nrows+1); /* Get the set of primitive rows within the map extent */ /* Look for spatial index file */ primitive_rows.size = 0; if (mapenv->projection == PLATE_CARREE && mapenv->mapextent.x1 < mapenv->mapextent.x2) { sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]); if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) { primitive_rows = spatial_index_search(path, mapenv->mapextent.x1,mapenv->mapextent.y1, mapenv->mapextent.x2,mapenv->mapextent.y2); } else { /* Next best thing - bounding rectangle table */ sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]); if (access(path,0)==0) { primitive_rows = bounding_select(path,mapenv->mapextent, library->dec_degrees); } } } /* projection check */ if (primitive_rows.size == 0) { /* Search through all the primitives */ primitive_rows=set_init(fcrel.table[prim].nrows+1); set_on(primitive_rows); } tile_thematic_index_name(fcrel.table[feature], path); if ( (strcmp(path,"") != 0) && (access(path,4)==0) ) { /* Tile thematic index for feature table present, */ tile_features = read_thematic_index( path, (char *)&tile ); } else { tile_features = set_init(fcrel.table[feature].nrows+1); set_on(tile_features); } idx.fp = NULL; i = table_pos(rcell.key2,fcrel.table[prim]); if (i >= 0) { if (fcrel.table[prim].header[i].tdx) { sprintf(path,"%s%s",fcrel.table[prim].path, fcrel.table[prim].header[i].tdx); if (access(path,0)==0) idx = open_thematic_index(path); } if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE; if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY; if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE; } finished = 1; start = set_min(tile_features); end = set_max(tile_features); fseek(fcrel.table[feature].fp, index_pos(start,fcrel.table[feature]), SEEK_SET); for (i=start;i<=end;i++) { row = read_next_row(fcrel.table[feature]); if (!set_member( i, feature_rows )) { free_row(row,fcrel.table[feature]); continue; } if (!set_member( i, tile_features )) { free_row(row,fcrel.table[feature]); continue; } if (degree == R_ONE) { prim_rownum = fc_row_number( row, fcrel, tile ); primlist = NULL; p = NULL; } else { primlist = fc_row_numbers( row, fcrel, tile, &idx ); } free_row( row, fcrel.table[feature] ); if (!primlist) { if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives[tile]); } } else { p = ll_first(primlist); while (!ll_end(p)) { ll_element(p,&prim_rownum); if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives[tile]); } p = ll_next(p); } } if (kbhit()) { if (getch()==27) { *status = 0; finished = 0; break; } } } if (idx.fp) close_thematic_index(&idx); vpf_close_table(&(fcrel.table[prim])); set_nuke(&primitive_rows); set_nuke(&tile_features); if (set_empty(primitives[tile])) { set_nuke(&primitives[tile]); primitives[tile].size = 0; primitives[tile].buf = NULL; } if (!finished) { *status = 0; break; } } if (!finished) { *status = 0; deselect_feature_class_relate( &fcrel ); break; } if (found) *status = 1; if (kbhit()) { if (getch()==27) { *status = 0; deselect_feature_class_relate( &fcrel ); break; } } deselect_feature_class_relate( &fcrel ); } set_nuke(&feature_rows); if (tilecover) { vpf_close_table(&tile_table); } return primitives; }
/************************************************************************* * *N draw_selected_features * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function draws the selected features from a specified feature * class based upon a query (either an expression or the pre-compiled * results of an expression). *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * view <inout>==(view_type *) view structure. * themenum <input>==(int) theme number. * library <input>==(library_type *) VPF library structure. * mapenv <input>==(map_environment_type *) map environment structure. * return <output>==(int) completion status: * 1 if completed successfully, * 0 if an error occurred. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels August 1991 DOS Turbo C *E *************************************************************************/ int draw_selected_features( view_type *view, int themenum, library_type *library, map_environment_type *mapenv ) { int status, fcnum, finished, cov, tilecover, TILEPATH_, prim; int outline, color1, color2, color3, color4; vpf_table_type rngtable,edgtable,fbrtable, tile_table; row_type row; char *ptable[] = {"","edg","fac","txt","end","cnd"}; register rspf_int32 i, j, p, pclass, tile; int display_order[] = {FACE,EDGE,ENTITY_NODE,CONNECTED_NODE,TEXT}; register rspf_int32 starttile, endtile, startprim, endprim; rspf_int32 count; char path[255], covpath[255], tiledir[255], *buf, str[255]; char *drive, rngpath[255],edgpath[255],edxpath[255],fbrpath[255]; boolean rng_rdisk,edg_rdisk,fbr_rdisk; set_type primitives, feature_rows; fcrel_type fcrel; window_type info; struct viewporttype vp; getviewsettings(&vp); fcnum = view->theme[themenum].fcnum; sprintf(path,"%stileref\\tileref.aft",library->path); if (access(path,0) != 0) { tilecover = FALSE; } else { tile_table = vpf_open_table(path,disk,"rb",NULL); TILEPATH_ = table_pos("TILE_NAME",tile_table); tilecover = TRUE; } feature_rows = get_selected_features( view, themenum, *library ); for (p=0;p<5;p++) { pclass = display_order[p]; if ((pclass != library->fc[fcnum].primclass) && (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue; if ((library->fc[fcnum].primclass == COMPLEX_FEATURE) && (!library->fc[fcnum].cprim[pclass])) continue; /* Set up the feature class table relate chain. */ /* The feature table is fcrel.table[0]. */ /* The primitive table is the last table in the chain: */ /* fcrel.table[ fcrel.nchain-1 ]. */ j = 0; for (i=0;i<strlen(library->fc[fcnum].table);i++) if (library->fc[fcnum].table[i] == '\\') j = i+1; strcpy( str, &(library->fc[fcnum].table[j])); fcrel = select_feature_class_relate(fcnum, library, str, ptable[pclass]); prim = fcrel.nchain-1; /*** 'Tile' number 1 is the universe polygon for the tileref cover ***/ starttile = set_min(library->tile_set); if (starttile < 2) starttile = 2; endtile = set_max(library->tile_set); if (endtile < 2) endtile = 2; for (tile = starttile; tile <= endtile; tile++ ) { if (!set_member(tile,library->tile_set)) continue; if (tilecover) { row = get_row(tile,tile_table); buf = (char *)get_table_element(TILEPATH_,row,tile_table, NULL,&count); free_row(row,tile_table); strcpy(tiledir,buf); rightjust(tiledir); strcat(tiledir,"\\"); free(buf); } else { strcpy(tiledir,""); } cov = library->fc[fcnum].coverage; strcpy( covpath, library->cover[cov].path ); finished = TRUE; sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]); if (access(path,0) != 0) continue; fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL); info = info_window("Searching..."); primitives = get_selected_tile_primitives( library, fcnum, fcrel, feature_rows, mapenv, tile, tiledir, &status ); delete_window(&info); setviewport(vp.left,vp.top,vp.right,vp.bottom,vp.clip); /* Reset plate-carree parameters (changed in */ /* get_selected_tile_primitives() ) */ if (mapenv->projection == PLATE_CARREE) set_plate_carree_parameters( central_meridian( mapenv->mapextent.x1, mapenv->mapextent.x2), 0.0, 1.0 ); if (primitives.size < 1) { vpf_close_table(&fcrel.table[prim]); continue; } if (!status) { set_nuke(&primitives); vpf_close_table(&fcrel.table[prim]); break; } if (pclass == FACE) { /* Must also open RNG, EDG, and FBR for drawing faces. */ /* If a RAM disk is specified, copy these to it and open */ /* them there. */ rng_rdisk = FALSE; edg_rdisk = FALSE; fbr_rdisk = FALSE; drive = getenv("TMP"); buf = (char *)vpfmalloc(255); sprintf(path,"%s%srng",covpath,tiledir); strcpy(rngpath,path); if (drive && filesize(path) < available_space(drive)) { sprintf(rngpath,"%s\\RNG",drive); sprintf(buf,"COPY %s %s > NUL",path,rngpath); system(buf); rng_rdisk = TRUE; } rngtable = vpf_open_table(rngpath,disk,"rb",NULL); sprintf(path,"%s%sedg",covpath,tiledir); strcpy(edgpath,path); sprintf(edxpath,"%s%sedx",covpath,tiledir); if (drive && (filesize(path)+filesize(edxpath))<available_space(drive)) { sprintf(edgpath,"%s\\EDG",drive); sprintf(buf,"COPY %s %s > NUL",path,edgpath); system(buf); sprintf(edxpath,"%s\\EDX",drive); sprintf(buf,"COPY %s%sedx %s > NUL",covpath,tiledir,edxpath); system(buf); edg_rdisk = TRUE; } edgtable = vpf_open_table(edgpath,disk,"rb",NULL); sprintf(path,"%s%sfbr",covpath,tiledir); strcpy(fbrpath,path); if (drive && filesize(path) < available_space(drive)) { sprintf(fbrpath,"%s\\FBR",drive); sprintf(buf,"COPY %s %s > NUL",path,fbrpath); system(buf); fbr_rdisk = TRUE; } fbrtable = vpf_open_table(fbrpath,disk,"rb",NULL); free(buf); } finished = 1; startprim = set_min(primitives); endprim = set_max(primitives); /* It turns out to be MUCH faster off of a CD-ROM to */ /* read each row and discard unwanted ones than to */ /* forward seek past them. It's about the same off */ /* of a hard disk. */ fseek(fcrel.table[prim].fp, index_pos(startprim,fcrel.table[prim]), SEEK_SET); for (i=startprim;i<=endprim;i++) { row = read_next_row(fcrel.table[prim]); if (set_member( i, primitives )) { /* Draw the primitive */ switch (pclass) { case EDGE: finished = draw_edge_row(row,fcrel.table[prim]); break; case ENTITY_NODE: case CONNECTED_NODE: finished = draw_point_row(row,fcrel.table[prim]); break; case FACE: gpgetlinecolor( &outline ); gpgetpattern( &color1, &color2, &color3, &color4 ); hidemousecursor(); draw_face_row( row,fcrel.table[prim], rngtable, edgtable, fbrtable, outline, color1, color2, color3, color4 ); showmousecursor(); finished = 1; if (kbhit()) { if (getch()==27) finished = 0; } break; case TEXT: finished = draw_text_row(row,fcrel.table[prim]); break; } } free_row(row,fcrel.table[prim]); if (!finished) { status = 0; break; } } if (pclass == FACE) { vpf_close_table(&rngtable); if (rng_rdisk) remove(rngpath); vpf_close_table(&edgtable); if (edg_rdisk) { remove(edgpath); remove(edxpath); } vpf_close_table(&fbrtable); if (fbr_rdisk) remove(fbrpath); } vpf_close_table(&fcrel.table[prim]); set_nuke(&primitives); if (!finished) { status = 0; break; } } if (!finished) { status = 0; deselect_feature_class_relate( &fcrel ); break; } status = 1; if (kbhit()) { if (getch()==27) { status = 0; deselect_feature_class_relate( &fcrel ); break; } } deselect_feature_class_relate(&fcrel); } if (tilecover) { vpf_close_table(&tile_table); } set_nuke(&feature_rows); return status; }
/************************************************************************* * *N vpf_display_record * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function displays all of the fields of a particular VPF * record, including the descriptions of the fields and their * values. It accesses the online data dictionary metadata * contained in the specified Value Description Tables. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * row <input> == (row_type) vpf table row structure. * table <input> == (vpf_table_type) vpf table. * fp <input> == (FILE *) pointer to the output file. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels Sept 1991 DOS Turbo C *E *************************************************************************/ void vpf_display_record( row_type row, vpf_table_type table, FILE *fp ) { register int i,j; char *buf,*num, path[128], *tablename; char *attr,*val,*descr, vdtpath[128], fmtdate[40]; vpf_table_type vdt; row_type vdtrow; int found; ossim_int32 l, lval, count, *lptr; short int s,sval,*sptr; float f,*fptr; date_type date; int TABLE_ = 1, ATTR_ = 2, VAL_ = 3, DESCR_ = 4; num = (char *)vpfmalloc(20*sizeof(char)); strcpy( vdtpath, "" ); /* Display all secondary attributes */ for (i=0;i<table.nfields;i++) { switch (table.header[i].type) { case 'T': buf = (char *)get_table_element(i,row,table, NULL,&count); rightjust(buf); if (strcmp( buf, "" ) != 0) { fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": ",fp); fputs(buf,fp); strcpy( path, table.path ); strcat( path, table.header[i].vdt ); if ( (access(path,4)==0) && (strcmp(table.header[i].vdt,"") != 0) ) { if (strcmp(vdtpath,path) != 0) { if (strcmp(vdtpath,"") != 0) { vpf_close_table(&vdt); } vdt = vpf_open_table( path, disk, "rb", NULL ); } strcpy( vdtpath, path ); for (j=1;j<=vdt.nrows;j++) { vdtrow = read_row( j, vdt ); tablename = (char *)get_table_element( TABLE_, vdtrow, vdt, NULL, &count ); rightjust(tablename); strupr2(tablename); attr = (char *)get_table_element( ATTR_, vdtrow, vdt, NULL, &count ); rightjust(attr); val = (char *)get_table_element( VAL_, vdtrow, vdt, NULL, &count ); rightjust(val); found = FALSE; if ( (strstr(table.name,tablename)) && (ossim_strcasecmp(attr,table.header[i].name)==0) && (ossim_strcasecmp(val,buf)==0) ) { descr = (char *)get_table_element(DESCR_,vdtrow,vdt, NULL, &count); rightjust(descr); fputs(" (",fp); fputs(descr,fp); fputs(")",fp); free(descr); found = TRUE; } free(tablename); free(attr); free(val); free_row( vdtrow, vdt ); if (found) break; } } fputc('\n',fp); } free(buf); break; case 'I': if (table.header[i].count==1) { get_table_element(i,row,table,&l,&count); if (l != NULLINT) { fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": ",fp); ltoa((int)l,num,10); fputs(num,fp); strcpy( path, table.path ); strcat( path, table.header[i].vdt ); if ( (access(path,4)==0) && (strcmp(table.header[i].vdt,"") != 0) ) { if (strcmp(vdtpath,path) != 0) { if (strcmp(vdtpath,"") != 0) { vpf_close_table(&vdt); } vdt = vpf_open_table( path, disk, "rb", NULL ); } strcpy( vdtpath, path ); for (j=1;j<=vdt.nrows;j++) { vdtrow = read_row( j, vdt ); tablename = (char *)get_table_element( TABLE_, vdtrow, vdt, NULL, &count ); rightjust(tablename); strupr2(tablename); attr = (char *)get_table_element( ATTR_, vdtrow, vdt, NULL, &count ); rightjust(attr); get_table_element( VAL_, vdtrow, vdt, &lval, &count ); found = FALSE; if ( (strstr(table.name,tablename)) && (ossim_strcasecmp(attr,table.header[i].name)==0) && (lval==l) ) { descr = (char *)get_table_element(DESCR_,vdtrow, vdt, NULL, &count); rightjust(descr); fputs(" (",fp); fputs(descr,fp); fputs(")",fp); free(descr); found = TRUE; } free(tablename); free(attr); free_row( vdtrow, vdt ); if (found) break; } } fputc('\n',fp); } } else { get_table_element(i,row,table,&lptr,&count); fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": (",fp); for (j=0;j<count;j++) { ltoa((int)lptr[j],num,10); fputs(num,fp); if (j<count-1) fputs(", ",fp); } fputs(")\n",fp); } break; case 'S': if (table.header[i].count==1) { get_table_element(i,row,table,&s,&count); if (s != NULLSHORT) { fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": ",fp); itoa(s,num,10); fputs(num,fp); strcpy( path, table.path ); strcat( path, table.header[i].vdt ); if ( (access(path,4)==0) && (strcmp(table.header[i].vdt,"") != 0) ) { if (strcmp(vdtpath,path) != 0) { if (strcmp(vdtpath,"") != 0) { vpf_close_table(&vdt); } vdt = vpf_open_table( path, disk, "rb", NULL ); } strcpy( vdtpath, path ); for (j=1;j<=vdt.nrows;j++) { vdtrow = read_row( j, vdt ); tablename = (char *)get_table_element( TABLE_, vdtrow, vdt, NULL, &count ); rightjust(tablename); strupr2(tablename); attr = (char *)get_table_element( ATTR_, vdtrow, vdt, NULL, &count ); rightjust(attr); get_table_element( VAL_, vdtrow, vdt, &sval, &count ); found = FALSE; if ( (strstr(table.name,tablename)) && (ossim_strcasecmp(attr,table.header[i].name)==0) && (sval==s) ) { descr = (char *)get_table_element(DESCR_,vdtrow, vdt, NULL, &count); rightjust(descr); fputs(" (",fp); fputs(descr,fp); fputs(")",fp); free(descr); found = TRUE; } free(tablename); free(attr); free_row( vdtrow, vdt ); if (found) break; } } fputc('\n',fp); } } else { get_table_element(i,row,table,&sptr,&count); fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": (",fp); for (j=0;j<count;j++) { itoa(sptr[j],num,10); fputs(num,fp); if (j<count-1) fputs(", ",fp); } fputs(")\n",fp); } break; case 'F': if (table.header[i].count==1) { get_table_element(i,row,table,&f,&count); if (!is_vpf_null_float(f)) { fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": ",fp); #if !defined(__APPLE__) && !defined(__FreeBSD__) gcvt(f,6,num); #endif fputs(num,fp); fputc('\n',fp); } } else { get_table_element(i,row,table,&fptr,&count); fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": (",fp); for (j=0;j<count;j++) { if (is_vpf_null_float(fptr[j])) { fputs("(null)",fp); } else { #if !defined(__APPLE__) && !defined(__FreeBSD__) gcvt(fptr[j],6,num); #endif fputs(num,fp); } if (j<count-1) fputs(", ",fp); } fputs(")\n",fp); } break; case 'D': if (table.header[i].count==1) { get_table_element(i,row,table,date,&count); fputs(table.header[i].name,fp); fputs(" - ",fp); fputs(table.header[i].description,fp); fputs(": ",fp); format_date(date,fmtdate); fputs(fmtdate,fp); fputc('\n',fp); } break; } } if (strcmp(vdtpath,"") != 0) vpf_close_table( &vdt ); free(num); }