Mercurial > hg > index.cgi
comparison lwar/replace.c @ 427:45df37e81741
Add option to ignore paths when extracting or adding files with lwar
Add option to lwar to strip path names from filenames when objects are added
to an archive. Also strip path names from objects when extracting them, if
present.
author | David Flamand <dlflamand@gmail.com> |
---|---|
date | Tue, 15 Nov 2016 21:43:33 -0700 |
parents | 221b5f58d8ad |
children | 6df8d62302e2 |
comparison
equal
deleted
inserted
replaced
426:b4825b42c151 | 427:45df37e81741 |
---|---|
35 void do_replace(void) | 35 void do_replace(void) |
36 { | 36 { |
37 FILE *f; | 37 FILE *f; |
38 FILE *nf; | 38 FILE *nf; |
39 unsigned char buf[8]; | 39 unsigned char buf[8]; |
40 char *filename; | |
40 long l; | 41 long l; |
41 int c; | 42 int c; |
42 FILE *f2; | 43 FILE *f2; |
43 int i; | 44 int i; |
44 char fnbuf[1024]; | 45 char fnbuf[1024]; |
104 fprintf(stderr, "Bad archive file\n"); | 105 fprintf(stderr, "Bad archive file\n"); |
105 exit(1); | 106 exit(1); |
106 } | 107 } |
107 } | 108 } |
108 fnbuf2[i] = 0; | 109 fnbuf2[i] = 0; |
110 filename = get_file_name(fnbuf2); | |
109 | 111 |
110 // get length of archive member | 112 // get length of archive member |
111 l = 0; | 113 l = 0; |
112 c = fgetc(f); | 114 c = fgetc(f); |
113 l = c << 24; | 115 l = c << 24; |
119 l |= c; | 121 l |= c; |
120 | 122 |
121 // is it a file we are replacing? if so, do not copy it | 123 // is it a file we are replacing? if so, do not copy it |
122 for (i = 0; i < nfiles; i++) | 124 for (i = 0; i < nfiles; i++) |
123 { | 125 { |
124 if (!strcmp(files[i], fnbuf2)) | 126 if (!strcmp(get_file_name(files[i]), filename)) |
125 break; | 127 break; |
126 } | 128 } |
127 if (i < nfiles) | 129 if (i < nfiles) |
128 { | 130 { |
129 fseek(f, l, SEEK_CUR); | 131 fseek(f, l, SEEK_CUR); |
130 } | 132 } |
131 else | 133 else |
132 { | 134 { |
133 // otherwise, copy it | 135 // otherwise, copy it |
134 fprintf(nf, "%s", fnbuf2); | 136 fprintf(nf, "%s", filename); |
135 fputc(0, nf); | 137 fputc(0, nf); |
136 fputc(l >> 24, nf); | 138 fputc(l >> 24, nf); |
137 fputc((l >> 16) & 0xff, nf); | 139 fputc((l >> 16) & 0xff, nf); |
138 fputc((l >> 8) & 0xff, nf); | 140 fputc((l >> 8) & 0xff, nf); |
139 fputc(l & 0xff, nf); | 141 fputc(l & 0xff, nf); |
149 // done with the original file | 151 // done with the original file |
150 fclose(f); | 152 fclose(f); |
151 doadd: | 153 doadd: |
152 for (i = 0; i < nfiles; i++) | 154 for (i = 0; i < nfiles; i++) |
153 { | 155 { |
154 f2 = fopen(files[i], "rb"); | 156 filename = get_file_name(files[i]); |
157 f2 = fopen(filename, "rb"); | |
155 if (!f2) | 158 if (!f2) |
156 { | 159 { |
157 fprintf(stderr, "Cannot open file %s:", files[i]); | 160 fprintf(stderr, "Cannot open file %s:", filename); |
158 perror(""); | 161 perror(""); |
159 exit(1); | 162 exit(1); |
160 } | 163 } |
161 (void)(fread(buf, 1, 6, f2) && 1); | 164 (void)(fread(buf, 1, 6, f2) && 1); |
162 if (mergeflag && !memcmp("LWAR1V", buf, 6)) | 165 if (mergeflag && !memcmp("LWAR1V", buf, 6)) |
218 continue; | 221 continue; |
219 } | 222 } |
220 fseek(f2, 0, SEEK_END); | 223 fseek(f2, 0, SEEK_END); |
221 l = ftell(f2); | 224 l = ftell(f2); |
222 fseek(f2, 0, SEEK_SET); | 225 fseek(f2, 0, SEEK_SET); |
223 fputs(files[i], nf); | 226 fputs(filename, nf); |
224 fputc(0, nf); | 227 fputc(0, nf); |
225 fputc(l >> 24, nf); | 228 fputc(l >> 24, nf); |
226 fputc((l >> 16) & 0xff, nf); | 229 fputc((l >> 16) & 0xff, nf); |
227 fputc((l >> 8) & 0xff, nf); | 230 fputc((l >> 8) & 0xff, nf); |
228 fputc(l & 0xff, nf); | 231 fputc(l & 0xff, nf); |