MCPcopy Create free account
hub / github.com/F-Stack/f-stack / db_script_cmd

Function db_script_cmd

freebsd/ddb/db_script.c:385–426  ·  view source on GitHub ↗

* Print or set a named script, with the set portion broken out into its own * function. We must directly access the remainder of the DDB line input as * we do not wish to use db_lex's token processing. */

Source from the content-addressed store, hash-verified

383 * we do not wish to use db_lex's token processing.
384 */
385void
386db_script_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
387 char *modif)
388{
389 char *buf, scriptname[DB_MAXSCRIPTNAME];
390 struct ddb_script *dsp;
391 int error, t;
392
393 t = db_read_token();
394 if (t != tIDENT) {
395 db_printf("usage: script scriptname=script\n");
396 db_skip_to_eol();
397 return;
398 }
399
400 if (strlcpy(scriptname, db_tok_string, sizeof(scriptname)) >=
401 sizeof(scriptname)) {
402 db_printf("scriptname too long\n");
403 db_skip_to_eol();
404 return;
405 }
406
407 t = db_read_token();
408 if (t == tEOL) {
409 dsp = db_script_lookup(scriptname);
410 if (dsp == NULL) {
411 db_printf("script '%s' not found\n", scriptname);
412 db_skip_to_eol();
413 return;
414 }
415 db_printf("%s=%s\n", scriptname, dsp->ds_script);
416 } else if (t == tEQ) {
417 buf = db_get_line();
418 if (buf[strlen(buf)-1] == '\n')
419 buf[strlen(buf)-1] = '\0';
420 error = db_script_set(scriptname, buf);
421 if (error != 0)
422 db_printf("Error: %d\n", error);
423 } else
424 db_printf("?\n");
425 db_skip_to_eol();
426}
427
428/*
429 * Remove a named script.

Callers

nothing calls this directly

Calls 7

db_read_tokenFunction · 0.85
db_printfFunction · 0.85
db_skip_to_eolFunction · 0.85
db_script_lookupFunction · 0.85
db_get_lineFunction · 0.85
db_script_setFunction · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected