72877dcb82226f52da4fa37022c6e829a9b1fa23
3 * Written by Jan Roeloffzen
5 * - Cli for escape commands
14 #include "log2lines.h"
17 /* When you edit the cmd line and/or use the history instead of just typing,
18 * a bunch of editing BS and space characters
19 * is inserted, so the string looks right on the console but still
20 * starts with the original string:
23 *backSpaceEdit(char *s
)
29 while (( c
= *edit
++ ))
47 handle_switch(FILE *outFile
, int *sw
, char *arg
, char *desc
)
52 if (arg
&& (strcmp(arg
,"") != 0))
63 esclog(outFile
, "%s is %d (%s)\n", desc
, *sw
, changed
? "changed":"unchanged");
65 esclog(outFile
, "(readonly)\n");
72 handle_switch_str(FILE *outFile
, char *sw
, char *arg
, char *desc
)
78 if (strcmp(arg
,"") != 0)
80 if (strcmp(arg
,KDBG_ESC_OFF
) == 0)
86 else if (strcmp(arg
, sw
) != 0)
95 esclog(outFile
, "%s is \"%s\" (%s)\n", desc
, sw
, changed
? "changed":"unchanged");
97 esclog(outFile
, "(readonly)\n");
104 handle_switch_pstr(FILE *outFile
, char **psw
, char *arg
, char *desc
)
110 if (strcmp(arg
,"") != 0)
112 if (strcmp(arg
,KDBG_ESC_OFF
) == 0)
123 *psw
= malloc(LINESIZE
);
127 if (strcmp(arg
, *psw
) != 0)
137 esclog(outFile
, "%s is \"%s\" (%s)\n", desc
, *psw
, changed
? "changed":"unchanged");
139 esclog(outFile
, "(readonly)\n");
146 handle_escape_cmd(FILE *outFile
, char *Line
, char *path
, char *LineOut
)
156 l
= backSpaceEdit(l
);
157 if (l
[1] != KDBG_ESC_CHAR
)
158 return l
[1]; //for reprocessing as not escaped
162 l
+= 2; //skip space+escape character
163 if ( (cnt
=sscanf(l
,"%c%c",&cmd
,&sep
)) < 1)
165 esclog(outFile
, "Command expected\n");
169 if (res
&& cnt
==2 && sep
!= ' ')
171 esclog(outFile
, "' ' expected\n");
175 while ( *l
== ' ')l
++; //skip more spaces
184 if (handle_switch(outFile
, &opt_buffered
, arg
, "-b Logfile buffering"))
185 set_LogFile(logFile
); //re-open same logfile
188 handle_switch(outFile
, &opt_console
, NULL
, "-c Console option");
191 handle_switch_str(outFile
, opt_dir
, NULL
, "-d Directory option");
194 if (handle_switch_str(outFile
, opt_logFile
, arg
, "-l logfile"))
195 set_LogFile(logFile
); //open new logfile
198 handle_switch(outFile
, &opt_Mark
, arg
, "-m mark (*)");
201 handle_switch(outFile
, &opt_Mark
, arg
, "-M Mark (?)");
204 handle_switch_str(outFile
, opt_Pipe
, NULL
, "-P Pipeline option");
208 esclog(outFile
, "Bye!\n");
211 handle_switch(outFile
, &opt_raw
, arg
, "-r Raw");
214 changed
= handle_switch_pstr(outFile
, &opt_Revision
, arg
, NULL
);
217 if (strstr(opt_Revision
, "check") == opt_Revision
)
219 esclog(outFile
, "-R is \"%s\" (%s)\n", opt_Revision
, changed
? "changed":"unchanged");
221 else if (strstr(opt_Revision
, "regscan") == opt_Revision
)
223 char *s
= strchr(opt_Revision
, ',');
225 revinfo
.range
= DEF_RANGE
;
229 revinfo
.range
= atoi(s
);
233 else if (strstr(opt_Revision
, "regclear") == opt_Revision
)
235 list_clear(&sources
);
237 esclog(outFile
, "cleared regression scan results\n");
242 if (strcmp(arg
,"clear") == 0)
244 memset(&summ
, 0, sizeof(SUMM
));
245 esclog(outFile
, "Statistics cleared\n");
248 stat_print(outFile
, &summ
);
251 cnt
= sscanf(arg
, "%d+%d", &opt_Source
, &opt_SrcPlus
);
254 handle_switch(outFile
, &opt_undo
, "1", "-u Undo");
255 handle_switch(outFile
, &opt_redo
, "1", "-U Undo and reprocess");
257 esclog(outFile
, "-S Sources option is %d+%d,\"%s\"\n", opt_Source
, opt_SrcPlus
, opt_SourcesPath
);
258 esclog(outFile
, "(Setting source tree not implemented)\n");
261 handle_switch(outFile
, &opt_twice
, arg
, "-t Translate twice");
264 handle_switch(outFile
, &opt_twice
, arg
, NULL
);
265 handle_switch(outFile
, &opt_Twice
, arg
, "-T Translate for (address-1)");
268 handle_switch(outFile
, &opt_undo
, arg
, "-u undo");
271 handle_switch(outFile
, &opt_undo
, arg
, NULL
);
272 handle_switch(outFile
, &opt_redo
, arg
, "-U Undo and reprocess");
275 handle_switch(outFile
, &opt_verbose
, arg
, "-v Verbosity");
278 handle_switch_str(outFile
, opt_7z
, NULL
, "-z 7z path");
281 if (strchr(optchars
, cmd
))
282 esclog(outFile
, "Command not implemented in cli: %c %s\n",cmd
, arg
)
284 esclog(outFile
, "Unknown command: %c %s\n",cmd
, arg
);
288 memset(Line
, '\0', LINESIZE
); // flushed
290 return KDBG_ESC_CHAR
; //handled escaped command