Patch to add in the -X option and fix the --exclude bug, originally by
authorEric Andersen <andersen@codepoet.org>
Mon, 4 Dec 2000 18:51:09 +0000 (18:51 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 4 Dec 2000 18:51:09 +0000 (18:51 -0000)
Sebastien Huet, and now ported to the latest and greatest by both Arne Bernin
<ab@netropol.de> and kent robotti <robotti@metconnect.com>.

Config.h
applets/usage.c
archival/tar.c
tar.c
usage.c

index 0f31ae16b60fd9b8e5645da3e3acc0b146b5b7d7..e07044690579577c01569ef3880a5dda25a0f204 100644 (file)
--- a/Config.h
+++ b/Config.h
 // Enable support for creation of tar files.
 #define BB_FEATURE_TAR_CREATE
 //
-// Enable support for "--exclude" for excluding files
+// Enable support for "--exclude" and "-X" for excluding files
 #define BB_FEATURE_TAR_EXCLUDE
 //
 //// Enable reverse sort
index bab6d21b3001982b07d9dfd3f4052320ad173425..bd2321fbce3327cb2cc0872f26b06381218d02ef 100644 (file)
@@ -1218,6 +1218,7 @@ const char tar_usage[] =
 #endif
 #if defined BB_FEATURE_TAR_EXCLUDE
        "[--exclude File] "
+        "[-X File]"
 #endif
        "[-f tarFile] [FILE(s)] ...\n"
 #ifndef BB_FEATURE_TRIVIAL_HELP
@@ -1234,6 +1235,7 @@ const char tar_usage[] =
        "\tO\t\textract to stdout\n"
 #if defined BB_FEATURE_TAR_EXCLUDE
        "\texclude\t\tfile to exclude\n"
+        "\tX\t\tfile with names to exclude\n"
 #endif
        "\nInformative output:\n"
        "\tv\t\tverbosely list files processed\n"
index 6d8e633b00b414fe3bd12f417845bd20f0afb0db..7e56fb99ab848f77eeeafdf74bdbadde41e3030e 100644 (file)
@@ -147,6 +147,9 @@ extern int tar_main(int argc, char **argv)
        char** extractList=NULL;
 #if defined BB_FEATURE_TAR_EXCLUDE
        int excludeListSize=0;
+        char *excludeFileName ="-";
+        FILE *fileList;
+        char file[256];
 #endif
        const char *tarName="-";
        int listFlag     = FALSE;
@@ -198,7 +201,7 @@ extern int tar_main(int argc, char **argv)
                                        break;
 #if defined BB_FEATURE_TAR_EXCLUDE
                                case 'e':
-                                       if (strcmp(*argv, "exclude")==0) {
+                                       if (strcmp(*argv, "xclude")==0) {
                                                excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
                                                excludeList[excludeListSize] = *(++argv);
                                                if (excludeList[excludeListSize] == NULL)
@@ -211,6 +214,30 @@ extern int tar_main(int argc, char **argv)
                                                stopIt=TRUE;
                                                break;
                                        }
+                                case 'X':
+                                       if (*excludeFileName != '-')
+                                               fatalError("Only one 'X' option allowed\n");
+                                       excludeFileName = *(++argv);
+                                       if  (excludeFileName == NULL)
+                                               fatalError("Option requires an argument: No file specified\n");
+                                       fileList = fopen (excludeFileName, "rt");
+                                       if (! fileList)
+                                               fatalError("Exclude file: file not found\n");
+                                       while (!feof(fileList)) {
+                                               fscanf(fileList, "%s", file);
+                                               excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
+                                               excludeList[excludeListSize] = malloc(sizeof(char) * (strlen(file)+1));
+                                               strcpy(excludeList[excludeListSize],file);
+                                               /* Remove leading "/"s */
+                                               if (*excludeList[excludeListSize] == '/')
+                                                       excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
+                                               /* Tack a NULL onto the end of the list */
+                                                       excludeList[++excludeListSize] = NULL;
+                                       }
+                                       fclose(fileList);
+                                       stopIt=TRUE;
+                                       break;
 #endif
                                case '-':
                                                break;
diff --git a/tar.c b/tar.c
index 6d8e633b00b414fe3bd12f417845bd20f0afb0db..7e56fb99ab848f77eeeafdf74bdbadde41e3030e 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -147,6 +147,9 @@ extern int tar_main(int argc, char **argv)
        char** extractList=NULL;
 #if defined BB_FEATURE_TAR_EXCLUDE
        int excludeListSize=0;
+        char *excludeFileName ="-";
+        FILE *fileList;
+        char file[256];
 #endif
        const char *tarName="-";
        int listFlag     = FALSE;
@@ -198,7 +201,7 @@ extern int tar_main(int argc, char **argv)
                                        break;
 #if defined BB_FEATURE_TAR_EXCLUDE
                                case 'e':
-                                       if (strcmp(*argv, "exclude")==0) {
+                                       if (strcmp(*argv, "xclude")==0) {
                                                excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
                                                excludeList[excludeListSize] = *(++argv);
                                                if (excludeList[excludeListSize] == NULL)
@@ -211,6 +214,30 @@ extern int tar_main(int argc, char **argv)
                                                stopIt=TRUE;
                                                break;
                                        }
+                                case 'X':
+                                       if (*excludeFileName != '-')
+                                               fatalError("Only one 'X' option allowed\n");
+                                       excludeFileName = *(++argv);
+                                       if  (excludeFileName == NULL)
+                                               fatalError("Option requires an argument: No file specified\n");
+                                       fileList = fopen (excludeFileName, "rt");
+                                       if (! fileList)
+                                               fatalError("Exclude file: file not found\n");
+                                       while (!feof(fileList)) {
+                                               fscanf(fileList, "%s", file);
+                                               excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
+                                               excludeList[excludeListSize] = malloc(sizeof(char) * (strlen(file)+1));
+                                               strcpy(excludeList[excludeListSize],file);
+                                               /* Remove leading "/"s */
+                                               if (*excludeList[excludeListSize] == '/')
+                                                       excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
+                                               /* Tack a NULL onto the end of the list */
+                                                       excludeList[++excludeListSize] = NULL;
+                                       }
+                                       fclose(fileList);
+                                       stopIt=TRUE;
+                                       break;
 #endif
                                case '-':
                                                break;
diff --git a/usage.c b/usage.c
index bab6d21b3001982b07d9dfd3f4052320ad173425..bd2321fbce3327cb2cc0872f26b06381218d02ef 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -1218,6 +1218,7 @@ const char tar_usage[] =
 #endif
 #if defined BB_FEATURE_TAR_EXCLUDE
        "[--exclude File] "
+        "[-X File]"
 #endif
        "[-f tarFile] [FILE(s)] ...\n"
 #ifndef BB_FEATURE_TRIVIAL_HELP
@@ -1234,6 +1235,7 @@ const char tar_usage[] =
        "\tO\t\textract to stdout\n"
 #if defined BB_FEATURE_TAR_EXCLUDE
        "\texclude\t\tfile to exclude\n"
+        "\tX\t\tfile with names to exclude\n"
 #endif
        "\nInformative output:\n"
        "\tv\t\tverbosely list files processed\n"