#ident "$URL: svn://elmer/devel/SVN/SDDAS/trunk/libCfg/Item.c $ %D% SwRI" #include #include #include #include #include "libCfg.h" /* * This program returns the names of the nodes at the next level in the * Projects tree. If no arguments are given then the return strings are * the names of all Projects in the Projects tree. Various levels of a * project may be given, the program will return a list of strings representing * the next level in the hierachy */ int main(int argc, char **argv) { #ifdef __CYGWIN__ extern int __declspec(dllimport) optind; /* index into parent argv vector */ extern char __declspec(dllimport) *optarg; /* argument associated with option */ #else extern char *optarg; extern int optind; #endif LinkList l = NULL; int c, errflg = 0, dbp=0, flg=0, ptp=0, rtp=0, pp=0, itemflg=0, args, i; char *path, *item = NULL, *s; StrHier S = NULL; while ((c = getopt(argc, argv, "vdptrs:")) != EOF) switch (c) { case 'v': break; case 's': item = optarg; flg = itemflg = 1; break; #ifndef NEW_DB case 'd': /* DatabasePath */ flg = dbp = 1; break; #endif case 'p': /* PidfPath */ flg = pp = 1; break; case 'r': /* RealTimePath */ flg = rtp = 1; break; case 't': /* PostTimePath */ flg = ptp = 1; break; default: errflg++; } args = argc - optind; if (flg && (args < 1)) errflg++; if (args > 5) errflg++; if (errflg) { (void)fprintf(stderr, "usage: %s [-s ][dptr] \n", argv[0]); (void)fprintf(stderr, " -s = print value for \n"); (void)fprintf(stderr, " -d = print database path\n"); (void)fprintf(stderr, " -p = print pidf path\n"); (void)fprintf(stderr, " -t = print post time path\n"); (void)fprintf(stderr, " -r = print real time path\n"); exit (2); } CfgInit(); l = CfgProjects (); if (l && !flg) { c = 1; while (argv [c] != NULL) c++; switch (c - 1) { case 1 : S = CfgStrHier (1, argv [1]); break; case 2 : S = CfgStrHier (2, argv [1], argv [2]); break; case 3 : S = CfgStrHier (3, argv [1], argv [2], argv [3]); break; case 4 : S = CfgStrHier (4, argv [1], argv [2], argv [3], argv [4]); break; case 5 : S = CfgStrHier (5, argv [1], argv [2], argv [3], argv [4], argv [5]); break; } /* switch */ if (c != 1 && S == NULL) printf ("ERROR: Does not exist!\n"); else if (S) l = S->sublist; if (l) { while (l != NULL) { S = (StrHier) l->data; fprintf (stdout, "%s ", SNAME(S)); l = l->next; } printf("\n"); } } if (flg) { if (itemflg) { printf("%s ", item); i = 0; do { switch (args) { case 1 : s = CfgGetItem (item, i, argv [3], NULL); break; case 2 : s = CfgGetItem (item, i, argv [3], argv [4], NULL); break; case 3 : s = CfgGetItem (item, i, argv [3], argv [4], argv [5], NULL); break; case 4 : s = CfgGetItem (item, i, argv [3], argv [4], argv [5], argv [6], NULL); break; case 5 : s = CfgGetItem (item, i, argv [3], argv [4], argv [5], argv [6], argv [7], NULL); break; } /* switch */ if (s != NULL) printf("%s ", s); i++; } while (s != NULL); printf("\n"); } /* all these below need a full hierarchy - check the number of arguments */ if ((pp || rtp || ptp) && (argc < 6)) { printf ("ERROR - need a full hierarchy!\n"); exit (-1); } if (pp) { if ((path = CfgGetPath("PidfPath", argv [2], argv [3], argv [4], argv [5], argv [6]))) { printf("PidfPath %s\n", path); } else { printf("BadPath for PidfPath\n"); } } if (rtp) { if ((path = CfgGetPath("RealTimePath", argv [2], argv [3], argv [4], argv [5], argv [6]))) { printf("RealTimePath %s\n", path); } else { printf("BadPath for RealTimePath\n"); } } if (ptp) { if ((path = CfgGetPath("PostTimePath", argv [2], argv [3], argv [4], argv [5], argv [6]))) { printf("PostTimePath %s\n", path); } else { printf("BadPath for PostTimePath\n"); } } #ifndef NEW_DB if (dbp) { if ((path = CfgGetPath("DatabasePath", argv [2], argv [3], argv [4], argv [5], argv [6]))) { printf("DatabasePath %s/Database\n", path); } else { printf("BadPath for DatabasePath\n"); } } #endif } CfgTerm(); exit(0); }