Mercurial > hg > index.cgi
comparison lwar/extract.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 | 6f4c4d59666f |
children |
comparison
equal
deleted
inserted
replaced
426:b4825b42c151 | 427:45df37e81741 |
---|---|
28 | 28 |
29 void do_extract(void) | 29 void do_extract(void) |
30 { | 30 { |
31 FILE *f; | 31 FILE *f; |
32 char buf[8]; | 32 char buf[8]; |
33 char *filename; | |
33 long l; | 34 long l; |
34 int c; | 35 int c; |
35 char fnbuf[1024]; | 36 char fnbuf[1024]; |
36 int i; | 37 int i; |
37 FILE *nf; | 38 FILE *nf; |
76 fprintf(stderr, "Bad archive file\n"); | 77 fprintf(stderr, "Bad archive file\n"); |
77 exit(1); | 78 exit(1); |
78 } | 79 } |
79 } | 80 } |
80 fnbuf[i] = 0; | 81 fnbuf[i] = 0; |
82 filename = get_file_name(fnbuf); | |
81 | 83 |
82 // get length of archive member | 84 // get length of archive member |
83 l = 0; | 85 l = 0; |
84 c = fgetc(f); | 86 c = fgetc(f); |
85 l = c << 24; | 87 l = c << 24; |
90 c = fgetc(f); | 92 c = fgetc(f); |
91 l |= c; | 93 l |= c; |
92 | 94 |
93 for (i = 0; i < nfiles; i++) | 95 for (i = 0; i < nfiles; i++) |
94 { | 96 { |
95 if (!strcmp(files[i], fnbuf)) | 97 if (!strcmp(get_file_name(files[i]), filename)) |
96 break; | 98 break; |
97 } | 99 } |
98 if (i < nfiles || nfiles == 0) | 100 if (i < nfiles || nfiles == 0) |
99 { | 101 { |
100 // extract the file | 102 // extract the file |
101 nf = fopen(fnbuf, "wb"); | 103 nf = fopen(filename, "wb"); |
102 if (!nf) | 104 if (!nf) |
103 { | 105 { |
104 fprintf(stderr, "Cannot extract '%s': %s\n", fnbuf, strerror(errno)); | 106 fprintf(stderr, "Cannot extract '%s': %s\n", filename, strerror(errno)); |
105 exit(1); | 107 exit(1); |
106 } | 108 } |
107 while (l) | 109 while (l) |
108 { | 110 { |
109 c = fgetc(f); | 111 c = fgetc(f); |