Mail Archives: djgpp-workers/2007/11/07/22:13:20
Am Mittwoch, 7. November 2007 01:36 schrieben Sie:
> Some things we can do:
>
> 1. Change the logic to use the last space in the line, not the first one.
>
> 2. *If* the line has a tab, use that as the separator instead of a
> space, but if there's no tab, use the last space as above.
>
> 3. Same, but look for a NUL byte.
I am not sure if it is right, but I have assumed that you have proposed to use
the NUL byte as one alternate separating character more apart from the tab char.
Anyway I have followed that interpretation of the suggestion and implemented the
following:
If no space nor tab characters are part of the old and new dirnames and filenames
then all three separating chars may be used. If the space char apears only in the
old filename but not in the old dirname, then the space char can still be used as
separating char. If the space char apears in both old and new dirnames and filenames,
then only tab and NUL byte can be used as separator. If the space and tab chars
apears in both old and new dirnames and filenames the only the NUL byte can be
used as separator. If the tab char apears only in the old filename but not
in the old dirname, then tab can still be used as separator.
See the patch for details.
As usual suggestions, objections, comments are welcome.
If the english expanation in utils.tex is confusing, feel free to change or
correct it.
Regards,
Juan M. Guerrero
2007-11-08 Juan Manuell Guerrero <juan DOT guerrero AT gmx DOT de>
* src/utils/utils.tex: Info about the new field separating chars in
the change file.
* src/docs/kb/wc204.txi: Info about the new field separating chars in
the change file.
* src/utils/djtar/djtar.c (DoNameChanges): Implementation of use of tab
char and NUL byte as alternate field separating chars.
diff -aprNU3 djgpp.orig/src/docs/kb/wc204.txi djgpp/src/docs/kb/wc204.txi
--- djgpp.orig/src/docs/kb/wc204.txi 2005-05-11 20:06:08 +0000
+++ djgpp/src/docs/kb/wc204.txi 2007-11-06 23:53:16 +0000
@@ -1094,3 +1094,8 @@ formats for @code{"%x"} and @code{"%X"}
@pindex djasm AT r{, cr4 register}
@code{djasm} recognises the fourth control register, @code{cr4}.
+
+@pindex djtar AT r{, name change file format}
+To allow for directory and file names that may contain space and
+tab characters the list of recognized file name separating characters
+has been incremented by the tab character and the NUL byte.
diff -aprNU3 djgpp.orig/src/utils/djtar/djtar.c djgpp/src/utils/djtar/djtar.c
--- djgpp.orig/src/utils/djtar/djtar.c 2002-10-17 23:00:26 +0000
+++ djgpp/src/utils/djtar/djtar.c 2007-11-06 23:37:32 +0000
@@ -5,6 +5,7 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
@@ -99,6 +100,26 @@ get_entry(char *from)
static void
DoNameChanges(char *fname)
{
+ /*
+ * The following field separating characters
+ * will be recognized: NUL byte, tab and space.
+ * There may be up to two fields in every line:
+ * the from- and the to-filenames.
+ * If neither space nor tab characters are part
+ * of the from- and to-file names then every one
+ * of the three field separating characters can
+ * be used. If space characters are part of the
+ * from- and to-filenames then tab and the NUL byte
+ * can be used as field separating characters.
+ * If space characters are only part of the
+ * from-filename then every one of the three
+ * field separating characters can be used.
+ * If tab characters or tab and space characters
+ * are part of the from- and to-filenames then
+ * only the NUL byte can be used as field separating
+ * character.
+ */
+
struct skip_dir_list * new_entry;
FILE *f = fopen(fname, "r");
char from[PATH_MAX], to[PATH_MAX];
@@ -110,13 +131,44 @@ DoNameChanges(char *fname)
}
while (1)
{
+ char *field_separator;
+ size_t length;
+
fgets(line, sizeof(line), f);
if (feof(f))
break;
- to[0] = 0;
- sscanf(line, "%s %s", from, to);
- if (to[0])
+
+ length = strlen(line);
+ if (length == 1)
+ continue; /* Skip empty line. */
+ field_separator = line + length;
+ if (field_separator[-1] == '\n')
+ {
+ length--;
+ /*
+ * FIXME: this will fail when no to-filename
+ * is given and the from-filename looks like
+ * this:
+ * dir 1/dir\t2/dir3
+ * Unfortunately we have not defined
+ * an unique string terminating char.
+ */
+ field_separator = strrchr(line, '\t');
+ if (!field_separator)
+ field_separator = strrchr(line, ' ');
+ if (field_separator)
+ length = field_separator - line;
+ }
+ memcpy(from, line, length);
+ from[length] = '\0';
+ if (field_separator)
+ {
+ strcpy(to, ++field_separator);
+ length = strlen(to);
+ if (to[--length] == '\n')
+ to[length] = '\0';
store_entry(from, to);
+ }
else
{
new_entry = xmalloc(sizeof(struct skip_dir_list));
diff -aprNU3 djgpp.orig/src/utils/utils.tex djgpp/src/utils/utils.tex
--- djgpp.orig/src/utils/utils.tex 2004-01-10 21:55:48 +0000
+++ djgpp/src/utils/utils.tex 2007-11-07 00:07:52 +0000
@@ -285,6 +285,20 @@ The directories must be complete, not re
must match the complete path in the tar file, and the ``new'' directories
indicate where the file goes on the DOS disk. If there is no ``new'' directory
specified, the ``old'' one and all its siblings will be not extracted.
+The space and tab characters and the NUL byte will be recognized as separating
+characters between the ``old'' directories and filenames and the ``new''
+directories and filenames in the @file{changeFile} file. If neither the ``old''
+nor the ``new'' directories and filenames contain spaces nor tabs, then every
+one of the three separator characters are allowed. If space characters are part
+of the ``old'' and ``new'' directories and filenames, then the tab character or
+the NUL byte can be used as separating characters. If the space character
+apears only in the ``old'' filename but @emph{not} in the ``old'' directory,
+then the space character can still be used as separating character apart from
+the other twos. If tab characters or tab and space characters are part of the
+``old'' and ``new'' directories and filenames, then only the NUL byte can be
+used as separating character. If the space and tab characters apear only in the
+``old'' filename but @emph{not} in the ``old'' directory, then the tab character
+can still be used as separating character apart from the NUL byte.
@item -d
- Raw text -