summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2007-08-24 20:38:54 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2007-08-24 20:38:54 (GMT)
commitab736c0b1959c6c605c210d5fd9665bfe002042e (patch) (side-by-side diff)
treee23a335c9a0e81505c9c06ba089e776200e1d443
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 (more/less context) (show whitespace changes)
-rw-r--r--Makefile.am3
-rw-r--r--ckaliases.c82
-rw-r--r--ckaliases.h30
-rw-r--r--gram.y100
-rw-r--r--lex.l47
5 files changed, 138 insertions, 124 deletions
diff --git a/Makefile.am b/Makefile.am
index c43b7a3..12f531c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,9 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with GSC. If not, see <http://www.gnu.org/licenses/>.
-AM_INSTALLCHECK_STD_OPTIONS_EXEMPT=ckaliases
AM_YFLAGS=-vtd
AM_LFLAGS=-d
sbin_PROGRAMS=ckaliases
noinst_HEADERS=gram.h
ckaliases_SOURCES=gram.y lex.l ckaliases.c ckaliases.h
+LDADD=../lib/libgsc.a ../gnu/libgnu.a
+INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gnu -I../gnu
diff --git a/ckaliases.c b/ckaliases.c
index 343a52f..d77e62d 100644
--- a/ckaliases.c
+++ b/ckaliases.c
@@ -1,5 +1,5 @@
/* ckaliases - verify syntax of sendmail-style alias files
- Copyright (C) 2005 Sergey Poznyakoff
+ Copyright (C) 2005, 2007 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -14,28 +14,8 @@
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
#include "ckaliases.h"
-void *
-xmalloc(size_t size)
-{
- void *p = malloc(size);
- if (!p) {
- fprintf(stderr, "not enough memory\n");
- exit(1);
- }
- return p;
-}
-
-
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
@@ -70,18 +50,23 @@ TC(unsigned *R, int n)
cword = R;
mask = 1;
rowi = R;
- while (rowi < relend) {
+ while (rowi < relend)
+ {
ccol = cword;
rowj = R;
- while (rowj < relend) {
- if (*ccol & mask) {
+ while (rowj < relend)
+ {
+ if (*ccol & mask)
+ {
rp = rowi;
rend = (unsigned *) ((char *) rowj + rowsize);
while (rowj < rend)
*rowj++ |= *rp++;
- } else {
+ }
+ else
+ {
rowj = (unsigned *) ((char *) rowj + rowsize);
}
@@ -89,7 +74,8 @@ TC(unsigned *R, int n)
}
mask <<= 1;
- if (mask == 0) {
+ if (mask == 0)
+ {
mask = 1;
cword++;
}
@@ -98,7 +84,6 @@ TC(unsigned *R, int n)
}
-
void
slist_add(SLIST **plist, char *str)
{
@@ -106,15 +91,19 @@ slist_add(SLIST **plist, char *str)
p->str = str;
p->next = NULL;
- if (!*plist) {
+ if (!*plist)
+ {
*plist = xmalloc(sizeof(**plist));
(*plist)->head = NULL;
}
- if ((*plist)->head == NULL) {
+ if ((*plist)->head == NULL)
+ {
(*plist)->head = p;
(*plist)->count = 0;
- } else {
+ }
+ else
+ {
(*plist)->tail->next = p;
(*plist)->count++;
}
@@ -126,7 +115,8 @@ slist_append(SLIST **pdst, SLIST *src)
{
struct string_list *tail;
- if (!*pdst) {
+ if (!*pdst)
+ {
*pdst = xmalloc(sizeof(**pdst));
(*pdst)->head = NULL;
(*pdst)->count = 0;
@@ -161,7 +151,8 @@ slist_destroy(SLIST **plist)
if (!plist || !*plist)
return;
p = (*plist)->head;
- while (p) {
+ while (p)
+ {
struct string_list *next = p->next;
free(p);
p = next;
@@ -171,9 +162,8 @@ slist_destroy(SLIST **plist)
}
-
-
-typedef struct {
+typedef struct
+{
char *name;
SLIST *exp;
} ALIAS;
@@ -238,7 +228,10 @@ end_aliases()
qsort(aliases, alias_count, sizeof aliases[0], alias_cmp);
for (i = 1; i < alias_count; i++)
if (alias_cmp(aliases + i - 1, aliases + i) == 0)
- error("alias `%s' multiply defined", aliases[i].name);
+ {
+ error (0, 0, "alias `%s' multiply defined", aliases[i].name);
+ error_count++;
+ }
}
@@ -273,10 +266,13 @@ mark_connected(unsigned *r, unsigned size)
{
int i;
- for (i = 0; i < alias_count; i++) {
- if (aliases[i].exp) {
+ for (i = 0; i < alias_count; i++)
+ {
+ if (aliases[i].exp)
+ {
struct string_list *p;
- for (p = aliases[i].exp->head; p; p = p->next) {
+ for (p = aliases[i].exp->head; p; p = p->next)
+ {
int n = find_alias(p->str);
if (n >= 0)
alias_setbit(r, size, i, n);
@@ -290,9 +286,13 @@ check_circular_deps(unsigned *r, unsigned size)
{
int i;
- for (i = 0; i < alias_count; i++) {
+ for (i = 0; i < alias_count; i++)
+ {
if (alias_bitisset(r, size, i, i))
- error("%s: circular dependency", aliases[i].name);
+ {
+ error (0, 0, "%s: circular dependency", aliases[i].name);
+ error_count++;
+ }
}
}
diff --git a/ckaliases.h b/ckaliases.h
index 8d6546d..d3e053c 100644
--- a/ckaliases.h
+++ b/ckaliases.h
@@ -14,20 +14,44 @@
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#define obstack_chunk_alloc malloc
+#define obstack_chunk_free free
+#include <obstack.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include "getopt.h"
+#include "progname.h"
+#include "error.h"
+#include "xalloc.h"
+
extern char *file_name;
extern int line_num;
+extern int error_count;
void init_lex();
void lex_debug(int n);
void openaliases(char *name);
void openaliases_prefix(char *prefix, char *name);
-struct string_list {
+struct string_list
+{
struct string_list *next;
char *str;
};
-typedef struct slist {
+typedef struct slist
+{
struct string_list *head, *tail;
int count;
} SLIST;
@@ -43,7 +67,5 @@ void regalias(char *name, SLIST *exp);
void begin_aliases(void);
void end_aliases(void);
-void error(char *fmt, ...);
-
extern SLIST *cw_list;
extern int verbose;
diff --git a/gram.y b/gram.y
index d20f9d8..92346c7 100644
--- a/gram.y
+++ b/gram.y
@@ -1,6 +1,6 @@
%{
/* ckaliases - verify syntax of sendmail-style alias files
- Copyright (C) 2005 Sergey Poznyakoff
+ Copyright (C) 2005, 2007 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -15,18 +15,13 @@
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 <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <getopt.h>
-#include <errno.h>
#include "ckaliases.h"
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 */
+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 */
+int error_count; /* Number of errors detected so far */
%}
%union {
@@ -84,7 +79,8 @@ emails: email
email : string
{
- if (restricted && ($1[0] == '|' || $1[0] == '/')) {
+ if (restricted && ($1[0] == '|' || $1[0] == '/'))
+ {
yyerror("Construct not allowed");
YYERROR;
}
@@ -98,7 +94,8 @@ email : string
}
| INCLUDE string
{
- if (restricted) {
+ if (restricted)
+ {
yyerror("Include statement is not allowed");
YYERROR;
}
@@ -113,45 +110,48 @@ 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++;
-}
-
+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()
{
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 (" -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(" -h Display this help list\n");
- printf(" -r Restrict alias file syntax to aliases only (i.e.\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 Revert the effect of the previous -r option\n");
- printf(" -v Verbose mode\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)
@@ -166,8 +166,11 @@ main(int argc, char **argv)
begin_aliases();
init_lex();
- while ((c = getopt(argc, argv, "-d:f:hp:ruvw:")) != EOF) {
- switch (c) {
+ 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);
@@ -177,25 +180,28 @@ main(int argc, char **argv)
break;
case 'd':
- for (p = optarg; *p; p++) {
- switch (*p) {
+ 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);
+ error (1, 0, "%s: unknown debug option %c", argv[0]);
}
}
break;
@@ -205,7 +211,8 @@ main(int argc, char **argv)
read_include(&cw_list, cwfile);
file_list = NULL;
read_include(&file_list, optarg);
- for (s = file_list->head; s; s = s->next) {
+ for (s = file_list->head; s; s = s->next)
+ {
openaliases_prefix(optarg, s->str);
yyparse();
file_count++;
@@ -229,11 +236,13 @@ main(int argc, char **argv)
verbose++;
break;
+ case 'V':
+ gsc_version ("ckaliases");
+ exit (0);
+
case 'w':
- if (file_count) {
- error("-w must be used before first non-option argument");
- exit(1);
- }
+ if (file_count)
+ error (1, 0, "-w must be used before first non-option argument");
cwfile = optarg;
break;
@@ -247,16 +256,15 @@ main(int argc, char **argv)
if (!cw_list)
read_include(&cw_list, cwfile);
- while (argc--) {
+ 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);
diff --git a/lex.l b/lex.l
index 48f943a..ba48a9c 100644
--- a/lex.l
+++ b/lex.l
@@ -1,6 +1,6 @@
%{
/* ckaliases - verify syntax of sendmail-style alias files
- Copyright (C) 2005 Sergey Poznyakoff
+ Copyright (C) 2005, 2007 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -15,16 +15,6 @@
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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/file.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
#include "ckaliases.h"
#include "gram.h"
@@ -87,11 +77,9 @@ SPEC [:@\\]
\n{WS}+/[^ \t\n] { line_num++; return CONT; }
\n { line_num++; return EOL; }
, return yytext[0];
-. { char *p;
- asprintf(&p,
+. { error_at_line (0, 0, file_name, line_num,
"Stray character %03o in alias file", yytext[0]);
- yyerror(p);
- free (p); }
+ error_count++; }
%%
int
@@ -147,11 +135,8 @@ void
openaliases(char *name)
{
yyin = fopen(name, "r");
- if (!yyin) {
- fprintf(stderr, "cannot open file `%s': %s\n",
- name, strerror(errno));
- exit(1);
- }
+ if (!yyin)
+ error (1, errno, "cannot open file `%s'", name);
file_name = name;
line_num = 0;
}
@@ -162,13 +147,11 @@ openaliases_prefix(char *prefix, char *name)
char *fullname = NULL;
struct stat st;
- if (stat(prefix, &st)) {
- fprintf(stderr, "cannot stat `%s': %s\n",
- prefix, strerror(errno));
- exit(1);
- }
+ if (stat (prefix, &st))
+ error (1, errno, "cannot stat `%s'", prefix);
- if (!S_ISDIR(st.st_mode)) {
+ if (!S_ISDIR (st.st_mode))
+ {
char *p = strrchr(prefix, '/');
if (p)
*p = 0;
@@ -200,17 +183,17 @@ read_include(SLIST **plist, char *name)
char buffer[256];
FILE *fp = fopen(name, "r");
- if (!fp) {
- char *p;
- asprintf(&p,
+ if (!fp)
+ {
+ error_at_line (0, 0, file_name, line_num,
"cannot open include file `%s': %s",
name, strerror(errno));
- yyerror(p);
- free(p);
+ error_count++;
return;
}
- while (p = fgets(buffer, sizeof buffer, fp)) {
+ while (p = fgets (buffer, sizeof buffer, fp))
+ {
char *q;
while (*p && isspace(*p))

Return to:

Send suggestions and report system problems to the System administrator.