diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-02-22 12:29:58 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-02-22 12:29:58 +0200 |
commit | e7860f6f4b7da3e45eee6d2100dfb42823d8106f (patch) | |
tree | a9dca4490c567054391579b627ae5db14995f5dd | |
parent | 0b63c31eadfe5d4e94c7014bd0f3bd4370783d19 (diff) | |
download | wydawca-e7860f6f4b7da3e45eee6d2100dfb42823d8106f.tar.gz wydawca-e7860f6f4b7da3e45eee6d2100dfb42823d8106f.tar.bz2 |
Minor improvements
* src/report.c: New file
* src/Makefile.am (wydawca_SOURCES): Add report.c
* src/cmdline.opt: Group options.
New option -D (--define).
* src/directive.c (process_directives): Call report_init before processing
and report_finish afterwards.
* src/triplet.c: New meta-variable `report'.
* src/vtab.c (move_file, archive_file, symlink_file, rmsymlink_file): Update
report stack.
* src/wydawca.h: Include obstack.h
(report_init, report_add, report_finish): New protos.
(report_string): New declaration.
* src/builtin.c, src/meta.c: Remove obstack inclusion.
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/builtin.c | 3 | ||||
-rw-r--r-- | src/cmdline.opt | 85 | ||||
-rw-r--r-- | src/directive.c | 2 | ||||
-rw-r--r-- | src/meta.c | 3 | ||||
-rw-r--r-- | src/report.c | 52 | ||||
-rw-r--r-- | src/triplet.c | 7 | ||||
-rw-r--r-- | src/vtab.c | 22 | ||||
-rw-r--r-- | src/wydawca.h | 8 |
9 files changed, 152 insertions, 33 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 110bd07..bf38ec8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,7 +38,8 @@ wydawca_SOURCES=\ mail.c\ vtab.c\ null.c\ - timer.c + timer.c\ + report.c BUILT_SOURCES=cmdline.h EXTRA_DIST=cmdline.opt getopt.m4 pp-setup diff --git a/src/builtin.c b/src/builtin.c index 761a01a..e5641d1 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -18,9 +18,6 @@ #include "builtin.h" #include "fnmatch.h" #include "regex.h" -#define obstack_chunk_alloc malloc -#define obstack_chunk_free free -#include "obstack.h" int builtin_init (struct access_method *meth) diff --git a/src/cmdline.opt b/src/cmdline.opt index cb269f6..153199b 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -14,15 +14,44 @@ You should have received a copy of the GNU General Public License along with wydawca. If not, see <http://www.gnu.org/licenses/>. */ +static struct obstack pp_cmd_stack; +static int pp_cmd_stack_init; + OPTIONS_BEGIN(gnu, "wydawca", [<wydawca synchronizes files from a set of upload directories with the corresponding distribution sites>]) +GROUP(Selecting program mode) + +OPTION(lint,t,, + [<parse configuration file and exit>]) +BEGIN + lint_mode = 1; + log_to_stderr = 1; +END + +OPTION(,E,, + [<preprocess config and exit>]) +BEGIN + preprocess_only = 1; +END + +OPTION(dry-run,n,, + [<do nothing, print almost everything; implies `--debug --stderr', + use additional `--debug' options to get even more info>]) +BEGIN + log_to_stderr = 1; + debug_level++; + dry_run_mode = 1; +END + OPTION(config-file,c,FILE, [<use FILE instead of the default configuration>]) BEGIN conffile = optarg; END +GROUP(Logging) + OPTION(cron,,, [<log to syslog>]) ALIAS(syslog) @@ -36,11 +65,7 @@ BEGIN log_to_stderr = 1; END -OPTION(debug,d,, - [<increase debugging level>]) -BEGIN - debug_level++; -END +GROUP(Preprocessor control) OPTION(include-directory,I,[DIR], [<add include directory>]) @@ -48,20 +73,24 @@ BEGIN gconf_preproc_add_include_dir (optarg); END -OPTION(dry-run,n,, - [<do nothing, print almost everything; implies `--debug --stderr', - use additional `--debug' options to get even more info>]) +OPTION(define,D,SYMBOL[=VALUE], + [<define a preprocessor symbol>]) BEGIN - log_to_stderr = 1; - debug_level++; - dry_run_mode = 1; -END - -OPTION(lint,t,, - [<parse configuration file and exit>]) -BEGIN - lint_mode = 1; - log_to_stderr = 1; + char *p; + + if (!pp_cmd_stack_init) + { + obstack_init (&pp_cmd_stack); + pp_cmd_stack_init = 1; + } + obstack_grow (&pp_cmd_stack, " \"-D", 4); + for (p = optarg; *p; p++) + { + if (*p == '\\' || *p == '"') + obstack_1grow (&pp_cmd_stack, '\\'); + obstack_1grow (&pp_cmd_stack, *p); + } + obstack_1grow (&pp_cmd_stack, '"'); END OPTION(preprocessor,,COMMAND, @@ -76,10 +105,12 @@ BEGIN gconf_preprocessor = NULL; END -OPTION(,E,, - [<preprocess config and exit>]) +GROUP(Debugging) + +OPTION(debug,d,, + [<increase debugging level>]) BEGIN - preprocess_only = 1; + debug_level++; END OPTION(dump-grammar-trace,,, @@ -94,6 +125,7 @@ BEGIN gconf_lex_trace (1); END +GROUP([<Additional help>]) OPTION(config-help,,, [<show configuration file summary>]) BEGIN @@ -106,5 +138,14 @@ OPTIONS_END void parse_options(int argc, char *argv[]) { - GETOPT(argc, argv) + GETOPT(argc, argv) + if (pp_cmd_stack_init && gconf_preprocessor) + { + char *defs = obstack_finish (&pp_cmd_stack); + char *cmd = xmalloc (strlen (gconf_preprocessor) + strlen (defs) + 1); + strcpy (cmd, gconf_preprocessor); + strcat (cmd, defs); + gconf_preprocessor = cmd; + obstack_free (&pp_cmd_stack, NULL); + } } diff --git a/src/directive.c b/src/directive.c index b050ffb..f18479c 100644 --- a/src/directive.c +++ b/src/directive.c @@ -309,6 +309,7 @@ process_directives (struct file_triplet *trp, struct directory_pair *dpair) char *relative_dir; timer_start ("triplet"); + report_init (); UPDATE_STATS (STAT_COMPLETE_TRIPLETS); for (n = directive_first (trp, &key, &val); n; n = directive_next (trp, n, &key, &val)) @@ -401,6 +402,7 @@ process_directives (struct file_triplet *trp, struct directory_pair *dpair) free (relative_dir); UPDATE_STATS (STAT_TRIPLET_SUCCESS); + report_finish (); timer_stop ("triplet"); notify (dpair->notification, trp, ev_success); return 0; @@ -16,9 +16,6 @@ #include "wydawca.h" #include "sql.h" -#define obstack_chunk_alloc malloc -#define obstack_chunk_free free -#include <obstack.h> #include <c-ctype.h> static const char * diff --git a/src/report.c b/src/report.c new file mode 100644 index 0000000..fe38fe9 --- /dev/null +++ b/src/report.c @@ -0,0 +1,52 @@ +/* wydawca - automatic release submission daemon + Copyright (C) 2009 Sergey Poznyakoff + + Wydawca is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. + + Wydawca is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with wydawca. If not, see <http://www.gnu.org/licenses/>. */ + +#include "wydawca.h" + +static struct obstack report_stk; +static int report_stk_inited; +char *report_string; + +void +report_init () +{ + if (!report_stk_inited) + obstack_init (&report_stk); + else + obstack_free (&report_stk, report_string); +} + +void +report_add (const char *fmt, ...) +{ + va_list ap; + char *str = NULL; + va_start (ap, fmt); + vasprintf (&str, fmt, ap); + va_end (ap); + if (str) + { + obstack_grow (&report_stk, str, strlen (str)); + obstack_1grow (&report_stk, '\n'); + } +} + +void +report_finish () +{ + obstack_1grow (&report_stk, 0); + report_string = obstack_finish (&report_stk); +} diff --git a/src/triplet.c b/src/triplet.c index 6ebc142..3cfc4d0 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -543,6 +543,12 @@ expand_user_email (struct metadef *def, void *data) return def->value; } +static const char * +expand_report (struct metadef *def, void *data) +{ + return report_string; +} + #define DECL_EXPAND_TIMER(what) \ static const char * \ __cat2__(expand_timer_,what) (struct metadef *def, void *data) \ @@ -578,6 +584,7 @@ struct metadef triplet_meta[] = { { "user:name", NULL, expand_user_name, NULL }, { "user:real-name", NULL, expand_user_real_name, NULL }, { "user:email", NULL, expand_user_email, NULL }, + { "report", NULL, expand_report, NULL }, DECL_FULL_TIMER(wydawca), DECL_FULL_TIMER(triplet), DECL_FULL_TIMER(directory), @@ -54,14 +54,20 @@ int move_file (struct file_triplet *trp, struct directory_pair *dpair, enum file_type file_id, const char *reldir) { - return dpair->vtab.move_file (trp, dpair, file_id, reldir); + int rc = dpair->vtab.move_file (trp, dpair, file_id, reldir); + report_add ("Move %s to %s: %s", trp->file[file_id].name, reldir, + rc == 0 ? "OK" : "FAILED"); + return rc; } int archive_file (struct file_triplet *trp, struct directory_pair *dpair, const char *reldir, const char *file_name) { - return dpair->vtab.archive_file (trp, dpair, reldir, file_name); + int rc = dpair->vtab.archive_file (trp, dpair, reldir, file_name); + report_add ("Archive and remove %s/%s: %s", reldir, file_name, + rc == 0 ? "OK" : "FAILED"); + return rc; } int @@ -69,12 +75,20 @@ symlink_file (struct file_triplet *trp, struct directory_pair *dpair, const char *reldir, const char *wanted_src, const char *wanted_dst) { - return dpair->vtab.symlink_file (trp, dpair, reldir, wanted_src, wanted_dst); + int rc = dpair->vtab.symlink_file (trp, dpair, reldir, + wanted_src, wanted_dst); + report_add ("Symlink %s to %s in %s/: %s", wanted_src, wanted_dst, + reldir, + rc == 0 ? "OK" : "FAILED"); + return rc; } int rmsymlink_file (struct file_triplet *trp, struct directory_pair *dpair, const char *reldir, const char *file_name) { - return dpair->vtab.rmsymlink_file (trp, dpair, reldir, file_name); + int rc = dpair->vtab.rmsymlink_file (trp, dpair, reldir, file_name); + report_add ("Remove symlink %s/%s: %s", reldir, file_name, + rc == 0 ? "OK" : "FAILED"); + return rc; } diff --git a/src/wydawca.h b/src/wydawca.h index 2e00f65..2ba065b 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -38,6 +38,9 @@ #include <mailutils/url.h> #include <mailutils/errno.h> +#define obstack_chunk_alloc malloc +#define obstack_chunk_free free +#include "obstack.h" #include "error.h" #include "xalloc.h" #include "progname.h" @@ -457,3 +460,8 @@ size_t timer_get_count (void); void timer_fill_meta (struct metadef *def, size_t num); void timer_free_meta (struct metadef *def, size_t num); + +void report_init (void); +void report_add (const char *fmt, ...); +void report_finish (void); +extern char *report_string; |