* 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. */
| 383 | * we do not wish to use db_lex's token processing. |
| 384 | */ |
| 385 | void |
| 386 | db_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. |
nothing calls this directly
no test coverage detected