aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2006-12-07 13:05:07 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2006-12-07 13:05:07 +0000
commitfdc01e64a149413b89335e9bd8a5e94c8deec8da (patch)
treed23502beb68d2c76d3926f71b08d4bfe9e500cd4
parent1d6928b2d8f9aa0844e26d56d04e84f36e1dac9d (diff)
downloadmailfromd-fdc01e64a149413b89335e9bd8a5e94c8deec8da.tar.gz
mailfromd-fdc01e64a149413b89335e9bd8a5e94c8deec8da.tar.bz2
Update
git-svn-id: file:///svnroot/mailfromd/trunk@1100 7a8a7f39-df28-0410-adc6-e0d955640f24
-rw-r--r--ChangeLog4
-rw-r--r--NEWS20
-rw-r--r--doc/mailfromd.texi44
-rw-r--r--src/Makefile.am1
-rw-r--r--src/lex.l83
-rw-r--r--src/mailfrom.h2
-rw-r--r--src/main.c1
7 files changed, 108 insertions, 47 deletions
diff --git a/ChangeLog b/ChangeLog
index ac655fd5..2c7b4a87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-12-07 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * NEWS, configure.ac: Version 3.1
+
2006-12-06 Sergey Poznyakoff <gray@gnu.org.ua>
* configure.ac (MAILFROMSTATEDIR): Rename to DEFAULT_STATE_DIR
diff --git a/NEWS b/NEWS
index 30de7502..3bd80689 100644
--- a/NEWS
+++ b/NEWS
@@ -47,14 +47,18 @@ Usual C notation (0xNNN for hex and 0NNN for octal) is accepted.
** Search path for include files
The `#include' statement handles its argument the same way C
-preprocessor does: if the argument is enclosed in angle brackets (<>),
-it is searched in "the system include file directory" (currently - the
-current working directory). If it is enclosed in double quotes, it is
-searched in the include search path first and then in the current
-working directory.
-
-The directories are added to the include search path using -I
-(--include) command line option.
+preprocessor does: the argument is searched in the include file path,
+if enclosed in angle brackets (<>), and in the current working
+directory first and then in the include file path, if it is enclosed
+in double quotes. The default include file path is
+
+/usr/share/mailfromd/include:/usr/local/share/mailfromd/include
+
+plus $prefix/share/mailfromd/include if $prefix is not `/usr' or
+`/usr/local'.
+
+The command line option -I (--include) adds the named directory in
+front of the default include path.
** Code optimization
diff --git a/doc/mailfromd.texi b/doc/mailfromd.texi
index 29356e95..03caeed5 100644
--- a/doc/mailfromd.texi
+++ b/doc/mailfromd.texi
@@ -2480,27 +2480,43 @@ of the specified file, as in C. There are two forms of the
@item @code{#include "@var{file}"}
@end enumerate
+ The quotes around @var{file} in the second form quotes are optional.
+
@cindex include search path, introduced
- The first form, using angle brackets, will look for file @var{file} in
-the current working directory. The second one will look for it in the
-@dfn{include search path} first, and then in the current working
-directory. The include search path is a set of directories where
-include files can be located. Initially it is empty. It is created
-and modified using @option{-I} (@option{--include}) command line
-option.
-
Both forms are equivalent if @var{file} is an absolute file name.
-
- In second form quotes around @var{file} are optional.
+Otherwise, the first form will look for @var{file} in the include
+search path. The second one will look for it in the current working
+directory first, and, if not found there, in the include search
+path.
+
+The default @dfn{include search path} is:
+
+@enumerate 1
+@item @file{/usr/share/mailfromd/include}
+@item @file{/usr/local/share/mailfromd/include}
+@item @file{@var{prefix}/share/mailfromd/include}
+Where @var{prefix} is the installation prefix.
+@end enumerate
+
+ New directories can be appended in front of it using @option{-I}
+(@option{--include}) command line option.
-For example:
+For example, invoking
@smallexample
-#include /etc/mailfromd/settings
+$ @kbd{mailfromd -I/var/mailfromd -I/com/mailfromd}
@end smallexample
- This statement produces the same effect as if the contents of the
-named file were inserted at this line.
+@noindent
+creates the following include search path
+
+@enumerate 1
+@item @file{/var/mailfromd}
+@item @file{/com/mailfromd}
+@item @file{/usr/share/mailfromd/include}
+@item @file{/usr/local/share/mailfromd/include}
+@item @file{@var{prefix}/share/mailfromd/include}
+@end enumerate
@anchor{Pragmatic comments}
@cindex Pragmatic comments
diff --git a/src/Makefile.am b/src/Makefile.am
index 8d213333..dbb01f39 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,7 @@ EXTRA_DIST = gram.h snarf.m4 init.m4 $(M4_FILES) builtin.h builtin.def
BUILT_SOURCES=$(M4_FILES:.m4=.c) builtin.h
AM_CPPFLAGS=-DSYSCONFDIR=\"$(sysconfdir)\"\
+ -DDATAROOTDIR=\"$(datarootdir)\"\
-DDEFAULT_STATE_DIR=\"$(DEFAULT_STATE_DIR)\"\
-DDEFAULT_SOCKET=\"$(DEFAULT_SOCKET)\"
diff --git a/src/lex.l b/src/lex.l
index afb5f28b..4a844668 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -134,6 +134,7 @@ ctx_lookup(struct stat *st)
}
static mu_list_t include_path;
+static mu_list_t std_include_path;
struct file_data {
const char *name;
@@ -158,37 +159,31 @@ find_include_file(void *item, void *data)
strcat(dptr->buf, dptr->name);
return dptr->found = access(dptr->buf, F_OK) == 0;
}
-
+
+void
+lex_setup()
+{
+ mu_list_create(&include_path);
+ mu_list_create(&std_include_path);
+ mu_list_append(std_include_path, "/usr/share/mailfromd/include");
+ mu_list_append(std_include_path, "/usr/local/share/mailfromd/include");
+ mu_list_append(std_include_path, DATAROOTDIR "/mailfromd/include");
+}
int
-push_source(const char *name, int search_include_path)
+push_source(const char *name)
{
FILE *fp;
struct buffer_ctx *ctx;
struct stat st;
- struct file_data fd;
-
- fd.name = name;
- fd.namelen = strlen(name);
- fd.buf = NULL;
- fd.buflen = 0;
- fd.found = 0;
-
- if (name[0] != '/' && search_include_path && include_path)
- mu_list_do(include_path, find_include_file, &fd);
-
- if (fd.found)
- name = fd.buf;
-
+
if (stat(name, &st)) {
parse_error("cannot stat `%s': %s", name, mu_strerror(errno));
- free(fd.buf);
return 1;
}
if (locus.file && STAT_ID_EQ(st, source_id)) {
parse_error("recursive inclusion");
- free(fd.buf);
return 1;
}
@@ -201,7 +196,6 @@ push_source(const char *name, int search_include_path)
else
parse_error("`%s' already included at top level",
name);
- free(fd.buf);
return 1;
}
@@ -233,7 +227,7 @@ push_source(const char *name, int search_include_path)
if (yy_flex_debug)
fprintf(stderr, "Processing file `%s'\n", name);
- free(fd.buf);
+
return 0;
}
@@ -275,15 +269,56 @@ parse_include()
else if (argc > 2)
parse_error("invalid include statement");
else {
+ char *tmp = NULL;
char *p = argv[1];
- int search_include_path = 1;
size_t len = strlen(p);
+ int allow_cwd;
+ static char *cwd = ".";
+
if (p[0] == '<' && p[len - 1] == '>') {
- search_include_path = 0;
+ allow_cwd = 0;
p[len - 1] = 0;
p++;
+ } else
+ allow_cwd = 1;
+
+ if (p[0] != '/') {
+ struct file_data fd;
+
+ fd.name = p;
+ fd.namelen = strlen(p);
+ fd.buf = NULL;
+ fd.buflen = 0;
+ fd.found = 0;
+
+
+ if (allow_cwd) {
+ mu_list_prepend(include_path, cwd);
+ mu_list_do(include_path,
+ find_include_file, &fd);
+ mu_list_remove(std_include_path, cwd);
+ } else
+ mu_list_do(include_path,
+ find_include_file, &fd);
+
+ if (!fd.found) {
+ mu_list_do(std_include_path,
+ find_include_file, &fd);
+
+ if (!fd.found) {
+ parse_error("%s: No such file or directory",
+ p);
+ p = NULL;
+ }
+ }
+ if (fd.found)
+ p = tmp = fd.buf;
}
- push_source(p, search_include_path);
+
+ if (p)
+ push_source(p);
+
+ free(tmp);
}
mu_argcv_free(argc, argv);
}
@@ -762,7 +797,7 @@ source(char *name, int ldebug)
{
yy_flex_debug = ldebug;
obstack_init(&string_stk);
- return push_source(name, 0);
+ return push_source(name);
}
int
diff --git a/src/mailfrom.h b/src/mailfrom.h
index 6ff51aad..9a6a2bd8 100644
--- a/src/mailfrom.h
+++ b/src/mailfrom.h
@@ -607,7 +607,7 @@ int parse_time_interval(char *str, time_t *pint, char **endp);
void print_syntax_tree(void);
void print_macros(void);
const char *function_name(void);
-
+void lex_setup(void);
char *string_alloc(char *str, size_t len);
void string_begin(void);
void string_add(char *str, size_t len);
diff --git a/src/main.c b/src/main.c
index 06cfbd94..ae106f9b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1609,6 +1609,7 @@ main(int argc, char **argv)
mu_error_set_print(stderr_error_printer);
builtin_setup();
db_format_setup();
+ lex_setup();
mu_argp_init (program_version, "<" PACKAGE_BUGREPORT ">");
mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL);

Return to:

Send suggestions and report system problems to the System administrator.