Deleted Added
full compact
options.cc (58551) options.cc (67064)
1/* Handles parsing the Options provided to the user.
1/* Handles parsing the Options provided to the user.
2 Copyright (C) 1989-1998 Free Software Foundation, Inc.
2 Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc.
3 written by Douglas C. Schmidt (schmidt@ics.uci.edu)
4
5This file is part of GNU GPERF.
6
7GNU GPERF is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 1, or (at your option)
10any later version.

--- 27 unchanged lines hidden (view full) ---

38static const int DEFAULT_JUMP_VALUE = 5;
39
40/* Default name for generated lookup function. */
41static const char *const DEFAULT_NAME = "in_word_set";
42
43/* Default name for the key component. */
44static const char *const DEFAULT_KEY = "name";
45
3 written by Douglas C. Schmidt (schmidt@ics.uci.edu)
4
5This file is part of GNU GPERF.
6
7GNU GPERF is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 1, or (at your option)
10any later version.

--- 27 unchanged lines hidden (view full) ---

38static const int DEFAULT_JUMP_VALUE = 5;
39
40/* Default name for generated lookup function. */
41static const char *const DEFAULT_NAME = "in_word_set";
42
43/* Default name for the key component. */
44static const char *const DEFAULT_KEY = "name";
45
46/* Default struct initializer suffix. */
47static const char *const DEFAULT_INITIALIZER_SUFFIX = "";
48
46/* Default name for the generated class. */
47static const char *const DEFAULT_CLASS_NAME = "Perfect_Hash";
48
49/* Default name for generated hash function. */
50static const char *const DEFAULT_HASH_NAME = "hash";
51
52/* Default name for generated hash table array. */
53static const char *const DEFAULT_WORDLIST_NAME = "wordlist";

--- 8 unchanged lines hidden (view full) ---

62int Options::key_pos;
63int Options::jump;
64int Options::initial_asso_value;
65int Options::argument_count;
66int Options::iterations;
67char **Options::argument_vector;
68const char *Options::function_name;
69const char *Options::key_name;
49/* Default name for the generated class. */
50static const char *const DEFAULT_CLASS_NAME = "Perfect_Hash";
51
52/* Default name for generated hash function. */
53static const char *const DEFAULT_HASH_NAME = "hash";
54
55/* Default name for generated hash table array. */
56static const char *const DEFAULT_WORDLIST_NAME = "wordlist";

--- 8 unchanged lines hidden (view full) ---

65int Options::key_pos;
66int Options::jump;
67int Options::initial_asso_value;
68int Options::argument_count;
69int Options::iterations;
70char **Options::argument_vector;
71const char *Options::function_name;
72const char *Options::key_name;
73const char *Options::initializer_suffix;
70const char *Options::class_name;
71const char *Options::hash_name;
72const char *Options::wordlist_name;
73const char *Options::delimiters;
74char Options::key_positions[MAX_KEY_POS];
75
76/* Prints program usage to given stream. */
77
78void
79Options::short_usage (FILE * strm)
80{
81 T (Trace t ("Options::short_usage");)
74const char *Options::class_name;
75const char *Options::hash_name;
76const char *Options::wordlist_name;
77const char *Options::delimiters;
78char Options::key_positions[MAX_KEY_POS];
79
80/* Prints program usage to given stream. */
81
82void
83Options::short_usage (FILE * strm)
84{
85 T (Trace t ("Options::short_usage");)
82 fprintf (strm, "Usage: %s [-cCdDef[num]GhHiIjkKlLnNorsStTvWZ7] [input-file]\n"
86 fprintf (strm, "Usage: %s [-cCdDef[num]F<initializers>GhH<hashname>i<init>Ijk<keys>K<keyname>lL<language>nN<function name>ors<size>S<switches>tTvW<wordlistname>Z<class name>7] [input-file]\n"
83 "Try `%s --help' for more information.\n",
84 program_name, program_name);
85}
86
87void
88Options::long_usage (FILE * strm)
89{
90 T (Trace t ("Options::long_usage");)

--- 20 unchanged lines hidden (view full) ---

111 " -L, --language=LANGUAGE-NAME\n"
112 " Generates code in the specified language. Languages\n"
113 " handled are currently C++, ANSI-C, C, and KR-C. The\n"
114 " default is C.\n"
115 "\n"
116 "Details in the output code:\n"
117 " -K, --slot-name=NAME Select name of the keyword component in the keyword\n"
118 " structure.\n"
87 "Try `%s --help' for more information.\n",
88 program_name, program_name);
89}
90
91void
92Options::long_usage (FILE * strm)
93{
94 T (Trace t ("Options::long_usage");)

--- 20 unchanged lines hidden (view full) ---

115 " -L, --language=LANGUAGE-NAME\n"
116 " Generates code in the specified language. Languages\n"
117 " handled are currently C++, ANSI-C, C, and KR-C. The\n"
118 " default is C.\n"
119 "\n"
120 "Details in the output code:\n"
121 " -K, --slot-name=NAME Select name of the keyword component in the keyword\n"
122 " structure.\n"
123 " -F, --initializer-suffix=INITIALIZERS\n"
124 " Initializers for additional components in the keyword\n"
125 " structure.\n"
119 " -H, --hash-fn-name=NAME\n"
120 " Specify name of generated hash function. Default is\n"
121 " `hash'.\n"
122 " -N, --lookup-fn-name=NAME\n"
123 " Specify name of generated lookup function. Default\n"
124 " name is `in_word_set'.\n"
125 " -Z, --class-name=NAME Specify name of generated C++ class. Default name is\n"
126 " `Perfect_Hash'.\n"

--- 90 unchanged lines hidden (view full) ---

217Options::print_options (void)
218{
219 T (Trace t ("Options::print_options");)
220 int i;
221
222 printf ("/* Command-line: ");
223
224 for (i = 0; i < argument_count; i++)
126 " -H, --hash-fn-name=NAME\n"
127 " Specify name of generated hash function. Default is\n"
128 " `hash'.\n"
129 " -N, --lookup-fn-name=NAME\n"
130 " Specify name of generated lookup function. Default\n"
131 " name is `in_word_set'.\n"
132 " -Z, --class-name=NAME Specify name of generated C++ class. Default name is\n"
133 " `Perfect_Hash'.\n"

--- 90 unchanged lines hidden (view full) ---

224Options::print_options (void)
225{
226 T (Trace t ("Options::print_options");)
227 int i;
228
229 printf ("/* Command-line: ");
230
231 for (i = 0; i < argument_count; i++)
225 printf ("%s ", argument_vector[i]);
232 {
233 const char *arg = argument_vector[i];
226
234
235 /* Escape arg if it contains shell metacharacters. */
236 if (*arg == '-')
237 {
238 putchar (*arg);
239 arg++;
240 if (*arg >= 'A' && *arg <= 'Z' || *arg >= 'a' && *arg <= 'z')
241 {
242 putchar (*arg);
243 arg++;
244 }
245 }
246 if (strpbrk (arg, "\t\n !\"#$&'()*;<>?[\\]`{|}~") != NULL)
247 {
248 if (strchr (arg, '\'') != NULL)
249 {
250 putchar ('"');
251 for (; *arg; arg++)
252 {
253 if (*arg == '\"' || *arg == '\\' || *arg == '$')
254 putchar ('\\');
255 putchar (*arg);
256 }
257 putchar ('"');
258 }
259 else
260 {
261 putchar ('\'');
262 for (; *arg; arg++)
263 {
264 if (*arg == '\\')
265 putchar ('\\');
266 putchar (*arg);
267 }
268 putchar ('\'');
269 }
270 }
271 else
272 printf ("%s", arg);
273
274 printf (" ");
275 }
276
227 printf (" */");
228}
229
230/* Sorts the key positions *IN REVERSE ORDER!!*
231 This makes further routines more efficient. Especially when generating code.
232 Uses a simple Insertion Sort since the set is probably ordered.
233 Returns 1 if there are no duplicates, 0 otherwise. */
234

--- 26 unchanged lines hidden (view full) ---

261 key_positions[1] = WORD_END;
262 key_positions[2] = EOS;
263 total_keysig_size = 2;
264 delimiters = DEFAULT_DELIMITERS;
265 jump = DEFAULT_JUMP_VALUE;
266 option_word = DEFAULTCHARS | C;
267 function_name = DEFAULT_NAME;
268 key_name = DEFAULT_KEY;
277 printf (" */");
278}
279
280/* Sorts the key positions *IN REVERSE ORDER!!*
281 This makes further routines more efficient. Especially when generating code.
282 Uses a simple Insertion Sort since the set is probably ordered.
283 Returns 1 if there are no duplicates, 0 otherwise. */
284

--- 26 unchanged lines hidden (view full) ---

311 key_positions[1] = WORD_END;
312 key_positions[2] = EOS;
313 total_keysig_size = 2;
314 delimiters = DEFAULT_DELIMITERS;
315 jump = DEFAULT_JUMP_VALUE;
316 option_word = DEFAULTCHARS | C;
317 function_name = DEFAULT_NAME;
318 key_name = DEFAULT_KEY;
319 initializer_suffix = DEFAULT_INITIALIZER_SUFFIX;
269 hash_name = DEFAULT_HASH_NAME;
270 wordlist_name = DEFAULT_WORDLIST_NAME;
271 class_name = DEFAULT_CLASS_NAME;
272 total_switches = size = 1;
273 initial_asso_value = iterations = 0;
274}
275
276/* Dumps option status when debug is set. */

--- 27 unchanged lines hidden (view full) ---

304 "\nENUM is........: %s"
305 "\nINCLUDE is.....: %s"
306 "\nSEVENBIT is....: %s"
307 "\niterations = %d"
308 "\nlookup function name = %s"
309 "\nhash function name = %s"
310 "\nword list name = %s"
311 "\nkey name = %s"
320 hash_name = DEFAULT_HASH_NAME;
321 wordlist_name = DEFAULT_WORDLIST_NAME;
322 class_name = DEFAULT_CLASS_NAME;
323 total_switches = size = 1;
324 initial_asso_value = iterations = 0;
325}
326
327/* Dumps option status when debug is set. */

--- 27 unchanged lines hidden (view full) ---

355 "\nENUM is........: %s"
356 "\nINCLUDE is.....: %s"
357 "\nSEVENBIT is....: %s"
358 "\niterations = %d"
359 "\nlookup function name = %s"
360 "\nhash function name = %s"
361 "\nword list name = %s"
362 "\nkey name = %s"
363 "\ninitializer suffix = %s"
312 "\njump value = %d"
313 "\nmax associated value = %d"
314 "\ninitial associated value = %d"
315 "\ndelimiters = %s"
316 "\nnumber of switch statements = %d\n",
317 option_word & DEBUG ? "enabled" : "disabled",
318 option_word & ORDER ? "enabled" : "disabled",
319 option_word & TYPE ? "enabled" : "disabled",

--- 12 unchanged lines hidden (view full) ---

332 option_word & C ? "enabled" : "disabled",
333 option_word & ANSIC ? "enabled" : "disabled",
334 option_word & CPLUSPLUS ? "enabled" : "disabled",
335 option_word & ENUM ? "enabled" : "disabled",
336 option_word & INCLUDE ? "enabled" : "disabled",
337 option_word & SEVENBIT ? "enabled" : "disabled",
338 iterations,
339 function_name, hash_name, wordlist_name, key_name,
364 "\njump value = %d"
365 "\nmax associated value = %d"
366 "\ninitial associated value = %d"
367 "\ndelimiters = %s"
368 "\nnumber of switch statements = %d\n",
369 option_word & DEBUG ? "enabled" : "disabled",
370 option_word & ORDER ? "enabled" : "disabled",
371 option_word & TYPE ? "enabled" : "disabled",

--- 12 unchanged lines hidden (view full) ---

384 option_word & C ? "enabled" : "disabled",
385 option_word & ANSIC ? "enabled" : "disabled",
386 option_word & CPLUSPLUS ? "enabled" : "disabled",
387 option_word & ENUM ? "enabled" : "disabled",
388 option_word & INCLUDE ? "enabled" : "disabled",
389 option_word & SEVENBIT ? "enabled" : "disabled",
390 iterations,
391 function_name, hash_name, wordlist_name, key_name,
340 jump, size - 1, initial_asso_value, delimiters, total_switches);
392 initializer_suffix, jump, size - 1, initial_asso_value,
393 delimiters, total_switches);
341 if (option_word & ALLCHARS)
342 fprintf (stderr, "all characters are used in the hash function\n");
343
344 fprintf (stderr, "maximum keysig size = %d\nkey positions are: \n",
345 total_keysig_size);
346
347 for (ptr = key_positions; *ptr != EOS; ptr++)
348 if (*ptr == WORD_END)

--- 9 unchanged lines hidden (view full) ---

358/* Parses the command line Options and sets appropriate flags in option_word. */
359
360static const struct option long_options[] =
361{
362 { "delimiters", required_argument, 0, 'e' },
363 { "struct-type", no_argument, 0, 't' },
364 { "language", required_argument, 0, 'L' },
365 { "slot-name", required_argument, 0, 'K' },
394 if (option_word & ALLCHARS)
395 fprintf (stderr, "all characters are used in the hash function\n");
396
397 fprintf (stderr, "maximum keysig size = %d\nkey positions are: \n",
398 total_keysig_size);
399
400 for (ptr = key_positions; *ptr != EOS; ptr++)
401 if (*ptr == WORD_END)

--- 9 unchanged lines hidden (view full) ---

411/* Parses the command line Options and sets appropriate flags in option_word. */
412
413static const struct option long_options[] =
414{
415 { "delimiters", required_argument, 0, 'e' },
416 { "struct-type", no_argument, 0, 't' },
417 { "language", required_argument, 0, 'L' },
418 { "slot-name", required_argument, 0, 'K' },
419 { "initializer-suffix", required_argument, 0, 'F' },
366 { "hash-fn-name", required_argument, 0, 'H' },
367 { "lookup-fn-name", required_argument, 0, 'N' },
368 { "class-name", required_argument, 0, 'Z' },
369 { "seven-bit", no_argument, 0, '7' },
370 { "compare-strncmp", no_argument, 0, 'c' },
371 { "readonly-tables", no_argument, 0, 'C' },
372 { "enum", no_argument, 0, 'E' },
373 { "includes", no_argument, 0, 'I' },

--- 24 unchanged lines hidden (view full) ---

398 int option_char;
399
400 program_name = argv[0];
401 argument_count = argc;
402 argument_vector = argv;
403
404 while ((option_char =
405 getopt_long (argument_count, argument_vector,
420 { "hash-fn-name", required_argument, 0, 'H' },
421 { "lookup-fn-name", required_argument, 0, 'N' },
422 { "class-name", required_argument, 0, 'Z' },
423 { "seven-bit", no_argument, 0, '7' },
424 { "compare-strncmp", no_argument, 0, 'c' },
425 { "readonly-tables", no_argument, 0, 'C' },
426 { "enum", no_argument, 0, 'E' },
427 { "includes", no_argument, 0, 'I' },

--- 24 unchanged lines hidden (view full) ---

452 int option_char;
453
454 program_name = argv[0];
455 argument_count = argc;
456 argument_vector = argv;
457
458 while ((option_char =
459 getopt_long (argument_count, argument_vector,
406 "adcCDe:Ef:gGhH:i:Ij:k:K:lL:nN:oprs:S:tTvW:Z:7",
460 "adcCDe:Ef:F:gGhH:i:Ij:k:K:lL:nN:oprs:S:tTvW:Z:7",
407 long_options, (int *)0))
408 != -1)
409 {
410 switch (option_char)
411 {
412 case 'a': /* Generated code uses the ANSI prototype format. */
413 break; /* This is now the default. */
414 case 'c': /* Generate strncmp rather than strcmp. */

--- 33 unchanged lines hidden (view full) ---

448 option_word |= FAST;
449 if ((iterations = atoi (/*getopt*/optarg)) < 0)
450 {
451 fprintf (stderr, "iterations value must not be negative, assuming 0\n");
452 iterations = 0;
453 }
454 break;
455 }
461 long_options, (int *)0))
462 != -1)
463 {
464 switch (option_char)
465 {
466 case 'a': /* Generated code uses the ANSI prototype format. */
467 break; /* This is now the default. */
468 case 'c': /* Generate strncmp rather than strcmp. */

--- 33 unchanged lines hidden (view full) ---

502 option_word |= FAST;
503 if ((iterations = atoi (/*getopt*/optarg)) < 0)
504 {
505 fprintf (stderr, "iterations value must not be negative, assuming 0\n");
506 iterations = 0;
507 }
508 break;
509 }
510 case 'F':
511 {
512 initializer_suffix = /*getopt*/optarg;
513 break;
514 }
456 case 'g': /* Use the ``inline'' keyword for generated sub-routines, ifdef __GNUC__. */
457 break; /* This is now the default. */
458 case 'G': /* Make the keyword table a global variable. */
459 {
515 case 'g': /* Use the ``inline'' keyword for generated sub-routines, ifdef __GNUC__. */
516 break; /* This is now the default. */
517 case 'G': /* Make the keyword table a global variable. */
518 {
460 option_word |= GLOBAL;
519 option_word |= GLOBAL;
461 break;
462 }
463 case 'h': /* Displays a list of helpful Options to the user. */
464 {
465 long_usage (stdout);
466 exit (0);
467 }
468 case 'H': /* Sets the name for the hash function */

--- 200 unchanged lines hidden ---
520 break;
521 }
522 case 'h': /* Displays a list of helpful Options to the user. */
523 {
524 long_usage (stdout);
525 exit (0);
526 }
527 case 'H': /* Sets the name for the hash function */

--- 200 unchanged lines hidden ---