Allow compilation when not using BB_FEATURE_TAR_EXCLUDE, and fix

handling of --exclude option.
This commit is contained in:
Matt Kraai 2000-09-04 16:51:55 +00:00
parent 61a9d8d145
commit 43c8c38bbf
2 changed files with 38 additions and 44 deletions

View File

@ -49,6 +49,7 @@
#include <utime.h> #include <utime.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#include <getopt.h>
/* Tar file constants */ /* Tar file constants */
#ifndef MAJOR #ifndef MAJOR
@ -136,6 +137,13 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
int verboseFlag, int argc, char **argv, char** excludeList); int verboseFlag, int argc, char **argv, char** excludeList);
#endif #endif
static struct option longopts[] =
{
#ifdef BB_FEATURE_TAR_EXCLUDE
{"exclude",required_argument,NULL,'e'},
#endif
{NULL,0,NULL,0}
};
extern int tar_main(int argc, char **argv) extern int tar_main(int argc, char **argv)
{ {
@ -155,7 +163,7 @@ extern int tar_main(int argc, char **argv)
usage(tar_usage); usage(tar_usage);
/* do normal option parsing */ /* do normal option parsing */
while ((opt = getopt(argc, argv, "cxtvOf:-:")) > 0) { while ((opt = getopt_long(argc, argv, "cxtvOf:", longopts, NULL)) != EOF) {
switch (opt) { switch (opt) {
case 'c': case 'c':
if (extractFlag == TRUE || listFlag == TRUE) if (extractFlag == TRUE || listFlag == TRUE)
@ -186,28 +194,19 @@ extern int tar_main(int argc, char **argv)
if (!strcmp(tarName, "-") && createFlag == TRUE) if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE; tostdoutFlag = TRUE;
break; break;
case '-':
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
if (strcmp(optarg, "exclude")==0) { case 'e':
if (argv[optind]==NULL)
fatalError( "option `--exclude' requires an argument\n");
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2)); excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
excludeList[excludeListSize] = argv[optind]; excludeList[excludeListSize] = optarg;
/* Remove leading "/"s */ /* Remove leading "/"s */
if (*excludeList[excludeListSize] =='/') { if (*excludeList[excludeListSize] =='/')
excludeList[excludeListSize] = (excludeList[excludeListSize])+1; excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
}
/* Tack a NULL onto the end of the list */ /* Tack a NULL onto the end of the list */
excludeList[excludeListSize] = NULL; excludeList[++excludeListSize] = NULL;
optind++;
break; break;
}
#endif #endif
fatalError( "Unknown tar flag '%s'\n"
"Try `tar --help' for more information\n", optarg);
default: default:
fatalError( "Unknown tar flag '%c'\n" usage(tar_usage);
"Try `tar --help' for more information\n", **argv);
} }
} }
@ -485,9 +484,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
int errorFlag=FALSE; int errorFlag=FALSE;
TarHeader rawHeader; TarHeader rawHeader;
TarInfo header; TarInfo header;
#if defined BB_FEATURE_TAR_EXCLUDE
char** tmpList; char** tmpList;
#endif
/* Open the tar file for reading. */ /* Open the tar file for reading. */
if (!strcmp(tarName, "-")) if (!strcmp(tarName, "-"))

31
tar.c
View File

@ -49,6 +49,7 @@
#include <utime.h> #include <utime.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#include <getopt.h>
/* Tar file constants */ /* Tar file constants */
#ifndef MAJOR #ifndef MAJOR
@ -136,6 +137,13 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
int verboseFlag, int argc, char **argv, char** excludeList); int verboseFlag, int argc, char **argv, char** excludeList);
#endif #endif
static struct option longopts[] =
{
#ifdef BB_FEATURE_TAR_EXCLUDE
{"exclude",required_argument,NULL,'e'},
#endif
{NULL,0,NULL,0}
};
extern int tar_main(int argc, char **argv) extern int tar_main(int argc, char **argv)
{ {
@ -155,7 +163,7 @@ extern int tar_main(int argc, char **argv)
usage(tar_usage); usage(tar_usage);
/* do normal option parsing */ /* do normal option parsing */
while ((opt = getopt(argc, argv, "cxtvOf:-:")) > 0) { while ((opt = getopt_long(argc, argv, "cxtvOf:", longopts, NULL)) != EOF) {
switch (opt) { switch (opt) {
case 'c': case 'c':
if (extractFlag == TRUE || listFlag == TRUE) if (extractFlag == TRUE || listFlag == TRUE)
@ -186,28 +194,19 @@ extern int tar_main(int argc, char **argv)
if (!strcmp(tarName, "-") && createFlag == TRUE) if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE; tostdoutFlag = TRUE;
break; break;
case '-':
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
if (strcmp(optarg, "exclude")==0) { case 'e':
if (argv[optind]==NULL)
fatalError( "option `--exclude' requires an argument\n");
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2)); excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
excludeList[excludeListSize] = argv[optind]; excludeList[excludeListSize] = optarg;
/* Remove leading "/"s */ /* Remove leading "/"s */
if (*excludeList[excludeListSize] =='/') { if (*excludeList[excludeListSize] =='/')
excludeList[excludeListSize] = (excludeList[excludeListSize])+1; excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
}
/* Tack a NULL onto the end of the list */ /* Tack a NULL onto the end of the list */
excludeList[excludeListSize] = NULL; excludeList[++excludeListSize] = NULL;
optind++;
break; break;
}
#endif #endif
fatalError( "Unknown tar flag '%s'\n"
"Try `tar --help' for more information\n", optarg);
default: default:
fatalError( "Unknown tar flag '%c'\n" usage(tar_usage);
"Try `tar --help' for more information\n", **argv);
} }
} }
@ -485,9 +484,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
int errorFlag=FALSE; int errorFlag=FALSE;
TarHeader rawHeader; TarHeader rawHeader;
TarInfo header; TarInfo header;
#if defined BB_FEATURE_TAR_EXCLUDE
char** tmpList; char** tmpList;
#endif
/* Open the tar file for reading. */ /* Open the tar file for reading. */
if (!strcmp(tarName, "-")) if (!strcmp(tarName, "-"))