aboutsummaryrefslogtreecommitdiff
path: root/tests/wstest.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-07-15 11:51:50 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-07-15 11:51:50 +0300
commitab6db76c77ea6480b307e43107bf570eb90d95eb (patch)
tree6a91c191411af18825cb50d012c2e38c0efebdc2 /tests/wstest.c
parent65ce987f7408a46233d9b0404c2396e4370a12ea (diff)
downloadwydawca-ab6db76c77ea6480b307e43107bf570eb90d95eb.tar.gz
wydawca-ab6db76c77ea6480b307e43107bf570eb90d95eb.tar.bz2
Switch to grecs eb66a000
Diffstat (limited to 'tests/wstest.c')
-rw-r--r--tests/wstest.c141
1 files changed, 0 insertions, 141 deletions
diff --git a/tests/wstest.c b/tests/wstest.c
deleted file mode 100644
index 9f02b0e..0000000
--- a/tests/wstest.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/* wordsplit - a word splitter
- Copyright (C) 2009, 2010, 2011, 2017, 2019 Sergey Poznyakoff
-
- This program 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 of the License, or (at your
- option) any later version.
-
- This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <wordsplit.h>
-
-struct flgtab
-{
- char *name;
- int flag;
-};
-
-struct flgtab flgtab[] = {
-#define FLG(n) { #n, n }
- FLG(WRDSF_SHOWERR),
- FLG(WRDSF_ENOMEMABRT),
- FLG(WRDSF_WS),
- FLG(WRDSF_QUOTE),
- FLG(WRDSF_SQUEEZE_DELIMS),
- FLG(WRDSF_RETURN_DELIMS),
- FLG(WRDSF_SED_EXPR),
- FLG(WRDSF_DEFFLAGS),
- { NULL }
-#undef FLG
-};
-
-int
-str2flag (const char *opt)
-{
- struct flgtab *f;
- for (f = flgtab; f->name; f++)
- if (strcmp (f->name, opt) == 0)
- return f->flag;
- return 0;
-}
-
-int
-main (int argc, char **argv)
-{
- struct wordsplit ws;
- int flags = 0;
- int f;
- size_t i;
- char *text;
-
- char *progname = argv[0];
-
- while (--argc)
- {
- char *opt = *++argv;
- if (strncmp (opt, "delim=", 6) == 0)
- {
- ws.ws_delim = opt + 6;
- flags |= WRDSF_DELIM;
- }
- else if (strncmp (opt, "comment=", 8) == 0)
- {
- ws.ws_comment = opt + 8;
- flags |= WRDSF_COMMENT;
- }
- else if ((opt[0] == '!' || opt[0] == '~')
- && strncmp (opt+1, "WRDSF_", 6) == 0)
- {
- f = str2flag (opt + 1);
- if (!f)
- {
- fprintf (stderr, "%s: unknown flag: %s\n", progname, opt+1);
- exit (1);
- }
- flags &= ~f;
- }
- else if (strncmp (opt, "WRDSF_", 6) == 0)
- {
- f = str2flag (opt);
- if (!f)
- {
- fprintf (stderr, "%s: unknown flag: %s\n", progname, opt);
- exit (1);
- }
- flags |= f;
- }
- else if (strcmp (opt, "--") == 0)
- break;
- else
- break;
- }
-
- if (!flags)
- flags = WRDSF_DEFFLAGS;
-
- if (argc == 0)
- {
- fprintf (stderr, "%s: not enough arguments\n", progname);
- return 1;
- }
- text = *argv++;
- argc--;
-
- if (wordsplit (text, &ws, flags))
- {
- fprintf (stderr, "%s: parse error\n", progname);
- return 1;
- }
-
- if (ws.ws_wordc != argc)
- {
- fprintf (stderr, "%s: wrong number of fields (%lu/%d)\n",
- progname, (unsigned long) ws.ws_wordc, argc);
- return 1;
- }
-
- for (i = 0; i < ws.ws_wordc; i++)
- if (strcmp (ws.ws_wordv[i], argv[i]))
- {
- fprintf (stderr, "%s: word %lu mismatch (got %s)\n",
- progname, (unsigned long) i, ws.ws_wordv[i]);
- return 1;
- }
-
- wordsplit_free (&ws);
- return 0;
-}

Return to:

Send suggestions and report system problems to the System administrator.