Debian Codegraph @

tools/lou_tableinfo.c

raw symbols SCIP
1 /* liblouis Braille Translation and Back-Translation Library
2
3 Copyright (C) 2017 Bert Frees
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <config.h>
20
21 #include <stdlib.h>
22 #include "liblouis.h"
23 #include <getopt.h>
24 #include "progname.h"
25 #include "version-etc.h"
26
27 static const struct option longopts[] = {
28 { "help", no_argument, NULL, 'h' },
29 { "version", no_argument, NULL, 'v' },
30 { NULL, 0, NULL, 0 },
31 };
32
33 const char version_etc_copyright[] = "Copyright %s %d Bert Frees";
34
35 #define AUTHORS "Bert Frees"
36
37 static void
38 print_help(void) {
39 printf("\
40 Usage: %s [KEY] TABLE\n",
41 program_name);
42
43 fputs("\
44 Print all table metadata defined in TABLE, or a specific metadata field\n\
45 if KEY is specified. Return 0 if the requested metadata could be found,\n\
46 1 otherwise.\n\n",
47 stdout);
48
49 fputs("\
50 -h, --help display this help and exit\n\
51 -v, --version display version information and exi\n",
52 stdout);
53
54 printf("\n");
55 printf("Report bugs to %s.\n", PACKAGE_BUGREPORT);
56
57 #ifdef PACKAGE_PACKAGER_BUG_REPORTS
58 printf("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
59 #endif
60 #ifdef PACKAGE_URL
61 printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
62 #endif
63 }
64
65 int
66 main(int argc, char **argv) {
67 int optc;
68 set_program_name(argv[0]);
69 while ((optc = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) switch (optc) {
70 /* --help and --version exit immediately, per GNU coding standards. */
71 case 'v':
72 version_etc(
73 stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *)NULL);
74 exit(EXIT_SUCCESS);
75 break;
76 case 'h':
77 print_help();
78 exit(EXIT_SUCCESS);
79 break;
80 default:
81 fprintf(stderr, "Try `%s --help' for more information.\n", program_name);
82 exit(EXIT_FAILURE);
83 break;
84 }
85 if (optind > argc - 1) {
86 fprintf(stderr, "%s: no table specified\n", program_name);
87 fprintf(stderr, "Try `%s --help' for more information.\n", program_name);
88 exit(EXIT_FAILURE);
89 } else if (optind == argc - 1) {
90 // const char *table = argv[optind];
91 fprintf(stderr, "Not supported yet\n");
92 exit(EXIT_FAILURE);
93 } else if (optind == argc - 2) {
94 const char *key = argv[optind];
95 const char *table = argv[optind + 1];
96 const char *value = lou_getTableInfo(table, key);
97 if (value != NULL) {
98 printf("%s\n", value);
99 exit(EXIT_SUCCESS);
100 } else {
101 fprintf(stderr, "%s: no such field in %s\n", key, table);
102 exit(EXIT_FAILURE);
103 }
104 } else {
105 fprintf(stderr, "%s: extra operand: %s\n", program_name, argv[optind + 1]);
106 fprintf(stderr, "Try `%s --help' for more information.\n", program_name);
107 exit(EXIT_FAILURE);
108 }
109 }