330{
331 char command[512];
334
337 char eqpstr[128] = { '\0' };
338 char cmdline[256];
339 signed char ch;
340 char mchart_dir[128] = { '\0' };
341 char mchart_data[128];
342 char mchart_conf[128+10];
344 int sys_err;
345
349
350
351 if (getenv("MCHART_DIR")) {
352 strcpy(mchart_dir, getenv("MCHART_DIR"));
355 }
356
357
358 for (
int i = 1;
i < argc;
i++) {
359 if (argv[
i][0] ==
'-' && argv[
i][1] ==
'd')
361 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'c')
363 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
's')
365 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'g' && argv[
i][2] ==
'g')
367 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'g' && argv[
i][2] ==
'h')
369 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'g')
371 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'k')
373 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'D')
375 else if (argv[
i][0] ==
'-') {
376 if (
i + 1 >= argc || (argv[
i + 1][0] ==
'-' && !isdigit(argv[
i + 1][1])))
378 if (strncmp(argv[
i],
"-u", 2) == 0)
380 else if (strncmp(argv[
i],
"-f", 2) == 0) {
381 char *pt;
382 pt = strstr(argv[++
i],
".conf");
383 if (pt)
384 *pt = '\0';
385 strcpy(mchart_data, mchart_dir);
386 strcat(mchart_data, argv[
i]);
387 sprintf(mchart_conf, "%s.conf", mchart_data);
388 }
else if (strncmp(argv[
i],
"-e", 2) == 0)
390 else if (strncmp(argv[
i],
"-h", 2) == 0)
392 else if (strncmp(argv[
i],
"-q", 2) == 0) {
393 if (argv[++
i][0] !=
'/')
394 strcpy(eqpstr, "/");
395 strcat(eqpstr, argv[
i]);
397 }
else if (strncmp(argv[
i],
"-b", 2) == 0)
399 else if (strncmp(argv[
i],
"-t", 2) == 0)
401 } else {
403 printf("usage: mchart -u updates (5sec)\n");
404 printf(" -f configuration or data file name\n");
405 printf(" -q equipment\n");
406 printf(" (override all) -b bot_limit -t top_limit (only with -q) \n");
407 printf(" -c create config only \n");
408 printf(" -k keep spawned stripchart or gstripchart\n");
409 printf
410 (" -g spawn Hofman stripchart or gstripchart if possible\n");
411 printf(" -gg forces gstripchart spawning\n");
412 printf(" -gh forces stripchart spawning\n");
413 printf(" -D start as daemon (prevented if -c or -q)\n");
414 printf(" requires $MCHART_DIR\n");
415 printf(" [-h Hostname] [-e Experiment]\n\n");
416 printf("ex: Creation : mchart -e myexpt -h myhost -c \n");
417 printf(" -f mydata -q /equipement/myeqp/variables\n");
418 printf(" Running : mchart -e myexpt -h myhost -f mydata \n");
419 printf(" Run/Graph : mchart -e myexpt -h myhost -f mydata -g\n");
420 printf(" MCHART_DIR: environment variable for mchar directory\n\n");
421 return 0;
422 }
423 }
424
425
427 printf("Becoming a daemon...\n");
429 }
430
432 printf("arg -D ignored due to creation request! \n");
433
434
437 return 1;
438
441
442
444
445
447
448
450
451
452 sprintf(cmdline, "%s ", argv[1]);
453 for (
int i = 2;
i < argc;
i++) {
454 strcat(cmdline, " ");
455 strcat(cmdline, argv[
i]);
456 }
457
458
460
461 FILE *f;
462 char strtmp[128];
463 char *peqp;
464 char *s;
465
468
469 f = fopen(mchart_conf, "r");
470 if (f == NULL) {
471 printf("Error: Cannot open %s\n", mchart_conf);
472 goto error;
473 }
474 s = fgets(strtmp, 128, f);
475 if (s == NULL) {
476 printf("Error: Cannot read %s\n", mchart_conf);
477 goto error;
478 }
479 if (strstr(strtmp, "#Equipment")) {
480 peqp = strstr(strtmp, ">");
481 sprintf(eqpstr, "%s", peqp + 1);
482 }
483 fclose(f);
484 peqp = strstr(eqpstr, "\n");
485 *peqp = 0;
486 } else {
487
488
489
491 printf("unknown odb path under -q arg. (%s)\n", eqpstr);
492 goto error;
493 }
496 goto error;
497 }
498
499 do {
504 goto error;
506 printf("mchart file %s created\n", mchart_conf);
507 goto out;
508 }
509 }
510
511
513 char command[512];
516
517 char strip[][32] = { "/usr/local/bin", "stripchart",
518 "/usr/bin", "gstripchart",
519 "/home/midas/bin", "stripchart",
520 "/usr/sbin", "gstripchart",
521 "/home/chaos/bin", "stripchart",
522 "/sbin", "gstripchart",
523 ""
524 };
525
527 while (strip[
i][0]) {
530 if (nfile == 1)
531 break;
533 }
534 if (strip[
i][0] == 0) {
535 printf("No graphic package found in following dir:\n");
537 while (strip[
i][0]) {
538 printf(
"Package : %s/%s \n", strip[
i], strip[
i + 1]);
540 }
541 break;
542 }
544 sprintf(command, "gstripchart -g 500x200-200-800 -f %s", mchart_conf);
545 else
546 sprintf(command, "stripchart %s", mchart_conf);
547
549 printf("Spawning graph with %s ...\nUse '!' to exit\n", command);
551 }
else if (
graph == 2) {
552 sprintf(command, "gstripchart -g 500x200-200-800 -f %s", mchart_conf);
554 printf("Spawning graph with %s ...\nUse '!' to exit\n", command);
556 }
else if (
graph == 3) {
558 sprintf(command, "stripchart -debug %s", mchart_conf);
560 printf("Spawning graph with %s ...in DEBUG mode \nUse '!' to exit\n",
561 command);
562 sys_err = system(command);
563 printf("system error return %d \n", sys_err);
565 return 1;
566
567 } else {
568 sprintf(command, "stripchart %s", mchart_conf);
570 printf("Spawning graph with %s .... \nUse '!' to exit\n", command);
572 }
573
574 }
575
577 ch = 0;
580 if (ch == -1)
581 ch = getchar();
582 if (ch == 'R')
584 if ((char) ch == '!')
585 break;
586 }
588
589
591 break;
592
594
595 out:
596 error:
597 printf("\n");
598
599
601
603 return 1;
604}
INT cm_yield(INT millisec)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_connect_experiment(const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *))
INT cm_disconnect_experiment(void)
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
INT ss_getchar(BOOL reset)
INT ss_daemon_init(BOOL keep_stdout)
INT ss_exec(const char *command, INT *pid)
BOOL ss_existpid(INT pid)
INT ss_file_find(const char *path, const char *pattern, char **plist)
INT cm_set_msg_print(INT system_mask, INT user_mask, int(*func)(const char *))
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
char host_name[HOST_NAME_LENGTH]
INT conf_compose(INT action, char *confpath, char *datapath, char *field, float val)
BOOL debug
debug printouts
INT mchart_compose(HNDLE hDB, char *confpath, char *datapath, char *eqpstr)
char expt_name[NAME_LENGTH]
#define DIR_SEPARATOR_STR
static te_expr * list(state *s)