Annotation of 42BSD/ucb/lisp/utils/append.c, revision 1.1.1.1

1.1       root        1: static char *rcsid =
                      2:   "$Header: /na/franz/doc/RCS/append.c,v 1.1 83/01/31 07:14:03 jkf Exp $";
                      3:   
                      4: /*
                      5:  * append:  append a tail to a list of roots or prepend a head to a list
                      6:  *         of tails. 
                      7:  * use:
                      8:  *     append tail root1 root2 ... rootn
                      9:  * result:
                     10:  *     root1tail root2tail ... rootntail
                     11:  * or
                     12:  *     append -p root tail1 tail2 ... tailn
                     13:  *  result:
                     14:  *     roottail1 roottail2 ... roottailn
                     15:  *
                     16:  * or
                     17:  *     append -s xtail root1xoldt root2xoldt ...
                     18:  *  result:
                     19:  *     root1xtail  root2xtail ...
                     20:  *   that is, each root is tested for the presence of 'x', the first character
                     21:  *   in the tail.  If it is present, then all characters beyond it are thrown
                     22:  *   away before merging.  This is useful for things like
                     23:  *     append -s .c foo.o bar.o baz.o =>> foo.c bar.c baz.c
                     24:  *
                     25:  * Useful in Makefiles due to the lack of such facilities in make.
                     26:  * 
                     27: */
                     28: #include <stdio.h>
                     29: 
                     30: char buffer[2000];     /* nice and big */
                     31: char *rindex();
                     32: 
                     33:  main(argc,argv)
                     34:  char **argv;
                     35:  {
                     36:      int i, base;
                     37:      int prepend = 0,
                     38:          append = 0,
                     39:         strip = 0;
                     40:      char stripchar;
                     41:      char *chp;
                     42:      
                     43:      if(argc <= 2)
                     44:      {
                     45:         fprintf(stderr,"use: append tail root1 root2 ... rootn\n");
                     46:         exit(1);
                     47:      }
                     48:      if(argv[1][0] == '-')
                     49:      {
                     50:         switch(argv[1][1])
                     51:         {
                     52:             case 'p' : prepend = 1;
                     53:                        break;
                     54:             case 's' : strip = 1;
                     55:                        append = 1;
                     56:                        stripchar = argv[2][0]; /* first char of tail */
                     57:                        break;
                     58:             default:  fprintf(stderr,"append: illegal switch %s\n",argv[1]);
                     59:                        exit(1);
                     60:         }
                     61:         base = 2;
                     62:      }
                     63:      else {
                     64:         append = 1;
                     65:         base = 1;
                     66:      }
                     67:      
                     68:      for(i = base +1; i < argc ; i++)
                     69:      {
                     70:         if(append)
                     71:         {
                     72:            strcpy(buffer,argv[i]);
                     73:            if(strip && (chp = rindex(buffer,stripchar)))
                     74:            {
                     75:                *chp = '\0';
                     76:            }
                     77:            strcat(buffer,argv[base]);
                     78:         }
                     79:         else {
                     80:             strcpy(buffer,argv[base]);
                     81:             strcat(buffer,argv[i]);
                     82:         }
                     83:         printf("%s ",buffer);
                     84:      }
                     85:      printf("\n");
                     86:      exit(0);
                     87:  }
                     88:  

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.