summaryrefslogtreecommitdiffabout
path: root/gram.y
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-05 07:16:29 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-03-05 07:16:29 (GMT)
commitf142ee94c2fa3d5f8ec3686b2ced2e1f0b807def (patch) (side-by-side diff)
tree6a150aea4679db77420db91c26e6a93865abbe65 /gram.y
parenta75760ff7d9bedcb1377fc3441f5e38178da1d6a (diff)
downloadalck-f142ee94c2fa3d5f8ec3686b2ced2e1f0b807def.tar.gz
alck-f142ee94c2fa3d5f8ec3686b2ced2e1f0b807def.tar.bz2
Revamp as a standalone project. Remove unneeded dependencies.
* Makefile.am: Remove * Makefile: Restore from bc518485 * ckaliases.c: Rename to alck.c * ckaliases.h: Rename to alck.h * gram.y (emalloc, error) (syserror, parserror): New functions. (main): Use traditional getopt. * lex.l: Use slist instead of obstack. * slist.c: New file.
Diffstat (limited to 'gram.y') (more/less context) (ignore whitespace changes)
-rw-r--r--gram.y115
1 files changed, 83 insertions, 32 deletions
diff --git a/gram.y b/gram.y
index 34d46e2..4da7cb2 100644
--- a/gram.y
+++ b/gram.y
@@ -15,8 +15,10 @@
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "ckaliases.h"
-
+#include "alck.h"
+#include <stdarg.h>
+
+char *program_name;
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 */
@@ -111,9 +113,53 @@ string: IDENT
int
yyerror (char *s)
{
- error_at_line(0, 0, file_name, line_num, "%s", s);
+ parserror(file_name, line_num, "%s", s);
error_count++;
}
+
+void *
+emalloc(size_t size)
+{
+ void *p = malloc(size);
+ if (!p) {
+ error("not enough memory");
+ exit(1);
+ }
+ return p;
+}
+
+void
+error(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(stderr, "%s: ", program_name);
+ vfprintf(stderr, fmt, ap);
+ fputc('\n', stderr);
+ va_end(ap);
+}
+
+void
+syserror(int ec, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(stderr, "%s: ", program_name);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": %s\n", strerror(ec));
+ va_end(ap);
+}
+
+void
+parserror(const char *file, int line, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(stderr, "%s: %s:%d: ", program_name, file, line);
+ vfprintf(stderr, fmt, ap);
+ fputc('\n', stderr);
+ va_end(ap);
+}
void
@@ -122,36 +168,40 @@ 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(" -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(" -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(" -f FILE Read names of alias files from FILE\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, --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(" -u Revert the effect of the previous -r option\n");
+ printf(" -v Verbose mode\n");
+ printf(" -V 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("Report bugs to <%s>\n", "gray@gnu.org");
}
-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 }
-};
+static char license[] = "\
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
+This is free software: you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law.\n";
+
+#define VERSION "2.0"
+
+void
+version()
+{
+ printf("alck %s\n", VERSION);
+ printf("Copyright (C) 2005, 2007, 2013 Sergey Poznyakoff\n");
+ printf("%s\n", license);
+ exit(0);
+}
int
main(int argc, char **argv)
@@ -164,11 +214,9 @@ main(int argc, char **argv)
SLIST *file_list; /* List of files to be read */
struct string_list *s;
- begin_aliases();
- init_lex ();
+ init_lex();
program_name = argv[0];
- while ((c = getopt_long(argc, argv, "-d:f:hp:ruvw:",
- options, NULL)) != EOF) {
+ while ((c = getopt(argc, argv, "-d:f:hp:ruVvw:")) != EOF) {
switch (c) {
case 1:
if (!cw_list)
@@ -198,7 +246,8 @@ main(int argc, char **argv)
break;
default:
- error(1, 0, "%s: unknown debug option %c", argv[0]);
+ error("%s: unknown debug option %c",
+ argv[0], c);
}
}
break;
@@ -235,12 +284,12 @@ main(int argc, char **argv)
break;
case 'V':
- gsc_version ("ckaliases");
+ version();
exit (0);
case 'w':
if (file_count)
- error(1, 0, "-w must be used before first non-option argument");
+ error("-w must be used before first non-option argument");
cwfile = optarg;
break;
@@ -260,9 +309,11 @@ main(int argc, char **argv)
file_count++;
}
- if (!file_count)
- error(1, 0, "no files specified");
-
+ if (!file_count) {
+ error("no files specified");
+ exit(1);
+ }
+
if (verbose)
printf("%d files\n", file_count);
end_aliases();

Return to:

Send suggestions and report system problems to the System administrator.