aboutsummaryrefslogtreecommitdiff
path: root/gram.y
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-08-24 20:38:54 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-08-24 20:38:54 +0000
commitab736c0b1959c6c605c210d5fd9665bfe002042e (patch)
treee23a335c9a0e81505c9c06ba089e776200e1d443 /gram.y
parented4ec220dcfcba29a7fc8ff161999c32a98e4430 (diff)
downloadalck-ab736c0b1959c6c605c210d5fd9665bfe002042e.tar.gz
alck-ab736c0b1959c6c605c210d5fd9665bfe002042e.tar.bz2
* lib/version.c: New file
* lib/gsc.h (gsc_version): New function * cvs/Makefile.am, ckaliases/Makefile.am, wydawca/Makefile.am, lib/Makefile.am, jabberd/Makefile.am: Fix include dirs * ckaliases/ckaliases.c, ckaliases/lex.l, ckaliases/ckaliases.h, ckaliases/gram.y: Use long options. Implement --version * wydawca/wydawca.c, jabberd/main.c: Use gsc_version to display program version. * doc/gsc.texi: Update * bootstrap: Add vasprintf git-svn-id: file:///svnroot/gsc/trunk@289 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (limited to 'gram.y')
-rw-r--r--gram.y336
1 files changed, 172 insertions, 164 deletions
diff --git a/gram.y b/gram.y
index d20f9d8..92346c7 100644
--- a/gram.y
+++ b/gram.y
@@ -2,3 +2,3 @@
/* ckaliases - verify syntax of sendmail-style alias files
- Copyright (C) 2005 Sergey Poznyakoff
+ Copyright (C) 2005, 2007 Sergey Poznyakoff
@@ -17,7 +17,2 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <getopt.h>
-#include <errno.h>
#include "ckaliases.h"
@@ -25,6 +20,6 @@
SLIST *cw_list; /* List of domain names pertaining to Sendmail 'w' class */
-static int restricted; /* prohibit use of `special' aliases (pipes, file redirections
- and includes */
-int verbose; /* Verbose mode */
-static int error_count; /* Number of errors detected so far */
+static int restricted; /* prohibit use of `special' aliases (pipes,
+ file redirections and includes */
+int verbose; /* Verbose mode */
+int error_count; /* Number of errors detected so far */
%}
@@ -32,4 +27,4 @@ static int error_count; /* Number of errors detected so far */
%union {
- char *string;
- SLIST *slist;
+ char *string;
+ SLIST *slist;
};
@@ -53,4 +48,4 @@ list : alias
{
- yyclearin;
- yyerrok;
+ yyclearin;
+ yyerrok;
}
@@ -61,3 +56,3 @@ alias : /* empty */
{
- regalias($1, $2);
+ regalias ($1, $2);
}
@@ -71,4 +66,4 @@ rhs : emails
{
- slist_append(&$1, $3);
- $$ = $1;
+ slist_append (&$1, $3);
+ $$ = $1;
}
@@ -79,4 +74,4 @@ emails: email
{
- slist_append(&$1, $3);
- $$ = $1;
+ slist_append (&$1, $3);
+ $$ = $1;
}
@@ -86,8 +81,9 @@ 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);
}
@@ -95,4 +91,4 @@ email : string
{
- $$ = NULL;
- slist_add(&$$, $1);
+ $$ = NULL;
+ slist_add (&$$, $1);
}
@@ -100,8 +96,9 @@ email : 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);
}
@@ -115,154 +112,165 @@ string: IDENT
-void
-error(char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
- va_end(ap);
- fprintf(stderr, "\n");
- error_count++;
-}
-
-yyerror(char *s)
+int
+yyerror (char *s)
{
- error("%s:%d: %s", file_name, line_num, s);
+ 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 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(" -h Display this help list\n");
- printf(" -r Restrict alias file syntax to aliases only (i.e.\n");
- printf(" prohibit use of pipes and file redirections\n");
- printf(" -u Revert the effect of the previous -r option\n");
- printf(" -v Verbose mode\n");
- printf(" -w FILE Read contents of Sendmail `w' class from the given\n");
- printf(" file.\n");
+ 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");
}
+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 }
+};
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();
- while ((c = getopt(argc, argv, "-d:f:hp:ruvw:")) != 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:
- fprintf(stderr, "%s: unknown debug option %c\n",
- argv[0], *p);
- exit(1);
- }
- }
- break;
-
- case 'f':
- if (!cw_list)
- read_include(&cw_list, cwfile);
- file_list = NULL;
- read_include(&file_list, optarg);
- 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 'r':
- restricted = 1;
- break;
-
- case 'u':
- restricted = 0;
- 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;
- case 'v':
- verbose++;
- break;
-
- case 'w':
- if (file_count) {
- error("-w must be used before first non-option argument");
- exit(1);
- }
- cwfile = optarg;
- break;
-
default:
- exit(1);
+ 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);
+ 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);
- argc -= optind;
- argv += optind;
+ case 'r':
+ restricted = 1;
+ break;
+
+ case 'u':
+ restricted = 0;
+ break;
+
+ case 'v':
+ verbose++;
+ break;
- if (!cw_list)
- read_include(&cw_list, cwfile);
- while (argc--) {
- openaliases(*argv++);
- yyparse();
- file_count++;
+ 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;
+
+ default:
+ exit (1);
}
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (!cw_list)
+ read_include (&cw_list, cwfile);
+ while (argc--)
+ {
+ openaliases (*argv++);
+ yyparse ();
+ file_count++;
+ }
- if (!file_count) {
- error("no files specified");
- exit(1);
- }
+ 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);
}

Return to:

Send suggestions and report system problems to the System administrator.