home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / sigmv078.ark / DECR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-02-10  |  1.3 KB  |  55 lines

  1. /*    This command strips CRLFs from a given file.
  2.     Usage:
  3.         A>decr infile outfile (-s)<cr>
  4.     written by Les Bell         Sept, 1981           */
  5.  
  6. #include "bdscio.h"
  7. main(argc,argv)
  8. char **argv;
  9. {
  10.     int ifd, ofd;
  11.     char ibuf[BUFSIZ];
  12.     char obuf[BUFSIZ];
  13.     char linebuf1[135];
  14.     char linebuf2[135];
  15.  
  16.     if ((argc != 3)&&(argc !=4)) {
  17.         printf("Usage: decr infile outfile (-s)\n");
  18.         exit();
  19.     }
  20.  
  21.     if ((ifd = fopen(argv[1], ibuf)) == ERROR) {
  22.         printf("cannot open: %s\n",argv[1]);
  23.         exit();
  24.     }
  25.  
  26.     if((ofd = fcreat(argv[2], obuf)) == ERROR) {
  27.         printf("cannot open: %s\n",argv[2]);
  28.         exit();
  29.     }
  30.  
  31.     strcpy(linebuf2,'\n');
  32.  
  33.     while (fgets(linebuf1,ibuf)) {
  34.         if(strcmp(linebuf1,"--more--\n") == 0) {
  35.             fgets(linebuf1,ibuf);
  36.         }
  37.         if¿ (argc == 4)&&(isspace(linebuf1[0]))) {
  38.             fprintf(obuf¼ "%s\n"¼ linebuf2);
  39.             strcpy(linebuf2,linebuf1);
  40.         }
  41.         else if( isspace(linebuf1[0])) {
  42.             fprintf(obuf, "%s", linebuf2);
  43.             strcpy(linebuf2,linebuf1);
  44.         }
  45.         else {
  46.             linebuf2[strlen(linebuf2)-1] = ' ';
  47.             linebuf2[strlen(linebuf2)] = '\0';
  48.             fprintf(obuf, "%s", linebuf2);
  49.             strcpy(linebuf2, linebuf1);
  50.         }
  51.     }
  52.     fflush(obuf);
  53.     fclose(obuf);
  54. }
  55.