| 1 | /* liblouis Braille Translation and Back-Translation Library |
| 2 | |
| 3 | Based on BRLTTY, copyright (C) 1999-2006 by |
| 4 | The BRLTTY Team |
| 5 | |
| 6 | Copyright (C) 2004, 2005, 2006, 2009 |
| 7 | ViewPlus Technologies, Inc. www.viewplus.com and |
| 8 | JJB Software, Inc. www.jjb-software.com |
| 9 | |
| 10 | 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. |
| 14 | |
| 15 | 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. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | |
| 24 | #include <config.h> |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | #include <stdlib.h> |
| 29 | #include "internal.h" |
| 30 | #include <getopt.h> |
| 31 | #include "progname.h" |
| 32 | #include "version-etc.h" |
| 33 | |
| 34 | static const struct option longopts[] = { |
| 35 | { "help", no_argument, NULL, 'h' }, |
| 36 | { "version", no_argument, NULL, 'v' }, |
| 37 | { "quiet", no_argument, NULL, 'q' }, |
| 38 | { NULL, 0, NULL, 0 }, |
| 39 | }; |
| 40 | |
| 41 | const char version_etc_copyright[] = |
| 42 | "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc."; |
| 43 | |
| 44 | #define AUTHORS "John J. Boyer" |
| 45 | |
| 46 | static int quiet_flag = 0; |
| 47 | |
| 48 | static void |
| 49 | print_help(void) { |
| 50 | printf("\ |
| 51 | Usage: %s [OPTIONS] TABLE[,TABLE,...]\n", |
| 52 | program_name); |
| 53 | |
| 54 | fputs("\ |
| 55 | Test a Braille translation table. If the table contains errors,\n\ |
| 56 | appropriate messages are displayed. If there are no errors the\n\ |
| 57 | message \"no errors found.\" is shown unless you specify the --quiet\n\ |
| 58 | option.\n", |
| 59 | stdout); |
| 60 | |
| 61 | fputs("\ |
| 62 | -h, --help display this help and exit\n\ |
| 63 | -v, --version display version information and exit\n\ |
| 64 | -q, --quiet do not write to standard error if there are no errors.\n", |
| 65 | stdout); |
| 66 | |
| 67 | printf("\n"); |
| 68 | printf("Report bugs to %s.\n", PACKAGE_BUGREPORT); |
| 69 | |
| 70 | #ifdef PACKAGE_PACKAGER_BUG_REPORTS |
| 71 | printf("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS); |
| 72 | #endif |
| 73 | #ifdef PACKAGE_URL |
| 74 | printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL); |
| 75 | #endif |
| 76 | } |
| 77 | |
| 78 | int |
| 79 | main(int argc, char **argv) { |
| 80 | const TranslationTableHeader *table; |
| 81 | int optc; |
| 82 | |
| 83 | set_program_name(argv[0]); |
| 84 | |
| 85 | while ((optc = getopt_long(argc, argv, "hvq", longopts, NULL)) != -1) switch (optc) { |
| 86 | /* --help and --version exit immediately, per GNU coding standards. */ |
| 87 | case 'v': |
| 88 | version_etc( |
| 89 | stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *)NULL); |
| 90 | exit(EXIT_SUCCESS); |
| 91 | break; |
| 92 | case 'h': |
| 93 | print_help(); |
| 94 | exit(EXIT_SUCCESS); |
| 95 | break; |
| 96 | case 'q': |
| 97 | quiet_flag = 1; |
| 98 | break; |
| 99 | default: |
| 100 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); |
| 101 | exit(EXIT_FAILURE); |
| 102 | break; |
| 103 | } |
| 104 | |
| 105 | if (optind != argc - 1) { |
| 106 | /* Print error message and exit. */ |
| 107 | if (optind < argc - 1) |
| 108 | fprintf(stderr, "%s: extra operand: %s\n", program_name, argv[optind + 1]); |
| 109 | else |
| 110 | fprintf(stderr, "%s: no table specified\n", program_name); |
| 111 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); |
| 112 | exit(EXIT_FAILURE); |
| 113 | } |
| 114 | |
| 115 | if (!(table = lou_getTable(argv[optind]))) { |
| 116 | lou_free(); |
| 117 | exit(EXIT_FAILURE); |
| 118 | } |
| 119 | if (quiet_flag == 0) fprintf(stderr, "No errors found.\n"); |
| 120 | lou_free(); |
| 121 | exit(EXIT_SUCCESS); |
| 122 | } |