command: Factor command name matching out of command.c.
[pspp-builds.git] / src / language / lexer / command-name.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2010 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef COMMAND_NAME_H
18 #define COMMAND_NAME_H 1
19
20 #include <stdbool.h>
21 #include "libpspp/str.h"
22
23 bool command_match (struct substring command, struct substring string,
24                     bool *exact, int *missing_words);
25
26 /* Allows matching a string against a table of command names. */
27 struct command_matcher
28   {
29     struct substring string;
30     bool extensible;
31     void *exact_match;
32     int n_matches;
33     void *match;
34     int match_missing_words;
35   };
36
37 void command_matcher_init (struct command_matcher *, struct substring string);
38 void command_matcher_destroy (struct command_matcher *);
39
40 void command_matcher_add (struct command_matcher *, struct substring command,
41                           void *aux);
42
43 void *command_matcher_get_match (const struct command_matcher *);
44 int command_matcher_get_missing_words (const struct command_matcher *);
45
46 #endif /* command-name.h */