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

1.1       root        1: static char *rcsid =
                      2:   "$Header: append.c,v 1.2 84/01/22 04:07:25 sklower 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: #include "lconf.h"
                     30: #include "config.h"
                     31: #if os_unix_ts || os_masscomp
                     32: #define rindex strrchr
                     33: #endif
                     34: 
                     35: char buffer[2000];     /* nice and big */
                     36: char *rindex();
                     37: 
                     38:  main(argc,argv)
                     39:  char **argv;
                     40:  {
                     41:      int i, base;
                     42:      int prepend = 0,
                     43:          append = 0,
                     44:         strip = 0;
                     45:      char stripchar;
                     46:      char *chp;
                     47:      
                     48:      if(argc <= 2)
                     49:      {
                     50:         fprintf(stderr,"use: append tail root1 root2 ... rootn\n");
                     51:         exit(1);
                     52:      }
                     53:      if(argv[1][0] == '-')
                     54:      {
                     55:         switch(argv[1][1])
                     56:         {
                     57:             case 'p' : prepend = 1;
                     58:                        break;
                     59:             case 's' : strip = 1;
                     60:                        append = 1;
                     61:                        stripchar = argv[2][0]; /* first char of tail */
                     62:                        break;
                     63:             default:  fprintf(stderr,"append: illegal switch %s\n",argv[1]);
                     64:                        exit(1);
                     65:         }
                     66:         base = 2;
                     67:      }
                     68:      else {
                     69:         append = 1;
                     70:         base = 1;
                     71:      }
                     72:      
                     73:      for(i = base +1; i < argc ; i++)
                     74:      {
                     75:         if(append)
                     76:         {
                     77:            strcpy(buffer,argv[i]);
                     78:            if(strip && (chp = rindex(buffer,stripchar)))
                     79:            {
                     80:                *chp = '\0';
                     81:            }
                     82:            strcat(buffer,argv[base]);
                     83:         }
                     84:         else {
                     85:             strcpy(buffer,argv[base]);
                     86:             strcat(buffer,argv[i]);
                     87:         }
                     88:         printf("%s ",buffer);
                     89:      }
                     90:      printf("\n");
                     91:      exit(0);
                     92:  }
                     93:  

unix.superglobalmegacorp.com

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