/*****************************************************************************
- * RRDtool 1.2.12 Copyright by Tobi Oetiker, 1997-2005
+ * RRDtool 1.2.15 Copyright by Tobi Oetiker, 1997-2006
*****************************************************************************
* rrd_tool.c Startup wrapper
*****************************************************************************/
{
char help_main[] =
- "RRDtool " PACKAGE_VERSION " Copyright 1997-2005 by Tobias Oetiker <tobi@oetiker.ch>\n"
+ "RRDtool " PACKAGE_VERSION " Copyright 1997-2006 by Tobias Oetiker <tobi@oetiker.ch>\n"
" Compiled " __DATE__ " " __TIME__ "\n\n"
"Usage: rrdtool [options] command command_options\n\n";
"\t\tlast, first, info, fetch, tune, resize, xport\n\n";
char help_listremote[] =
- "Valid remote commands: quit, ls, cd, mkdir\n\n";
+ "Valid remote commands: quit, ls, cd, mkdir, pwd\n\n";
char help_create[] =
"\t\t[-f|--imginfo printfstr]\n"
"\t\t[-a|--imgformat PNG]\n"
"\t\t[-c|--color COLORTAG#rrggbb[aa]] [-t|--title string]\n"
- "\t\t[DEF:vname=rrd:ds-name:CF]\n"
- "\t\t[CDEF:vname=rpn-expression]\n";
+ "\t\t[-W|--watermark string]\n"
+ "\t\t[DEF:vname=rrd:ds-name:CF]\n";
char help_graph3[] =
+ "\t\t[CDEF:vname=rpn-expression]\n"
"\t\t[VDEF:vdefname=rpn-expression]\n"
"\t\t[PRINT:vdefname:format]\n"
"\t\t[GPRINT:vdefname:format]\n"
"\trrdtool xport [-s|--start seconds] [-e|--end seconds]\n"
"\t\t[-m|--maxrows rows]\n"
"\t\t[--step seconds]\n"
+ "\t\t[--enumds]\n"
"\t\t[DEF:vname=rrd:ds-name:CF]\n"
"\t\t[CDEF:vname=rpn-expression]\n"
"\t\t[XPORT:vname:legend]\n\n";
" * mkdir - creates a new directory\n\n"
"\trrdtool mkdir newdirectoryname\n\n";
+ char help_pwd[] =
+ " * pwd - returns the current working directory\n\n"
+ "\trrdtool pwd\n\n";
+
char help_lic[] =
"RRDtool is distributed under the Terms of the GNU General\n"
"Public License Version 2. (www.gnu.org/copyleft/gpl.html)\n\n"
enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST, C_FIRST,
C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE, C_XPORT,
- C_QUIT, C_LS, C_CD, C_MKDIR, C_UPDATEV };
+ C_QUIT, C_LS, C_CD, C_MKDIR, C_PWD, C_UPDATEV };
int help_cmd = C_NONE;
help_cmd = C_CD;
else if (!strcmp(cmd,"mkdir"))
help_cmd = C_MKDIR;
+ else if (!strcmp(cmd,"pwd"))
+ help_cmd = C_PWD;
}
fputs(help_main, stdout);
switch (help_cmd)
case C_MKDIR:
fputs(help_mkdir, stdout);
break;
+ case C_PWD:
+ fputs(help_pwd, stdout);
+ break;
}
fputs(help_lic, stdout);
}
+static char *fgetslong(char **aLinePtr, FILE *stream)
+{
+ char *linebuf;
+ size_t bufsize = MAX_LENGTH;
+ int eolpos = 0;
+
+ if (feof(stream)) return *aLinePtr = 0;
+ if (!(linebuf = malloc(bufsize))) {
+ perror("fgetslong: malloc");
+ exit(1);
+ }
+ linebuf[0] = '\0';
+ while (fgets(linebuf + eolpos, MAX_LENGTH, stream)) {
+ eolpos += strlen(linebuf + eolpos);
+ if (linebuf[eolpos - 1] == '\n') return *aLinePtr = linebuf;
+ bufsize += MAX_LENGTH;
+ if (!(linebuf = realloc(linebuf, bufsize))) {
+ perror("fgetslong: realloc");
+ exit(1);
+ }
+ }
+ return *aLinePtr = linebuf[0] ? linebuf : 0;
+}
int main(int argc, char *argv[])
{
char **myargv;
- char aLine[MAX_LENGTH];
+ char *aLine;
char *firstdir="";
#ifdef MUST_DISABLE_SIGFPE
signal(SIGFPE,SIG_IGN);
}
}
- while (fgets(aLine, sizeof(aLine)-1, stdin)){
+ while (fgetslong(&aLine, stdin)){
if ((argc = CountArgs(aLine)) == 0) {
- fprintf(stderr,"ERROR: not enough arguments\n");
+ printf("ERROR: not enough arguments\n");
}
if ((myargv = (char **) malloc((argc+1) *
sizeof(char *))) == NULL) {
}
}
fflush(stdout); /* this is important for pipes to work */
+ free(aLine);
}
}
else if (argc == 2)
#if defined(HAVE_SYS_STAT_H)
struct stat st;
#endif
+ char* cwd; /* To hold current working dir on call to pwd */
+
+ /* Reset errno to 0 before we start.
+ */
+ errno = 0;
if (RemoteMode){
if (argc>1 && strcmp("quit", argv[1]) == 0){
}
return(0);
}
+ if (argc>1 && strcmp("pwd", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for pwd\n");
+ return(1);
+ }
+ cwd = getcwd(NULL, MAXPATH);
+ if(cwd == NULL) {
+ printf("ERROR: %s\n",rrd_strerror(errno));
+ return(1);
+ }
+ printf("%s\n", cwd);
+ free(cwd);
+ return(0);
+ }
if (argc>1 && strcmp("mkdir", argv[1]) == 0){
if (argc>3){
printf("ERROR: invalid parameter count for mkdir\n");
}
}
}
+ closedir(curdir);
}
else{
printf("ERROR: %s\n",rrd_strerror(errno));
free (data);
}
} else if (strcmp("xport", argv[1]) == 0) {
- int xxsize;
+ int xxsize;
unsigned long int j = 0;
time_t start,end, ti;
unsigned long step, col_cnt,row_cnt;
rrd_value_t *data,*ptr;
char **legend_v;
- if(rrd_xport(argc-1, &argv[1], &xxsize,&start,&end,&step,&col_cnt,&legend_v,&data) != -1) {
+ int enumds = 0;
+ int i;
+ char *vtag = NULL;
+ vtag = malloc( strlen(COL_DATA_TAG)+10);
+ for ( i = 2; i < argc; i++){
+ if (strcmp("--enumds", argv[i]) == 0)
+ enumds = 1;
+ }
+
+ if(rrd_xport(argc-1, &argv[1], &xxsize,&start,&end,&step,&col_cnt,&legend_v,&data) != -1) {
row_cnt = (end-start)/step;
ptr = data;
printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n\n", XML_ENCODING);
printf (" <%s>", DATA_ROW_TAG);
printf ("<%s>%lu</%s>", COL_TIME_TAG, ti, COL_TIME_TAG);
for (j = 0; j < col_cnt; j++) {
+ if (enumds == 1)
+ snprintf(vtag,15,"%s%lu", COL_DATA_TAG, j);
+ else
+ snprintf(vtag,15,"%s",COL_DATA_TAG);
+
rrd_value_t newval = DNAN;
newval = *ptr;
if(isnan(newval)){
- printf("<%s>NaN</%s>", COL_DATA_TAG, COL_DATA_TAG);
+ printf("<%s>NaN</%s>", vtag,vtag);
} else {
- printf("<%s>%0.10e</%s>", COL_DATA_TAG, newval, COL_DATA_TAG);
+ printf("<%s>%0.10e</%s>", vtag, newval, vtag);
};
ptr++;
}
printf(" </%s>\n", DATA_TAG);
printf("</%s>\n", ROOT_TAG);
}
+ free(vtag);
}
else if (strcmp("graph", argv[1]) == 0) {
char **calcpr;
double ymin,ymax;
int i;
int tostdout = (strcmp(argv[2],"-") == 0);
+ int imginfo = 0;
+ for (i=2;i<argc;i++){
+ if (strcmp(argv[i],"--imginfo") == 0 || strcmp(argv[i],"-f") == 0){
+ imginfo = 1;
+ break;
+ }
+ }
if( rrd_graph(argc-1, &argv[1], &calcpr, &xsize, &ysize, NULL, &ymin, &ymax) != -1 ) {
- if (!tostdout)
+ if (!tostdout && !imginfo)
printf ("%dx%d\n",xsize,ysize);
if (calcpr) {
for(i=0;calcpr[i];i++){