/* ///////////////////////////////////////////////////////////////////////// // // // top.c - display first few lines of text file // // ver 1.1 // // manual and maintenance page // // // // Language: Borland C, ver 3.0 // // Platform: Gateway 386/25, win95.400 // // Application: CSE784 demonstration // // Author: Jim Fawcett, 123 Link Hall, Syracuse University // // (315) 443-2654, jfawcett@cat.syr.edu // // // ///////////////////////////////////////////////////////////////////////// // // // Program Operations: // // =================== // // This is a simple demonstration of how modules are constructed // // and used to partition a program. // // // // This program displays the first few lines of a text file. It // // uses the services of module lines for building lines of text from // // files or by copying other lines. It also uses the services of // // module open to attach files for reading. // // // // Program will expand wildcards in filenames on command line if // // linked with wildargs.obj (see below). // // // ///////////////////////////////////////////////////////////////////////// // // // Build Process // // // // Files Required: // // top.c, open.h, open.c, lines.h, lines.c, // // borlandc\lib\wildargs.obj // // // // Integrated Environment: // // - open project citing all *.c files above and citing // // z:\turbos\wildargs.obj // // - select Options\Compiler\Code generation\defines // // clear defines // // - run // // // // Command Line Environment: // // tcc -w+ top.c open.c lines.c z:\turbos\wildargs.obj // // // ///////////////////////////////////////////////////////////////////////// Maintenance History: ver 1.1 : 31 Mar 97 - added expand option ver 1.0 : 05 Sep 96 - first release */ /* */ /* /////////////////////////////////////////////////////////////// // // // definitions // // // /////////////////////////////////////////////////////////////// */ #include /* free() */ #include /* fprintf() */ #include /* isalpha() */ #include /* strlen() */ #include "open.h" /* getRStream(char*), getWStream(char*) */ #include "lines.h" /* getLine(fptr) */ static int expand = 0; /* send ff to output? */ /*----< display first few lines of file >---------------------- Processing: - read numLines lines from input stream in - display on stdout Inputs: - numLines is the number of lines to be displayed - input FILE stream in Outputs: - numLines lines sent to stdout */ void display(int numLines, FILE *in) { int i; char *line=0; for(i=0; i 75) line[75] = '\0'; fprintf(stdout, "%s\n", line); free(line); } fprintf(stdout, "\n"); } /* */ /*----< parse command line, open files, display top lines >---- Processing: - process commands to set number of lines displayed - open files cited on command line and display Inputs: - argc is the number of arguments on command line - argv is an array of pointers to command line arguments Outputs: - displays top lines for each existing file cited on command line */ void main(int argc, char *argv[]) { FILE *in=0; int files=0, i; int numLines = 10; /* default display size */ /* parse command line and open named files */ for(i=1; i