[bwm-tools-devel] COMMIT - r33 - in trunk: bwm_graph lib
Brought to you by:
nkukard
From: SVN C. <sv...@li...> - 2005-01-09 16:24:09
|
Author: nkukard Date: 2005-01-09 18:23:48 +0200 (Sun, 09 Jan 2005) New Revision: 33 Modified: trunk/bwm_graph/bwm_graph.c trunk/lib/misc.c Log: * Fixed up displaying of usage information * Fixed bug when invalid options were specified but no error given * If no graph output file is specified, no graph will be generated * Added "hidden" options to available options to specify * -o option changed to --graph-filename * -t option changed to --graph-title * Changed date format to YYYY/MM/DD HH:MM:SS Modified: trunk/bwm_graph/bwm_graph.c =================================================================== --- trunk/bwm_graph/bwm_graph.c 2005-01-09 11:27:01 UTC (rev 32) +++ trunk/bwm_graph/bwm_graph.c 2005-01-09 16:23:48 UTC (rev 33) @@ -1,6 +1,6 @@ /* * bwm_graph.c - BWM Graph - * Copyright (C) 2003-2004, Linux Based Systems Design + * Copyright (C) 2003-2005, Linux Based Systems Design * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,25 +37,27 @@ // Function to print out our usage void printUsage(char **argv) { - printf("Usage: %s [-h|--help] [options]\n\n\n",argv[0]); - printf("Options...\n\n"); - printf("--flows=<flow1>[(counter)][:<rrd_line_type>[#rrbbgg]][,<flow2>[...]]\n"); - printf(" Flow(s) to generate report on\n\n"); - printf("--start=<start_date>\n"); - printf(" Date/Time of report start\n\n"); - printf("--end=<end_date>\n"); - printf(" Date/Time or report end\n\n"); - printf("--output=<filename>\n"); - printf(" Output filename\n\n"); - printf("--title=<graph_title>\n"); - printf(" Title of graph\n\n\n"); - printf("Graph Options...\n\n"); - printf("--graph-avg\n"); - printf(" Add averages per flow at bottom of graph\n\n"); - printf("--graph-date\n"); - printf(" Add date information under graph\n\n"); - printf("--graph-total\n"); - printf(" Add totals per flow at bottom of graph\n\n"); + printf("Usage: %s <options>\n",argv[0]); + printf("\n"); + printf("Options:\n"); + printf(" -f, --flows=<flow1>[(counter)][:<rrd_line_type>[#rrbbgg]][,<flow2>[...]]\n"); + printf(" Flow(s) to generate report on\n\n"); + printf(" -s, --start=\"YYYY/MM/DD HH:MM:SS\"\n"); + printf(" Date/Time of report start\n"); + printf(" -e, --end=\"YYYY/MM/DD HH:MM:SS\"\n"); + printf(" Date/Time of report end\n"); + printf(" -h, --help Display this page\n"); + printf("\n"); + printf("Graph Options:\n"); + printf(" --graph-filename=<filename> Output image filename\n"); + printf(" --graph-avg Add averages per flow at bottom of graph\n"); + printf(" --graph-date Add date information under graph\n"); + printf(" --graph-title=<graph_title> Title of graph\n"); + printf(" --graph-total Add totals per flow at bottom of graph\n"); + printf(" --graph-maxRate Specify your own maxRate value\n"); + printf(" --graph-vert-title=<graph_title>\n"); + printf(" Vertical title of graph\n"); + printf("\n"); } @@ -67,21 +69,20 @@ // Our options struct option long_options[] = { + {"flows",1,0,'f'}, + {"start",1,0,'s'}, {"end",1,0,'e'}, - {"flows",1,0,'f'}, {"help",0,0,'h'}, - {"output",1,0,'o'}, - {"start",1,0,'s'}, - {"title",1,0,'t'}, - {"vertical-title",1,0,'v'}, - {"graph-avg",0,0,1}, - {"graph-total",0,0,2}, - {"graph-maxRate",0,0,3}, - {"graph-date",0,0,4}, + {"graph-filename",0,0,1}, + {"graph-avg",0,0,2}, + {"graph-date",0,0,3}, + {"graph-title",1,0,4}, + {"graph-total",0,0,5}, + {"graph-maxRate",0,0,6}, + {"graph-vert-title",1,0,7}, {0,0,0,0} }; char **flowArray = NULL; - char *outputFile = "image.png"; int result = 0; char *aFlow; struct graphSource_t *gFlow; @@ -90,10 +91,14 @@ options = (struct graphOptions_t*) malloc0(sizeof(struct graphOptions_t)); - // FIXME - error check + if (!options) + { + fprintf(stderr,"ERROR: Failed to allocate memory options\n"); + return 1; + } + + printf("BWM Graph v%s - Copyright (c) 2003-2005 Linux Based Systems Design\n\n",PACKAGE_VERSION); - printf("BWM Graph v%s - Copyright (c) 2003-2004 Linux Based Systems Design\n\n",PACKAGE_VERSION); - // Print out help if (argc == 1) { @@ -107,21 +112,14 @@ int option_index = 0; // Process - c = getopt_long(argc,argv,"e:f:hs:t:v:",long_options,&option_index); + c = getopt_long(argc,argv,"f:s:e:h",long_options,&option_index); if (c == -1) break; // Check... switch (c) { - case 'e': - options->end = parseDateTime(optarg); - if (options->end < 0) - { - fprintf(stderr,"ERROR: Error in end time specified\n"); - return(1); - } - break; + // Normal options case 'f': // Grab the flows... flows = strndup(optarg,BUFFER_SIZE); @@ -129,12 +127,6 @@ flowArray = g_strsplit(flows,",",0); free(flows); break; - case 'h': - printUsage(argv); - return(0); - case 'o': - outputFile = strndup(optarg,BUFFER_SIZE); - break; case 's': options->start = parseDateTime(optarg); if (options->start < 0) @@ -143,52 +135,72 @@ return(1); } break; - case 't': - options->title = strndup(optarg,BUFFER_SIZE); + case 'e': + options->end = parseDateTime(optarg); + if (options->end < 0) + { + fprintf(stderr,"ERROR: Error in end time specified\n"); + return(1); + } break; - case 'v': - options->verticalTitle = strndup(optarg,BUFFER_SIZE); - break; + case 'h': + printUsage(argv); + return 0; + // Graphing options case 1: - options->graph_avg = 1; + options->outputFile = strndup(optarg,BUFFER_SIZE); break; case 2: - options->graph_total = 1; + options->graph_avg = 1; break; case 3: - options->graph_maxRate = 1; + options->graph_date = 1; break; case 4: - options->graph_date = 1; + options->title = strndup(optarg,BUFFER_SIZE); break; + case 5: + options->graph_total = 1; + break; + case 6: + options->graph_maxRate = 1; + break; + case 7: + options->verticalTitle = strndup(optarg,BUFFER_SIZE); + break; + + default: + printUsage(argv); + return 1; } } - // Let us know about ahy unknown options + // Let us know about any unknown options if (optind < argc) { while (optind < argc) - fprintf(stderr,"%s: invalid option -- %s\n",argv[0],argv[optind++]); - return(1); + fprintf(stderr,"ERROR: Invalid option -- %s\n",argv[optind++]); + printUsage(argv); + return 1; } // Check everything is ok... if (options->start <= 0) { fprintf(stderr,"ERROR: Report start date must be specified\n"); - return(1); + return 1; } if (options->end <= 0) { fprintf(stderr,"ERROR: Report end date must be specified\n"); - return(1); + return 1; } if (flowArray == 0) { fprintf(stderr,"ERROR: No flows specified for reporting\n"); - return(1); + return 1; } @@ -208,9 +220,6 @@ } free(flowArray); - // Create our graph options... - options->outputFile = outputFile; - // Create the files we need... printf("Creating RRD files...\n"); result = createRRDFiles(graphSources,options); @@ -222,13 +231,13 @@ result = writeRRDFile(graphSources,options); } // Graph... - if (result == 0) + if (result == 0 && options->outputFile) { printf("Graphing flows..."); result = writeGraphs(graphSources,options); } - return(result); + return result; } Modified: trunk/lib/misc.c =================================================================== --- trunk/lib/misc.c 2005-01-09 11:27:01 UTC (rev 32) +++ trunk/lib/misc.c 2005-01-09 16:23:48 UTC (rev 33) @@ -57,7 +57,7 @@ // Scan datetime provided and get our variables - ret = sscanf(dateTime, "%d/%d/%d %d:%d:%d", &day, &month, &year, &hour, + ret = sscanf(dateTime, "%d/%d/%d %d:%d:%d", &year, &month, &day, &hour, &minute, &second); // Check if we have an acceptable number of variables scanned |