aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ar.c34
-rw-r--r--archival/ar.c34
2 files changed, 30 insertions, 38 deletions
diff --git a/ar.c b/ar.c
index 41750ac7c..5803ad1a7 100644
--- a/ar.c
+++ b/ar.c
@@ -43,6 +43,7 @@
43#define DISPLAY 4 /* display contents */ 43#define DISPLAY 4 /* display contents */
44#define EXT_TO_FILE 8 /* extract contents of archive */ 44#define EXT_TO_FILE 8 /* extract contents of archive */
45#define EXT_TO_STDOUT 16 /* extract to stdout */ 45#define EXT_TO_STDOUT 16 /* extract to stdout */
46#define RECURSIVE 32
46 47
47#define MAX_NAME_LENGTH 100 48#define MAX_NAME_LENGTH 100
48 49
@@ -168,34 +169,26 @@ static int readArEntry(int srcFd, headerL_t *newEntry)
168/* 169/*
169 * return the headerL_t struct for the specified filename 170 * return the headerL_t struct for the specified filename
170 */ 171 */
171static headerL_t *getHeaders(int srcFd, headerL_t *head) 172static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
172{ 173{
173 int arEntry=FALSE;
174 headerL_t *list; 174 headerL_t *list;
175 list = (headerL_t *) malloc(sizeof(headerL_t)); 175 list = (headerL_t *) malloc(sizeof(headerL_t));
176 176
177 if (checkArMagic(srcFd)==TRUE) 177 if (checkArMagic(srcFd)==TRUE) {
178 arEntry=TRUE; 178 printf("found ar header ");
179 else
180 errorMsg("isnt an ar archive\n");
181
182 if (arEntry==TRUE) {
183 while(readArEntry(srcFd, list) == TRUE) { 179 while(readArEntry(srcFd, list) == TRUE) {
184 list->next = (headerL_t *) malloc(sizeof(headerL_t)); 180 list->next = (headerL_t *) malloc(sizeof(headerL_t));
185 *list->next = *head; 181 *list->next = *head;
186 *head = *list; 182 *head = *list;
187 183
188 /* recursive check for sub-archives */ 184 /* recursive check for sub-archives */
189 lseek(srcFd, list->size, SEEK_CUR); 185 if ((funct & RECURSIVE) == RECURSIVE)
190/* printf("checking for sub headers\n"); 186 head = getHeaders(srcFd, head, funct);
191 if ((subList = getHeaders(srcFd, list->next)) != NULL) { 187 lseek(srcFd, head->offset + head->size, SEEK_SET);
192 printf("found a sub archive !\n");
193 }
194 else
195 printf("didnt find a sub header\n"); */
196 } 188 }
197 } 189 }
198 190 else
191 printf("not an ar header\n");
199 return(head); 192 return(head);
200} 193}
201 194
@@ -239,7 +232,7 @@ extern int ar_main(int argc, char **argv)
239 int srcFd=0, dstFd=0; 232 int srcFd=0, dstFd=0;
240 headerL_t *header, *entry, *extractList; 233 headerL_t *header, *entry, *extractList;
241 234
242 while ((opt = getopt(argc, argv, "ovtpx")) != -1) { 235 while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
243 switch (opt) { 236 switch (opt) {
244 case 'o': 237 case 'o':
245 funct = funct | PRESERVE_DATE; 238 funct = funct | PRESERVE_DATE;
@@ -256,6 +249,9 @@ extern int ar_main(int argc, char **argv)
256 case 'p': 249 case 'p':
257 funct = funct | EXT_TO_STDOUT; 250 funct = funct | EXT_TO_STDOUT;
258 break; 251 break;
252 case 'R':
253 funct = funct | RECURSIVE;
254 break;
259 default: 255 default:
260 usage(ar_usage); 256 usage(ar_usage);
261 } 257 }
@@ -276,7 +272,7 @@ extern int ar_main(int argc, char **argv)
276 header = (headerL_t *) malloc(sizeof(headerL_t)); 272 header = (headerL_t *) malloc(sizeof(headerL_t));
277 extractList = (headerL_t *) malloc(sizeof(headerL_t)); 273 extractList = (headerL_t *) malloc(sizeof(headerL_t));
278 274
279 header = getHeaders(srcFd, header); 275 header = getHeaders(srcFd, header, funct);
280 276
281 /* find files to extract or display */ 277 /* find files to extract or display */
282 if (optind<argc) { 278 if (optind<argc) {
diff --git a/archival/ar.c b/archival/ar.c
index 41750ac7c..5803ad1a7 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -43,6 +43,7 @@
43#define DISPLAY 4 /* display contents */ 43#define DISPLAY 4 /* display contents */
44#define EXT_TO_FILE 8 /* extract contents of archive */ 44#define EXT_TO_FILE 8 /* extract contents of archive */
45#define EXT_TO_STDOUT 16 /* extract to stdout */ 45#define EXT_TO_STDOUT 16 /* extract to stdout */
46#define RECURSIVE 32
46 47
47#define MAX_NAME_LENGTH 100 48#define MAX_NAME_LENGTH 100
48 49
@@ -168,34 +169,26 @@ static int readArEntry(int srcFd, headerL_t *newEntry)
168/* 169/*
169 * return the headerL_t struct for the specified filename 170 * return the headerL_t struct for the specified filename
170 */ 171 */
171static headerL_t *getHeaders(int srcFd, headerL_t *head) 172static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
172{ 173{
173 int arEntry=FALSE;
174 headerL_t *list; 174 headerL_t *list;
175 list = (headerL_t *) malloc(sizeof(headerL_t)); 175 list = (headerL_t *) malloc(sizeof(headerL_t));
176 176
177 if (checkArMagic(srcFd)==TRUE) 177 if (checkArMagic(srcFd)==TRUE) {
178 arEntry=TRUE; 178 printf("found ar header ");
179 else
180 errorMsg("isnt an ar archive\n");
181
182 if (arEntry==TRUE) {
183 while(readArEntry(srcFd, list) == TRUE) { 179 while(readArEntry(srcFd, list) == TRUE) {
184 list->next = (headerL_t *) malloc(sizeof(headerL_t)); 180 list->next = (headerL_t *) malloc(sizeof(headerL_t));
185 *list->next = *head; 181 *list->next = *head;
186 *head = *list; 182 *head = *list;
187 183
188 /* recursive check for sub-archives */ 184 /* recursive check for sub-archives */
189 lseek(srcFd, list->size, SEEK_CUR); 185 if ((funct & RECURSIVE) == RECURSIVE)
190/* printf("checking for sub headers\n"); 186 head = getHeaders(srcFd, head, funct);
191 if ((subList = getHeaders(srcFd, list->next)) != NULL) { 187 lseek(srcFd, head->offset + head->size, SEEK_SET);
192 printf("found a sub archive !\n");
193 }
194 else
195 printf("didnt find a sub header\n"); */
196 } 188 }
197 } 189 }
198 190 else
191 printf("not an ar header\n");
199 return(head); 192 return(head);
200} 193}
201 194
@@ -239,7 +232,7 @@ extern int ar_main(int argc, char **argv)
239 int srcFd=0, dstFd=0; 232 int srcFd=0, dstFd=0;
240 headerL_t *header, *entry, *extractList; 233 headerL_t *header, *entry, *extractList;
241 234
242 while ((opt = getopt(argc, argv, "ovtpx")) != -1) { 235 while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
243 switch (opt) { 236 switch (opt) {
244 case 'o': 237 case 'o':
245 funct = funct | PRESERVE_DATE; 238 funct = funct | PRESERVE_DATE;
@@ -256,6 +249,9 @@ extern int ar_main(int argc, char **argv)
256 case 'p': 249 case 'p':
257 funct = funct | EXT_TO_STDOUT; 250 funct = funct | EXT_TO_STDOUT;
258 break; 251 break;
252 case 'R':
253 funct = funct | RECURSIVE;
254 break;
259 default: 255 default:
260 usage(ar_usage); 256 usage(ar_usage);
261 } 257 }
@@ -276,7 +272,7 @@ extern int ar_main(int argc, char **argv)
276 header = (headerL_t *) malloc(sizeof(headerL_t)); 272 header = (headerL_t *) malloc(sizeof(headerL_t));
277 extractList = (headerL_t *) malloc(sizeof(headerL_t)); 273 extractList = (headerL_t *) malloc(sizeof(headerL_t));
278 274
279 header = getHeaders(srcFd, header); 275 header = getHeaders(srcFd, header, funct);
280 276
281 /* find files to extract or display */ 277 /* find files to extract or display */
282 if (optind<argc) { 278 if (optind<argc) {