MIDAS
Loading...
Searching...
No Matches
odbedit.cxx File Reference
#include "midas.h"
#include "mstrlcpy.h"
#include "msystem.h"
#include <stdio.h>
#include <assert.h>
#include <string>
Include dependency graph for odbedit.cxx:

Go to the source code of this file.

Classes

struct  PRINT_INFO
 

Macros

#define PI_LONG   (1 << 0)
 
#define PI_RECURSIVE   (1 << 1)
 
#define PI_VALUE   (1 << 2)
 
#define PI_HEX   (1 << 3)
 
#define PI_PAUSE   (1 << 4)
 

Functions

INT cmd_edit (const char *prompt, char *cmd, INT(*dir)(char *, INT *), INT(*idle)())
 
INT thread (void *p)
 
void key_update (HNDLE hDB, HNDLE hkey, void *info)
 
void print_help (char *command)
 
void process_message (HNDLE hBuf, HNDLE id, EVENT_HEADER *pheader, void *message)
 
int print_message (const char *msg)
 
BOOL match (char *pat, char *str)
 
BOOL check_abort (int flags, int l)
 
static void pad_to_pos (std::string *s, size_t pos)
 
INT print_key (HNDLE hDB, HNDLE hKey, KEY *pkey, INT level, void *info)
 
void set_key (HNDLE hDB, HNDLE hKey, int index1, int index2, char *value)
 
INT cmd_dir (char *line, INT *cursor)
 
INT search_key (HNDLE hDB, HNDLE hKey, KEY *key, INT level, void *info)
 
void del_tree (HNDLE hDB, HNDLE hKey, INT level)
 
static void xwrite (const char *filename, int fd, const void *data, int size)
 
void create_experim_h (HNDLE hDB, const char *analyzer_name)
 
INT cmd_idle ()
 
void compose_name (char *pwd, char *name, char *full_name)
 
void assemble_prompt (char *prompt, int psize, char *host_name, char *exp_name, char *pwd)
 
void watch_callback (HNDLE hDB, HNDLE hKey, INT index, void *info)
 
int command_loop (char *host_name, char *exp_name, char *cmd, char *start_dir)
 
void ctrlc_odbedit (INT i)
 
int main (int argc, char *argv[])
 

Variables

BOOL need_redraw
 
BOOL in_cmd_edit
 
char pwd [256]
 
BOOL cmd_mode
 
MUTEX_Ttm
 
BOOL key_modified
 
int ls_line
 
int ls_abort
 

Macro Definition Documentation

◆ PI_HEX

#define PI_HEX   (1 << 3)

Definition at line 36 of file odbedit.cxx.

◆ PI_LONG

#define PI_LONG   (1 << 0)

Definition at line 33 of file odbedit.cxx.

◆ PI_PAUSE

#define PI_PAUSE   (1 << 4)

Definition at line 37 of file odbedit.cxx.

◆ PI_RECURSIVE

#define PI_RECURSIVE   (1 << 1)

Definition at line 34 of file odbedit.cxx.

◆ PI_VALUE

#define PI_VALUE   (1 << 2)

Definition at line 35 of file odbedit.cxx.

Function Documentation

◆ assemble_prompt()

void assemble_prompt ( char prompt,
int  psize,
char host_name,
char exp_name,
char pwd 
)

Definition at line 1320 of file odbedit.cxx.

1320 {
1321 HNDLE hDB;
1322 char mask[256], str[32];
1323 int state, size;
1324 char *pp, *pm, *pc;
1325 time_t now;
1326
1327 const char *state_char[] = {"U", "S", "P", "R"};
1328 const char *state_str[] = {"Unknown", "Stopped", "Paused", "Running"};
1329
1331
1332 size = sizeof(mask);
1333 strcpy(mask, "[%h:%e:%s]%p>");
1334 db_get_value(hDB, 0, "/System/Prompt", mask, &size, TID_STRING, TRUE);
1335
1337 size = sizeof(state);
1338 db_get_value(hDB, 0, "/Runinfo/State", &state, &size, TID_INT, TRUE);
1339 if (state > STATE_RUNNING)
1340 state = 0;
1341
1342 pm = mask;
1343 pp = prompt;
1344 memset(prompt, 0, psize);
1345 do {
1346 if (*pm != '%') {
1347 *pp++ = *pm++;
1348 } else {
1349 switch (*++pm) {
1350 case 't':
1351 time(&now);
1352 assert(sizeof(str) >= 32);
1353 ctime_r(&now, str);
1354 str[19] = 0;
1355 strcpy(pp, str + 11);
1356 break;
1357 case 'h':
1358 if (host_name[0])
1360 else
1361 strcat(pp, "local");
1362 break;
1363 case 'e':
1364 if (exp_name[0])
1365 strcat(pp, exp_name);
1366 else
1367 strcat(pp, "Default");
1368 break;
1369 case 's':
1371 break;
1372 case 'S':
1374 break;
1375 case 'P':
1376 strcat(pp, pwd);
1377 break;
1378 case 'p':
1379 pc = pwd + strlen(pwd) - 1;
1380 while (*pc != '/' && pc != pwd)
1381 pc--;
1382 if (pc == pwd)
1383 strcat(pp, pwd);
1384 else
1385 strcat(pp, pc + 1);
1386 break;
1387 }
1388 pm++;
1389 pp += strlen(pp);
1390 }
1391 } while (*pm);
1392}
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
#define STATE_STOPPED
Definition midas.h:305
#define TID_STRING
Definition midas.h:346
#define STATE_RUNNING
Definition midas.h:307
#define TID_INT
Definition midas.h:338
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
Definition odb.cxx:5415
char exp_name[NAME_LENGTH]
Definition mana.cxx:243
HNDLE hDB
main ODB handle
Definition mana.cxx:207
char host_name[HOST_NAME_LENGTH]
Definition mana.cxx:242
INT HNDLE
Definition midas.h:132
#define TRUE
Definition midas.h:182
#define mask(slot)
Definition midas_macro.h:54
char pwd[256]
Definition odbedit.cxx:24
char str[256]
Definition odbhist.cxx:33
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_abort()

BOOL check_abort ( int  flags,
int  l 
)

Definition at line 212 of file odbedit.cxx.

212 {
213 int c;
214
215 if ((flags & PI_PAUSE) && (l % 24) == 23) {
216 printf("Press any key to continue or q to quit ");
217 fflush(stdout);
218 do {
219 c = ss_getchar(0);
220 if (c == 'q') {
221 printf("\n");
222 ls_abort = TRUE;
223 return TRUE;
224 } else if (c > 0) {
225 printf("\r \r");
226 return FALSE;
227 }
228
229 int status = cm_yield(100);
230 if (status == SS_ABORT || status == RPC_SHUTDOWN)
231 break;
232
233 } while (!cm_is_ctrlc_pressed());
234 }
235
236 if (cm_is_ctrlc_pressed()) {
237 ls_abort = TRUE;
238 return TRUE;
239 }
240
241 return FALSE;
242}
#define FALSE
Definition cfortran.h:309
INT cm_yield(INT millisec)
Definition midas.cxx:5642
BOOL cm_is_ctrlc_pressed()
Definition midas.cxx:5452
#define SS_ABORT
Definition midas.h:677
#define RPC_SHUTDOWN
Definition midas.h:707
INT ss_getchar(BOOL reset)
Definition system.cxx:7503
int ls_abort
Definition odbedit.cxx:210
#define PI_PAUSE
Definition odbedit.cxx:37
DWORD status
Definition odbhist.cxx:39
char c
Definition system.cxx:1310
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmd_dir()

INT cmd_dir ( char line,
INT cursor 
)

Definition at line 751 of file odbedit.cxx.

751 {
752 KEY key;
754 INT i, j, match, size;
755 char *pc, partial[256], last_match[256];
756 char head[256], tail[256], key_name[256], c;
757 char test_key[256];
759
761
762 /* remember tail for later */
763 strcpy(head, line);
764 strcpy(tail, line + *cursor);
765 line[*cursor] = 0;
766
767 /* search beginning of key */
768 pc = head;
769 do {
770 while (*pc && *pc != ' ')
771 pc++;
772 while (*pc && *pc == ' ')
773 pc++;
774 } while (*pc == '-'); /* skip flags */
775
776 if (*pc) {
777 strcpy(key_name, pc);
778 *pc = 0; /* end of head */
779 } else
780 key_name[0] = 0;
781
782 /* check if key exists (for "set <key>" completion) */
783 if (strncmp(head, "set", 3) == 0 && strlen(key_name) > 0) {
784 std::string ystr;
785 if (key_name[0] == '"')
786 ystr = (key_name + 1);
787 else
788 ystr = key_name;
789 if (key_name[0] != '/') {
790 strcpy(test_key, pwd);
791 if (test_key[strlen(test_key) - 1] != '/')
792 strcat(test_key, "/");
793 strcat(test_key, ystr.c_str());// FIXME: buffer overflow. KO aug2024
794 } else {
795 strcpy(test_key, ystr.c_str());// FIXME: buffer overflow. KO aug2024
796 }
797
798 pc = test_key + strlen(test_key) - 1;
799 while (pc > test_key && (*pc == ' ' || *pc == '"'))
800 *pc-- = 0;
802 if (status == DB_SUCCESS) {
803 /* retrieve key data */
805
806 if (key.type != TID_KEY) {
807 if (strlen(key_name) > 0 && key_name[strlen(key_name) - 1] != ' ')
808 strcat(key_name, " ");
809
810 assert(key.total_size > 0);
811 char *buf = (char *) malloc(key.total_size);
812 size = key.total_size;
813 status = db_get_link_data(hDB, hSubkey, buf, &size, key.type);
814
815 std::string xstr;
816
817 if (key.type == TID_STRING || key.type == TID_LINK) {
818 xstr += "\"";
819 xstr += buf;
820 xstr += "\"";
821 } else {
822 xstr = db_sprintf(buf, size, 0, key.type);
823 }
824
825 free(buf);
826
827 strcpy(line, head);
828 strcat(line, key_name);
829 strcat(line, xstr.c_str());// FIXME: buffer overflow. KO Aug2024
830 *cursor = strlen(line);
831 strcat(line, tail);
832 return TRUE;
833 }
834 }
835 }
836
837 /* combine pwd and key_name */
838 pc = key_name;
839 if (*pc == '"')
840 pc++;
841
842 char str[256];// FIXME: buffer overflows. K.O> Aug2024
843 str[0] = 0;
844
845 if (*pc != '/') {
846 strcpy(str, pwd);
847 if (str[strlen(str) - 1] != '/')
848 strcat(str, "/");
849 strcat(str, pc);
850 } else
851 strcpy(str, pc);
852
853 /* split key_name into known and new directory */
854 for (pc = str + strlen(str) - 1; pc > str && *pc != '/'; pc--)
855 ;
856
857 if (*pc == '/') {
858 *pc = 0;
859 strcpy(partial, pc + 1);
860 } else
861 strcpy(partial, str);
862
863 db_find_link(hDB, 0, str, &hKey);
864 for (i = 0, match = 0;; i++) {
866
867 if (!hSubkey)
868 break;
869
871 strcpy(str, key.name);
872
873 str[strlen(partial)] = 0;
874
876 match++;
877 }
878
879 if (match != 1)
880 printf("\r\n");
881
882 for (i = 0;; i++) {
884
885 if (!hSubkey)
886 break;
887
889 strcpy(str, key.name);
890
891 str[strlen(partial)] = 0;
892
893 if (equal_ustring(str, partial)) {
894 if (match == 1) {
895 /* search split point */
896 pc = key_name;
897 if (strlen(key_name) > 0)
898 for (pc = key_name + strlen(key_name) - 1; pc > key_name && *pc != '/';
899 pc--)
900 ;
901 if (*pc == '/')
902 pc++;
903
904 strcpy(pc, key.name);
905 if (key.type == TID_KEY)
906 strcat(pc, "/");
907
908 /* insert '"' if blanks in name */
909 if (strchr(key.name, ' ')) {
910 if (key_name[0] != '"') {
911 for (i = strlen(key_name); i >= 0; i--)
912 key_name[i + 1] = key_name[i];
913
914 key_name[0] = '"';
915 }
916 if (key.type != TID_KEY)
917 strcat(key_name, "\"");
918 }
919
920 if (key.type != TID_KEY) {
921 if (key_name[0] == '"' && key_name[strlen(key_name) - 1] != '"')
922 strcat(pc, "\" ");
923 else
924 strcat(pc, " ");
925 }
926
927 strcpy(line, head);
928 strcat(line, key_name);
929 *cursor = strlen(line);
930 strcat(line, tail);
931 return TRUE;
932 }
933 }
934 if (match == 0 || (match > 1 && equal_ustring(str, partial)))
935 printf("%s\r\n", key.name);
936 }
937
938 if (match > 1 && key_name[0]) {
939 blanks = FALSE;
940
941 for (j = strlen(partial);; j++) {
942 for (i = 0, c = 1, mismatch = FALSE;; i++) {
944
945 if (!hSubkey)
946 break;
947
949 strcpy(str, key.name);
950
951 str[strlen(partial)] = 0;
952
953 if (strchr(key.name, ' '))
954 blanks = TRUE;
955
956 if (equal_ustring(str, partial)) {
957 strcpy(last_match, key.name);
958 if (c == 1)
959 c = toupper(key.name[j]);
960 else if (c != toupper(key.name[j])) {
961 mismatch = TRUE;
962 break;
963 }
964 }
965 }
966
967 if (mismatch || last_match[j] == 0)
968 break;
969 }
970
971 /* search split point */
972 for (pc = key_name + strlen(key_name) - 1; pc > key_name && *pc != '/'; pc--)
973 ;
974 if (*pc == '/')
975 pc++;
976
977 for (i = 0; i < j; i++)
978 pc[i] = last_match[i];
979 pc[i] = 0;
980
981 /* insert '"' if blanks in name */
982 if (blanks) {
983 if (key_name[0] != '"') {
984 for (i = strlen(key_name); i >= 0; i--)
985 key_name[i + 1] = key_name[i];
986
987 key_name[0] = '"';
988 }
989 }
990
991 strcpy(line, head);
992 strcat(line, key_name);
993 *cursor = strlen(line);
994 strcat(line, tail);
995 return TRUE;
996 }
997
998 /* beep if not found */
999 printf("\007");
1000
1001 strcpy(line, head);
1002 strcat(line, key_name);
1003 *cursor = strlen(line);
1004 strcat(line, tail);
1005 return FALSE;
1006}
#define DB_SUCCESS
Definition midas.h:631
#define TID_KEY
Definition midas.h:349
#define TID_LINK
Definition midas.h:350
BOOL equal_ustring(const char *str1, const char *str2)
Definition odb.cxx:3201
INT db_find_link(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4274
INT db_get_link(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6072
INT db_enum_link(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
Definition odb.cxx:5725
INT db_sprintf(char *string, const void *data, INT data_size, INT idx, DWORD type)
Definition odb.cxx:10843
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
INT db_get_link_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:6656
HNDLE hKey
KEY key
Definition mdump.cxx:34
INT i
Definition mdump.cxx:32
HNDLE hSubkey
Definition mdump.cxx:35
DWORD BOOL
Definition midas.h:105
int INT
Definition midas.h:129
BOOL match(char *pat, char *str)
Definition odbedit.cxx:190
INT j
Definition odbhist.cxx:40
Definition midas.h:1026
DWORD type
Definition midas.h:1027
INT total_size
Definition midas.h:1031
char name[NAME_LENGTH]
Definition midas.h:1029
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmd_edit()

INT cmd_edit ( const char prompt,
char cmd,
INT(*)(char *, INT *)  dir,
INT(*)()  idle 
)
extern

Definition at line 38 of file cmdedit.cxx.

39{
40 char line[LINE_LENGTH];
41 INT i, j, k, c, hi;
42 INT status;
43 DWORD last_time = 0;
44 BOOL escape_flag = 0;
45
46 if (ss_getchar(0) == -1) {
47 /* normal input if ss_getchar not supported */
49 ss_gets(cmd, 256);
50 return strlen(cmd);
51 }
52
55
56 hi = his_index;
57 memset(line, 0, LINE_LENGTH);
59 strcpy(line, cmd);
60 fputs(line, stdout);
61 i = strlen(cmd);
63
64 do {
65 c = ss_getchar(0);
66
67 if (c == 27)
69
70 if (c >= ' ' && c < CH_EXT && escape_flag) {
72 if (c == 'p')
73 c = 6;
74 }
75
76 /* normal input */
77 if (c >= ' ' && c < CH_EXT) {
78 if (strlen(line) < LINE_LENGTH - 1) {
79 for (j = strlen(line); j >= i; j--)
80 line[j + 1] = line[j];
81 if (i < LINE_LENGTH - 1) {
82 line[i++] = c;
83 fputc(c, stdout);
84 }
85 for (j = i; j < (INT) strlen(line); j++)
86 fputc(line[j], stdout);
87 for (j = i; j < (INT) strlen(line); j++)
88 fputc('\b', stdout);
89 }
90 }
91
92 /* BS */
93 if (c == CH_BS && i > 0) {
94 i--;
95 fputc('\b', stdout);
96 for (j = i; j <= (INT) strlen(line); j++) {
97 line[j] = line[j + 1];
98 if (line[j])
99 fputc(line[j], stdout);
100 else
101 fputc(' ', stdout);
102 }
103 for (k = 0; k < j - i; k++)
104 fputc('\b', stdout);
105 }
106
107 /* DELETE/Ctrl-D */
108 if (c == CH_DELETE || c == 4) {
109 for (j = i; j <= (INT) strlen(line); j++) {
110 line[j] = line[j + 1];
111 if (line[j])
112 fputc(line[j], stdout);
113 else
114 fputc(' ', stdout);
115 }
116 for (k = 0; k < j - i; k++)
117 fputc('\b', stdout);
118 }
119
120 /* Erase line: CTRL-W, CTRL-U */
121 if (c == 23 || c == 21) {
122 i = strlen(line);
123 memset(line, 0, sizeof(line));
124 printf("\r%s", prompt);
125 for (j = 0; j < i; j++)
126 fputc(' ', stdout);
127 for (j = 0; j < i; j++)
128 fputc('\b', stdout);
129 i = 0;
130 }
131
132 /* Erase line from cursor: CTRL-K */
133 if (c == 11) {
134 for (j = i; j < (INT) strlen(line); j++)
135 fputc(' ', stdout);
136 for (j = i; j < (INT) strlen(line); j++)
137 fputc('\b', stdout);
138 for (j = strlen(line); j >= i; j--)
139 line[j] = 0;
140 }
141
142 /* left arrow, CTRL-B */
143 if ((c == CH_LEFT || c == 2) && i > 0) {
144 i--;
145 fputc('\b', stdout);
146 }
147
148 /* right arrow, CTRL-F */
149 if ((c == CH_RIGHT || c == 6) && i < (INT) strlen(line))
150 fputc(line[i++], stdout);
151
152 /* HOME, CTRL-A */
153 if ((c == CH_HOME || c == 1) && i > 0) {
154 for (j = 0; j < i; j++)
155 fputc('\b', stdout);
156 i = 0;
157 }
158
159 /* END, CTRL-E */
160 if ((c == CH_END || c == 5) && i < (INT) strlen(line)) {
161 for (j = i; j < (INT) strlen(line); j++)
162 fputc(line[i++], stdout);
163 i = strlen(line);
164 }
165
166 /* up arrow / CTRL-P */
167 if (c == CH_UP || c == 16) {
168 if (history[(hi + MAX_HISTORY - 1) % MAX_HISTORY][0]) {
169 hi = (hi + MAX_HISTORY - 1) % MAX_HISTORY;
170 i = strlen(line);
171 fputc('\r', stdout);
173 for (j = 0; j < i; j++)
174 fputc(' ', stdout);
175 for (j = 0; j < i; j++)
176 fputc('\b', stdout);
177 memcpy(line, history[hi], 256);
178 i = strlen(line);
179 for (j = 0; j < i; j++)
180 fputc(line[j], stdout);
181 }
182 }
183
184 /* down arrow / CTRL-N */
185 if (c == CH_DOWN || c == 14) {
186 if (history[hi][0]) {
187 hi = (hi + 1) % MAX_HISTORY;
188 i = strlen(line);
189 fputc('\r', stdout);
191 for (j = 0; j < i; j++)
192 fputc(' ', stdout);
193 for (j = 0; j < i; j++)
194 fputc('\b', stdout);
195 memcpy(line, history[hi], 256);
196 i = strlen(line);
197 for (j = 0; j < i; j++)
198 fputc(line[j], stdout);
199 }
200 }
201
202 /* CTRL-F */
203 if (c == 6) {
204 for (j = (hi + MAX_HISTORY - 1) % MAX_HISTORY; j != hi;
205 j = (j + MAX_HISTORY - 1) % MAX_HISTORY)
206 if (history[j][0] && strncmp(line, history[j], i) == 0) {
207 memcpy(line, history[j], 256);
208 fputs(line + i, stdout);
209 i = strlen(line);
210 break;
211 }
212 if (j == hi)
213 fputc(7, stdout);
214 }
215
216 /* tab */
217 if (c == 9 && dir != NULL) {
218 status = dir(line, &i);
219
220 /* redraw line */
221 fputc('\r', stdout);
223 fputs(line, stdout);
224
225 for (j = 0; j < (INT) strlen(line) - i; j++)
226 fputc('\b', stdout);
227 }
228
229 if (c != 0) {
231 fflush(stdout);
232 }
233
234 if ((ss_millitime() - last_time > 300) && idle != NULL) {
235 status = idle();
236
237 if (status) {
238 fputc('\r', stdout);
240 fputs(line, stdout);
241
242 for (j = 0; j < (INT) strlen(line) - i; j++)
243 fputc('\b', stdout);
244
245 fflush(stdout);
246 }
247 }
248
249 } while (c != CH_CR && c != CH_LF);
250
251 strcpy(cmd, line);
252
253 if (dir != NULL)
254 if (strcmp(cmd, history[(his_index + MAX_HISTORY - 1) % MAX_HISTORY]) != 0 &&
255 cmd[0]) {
256 strcpy(history[his_index], cmd);
258 }
259
260 /* reset terminal */
261 ss_getchar(1);
262
263 fputc('\n', stdout);
264
265 return strlen(line);
266}
char history[MAX_HISTORY][LINE_LENGTH]
Definition cmdedit.cxx:23
#define MAX_HISTORY
Definition cmdedit.cxx:18
#define LINE_LENGTH
Definition cmdedit.cxx:21
INT his_index
Definition cmdedit.cxx:24
unsigned int DWORD
Definition mcstd.h:51
DWORD ss_millitime()
Definition system.cxx:3393
char * ss_gets(char *string, int size)
Definition system.cxx:7770
DWORD last_time
Definition mana.cxx:3070
#define CH_LF
Definition midas.h:447
#define CH_END
Definition midas.h:455
#define CH_DOWN
Definition midas.h:459
#define CH_DELETE
Definition midas.h:454
#define CH_EXT
Definition midas.h:450
#define CH_RIGHT
Definition midas.h:460
#define CH_CR
Definition midas.h:448
#define CH_LEFT
Definition midas.h:461
#define CH_HOME
Definition midas.h:452
#define CH_UP
Definition midas.h:458
#define CH_BS
Definition midas.h:445
INT k
Definition odbhist.cxx:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmd_idle()

INT cmd_idle ( )

Definition at line 1283 of file odbedit.cxx.

1283 {
1284 INT status;
1285
1287
1288 status = cm_yield(100);
1289
1290 /* abort if server connection is broken */
1291 if (status == SS_ABORT || status == RPC_SHUTDOWN) {
1292 if (status == SS_ABORT)
1293 printf("Server connection broken.\n");
1294
1295 ss_getchar(1);
1297 exit(0);
1298 }
1299
1300 /* check for broken client connections */
1302
1303 return need_redraw;
1304}
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
void rpc_client_check()
Definition midas.cxx:12270
BOOL need_redraw
Definition odbedit.cxx:22
Here is the call graph for this function:
Here is the caller graph for this function:

◆ command_loop()

int command_loop ( char host_name,
char exp_name,
char cmd,
char start_dir 
)

Definition at line 1445 of file odbedit.cxx.

1445 {
1447 char line[2000], prompt[256];
1448 char param[10][2000];
1449 char str[2000], str2[80], name[256], *pc;
1450 char old_password[32], new_password[32];
1451 INT nparam, flags, index1, index2, debug_flag, mthread_flag;
1452 WORD mode;
1454 KEY key;
1455 char user_name[80] = "";
1456 FILE *cmd_file = NULL;
1457 DWORD last_msg_time = 0;
1458 char message[2000], client_name[256], *p;
1459 INT n1, n2;
1461
1463
1464 /* command loop */
1465 if (start_dir[0])
1466 strcpy(pwd, start_dir);
1467 else
1468 strcpy(pwd, "/");
1469
1470 /* check if dir exists */
1471 if (db_find_key(hDB, 0, pwd, &hKey) != DB_SUCCESS) {
1472 printf("Directory \"%s\" not found.\n", pwd);
1473 return -1;
1474 }
1475
1476 /* open command file */
1477 if (cmd[0] == '@') {
1478 cmd_file = fopen(cmd + 1, "r");
1479 if (cmd_file == NULL) {
1480 printf("Command file %s not found.\n", cmd + 1);
1481 return -1;
1482 }
1483 }
1484
1485 do {
1486 /* print prompt */
1487 if (!cmd_mode) {
1489
1490 in_cmd_edit = TRUE;
1491 line[0] = 0;
1494 } else if (cmd[0] != '@')
1495 mstrlcpy(line, cmd, sizeof(line));
1496 else {
1497 memset(line, 0, sizeof(line));
1498 char *s = fgets(line, sizeof(line), cmd_file);
1499
1500 if (s == NULL || line[0] == 0)
1501 break;
1502
1503 /* cut off CR */
1504 while (strlen(line) > 0 && line[strlen(line) - 1] == '\n')
1505 line[strlen(line) - 1] = 0;
1506
1507 if (line[0] == 0)
1508 continue;
1509 }
1510
1511 /* analyze line */
1512 nparam = 0;
1513 pc = line;
1514 while (*pc == ' ')
1515 pc++;
1516
1517 memset(param, 0, sizeof(param));
1518 do {
1519 if (*pc == '"') {
1520 pc++;
1521 for (i = 0; *pc && *pc != '"' && i < (int) sizeof(param[0]) - 1; i++)
1522 param[nparam][i] = *pc++;
1523 if (*pc)
1524 pc++;
1525 } else if (*pc == '\'') {
1526 pc++;
1527 for (i = 0; *pc && *pc != '\'' && i < (int) sizeof(param[0]) - 1; i++)
1528 param[nparam][i] = *pc++;
1529 if (*pc)
1530 pc++;
1531 } else if (*pc == '`') {
1532 pc++;
1533 for (i = 0; *pc && *pc != '`' && i < (int) sizeof(param[0]) - 1; i++)
1534 param[nparam][i] = *pc++;
1535 if (*pc)
1536 pc++;
1537 } else
1538 for (i = 0; *pc && *pc != ' ' && i < (int) sizeof(param[0]) - 1; i++)
1539 param[nparam][i] = *pc++;
1540 param[nparam][i] = 0;
1541 while (*pc == ' ')
1542 pc++;
1543 nparam++;
1544 } while (*pc);
1545
1546 /* help */
1547 if ((param[0][0] == 'h' && param[0][1] == 'e') || param[0][0] == '?')
1548 print_help(param[1]);
1549
1550 /* ls */
1551 else if ((param[0][0] == 'l' && param[0][1] == 's') || (param[0][0] == 'd' && param[0][1] == 'i')) {
1552 db_find_key(hDB, 0, pwd, &hKey);
1553 print_info.flags = 0;
1554 print_info.pattern[0] = 0;
1555 ls_line = 0;
1556 ls_abort = FALSE;
1557
1558 /* parse options */
1559 for (i = 1; i < 4; i++)
1560 if (param[i][0] == '-') {
1561 for (int j = 1; param[i][j] != ' ' && param[i][j]; j++) {
1562 if (param[i][j] == 'l')
1563 print_info.flags |= PI_LONG;
1564 if (param[i][j] == 'r')
1565 print_info.flags |= PI_RECURSIVE;
1566 if (param[i][j] == 'v')
1567 print_info.flags |= PI_VALUE;
1568 if (param[i][j] == 'h')
1569 print_info.flags |= PI_HEX;
1570 if (param[i][j] == 'p')
1571 print_info.flags |= PI_PAUSE;
1572 }
1573 }
1574
1575 for (i = 1; param[i][0] == '-'; i++)
1576 ;
1577
1578 /* check if parameter contains array index */
1579 print_info.index = -1;
1580 if (strchr(param[i], '[') && strchr(param[i], ']')) {
1581 for (p = strchr(param[i], '[') + 1; *p && *p != ']'; p++)
1582 if (!isdigit(*p))
1583 break;
1584
1585 if (*p && *p == ']') {
1586 print_info.index = atoi(strchr(param[i], '[') + 1);
1587 *strchr(param[i], '[') = 0;
1588 }
1589 }
1590
1591 if (param[i][0]) {
1592 if (strpbrk(param[i], "*?") != NULL) {
1593 /* if parameter contains wildcards, set pattern */
1594 strcpy(print_info.pattern, param[i]);
1595 } else {
1596 if (param[i][0] == '/')
1597 status = db_find_link(hDB, 0, param[i], &hKey);
1598 else
1600
1601 if (status == DB_NO_KEY)
1602 printf("key %s not found\n", param[i]);
1603
1604 if (status == DB_INVALID_LINK)
1605 printf("link %s points to invalid location\n", param[i]);
1606 }
1607 }
1608
1609 if (hKey) {
1610 if ((print_info.flags & PI_LONG) && (print_info.flags & PI_VALUE) == 0) {
1611 printf("Key name Type #Val Size Last Opn Mode Value\n");
1612 printf("---------------------------------------------------------------------------\n");
1613 }
1614
1615 if (print_info.flags & PI_RECURSIVE) {
1617 if (cm_is_ctrlc_pressed())
1619 } else {
1620 db_get_link(hDB, hKey, &key);
1621 if (key.type != TID_KEY)
1622 print_key(hDB, hKey, &key, 0, &print_info);
1623 else
1624 for (i = 0;; i++) {
1625 if (cm_is_ctrlc_pressed()) {
1627 break;
1628 }
1629
1631
1632 if (!hSubkey)
1633 break;
1634
1637 if (status == 0)
1638 break;
1639 }
1640 }
1641 }
1642 }
1643
1644 /* cd */
1645 else if (param[0][0] == 'c' && param[0][1] == 'd') {
1646 if (strlen(param[1]) == 0)
1647 strcpy(str, "/");
1648 else
1649 compose_name(pwd, param[1], str);
1650
1651 status = db_find_key(hDB, 0, str, &hKey);
1652
1653 if (strcmp(str, "/") == 0)
1654 strcpy(pwd, str);
1655 else if (status == DB_SUCCESS) {
1656 db_get_key(hDB, hKey, &key);
1657 if (key.type != TID_KEY)
1658 printf("key has no subkeys\n");
1659 else {
1660 std::string path = db_get_path(hDB, hKey);
1661 mstrlcpy(pwd, path.c_str(), sizeof(pwd));
1662 }
1663 } else
1664 printf("key not found\n");
1665 }
1666
1667 /* pwd */
1668 else if (param[0][0] == 'p' && param[0][1] == 'w') {
1669 printf("%s\n", pwd);
1670 }
1671
1672 /* create */
1673 else if (param[0][0] == 'c' && param[0][1] == 'r') {
1674 compose_name(pwd, param[2], str);
1675
1676 /* check if array */
1677
1678 k = -1;
1679 int j = 0;
1680 if (str[strlen(str) - 1] == ']') {
1681 if (strchr(str, '[')) {
1682 j = atoi(strchr(str, '[') + 1);
1683 mstrlcpy(str2, strchr(str, '[') + 1, sizeof(str2));
1684 *strchr(str, '[') = 0;
1685 if (strchr(str2, '['))
1686 k = atoi(strchr(str2, '[') + 1);
1687 }
1688 } else
1689 j = 1;
1690
1691 /* get TID */
1692 for (i = 0; i < TID_LAST; i++) {
1694 break;
1695 }
1696
1697 if (i == TID_LAST) {
1698 printf("Unknown type. Must be one of:\n");
1699 printf("{ UINT8,INT8,UINT16,INT16,UINT32,INT32,UINT64,INT64,BOOL,FLOAT,DOUBLE,STRING }\n");
1700 } else {
1701 db_create_key(hDB, 0, str, i);
1702 db_find_key(hDB, 0, str, &hKey);
1703 db_get_key(hDB, hKey, &key);
1704
1705 if (i == TID_STRING) {
1706 if (!cmd_mode && k == -1) {
1707 printf("String length [%d]: ", NAME_LENGTH);
1708 ss_gets(str, 256);
1709 if (str[0])
1710 key.item_size = atoi(str);
1711 else
1713 } else if (k == -1)
1715 else
1716 key.item_size = k;
1717
1718 char *buf = (char *) malloc(key.item_size);
1719 memset(buf, 0, sizeof(key.item_size));
1721 free(buf);
1722 }
1723
1724 if (j > 1) {
1725 if (key.type == TID_LINK)
1727 char *buf = (char *) malloc(key.item_size);
1728 memset(buf, 0, sizeof(key.item_size));
1730 free(buf);
1731 }
1732 }
1733 }
1734
1735 /* mkdir */
1736 else if (param[0][0] == 'm' && param[0][1] == 'k') {
1737 compose_name(pwd, param[1], str);
1739 }
1740
1741 /* link */
1742 else if (param[0][0] == 'l' && param[0][1] == 'n') {
1743 compose_name(pwd, param[2], str);
1744 db_create_link(hDB, 0, str, param[1]);
1745 }
1746
1747 /* copy */
1748 else if (param[0][0] == 'c' && (param[0][1] == 'o' || param[0][1] == 'p')) {
1749 /* test if destination exists */
1750 compose_name(pwd, param[2], str);
1751 status = db_find_link(hDB, 0, str, &hKey);
1752 if (status == DB_SUCCESS) {
1753 if (cmd_mode)
1754 str[0] = 'y';
1755 else {
1756 printf("Overwrite existing key\n\"%s\"\n(y/[n]) ", str);
1757 ss_gets(str, 256);
1758 }
1759 if (str[0] == 'y')
1761 }
1762
1763 if (status == DB_NO_KEY || str[0] == 'y') {
1764 compose_name(pwd, param[1], str);
1765
1766 status = db_find_link(hDB, 0, str, &hKey);
1767 if (status == DB_SUCCESS) {
1768 compose_name(pwd, param[2], str);
1769
1770 db_get_key(hDB, hKey, &key);
1772
1773 if (key.type != TID_KEY) {
1774 assert(key.total_size > 0);
1775 char *buf = (char *) malloc(key.total_size);
1776 size = key.total_size;
1777 db_get_data(hDB, hKey, buf, &size, key.type);
1778 db_find_key(hDB, 0, str, &hKey);
1780 free(buf);
1781 } else {
1782 char data[50000];
1783 size = sizeof(data);
1784 status = db_copy(hDB, hKey, data, &size, "");
1785 if (status == DB_TRUNCATED) {
1786 printf("error: db_copy() status %d, odbedit internal buffer is too small, size %d\n", status, size);
1787 } else if (status != DB_SUCCESS) {
1788 printf("error: db_copy() status %d\n", status);
1789 } else {
1790 db_find_key(hDB, 0, str, &hKey);
1791 db_paste(hDB, hKey, data);
1792 }
1793 }
1794 } else {
1795 printf("key not found\n");
1796 }
1797 }
1798 }
1799
1800 /* delete */
1801 else if ((param[0][0] == 'd' && param[0][1] == 'e') || (param[0][0] == 'r' && param[0][1] == 'm')) {
1802 flags = 0;
1803 if ((param[1][0] == '-' && param[1][1] == 'f') || (param[2][0] == '-' && param[2][1] == 'f'))
1804 flags |= (1 << 0);
1805 if ((param[1][0] == '-' && param[1][1] == 'l') || (param[2][0] == '-' && param[2][1] == 'l'))
1806 flags |= (1 << 1);
1807
1808 for (i = 1; param[i][0] == '-'; i++)
1809 ;
1810
1812
1813 status = db_find_link(hDB, 0, str, &hKey);
1814 db_get_key(hDB, hKey, &key);
1815
1816 if (status == DB_SUCCESS) {
1817 if (flags & (1 << 0) || cmd_mode)
1818 str[0] = 'y';
1819 else {
1820 if (key.type == TID_KEY)
1821 printf("Are you sure to delete the key\n\"%s\"\nand all its subkeys? (y/[n]) ",
1822 str);
1823 else
1824 printf("Are you sure to delete the key\n\"%s\"\n(y/[n]) ", str);
1825
1826 ss_gets(str, 256);
1827 }
1828
1829 if (str[0] == 'y') {
1830 status = db_delete_key(hDB, hKey, (flags & (1 << 1)) > 0);
1831 if (status == DB_NO_ACCESS) {
1832 printf("deletion of key not allowed\n");
1833 } else if (status == DB_OPEN_RECORD) {
1834 printf("key is open by other client\n");
1835 } else if (status != DB_SUCCESS) {
1836 printf("Error, db_delete_key() status %d\n", status);
1837 }
1838 }
1839 } else
1840 printf("key not found\n");
1841 }
1842
1843 /* set */
1844 else if (param[0][0] == 's' && param[0][1] == 'e') {
1845 /* check if index is supplied */
1846 index1 = index2 = 0;
1847 strcpy(str, param[1]);
1850
1851 std::vector<HNDLE> keys;
1852 status = db_find_keys(hDB, 0, name, keys);
1853
1854 if (status != DB_SUCCESS) {
1855 printf("Error: Key \"%s\" not found\n", name);
1856 if (cmd_mode)
1857 return -1;
1858 } else {
1859 for (HNDLE hMatchedKey : keys) {
1861 }
1862 }
1863 }
1864
1865 /* set mode */
1866 else if (param[0][0] == 'c' && param[0][1] == 'h' && param[0][2] == 'm') {
1867 if (param[1][0] == 0 && param[2][0] == 0) {
1868 printf("Please specify mode and key\n");
1869 } else {
1870 compose_name(pwd, param[2], str);
1871
1872 mode = atoi(param[1]);
1873
1874 if (strcmp(str, "/") != 0) {
1875 status = db_find_key(hDB, 0, str, &hKey);
1876 } else {
1878 hKey = 0;
1879 }
1880
1881 if (status == DB_SUCCESS) {
1882 if (cmd_mode)
1883 str[0] = 'y';
1884 else {
1885 printf("Are you sure to change the mode of key\n %s\nand all its subkeys\n",
1886 str);
1887 printf("to mode [%c%c%c%c]? (y/[n]) ", mode & MODE_READ ? 'R' : 0,
1888 mode & MODE_WRITE ? 'W' : 0, mode & MODE_DELETE ? 'D' : 0,
1889 mode & MODE_EXCLUSIVE ? 'E' : 0);
1890 ss_gets(str, 256);
1891 }
1892 if (str[0] == 'y')
1894 } else {
1895 printf("Error: Key \"%s\" not found\n", str);
1896 if (cmd_mode)
1897 return -1;
1898 }
1899 }
1900 }
1901
1902 /* test_rpc */
1903 else if (strcmp(param[0], "test_rpc") == 0) {
1904 status = rpc_test_rpc();
1905 if (status == RPC_SUCCESS)
1906 printf("RPC test passed!\n");
1907 else
1908 printf("RPC test failed!\n");
1909 }
1910
1911 /* truncate */
1912 else if (param[0][0] == 't' && param[0][1] == 'r') {
1913 if (param[1][0] == 0) {
1914 printf("Please specify key\n");
1915 } else {
1916 compose_name(pwd, param[1], str);
1917
1918 status = db_find_key(hDB, 0, str, &hKey);
1919
1920 i = atoi(param[2]);
1921 if (i == 0)
1922 i = 1;
1923
1924 if (status == DB_SUCCESS)
1926 else {
1927 printf("Error: Key \"%s\" not found\n", str);
1928 if (cmd_mode)
1929 return -1;
1930 }
1931 }
1932 }
1933
1934 /* rename */
1935 else if (param[0][0] == 'r' && param[0][1] == 'e' && param[0][2] == 'n') {
1936 if (param[1][0] == 0) {
1937 printf("Please specify key\n");
1938 } else {
1939 compose_name(pwd, param[1], str);
1940
1941 if (strcmp(str, "/") != 0)
1942 status = db_find_link(hDB, 0, str, &hKey);
1943 else
1944 hKey = 0;
1945
1946 if (status == DB_SUCCESS || !hKey)
1948 else {
1949 printf("Error: Key \"%s\" not found\n", str);
1950 if (cmd_mode)
1951 return -1;
1952 }
1953 }
1954 }
1955
1956 /* move */
1957 else if (param[0][0] == 'm' && param[0][1] == 'o') {
1958 if (param[1][0] == 0) {
1959 printf("Please specify key\n");
1960 } else {
1961 compose_name(pwd, param[1], str);
1962
1963 if (strcmp(str, "/") != 0)
1964 status = db_find_link(hDB, 0, str, &hKey);
1965 else
1966 hKey = 0;
1967
1968 if (status == DB_SUCCESS || !hKey) {
1969 if (param[2][0] == 't')
1970 i = 0;
1971 else if (param[2][0] == 'b')
1972 i = -1;
1973 else
1974 i = atoi(param[2]);
1975
1977 if (status == DB_NO_ACCESS)
1978 printf("no write access to key\n");
1979 if (status == DB_OPEN_RECORD)
1980 printf("key is open by other client\n");
1981 } else {
1982 printf("Error: Key \"%s\" not found\n", str);
1983 if (cmd_mode)
1984 return -1;
1985 }
1986 }
1987 }
1988
1989 /* find key */
1990 else if (param[0][0] == 'f' && param[0][1] == 'i') {
1991 status = db_find_key(hDB, 0, pwd, &hKey);
1992
1993 if (status == DB_SUCCESS)
1994 db_scan_tree(hDB, hKey, 0, search_key, (void *) param[1]);
1995 else
1996 printf("current key is invalid / no read access\n");
1997 }
1998
1999 /* load */
2000 else if (param[0][0] == 'l' && param[0][1] == 'o') {
2001 db_find_key(hDB, 0, pwd, &hKey);
2002
2003 db_load(hDB, hKey, param[1], FALSE);
2004 }
2005
2006 /* save */
2007 else if (param[0][0] == 's' && param[0][1] == 'a') {
2008 db_find_key(hDB, 0, pwd, &hKey);
2009
2010 if (strstr(param[1], ".xml") || strstr(param[1], ".XML"))
2011 db_save_xml(hDB, hKey, param[1]);
2012 else if (strstr(param[1], ".json") || strstr(param[1], ".js"))
2013 db_save_json(hDB, hKey, param[1]);
2014 else if (param[1][0] == '-') {
2015 if (param[1][1] == 'c' && param[1][2] == 's') {
2018 } else if (param[1][1] == 'c')
2020 else if (param[1][1] == 's')
2022 else if (param[1][1] == 'x')
2023 db_save_xml(hDB, hKey, param[2]);
2024 else if (param[1][1] == 'j')
2025 db_save_json(hDB, hKey, param[2]);
2026 else if (param[1][1] == 'z')
2029 } else
2030 db_save(hDB, hKey, param[1], FALSE);
2031 }
2032
2033 /* json */
2034 else if (strncmp(param[0], "json", 8) == 0) {
2035
2036 if (param[1][0] == '/') {
2037 db_find_key(hDB, 0, param[1], &hKey);
2038 } else if (strlen(param[1]) > 0) {
2039 db_find_key(hDB, 0, pwd, &hKey);
2040 db_find_key(hDB, hKey, param[1], &hKey);
2041 } else {
2042 db_find_key(hDB, 0, pwd, &hKey);
2043 }
2044
2045 char *buffer = NULL;
2046 int buffer_size = 0;
2047 int buffer_end = 0;
2048
2049 status = db_copy_json_save(hDB, hKey, &buffer, &buffer_size, &buffer_end);
2050
2051 printf("status: %d, json: %s\n", status, buffer);
2052
2053 if (buffer)
2054 free(buffer);
2055 }
2056
2057 /* jsvalues */
2058 else if (strncmp(param[0], "jsvalues", 8) == 0) {
2059 db_find_key(hDB, 0, pwd, &hKey);
2060
2061 char *buffer = NULL;
2062 int buffer_size = 0;
2063 int buffer_end = 0;
2064
2065 int omit_names = 0;
2066 int omit_last_written = 0;
2068 int preserve_case = 0;
2069
2071
2072 printf("status: %d, json: %s\n", status, buffer);
2073
2074 if (buffer)
2075 free(buffer);
2076 }
2077
2078 /* jsls */
2079 else if (strncmp(param[0], "jsls", 4) == 0) {
2080
2081 if (param[1][0] == '/') {
2082 db_find_key(hDB, 0, param[1], &hKey);
2083 } else if (strlen(param[1]) > 0) {
2084 db_find_key(hDB, 0, pwd, &hKey);
2085 db_find_key(hDB, hKey, param[1], &hKey);
2086 } else {
2087 db_find_key(hDB, 0, pwd, &hKey);
2088 }
2089
2090 char *buffer = NULL;
2091 int buffer_size = 0;
2092 int buffer_end = 0;
2093
2094 status = db_copy_json_ls(hDB, hKey, &buffer, &buffer_size, &buffer_end);
2095
2096 printf("jsls \"%s\", status: %d, json: %s\n", pwd, status, buffer);
2097
2098 if (buffer)
2099 free(buffer);
2100 }
2101
2102 /* make */
2103 else if (param[0][0] == 'm' && param[0][1] == 'a') {
2104 if (param[1][0])
2106 else
2107 create_experim_h(hDB, "Analyzer");
2108 }
2109
2110 /* passwd */
2111 else if (param[0][0] == 'p' && param[0][1] == 'a' && param[0][2] == 's') {
2112 /*
2113 strcpy(str, ss_crypt("foob", "ar"));
2114 if(strcmp(str, "arlEKn0OzVJn.") != 0)
2115 printf("Warning: ss_crypt() works incorrect");
2116 */
2117
2118 if (db_find_key(hDB, 0, "/Experiment/Security/Password", &hKey) == DB_SUCCESS) {
2119 size = sizeof(old_password);
2121
2122 strcpy(str, ss_getpass("Old password: "));
2123 strcpy(str, ss_crypt(str, "mi"));
2124
2125 if (strcmp(str, old_password) == 0 || strcmp(str, "mid7qBxsNMHux") == 0) {
2126 strcpy(str, ss_getpass("New password: "));
2127 strcpy(new_password, ss_crypt(str, "mi"));
2128
2129 strcpy(str, ss_getpass("Retype new password: "));
2130 if (strcmp(new_password, ss_crypt(str, "mi")) != 0)
2131 printf("Mismatch - password unchanged\n");
2132 else
2134 } else
2135 printf("Wrong password\n");
2136 } else {
2137 strcpy(str, ss_getpass("Password: "));
2138 strcpy(new_password, ss_crypt(str, "mi"));
2139
2140 strcpy(str, ss_getpass("Retype password: "));
2141 if (strcmp(new_password, ss_crypt(str, "mi")) != 0)
2142 printf("Mismatch - password not set\n");
2143 else {
2144 /* set password */
2145 db_set_value(hDB, 0, "/Experiment/Security/Password", new_password, 32, 1,
2146 TID_STRING);
2147
2148 /* create empty allowed hosts and allowd programs entries */
2149 db_create_key(hDB, 0,
2150 "/Experiment/Security/Allowed hosts/host.sample.domain",
2151 TID_INT);
2152 db_create_key(hDB, 0, "/Experiment/Security/Allowed programs/mstat",
2153 TID_INT);
2154 }
2155 }
2156
2157 }
2158
2159 /* webpasswd */
2160 else if (param[0][0] == 'w' && param[0][1] == 'e' && param[0][2] == 'b') {
2161 if (db_find_key(hDB, 0, "/Experiment/Security/Web Password", &hKey) == DB_SUCCESS) {
2162 size = sizeof(old_password);
2164
2165 strcpy(str, ss_getpass("Old password: "));
2166 strcpy(str, ss_crypt(str, "mi"));
2167
2168 if (strcmp(str, old_password) == 0 || strcmp(str, "mid7qBxsNMHux") == 0) {
2169 strcpy(str, ss_getpass("New password: "));
2170 strcpy(new_password, ss_crypt(str, "mi"));
2171
2172 strcpy(str, ss_getpass("Retype new password: "));
2173 if (strcmp(new_password, ss_crypt(str, "mi")) != 0)
2174 printf("Mismatch - password unchanged\n");
2175 else
2177 } else
2178 printf("Wrong password\n");
2179 } else {
2180 strcpy(str, ss_getpass("Password: "));
2181 strcpy(new_password, ss_crypt(str, "mi"));
2182
2183 strcpy(str, ss_getpass("Retype password: "));
2184 if (strcmp(new_password, ss_crypt(str, "mi")) != 0)
2185 printf("Mismatch - password not set\n");
2186 else
2187 /* set password */
2188 db_set_value(hDB, 0, "/Experiment/Security/Web Password", new_password, 32,
2189 1, TID_STRING);
2190 }
2191 }
2192
2193 /* hi */
2194 else if (param[0][0] == 'h' && param[0][1] == 'i') {
2195 HNDLE hConn;
2196
2197 client_name[0] = 0;
2198
2199 if (!isalpha(param[1][0])) {
2200 /* find client which exports RPC_ANA_CLEAR_HISTOS */
2201 status = db_find_key(hDB, 0, "System/Clients", &hRootKey);
2202 if (status == DB_SUCCESS) {
2203 for (i = 0;; i++) {
2205 if (status == DB_NO_MORE_SUBKEYS) {
2206 printf("No client currently exports the CLEAR HISTO functionality.\n");
2207 break;
2208 }
2209
2210 sprintf(str, "RPC/%d", RPC_ANA_CLEAR_HISTOS);
2212 if (status == DB_SUCCESS) {
2213 size = sizeof(client_name);
2214 db_get_value(hDB, hSubkey, "Name", client_name, &size, TID_STRING,
2215 TRUE);
2216 break;
2217 }
2218 }
2219 }
2220
2221 if (isdigit(param[1][0]))
2222 n1 = atoi(param[1]);
2223 else
2224 n1 = 0; /* all histos by default */
2225
2226 if (isdigit(param[2][0]))
2227 n2 = atoi(param[2]);
2228 else
2229 n2 = n1; /* single histo by default */
2230 } else {
2231 strcpy(client_name, param[1]);
2232
2233 if (isdigit(param[2][0]))
2234 n1 = atoi(param[2]);
2235 else
2236 n1 = 0; /* all histos by default */
2237
2238 if (isdigit(param[3][0]))
2239 n2 = atoi(param[3]);
2240 else
2241 n2 = n1; /* single histo by default */
2242 }
2243
2244 if (client_name[0]) {
2245 if (cm_connect_client(client_name, &hConn) == CM_SUCCESS) {
2247 //cm_disconnect_client(hConn, FALSE);
2248 } else
2249 printf("Cannot connect to client %s\n", client_name);
2250 }
2251 }
2252
2253 /* import */
2254 else if (param[0][0] == 'i' && param[0][1] == 'm') {
2255 int fh = open(param[1], O_RDONLY | O_TEXT);
2256 if (fh < 0) {
2257 printf("Could not open file \"%s\", errno %d (%s)\n", param[1], errno, strerror(errno));
2258 } else {
2259 off_t off = lseek(fh, 0, SEEK_END);
2260 if (off < 0) {
2261 printf("Could not get size of file \"%s\", lseek(SEEK_END) errno %d (%s)\n", param[1], errno, strerror(errno));
2262 close(fh);
2263 } else {
2264 lseek(fh, 0, SEEK_SET);
2265 size_t size = off;
2266 char *buf = (char *) malloc(size + 1);
2267 ssize_t rd = read(fh, buf, size);
2268 if (rd < 0) {
2269 printf("Could not read file \"%s\", read(%zu) errno %d (%s)\n", param[1], size, errno, strerror(errno));
2270 close(fh);
2271 free(buf);
2272 } else {
2273 close(fh);
2274 size = rd;
2275 if (size == 0) {
2276 buf[size] = 0;
2277 size++;
2278 } else if (buf[size - 1] != 0) {
2279 buf[size] = 0;
2280 size++;
2281 }
2282
2283 if (param[2][0] == 0) {
2284 printf("Key name: ");
2285 ss_gets(name, 256);
2286 } else {
2287 strcpy(name, param[2]);
2288 }
2289
2291
2293 db_find_key(hDB, 0, str, &hKey);
2294 db_set_data(hDB, hKey, buf, size, 1, TID_STRING);
2295 free(buf);
2296 }
2297 }
2298 }
2299
2300 }
2301
2302 /* export */
2303 else if (param[0][0] == 'e' && param[0][1] == 'x' && param[0][2] == 'p') {
2304 FILE *f;
2305
2306 if (param[1][0] == 0)
2307 printf("please specify key\n");
2308 else {
2309 compose_name(pwd, param[1], str);
2310
2311 db_find_key(hDB, 0, str, &hKey);
2312 if (hKey == 0)
2313 printf("Error: Key \"%s\" not found\n", param[1]);
2314 else {
2315 if (param[2][0] == 0) {
2316 printf("File name: ");
2317 ss_gets(name, 256);
2318 } else
2319 strcpy(name, param[2]);
2320
2321 f = fopen(name, "w");
2322 if (f == NULL)
2323 printf("Cannot open file \"%s\"\n", name);
2324 else {
2325 db_get_key(hDB, hKey, &key);
2326 if (key.type != TID_STRING)
2327 printf("Only export of STRING key possible\n");
2328 else {
2329 char *buf = (char *) malloc(key.total_size);
2330 size = key.total_size;
2331 memset(buf, 0, size);
2332 db_get_data(hDB, hKey, buf, &size, key.type);
2333 fprintf(f, "%s", buf);
2334 fclose(f);
2335 free(buf);
2336 }
2337 }
2338 }
2339 }
2340 }
2341
2342 /* alarm reset */
2343 else if (param[0][0] == 'a' && param[0][1] == 'l') {
2344 /* go through all alarms */
2345 db_find_key(hDB, 0, "/Alarms/Alarms", &hKey);
2346 if (hKey) {
2347 for (i = 0;; i++) {
2349
2350 if (!hSubkey)
2351 break;
2352
2355 if (status == AL_RESET)
2356 printf("Alarm of class \"%s\" reset sucessfully\n", key.name);
2357 }
2358 }
2359 }
2360
2361 /* mem */
2362 else if (param[0][0] == 'm' && param[0][1] == 'e') {
2363 if (rpc_is_remote())
2364 printf("This function works only locally\n");
2365 else {
2366#ifdef LOCAL_ROUTINES
2367 char *buf = NULL;
2368 db_show_mem(hDB, &buf, param[1][0]);
2369 if (buf) {
2370 puts(buf);
2371 free(buf);
2372 }
2373#else
2374 printf("This MIDAS only works remotely\n");
2375#endif// LOCAL_ROUTINES
2376 }
2377 }
2378
2379 /* sor (show open records) */
2380 else if (param[0][0] == 's' && param[0][1] == 'o') {
2381 db_find_key(hDB, 0, pwd, &hKey);
2382 char data[50000];
2384 printf("%s", data);
2385 }
2386
2387 /* scl (show clients ) */
2388 else if (param[0][0] == 's' && param[0][1] == 'c') {
2389 status = db_find_key(hDB, 0, "System/Clients", &hKey);
2390 if (status != DB_SUCCESS)
2391 cm_msg(MERROR, "command_loop",
2392 "cannot find System/Clients entry in database");
2393 else {
2394 if (param[1][1] == 'w')
2395 printf("Name Host Timeout Last called\n");
2396 else
2397 printf("Name Host\n");
2398
2399 /* search database for clients with transition mask set */
2400 for (i = 0, status = 0;; i++) {
2403 break;
2404
2405 if (status == DB_SUCCESS) {
2406 size = sizeof(name);
2407 db_get_value(hDB, hSubkey, "Name", name, &size, TID_STRING, TRUE);
2408 printf("%s", name);
2409 for (int j = 0; j < 20 - (int) strlen(name); j++)
2410 printf(" ");
2411
2412 size = sizeof(str);
2413 db_get_value(hDB, hSubkey, "Host", str, &size, TID_STRING, TRUE);
2414 printf("%s", str);
2415 for (int j = 0; j < 20 - (int) strlen(str); j++)
2416 printf(" ");
2417
2418 /* display optional watchdog info */
2419 if (param[1][1] == 'w') {
2420 DWORD timeout, last;
2421
2422 status = cm_get_watchdog_info(hDB, name, &timeout, &last);
2423 printf("%-10d %-10d", timeout, last);
2424 }
2425
2426 printf("\n");
2427 }
2428 }
2429 }
2430 }
2431
2432 /* start */
2433 else if (param[0][0] == 's' && param[0][1] == 't' && param[0][2] == 'a') {
2434 debug_flag = ((param[1][0] == '-' && param[1][1] == 'v') || (param[2][0] == '-' && param[2][1] == 'v') || (param[3][0] == '-' && param[3][1] == 'v'));
2435 mthread_flag = ((param[1][0] == '-' && param[1][1] == 'm') || (param[2][0] == '-' && param[2][1] == 'm') || (param[3][0] == '-' && param[3][1] == 'm'));
2436
2437 /* check if run is already started */
2438 size = sizeof(i);
2439 i = STATE_STOPPED;
2440 db_get_value(hDB, 0, "/Runinfo/State", &i, &size, TID_INT, TRUE);
2441 if (i == STATE_RUNNING) {
2442 printf("Run is already started\n");
2443 } else if (i == STATE_PAUSED) {
2444 printf("Run is paused, please use \"resume\"\n");
2445 } else {
2446 /* get present run number */
2447 old_run_number = 0;
2448 status = db_get_value(hDB, 0, "/Runinfo/Run number", &old_run_number, &size, TID_INT, TRUE);
2449 assert(status == SUCCESS);
2450 assert(old_run_number >= 0);
2451
2452 /* edit run parameter if command is not "start now" */
2453 if ((param[1][0] == 'n' && param[1][1] == 'o' && param[1][2] == 'w') || cmd_mode) {
2455 line[0] = 'y';
2456 } else {
2457 db_find_key(hDB, 0, "/Experiment/Edit on start", &hKey);
2458 do {
2459 if (hKey) {
2460 for (i = 0;; i++) {
2462
2463 if (!hSubkey)
2464 break;
2465
2467 std::string str = key.name;
2468
2469 if (equal_ustring(str.c_str(), "Edit run number"))
2470 continue;
2471
2472 if (str.find("Options ") == 0)
2473 continue;
2474
2477
2478 assert(key.total_size > 0);
2479 char *buf = (char *) malloc(key.total_size);
2480
2481 size = key.total_size;
2482 status = db_get_data(hDB, hSubkey, buf, &size, key.type);
2483 if (status != DB_SUCCESS) {
2484 free(buf);
2485 continue;
2486 }
2487
2488 for (int j = 0; j < key.num_values; j++) {
2489 std::string xdata_str = db_sprintf(buf, key.item_size, j, key.type);
2490 std::string xprompt;
2491 xprompt += str;
2492 if (key.num_values == 1) {
2493 xprompt += " : ";
2494 } else {
2495 xprompt += msprintf("[%d] : ", j);
2496 }
2497
2498 strcpy(line, xdata_str.c_str());// FIXME: buffer overflow. K.O. aug2024
2499 in_cmd_edit = TRUE;
2500 cmd_edit(xprompt.c_str(), line, NULL, cmd_idle);
2502
2503 if (line[0]) {
2504 db_sscanf(line, buf, &size, j, key.type);
2506 }
2507 }
2508
2509 free(buf);
2510 }
2511 }
2512
2513 /* increment run number */
2515
2516 if (db_find_key(hDB, 0, "/Experiment/Edit on start/Edit Run number", &hKey) == DB_SUCCESS && db_get_data(hDB, hKey, &i, &size, TID_BOOL) && i == 0) {
2517 printf("Run number: %d\n", new_run_number);
2518 } else {
2519
2520 printf("Run number [%d]: ", new_run_number);
2521 ss_gets(line, 256);
2522 if (line[0] && atoi(line) > 0)
2523 new_run_number = atoi(line);
2524 }
2525
2526 printf("Are the above parameters correct? ([y]/n/q): ");
2527 ss_gets(line, 256);
2528
2529 } while (line[0] == 'n' || line[0] == 'N');
2530 }
2531
2532 if (line[0] != 'q' && line[0] != 'Q') {
2533 /* start run */
2534 printf("Starting run #%d\n", new_run_number);
2535
2536 assert(new_run_number > 0);
2537
2539 sizeof(str), mthread_flag ? TR_MTHREAD | TR_SYNC : TR_SYNC, debug_flag);
2540 if (status != CM_SUCCESS) {
2541 /* in case of error, reset run number */
2542 status =
2543 db_set_value(hDB, 0, "/Runinfo/Run number", &old_run_number,
2544 sizeof(old_run_number), 1, TID_INT);
2545 assert(status == SUCCESS);
2546
2547 printf("Error: %s\n", str);
2548 }
2549 }
2550 }
2551 }
2552
2553 /* stop */
2554 else if (param[0][0] == 's' && param[0][1] == 't' && param[0][2] == 'o') {
2555 debug_flag = ((param[1][0] == '-' && param[1][1] == 'v') || (param[2][0] == '-' && param[2][1] == 'v') || (param[3][0] == '-' && param[3][1] == 'v'));
2556 mthread_flag = ((param[1][0] == '-' && param[1][1] == 'm') || (param[2][0] == '-' && param[2][1] == 'm') || (param[3][0] == '-' && param[3][1] == 'm'));
2557
2558 /* check if run is stopped */
2560 size = sizeof(i);
2561 db_get_value(hDB, 0, "/Runinfo/State", &state, &size, TID_INT, TRUE);
2562 str[0] = 0;
2563 if (state == STATE_STOPPED && !cmd_mode) {
2564 printf("Run is already stopped. Stop again? (y/[n]) ");
2565 ss_gets(str, 256);
2566 }
2567 if (str[0] == 'y' || state != STATE_STOPPED || cmd_mode) {
2568 if (param[1][0] == 'n')
2569 status =
2570 cm_transition(TR_STOP | TR_DEFERRED, 0, str, sizeof(str), mthread_flag ? TR_MTHREAD | TR_SYNC : TR_SYNC, debug_flag);
2571 else
2572 status = cm_transition(TR_STOP, 0, str, sizeof(str), mthread_flag ? TR_MTHREAD | TR_SYNC : TR_SYNC, debug_flag);
2573
2575 printf("%s\n", str);
2577 printf("Deferred stop already in progress, enter \"stop now\" to force stop\n");
2578 else if (status != CM_SUCCESS)
2579 printf("Error: %s\n", str);
2580 }
2581 }
2582
2583 /* pause */
2584 else if (param[0][0] == 'p' && param[0][1] == 'a' && param[0][2] == 'u') {
2585 debug_flag = ((param[1][0] == '-' && param[1][1] == 'v') || (param[2][0] == '-' && param[2][1] == 'v'));
2586
2587 /* check if run is started */
2588 i = STATE_STOPPED;
2589 size = sizeof(i);
2590 db_get_value(hDB, 0, "/Runinfo/State", &i, &size, TID_INT, TRUE);
2591 if (i != STATE_RUNNING) {
2592 printf("Run is not started\n");
2593 } else {
2594 if (param[1][0] == 'n')
2595 status = cm_transition(TR_PAUSE | TR_DEFERRED, 0, str, sizeof(str), TR_SYNC, debug_flag);
2596 else
2597 status = cm_transition(TR_PAUSE, 0, str, sizeof(str), TR_SYNC, debug_flag);
2598
2600 printf("%s\n", str);
2602 printf("Deferred pause already in progress, enter \"pause now\" to force pause\n");
2603 else if (status != CM_SUCCESS)
2604 printf("Error: %s\n", str);
2605 }
2606 }
2607
2608 /* resume */
2609 else if (param[0][0] == 'r' && param[0][1] == 'e' && param[0][2] == 's') {
2610 debug_flag = ((param[1][0] == '-' && param[1][1] == 'v') || (param[2][0] == '-' && param[2][1] == 'v'));
2611
2612 /* check if run is paused */
2613 i = STATE_STOPPED;
2614 size = sizeof(i);
2615 db_get_value(hDB, 0, "/Runinfo/State", &i, &size, TID_INT, TRUE);
2616 if (i != STATE_PAUSED) {
2617 printf("Run is not paused\n");
2618 } else {
2619 status = cm_transition(TR_RESUME, 0, str, sizeof(str), TR_SYNC, debug_flag);
2620 if (status != CM_SUCCESS)
2621 printf("Error: %s\n", str);
2622 }
2623 }
2624
2625 /* msg */
2626 else if (param[0][0] == 'm' && param[0][1] == 's') {
2627 // param[1]: facility, param[2]: type, param[3]: name param[4]: message
2628 if (!param[4][0]) {
2629 printf("Error: Not enough parameters. Please use\n\n");
2630 printf(" msg <facility> <type> <name> <message>\n\n");
2631 printf("where <facility> can be \"midas\", \"chat\", ...\n");
2632 printf("and <type> must be \"error\", \"info\", \"debug\", \"user\", \"log\", \"talk\" or \"call\".\n");
2633 } else {
2634 int type = 0;
2636 type = MT_ERROR;
2638 type = MT_INFO;
2640 type = MT_DEBUG;
2642 type = MT_USER;
2644 type = MT_LOG;
2646 type = MT_TALK;
2648 type = MT_CALL;
2649 if (type == 0) {
2650 printf("Error: inavlid type \"%s\".\n", param[2]);
2651 printf("<type> must be one of \"error\", \"info\", \"debug\", \"user\", \"log\", \"talk\", \"call\".\n");
2652 } else {
2653
2654 cm_msg1(type, __FILE__, __LINE__, param[1], param[3], "%s", param[4]);
2656 }
2657 }
2658 }
2659
2660 /* chat */
2661 else if (param[0][0] == 'c' && param[0][1] == 'h' && param[0][2] == 'a') {
2662 message[0] = 0;
2663
2664 if (ss_time() - last_msg_time > 300) {
2665 printf("Your name> ");
2666 ss_gets(user_name, 80);
2667 }
2668
2669 printf("Exit chat mode with empty line.\n");
2670 do {
2671 in_cmd_edit = TRUE;
2672 message[0] = 0;
2673 cmd_edit("> ", message, NULL, cmd_idle);
2675
2676 if (message[0])
2677 cm_msg1(MUSER, "chat", user_name, "%s", message);
2678
2679 } while (message[0]);
2680
2682 }
2683
2684 /* old */
2685 else if (param[0][0] == 'o' && param[0][1] == 'l') {
2686 i = 20;
2687 if (param[1][0])
2688 i = atoi(param[1]);
2689
2690 char data[50000];
2691 cm_msg_retrieve(i, data, sizeof(data));
2692 printf("%s\n\n", data);
2693 }
2694
2695 /* cleanup */
2696 else if (param[0][0] == 'c' && param[0][1] == 'l') {
2697 HNDLE hBuf;
2698 BOOL force;
2699
2700 force = FALSE;
2701 if (param[1][0] == '-' && param[1][1] == 'f')
2702 force = TRUE;
2703 if (param[2][0] == '-' && param[2][1] == 'f')
2704 force = TRUE;
2705
2707
2708 if (param[1][0] && param[1][0] != '-')
2709 cm_cleanup(param[1], force);
2710 else
2711 cm_cleanup("", force);
2713 }
2714
2715 /* shutdown */
2716 else if (param[0][0] == 's' && param[0][1] == 'h') {
2717 if (param[1][0] == 0)
2718 printf("Please enter client name or \"all\" to shutdown all clients.\n");
2719 else {
2721 if (status != CM_SUCCESS) {
2722 if (strcmp(param[1], "all") == 0)
2723 printf("No clients found\n");
2724 else
2725 printf("Client \"%s\" not active\n", param[1]);
2726 }
2727 }
2728 }
2729
2730 /* ver */
2731 else if (param[0][0] == 'v' && param[0][1] == 'e') {
2732 printf("MIDAS version: %s\n", cm_get_version());
2733 printf("GIT revision: %s\n", cm_get_revision());
2734 printf("ODB version: %d\n", DATABASE_VERSION);
2735 }
2736
2737 /* exec */
2738 else if (param[0][0] == 'e' && param[0][1] == 'x' && param[0][2] == 'e') {
2739 compose_name(pwd, param[1], str);
2740 char data[50000];
2741 status = db_find_key(hDB, 0, str, &hKey);
2742 if (status == DB_SUCCESS) {
2743 db_get_key(hDB, hKey, &key);
2744 if (key.type != TID_STRING) {
2745 printf("Key contains no command\n");
2746 continue;
2747 }
2748 size = sizeof(str);
2749 db_get_data(hDB, hKey, str, &size, key.type);
2750
2751 cm_execute(str, data, sizeof(data));
2752 } else {
2753 cm_execute(param[1], data, sizeof(data));
2754 }
2755 puts(data);
2756 }
2757
2758 /* wait */
2759 else if (param[0][0] == 'w' && param[0][1] == 'a' && param[0][2] == 'i') {
2760 if (param[1][0] == 0) {
2761 printf("Please specify key\n");
2762 } else {
2763 compose_name(pwd, param[1], str);
2764
2765 if (equal_ustring(str, "/")) {
2767 status = db_find_link(hDB, 0, "/", &hKey);
2768 } else
2769 status = db_find_link(hDB, 0, str, &hKey);
2770
2771 if (status == DB_SUCCESS) {
2772 db_get_key(hDB, hKey, &key);
2773 printf("Waiting for key \"%s\" to be modified, abort with any key\n", key.name);
2774 db_get_record_size(hDB, hKey, 0, &size);
2775 char *buf = (char *) malloc(size);
2778
2779 do {
2780 status = cm_yield(1000);
2781 if (status == SS_ABORT || status == RPC_SHUTDOWN)
2782 break;
2783 } while (!key_modified && !ss_kbhit());
2784
2785 while (ss_kbhit())
2786 ss_getchar(0);
2787
2789 if (buf) {
2790 free(buf);
2791 buf = NULL;
2792 }
2793
2794 if (status == SS_ABORT || status == RPC_SHUTDOWN)
2795 break;
2796
2797 if (i == '!')
2798 printf("Wait aborted.\n");
2799 else
2800 printf("Key has been modified.\n");
2801 } else
2802 printf("key \"%s\" not found\n", str);
2803 }
2804 }
2805
2806 /* watch */
2807 else if (param[0][0] == 'w' && param[0][1] == 'a' && param[0][2] == 't') {
2808 if (param[1][0] == 0) {
2809 printf("Please specify key\n");
2810 } else {
2811 compose_name(pwd, param[1], str);
2812
2813 status = db_find_link(hDB, 0, str, &hKey);
2814 if (status == DB_SUCCESS) {
2815 db_get_key(hDB, hKey, &key);
2816 if (key.type != TID_KEY)
2817 printf("Watch key \"%s\" to be modified, abort with any key\n", str);
2818 else
2819 printf("Watch ODB tree \"%s\" to be modified, abort with any key\n", str);
2821
2822 do {
2823 status = cm_yield(1000);
2824 if (status == SS_ABORT || status == RPC_SHUTDOWN)
2825 break;
2826 } while (!ss_kbhit());
2827
2828 while (ss_kbhit())
2829 ss_getchar(0);
2830
2832
2833 if (status == SS_ABORT || status == RPC_SHUTDOWN)
2834 break;
2835 } else
2836 printf("key \"%s\" not found\n", str);
2837 }
2838 }
2839
2840 /* test 1 */
2841 else if (param[0][0] == 't' && param[0][1] == '1') {
2842 DWORD start_time;
2843 INT i, size, rn;
2844 HNDLE hKey;
2845
2846 start_time = ss_millitime();
2847 status = db_find_key(hDB, 0, "/runinfo/run number", &hKey);
2848 assert(status == SUCCESS);
2849 size = sizeof(rn);
2850
2851 i = 0;
2852 do {
2853 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2854 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2855 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2856 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2857 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2858 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2859 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2860 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2861 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2862 db_get_data(hDB, hKey, &rn, &size, TID_INT);
2863 i += 10;
2864 } while (ss_millitime() - start_time < 5000);
2865
2866 printf("%d accesses per second\n", i / 5);
2867 }
2868
2869 /* test 2 */
2870 else if (param[0][0] == 't' && param[0][1] == '2') {
2871 do {
2872 do {
2873 i = ss_getchar(0);
2874 printf("%d\n", i);
2875 } while (i > 0 && i != 4);
2876
2877 ss_sleep(1000);
2878 } while (i != 4);
2879
2880 ss_getchar(1);
2881 }
2882
2883 /* test 3 */
2884 else if (param[0][0] == 't' && param[0][1] == '3') {
2885#ifdef USE_ADDRESS_SANITIZER
2886 // test address sanitizer
2887 int *a = (int *) malloc(sizeof(int) * 10);
2888 i = a[11];
2889 free(a);
2890#else
2891 printf("test address sanitizer is disabled!\n");
2892#endif
2893 }
2894
2895 /* exit/quit */
2896 else if ((param[0][0] == 'e' && param[0][1] == 'x' && param[0][2] == 'i') || (param[0][0] == 'q'))
2897 break;
2898
2899 else if (param[0][0] == 0)
2900 ;
2901
2902 else
2903 printf("Unknown command %s %s %s\n", param[0], param[1], param[2]);
2904
2905 /* exit after single command */
2906 if (cmd_mode && cmd[0] != '@')
2907 break;
2908
2909 /* check if client connections are broken */
2910 status = cm_yield(0);
2911 if (status == SS_ABORT || status == RPC_SHUTDOWN)
2912 break;
2913
2914 } while (TRUE);
2915
2916 /* check if client connections are broken */
2917 status = cm_yield(0);
2918
2919 return 1; /* indicate success */
2920}
INT al_reset_alarm(const char *alarm_name)
Definition alarm.cxx:525
INT bm_open_buffer(const char *buffer_name, INT buffer_size, INT *buffer_handle)
Definition midas.cxx:6717
INT bm_close_buffer(INT buffer_handle)
Definition midas.cxx:7096
INT cm_shutdown(const char *name, BOOL bUnique)
Definition midas.cxx:7400
INT cm_connect_client(const char *client_name, HNDLE *hConn)
Definition midas.cxx:2766
INT cm_transition(INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag)
Definition midas.cxx:5286
void cm_ack_ctrlc_pressed()
Definition midas.cxx:5456
INT cm_execute(const char *command, char *result, INT bufsize)
Definition midas.cxx:5723
INT cm_get_watchdog_info(HNDLE hDB, const char *client_name, DWORD *timeout, DWORD *last)
Definition midas.cxx:3336
INT cm_cleanup(const char *client_name, BOOL ignore_timeout)
Definition midas.cxx:7610
const char * cm_get_version()
Definition midas.cxx:1476
const char * cm_get_revision()
Definition midas.cxx:1484
#define CM_SUCCESS
Definition midas.h:582
#define CM_DEFERRED_TRANSITION
Definition midas.h:591
#define CM_TRANSITION_IN_PROGRESS
Definition midas.h:592
#define DB_NO_ACCESS
Definition midas.h:648
#define DB_NO_KEY
Definition midas.h:642
#define DB_INVALID_LINK
Definition midas.h:652
#define DB_OPEN_RECORD
Definition midas.h:650
#define DB_NO_MORE_SUBKEYS
Definition midas.h:646
#define DB_TRUNCATED
Definition midas.h:644
#define RPC_SUCCESS
Definition midas.h:698
#define AL_RESET
Definition midas.h:757
unsigned short int WORD
Definition mcstd.h:49
#define SUCCESS
Definition mcstd.h:54
#define TR_RESUME
Definition midas.h:408
#define TR_PAUSE
Definition midas.h:407
#define MT_LOG_STR
Definition midas.h:555
#define TID_BOOL
Definition midas.h:340
#define TR_START
Definition midas.h:405
#define TR_SYNC
Definition midas.h:358
#define MODE_EXCLUSIVE
Definition midas.h:373
#define MUSER
Definition midas.h:562
#define MT_CALL_STR
Definition midas.h:557
#define MT_INFO_STR
Definition midas.h:552
#define TR_MTHREAD
Definition midas.h:361
#define MT_INFO
Definition midas.h:543
#define MODE_DELETE
Definition midas.h:372
#define MT_DEBUG_STR
Definition midas.h:553
#define MT_TALK
Definition midas.h:547
#define MT_USER
Definition midas.h:545
#define MT_USER_STR
Definition midas.h:554
#define MT_LOG
Definition midas.h:546
#define STATE_PAUSED
Definition midas.h:306
#define MT_TALK_STR
Definition midas.h:556
#define MODE_WRITE
Definition midas.h:371
#define TR_DEFERRED
Definition midas.h:410
#define MERROR
Definition midas.h:559
#define MODE_READ
Definition midas.h:370
#define MT_DEBUG
Definition midas.h:544
#define MT_CALL
Definition midas.h:548
#define TR_STOP
Definition midas.h:406
#define TID_LAST
Definition midas.h:354
#define MT_ERROR
Definition midas.h:542
#define MT_ERROR_STR
Definition midas.h:551
#define O_TEXT
Definition msystem.h:220
BOOL ss_kbhit()
Definition system.cxx:3664
char * ss_getpass(const char *prompt)
Definition system.cxx:7440
DWORD ss_time()
Definition system.cxx:3462
INT ss_sleep(INT millisec)
Definition system.cxx:3628
char * ss_crypt(const char *buf, const char *salt)
Definition system.cxx:7891
INT cm_msg1(INT message_type, const char *filename, INT line, const char *facility, const char *routine, const char *format,...)
Definition midas.cxx:973
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT cm_msg_retrieve(INT n_message, char *message, INT buf_size)
Definition midas.cxx:1334
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
Definition odb.cxx:3856
INT db_reorder_key(HNDLE hDB, HNDLE hKey, INT idx)
Definition odb.cxx:6361
INT db_save_json(HNDLE hDB, HNDLE hKey, const char *filename, int flags)
Definition odb.cxx:10527
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
Definition odb.cxx:13291
INT db_get_open_records(HNDLE hDB, HNDLE hKey, char *str, INT buf_size, BOOL fix)
Definition odb.cxx:5188
INT db_show_mem(HNDLE hDB, char **result, BOOL verbose)
Definition odb.cxx:670
INT db_save_xml(HNDLE hDB, HNDLE hKey, const char *filename)
Definition odb.cxx:9480
INT db_set_link_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7425
INT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size)
Definition odb.cxx:4990
INT db_copy(HNDLE hDB, HNDLE hKey, char *buffer, INT *buffer_size, const char *path)
Definition odb.cxx:8217
INT db_set_link_data_index(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type)
Definition odb.cxx:7754
INT db_get_record_size(HNDLE hDB, HNDLE hKey, INT align, INT *buf_size)
Definition odb.cxx:11615
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:6539
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
Definition odb.cxx:3308
INT db_copy_json_save(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end)
Definition odb.cxx:10475
INT db_save_struct(HNDLE hDB, HNDLE hKey, const char *file_name, const char *struct_name, BOOL append)
Definition odb.cxx:10626
INT db_unwatch(HNDLE hDB, HNDLE hKey)
Definition odb.cxx:13887
INT db_set_mode(HNDLE hDB, HNDLE hKey, WORD mode, BOOL recurse)
Definition odb.cxx:8027
INT db_save(HNDLE hDB, HNDLE hKey, const char *filename, BOOL bRemote)
Definition odb.cxx:9245
INT db_scan_tree(HNDLE hDB, HNDLE hKey, INT level, INT(*callback)(HNDLE, HNDLE, KEY *, INT, void *), void *info)
Definition odb.cxx:4767
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
INT db_load(HNDLE hDB, HNDLE hKeyRoot, const char *filename, BOOL bRemote)
Definition odb.cxx:8126
INT db_set_data_index(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type)
Definition odb.cxx:7648
INT db_find_keys(HNDLE hDB, HNDLE hKeyRoot, char *odbpath, std::vector< HNDLE > &hKeyVector)
Definition odb.cxx:4586
INT db_save_string(HNDLE hDB, HNDLE hKey, const char *file_name, const char *string_name, BOOL append)
Definition odb.cxx:10687
INT db_paste(HNDLE hDB, HNDLE hKeyRoot, const char *buffer)
Definition odb.cxx:8487
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
Definition odb.cxx:13813
INT db_set_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7215
INT db_copy_json_ls(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end)
Definition odb.cxx:10421
void strarrayindex(char *odbpath, int *index1, int *index2)
Definition odb.cxx:3273
INT db_copy_json_values(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end, int omit_names, int omit_last_written, time_t omit_old_timestamp, int preserve_case)
Definition odb.cxx:10443
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
Definition odb.cxx:5261
INT db_rename_key(HNDLE hDB, HNDLE hKey, const char *name)
Definition odb.cxx:6261
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
Definition odb.cxx:5586
INT db_close_record(HNDLE hDB, HNDLE hKey)
Definition odb.cxx:13473
INT db_sscanf(const char *data_str, void *data, INT *data_size, INT i, DWORD tid)
Definition odb.cxx:11314
INT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values)
Definition odb.cxx:7502
INT db_create_link(HNDLE hDB, HNDLE hKey, const char *link_name, const char *destination)
Definition odb.cxx:3601
INT rpc_client_call(HNDLE hConn, DWORD routine_id,...)
Definition midas.cxx:13472
bool rpc_is_remote(void)
Definition midas.cxx:12761
int rpc_test_rpc()
Definition midas.cxx:15046
const char * rpc_tid_name(INT id)
Definition midas.cxx:11764
#define RPC_ANA_CLEAR_HISTOS
Definition mrpc.h:118
char param[10][256]
Definition mana.cxx:250
void * data
Definition mana.cxx:268
INT type
Definition mana.cxx:269
std::string msprintf(const char *format,...)
Definition midas.cxx:410
#define JSFLAG_RECURSE
Definition midas.h:1724
#define JSFLAG_FOLLOW_LINKS
Definition midas.h:1723
#define JSFLAG_OMIT_LAST_WRITTEN
Definition midas.h:1727
#define DATABASE_VERSION
Definition midas.h:34
#define DEFAULT_BUFFER_SIZE
Definition midas.h:255
#define EVENT_BUFFER_NAME
Definition midas.h:269
#define NAME_LENGTH
Definition midas.h:272
#define message(type, str)
#define read(n, a, f)
#define name(x)
Definition midas_macro.h:24
HNDLE hBuf
Definition minife.c:23
INT rn
Definition mstat.cxx:30
INT cmd_edit(const char *prompt, char *cmd, INT(*dir)(char *, INT *), INT(*idle)())
Definition cmdedit.cxx:38
void watch_callback(HNDLE hDB, HNDLE hKey, INT index, void *info)
Definition odbedit.cxx:1396
void compose_name(char *pwd, char *name, char *full_name)
Definition odbedit.cxx:1308
#define PI_HEX
Definition odbedit.cxx:36
void set_key(HNDLE hDB, HNDLE hKey, int index1, int index2, char *value)
Definition odbedit.cxx:549
int ls_line
Definition odbedit.cxx:210
void print_help(char *command)
Definition odbedit.cxx:65
#define PI_VALUE
Definition odbedit.cxx:35
BOOL in_cmd_edit
Definition odbedit.cxx:23
INT cmd_dir(char *line, INT *cursor)
Definition odbedit.cxx:751
#define PI_RECURSIVE
Definition odbedit.cxx:34
void assemble_prompt(char *prompt, int psize, char *host_name, char *exp_name, char *pwd)
Definition odbedit.cxx:1320
INT cmd_idle()
Definition odbedit.cxx:1283
INT search_key(HNDLE hDB, HNDLE hKey, KEY *key, INT level, void *info)
Definition odbedit.cxx:1010
BOOL cmd_mode
Definition odbedit.cxx:25
#define PI_LONG
Definition odbedit.cxx:33
void create_experim_h(HNDLE hDB, const char *analyzer_name)
Definition odbedit.cxx:1081
BOOL key_modified
Definition odbedit.cxx:57
void key_update(HNDLE hDB, HNDLE hkey, void *info)
Definition odbedit.cxx:59
INT print_key(HNDLE hDB, HNDLE hKey, KEY *pkey, INT level, void *info)
Definition odbedit.cxx:249
INT num_values
Definition midas.h:1028
INT item_size
Definition midas.h:1032
Here is the caller graph for this function:

◆ compose_name()

void compose_name ( char pwd,
char name,
char full_name 
)

Definition at line 1308 of file odbedit.cxx.

1308 {
1309 if (name[0] != '/') {
1310 strcpy(full_name, pwd);
1311 if (full_name[strlen(full_name) - 1] != '/')
1312 strcat(full_name, "/");
1314 } else
1315 strcpy(full_name, name);
1316}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_experim_h()

void create_experim_h ( HNDLE  hDB,
const char analyzer_name 
)

Definition at line 1081 of file odbedit.cxx.

1081 {
1082 INT i, index, subindex, hfile, status, size;
1084 char str[100 + 80], eq_name[80], subeq_name[80];
1085 KEY key;
1086 time_t now;
1087
1088 char experim_h_comment1[] =
1089 "/********************************************************************\\\n\
1090\n\
1091 Name: experim.h\n\
1092 Created by: ODBedit program\n\
1093\n\
1094 Contents: This file contains C structures for the \"Experiment\"\n\
1095 tree in the ODB and the \"/Analyzer/Parameters\" tree.\n\
1096\n\
1097 Additionally, it contains the \"Settings\" subtree for\n\
1098 all items listed under \"/Equipment\" as well as their\n\
1099 event definition.\n\
1100\n\
1101 It can be used by the frontend and analyzer to work\n\
1102 with these information.\n\
1103\n\
1104 All C structures are accompanied with a string represen-\n\
1105 tation which can be used in the db_create_record function\n\
1106 to setup an ODB structure which matches the C structure.\n\
1107\n";
1108 char experim_h_comment2[] =
1109 "\\********************************************************************/\n\n";
1110
1111 const char *file_name = "experim.h";
1112
1113 /* create file */
1114 hfile = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1115 if (hfile == -1)
1116 cm_msg(MERROR, "create_experim_h", "cannot open experim.h file.");
1117
1118 /* write comment to file */
1120 time(&now);
1121 char ctimebuf[32];
1122 ctime_r(&now, ctimebuf);
1123 sprintf(str, " Created on: %s\n", ctimebuf);
1126
1127 /* write /experiment/run parameters */
1128 db_find_key(hDB, 0, "/Experiment/Run Parameters", &hKey);
1129 if (hKey) {
1130 sprintf(str, "#define EXP_PARAM_DEFINED\n\n");
1132 db_save_struct(hDB, hKey, file_name, "EXP_PARAM", TRUE);
1133 db_save_string(hDB, hKey, file_name, "EXP_PARAM_STR", TRUE);
1134 lseek(hfile, 0, SEEK_END);
1135 }
1136
1137 /* write /experiment/edit on start */
1138 db_find_key(hDB, 0, "/Experiment/Edit on start", &hKey);
1139 if (hKey) {
1140 sprintf(str, "#define EXP_EDIT_DEFINED\n\n");
1142 db_save_struct(hDB, hKey, file_name, "EXP_EDIT", TRUE);
1143 db_save_string(hDB, hKey, file_name, "EXP_EDIT_STR", TRUE);
1144 lseek(hfile, 0, SEEK_END);
1145 }
1146
1147 /* write /<Analyzer>/parameters tree */
1148 sprintf(str, "/%s/Parameters", analyzer_name);
1150 if (status != DB_SUCCESS) {
1151 printf("Analyzer \"%s\" not found in ODB, skipping analyzer parameters.\n",
1153 } else {
1154 for (index = 0;; index++) {
1157 break;
1158
1160 mstrlcpy(eq_name, key.name, sizeof(eq_name));
1161 name2c(eq_name);
1162 for (i = 0; i < (int) strlen(eq_name); i++)
1163 eq_name[i] = toupper(eq_name[i]);
1164
1165 lseek(hfile, 0, SEEK_END);
1166 sprintf(str, "#ifndef EXCL_%s\n\n", eq_name);
1168
1169 sprintf(str, "#define %s_PARAM_DEFINED\n\n", eq_name);
1171 sprintf(str, "%s_PARAM", eq_name);
1173 sprintf(str, "%s_PARAM_STR", eq_name);
1175
1176 lseek(hfile, 0, SEEK_END);
1177 sprintf(str, "#endif\n\n");
1179 }
1180 }
1181
1182 /* loop through equipment list */
1183 status = db_find_key(hDB, 0, "/Equipment", &hKeyRoot);
1184 if (status == DB_SUCCESS)
1185 for (index = 0;; index++) {
1188 break;
1189
1191 strcpy(eq_name, key.name);
1192 name2c(eq_name);
1193 for (i = 0; i < (int) strlen(eq_name); i++)
1194 eq_name[i] = toupper(eq_name[i]);
1195
1196 lseek(hfile, 0, SEEK_END);
1197 sprintf(str, "#ifndef EXCL_%s\n\n", eq_name);
1199
1200 size = sizeof(str);
1201 str[0] = 0;
1202 db_get_value(hDB, hKeyEq, "Common/Format", str, &size, TID_STRING, TRUE);
1203
1204 /* if event is in fixed format, extract header file */
1205 if (equal_ustring(str, "Fixed")) {
1206 db_find_key(hDB, hKeyEq, "Variables", &hDefKey);
1207 if (hDefKey) {
1208 lseek(hfile, 0, SEEK_END);
1209 sprintf(str, "#define %s_EVENT_DEFINED\n\n", eq_name);
1211
1212 sprintf(str, "%s_EVENT", eq_name);
1213 db_save_struct(hDB, hDefKey, file_name, str, TRUE);
1214 sprintf(str, "%s_EVENT_STR", eq_name);
1215 db_save_string(hDB, hDefKey, file_name, str, TRUE);
1216 }
1217 }
1218
1219 /* if event is in MIDAS format, extract bank definition */
1220 else if (equal_ustring(str, "MIDAS")) {
1221 db_find_key(hDB, hKeyEq, "Variables", &hDefKey);
1222 if (hDefKey) {
1223 for (i = 0;; i++) {
1224 status = db_enum_key(hDB, hDefKey, i, &hKeyBank);
1226 break;
1227
1229
1230 if (key.type == TID_KEY) {
1231 lseek(hfile, 0, SEEK_END);
1232 sprintf(str, "#define %s_BANK_DEFINED\n\n", key.name);
1234
1235 sprintf(str, "%s_BANK", key.name);
1237 sprintf(str, "%s_BANK_STR", key.name);
1239 }
1240 }
1241 }
1242 }
1243
1244 /* Scan sub tree for that equipment */
1245 for (subindex = 0;; subindex++) {
1246 status = db_enum_key(hDB, hKeyEq, subindex, &hDefKey);
1248 break;
1249
1250 db_get_key(hDB, hDefKey, &key);
1251 strcpy(subeq_name, key.name);
1253
1254 for (i = 0; i < (int) strlen(subeq_name); i++)
1256
1257 /* Skip only the statistics */
1258 if (!equal_ustring(subeq_name, "statistics") && !equal_ustring(subeq_name, "variables")) {
1259 lseek(hfile, 0, SEEK_END);
1260 sprintf(str, "#define %s_%s_DEFINED\n\n", eq_name, subeq_name);
1262
1263 sprintf(str, "%s_%s", eq_name, subeq_name);
1264 db_save_struct(hDB, hDefKey, file_name, str, TRUE);
1265 sprintf(str, "%s_%s_STR", eq_name, subeq_name);
1266 db_save_string(hDB, hDefKey, file_name, str, TRUE);
1267 }
1268 }
1269
1270 lseek(hfile, 0, SEEK_END);
1271 sprintf(str, "#endif\n\n");
1273 }
1274
1275 close(hfile);
1276
1277 std::string cwd = ss_getcwd();
1278 printf("\"experim.h\" has been written to %s/%s\n", cwd.c_str(), file_name);
1279}
std::string ss_getcwd()
Definition system.cxx:5770
void name2c(char *str)
Definition odb.cxx:9097
INT index
Definition mana.cxx:271
const char * analyzer_name
Definition analyzer.c:25
static void xwrite(const char *filename, int fd, const void *data, int size)
Definition odbedit.cxx:1074
char file_name[256]
Definition odbhist.cxx:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctrlc_odbedit()

void ctrlc_odbedit ( INT  i)

Definition at line 2924 of file odbedit.cxx.

2924 {
2925 /* reset terminal */
2926 ss_getchar(1);
2927
2928 /* no shutdown message */
2930
2932
2933 printf("\n");
2934 exit(EXIT_SUCCESS);
2935}
INT cm_set_msg_print(INT system_mask, INT user_mask, int(*func)(const char *))
Definition midas.cxx:647
Here is the call graph for this function:
Here is the caller graph for this function:

◆ del_tree()

void del_tree ( HNDLE  hDB,
HNDLE  hKey,
INT  level 
)

Definition at line 1052 of file odbedit.cxx.

1052 {
1053 INT i;
1054 KEY key;
1055 HNDLE hSubkey;
1056
1057 for (i = 0;; i++) {
1059
1060 if (!hSubkey)
1061 break;
1062
1064 if (key.type == TID_KEY)
1065 del_tree(hDB, hSubkey, level + 1);
1066
1067 if (rand() < RAND_MAX / 10)
1069 }
1070}
void del_tree(HNDLE hDB, HNDLE hKey, INT level)
Definition odbedit.cxx:1052
Here is the call graph for this function:
Here is the caller graph for this function:

◆ key_update()

void key_update ( HNDLE  hDB,
HNDLE  hkey,
void info 
)

Definition at line 59 of file odbedit.cxx.

59 {
61}
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char argv[] 
)

Definition at line 2942 of file odbedit.cxx.

2944{
2945 INT status, i, odb_size, size;
2947 char cmd[2000], dir[256];
2948 BOOL debug;
2949 BOOL quiet;
2952 HNDLE hDB;
2953
2954 cmd[0] = dir[0] = 0;
2957
2958#ifdef OS_VXWORKS
2959 strcpy(host_name, ahost_name);
2960 strcpy(exp_name, aexp_name);
2961#else
2962
2963 /* get default from environment */
2965
2966 /* check for MIDASSYS */
2967 if (!getenv("MIDASSYS")) {
2968 puts("Please define environment variable 'MIDASSYS'");
2969 puts("pointing to the midas source installation directory.");
2970 }
2971
2972 /* parse command line parameters */
2973 for (i = 1; i < argc; i++) {
2974 if (argv[i][0] == '-' && argv[i][1] == 'g')
2975 debug = TRUE;
2976 else if (argv[i][0] == '-' && argv[i][1] == 'q')
2977 quiet = TRUE;
2978 else if (argv[i][0] == '-' && argv[i][1] == 'R')
2980 else if (argv[i][0] == '-' && argv[i][1] == 'C')
2981 corrupted = TRUE;
2982 else if (argv[i][0] == '-') {
2983 if (i + 1 >= argc || argv[i + 1][0] == '-')
2984 goto usage;
2985 if (argv[i][1] == 'e')
2986 strcpy(exp_name, argv[++i]);
2987 else if (argv[i][1] == 'h')
2988 strcpy(host_name, argv[++i]);
2989 else if (argv[i][1] == 'c') {
2990 if (strlen(argv[i + 1]) >= sizeof(cmd)) {
2991 printf("error: command line too long (>%d bytes)\n", (int) sizeof(cmd));
2992 return 0;
2993 }
2994 mstrlcpy(cmd, argv[++i], sizeof(cmd));
2995 cmd_mode = TRUE;
2996 } else if (argv[i][1] == 'd')
2997 mstrlcpy(dir, argv[++i], sizeof(dir));
2998 else if (argv[i][1] == 's')
2999 odb_size = atoi(argv[++i]);
3000 else {
3001 usage:
3002 printf("usage: odbedit [-h Hostname] [-e Experiment] [-d ODB Subtree]\n");
3003 printf(" [-q] [-c Command] [-c @CommandFile] [-s size]\n");
3004 printf(" [-g (debug)] [-C (connect to corrupted ODB)]\n");
3005 printf(" [-R (reload ODB from .ODB.SHM)]\n\n");
3006 printf("For a list of valid commands start odbedit interactively\n");
3007 printf("and type \"help\".\n");
3008 return 0;
3009 }
3010 } else
3011 mstrlcpy(host_name, argv[i], sizeof(host_name));
3012 }
3013#endif
3014
3015 if (reload_from_file) {
3016#ifdef LOCAL_ROUTINES
3018 if (status != CM_SUCCESS) {
3019 printf("Cannot setup experiment name and path.\n");
3020 return 1;
3021 }
3022 status = ss_shm_delete("ODB");
3023 printf("MIDAS ODB shared memory was deleted, ss_shm_delete(ODB) status %d\n", status);
3024 printf("Please run odbedit again without \'-R\' and ODB will be reloaded from .ODB.SHM\n");
3025 return 1;
3026#else
3027 printf("This odbedit only works remotely, -R is not supported\n");
3028 return 1;
3029#endif
3030 }
3031
3032 /* no startup message if called with command */
3033 if (cmd[0])
3035
3038
3039 if (host_name[0])
3040 printf("Connected to MIDAS server \"%s\" experiment \"%s\"", host_name, exp_name);
3041
3043 return 1;
3044
3046
3047 if ((status == DB_INVALID_HANDLE) && corrupted) {
3048 std::string s = cm_get_error(status);
3049 puts(s.c_str());
3050 printf("ODB is corrupted, connecting anyway...\n");
3051 } else if (status != CM_SUCCESS) {
3052 std::string s = cm_get_error(status);
3053 puts(s.c_str());
3054 return 1;
3055 }
3056
3057 /* place a request for system messages */
3059
3060 /* route local messages through print_message */
3062
3063 /* turn off watchdog if in debug mode */
3064 if (debug)
3066
3067 /* get experiment name */
3068 if (!exp_name[0]) {
3070 size = NAME_LENGTH;
3071 db_get_value(hDB, 0, "/Experiment/Name", exp_name, &size, TID_STRING, TRUE);
3072 }
3073
3074 /* register Ctrl-C handler */
3076
3077 /* for use with the mac os profiler */
3078 //cmd_mode = TRUE;
3079 //status = command_loop(host_name, exp_name, "save xxx3.json", dir);
3080
3081 /* log all commands passed via -c on command line */
3082 if (cmd_mode && !quiet)
3083 cm_msg(MINFO, "odbedit", "Execute command from command line: \"%s\"", cmd);
3084
3085 /* command loop */
3086 status = command_loop(host_name, exp_name, cmd, dir);
3087
3088 /* no shutdown message if called with command */
3089 if (cmd_mode)
3091
3093
3094 if (status != 1)
3095 return EXIT_FAILURE;
3096
3097 return EXIT_SUCCESS;
3098}
static void usage()
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
Definition midas.cxx:2297
int cm_set_experiment_local(const char *exp_name)
Definition midas.cxx:2166
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
Definition midas.cxx:2134
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
Definition midas.cxx:3283
#define CM_WRONG_PASSWORD
Definition midas.h:589
#define DB_INVALID_HANDLE
Definition midas.h:635
#define MT_ALL
Definition midas.h:549
#define MINFO
Definition midas.h:560
INT ss_shm_delete(const char *name)
Definition system.cxx:909
void * ss_ctrlc_handler(void(*func)(int))
Definition system.cxx:3899
INT cm_msg_register(EVENT_HANDLER *func)
Definition midas.cxx:1051
INT cm_msg_flush_buffer()
Definition midas.cxx:865
std::string cm_get_error(INT code)
Definition midas.cxx:455
BOOL quiet
Definition mana.cxx:256
INT odb_size
Definition analyzer.cxx:46
BOOL debug
debug printouts
Definition mana.cxx:254
#define HOST_NAME_LENGTH
Definition midas.h:273
#define DEFAULT_WATCHDOG_TIMEOUT
Definition midas.h:290
#define DEFAULT_ODB_SIZE
Definition midas.h:270
void ctrlc_odbedit(INT i)
Definition odbedit.cxx:2924
int print_message(const char *msg)
Definition odbedit.cxx:178
void process_message(HNDLE hBuf, HNDLE id, EVENT_HEADER *pheader, void *message)
Definition odbedit.cxx:159
int command_loop(char *host_name, char *exp_name, char *cmd, char *start_dir)
Definition odbedit.cxx:1445
Here is the call graph for this function:

◆ match()

BOOL match ( char pat,
char str 
)

Definition at line 190 of file odbedit.cxx.

192{
193 if (!*str)
194 return *pat == '*' ? match(pat + 1, str) : !*pat;
195
196 switch (*pat) {
197 case '\0':
198 return 0;
199 case '*':
200 return match(pat + 1, str) || match(pat, str + 1);
201 case '?':
202 return match(pat + 1, str + 1);
203 default:
204 return (toupper(*pat) == toupper(*str)) && match(pat + 1, str + 1);
205 }
206}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pad_to_pos()

static void pad_to_pos ( std::string *  s,
size_t  pos 
)
static

Definition at line 244 of file odbedit.cxx.

244 {
245 while (s->length() < pos)
246 (*s) += " ";
247}
Here is the caller graph for this function:

◆ print_help()

void print_help ( char command)

Definition at line 65 of file odbedit.cxx.

65 {
66#ifndef OS_MSDOS /* save some DGROUP memory under MS-DOS */
67 if (!command[0]) {
68 printf("Database commands ([] are options, <> are placeholders):\n\n");
69 printf("alarm - reset all alarms\n");
70 printf("cd <dir> - change current directory\n");
71 printf("chat - enter chat mode\n");
72 printf("chmod <mode> <key> - change access mode of a key\n");
73 printf(" 1=read | 2=write | 4=delete\n");
74 printf("cleanup [client] [-f] - delete hanging clients [force]\n");
75 printf("copy <src> <dest> - copy a subtree to a new location\n");
76 printf("create <type> <key> - create a key of a certain type\n");
77 printf("create <type> <key>[n] - create an array of size [n]\n");
78 printf("create string <key>[n][m] - create an array of [n] strings of [m] characters\n");
79 printf("del/rm [-l] [-f] <key> - delete a key and its subkeys\n");
80 printf(" -l follow links\n");
81 printf(" -f force deletion without asking\n");
82 printf("exec <key>/<cmd> - execute shell command (stored in key) on server\n");
83 printf("exp <key> <filename> - import key into ASCII file\n");
84 printf("find <pattern> - find a key with wildcard pattern\n");
85 printf("help/? [command] - print this help [for a specific command]\n");
86 printf("hi [analyzer] [id] - tell analyzer to clear histos\n");
87 printf("imp <filename> [key] - import ASCII file into string key\n");
88 printf("json <odb path> - print \"ODB save\" encoding of current directory or given odb path\n");
89 printf("jsls - print \"ls\" encoding of current directory\n");
90 printf("jsvalues - print \"get_values\" encoding of current directory\n");
91 printf("ln <source> <linkname> - create a link to <source> key\n");
92 printf("load <file> - load database from .ODB file at current position\n");
93 printf("-- hit return for more --\r");
94 getchar();
95 printf("ls/dir [-lhvrp] [<pat>] - show database entries which match pattern\n");
96 printf(" -l detailed info\n");
97 printf(" -h hex format\n");
98 printf(" -v only value\n");
99 printf(" -r show database entries recursively\n");
100 printf(" -p pause between screens\n");
101 printf("make [analyzer name] - create experim.h\n");
102 printf("mem [-v] - show memeory usage [verbose]\n");
103 printf("mkdir <subdir> - make new <subdir>\n");
104 printf("move <key> [top/bottom/[n]] - move key to position in keylist\n");
105 printf("msg [user] <msg> - send chat message (from interactive odbedit)\n");
106 printf("msg <facility> <type> <name> <msg> - send message to [facility] log\n");
107 printf("old [n] - display old n messages\n");
108 printf("passwd - change MIDAS password\n");
109 printf("pause - pause current run\n");
110 printf("pwd - show current directory\n");
111 printf("resume - resume current run\n");
112 printf("rename <old> <new> - rename key\n");
113 printf("-- hit return for more --\r");
114 getchar();
115 printf("save [-c -s -x -j -cs] <file> - save database at current position\n");
116 printf(" in ASCII format\n");
117 printf(" -c as a C structure\n");
118 printf(" -s as a #define'd string\n");
119 printf(" -x as an XML file, or use file.xml\n");
120 printf(" -j as a JSON file, or use file.json\n");
121 printf(" -z as value-only JSON file\n");
122 printf("set <key> <value> - set the value of a key\n");
123 printf("set <key>[i] <value> - set the value of index i\n");
124 printf("set <key>[*] <value> - set the value of all indices of a key\n");
125 printf("set <key>[i..j] <value> - set the value of all indices i..j\n");
126 printf("scl [-w] - show all active clients [with watchdog info]\n");
127 printf("shutdown <client>/all - shutdown individual or all clients\n");
128 printf("sor - show open records in current subtree\n");
129 printf("start [number][now][-v] - start a run [with a specific number],\n");
130 printf(" [now] w/o asking parameters, [-v] debug output\n");
131 printf("stop [-v] - stop current run, [-v] debug output\n");
132 printf("test_rpc - test mserver RPC connection and parameter encoding and decoding\n");
133 printf("trunc <key> <index> - truncate key to [index] values\n");
134 printf("ver - show MIDAS library version\n");
135 printf("webpasswd - change WWW password for mhttpd\n");
136 printf("wait <key> - wait for key to get modified\n");
137 printf("watch <key> - watch key or ODB tree to be modified\n");
138
139 printf("\nquit/exit - exit\n");
140 return;
141 }
142
143 if (equal_ustring(command, "cd")) {
144 printf("cd <dir> - change current directory. Use \"cd /\" to change to the root\n");
145 printf(" of the ODB, \"cd ..\" to change to the parent directory.\n");
146 } else if (equal_ustring(command, "chat")) {
147 printf("chat - enter chat mode. In this mode, users can \"talk\" to each other.\n");
148 printf(" Each user running ODBEdit connected to the same experiment can see\n");
149 printf(" the other messages and each user running ODBEdit in chat mode can\n");
150 printf(" produce messages. All messages are logged in the MIDAS logging file.\n");
151 } else
152 printf("No specific help available for command \"%s\".\n", command);
153
154#endif
155}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_key()

INT print_key ( HNDLE  hDB,
HNDLE  hKey,
KEY pkey,
INT  level,
void info 
)

Definition at line 249 of file odbedit.cxx.

249 {
250 INT i, status;
251 DWORD delta;
252 PRINT_INFO *pi;
253 KEY key;
254
255 if (ls_abort)
256 return 0;
257
258 pi = (PRINT_INFO *) info;
259 memcpy(&key, pkey, sizeof(KEY));
260
261 /* if pattern set, check if match */
262 if (pi->pattern[0] && !match(pi->pattern, pkey->name))
263 return SUCCESS;
264
265 if (pi->flags & PI_VALUE) {
266 /* only print value */
267 if (key.type != TID_KEY) {
268 assert(key.total_size > 0);
269 char *buf = (char *) malloc(key.total_size);
270 int size = key.total_size;
271 status = db_get_link_data(hDB, hKey, buf, &size, key.type);
272
273 std::string xdata_str;
274
275 /* resolve links */
276 if (key.type == TID_LINK) {
277 if (strlen(buf) > 0 && buf[strlen(buf) - 1] == ']')
279 else
280 status = db_find_key(hDB, 0, buf, &hKey);
281 if (status == DB_SUCCESS) {
283 if (status == DB_SUCCESS) {
284 assert(key.total_size > 0);
285 buf = (char *) realloc(buf, key.total_size);
286 size = key.total_size;
287 if (key.type != TID_KEY)
288 status = db_get_data(hDB, hKey, buf, &size, key.type);
289 else
291 }
292 }
293 }
294
295 if (status == DB_NO_KEY)
296 xdata_str = "<cannot resolve link>";
297 else if (status == DB_NO_ACCESS)
298 xdata_str = "<no read access>";
299 else
300 for (i = 0; i < key.num_values; i++) {
301 if (pi->flags & PI_HEX)
303 else
305
306 if ((pi->index != -1 && i == pi->index) || pi->index == -1)
307 printf("%s\n", xdata_str.c_str());
308 if (check_abort(pi->flags, ls_line++))
309 return 0;
310 }
311 free(buf);
312 }
313 } else {
314 /* print key name with value */
315 //memset(line, ' ', sizeof(line));
316 //line[sizeof(line)-1] = 0;
317 //sprintf(line + level * 4, "%s", key.name);
318 std::string xline;
319 pad_to_pos(&xline, level * 4);
320 xline += key.name;
321 if (key.type == TID_LINK) {
322 if (key.total_size > 0) {
323 char *buf = (char *) malloc(key.total_size);
324 int size = key.total_size;
325 db_get_link_data(hDB, hKey, buf, &size, key.type);
326 //sprintf(line + strlen(line), " -> %s", buf);
327 xline += " -> ";
328 xline += buf;
329 free(buf);
330 } else {
331 //sprintf(line + strlen(line), " -> (empty)");
332 xline += " -> (empty)";
333 }
334 if (pi->index != -1) {
335 //sprintf(line + strlen(line), "[%d]", pi->index);
336 xline += "[";
337 xline += std::to_string(pi->index);
338 xline += "]";
339 }
340 if (xline.length() >= 32) {
341 printf("%s\n", xline.c_str());
342 xline = "";
343 } else {
344 //line[strlen(line)] = ' ';
345 xline += " ";
346 }
347 } else {
348 if (pi->index != -1) {
349 //sprintf(line + strlen(line), "[%d]", pi->index);
350 }
351 //line[strlen(line)] = ' ';
352 xline += " ";
353 }
354
355 if (key.type == TID_KEY) {
356 if (pi->flags & PI_LONG) {
357 //sprintf(line + 32, "DIR");
358 pad_to_pos(&xline, 32);
359 xline += "DIR";
360 }
361 printf("%s\n", xline.c_str());
362 if (check_abort(pi->flags, ls_line++))
363 return 0;
364 } else {
365 char *data_buf = NULL;
366
367 if (key.total_size > 0) {
368 data_buf = (char *) malloc(key.total_size);
369 int size = key.total_size;
371 } else {
373 }
374
375 std::string xdata_str;
376
377 /* resolve links */
378 if (key.type == TID_LINK && data_buf) {
379 if (strlen(data_buf) > 0 && data_buf[strlen(data_buf) - 1] == ']')
381 else
383 if (status == DB_SUCCESS) {
385 if (status == DB_SUCCESS) {
386 if (key.total_size > 0) {
388 int size = key.total_size;
389 if (key.type != TID_KEY)
391 else
393 } else {
394 if (data_buf)
395 free(data_buf);
396 data_buf = NULL;
397 }
398 }
399 }
400 }
401
403 xdata_str = "<subdirectory>";
404 else if (status == DB_NO_KEY || status == DB_INVALID_LINK)
405 xdata_str = "<cannot resolve link>";
406 else if (status == DB_NO_ACCESS)
407 xdata_str = "<no read access>";
408 else if (!data_buf)
409 xdata_str = "<empty>";
410 else {
411 if (pi->flags & PI_HEX)
413 else
415 }
416
417 if (pi->flags & PI_LONG) {
418 //sprintf(line + 32, "%s", rpc_tid_name(key.type));
419 //line[strlen(line)] = ' ';
420 //sprintf(line + 40, "%d", key.num_values);
421 //line[strlen(line)] = ' ';
422 //sprintf(line + 46, "%d", key.item_size);
423 //line[strlen(line)] = ' ';
424 pad_to_pos(&xline, 32);
426 pad_to_pos(&xline, 40);
427 xline += std::to_string(key.num_values);
428 pad_to_pos(&xline, 46);
429 xline += std::to_string(key.item_size);
430
432
433 //if (delta < 60)
434 // sprintf(line + 52, "%ds", delta);
435 //else if (delta < 3600)
436 // sprintf(line + 52, "%1.0lfm", delta / 60.0);
437 //else if (delta < 86400)
438 // sprintf(line + 52, "%1.0lfh", delta / 3600.0);
439 //else if (delta < 86400 * 99)
440 // sprintf(line + 52, "%1.0lfh", delta / 86400.0);
441 //else
442 // sprintf(line + 52, ">99d");
443 //line[strlen(line)] = ' ';
444
445 pad_to_pos(&xline, 52);
446 if (delta < 60)
447 xline += msprintf("%ds", delta);
448 else if (delta < 3600)
449 xline += msprintf("%1.0lfm", delta / 60.0);
450 else if (delta < 86400)
451 xline += msprintf("%1.0lfh", delta / 3600.0);
452 else if (delta < 86400 * 99)
453 xline += msprintf("%1.0lfh", delta / 86400.0);
454 else
455 xline += ">99d";
456
457 //sprintf(line + 57, "%d", key.notify_count);
458 //line[strlen(line)] = ' ';
459 pad_to_pos(&xline, 57);
460 xline += std::to_string(key.notify_count);
461
462 pad_to_pos(&xline, 60);
464 xline += 'R';
465 else
466 xline += ' ';
467
469 xline += 'W';
470 else
471 xline += ' ';
472
474 xline += 'D';
475 else
476 xline += ' ';
477
479 xline += 'E';
480 else
481 xline += ' ';
482
483 pad_to_pos(&xline, 66);
484 if (key.type == TID_STRING && strchr(xdata_str.c_str(), '\n'))
485 xline += "<multi-line>";
486 else if (key.num_values == 1)
487 xline += xdata_str;
488 } else if (key.num_values == 1) {
489 pad_to_pos(&xline, 32);
490 if (key.type == TID_STRING && strchr(xdata_str.c_str(), '\n'))
491 xline += "<multi-line>";
492 else
493 xline += xdata_str;
494 }
495
496 if (!xline.empty())
497 printf("%s\n", xline.c_str());
498
499 if (key.type == TID_STRING && strchr(xdata_str.c_str(), '\n'))
500 puts(xdata_str.c_str());
501
502 if (check_abort(pi->flags, ls_line++))
503 return 0;
504
505 if (key.num_values > 1) {
506 for (i = 0; i < key.num_values; i++) {
507 if (data_buf) {
508 if (pi->flags & PI_HEX)
510 else
512 } else {
513 xdata_str = "<empty>";
514 }
515
516 std::string yline;
517
518 if (pi->flags & PI_LONG) {
519 //sprintf(line + 40, "[%d]", i);
520 pad_to_pos(&yline, 40);
521 yline += "[";
522 yline += std::to_string(i);
523 yline += "]";
524
525 pad_to_pos(&yline, 56);
526 yline += xdata_str;
527 } else {
528 pad_to_pos(&yline, 32);
529 yline += xdata_str;
530 }
531
532 if ((pi->index != -1 && i == pi->index) || pi->index == -1)
533 printf("%s\n", yline.c_str());
534
535 if (check_abort(pi->flags, ls_line++))
536 return 0;
537 }
538 }
539 if (data_buf)
540 free(data_buf);
541 }
542 }
543
544 return SUCCESS;
545}
#define DB_TYPE_MISMATCH
Definition midas.h:645
INT db_sprintfh(char *string, const void *data, INT data_size, INT idx, DWORD type)
Definition odb.cxx:10983
INT db_get_key_time(HNDLE hDB, HNDLE hKey, DWORD *delta)
Definition odb.cxx:6132
void ** info
Definition fesimdaq.cxx:41
BOOL check_abort(int flags, int l)
Definition odbedit.cxx:212
static void pad_to_pos(std::string *s, size_t pos)
Definition odbedit.cxx:244
WORD notify_count
Definition midas.h:1034
WORD access_mode
Definition midas.h:1033
static double pi(void)
Definition tinyexpr.c:135
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_message()

int print_message ( const char msg)

Definition at line 178 of file odbedit.cxx.

178 {
179 if (in_cmd_edit)
180 printf("\r%s\n", msg);
181 else
182 printf("%s\n", msg);
183
185 return 0;
186}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_message()

void process_message ( HNDLE  hBuf,
HNDLE  id,
EVENT_HEADER pheader,
void message 
)

Definition at line 159 of file odbedit.cxx.

159 {
160 time_t tm;
161 char str[80];
162
163 /* prepare time */
164 time(&tm);
165 assert(sizeof(str) >= 32);
166 ctime_r(&tm, str);
167 str[19] = 0;
168
169 /* print message text which comes after event header */
170 if (in_cmd_edit)
171 printf("\r%s %s\n", str + 11, (char *) message);
172 else
173 printf("\n%s %s\n", str + 11, (char *) message);
174
176}
MUTEX_T * tm
Definition odbedit.cxx:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_key()

INT search_key ( HNDLE  hDB,
HNDLE  hKey,
KEY key,
INT  level,
void info 
)

Definition at line 1010 of file odbedit.cxx.

1010 {
1011 char *pattern = (char *) info;
1012
1013 if (match(pattern, key->name)) {
1014 std::string path = db_get_path(hDB, hKey);
1015 std::string line = path + " : ";
1016
1017 if (key->type != TID_KEY) {
1018 assert(key->total_size > 0);
1019 char *data = (char *) malloc(key->total_size);
1020 int size = key->total_size;
1021 int status = db_get_data(hDB, hKey, data, &size, key->type);
1022
1023 std::string data_str;
1024
1025 if (status == DB_NO_ACCESS)
1026 data_str = "<no read access>";
1027 else
1029
1030 if (key->num_values == 1)
1031 line += data_str;
1032
1033 printf("%s\n", line.c_str());
1034
1035 if (key->num_values > 1)
1036 for (int i = 0; i < key->num_values; i++) {
1038
1039 printf(" [%d] : %s\n", i, data_str.c_str());
1040 }
1041 free(data);
1042 } else {
1043 printf("%s\n", line.c_str());
1044 }
1045 }
1046
1047 return SUCCESS;
1048}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_key()

void set_key ( HNDLE  hDB,
HNDLE  hKey,
int  index1,
int  index2,
char value 
)

Definition at line 549 of file odbedit.cxx.

549 {
550 KEY key;
551 char data[1000];
552 int i, size, status = 0;
553
555
556 memset(data, 0, sizeof(data));
557 db_sscanf(value, data, &size, 0, key.type);
558
559 /* extend data size for single string if necessary */
560 if ((key.type == TID_STRING || key.type == TID_LINK)
561 && (int) strlen(data) + 1 > key.item_size && key.num_values == 1)
562 key.item_size = strlen(data) + 1;
563
564 if (key.item_size == 0)
566
567 if (key.num_values > 1 && index1 == -1) {
568 for (i = 0; i < key.num_values; i++)
570 } else if (key.num_values > 1 && index2 > index1) {
571 for (i = index1; i < key.num_values && i <= index2; i++)
573 } else if (key.num_values > 1 || index1 > 0)
575 else
577
578 if (status == DB_NO_ACCESS)
579 printf("Write access not allowed\n");
580}
INT rpc_tid_size(INT id)
Definition midas.cxx:11757
double value[100]
Definition odbhist.cxx:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread()

INT thread ( void p)

Definition at line 43 of file odbedit.cxx.

43 {
44 char str[32];
45 HNDLE hDB;
47 do {
49 db_set_value(hDB, 0, "/Experiment/Name", str, sizeof(str), 1, TID_STRING);
50 } while (1);
51
52 return 0;
53}
std::string ss_tid_to_string(midas_thread_t thread_id)
Definition system.cxx:1571
midas_thread_t ss_gettid(void)
Definition system.cxx:1519
Here is the call graph for this function:
Here is the caller graph for this function:

◆ watch_callback()

void watch_callback ( HNDLE  hDB,
HNDLE  hKey,
INT  index,
void info 
)

Definition at line 1396 of file odbedit.cxx.

1396 {
1397 KEY key;
1398 int status;
1399
1400 std::string path = db_get_path(hDB, hKey);
1401
1403 if (status != DB_SUCCESS) {
1404 printf("callback for invalid or deleted hkey %d odb path %s\n", hKey, path.c_str());
1405 return;
1406 }
1407
1408 if (key.type == TID_KEY)
1409 printf("%s modified\n", path.c_str());
1410 else {
1411 if (key.num_values == 1) {
1412 if (key.type == TID_STRING) {
1413 std::string data;
1414 db_get_value_string(hDB, 0, path.c_str(), 0, &data);
1415 printf("%s = \"%s\"\n", path.c_str(), data.c_str());
1416 } else {
1417 char data[10000];
1418 int size = sizeof(data);
1419 db_get_data(hDB, hKey, data, &size, key.type);
1420 std::string str = db_sprintf(data, size, 0, key.type);
1421 printf("%s = %s\n", path.c_str(), str.c_str());
1422 }
1423 } else {
1424 if (index == -1) {
1425 printf("%s[*] modified\n", path.c_str());
1426 } else {
1427 if (key.type == TID_STRING) {
1428 std::string data;
1429 db_get_value_string(hDB, 0, path.c_str(), index, &data);
1430 printf("%s[%d] = \"%s\"\n", path.c_str(), index, data.c_str());
1431 } else {
1432 char data[10000];
1433 int size = sizeof(data);
1435 std::string str = db_sprintf(data, size, 0, key.type);
1436 printf("%s[%d] = %s\n", path.c_str(), index, str.c_str());
1437 }
1438 }
1439 }
1440 }
1441}
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
Definition odb.cxx:6893
INT EXPRT db_get_value_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int index, std::string *s, BOOL create, int create_string_length)
Definition odb.cxx:13934
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xwrite()

static void xwrite ( const char filename,
int  fd,
const void data,
int  size 
)
static

Definition at line 1074 of file odbedit.cxx.

1074 {
1075 int wr = write(fd, data, size);
1076 if (wr != size) {
1077 cm_msg(MERROR, "xwrite", "cannot write to \'%s\', write(%d) returned %d, errno %d (%s)", filename, size, wr, errno, strerror(errno));
1078 }
1079}
#define write(n, a, f, d)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cmd_mode

BOOL cmd_mode

Definition at line 25 of file odbedit.cxx.

◆ in_cmd_edit

BOOL in_cmd_edit

Definition at line 23 of file odbedit.cxx.

◆ key_modified

BOOL key_modified

Definition at line 57 of file odbedit.cxx.

◆ ls_abort

int ls_abort

Definition at line 210 of file odbedit.cxx.

◆ ls_line

int ls_line

Definition at line 210 of file odbedit.cxx.

◆ need_redraw

BOOL need_redraw

Definition at line 22 of file odbedit.cxx.

◆ pwd

char pwd[256]

Definition at line 24 of file odbedit.cxx.

◆ tm

MUTEX_T* tm

Definition at line 39 of file odbedit.cxx.