diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-11-23 19:32:56 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-11-23 19:32:56 +0000 |
commit | 98ace5019679083b3575394ec271a98b2fd74031 (patch) | |
tree | b97717ac835b8da16c6eb38c4233218ae0650356 | |
parent | 4b0c983467aa29375ece60fb133a39d26ff479c2 (diff) | |
download | tagr-98ace5019679083b3575394ec271a98b2fd74031.tar.gz tagr-98ace5019679083b3575394ec271a98b2fd74031.tar.bz2 |
New options --list and --verbose.
Change handling of --import options: the source directory list is
taken from the command line arguments
(mkfilename): New function
git-svn-id: file:///svnroot/tagr/trunk@65 7c378d0d-a4e4-4a64-9229-dfce8bfd23d4
-rw-r--r-- | main.c | 69 |
1 files changed, 57 insertions, 12 deletions
@@ -59,9 +59,12 @@ int port; int sockfd; int foreground = 0; int single_process_option = 0; +int verbose_level; static int rebuild_option; + static int import_option; -static char *import_directory; + +static int list_option; static char *check_mode = 0; static char *user_option = NULL; @@ -72,7 +75,7 @@ static char doc[] = "tagr -- traffic analyzer and grapher"; static char args_doc[] = ""; enum { - OPT_IMPORT + OPT_IMPORT = 256 }; static struct argp_option options[] = { @@ -82,9 +85,11 @@ static struct argp_option options[] = { {"html-template", 't', "FILE", 0, "Use given HTML template file", 0}, {"test", 'T', "DEBUG-FLAGS", 0, "Run in test mode", 0}, {"user", 'u', "USER-NAME", 0, "Run with this user privileges", 0}, - {"import", OPT_IMPORT, "DIR", OPTION_ARG_OPTIONAL, + {"import", OPT_IMPORT, NULL, 0, "Import old (mrtg-style) log files from DIR. If DIR is not given, use basedir value from the configuration file", 0 }, {"rebuild", 'b', NULL, 0, "Rebuild graphs using existing statistics", 0}, + {"verbose", 'v', NULL, 0, "Increase verbosity level", 0}, + {"list", 'l', NULL, 0, "List contents of the rate database", 0}, {NULL} }; @@ -104,7 +109,11 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'c': configfile = arg; break; - + + case 'l': + list_option = 1; + break; + case 's': single_process_option++; break; @@ -113,17 +122,20 @@ parse_opt (int key, char *arg, struct argp_state *state) html_template_option = arg; break; - case 'u': - user_option = arg; - break; - case 'T': check_mode = arg; break; + case 'u': + user_option = arg; + break; + + case 'v': + verbose_level++; + break; + case OPT_IMPORT: import_option++; - import_directory = arg; break; default: @@ -285,13 +297,14 @@ main (int argc, char **argv) argc -= index; argv += index; - if (argc != 0) + if (argc != 0 && !(list_option || import_option)) die (1, "Too many arguments"); if (check_mode) { CHECK_USAGE (import_option, "--import", "--test"); CHECK_USAGE (rebuild_option, "--rebuild", "--test"); + CHECK_USAGE (list_option, "--list", "--test"); for (; *check_mode; check_mode++) switch (*check_mode) @@ -311,12 +324,21 @@ main (int argc, char **argv) exit (2); if (import_option) - import (import_directory ? import_directory : basedir); + { + if (argc) + while (argc--) + import (*argv++); + else + import (basedir); + } if (rebuild_option) rebuild (); + + if (list_option) + list_db (); - if (rebuild_option || import_option) + if (rebuild_option || import_option || list_option) exit (0); if (user_option) @@ -534,3 +556,26 @@ assign_string_n (char **pstr, const char *s, size_t length) else *pstr = NULL; } + +char * +mkfilename (char *dir, char *name, char *suffix) +{ + int ret; + int len = strlen (name) + strlen (suffix); + char *buf; + if (dir) + len += strlen (dir) + 1; + buf = malloc (len + 1); + if (buf) + { + buf[0] = 0; + if (dir) + { + strcat (buf, dir); + strcat (buf, "/"); + } + strcat (buf, name); + strcat (buf, suffix); + } + return buf; +} |