delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/02/12/06:36:27

Message-ID: <20010212113414.233.qmail@lauras.lt>
From: "Laurynas Biveinis" <lauras AT softhome DOT net>
Date: Mon, 12 Feb 2001 13:34:14 +0200
To: djgpp-workers AT delorie DOT com
Subject: PATCH: new djtar option
Mail-Followup-To: djgpp-workers AT delorie DOT com
Mime-Version: 1.0
User-Agent: Mutt/1.3.12i
Reply-To: djgpp-workers AT delorie DOT com

So I've implemented the -e option discussed before.
Also I've made djtar to accept multiple -o and -e options,
this functionality was missing before.

Any comments?

Laurynas

Index: djgpp/src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.53
diff -u -r1.53 wc204.txi
--- wc204.txi	2001/02/09 12:38:40	1.53
+++ wc204.txi	2001/02/12 11:24:07
@@ -317,3 +317,9 @@
 @findex setjmp AT r{, also a macro}
 @code{setjmp} is now a macro as well as a function.  This is required by
 the C AT t{++} standard, and also recommended by the C standard.
+
+@pindex djtar AT r{, new option -e}
+@pindex djtar AT r{, multiple -o and -e options}
+New option @samp{-e} has been added to @code{djtar} to skip specified files 
+and directories when extracting. Also @code{djtar} can accept multiple 
+@samp{-o} and @samp{-e} options in a single command line.
Index: djgpp/src/utils/utils.tex
===================================================================
RCS file: /cvs/djgpp/djgpp/src/utils/utils.tex,v
retrieving revision 1.13
diff -u -r1.13 utils.tex
--- utils.tex	2001/01/20 09:20:39	1.13
+++ utils.tex	2001/02/12 11:24:14
@@ -125,9 +125,10 @@
 @node djtar, dtou, djecho, Top
 @chapter djtar
 
-Usage: @code{djtar} [@code{-n} @file{changeFile}] [@code{-o} @file{dir}]
-[@code{-t}|@code{-x}] [@code{-i}] [@code{-v}] [@code{-p}]
-[@code{-.}|@code{-!.}] [@code{-d}|@code{-u}|@code{-b}] @file{tarfile}
+Usage: @code{djtar} [@code{-n} @file{changeFile}] [@code{-e} @file{dir}]
+[@code{-o} @file{dir}] [@code{-t}|@code{-x}] [@code{-i}] [@code{-v}] 
+[@code{-p}] [@code{-.}|@code{-!.}] [@code{-d}|@code{-u}|@code{-b}] 
+@file{tarfile}
 
 @code{djtar} is a program that is designed to ease the problems related
 to extracting Unix tar files on a DOS machine.  The long file names and
@@ -288,6 +289,13 @@
 with @samp{-p}, unless the output of @code{djtar} is redirected to a file
 or a pipe.
 
+@item -e @var{string}
+
+Only extract files whose full path names do @strong{not} begin with @var{string}.
+This option can be used to skip portions of archive.  If both this
+and @samp{-o} options are specified, then this option has precendence.  In
+other ways @samp{-e} is similar to @samp{-o} option.
+
 @item -o @var{string}
 
 Only extract files whose full path names begin with @var{string}.
@@ -296,7 +304,8 @@
 appended to their names.  When given the @samp{-o} option, @code{djtar}
 actually checks if @var{string} is the initial substring of each filename,
 so you can specify incomplete file names, thus using @samp{-o} as a poor man's
-wildcard facility.
+wildcard facility.  You may specify multiple @samp{-o} options to extract
+few different directories and files.
 
 @item -i
 
Index: djgpp/src/utils/djtar/djtar.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/utils/djtar/djtar.c,v
retrieving revision 1.7
diff -u -r1.7 djtar.c
--- djtar.c	1999/11/14 14:19:17	1.7
+++ djtar.c	2001/02/12 11:24:16
@@ -112,7 +112,20 @@
 int list_only = 1;
 char skipped_str[] = "[skipped]";
 
-char *only_dir;
+/* Do not extract files and directories starting with prefixes in this list. */
+/* It has precendence over only_dir below.  */
+struct skip_dir_list
+{
+   char *skip_dir;
+   struct skip_dir_list * next;
+} * skip_dirs;
+
+/* Extract only files and directories starting with prefixes in this list. */
+struct only_dir_list
+{
+   char *only_dir;
+   struct only_dir_list * next;
+} * only_dirs;
 
 /*------------------------------------------------------------------------*/
 
@@ -294,13 +307,39 @@
 get_new_name(char *name_to_change, int *should_be_written)
 {
   char *changed_name;
+  struct skip_dir_list * skip_dir_entry;
+  struct only_dir_list * only_dir_entry;
 
   /* ONLY_DIR says to extract only files which are siblings
      of that directory.  */
   *should_be_written = list_only == 0;
-  if (*should_be_written &&
-      only_dir && strncmp(only_dir, name_to_change, strlen(only_dir)))
-    *should_be_written = 0;
+
+  if (*should_be_written)
+  {
+     skip_dir_entry = skip_dirs;
+     while (skip_dir_entry)
+     {
+        if (!strncmp(skip_dir_entry->skip_dir, name_to_change, 
+                     strlen(skip_dir_entry->skip_dir)))
+           break;
+        skip_dir_entry = skip_dir_entry->next;
+     }
+     if (skip_dir_entry)
+        *should_be_written = 0;
+     else if (only_dirs)
+     {
+        only_dir_entry = only_dirs;
+        while (only_dir_entry)
+        {
+           if (!strncmp(only_dir_entry->only_dir, name_to_change,
+                        strlen(only_dir_entry->only_dir)))
+              break;
+           only_dir_entry = only_dir_entry->next;
+        }
+        if (!only_dir_entry)
+           *should_be_written = 0;
+     }
+  }
 
   changed_name = get_entry(name_to_change);
   if (*should_be_written && !to_stdout && NO_LFN(changed_name))
@@ -478,12 +517,14 @@
   int i = 1;
   char *tp;
   char *xp;
+  struct skip_dir_list * skip_entry;
+  struct only_dir_list * only_entry;
 
   progname = strlwr(strdup(argv[0]));
 
   if (argc < 2)
   {
-    fprintf(stderr, "Usage: %s [-n changeFile] [-p] [-i] [-t|x] [-o dir] [-v] [-u|d|b] [-[!].] tarfile...\n", progname);
+    fprintf(stderr, "Usage: %s [-n changeFile] [-p] [-i] [-t|x] [-e dir] [-o dir] [-v] [-u|d|b] [-[!].] tarfile...\n", progname);
     exit(1);
   }
 
@@ -495,6 +536,7 @@
     list_only = 1;
   else if (xp && (xp[sizeof(djtarx)-1] == '\0' || xp[sizeof(djtarx)-5] == '\0'))
     list_only = 0;
+
   while ((argc > i) && (argv[i][0] == '-') && argv[i][1])
   {
     switch (argv[i][1])
@@ -524,8 +566,17 @@
 	if (argv[i][2] == '.')
 	  dot_switch = 0;
 	break;
+      case 'e':
+        skip_entry = malloc(sizeof(struct skip_dir_list));
+        skip_entry->skip_dir = strdup(argv[++i]);
+        skip_entry->next = skip_dirs;
+        skip_dirs = skip_entry;
+	break;
       case 'o':
-        only_dir = strdup(argv[++i]);
+        only_entry = malloc(sizeof(struct only_dir_list));
+        only_entry->only_dir = strdup(argv[++i]);
+        only_entry->next = only_dirs;
+        only_dirs = only_entry;
         break;
       case 'p':
         to_stdout = 1;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019