aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-08-14 08:35:48 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-08-14 08:44:04 +0300
commitb46d05edecdbf77cb37205d9d29688851c5cd94c (patch)
treea942c7193de4b7485d82fae4dd04ff0dcebd24fd
parente0c4fa084b5d59f862276ddfa72b56b4a77babe1 (diff)
downloadcfpeek-b46d05edecdbf77cb37205d9d29688851c5cd94c.tar.gz
cfpeek-b46d05edecdbf77cb37205d9d29688851c5cd94c.tar.bz2
New option --done=expr supplies a cleanup expression.
This expression is run once, when the main loop has finished iterating over all nodes. * doc/cfpeek.1: Document the --done option. * doc/cfpeek.texi: Likewise. * NEWS: Update. * configure.ac: Version 1.1.90 * src/cfpeek.c (script_done_expr): New variable. (main): Call script_done before exiting. * src/cfpeek.h (script_done_expr): New extern (script_done, guile_done): New protos. * src/cmdline.opt (done): New option. * src/guile.c (guile_done): New function. * src/script.c (script_tab) <done>: New member. (script_tab): Fill in the new structure member. (script_done): New function.
-rw-r--r--NEWS15
-rw-r--r--configure.ac2
-rw-r--r--doc/cfpeek.16
-rw-r--r--doc/cfpeek.texi5
-rw-r--r--src/cfpeek.c3
-rw-r--r--src/cfpeek.h3
-rw-r--r--src/cmdline.opt6
-rw-r--r--src/guile.c6
-rw-r--r--src/script.c9
9 files changed, 51 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 1bda0dc..5901ec1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,23 @@
1Cfpeek NEWS -- history of user-visible changes. 2012-03-30 1Cfpeek NEWS -- history of user-visible changes. 2012-08-14
2Copyright (C) 2011, 2012 Sergey Poznyakoff 2Copyright (C) 2011, 2012 Sergey Poznyakoff
3See the end of file for copying conditions. 3See the end of file for copying conditions.
4 4
5Please send cfpeek bug reports to <bug-cfpeek@gnu.org.ua> 5Please send cfpeek bug reports to <bug-cfpeek@gnu.org.ua>
6 6
7 7
8Version 1.1.90 (Git)
9
10* New command line option --done (-d)
11
12This option is a counterpart of --init and supplies a cleanup
13expression, i.e. an expression that will be evaluated when the
14main loop has iterated over all nodes in the tree.
15
16* New parser: DHCPD
17
18A parser for dhcpd.conf file.
19
20
8Version 1.1, 2012-03-30 21Version 1.1, 2012-03-30
9 22
10* New command line option --init (-i) 23* New command line option --init (-i)
diff --git a/configure.ac b/configure.ac
index 5ee8bc2..4792a9c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,7 +15,7 @@
15# along with cfpeek. If not, see <http://www.gnu.org/licenses/>. 15# along with cfpeek. If not, see <http://www.gnu.org/licenses/>.
16 16
17AC_PREREQ(2.63) 17AC_PREREQ(2.63)
18AC_INIT([cfpeek], 1.1, [bug-cfpeek@gnu.org.ua],, 18AC_INIT([cfpeek], 1.1.90, [bug-cfpeek@gnu.org.ua],,
19 [http://www.gnu.org.ua/software/cfpeek]) 19 [http://www.gnu.org.ua/software/cfpeek])
20AC_CONFIG_SRCDIR([src/cfpeek.c]) 20AC_CONFIG_SRCDIR([src/cfpeek.c])
21AC_CONFIG_AUX_DIR([build-aux]) 21AC_CONFIG_AUX_DIR([build-aux])
diff --git a/doc/cfpeek.1 b/doc/cfpeek.1
index ff8ffa9..ca76ec1 100644
--- a/doc/cfpeek.1
+++ b/doc/cfpeek.1
@@ -14,7 +14,7 @@
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with cfpeek. If not, see <http://www.gnu.org/licenses/>. 15.\" along with cfpeek. If not, see <http://www.gnu.org/licenses/>.
16.\" 16.\"
17.TH CFPEEK 1 "August 13, 2012" "CFPEEK" "Cfpeek User Reference" 17.TH CFPEEK 1 "August 14, 2012" "CFPEEK" "Cfpeek User Reference"
18.SH NAME 18.SH NAME
19cfpeek \- retrieve values from a structured configuration file 19cfpeek \- retrieve values from a structured configuration file
20.SH SYNOPSIS 20.SH SYNOPSIS
@@ -434,6 +434,10 @@ This option provides an initialization expression, which is evaluated
434once, after loading the script file, if one is specified, and before 434once, after loading the script file, if one is specified, and before
435starting the main loop. 435starting the main loop.
436.TP 436.TP
437\fB\-d\fR, \fB\-\-done=\fIEXPR\fR
438This option supplies a cleanup expression. The expression will be
439evaluated once, after the main loop finishes.
440.TP
437\fB\-l\fR, \fB\-\-lang\fR=\fINAME\fR 441\fB\-l\fR, \fB\-\-lang\fR=\fINAME\fR
438Select scripting language to use. This is reserved for future use. 442Select scripting language to use. This is reserved for future use.
439.SS Preprocessor control 443.SS Preprocessor control
diff --git a/doc/cfpeek.texi b/doc/cfpeek.texi
index f2eae83..6b59e02 100644
--- a/doc/cfpeek.texi
+++ b/doc/cfpeek.texi
@@ -673,6 +673,11 @@ provides an initialization expression @var{expr}. This expression is
673evaluated once, after loading the script file, if one is specified, 673evaluated once, after loading the script file, if one is specified,
674and before starting the main loop. 674and before starting the main loop.
675 675
676@xopindex{done,d,described}
677Similarly, the option @option{--done=@var{expr}} (@option{-d
678@var{expr}}) introduces a Scheme expression to be evaluated at the end
679of the run, after all nodes have been processed.
680
676@menu 681@menu
677* Scripting Example:: 682* Scripting Example::
678@end menu 683@end menu
diff --git a/src/cfpeek.c b/src/cfpeek.c
index c096dda..1b4e125 100644
--- a/src/cfpeek.c
+++ b/src/cfpeek.c
@@ -28,6 +28,7 @@ unsigned max_matches;
28char *script_file; 28char *script_file;
29char *script_expr; 29char *script_expr;
30char *script_init_expr; 30char *script_init_expr;
31char *script_done_expr;
31 32
32#define MODE_GLOB 0 33#define MODE_GLOB 0
33#define MODE_LITERAL 1 34#define MODE_LITERAL 1
@@ -269,6 +270,7 @@ main(int argc, char **argv)
269 if (argc < 2) { 270 if (argc < 2) {
270 flags |= GRECS_NODE_FLAG_DESCEND; 271 flags |= GRECS_NODE_FLAG_DESCEND;
271 scan_tree(tree); 272 scan_tree(tree);
273 script_done();
272 exit(EX_OK); 274 exit(EX_OK);
273 } 275 }
274 276
@@ -294,5 +296,6 @@ main(int argc, char **argv)
294 } 296 }
295 cfp->free_buf(match_buf); 297 cfp->free_buf(match_buf);
296 } 298 }
299 script_done();
297 exit(rc); 300 exit(rc);
298} 301}
diff --git a/src/cfpeek.h b/src/cfpeek.h
index c5694cf..7c7d610 100644
--- a/src/cfpeek.h
+++ b/src/cfpeek.h
@@ -35,13 +35,16 @@ extern char *program_name;
35extern char *script_file; 35extern char *script_file;
36extern char *script_expr; 36extern char *script_expr;
37extern char *script_init_expr; 37extern char *script_init_expr;
38extern char *script_done_expr;
38 39
39void script_select(const char *lang); 40void script_select(const char *lang);
40void script_init(void); 41void script_init(void);
41int script_run(struct grecs_node *node); 42int script_run(struct grecs_node *node);
43void script_done(void);
42 44
43void guile_init(void); 45void guile_init(void);
44void guile_apply(struct grecs_node *node); 46void guile_apply(struct grecs_node *node);
47void guile_done(void);
45 48
46 49
47 50
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 55bc403..c4afef4 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -313,6 +313,12 @@ BEGIN
313 script_init_expr = optarg; 313 script_init_expr = optarg;
314END 314END
315 315
316OPTION(done,d,EXPR,
317 [<final cleanup expession>])
318BEGIN
319 script_done_expr = optarg;
320END
321
316GROUP(Preprocessor control) 322GROUP(Preprocessor control)
317 323
318OPTION(include-directory,I,DIR, 324OPTION(include-directory,I,DIR,
diff --git a/src/guile.c b/src/guile.c
index 254d671..1190fa7 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -881,3 +881,9 @@ guile_apply(struct grecs_node *node)
881 } 881 }
882} 882}
883 883
884void
885guile_done()
886{
887 if (script_done_expr)
888 scm_c_eval_string(script_done_expr);
889}
diff --git a/src/script.c b/src/script.c
index 869df55..45049fd 100644
--- a/src/script.c
+++ b/src/script.c
@@ -22,11 +22,12 @@ struct script_tab {
22 char *suf; 22 char *suf;
23 void (*init)(void); 23 void (*init)(void);
24 void (*run)(struct grecs_node *); 24 void (*run)(struct grecs_node *);
25 void (*done)(void);
25}; 26};
26 27
27static struct script_tab script_tab[] = { 28static struct script_tab script_tab[] = {
28#ifdef GUILE_VERSION_NUMBER 29#ifdef GUILE_VERSION_NUMBER
29 { "scheme", "scm\0", guile_init, guile_apply }, 30 { "scheme", "scm\0", guile_init, guile_apply, guile_done },
30#endif 31#endif
31 { NULL } 32 { NULL }
32}; 33};
@@ -103,3 +104,9 @@ script_run(struct grecs_node *node)
103 return 1; 104 return 1;
104} 105}
105 106
107void
108script_done()
109{
110 if (cur_script)
111 cur_script->done();
112}

Return to:

Send suggestions and report system problems to the System administrator.