Simplify a few little things, and merge in a patch from
robotti@metconnect.com so that 'ar -xv' and 'ar -x -v' both work. -Erik
This commit is contained in:
parent
605a819a17
commit
49352adf9c
22
ar.c
22
ar.c
@ -181,7 +181,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
|
|||||||
*head = *list;
|
*head = *list;
|
||||||
|
|
||||||
/* recursive check for sub-archives */
|
/* recursive check for sub-archives */
|
||||||
if ((funct & RECURSIVE) == RECURSIVE)
|
if ( funct & RECURSIVE )
|
||||||
head = getHeaders(srcFd, head, funct);
|
head = getHeaders(srcFd, head, funct);
|
||||||
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ static headerL_t *findEntry(headerL_t *head, const char *filename)
|
|||||||
*/
|
*/
|
||||||
static int displayEntry(headerL_t *head, int funct)
|
static int displayEntry(headerL_t *head, int funct)
|
||||||
{
|
{
|
||||||
if ((funct & VERBOSE) == VERBOSE) {
|
if ( funct & VERBOSE ) {
|
||||||
printf("%s %d/%d %8d %s ", modeString(head->mode), head->uid, head->gid, head->size, timeString(head->mtime));
|
printf("%s %d/%d %8d %s ", modeString(head->mode), head->uid, head->gid, head->size, timeString(head->mtime));
|
||||||
}
|
}
|
||||||
printf("%s\n", head->name);
|
printf("%s\n", head->name);
|
||||||
@ -232,22 +232,22 @@ extern int ar_main(int argc, char **argv)
|
|||||||
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
|
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'o':
|
case 'o':
|
||||||
funct = funct | PRESERVE_DATE;
|
funct |= PRESERVE_DATE;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
funct = funct | VERBOSE;
|
funct |= VERBOSE;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
funct = funct | DISPLAY;
|
funct |= DISPLAY;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
funct = funct | EXT_TO_FILE;
|
funct |= EXT_TO_FILE;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
funct = funct | EXT_TO_STDOUT;
|
funct |= EXT_TO_STDOUT;
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
funct = funct | RECURSIVE;
|
funct |= RECURSIVE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(ar_usage);
|
usage(ar_usage);
|
||||||
@ -288,14 +288,14 @@ extern int ar_main(int argc, char **argv)
|
|||||||
extractList = header;
|
extractList = header;
|
||||||
|
|
||||||
while(extractList->next != NULL) {
|
while(extractList->next != NULL) {
|
||||||
if ( (funct & EXT_TO_FILE) == EXT_TO_FILE) {
|
if ( funct & EXT_TO_FILE ) {
|
||||||
dstFd = open(extractList->name, O_WRONLY | O_CREAT, extractList->mode);
|
dstFd = open(extractList->name, O_WRONLY | O_CREAT, extractList->mode);
|
||||||
|
|
||||||
extractAr(srcFd, dstFd, extractList);
|
extractAr(srcFd, dstFd, extractList);
|
||||||
}
|
}
|
||||||
if ( (funct & EXT_TO_STDOUT) == EXT_TO_STDOUT)
|
if ( funct & EXT_TO_STDOUT )
|
||||||
extractAr(srcFd, fileno(stdout), extractList);
|
extractAr(srcFd, fileno(stdout), extractList);
|
||||||
if ( (funct & DISPLAY) == DISPLAY)
|
if ( (funct & DISPLAY) || (funct & VERBOSE))
|
||||||
displayEntry(extractList, funct);
|
displayEntry(extractList, funct);
|
||||||
extractList=extractList->next;
|
extractList=extractList->next;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
|
|||||||
*head = *list;
|
*head = *list;
|
||||||
|
|
||||||
/* recursive check for sub-archives */
|
/* recursive check for sub-archives */
|
||||||
if ((funct & RECURSIVE) == RECURSIVE)
|
if ( funct & RECURSIVE )
|
||||||
head = getHeaders(srcFd, head, funct);
|
head = getHeaders(srcFd, head, funct);
|
||||||
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ static headerL_t *findEntry(headerL_t *head, const char *filename)
|
|||||||
*/
|
*/
|
||||||
static int displayEntry(headerL_t *head, int funct)
|
static int displayEntry(headerL_t *head, int funct)
|
||||||
{
|
{
|
||||||
if ((funct & VERBOSE) == VERBOSE) {
|
if ( funct & VERBOSE ) {
|
||||||
printf("%s %d/%d %8d %s ", modeString(head->mode), head->uid, head->gid, head->size, timeString(head->mtime));
|
printf("%s %d/%d %8d %s ", modeString(head->mode), head->uid, head->gid, head->size, timeString(head->mtime));
|
||||||
}
|
}
|
||||||
printf("%s\n", head->name);
|
printf("%s\n", head->name);
|
||||||
@ -232,22 +232,22 @@ extern int ar_main(int argc, char **argv)
|
|||||||
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
|
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'o':
|
case 'o':
|
||||||
funct = funct | PRESERVE_DATE;
|
funct |= PRESERVE_DATE;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
funct = funct | VERBOSE;
|
funct |= VERBOSE;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
funct = funct | DISPLAY;
|
funct |= DISPLAY;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
funct = funct | EXT_TO_FILE;
|
funct |= EXT_TO_FILE;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
funct = funct | EXT_TO_STDOUT;
|
funct |= EXT_TO_STDOUT;
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
funct = funct | RECURSIVE;
|
funct |= RECURSIVE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(ar_usage);
|
usage(ar_usage);
|
||||||
@ -288,14 +288,14 @@ extern int ar_main(int argc, char **argv)
|
|||||||
extractList = header;
|
extractList = header;
|
||||||
|
|
||||||
while(extractList->next != NULL) {
|
while(extractList->next != NULL) {
|
||||||
if ( (funct & EXT_TO_FILE) == EXT_TO_FILE) {
|
if ( funct & EXT_TO_FILE ) {
|
||||||
dstFd = open(extractList->name, O_WRONLY | O_CREAT, extractList->mode);
|
dstFd = open(extractList->name, O_WRONLY | O_CREAT, extractList->mode);
|
||||||
|
|
||||||
extractAr(srcFd, dstFd, extractList);
|
extractAr(srcFd, dstFd, extractList);
|
||||||
}
|
}
|
||||||
if ( (funct & EXT_TO_STDOUT) == EXT_TO_STDOUT)
|
if ( funct & EXT_TO_STDOUT )
|
||||||
extractAr(srcFd, fileno(stdout), extractList);
|
extractAr(srcFd, fileno(stdout), extractList);
|
||||||
if ( (funct & DISPLAY) == DISPLAY)
|
if ( (funct & DISPLAY) || (funct & VERBOSE))
|
||||||
displayEntry(extractList, funct);
|
displayEntry(extractList, funct);
|
||||||
extractList=extractList->next;
|
extractList=extractList->next;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user