home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / shortc2 < prev    next >
Text File  |  1986-11-30  |  4KB  |  170 lines

  1. Newsgroups: mod.sources
  2. Subject: shortc: sed output, and standard input
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 50
  6. Submitted by: convex!smu!s100ms!marquez
  7.  
  8. I have put some hacks into the shortc program recently posted to mod.sources.
  9. First, shortc can now take input from a pipe,  as in:
  10.  
  11. cat *.h *.c | shortc -p > global.h
  12.  
  13. of course the same effect is gained by "shortc *.h *.c > global.h", but
  14. this allows for special applications.  I also added a -s option so that
  15. a sed command file can be created instead of an include file.  Remember,
  16. if the -s option is needed, then the -p option will probably be required
  17. too.
  18.  
  19. This submission is in the form of a context diff, suitable for "patch"ing
  20. the original.
  21.  
  22. manlio d marquez
  23. convex!smu!s100ms!marquez
  24.  
  25. ------- start of diffs -------------
  26. *** shortc.orig    Fri Apr  4 09:15:15 1986
  27. --- shortc.c    Fri Apr  4 09:15:35 1986
  28. ***************
  29. *** 14,17
  30.      they will cause (innocuous) redefinition messages.
  31.    */
  32.   
  33.   #include <ctype.h>
  34.  
  35. --- 14,20 -----
  36.      they will cause (innocuous) redefinition messages.
  37.    */
  38. + /*
  39. +    hacked by m.d. marquez to allow pipe into stdin and add -s (sed) option
  40. + */
  41.   
  42.   #include <ctype.h>
  43. ***************
  44. *** 45,48
  45.   int     symlen  = SYMLEN;
  46.   char    parsepp;            /* if set, parse preprocessor lines */
  47.   
  48.   symbol  *lookup();
  49.  
  50. --- 48,53 -----
  51.   int     symlen  = SYMLEN;
  52.   char    parsepp;            /* if set, parse preprocessor lines */
  53. + int    sedout = 0;        /* want sed output */
  54. + int    read_file = 0;        /* flag if read file arguments */
  55.   
  56.   symbol  *lookup();
  57. ***************
  58. *** 58,61
  59.           doarg(*++argv);
  60.   
  61.       dump();
  62.       exit(0);
  63.  
  64. --- 63,69 -----
  65.           doarg(*++argv);
  66.   
  67. +     if( !read_file )
  68. +         process();
  69.       dump();
  70.       exit(0);
  71. ***************
  72. *** 64,70
  73.   doarg (arg) char *arg; /*: process one file or flag arg */
  74.   {
  75. -     register char *s;
  76. -     register symbol *y;
  77.       if( *arg == '-' )
  78.       {   arg++;
  79.  
  80. --- 72,75 -----
  81.   doarg (arg) char *arg; /*: process one file or flag arg */
  82.   {
  83.       if( *arg == '-' )
  84.       {   arg++;
  85. ***************
  86. *** 73,76
  87.           else if( *arg == 'p' )
  88.           parsepp = 1;
  89.           else fputs(Usage, stderr);
  90.           return;
  91.  
  92. --- 78,83 -----
  93.           else if( *arg == 'p' )
  94.           parsepp = 1;
  95. +         else if( *arg == 's' )
  96. +         sedout = 1;
  97.           else fputs(Usage, stderr);
  98.           return;
  99. ***************
  100. *** 82,85
  101.       }
  102.   
  103.       while( s = token() )
  104.           if( (y = lookup(s))->flag < SEEN )
  105.  
  106. --- 89,102 -----
  107.       }
  108.   
  109. +     process();
  110. +     read_file++;
  111. + }
  112. + process()
  113. + {
  114. +     register char *s;
  115. +     register symbol *y;
  116.       while( s = token() )
  117.           if( (y = lookup(s))->flag < SEEN )
  118. ***************
  119. *** 177,180
  120.               break;
  121.           }
  122.           if( strcmp(y->inname, s) == 0 )
  123.               break;
  124.  
  125. --- 194,198 -----
  126.               break;
  127.           }
  128.           if( strcmp(y->inname, s) == 0 )
  129.               break;
  130. ***************
  131. *** 191,196
  132.       for( n = HASHSIZ; --n >= 0; )
  133.           for( y = symtab[n]; y; y = y->link )
  134. !         if( y->flag > SEEN )
  135. !             printf("#define %s %s%s\n", y->inname,
  136.                           y->prefix, y->inname);
  137.   }
  138.  
  139. --- 209,215 -----
  140.       for( n = HASHSIZ; --n >= 0; )
  141.           for( y = symtab[n]; y; y = y->link )
  142. !         if( y->flag > SEEN ) {
  143. !             if( sedout )
  144. !                 printf("/%s/s//%s%s/g\n", y->inname,
  145.                           y->prefix, y->inname);
  146.              else
  147. ***************
  148. *** 194,197
  149.               printf("#define %s %s%s\n", y->inname,
  150.                           y->prefix, y->inname);
  151.   }
  152.   
  153.  
  154. --- 213,220 -----
  155.                   printf("/%s/s//%s%s/g\n", y->inname,
  156.                           y->prefix, y->inname);
  157. +            else
  158. +                 printf("#define %s %s%s\n", y->inname,
  159. +                         y->prefix, y->inname);
  160. +         }
  161.   }
  162.   
  163. ----------- end of diffs -------------------
  164.