/[public]/getopt/trunk/getopt.c
ViewVC logotype

Diff of /getopt/trunk/getopt.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 322 Revision 325
115 free(BUFFER); 115 free(BUFFER);
116 116
117 if (!quote) { 117 if (!quote) {
118 /* Just copy arg */ 118 /* Just copy arg */
119 BUFFER = xmalloc(strlen(arg) + 1); 119 BUFFER = xmalloc(strlen(arg) + 1);
120
121 strcpy(BUFFER, arg); 120 strcpy(BUFFER, arg);
122 return BUFFER; 121 return BUFFER;
123 } 122 }
124 123
125 /* 124 /*
221 * we already sent a message, we just exit with a helpful hint. 220 * we already sent a message, we just exit with a helpful hint.
222 */ 221 */
223static void __attribute__ ((__noreturn__)) parse_error(const char *message) 222static void __attribute__ ((__noreturn__)) parse_error(const char *message)
224{ 223{
225 if (message) 224 if (message)
226 fprintf(stderr, "getopt: %s\n", message); 225 fprintf(stderr, "%s: %s\n", program_invocation_short_name, message);
227 fputs(_("Try `getopt --help' for more information.\n"), stderr); 226 fprintf(stderr, _("Try `%s --help' for more information.\n"),
227 program_invocation_short_name);
228 exit(PARAMETER_EXIT_CODE); 228 exit(PARAMETER_EXIT_CODE);
229} 229}
230 230
231static struct option *long_options = NULL; 231static struct option *long_options = NULL;
232static int long_options_length = 0; /* Length of array */ 232static int long_options_length = 0; /* Length of array */
320{ 320{
321 fputs(_("Usage: getopt optstring parameters\n"), stderr); 321 fputs(_("Usage: getopt optstring parameters\n"), stderr);
322 fputs(_(" getopt [options] [--] optstring parameters\n"), stderr); 322 fputs(_(" getopt [options] [--] optstring parameters\n"), stderr);
323 fputs(_(" getopt [options] -o|--options optstring [options] [--]\n"), stderr); 323 fputs(_(" getopt [options] -o|--options optstring [options] [--]\n"), stderr);
324 fputs(_(" parameters\n"), stderr); 324 fputs(_(" parameters\n"), stderr);
325 fputs(_("\nOptions:\n"), stderr);
325 fputs(_(" -a, --alternative Allow long options starting with single -\n"), stderr); 326 fputs(_(" -a, --alternative Allow long options starting with single -\n"), stderr);
326 fputs(_(" -h, --help This small usage guide\n"), stderr); 327 fputs(_(" -h, --help This small usage guide\n"), stderr);
327 fputs(_(" -l, --longoptions=longopts Long options to be recognized\n"), stderr); 328 fputs(_(" -l, --longoptions <longopts> Long options to be recognized\n"), stderr);
328 fputs(_(" -n, --name=progname The name under which errors are reported\n"), stderr); 329 fputs(_(" -n, --name <progname> The name under which errors are reported\n"), stderr);
329 fputs(_(" -o, --options=optstring Short options to be recognized\n"), stderr); 330 fputs(_(" -o, --options <optstring> Short options to be recognized\n"), stderr);
330 fputs(_(" -q, --quiet Disable error reporting by getopt(3)\n"), stderr); 331 fputs(_(" -q, --quiet Disable error reporting by getopt(3)\n"), stderr);
331 fputs(_(" -Q, --quiet-output No normal output\n"), stderr); 332 fputs(_(" -Q, --quiet-output No normal output\n"), stderr);
332 fputs(_(" -s, --shell=shell Set shell quoting conventions\n"), stderr); 333 fputs(_(" -s, --shell <shell> Set shell quoting conventions\n"), stderr);
333 fputs(_(" -T, --test Test for getopt(1) version\n"), stderr); 334 fputs(_(" -T, --test Test for getopt(1) version\n"), stderr);
334 fputs(_(" -u, --unqote Do not quote the output\n"), stderr); 335 fputs(_(" -u, --unquote Do not quote the output\n"), stderr);
335 fputs(_(" -V, --version Output version information\n"), stderr); 336 fputs(_(" -V, --version Output version information\n"), stderr);
337 fputc('\n', stderr);
338
336 exit(PARAMETER_EXIT_CODE); 339 exit(PARAMETER_EXIT_CODE);
337} 340}
338 341
339int main(int argc, char *argv[]) 342int main(int argc, char *argv[])
340{ 343{
357 {"alternative", no_argument, NULL, 'a'}, 360 {"alternative", no_argument, NULL, 'a'},
358 {"name", required_argument, NULL, 'n'}, 361 {"name", required_argument, NULL, 'n'},
359 {"version", no_argument, NULL, 'V'}, 362 {"version", no_argument, NULL, 'V'},
360 {NULL, 0, NULL, 0} 363 {NULL, 0, NULL, 0}
361 }; 364 };
362#if WITHOUT_GETTEXT
363#else
364 setlocale(LC_ALL, ""); 365 setlocale(LC_ALL, "");
365 bindtextdomain(PACKAGE, LOCALEDIR); 366 bindtextdomain(PACKAGE, LOCALEDIR);
366 textdomain(PACKAGE); 367 textdomain(PACKAGE);
367#endif
368 368
369 init_longopt(); 369 init_longopt();
370 getopt_long_fp = getopt_long; 370 getopt_long_fp = getopt_long;
371 371
372 if (getenv("GETOPT_COMPATIBLE")) 372 if (getenv("GETOPT_COMPATIBLE"))
428 return TEST_EXIT_CODE; 428 return TEST_EXIT_CODE;
429 case 'u': 429 case 'u':
430 quote = 0; 430 quote = 0;
431 break; 431 break;
432 case 'V': 432 case 'V':
433 printf(_("getopt (enhanced) 1.1.4\n")); 433 printf(_("%s (enhanced) %s\n"), program_invocation_short_name, program_version);
434 return EXIT_SUCCESS; 434 return EXIT_SUCCESS;
435 case '?': 435 case '?':
436 case ':': 436 case ':':
437 parse_error(NULL); 437 parse_error(NULL);
438 default: 438 default:

Legend:
Removed from v.322  
changed lines
  Added in v.325

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26