Compare commits
2 Commits
73effcd52a
...
91d648ade4
Author | SHA1 | Date | |
---|---|---|---|
91d648ade4 | |||
0232849994 |
@ -1,3 +1,3 @@
|
|||||||
%print 'this is an init script!'
|
print 'this is an init script!'
|
||||||
base:/bin/pctl ls
|
base:/bin/pctl ls
|
||||||
base:/bin/tb -m interactive -preload base:/scripts/rc.tb
|
base:/bin/tb -m interactive -preload base:/scripts/rc.tb
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
%mkalias pctl base:/bin/pctl
|
mkalias pctl base:/bin/pctl
|
||||||
%mkalias tb base:/bin/tb
|
mkalias tb base:/bin/tb
|
||||||
|
@ -14,4 +14,17 @@
|
|||||||
#define string_chr_isascii(c) (!((c) < 0 || (c) > 0x7f))
|
#define string_chr_isascii(c) (!((c) < 0 || (c) > 0x7f))
|
||||||
#define string_chr_isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
|
#define string_chr_isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
|
||||||
|
|
||||||
|
#define STRING_CHECK_ALL(str, macro, okp) \
|
||||||
|
do { \
|
||||||
|
(okp) = true; \
|
||||||
|
char *__p = (str); \
|
||||||
|
while (*__p) { \
|
||||||
|
if (!macro(*__p)) { \
|
||||||
|
(okp) = false; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
__p++; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#endif // ULIB_STRING_CHAR_H_
|
#endif // ULIB_STRING_CHAR_H_
|
||||||
|
@ -99,20 +99,23 @@ void tz_tokenize(Tokenizer *tz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tz_classify(Tokenizer *tz) {
|
void tz_classify(Tokenizer *tz) {
|
||||||
|
#define IF_RTCMD(name) if (string_strcmp(tk->str, #name) == 0) { \
|
||||||
|
tk->type = TOK_CMD; \
|
||||||
|
tk->cmd = &rt_ ## name; \
|
||||||
|
}
|
||||||
|
|
||||||
Token *tk, *tktmp;
|
Token *tk, *tktmp;
|
||||||
LL_FOREACH_SAFE(tz->tokens, tk, tktmp) {
|
LL_FOREACH_SAFE(tz->tokens, tk, tktmp) {
|
||||||
if (tk->str[0] == '\'') {
|
if (tk->str[0] == '\'') {
|
||||||
tk->type = TOK_STRING;
|
tk->type = TOK_STRING;
|
||||||
} else if (tk->str[0] == '%') {
|
|
||||||
RtCmd *cmd, *cmdtmp;
|
|
||||||
LL_FOREACH_SAFE(RTCMDS, cmd, cmdtmp) {
|
|
||||||
if (string_strcmp(tk->str, cmd->cmdname) == 0) {
|
|
||||||
tk->type = TOK_CMD;
|
|
||||||
tk->cmd = cmd;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
else IF_RTCMD(print)
|
||||||
} else {
|
else IF_RTCMD(mkalias)
|
||||||
|
else IF_RTCMD(PID)
|
||||||
|
else IF_RTCMD(do)
|
||||||
|
else IF_RTCMD(stackpush)
|
||||||
|
else IF_RTCMD(stackpop)
|
||||||
|
else {
|
||||||
tk->type = TOK_MISC;
|
tk->type = TOK_MISC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,6 +170,13 @@ bool interp_runstring(char *string, InterpResult **res, bool logcmds, bool inter
|
|||||||
uprintf("+%s\n", line);
|
uprintf("+%s\n", line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool skip;
|
||||||
|
STRING_CHECK_ALL(line, string_chr_isspace, skip);
|
||||||
|
if (skip) {
|
||||||
|
line = string_tokenizealloc(NULL, "\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Tokenizer tz; ZERO(&tz);
|
Tokenizer tz; ZERO(&tz);
|
||||||
tz_init(&tz, line);
|
tz_init(&tz, line);
|
||||||
|
|
||||||
@ -177,7 +187,7 @@ bool interp_runstring(char *string, InterpResult **res, bool logcmds, bool inter
|
|||||||
|
|
||||||
Token *cmdtk = tz.tokens;
|
Token *cmdtk = tz.tokens;
|
||||||
if (cmdtk->type == TOK_CMD) {
|
if (cmdtk->type == TOK_CMD) {
|
||||||
ok = cmdtk->cmd->fn(cmdtk->next);
|
ok = cmdtk->cmd(cmdtk->next);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
usprintf(RES.errmsg, "cmd %s failed", cmdtk->str);
|
usprintf(RES.errmsg, "cmd %s failed", cmdtk->str);
|
||||||
goto next;
|
goto next;
|
||||||
|
@ -21,7 +21,7 @@ typedef struct Token {
|
|||||||
TOK_MISC,
|
TOK_MISC,
|
||||||
} type;
|
} type;
|
||||||
|
|
||||||
struct RtCmd *cmd;
|
bool (*cmd)(struct Token *);
|
||||||
} Token;
|
} Token;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -30,6 +30,13 @@ void rt_init(void);
|
|||||||
extern RtCmd *RTCMDS;
|
extern RtCmd *RTCMDS;
|
||||||
extern RtAlias *RTALIASES;
|
extern RtAlias *RTALIASES;
|
||||||
|
|
||||||
|
bool rt_print(struct Token *);
|
||||||
|
bool rt_mkalias(struct Token *);
|
||||||
|
bool rt_PID(struct Token *);
|
||||||
|
bool rt_do(struct Token *);
|
||||||
|
bool rt_stackpush(struct Token *);
|
||||||
|
bool rt_stackpop(struct Token *);
|
||||||
|
|
||||||
void rtstringv_stackpushcopy(char *s, size_t len);
|
void rtstringv_stackpushcopy(char *s, size_t len);
|
||||||
char *rtstringv_stackpop(void);
|
char *rtstringv_stackpop(void);
|
||||||
char *rtstringv_stackpeek(void);
|
char *rtstringv_stackpeek(void);
|
||||||
|
Reference in New Issue
Block a user