/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "column.p" */ #include /* column: pull defined column from input Dr. Thomas D. Schneider National Institutes of Health National Cancer Institute Center for Cancer Research Nanobiology Program Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.ccrnp.ncifcrf.gov/~toms/ */ /* end of program */ /* begin module version */ #define version 1.06 /* of column.p 2005 Sep 13 2005 Sep 13, 1.06 upgrade documentation 2000 Jan 16, 1.05 upgrade documentation 1993 Sep 8, 1.04 previous changes origin 1992 September 15 */ /* end module version */ /* begin module describe.column */ /* name column: pull defined column from input synopsis column(input: in, columnp: in, output: out) files input: file with several columns of data separated by spaces lines that begin with asterisk, '*', are copied to output. These are comment lines for genhis and xyplo. columnp: parameters: one line containing one integer: which column to extract output: messages to the user description The column program allows one to extract columns from a dataset. Lines in input that start with '*' are simply copied to the output. examples documentation see also {Programs that use the same column conventions:} xyplo.p genhis.p author Thomas Dana Schneider bugs technical notes */ /* end module describe.column */ Static _TEXT columnp; /* a file used by this program */ Static jmp_buf _JL1; /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } /* end module halt version = 4.11; (@ of prgmod.p 1991 Apr 22 */ /* begin module copyaline */ Static Void copyaline(fin, fout) _TEXT *fin, *fout; { /* copy a line from file fin to file fout */ while (!P_eoln(fin->f)) { putc(P_peek(fin->f), fout->f); getc(fin->f); } fscanf(fin->f, "%*[^\n]"); getc(fin->f); putc('\n', fout->f); } /* copyaline */ /* end module copyaline version = 4.11; (@ of prgmod.p 1991 Apr 22 */ /* begin module skipblanks */ Static Void skipblanks(thefile) _TEXT *thefile; { /* skip over blanks until a non-blank, or end of line, is found */ while ((P_peek(thefile->f) == ' ') & (!P_eoln(thefile->f))) getc(thefile->f); } Static Void skipnonblanks(thefile) _TEXT *thefile; { /* skip over nonblanks until a blank, or end of line, is found */ while ((P_peek(thefile->f) != ' ') & (!P_eoln(thefile->f))) getc(thefile->f); } /* end module skipblanks version = 4.11; (@ of prgmod.p 1991 Apr 22 */ /* begin module copynonblanks */ Static Void copynonblanks(infile, outfile) _TEXT *infile, *outfile; { /* copy nonblanks until a blank, or end of line, is found */ skipblanks(infile); while ((P_peek(infile->f) != ' ') & (!P_eoln(infile->f))) { putc(P_peek(infile->f), outfile->f); getc(infile->f); } } /* end module copynonblanks */ /* begin module column.themain */ Static Void themain(fin, columnp, fout) _TEXT *fin, *columnp, *fout; { /* the main procedure of the program */ long c; /* current column */ long whichone; /* desired column */ /* writeln(output,'column ',version:4:2); */ if (*columnp->name != '\0') { if (columnp->f != NULL) columnp->f = freopen(columnp->name, "r", columnp->f); else columnp->f = fopen(columnp->name, "r"); } else rewind(columnp->f); if (columnp->f == NULL) _EscIO2(FileNotFound, columnp->name); RESETBUF(columnp->f, Char); fscanf(columnp->f, "%ld%*[^\n]", &whichone); getc(columnp->f); /* (* it's not a good idea to reset the input file! *) reset(fin); (* it's not a good idea to rewrite the output file! *) rewrite(fout); */ while (!BUFEOF(fin->f)) { if (P_peek(fin->f) == '*') { copyaline(fin, fout); continue; } c = 1; skipblanks(fin); while (c < whichone) { skipnonblanks(fin); skipblanks(fin); c++; } /* if the program does multiple columns later, this will be needed: write(fout,' '); */ copynonblanks(fin, fout); putc('\n', fout->f); fscanf(fin->f, "%*[^\n]"); getc(fin->f); } } /* end module column.themain */ main(argc, argv) int argc; Char *argv[]; { _TEXT TEMP, TEMP1; PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; columnp.f = NULL; strcpy(columnp.name, "columnp"); TEMP.f = stdin; *TEMP.name = '\0'; TEMP1.f = stdout; *TEMP1.name = '\0'; themain(&TEMP, &columnp, &TEMP1); _L1: if (columnp.f != NULL) fclose(columnp.f); exit(EXIT_SUCCESS); } /* End. */