///////////////////////////////////////////////////////////////////////// // // // top.c - display first few lines of text file // // ver 1.2 // // // // Language: Visual C++, ver 6.0 // // Platform: Micron dual Pentium Pro 200, Win NT 4.0, SP 3.0 // // Application: CSE784 demonstration // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, fawcett@ecs.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, // // // // Integrated Environment: // // - open project citing all *.c files above // // - add setargv.obj to Object/Modules: edit box in // // Project/Settings/Link // // - enter *.h *.c* in Program Arguments edit box in // // Project/Settings/Debug // // - compile, link, and run // // // // Command Line Environment: // // cl /GX top.c open.c lines.c setargv.obj // // // ///////////////////////////////////////////////////////////////////////// /* Maintenance History: ver 1.2 : 15 Jan 00 - cosmetic changes to these comments 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