/*****************************************************************************
- * RRDtool 1.2.13 Copyright by Tobi Oetiker, 1997-2006
+ * RRDtool 1.2.15 Copyright by Tobi Oetiker, 1997-2006
*****************************************************************************
* rrd_tool.c Startup wrapper
*****************************************************************************/
"\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[] =
"\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);
}
#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;