/* This program, written in ANSI C (NO GUARANTEES AS TO PORTABILITY! IT RUNS ON * SunOS 4.1.1, COMPILED WITH GCC), does not require HTTPD, CGI, or Mosaic. It * reads either the standard input or a series of files in the directory given by * the -d argument whose unit number is given, and prints plain text on stdout. * * The unit descriptions must be named box%.unit#, where % represents a * box number, of arbitrary format, and # is the unit * number, unpadded. Clearly this must be changed for DOS. * * The command line syntax is as follows: * lithterp_text [-ddirectory] [unit number] * With no arguments, the stdin is read until EOF or EOT. Unit number must be a * positive integer. If -d is absent and a number is given, the current directory (.) * is used. Please, no space after -d! * * 6/17/94 Version 2: RQD fields moved to header, fields renumbered * 6/16/94 Version 1: modified from cgi interpreter at expet * Paul Asimow (paul@expet.gps.caltech.edu) */ #include #include #include #include #include void main(int argc, char *argv[]) { FILE *fp1; char *buf, *data[100], instring[600], outstring[100]; char filename[20][50], *directory; int field,unit,i=0,j,k; int stdinflag=0, activecomma; buf = (char *) malloc(sizeof(char)); if (argc == 1) { stdinflag = 1; i = 1; } else { if (*argv[1] != '-') { if ((unit = atoi(argv[1])) == 0) { printf("Bad unit number\n"); exit(1); } directory = (char *) malloc(2*sizeof(char)); strcpy(directory,"."); } else if (*(++argv[1]) != 'd') { printf("Syntax: lithterp_text [-d directory][unit number]\n"); exit(1); } else { directory=(char *) malloc(strlen(++argv[1])*sizeof(char)); strcpy(directory,argv[1]); if ((unit = atoi(argv[2])) == 0) { printf("Bad unit number\n"); exit(1); } } /* Search directory for files with right unit number */ sprintf(outstring, "ls %s/box*.unit%d",directory,unit); fp1 = popen(outstring, "r"); while (fscanf(fp1, "%s", filename[i]) != EOF) i++; pclose(fp1); free(directory); printf("Lithologic Unit #%d (found in %d boxes)\n\n",unit,i); } for (j=0;j