home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 195_01 / unique.c < prev    next >
Text File  |  1987-10-05  |  2KB  |  81 lines

  1. /* [UNIQUE.C of JUGPDS Vol.16]
  2. *****************************************************************
  3. *                                *
  4. *    Written by  Hakuo Katayose (JUG-CP/M No.179)        *
  5. *            49-114 Kawauchi-Sanjuunin-machi        *
  6. *            Sendai, Miyagi 980                          *
  7. *            Phone: 0222-61-3219                *
  8. *                                *
  9. *    Edited & tested by Y. Monma (JUG-C/M Disk Editor)       * 
  10. *                                *
  11. *****************************************************************
  12. */
  13.  
  14. /* unique - strip adjacent duplicate lines */
  15.  
  16. #include <stdio.h>
  17. #include <dio.h>
  18. #include <def.h>
  19.  
  20. #define LINES 10000
  21.  
  22. char    opt_d;        /* dictionary order */
  23. char    opt_f;        /* fold order        */
  24. char    opt_n;        /* counter option   */
  25.  
  26. main(argc, argv)
  27. char    **argv;
  28. {
  29.     char    buf1[MAXLINE], buf2[MAXLINE];
  30.     int    i, len;
  31.     unsigned wcount;
  32.     char *ap, sub[8][16];
  33.  
  34.     dioinit(&argc,argv);
  35.     opt_d = opt_f = opt_n = OFF;
  36.     i = 0;
  37.     while(--argc > 0)
  38.         if ( (*++argv)[0] == '-')
  39.             for (ap = argv[0]+1; *ap != '\0'; ap++)
  40.                 switch( toupper(*ap) ) {
  41.                 case 'D':
  42.                     opt_d = ON;
  43.                     break;
  44.                 case 'F':
  45.                     opt_f = ON;
  46.                     break;
  47.                 case 'N':
  48.                     opt_n = ON;
  49.                     break;
  50.                 }
  51.         else
  52.             strcpy(sub[i++], *argv);
  53.     len = getlin(buf2, MAXLINE);
  54.     while( len > 0 ) {
  55.         strcpy(buf1, buf2);
  56.         wcount = 1;
  57.         while( (len = getlin(buf2, MAXLINE)) > 0 ) {
  58.             if( opt_d == ON && opt_f == ON ) {
  59.                 if (strdfcmp( buf1, buf2) != 0)
  60.                     break;
  61.                 }
  62.             else if( opt_d == ON ) {
  63.                 if (strdcmp( buf1, buf2) != 0)
  64.                     break;
  65.                 }
  66.             else if( opt_f == ON ) {
  67.                 if (strfcmp( buf1, buf2) != 0)
  68.                     break;
  69.                 }
  70.             else if (strcmp( buf1, buf2) != 0)
  71.                     break;
  72.             wcount++;
  73.             }
  74.         if( opt_n == ON )
  75.             printf( "%6d: %s", wcount, buf1);
  76.         else
  77.             printf( "%s", buf1 );
  78.         }
  79.     dioflush();
  80. }
  81.