home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / ut-c.lbr / VSPLIT.CZ / VSPLIT.C
Encoding:
C/C++ Source or Header  |  1993-10-25  |  2.5 KB  |  89 lines

  1. /* vsplit.c -- UTOOL. Vertically split a text file.
  2.  
  3.      author: David H. Wolen
  4.      last change: 2/20/83
  5.  
  6.      usage:    vsplit cc col
  7.  
  8.                vsplit ll 80   (output first 80 cols of each line)
  9.                vsplit lr 10   (delete first 10 cols, output rest)
  10.                vsplit rl 10   (delete last 10 cols, output rest)
  11.                vsplit rr 15   (output last 15 cols)
  12.  
  13.      options:  ll   split from left, output left part
  14.                lr   split from left, output right part
  15.                rl   split from right, output left part
  16.                rr   split from right, output right part
  17.  
  18.      input:    STDIN
  19.      output:   STDOUT
  20.  
  21.      notes:    1. If input line contains only <cr><lf>, so will output
  22.                2. If ll and col > line length, output will be whole line
  23.                3. If lr and col > line length, output will be <cr><lf>
  24.                4. If ll and col <= 0, output will be <cr><lf>
  25.                5. If lr and col <= 0, output will be whole line
  26.                6. If rl and col > line length, output will be <cr><lf>
  27.                7. If rr and col > line length, output will be whole line
  28.                8. If rl and col <= 0, output will be whole line
  29.                9. If rr and col <= 0, output will be <cr><lf>
  30.  
  31.      linkage:  a:clink vsplit spltscan -f dio -ca (uses deff3.crl)
  32. */
  33.  
  34. #include "a:bdscio.h"
  35. #include "dio.h"
  36.  
  37. #define  STDIN  0
  38. #define  STDOUT 1
  39.  
  40. main(argc,argv)
  41. int  argc;
  42. char *argv[];
  43. {
  44.      int  leftsplt, leftout, col;
  45.      char line[MAXLINE], left[MAXLINE], right[MAXLINE];
  46.  
  47.      dioinit(&argc,argv);
  48.  
  49.      /* process options */
  50.  
  51.      if(argc < 3)
  52.           error("usage: vsplit option col");
  53.  
  54.      if(eqs(argv[1],"LL"))
  55.           leftsplt=leftout=TRUE;
  56.      else if(eqs(argv[1],"LR"))
  57.           {leftsplt=TRUE;
  58.           leftout=FALSE;
  59.           }
  60.      else if(eqs(argv[1],"RL"))
  61.           {leftsplt=FALSE;
  62.           leftout=TRUE;
  63.           }
  64.      else if(eqs(argv[1],"RR"))
  65.           leftsplt=leftout=FALSE;
  66.      else
  67.           error("vsplit: valid options are ll lr rl rr");
  68.  
  69.      col=atoi(argv[2]);
  70.  
  71.      /* main */
  72.  
  73.      while(fgets(line,STDIN))
  74.           {line[strlen(line)-1]='\0';   /* zap newline */
  75.  
  76.           if(leftsplt)
  77.                split(line,col,left,right);
  78.           else
  79.                splitr(line,col,left,right);
  80.  
  81.           if(leftout)
  82.                fprintf(STDOUT,"%s\n",left);
  83.           else
  84.                fprintf(STDOUT,"%s\n",right);
  85.           }
  86.  
  87.      dioflush();
  88. }
  89.