tb Command-like scripts
This commit is contained in:
@ -136,6 +136,22 @@ void tz_expandspecial(Tokenizer *tz) {
|
|||||||
Token *tk, *tktmp;
|
Token *tk, *tktmp;
|
||||||
LL_FOREACH_SAFE(tz->tokens, tk, tktmp) {
|
LL_FOREACH_SAFE(tz->tokens, tk, tktmp) {
|
||||||
if (tk->str[0] == '$' && string_len(tk->str) > 1) {
|
if (tk->str[0] == '$' && string_len(tk->str) > 1) {
|
||||||
|
bool isnum;
|
||||||
|
STRING_CHECK_ALL(tk->str + 1, string_chr_isdigit, isnum);
|
||||||
|
if (isnum) {
|
||||||
|
// this is a special case for command-like scripts
|
||||||
|
char *endp;
|
||||||
|
unsigned long idx = string_conv_strtoul(tk->str + 1, &endp, 10);
|
||||||
|
idx += 2; // skip command itself and indicator / '.'
|
||||||
|
|
||||||
|
ufree(tk->str);
|
||||||
|
char *s = idx < argslen() ? args()[idx] : "";
|
||||||
|
size_t len = string_len(s);
|
||||||
|
char *copy = umalloc(len+1);
|
||||||
|
string_memcpy(copy, s, len);
|
||||||
|
copy[len] = '\0';
|
||||||
|
tk->str = copy;
|
||||||
|
} else {
|
||||||
if (string_strcmp(tk->str, "$stack") == 0) {
|
if (string_strcmp(tk->str, "$stack") == 0) {
|
||||||
char *s = rtstringv_stackpeek();
|
char *s = rtstringv_stackpeek();
|
||||||
ufree(tk->str);
|
ufree(tk->str);
|
||||||
@ -164,6 +180,7 @@ void tz_expandspecial(Tokenizer *tz) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LINE_MAX 1024
|
#define LINE_MAX 1024
|
||||||
|
|||||||
@ -134,6 +134,16 @@ void do_mode_interactive(void) {
|
|||||||
void main(void) {
|
void main(void) {
|
||||||
PID = proc_getpid();
|
PID = proc_getpid();
|
||||||
|
|
||||||
|
// short command-like script was supplied
|
||||||
|
if (argslen() > 0 && args()[0][0] == '.') {
|
||||||
|
do_file("base:/scripts/rc.tb");
|
||||||
|
char *path = umalloc(4096);
|
||||||
|
usprintf(path, "base:/scripts/%s.tb", args()[1]);
|
||||||
|
do_file(path);
|
||||||
|
ufree(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
set_config();
|
set_config();
|
||||||
|
|
||||||
do_file("base:/scripts/rc.tb");
|
do_file("base:/scripts/rc.tb");
|
||||||
|
|||||||
Reference in New Issue
Block a user