From c0c95c69115dadc90aa69ddc3dc5792004f43d5e Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Mon, 20 Jun 2016 13:59:30 +0300 Subject: Implement search path for #include and #include_once. * src/Makefile.am (AM_CPPFLAGS): Define INCLUDE_PATH_ARGS * src/cmdline.opt: New option --include-directory (-I). (help_hook): Print the actual content of the include search path. * src/config.c (config_finish): Remove. (config_init): New function. Set up include search path. (config_parse): New function. * src/direvent.c (main): Call config_init and config_parse. * src/direvent.h (config_finish): Remove. (config_init,config_parse): New proto. * grecs: Upgrade. * NEWS: Document changes. * README: Document the --with-include-path option. * configure.ac: New option --with-include-path. * doc/direvent.8: Document the -I option and include search paths. * doc/direvent.conf.5: Document include search paths. * doc/direvent.texi: Document the -I option and include search paths. --- NEWS | 35 ++++++++++++++++++++++++++++++++--- README | 17 +++++++++++++++++ configure.ac | 7 +++++++ doc/direvent.8 | 17 ++++++++++++++--- doc/direvent.conf.5 | 24 ++++++++++++++---------- doc/direvent.texi | 42 +++++++++++++++++++++++++++++++++++++++++- grecs | 2 +- src/Makefile.am | 3 ++- src/cmdline.opt | 21 +++++++++++++++++++++ src/config.c | 16 ++++++++++++++-- src/direvent.c | 10 +++------- src/direvent.h | 3 +-- 12 files changed, 167 insertions(+), 30 deletions(-) diff --git a/NEWS b/NEWS index 7da595f..2077f82 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -direvent -- history of user-visible changes. 2016-06-18 +direvent -- history of user-visible changes. 2016-06-20 Copyright (C) 2012-2016 Sergey Poznyakoff See the end of file for copying conditions. @@ -21,11 +21,40 @@ The 'shell' option causes watcher command to be executed via function). For example: watcher { - path "/etc/httpd/vhosts" - command "/usr/bin/scanhosts && service httpd restart" + path "/etc/httpd/vhosts"; + command "/usr/bin/scanhosts && service httpd restart"; option (shell); } +* Include path + +If the argument to the #include (#include_once) statement is not an +absolute file name or globbing pattern, it is looked up in the include +search path. The order of look up is as follows. First, directories +given with '-I' options (see below) are scanned, in the same order as +given on the command line. If no matching file is found in any of +them, directories in the standard include search path are scanned. + +By default, the standard include search path contains two directories: +'$(pkgdatadir)/$(VERSION)' and '$(pkgdatadir)/include', where +$(pkgdatadir) and $(VERSION) stand for the package data directory, and +package version, correspondingly. It can be redefined at compile time using +the '--with-include-path' to configure, e.g.: + + ./configure --with-include-path='$(sysconfdir)/direvent.d:$(pkgdatadir)/$(VERSION):$(pkgdatadir)/include' + +(see the file INSTALL, section "Building and Configuring", for a +detailed discussion of this option). + +To inspect the actual path at runtime, run \fBdirevent \-\-help\fR, +and look for the string 'Include search path:' in its output. + +* New command line option -I (--include) + +The '-I DIR' command line option adds DIR to the include search path. +When looking for include files, directories given with '-I' options +are scanned first. If the file is not found, the directories in the +standard include path are scanned. Version 5.0, 2014-09-06 diff --git a/README b/README index 80075c8..ea4713f 100644 --- a/README +++ b/README @@ -25,6 +25,23 @@ The usual incantation applies: See the file INSTALL for the description of ./configure and its generic options. +Following are the package-specific options: + + --with-include-path=PATH + + Define standard include path. This is a list of directories where + files given in the #include and #include_once configuration + statements will be searched. PATH is a list of directories + separated by colons. Directory names can contain references to + Makefile variables, which will be expanded to their actual values + at compile time. The default PATH is + + $(pkgdatadir)/$(VERSION):$(pkgdatadir)/include + + See the documentation, section 5.1.2 "Pragmatic Comments", for a + detailed description of #include and #include_path statements and + the meaning of the include search path. + * Usage Instructions Complete documentation is included with the package, both in man diff --git a/configure.ac b/configure.ac index e7285f0..35ccf1a 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,13 @@ AM_ICONV AM_GNU_GETTEXT([external], [need-formatstring-macros]) AM_GNU_GETTEXT_VERSION([0.18]) +AC_SUBST(INCLUDE_PATH_ARGS,[$(pkgdatadir)/$(VERSION):$(pkgdatadir)/include]) +AC_ARG_WITH([include-path], + [AC_HELP_STRING([--with-include-path=PATH], + [set direvent runtime include path])], + [INCLUDE_PATH_ARGS=$withval]) +INCLUDE_PATH_ARGS=$(echo "$INCLUDE_PATH_ARGS" | sed 's/:/\",\"/g;s/^/\"/;s/$/\"/') + # Initialize the test suite. AC_CONFIG_TESTDIR(tests) AC_CONFIG_FILES([tests/Makefile tests/atlocal po/Makefile.in]) diff --git a/doc/direvent.8 b/doc/direvent.8 index 6e8f63b..b4add02 100644 --- a/doc/direvent.8 +++ b/doc/direvent.8 @@ -13,17 +13,19 @@ .\" .\" You should have received a copy of the GNU General Public License along .\" with direvent. If not, see . -.TH DIREVENT 8 "September 1, 2014" "DIREVENT" "Direvent User Reference" +.TH DIREVENT 8 "June 20, 2016" "DIREVENT" "Direvent User Reference" .SH NAME direvent \- directory event monitor .SH SYNOPSIS \fBdirevent\fR [\fB\-HVdfh\fR] [\fB\-F\fR \fINAME\fR]\ [\fB\-P\fR \fIFILE\fR]\ - [\fB-l\fR \fIPRIO\fR]\ - [\fB-T\fR \fICOMMAND\fR]\ + [\fB\-l\fR \fIPRIO\fR]\ + [\fB\-I\fR \fIDIR\fR]\ + [\fB\-T\fR \fICOMMAND\fR]\ [\fB\-\-debug\fR]\ [\fB\-\-facility\fR=\fINAME\fR]\ [\fB\-\-foreground\fB]\ + [\fB\-\-include=\fIDIR\fR]\ [\fB\-\-pidfile\fR=\fIFILE\fR]\ [\fB\-\-self\-test\fR=\fICOMMAND\fR]\ [\fB\-\-user\fR=\fINAME\fR]\ @@ -122,6 +124,15 @@ The option \fB\-F 0\fR directs logging to the standard error. .BR \-f ", " \-\-foreground Run in the foreground. .TP +\fB\-I\fR, \fB\-\-include=\fIDIR\fR +Add \fIDIR\fR to the include search path. When looking for a file to +be included in the \fB#include\fR (\fB#include_once\fR) statement, +\fBdirevent\fR scans first the directories given with \fB\-I\fR +options (in the same order as given on the command line), and then the +directories in the standard include search path. The latter is +defined at compile time and can be inspected in the output of the +\fB\-\-help\fR option. +.TP \fB\-l\fR \fIPRIO\fR While connected to a terminal \fBdirevent\fR outputs its diagnostics messages to stderr and, if configured, to \fBsyslog\fR. This option diff --git a/doc/direvent.conf.5 b/doc/direvent.conf.5 index 4eaf5e6..265a2d2 100644 --- a/doc/direvent.conf.5 +++ b/doc/direvent.conf.5 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License along .\" with direvent. If not, see . -.TH DIREVENT.CONF 5 "June 18, 2016" "DIREVENT" "Direvent User Reference" +.TH DIREVENT.CONF 5 "June 20, 2016" "DIREVENT" "Direvent User Reference" .SH NAME direvent.conf \- configuration file for .BR direvent (8). @@ -68,18 +68,22 @@ absolute file name, the named file is included. An error message will be issued if it does not exist. If \fIFILE\fR contains wildcard characters (\fB*\fR, \fB[\fR, -\fB]\fR, or \fB?\fR), it is interpreted as shell globbing pattern and +\fB]\fR, or \fB?\fR), it is interpreted as a shell globbing pattern and all files matching that pattern are included, in lexicographical order. If no matching files are found, the directive is replaced with an empty line. -.\" If it is an -.\" absolute file name, both forms are equivalent. Otherwise, the form -.\" with angle brackets searches for the file in the \fIinclude -.\" search path\fR, while the second one looks for it in the current working -.\" directory first, and, if not found there, in the include search -.\" path. -.\" .sp -.\" The default include search path is: \fBFIXME\fR. + +Otherwise, the form with angle brackets searches for file in the +include search path, while the second one looks for it in the +current working directory first, and, if not found there, in the +include search path. If the file is not found, an error message will +be issued. + +The order of directories is as follows. First, \fBdirevent\fR scans +any directories given with \fB\-I\fR options, in the same order as +given on the command line, and then the directories in the standard +include search path. The latter is defined at compile time and can be +inspected in the output of the \fB\-\-help\fR option. .TP .BI "#include_once <" "FILE" > .PD 0 diff --git a/doc/direvent.texi b/doc/direvent.texi index a7ce4a4..47db410 100644 --- a/doc/direvent.texi +++ b/doc/direvent.texi @@ -331,6 +331,13 @@ Set syslog facility. @item -f @itemx --foreground Remain in foreground. +@opindex -I +@opindex --include +@anchor{include option} +@item -I @var{dir} +@itemx --include=@var{dir} +Add @var{dir} to the beginning of the include search path +(@pxref{include search path}). @opindex -l @item -l @var{prio} While connected to a terminal, @command{direvent} outputs its diagnostics @@ -497,11 +504,44 @@ absolute file name, the named file is included. An error message will be issued if it does not exist. If @var{file} contains wildcard characters (@samp{*}, @samp{[}, -@samp{]} or @samp{?}), it is interpreted as shell globbing pattern and +@samp{]} or @samp{?}), it is interpreted as a shell globbing pattern and all files matching that pattern are included, in lexicographical order. If no matching files are found, the directive is replaced with an empty line. +Otherwise, the form with angle brackets searches for file in the +@dfn{include search path}, while the second one looks for it in the +current working directory first, and, if not found there, in the +include search path. If the file is not found, an error message will +be issued. + +@cindex include search path, preprocessor +@cindex include directories, preprocessor +@cindex preprocessor include search path +@anchor{include search path} +@dfn{Include search path} is formed by two directory sets: the +user-defined search path, as defined by eventual @option{-I} +(@pxref{include option}) command line options, and the standard include +search path, defined at compile time. The latter can be inspected +using the @option{--help} option. + +The order of directories is as follows. First, @command{direvent} scans +any directories given with @option{-I} options, in the same order as +given on the command line. If @var{file} is not found in any of them, +the standard include search path is scanned. It is defined at the +compile time and by default consists of two directories: + +@itemize @bullet +@item @file{@var{prefix}/share/direvent/@value{VERSION}/include} +@item @file{@var{prefix}/share/direvent/include} +@end itemize + +@noindent +where @var{prefix} is the installation prefix. The default can be +changed when configuring the package. To inspect the actual standard +include search path at the runtime, run @code{direvent --help}, and +look for the string @samp{Include search path:} in its output. + @kwindex #include_once @item #include_once <@var{file}> @itemx #include_once @var{file} diff --git a/grecs b/grecs index 59f9073..6ab660a 160000 --- a/grecs +++ b/grecs @@ -1 +1 @@ -Subproject commit 59f9073082a0033a9a54ea27b2409bd087d63709 +Subproject commit 6ab660a7f9a9857a56cff44765144016356bd9f1 diff --git a/src/Makefile.am b/src/Makefile.am index cdb5bef..703edac 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -44,7 +44,8 @@ endif LDADD=@GRECS_LDADD@ @LIBINTL@ AM_CPPFLAGS=\ -I$(top_srcdir)/grecs/src/\ - -DLOCALEDIR=\"$(localedir)\" + -DLOCALEDIR=\"$(localedir)\"\ + -DINCLUDE_PATH_ARGS='$(INCLUDE_PATH_ARGS)' BUILT_SOURCES=cmdline.h EXTRA_DIST=cmdline.opt diff --git a/src/cmdline.opt b/src/cmdline.opt index a200ab8..39f34ec 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -34,6 +34,12 @@ BEGIN opt_foreground++; END +OPTION(include-directory,I,DIR, + []) +BEGIN + grecs_preproc_add_include_dir(optarg); +END + OPTION(self-test,T,PROG, []) BEGIN @@ -72,6 +78,14 @@ END OPTIONS_END +static int +print_dir(int flag, const char *dir, void *data) +{ + FILE *fp = data; + fprintf(fp, "%s\n", dir); + return 0; +} + static void help_hook(FILE *fp) { @@ -81,6 +95,13 @@ help_hook(FILE *fp) "to use instead of %s.\n\n"), DEFAULT_CONFFILE); /* TRANSLATORS: %s is one of: inotify, kqueue */ fprintf(fp, _("This direvent uses %s interface.\n\n"), INTERFACE); + + if (grecs_include_path_count(GRECS_STD_INCLUDE)) { + fprintf(fp, _("Include search path:\n")); + grecs_foreach_include_dir(GRECS_STD_INCLUDE, print_dir, fp); + } else + fprintf(fp, _("No include search path.\n")); + fprintf(fp, "\n"); } void diff --git a/src/config.c b/src/config.c index 16f5701..6b7563b 100644 --- a/src/config.c +++ b/src/config.c @@ -747,8 +747,20 @@ config_help() } void -config_finish(struct grecs_node *tree) -{ +config_init(void) +{ + grecs_include_path_setup(INCLUDE_PATH_ARGS, NULL); +} + +void +config_parse(char const *conffile) +{ + struct grecs_node *tree; + + tree = grecs_parse(conffile); + if (!tree) + exit(1); if (grecs_tree_process(tree, direvent_kw)) exit(1); + } diff --git a/src/direvent.c b/src/direvent.c index e24d619..b79df38 100644 --- a/src/direvent.c +++ b/src/direvent.c @@ -455,7 +455,6 @@ int main(int argc, char **argv) { int i; - struct grecs_node *tree; #ifdef ENABLE_NLS setlocale(LC_ALL, ""); @@ -467,7 +466,8 @@ main(int argc, char **argv) tag = estrdup(program_name); genev_init(); - + config_init(); + parse_options(argc, argv, &i); argc -= i; @@ -484,11 +484,7 @@ main(int argc, char **argv) break; } - tree = grecs_parse(conffile); - if (!tree) - exit(1); - - config_finish(tree); + config_parse(conffile); if (lint_only) return 0; diff --git a/src/direvent.h b/src/direvent.h index 3ce4693..2cd5344 100644 --- a/src/direvent.h +++ b/src/direvent.h @@ -201,8 +201,7 @@ struct pathent { }; void config_help(void); -struct grecs_node; -void config_finish(struct grecs_node *tree); +void config_init(void); void config_parse(const char *file); int get_facility(const char *arg); -- cgit v1.2.1