aboutsummaryrefslogtreecommitdiff
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
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
-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
@@ -16,3 +16,2 @@
-AM_INSTALLCHECK_STD_OPTIONS_EXEMPT=ckaliases
AM_YFLAGS=-vtd
@@ -22 +21,3 @@ 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,3 +1,3 @@
/* ckaliases - verify syntax of sendmail-style alias files
- Copyright (C) 2005 Sergey Poznyakoff
+ Copyright (C) 2005, 2007 Sergey Poznyakoff
@@ -16,24 +16,4 @@
-#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
@@ -72,3 +52,4 @@ TC(unsigned *R, int n)
rowi = R;
- while (rowi < relend) {
+ while (rowi < relend)
+ {
ccol = cword;
@@ -76,4 +57,6 @@ TC(unsigned *R, int n)
- while (rowj < relend) {
- if (*ccol & mask) {
+ while (rowj < relend)
+ {
+ if (*ccol & mask)
+ {
rp = rowi;
@@ -83,3 +66,5 @@ TC(unsigned *R, int n)
*rowj++ |= *rp++;
- } else {
+ }
+ else
+ {
rowj = (unsigned *) ((char *) rowj + rowsize);
@@ -91,3 +76,4 @@ TC(unsigned *R, int n)
mask <<= 1;
- if (mask == 0) {
+ if (mask == 0)
+ {
mask = 1;
@@ -100,3 +86,2 @@ TC(unsigned *R, int n)
-
void
@@ -108,3 +93,4 @@ slist_add(SLIST **plist, char *str)
- if (!*plist) {
+ if (!*plist)
+ {
*plist = xmalloc (sizeof (**plist));
@@ -113,6 +99,9 @@ slist_add(SLIST **plist, char *str)
- if ((*plist)->head == NULL) {
+ if ((*plist)->head == NULL)
+ {
(*plist)->head = p;
(*plist)->count = 0;
- } else {
+ }
+ else
+ {
(*plist)->tail->next = p;
@@ -128,3 +117,4 @@ slist_append(SLIST **pdst, SLIST *src)
- if (!*pdst) {
+ if (!*pdst)
+ {
*pdst = xmalloc (sizeof (**pdst));
@@ -163,3 +153,4 @@ slist_destroy(SLIST **plist)
p = (*plist)->head;
- while (p) {
+ while (p)
+ {
struct string_list *next = p->next;
@@ -173,5 +164,4 @@ slist_destroy(SLIST **plist)
-
-
-typedef struct {
+typedef struct
+{
char *name;
@@ -240,3 +230,6 @@ end_aliases()
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++;
+ }
}
@@ -275,6 +268,9 @@ mark_connected(unsigned *r, unsigned size)
- 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);
@@ -292,5 +288,9 @@ check_circular_deps(unsigned *r, unsigned size)
- 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
@@ -16,4 +16,26 @@
+#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;
@@ -24,3 +46,4 @@ void openaliases_prefix(char *prefix, char *name);
-struct string_list {
+struct string_list
+{
struct string_list *next;
@@ -29,3 +52,4 @@ struct string_list {
-typedef struct slist {
+typedef struct slist
+{
struct string_list *head, *tail;
@@ -45,4 +69,2 @@ void end_aliases(void);
-void error(char *fmt, ...);
-
extern SLIST *cw_list;
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 */
+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 */
%}
@@ -86,3 +81,4 @@ email : string
{
- if (restricted && ($1[0] == '|' || $1[0] == '/')) {
+ if (restricted && ($1[0] == '|' || $1[0] == '/'))
+ {
yyerror ("Construct not allowed");
@@ -100,3 +96,4 @@ email : string
{
- if (restricted) {
+ if (restricted)
+ {
yyerror ("Include statement is not allowed");
@@ -115,16 +112,7 @@ 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++;
}
@@ -132,3 +120,2 @@ yyerror(char *s)
-
void
@@ -139,3 +126,3 @@ usage()
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");
@@ -145,7 +132,10 @@ usage()
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");
@@ -154,2 +144,12 @@ usage()
+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 }
+};
@@ -168,4 +168,7 @@ main(int argc, char **argv)
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:
@@ -179,4 +182,6 @@ main(int argc, char **argv)
case 'd':
- for (p = optarg; *p; p++) {
- switch (*p) {
+ for (p = optarg; *p; p++)
+ {
+ switch (*p)
+ {
case '-':
@@ -184,2 +189,3 @@ main(int argc, char **argv)
break;
+
case 'y':
@@ -189,2 +195,3 @@ main(int argc, char **argv)
break;
+
case 'l':
@@ -194,6 +201,5 @@ main(int argc, char **argv)
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]);
}
@@ -207,3 +213,4 @@ main(int argc, char **argv)
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);
@@ -231,7 +238,9 @@ main(int argc, char **argv)
+ 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;
@@ -249,3 +258,4 @@ main(int argc, char **argv)
read_include (&cw_list, cwfile);
- while (argc--) {
+ while (argc--)
+ {
openaliases (*argv++);
@@ -255,6 +265,4 @@ main(int argc, char **argv)
- if (!file_count) {
- error("no files specified");
- exit(1);
- }
+ if (!file_count)
+ error (1, 0, "no files specified");
diff --git a/lex.l b/lex.l
index 48f943a..ba48a9c 100644
--- a/lex.l
+++ b/lex.l
@@ -2,3 +2,3 @@
/* ckaliases - verify syntax of sendmail-style alias files
- Copyright (C) 2005 Sergey Poznyakoff
+ Copyright (C) 2005, 2007 Sergey Poznyakoff
@@ -17,12 +17,2 @@
-#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"
@@ -89,7 +79,5 @@ SPEC [:@\\]
, 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++; }
%%
@@ -149,7 +137,4 @@ 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;
@@ -164,9 +149,7 @@ openaliases_prefix(char *prefix, char *name)
- 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, '/');
@@ -202,9 +185,8 @@ read_include(SLIST **plist, char *name)
- 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;
@@ -212,3 +194,4 @@ read_include(SLIST **plist, char *name)
- while (p = fgets(buffer, sizeof buffer, fp)) {
+ while (p = fgets (buffer, sizeof buffer, fp))
+ {
char *q;

Return to:

Send suggestions and report system problems to the System administrator.