diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-10-04 12:10:46 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-10-04 12:10:46 +0000 |
commit | d1e19a11d06653c8bd33b99d968a1d8a715e9656 (patch) | |
tree | 1ae8f823fa060e7035113bb8f6975dbff38396d7 | |
parent | 6124fdfc54336d0f96424e2f33f521218778d8b9 (diff) | |
download | swis-d1e19a11d06653c8bd33b99d968a1d8a715e9656.tar.gz swis-d1e19a11d06653c8bd33b99d968a1d8a715e9656.tar.bz2 |
src/version.c, src/readname.c: New files
src/word-split.c, src/html-strip.l: Add support for --from-file
(-T) option.
Makefile.am (libswis.a): New goal
swis.h: Add new prototypes
gnulib.modules: Add obstack
git-svn-id: file:///svnroot/swis/trunk@13 05ba3e8d-823b-0410-8fb2-de0ee4edb5ba
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | gnulib.modules | 2 | ||||
-rw-r--r-- | src/Makefile.am | 7 | ||||
-rw-r--r-- | src/html-strip.l | 21 | ||||
-rw-r--r-- | src/readname.c | 154 | ||||
-rw-r--r-- | src/swis.h | 10 | ||||
-rw-r--r-- | src/version.c | 25 | ||||
-rw-r--r-- | src/word-split.c | 21 |
8 files changed, 235 insertions, 13 deletions
@@ -1,5 +1,13 @@ 2007-10-04 Sergey Poznyakoff <gray@gnu.org.ua> + * src/version.c, src/readname.c: New files + * src/word-split.c, src/html-strip.l: Add support for --from-file + (-T) option. + * Makefile.am (libswis.a): New goal + * swis.h: Add new prototypes + * gnulib.modules: Add obstack + + * src/Makefile.am (LDADD): Add LIBICONV * configure.ac: Minor change * gnulib.modules: Add iconv diff --git a/gnulib.modules b/gnulib.modules index c8f9eaf..ca43b92 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -14,6 +14,8 @@ progname getline strerror iconv +fnmatch +obstack mbchar mbfile mbiter diff --git a/src/Makefile.am b/src/Makefile.am index 71f7ab8..9b46d15 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,11 +14,16 @@ # You should have received a copy of the GNU General Public License # along with SWIS. If not, see <http://www.gnu.org/licenses/>. +noinst_LIBRARIES=libswis.a bin_PROGRAMS=html-strip word-split html_strip_SOURCES=html-strip.l word_split_SOURCES=word-split.c +libswis_a_SOURCES=\ + readname.c\ + version.c + INCLUDES=-I${top_srcdir}/gnu -I../gnu -LDADD=../gnu/libgnu.a $(LIBICONV) +LDADD=./libswis.a ../gnu/libgnu.a $(LIBICONV) EXTRA_DIST=swis.h AM_LFLAGS=-d diff --git a/src/html-strip.l b/src/html-strip.l index f337c5d..a2dded3 100644 --- a/src/html-strip.l +++ b/src/html-strip.l @@ -241,11 +241,11 @@ struct option options[] = { { "version", no_argument, NULL, 'v' }, { "output", required_argument, NULL, 'o' }, { "tag", no_argument, NULL, 't' }, + { "files-from", required_argument, NULL, 'T' }, + { "null", no_argument, NULL, '0' }, { NULL } }; -DECL_COPYRIGHT; - void usage () { @@ -255,6 +255,8 @@ usage () printf (" -d, --debug output debugging info\n"); printf (" -o, --output=FILE direct output to FILE instead of stdout\n"); printf (" -t, --tag tag each output block with the source file name"); + printf (" -T, --from-file=FILE read input file names from FILE\n"); + printf (" -0, --null -T reads null-terminated names\n"); printf ("\n"); printf (" -h, --help print this help list\n"); printf (" -v, --version print program version and exit\n"); @@ -270,10 +272,14 @@ main (int argc, char **argv) program_name = argv[0]; yy_flex_debug = 0; - while ((c = getopt_long (argc, argv, "dho:tv", options, NULL)) != EOF) + while ((c = getopt_long (argc, argv, "0dhoT::tv", options, NULL)) != EOF) { switch (c) { + case '0': + filename_terminator = 0; + break; + case 'd': yy_flex_debug = 1; break; @@ -292,13 +298,16 @@ main (int argc, char **argv) error (1, errno, "cannot open output file %s", optarg); break; + case 'T': + read_names_from_file (optarg); + break; + case 't': tag_option = 1; break; case 'v': - version_etc (stdout, "html-strip", PACKAGE_NAME, VERSION, - PACKAGE_AUTHOR, NULL); + swis_version (stdout, "html-strip"); exit (0); default: @@ -309,6 +318,8 @@ main (int argc, char **argv) argc -= optind; argv += optind; + update_argcv (&argc, &argv); + if (argc) { input_file = argv; diff --git a/src/readname.c b/src/readname.c new file mode 100644 index 0000000..def30b6 --- /dev/null +++ b/src/readname.c @@ -0,0 +1,154 @@ +/* This file is part of SWIS + Copyright (C) 2007 Sergey Poznyakoff + + SWIS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + SWIS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SWIS. If not, see <http://www.gnu.org/licenses/>. */ + +#include "swis.h" + +int filename_terminator = '\n'; + +enum read_file_list_state /* Result of reading file name from the list file */ + { + file_list_success, /* OK, name read successfully */ + file_list_end, /* End of list file */ + file_list_zero, /* Zero separator encountered where it should not */ + file_list_skip /* Empty (zero-length) entry encountered, skip it */ + }; + +/* Read from FP a sequence of characters up to FILENAME_TERMINATOR and put them + into STK. + */ +static enum read_file_list_state +read_name_from_file (FILE *fp, struct obstack *stk) +{ + int c; + size_t counter = 0; + + for (c = getc (fp); c != EOF && c != filename_terminator; c = getc (fp)) + { + if (c == 0) + { + /* We have read a zero separator. The file possibly is + zero-separated */ + return file_list_zero; + } + obstack_1grow (stk, c); + counter++; + } + + if (counter == 0 && c != EOF) + return file_list_skip; + + obstack_1grow (stk, 0); + + return (counter == 0 && c == EOF) ? file_list_end : file_list_success; +} + +struct obstack argv_stk; +int stk_init; +size_t argcount; + +void +read_names_from_file (const char *filename) +{ + FILE *fp; + size_t count = 0, i; + enum read_file_list_state read_state; + + if (!strcmp (filename, "-")) + { + // request_stdin ("-T"); + fp = stdin; + } + else + { + if ((fp = fopen (filename, "r")) == NULL) + error (1, errno, "cannot open file %s", filename); + } + + if (!stk_init) + { + stk_init = 1; + obstack_init (&argv_stk); + } + + while ((read_state = read_name_from_file (fp, &argv_stk)) != file_list_end) + { + switch (read_state) + { + case file_list_success: + argcount++; + break; + + case file_list_end: /* won't happen, just to pacify gcc */ + break; + + case file_list_zero: + { + size_t size; + char *p; + + error (0, 0, "%s: file name read contains nul character", + filename); + + /* Prepare new stack contents */ + /* FIXME */ + size = obstack_object_size (&argv_stk); + p = obstack_finish (&argv_stk); + for (i = 0; size > 0; size--, p++) + { + if (*p) + obstack_1grow (&argv_stk, *p); + else if (i < argcount) + i++; + else + obstack_1grow (&argv_stk, '\n'); + } + obstack_1grow (&argv_stk, 0); + count = 1; + /* Read rest of files using new filename terminator */ + filename_terminator = 0; + break; + } + + case file_list_skip: + break; + } + } + + fclose (fp); + argcount += count; +} + +void +update_argcv (int *pargc, char ***pargv) +{ + int i, new_argc; + char **new_argv; + char *p, *start; + + new_argc = *pargc + argcount + 1; + new_argv = xmalloc (sizeof (new_argv[0]) * (new_argc + 1)); + memcpy (new_argv, *pargv, sizeof (new_argv[0]) * *pargc); + + start = obstack_finish (&argv_stk); + for (i = *pargc, p = start; *p; p += strlen (p) + 1, i++) + new_argv[i] = xstrdup (p); + new_argv[i] = NULL; + + obstack_free (&argv_stk, NULL); + + *pargv = new_argv; + *pargc = new_argc; +} @@ -39,7 +39,13 @@ #endif #include "version-etc.h" +#define obstack_chunk_alloc malloc +#define obstack_chunk_free free +#include "obstack.h" + #define PACKAGE_AUTHOR "Sergey Poznyakoff" -#define COPYRIGHT_STRING "Copyright %s %d " PACKAGE_AUTHOR -#define DECL_COPYRIGHT const char version_etc_copyright[] = COPYRIGHT_STRING +void swis_version (FILE *fp, const char *progname); +void read_names_from_file (const char *filename); +void update_argcv (int *pargc, char ***pargv); +extern int filename_terminator; diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000..9510a33 --- /dev/null +++ b/src/version.c @@ -0,0 +1,25 @@ +/* This file is part of SWIS + Copyright (C) 2007 Sergey Poznyakoff + + SWIS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + SWIS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SWIS. If not, see <http://www.gnu.org/licenses/>. */ + +#include "swis.h" + +const char version_etc_copyright[] = "Copyright %s %d " PACKAGE_AUTHOR; + +void +swis_version (FILE *fp, const char *progname) +{ + version_etc (fp, progname, PACKAGE_NAME, VERSION, PACKAGE_AUTHOR, NULL); +} diff --git a/src/word-split.c b/src/word-split.c index 59b11d6..b283223 100644 --- a/src/word-split.c +++ b/src/word-split.c @@ -26,11 +26,11 @@ struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { "output", required_argument, NULL, 'o' }, + { "files-from", required_argument, NULL, 'T' }, + { "null", no_argument, NULL, '0' }, { NULL } }; -DECL_COPYRIGHT; - void usage () { @@ -40,6 +40,8 @@ usage () /* printf (" -d, --debug output debugging info\n"); */ printf (" -o, --output=FILE direct output to FILE instead of stdout\n"); printf (" -t, --tag preserve file name tags\n"); + printf (" -T, --from-file=FILE read input file names from FILE\n"); + printf (" -0, --null -T reads null-terminated names\n"); printf ("\n"); printf (" -h, --help print this help list\n"); printf (" -v, --version print program version and exit\n"); @@ -153,10 +155,14 @@ main (int argc, char **argv) program_name = argv[0]; - while ((c = getopt_long (argc, argv, "dho:tv", options, NULL)) != EOF) + while ((c = getopt_long (argc, argv, "0dho:T:tv", options, NULL)) != EOF) { switch (c) { + case '0': + filename_terminator = 0; + break; + case 'd': error (0, 0, "warning: the --debug option is not yet supported"); /* FIXME */ @@ -176,13 +182,16 @@ main (int argc, char **argv) error (1, errno, "cannot open output file %s", optarg); break; + case 'T': + read_names_from_file (optarg); + break; + case 't': tag_option = 1; break; case 'v': - version_etc (stdout, "word-split", PACKAGE_NAME, VERSION, - PACKAGE_AUTHOR, NULL); + swis_version (stdout, "word-split"); exit (0); default: @@ -193,6 +202,8 @@ main (int argc, char **argv) argc -= optind; argv += optind; + update_argcv (&argc, &argv); + if (argc) { input_file = argv; |