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