1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "libpspp/assertion.h"
28 #include "libpspp/compiler.h"
29 #include "language/lexer/command-name.h"
32 #include "gl/progname.h"
34 static char **commands, **strings;
35 static size_t n_commands, n_strings;
37 static void parse_options (int argc, char **argv);
38 static void usage (void) NO_RETURN;
41 main (int argc, char *argv[])
45 set_program_name (argv[0]);
46 parse_options (argc, argv);
48 for (i = 0; i < n_strings; i++)
50 const char *string = strings[i];
51 struct command_matcher cm;
57 printf ("string=\"%s\":\n", string);
58 for (j = 0; j < n_commands; j++)
60 const char *command = commands[j];
64 match = command_match (ss_cstr (command), ss_cstr (string),
65 &exact, &missing_words);
66 printf ("\tcommand=\"%s\" match=%s",
67 command, match ? "yes" : "no");
69 printf (" exact=%s missing_words=%d",
70 exact ? "yes" : "no", missing_words);
74 command_matcher_init (&cm, ss_cstr (string));
75 for (j = 0; j < n_commands; j++)
76 command_matcher_add (&cm, ss_cstr (commands[j]), commands[j]);
77 best = command_matcher_get_match (&cm);
78 printf ("match: %s, missing_words=%d\n",
79 best ? best : "none", command_matcher_get_missing_words (&cm));
80 command_matcher_destroy (&cm);
87 parse_options (int argc, char **argv)
93 static const struct option options[] =
95 {"help", no_argument, NULL, 'h'},
99 int c = getopt_long (argc, argv, "h", options, NULL);
121 for (breakpoint = optind; ; breakpoint++)
122 if (breakpoint >= argc)
123 error (1, 0, "missing ',' on command line; use --help for help");
124 else if (!strcmp (argv[breakpoint], ","))
127 commands = &argv[optind];
128 n_commands = breakpoint - optind;
130 strings = &argv[breakpoint + 1];
131 n_strings = argc - (breakpoint + 1);
133 if (n_commands == 0 || n_strings == 0)
134 error (1, 0, "must specify at least one command and one string; "
135 "use --help for help");
142 %s, to match PSPP command names\n\
143 usage: %s [OPTIONS] COMMAND... , STRING...\n\
146 -h, --help print this help message\n",
147 program_name, program_name);