]> git.draconx.ca Git - cdecl99.git/blob - test/test.h
Add better --help text to the test programs.
[cdecl99.git] / test / test.h
1 /*
2  * Copyright © 2012, 2020 Nick Bowler
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 <https://www.gnu.org/licenses/>.
16  */
17
18 #ifndef CDECL_TEST_H_
19 #define CDECL_TEST_H_
20
21 #include <stddef.h>
22 #include <stdbool.h>
23 #include <limits.h>
24 #include <assert.h>
25 #include <getopt.h>
26
27 #ifndef _
28 #  define _(x) (x)
29 #endif
30
31 static inline int
32 print_option_start(const struct option *opt, const char *argname)
33 {
34         int w;
35
36         if (!argname)
37                 argname = _("ARG");
38
39         if (opt->val >= CHAR_MIN && opt->val <= CHAR_MAX) {
40                 switch (opt->has_arg) {
41                 case 0:
42                         w = printf(_("  -%c, --%s"), opt->val, opt->name);
43                         break;
44                 case 1:
45                         w = printf(_("  -%c, --%s=%s"),
46                                    opt->val, opt->name, argname);
47                         break;
48                 case 2:
49                         w = printf(_("  -%c, --%s[=%s]"),
50                                    opt->val, opt->name, argname);
51                         break;
52                 default:
53                         assert(0);
54                 }
55         } else {
56                 switch (opt->has_arg) {
57                 case 0:
58                         w = printf(_("  --%s"), opt->name);
59                         break;
60                 case 1:
61                         w = printf(_("  --%s=%s"), opt->name, argname);
62                         break;
63                 case 2:
64                         w = printf(_("  --%s[=%s]"), opt->name, argname);
65                         break;
66                 default:
67                         assert(0);
68                 }
69         }
70
71         if (w > 18) {
72                 putchar('\n');
73                 w = 0;
74         }
75
76         return w;
77 }
78
79 struct cdecl_declspec;
80 struct cdecl;
81
82 void *malloc_nofail(size_t size);
83 void *realloc_nofail(void *ptr, size_t size);
84 void test_print_specifiers(struct cdecl_declspec *spec);
85 void test_print_decl(struct cdecl *decl);
86 void test_explain_decl(struct cdecl *decl);
87
88 bool strict_strtoul(unsigned long *val, const char *str, int base);
89
90 void test_print_version(const char *program);
91
92 #endif