diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-04 21:44:25 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-04 21:44:25 +0200 |
commit | a75760ff7d9bedcb1377fc3441f5e38178da1d6a (patch) | |
tree | 39413a06ee259848dfc2cb585a357ddac5d2d4ca /gram.y | |
parent | 860ec4960ff61cf3b2e98e0d020e7f8a93a56008 (diff) | |
download | alck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.gz alck-a75760ff7d9bedcb1377fc3441f5e38178da1d6a.tar.bz2 |
Switch to a "right" style.
Diffstat (limited to 'gram.y')
-rw-r--r-- | gram.y | 330 |
1 files changed, 161 insertions, 169 deletions
@@ -25,8 +25,8 @@ int error_count; /* Number of errors detected so far */ %} %union { - char *string; - SLIST *slist; + char *string; + SLIST *slist; }; %token <string> IDENT EMAIL STRING LHS @@ -46,15 +46,15 @@ list : alias | list EOL alias | list error EOL { - yyclearin; - yyerrok; + yyclearin; + yyerrok; } ; alias : /* empty */ | lhs rhs { - regalias ($1, $2); + regalias($1, $2); } ; @@ -64,43 +64,41 @@ lhs : LHS ':' rhs : emails | rhs CONT emails { - slist_append (&$1, $3); - $$ = $1; + slist_append(&$1, $3); + $$ = $1; } ; emails: email | emails ',' email { - slist_append (&$1, $3); - $$ = $1; + slist_append(&$1, $3); + $$ = $1; } ; email : string { - if (restricted && ($1[0] == '|' || $1[0] == '/')) - { - yyerror ("Construct not allowed"); - YYERROR; - } - $$ = NULL; - slist_add (&$$, $1); + if (restricted && ($1[0] == '|' || $1[0] == '/')) { + yyerror("Construct not allowed"); + YYERROR; + } + $$ = NULL; + slist_add(&$$, $1); } | EMAIL { - $$ = NULL; - slist_add (&$$, $1); + $$ = NULL; + slist_add(&$$, $1); } | INCLUDE string { - if (restricted) - { - yyerror ("Include statement is not allowed"); - YYERROR; - } - $$ = NULL; - read_include (&$$, $2); + if (restricted) { + yyerror("Include statement is not allowed"); + YYERROR; + } + $$ = NULL; + read_include(&$$, $2); } ; @@ -113,169 +111,163 @@ string: IDENT int yyerror (char *s) { - error_at_line (0, 0, file_name, line_num, "%s", s); - error_count++; + error_at_line(0, 0, file_name, line_num, "%s", s); + error_count++; } void -usage () +usage() { - printf ("usage: ckaliases [OPTIONS] [FILES...]\n"); - printf ("OPTIONS and FILES may be interspered.\n"); - printf ("Valid options are:\n"); - printf (" -d,--debug=SPEC Set debug level. SPEC consists of the following\n"); - printf (" letters:\n"); - printf (" y enable parser debugging\n"); - printf (" l enable lexical analizer debugging\n"); - printf (" Upper-case variants are also accepted. Prepending\n"); - printf (" a letter with '-' reverts its sense\n"); - printf (" -f, --files-from=FILE\n"); - printf (" Read names of alias files from FILE\n"); - printf (" -h, --help Display this help list\n"); - printf (" -r, --restrict Restrict alias file syntax to aliases only (i.e.\n"); - printf (" prohibit use of pipes and file redirections\n"); - printf (" -u, --unrestrict Revert the effect of the previous -r option\n"); - printf (" -v, --verbose Verbose mode\n"); - printf (" -V, --version print program version and exit\n"); - printf (" -w FILE Read contents of Sendmail `w' class from the given\n"); - printf (" file.\n"); - printf ("\n"); - printf ("Report bugs to <%s>\n", PACKAGE_BUGREPORT); + printf("usage: ckaliases [OPTIONS] [FILES...]\n"); + printf("OPTIONS and FILES may be interspered.\n"); + printf("Valid options are:\n"); + printf(" -d,--debug=SPEC Set debug level. SPEC consists of the following\n"); + printf(" letters:\n"); + printf(" y enable parser debugging\n"); + printf(" l enable lexical analizer debugging\n"); + printf(" Upper-case variants are also accepted. Prepending\n"); + printf(" a letter with '-' reverts its sense\n"); + printf(" -f, --files-from=FILE\n"); + printf(" Read names of alias files from FILE\n"); + printf(" -h, --help Display this help list\n"); + printf(" -r, --restrict Restrict alias file syntax to aliases only (i.e.\n"); + printf(" prohibit use of pipes and file redirections\n"); + printf(" -u, --unrestrict Revert the effect of the previous -r option\n"); + printf(" -v, --verbose Verbose mode\n"); + printf(" -V, --version print program version and exit\n"); + printf(" -w FILE Read contents of Sendmail `w' class from the given\n"); + printf(" file.\n"); + printf("\n"); + printf("Report bugs to <%s>\n", PACKAGE_BUGREPORT); } struct option options[] = { - { "debug", required_argument, NULL, 'd' }, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, - { "restrict", no_argument, NULL, 'r' }, - { "unrestrict", no_argument, NULL, 'u' }, - { "verbose", no_argument, NULL, 'v' }, - { "files-from", required_argument, NULL, 'f' }, - { NULL } + { "debug", required_argument, NULL, 'd' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, + { "restrict", no_argument, NULL, 'r' }, + { "unrestrict", no_argument, NULL, 'u' }, + { "verbose", no_argument, NULL, 'v' }, + { "files-from", required_argument, NULL, 'f' }, + { NULL } }; int -main (int argc, char **argv) +main(int argc, char **argv) { - char *p; - int c; - int file_count = 0; - int true = 1; - char *cwfile = "/etc/mail/sendmail.cw"; - SLIST *file_list; /* List of files to be read */ - struct string_list *s; + char *p; + int c; + int file_count = 0; + int true = 1; + char *cwfile = "/etc/mail/sendmail.cw"; + SLIST *file_list; /* List of files to be read */ + struct string_list *s; - begin_aliases (); - init_lex (); - program_name = argv[0]; - while ((c = getopt_long (argc, argv, "-d:f:hp:ruvw:", options, NULL)) != EOF) - { - switch (c) - { - case 1: - if (!cw_list) - read_include (&cw_list, cwfile); - openaliases (optarg); - yyparse (); - file_count++; - break; + begin_aliases(); + init_lex (); + program_name = argv[0]; + while ((c = getopt_long(argc, argv, "-d:f:hp:ruvw:", + options, NULL)) != EOF) { + switch (c) { + case 1: + if (!cw_list) + read_include(&cw_list, cwfile); + openaliases(optarg); + yyparse(); + file_count++; + break; - case 'd': - for (p = optarg; *p; p++) - { - switch (*p) - { - case '-': - true = 0; - break; - - case 'y': - case 'Y': - yydebug = true; - true = 1; - break; - - case 'l': - case 'L': - lex_debug (true); - true = 1; - break; - - default: - error (1, 0, "%s: unknown debug option %c", argv[0]); - } - } - break; - - case 'f': - if (!cw_list) - read_include (&cw_list, cwfile); - file_list = NULL; - read_include (&file_list, optarg); - if (file_list) - { - for (s = file_list->head; s; s = s->next) - { - openaliases_prefix (optarg, s->str); - yyparse (); - file_count++; - } - slist_destroy (&file_list); - } - break; + case 'd': + for (p = optarg; *p; p++) { + switch (*p) { + case '-': + true = 0; + break; + + case 'y': + case 'Y': + yydebug = true; + true = 1; + break; + + case 'l': + case 'L': + lex_debug(true); + true = 1; + break; + + default: + error(1, 0, "%s: unknown debug option %c", argv[0]); + } + } + break; + + case 'f': + if (!cw_list) + read_include(&cw_list, cwfile); + file_list = NULL; + read_include(&file_list, optarg); + if (file_list) { + for (s = file_list->head; s; s = s->next) { + openaliases_prefix(optarg, s->str); + yyparse(); + file_count++; + } + slist_destroy(&file_list); + } + break; - case 'h': - usage (); - exit (0); + case 'h': + usage(); + exit(0); - case 'r': - restricted = 1; - break; - - case 'u': - restricted = 0; - break; - - case 'v': - verbose++; - break; + case 'r': + restricted = 1; + break; + + case 'u': + restricted = 0; + break; + + case 'v': + verbose++; + break; - case 'V': - gsc_version ("ckaliases"); - exit (0); - - case 'w': - if (file_count) - error (1, 0, "-w must be used before first non-option argument"); - cwfile = optarg; - break; + case 'V': + gsc_version ("ckaliases"); + exit (0); - default: - exit (1); + case 'w': + if (file_count) + error(1, 0, "-w must be used before first non-option argument"); + cwfile = optarg; + break; + + default: + exit (1); + } + } + + argc -= optind; + argv += optind; + + if (!cw_list) + read_include(&cw_list, cwfile); + while (argc--) { + openaliases(*argv++); + yyparse(); + file_count++; } - } - - argc -= optind; - argv += optind; - - if (!cw_list) - read_include (&cw_list, cwfile); - while (argc--) - { - openaliases (*argv++); - yyparse (); - file_count++; - } - if (!file_count) - error (1, 0, "no files specified"); + if (!file_count) + error(1, 0, "no files specified"); - if (verbose) - printf ("%d files\n", file_count); - end_aliases (); - check_aliases (); - if (verbose) - printf ("%lu errors\n", error_count); - exit (error_count!=0); + if (verbose) + printf("%d files\n", file_count); + end_aliases(); + check_aliases(); + if (verbose) + printf("%lu errors\n", error_count); + exit(error_count!=0); } |