home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol228 / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-13  |  1.6 KB  |  122 lines

  1.  
  2.  
  3. /*
  4. **    list.c
  5. **
  6. **    for public domain use only      by Mark Ellington
  7. **
  8. **   
  9. **    This program accepts filenames as arguments from the command line
  10. **    and prints the file contents to the LST: device.  You can list
  11. **    as many files as will fit on the command line, one file after
  12. **    another.
  13. **
  14. **
  15. */
  16.  
  17.  
  18.  
  19. #define ASCIEOF -1
  20. #define NULL 0
  21.  
  22.  
  23. char linbuf[130];
  24. int *inptr, *outptr;
  25.  
  26. /* files to LST: line at a time */
  27.  
  28. main(argc,argv)
  29. char *argv[];
  30. {
  31. int n;
  32.     
  33.     n = 0;    
  34.     while(n < argc) {
  35.  
  36.     ++n;
  37.     inptr = fopen(argv[n],"r");
  38.     if (!inptr) {
  39.         puts(argv[n]);
  40.         puts(" finished or error opening input file\n");
  41.         exit();
  42.     }
  43.  
  44.     outptr = fopen("LST:","w");
  45.     if (!outptr) {
  46.         puts("error opening list device\n");
  47.         exit();
  48.     }
  49.  
  50.         /* list filename */
  51.  
  52.     puts("\nListing file:  "); 
  53.     fputs("\nListing file:  ",outptr);
  54.     puts(argv[n]);
  55.     fputs(argv[n],outptr);
  56.     puts("\n\n");
  57.     fputs("\n\n",outptr);
  58.     
  59.     /* file to lst line at a time */
  60.     
  61.     while (fgets(linbuf,inptr)) {
  62.         puts(linbuf);
  63.         fputs(linbuf,outptr);
  64.     }
  65.     
  66.     fclose(inptr);
  67.     
  68.     /* ff */
  69.  
  70.     putc(12,outptr);    
  71.     putc(0,outptr);
  72.     
  73.  
  74.     }    /* while until all args read */
  75.  
  76. }
  77.  
  78.  
  79.  
  80. /* read string of input from a file */
  81.  
  82. fgets(ptr,infile)
  83. char *ptr;
  84. int infile;
  85. {
  86.     int n,c;
  87.     char *cs;
  88.  
  89.     n = 120;   /* max length */
  90.     cs = ptr;
  91.     while ( (--n > 0) && ((c = getc(infile)) != ASCIEOF) )
  92.         if ((*cs++ = c) == '\n') break;
  93.     *cs = '\0';    
  94.     return((c == ASCIEOF && cs == ptr) ? NULL : ptr);
  95. }
  96.  
  97.         
  98. /* send string to console and list device */
  99.  
  100. fputs(s,outfile)
  101. char *s;
  102. {
  103.     while (*s) 
  104.         putc(*s++,outfile);
  105. }
  106.         
  107.  
  108. /* send string to console */
  109.  
  110. puts(s)
  111. char *s;
  112. {
  113.     while (*s) 
  114.         putchar(*s++);
  115. }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.