diff options
| author | David M. Syzdek <syzdek@bindlebinaries.com> | 2010-09-27 17:19:22 -0800 |
|---|---|---|
| committer | David M. Syzdek <syzdek@bindlebinaries.com> | 2010-09-27 17:19:22 -0800 |
| commit | beb80d3ef58cc3365a17613c4127354be82f88c6 (patch) | |
| tree | 8ecac8da3baaeecb8e085d5d23a82510da245ca2 /src/colors.c | |
| parent | 438c1f37dbf0dbd4cf29827d7df6f39f175f821e (diff) | |
| download | dmstools-beb80d3ef58cc3365a17613c4127354be82f88c6.tar.gz dmstools-beb80d3ef58cc3365a17613c4127354be82f88c6.tar.bz2 dmstools-beb80d3ef58cc3365a17613c4127354be82f88c6.tar.xz dmstools-beb80d3ef58cc3365a17613c4127354be82f88c6.zip | |
Adding version and help to colors.
Diffstat (limited to 'src/colors.c')
| -rw-r--r-- | src/colors.c | 93 |
1 files changed, 89 insertions, 4 deletions
diff --git a/src/colors.c b/src/colors.c index c3a4102..a8db1b1 100644 --- a/src/colors.c +++ b/src/colors.c | |||
| @@ -50,6 +50,7 @@ | |||
| 50 | #endif | 50 | #endif |
| 51 | 51 | ||
| 52 | #include <stdio.h> | 52 | #include <stdio.h> |
| 53 | #include <getopt.h> | ||
| 53 | 54 | ||
| 54 | 55 | ||
| 55 | /////////////////// | 56 | /////////////////// |
| @@ -105,8 +106,14 @@ | |||
| 105 | // // | 106 | // // |
| 106 | ////////////////// | 107 | ////////////////// |
| 107 | 108 | ||
| 109 | // displays usage | ||
| 110 | void colors_usage PARAMS((void)); | ||
| 111 | |||
| 112 | // displays version information | ||
| 113 | void colors_version PARAMS((void)); | ||
| 114 | |||
| 108 | // main statement | 115 | // main statement |
| 109 | int main PARAMS((void)); | 116 | int main PARAMS((int argc, char * argv[])); |
| 110 | 117 | ||
| 111 | 118 | ||
| 112 | ///////////////// | 119 | ///////////////// |
| @@ -115,13 +122,91 @@ int main PARAMS((void)); | |||
| 115 | // // | 122 | // // |
| 116 | ///////////////// | 123 | ///////////////// |
| 117 | 124 | ||
| 125 | /// displays usage | ||
| 126 | void colors_usage(void) | ||
| 127 | { | ||
| 128 | // TRANSLATORS: The following strings provide usage for command. These | ||
| 129 | // strings are displayed if the program is passed `--help' on the command | ||
| 130 | // line. The two strings referenced are: PROGRAM_NAME, and | ||
| 131 | // PACKAGE_BUGREPORT | ||
| 132 | printf(_("Usage: %s [OPTIONS]\n" | ||
| 133 | " -h, --help print this help and exit\n" | ||
| 134 | " -V, --version print version number and exit\n" | ||
| 135 | "\n" | ||
| 136 | "Report bugs to <%s>.\n" | ||
| 137 | ), PROGRAM_NAME, PACKAGE_BUGREPORT | ||
| 138 | ); | ||
| 139 | return; | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | /// displays version information | ||
| 144 | void colors_version(void) | ||
| 145 | { | ||
| 146 | // TRANSLATORS: The following strings provide version and copyright | ||
| 147 | // information if the program is passed --version on the command line. | ||
| 148 | // The three strings referenced are: PROGRAM_NAME, PACKAGE_NAME, | ||
| 149 | // PACKAGE_VERSION. | ||
| 150 | printf(_("%s (%s) %s\n" | ||
| 151 | "Written by David M. Syzdek.\n" | ||
| 152 | "\n" | ||
| 153 | "%s\n" | ||
| 154 | "This is free software; see the source for copying conditions. There is NO\n" | ||
| 155 | "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | ||
| 156 | ), PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_COPYRIGHT | ||
| 157 | ); | ||
| 158 | return; | ||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 118 | /// main statement | 162 | /// main statement |
| 119 | /// @param[in] argc number of arguments passed to program | 163 | /// @param[in] argc number of arguments passed to program |
| 120 | /// @param[in] argv array of arguments passed to program | 164 | /// @param[in] argv array of arguments passed to program |
| 121 | int main(void) | 165 | int main(int argc, char * argv[]) |
| 122 | { | 166 | { |
| 123 | int x; | 167 | int c; |
| 124 | int y; | 168 | int x; |
| 169 | int y; | ||
| 170 | int opt_index; | ||
| 171 | |||
| 172 | static char short_opt[] = "hV"; | ||
| 173 | static struct option long_opt[] = | ||
| 174 | { | ||
| 175 | {"help", no_argument, 0, 'h'}, | ||
| 176 | {"version", no_argument, 0, 'V'}, | ||
| 177 | {NULL, 0, 0, 0 } | ||
| 178 | }; | ||
| 179 | |||
| 180 | #ifdef HAVE_GETTEXT | ||
| 181 | setlocale (LC_ALL, ""); | ||
| 182 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
| 183 | textdomain (PACKAGE); | ||
| 184 | #endif | ||
| 185 | |||
| 186 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) | ||
| 187 | { | ||
| 188 | switch(c) | ||
| 189 | { | ||
| 190 | case -1: /* no more arguments */ | ||
| 191 | case 0: /* long options toggles */ | ||
| 192 | break; | ||
| 193 | case 'h': | ||
| 194 | colors_usage(); | ||
| 195 | return(0); | ||
| 196 | case 'V': | ||
| 197 | colors_version(); | ||
| 198 | return(0); | ||
| 199 | case '?': | ||
| 200 | fprintf(stderr, _("Try `%s --help' for more information.\n"), PROGRAM_NAME); | ||
| 201 | return(1); | ||
| 202 | default: | ||
| 203 | fprintf(stderr, _("%s: unrecognized option `--%c'\n" | ||
| 204 | "Try `%s --help' for more information.\n" | ||
| 205 | ), PROGRAM_NAME, c, PROGRAM_NAME | ||
| 206 | ); | ||
| 207 | return(1); | ||
| 208 | }; | ||
| 209 | }; | ||
| 125 | 210 | ||
| 126 | for (y = 0; y < 9; y++) | 211 | for (y = 0; y < 9; y++) |
| 127 | { | 212 | { |
