/* ******************************************************************* * * * Copyright (c) L-DGO/MIT/JGOFS * * * * * * File : list.c * * * * Purpose : * * * * Version Number : 1.2b June 1, 1999 * * Version Number : 1.2a November 9, 1998 * * * * Version Number : 1.1a October 8, 1996 * * Version Number : 1.1 * * * * Revision History : * * * * Date Developer * * ---- --------- * * June 1, 1999 Christine Hammond * * per WJS and CLC - see comment in code re print of msg * * * * Nov 9, 1998 Christine Hammond * * ver 1.2a resolves diffs between ver 1.2 and 1.1a * * developed independently from same code * * * * Aug 29, 1995 12.00 Christine Hammond * * ver 1.2 attribute for width determines width of field * * option '-m' converts missing value from 'nd' to -9999.0 * * Oct. 8, 1996 Warren Sass * * Change number of char per flatfile output line before new line * * is inserted from 255 to 511 * * Sat Oct 17 1992 10.00 Glenn Flierl * * * ******************************************************************* */ #if HP || IBM #define jdbopen_ jdbopen #define jdbreada_ jdbreada #define jdbread_ jdbread #define jdbclose_ jdbclose #define jdbcomments_ jdbcomments #define jdblevel_ jdblevel #define jdbattributes_ jdbattributes #endif #include #include #ifndef PC #include #define CR 10 #else #define CR 13 #endif #define SPACE 32 #define NVALS 250 #define TOKEN 256 #define ATTRLEN 256 #define VALSIZE 80 #define OUTLINEBUF 4096 char names[NVALS][TOKEN], vals[NVALS][VALSIZE]; int levels[NVALS], widths[NVALS]; char outline[OUTLINEBUF]; int outcount; char blanks[]=" "; int unit,maxlevel,firstpass,num,level; int token=TOKEN; int valsize=VALSIZE; int nflag=1; int fflag=0; int mflag=0; int hflag=1; int cflag=1; int fillsize=7; int olen=OUTLINEBUF; char osep[]=","; FILE *ofile; #ifndef PC void rst_term(); #endif void writemln(outline) char *outline; { char ccc; if(outline[strlen(outline)-1] == osep[0])outline[strlen(outline)-1]='\0'; fprintf(ofile,"%s\n",outline); outcount++; if (outcount >= 23 && nflag){ printf("--More--"); #ifdef PC ccc=getch(); #else ccc=getchar(); #endif switch(ccc){ case SPACE: printf("\n");outcount=0;break; case CR: #ifdef PC printf("\n"); #endif outcount=22;break; default:printf("\n"); jdbclose_(&unit); system("/bin/stty opost"); #if SUN || ULTRIX if(nflag)system("/bin/stty -cbreak"); #endif #if IRIX || IBM || OSF || SOL || HP if(nflag)system("/bin/stty icanon"); #endif exit(1); break; }; }; } char *prettyprint(s,ifmt,vn) char *s; int ifmt, vn; { char tmp[OUTLINEBUF]; /* if the user wants to translate 'nd' vals to numeric */ if (mflag) { if (strcmp(s,"nd") ==0) strcpy(s,"-9999.0"); }; /* if the user wants no extra spaces at all, do not align columns */ if (ifmt >0) { if (widths[vn] != 0) ifmt=widths[vn]; }; if (strlen(s)olen){ writemln(outline); outline[0]='\0'; }; strcat(outline,s); strcat(outline,osep); } void outflush() { if(outline[0])writemln(outline); outline[0]='\0'; } void writevar(level) int level; { int i,j; char tmp[OUTLINEBUF],msg[TOKEN]; if(fflag){ if(firstpass){ if(cflag) while(jdbcomments_(&unit,msg)){ strcpy(tmp,"# "); strcat(tmp,msg); strcat(tmp," "); writemln(tmp); }; if(hflag) { for(i=0;i=argc){ printf ("Usage: %s [-n] [-s] [-t] [-f] [-b] [-m] [-c] [-z] object [outfile]\n", argv[0]); printf("Options: \n -n nonstop\n -s space-separated\n"); printf(" -t tab-separated\n -f flat file output\n"); printf(" -b brief flat file (no header info)\n"); printf(" -m missing value converted to -9999.0\n"); printf(" -c no comments\n"); printf(" -z delete extra spaces\n"); exit(1); }; ofile=stdout; while(argv[i][0]=='-') { switch(argv[i++][1]){ case 'f': fflag=1; olen=511;break; case 'm': mflag=1; break; case 'n': nflag=0; break; case 's': osep[0]=' '; break; case 't': osep[0]='\t'; break; case 'b': fflag=1;hflag=0;cflag=0; olen=511;break; case 'c': cflag=0;break; case 'z': fillsize=0;break; }; } strcpy(outline,argv[i]); if(++i < argc){ofile=fopen(argv[i],"w");nflag=0;}; unit=1; num= -NVALS; maxlevel=jdbopen_(&unit,outline,names,&token,&num); if(maxlevel<0){printf("Object not found(0)\n");exit(1);}; /* do levels, attributes & cleanup names*/ for(i=0;i=0) { for(i=0;i