blob: 267eb18cd64f46f6c679fa7ab7bbde7ad059fa81 [file] [log] [blame]
Eitan Isaacson80be8fd2008-01-16 01:14:49 +00001/* liblouis Braille Translation and Back-Translation Library
2
3 Based on BRLTTY, copyright (C) 1999-2006 by
4 The BRLTTY Team
5
Christian Egli08d96a72009-10-08 08:49:13 +00006 Copyright (C) 2004, 2005, 2006, 2009
7 ViewPlus Technologies, Inc. www.viewplus.com and
Eitan Isaacson80be8fd2008-01-16 01:14:49 +00008 JJB Software, Inc. www.jjb-software.com
9
Christian Egli08d96a72009-10-08 08:49:13 +000010 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
Bert Frees92a80352017-09-30 23:01:02 +020014
Christian Egli08d96a72009-10-08 08:49:13 +000015 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
Bert Frees92a80352017-09-30 23:01:02 +020019
Eitan Isaacson80be8fd2008-01-16 01:14:49 +000020 You should have received a copy of the GNU General Public License
Christian Egli08d96a72009-10-08 08:49:13 +000021 along with this program. If not, see <http://www.gnu.org/licenses/>.
Bert Frees312affd2017-09-30 19:49:15 +020022*/
Eitan Isaacson80be8fd2008-01-16 01:14:49 +000023
Bert Frees92a80352017-09-30 23:01:02 +020024#include <config.h>
Eitan Isaacson80be8fd2008-01-16 01:14:49 +000025#include <stdio.h>
26#include <string.h>
27#include <stdlib.h>
Davy Kagerff52a4f2017-04-26 22:01:10 +020028#include "internal.h"
Christian Egli80d0b502009-10-08 13:06:33 +000029#include <getopt.h>
30#include "progname.h"
Christian Egli80d0b502009-10-08 13:06:33 +000031#include "version-etc.h"
32
Bert Frees92a80352017-09-30 23:01:02 +020033static const struct option longopts[] = {
Christian Egli585c6762019-06-05 15:19:10 +020034 { "help", no_argument, NULL, 'h' },
35 { "version", no_argument, NULL, 'v' },
36 { "quiet", no_argument, NULL, 'q' },
37 { NULL, 0, NULL, 0 },
Christian Egli80d0b502009-10-08 13:06:33 +000038};
39
40const char version_etc_copyright[] =
Bert Frees92a80352017-09-30 23:01:02 +020041 "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc.";
Christian Egli80d0b502009-10-08 13:06:33 +000042
Christian Eglic1fe3142009-10-09 08:16:21 +000043#define AUTHORS "John J. Boyer"
Christian Egli80d0b502009-10-08 13:06:33 +000044
Christian Egli2ac36f72011-03-14 13:10:39 +000045static int quiet_flag = 0;
46
Christian Egli80d0b502009-10-08 13:06:33 +000047static void
Bert Frees92a80352017-09-30 23:01:02 +020048print_help(void) {
49 printf("\
50Usage: %s [OPTIONS] TABLE[,TABLE,...]\n",
51 program_name);
52
53 fputs("\
Christian Eglic1fe3142009-10-09 08:16:21 +000054Test a Braille translation table. If the table contains errors,\n\
55appropriate messages are displayed. If there are no errors the\n\
Christian Egli2ac36f72011-03-14 13:10:39 +000056message \"no errors found.\" is shown unless you specify the --quiet\n\
Bert Frees92a80352017-09-30 23:01:02 +020057option.\n",
58 stdout);
Christian Egli80d0b502009-10-08 13:06:33 +000059
Bert Frees92a80352017-09-30 23:01:02 +020060 fputs("\
Christian Egli80d0b502009-10-08 13:06:33 +000061 -h, --help display this help and exit\n\
Christian Egli2ac36f72011-03-14 13:10:39 +000062 -v, --version display version information and exit\n\
Bert Frees92a80352017-09-30 23:01:02 +020063 -q, --quiet do not write to standard error if there are no errors.\n",
64 stdout);
Christian Egli80d0b502009-10-08 13:06:33 +000065
Bert Frees92a80352017-09-30 23:01:02 +020066 printf("\n");
67 printf("Report bugs to %s.\n", PACKAGE_BUGREPORT);
Christian Eglidc50af92012-09-27 13:10:51 +000068
69#ifdef PACKAGE_PACKAGER_BUG_REPORTS
Bert Frees92a80352017-09-30 23:01:02 +020070 printf("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
Christian Eglidc50af92012-09-27 13:10:51 +000071#endif
72#ifdef PACKAGE_URL
Bert Frees92a80352017-09-30 23:01:02 +020073 printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
Christian Eglidc50af92012-09-27 13:10:51 +000074#endif
Christian Egli80d0b502009-10-08 13:06:33 +000075}
Eitan Isaacson80be8fd2008-01-16 01:14:49 +000076
77int
Bert Frees92a80352017-09-30 23:01:02 +020078main(int argc, char **argv) {
79 const TranslationTableHeader *table;
80 int optc;
Christian Egli80d0b502009-10-08 13:06:33 +000081
Bert Frees92a80352017-09-30 23:01:02 +020082 set_program_name(argv[0]);
Christian Egli80d0b502009-10-08 13:06:33 +000083
Bert Frees92a80352017-09-30 23:01:02 +020084 while ((optc = getopt_long(argc, argv, "hvq", longopts, NULL)) != -1) switch (optc) {
85 /* --help and --version exit immediately, per GNU coding standards. */
86 case 'v':
87 version_etc(
88 stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *)NULL);
89 exit(EXIT_SUCCESS);
90 break;
91 case 'h':
92 print_help();
93 exit(EXIT_SUCCESS);
94 break;
95 case 'q':
96 quiet_flag = 1;
97 break;
98 default:
99 fprintf(stderr, "Try `%s --help' for more information.\n", program_name);
100 exit(EXIT_FAILURE);
101 break;
102 }
Christian Egli80d0b502009-10-08 13:06:33 +0000103
Bert Frees92a80352017-09-30 23:01:02 +0200104 if (optind != argc - 1) {
105 /* Print error message and exit. */
106 if (optind < argc - 1)
107 fprintf(stderr, "%s: extra operand: %s\n", program_name, argv[optind + 1]);
108 else
109 fprintf(stderr, "%s: no table specified\n", program_name);
110 fprintf(stderr, "Try `%s --help' for more information.\n", program_name);
111 exit(EXIT_FAILURE);
112 }
Christian Egli80d0b502009-10-08 13:06:33 +0000113
Bert Frees92a80352017-09-30 23:01:02 +0200114 if (!(table = lou_getTable(argv[optind]))) {
115 lou_free();
116 exit(EXIT_FAILURE);
117 }
118 if (quiet_flag == 0) fprintf(stderr, "No errors found.\n");
119 lou_free();
120 exit(EXIT_SUCCESS);
Eitan Isaacson80be8fd2008-01-16 01:14:49 +0000121}