Compare commits
3 Commits
97bc0aa05b
...
222e846881
Author | SHA1 | Date | |
---|---|---|---|
222e846881 | |||
a24b1fc677 | |||
a8005917eb |
@ -13,6 +13,7 @@ SRCFILES := $(call GRABSRC, \
|
|||||||
dlmalloc \
|
dlmalloc \
|
||||||
sync \
|
sync \
|
||||||
args \
|
args \
|
||||||
|
util \
|
||||||
)
|
)
|
||||||
|
|
||||||
CFLAGS += -isystem $(ROOT)/share -isystem $(ROOT)/ulib -isystem $(ROOT)/std/include \
|
CFLAGS += -isystem $(ROOT)/share -isystem $(ROOT)/ulib -isystem $(ROOT)/std/include \
|
||||||
|
6
ulib/util/util.c
Normal file
6
ulib/util/util.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <system/system.h>
|
||||||
|
#include <sysdefs/processctl.h>
|
||||||
|
|
||||||
|
void quit(void) {
|
||||||
|
processctl(-1, PCTL_KILL, 0, 0, 0);
|
||||||
|
}
|
@ -11,4 +11,6 @@
|
|||||||
*(X); \
|
*(X); \
|
||||||
}) \
|
}) \
|
||||||
|
|
||||||
|
void quit(void);
|
||||||
|
|
||||||
#endif // ULIB_UTIL_UTIL_H_
|
#endif // ULIB_UTIL_UTIL_H_
|
||||||
|
2
user/diagdummy/.gitignore
vendored
Normal file
2
user/diagdummy/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.o
|
||||||
|
diagdummy
|
24
user/diagdummy/Makefile
Normal file
24
user/diagdummy/Makefile
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
include $(ROOT)/mk/grabsrc.mk
|
||||||
|
include ../Makefile.inc
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
TARGET := diagdummy
|
||||||
|
|
||||||
|
LDFLAGS += -L$(ROOT)/ulib -l:libulib.a
|
||||||
|
|
||||||
|
SRCFILES := $(call GRABSRC, .)
|
||||||
|
CFILES := $(call GET_CFILES, $(SRCFILES))
|
||||||
|
OBJ := $(call GET_OBJ, $(SRCFILES))
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(OBJ)
|
||||||
|
$(LD) $^ $(LDFLAGS) -o $@
|
||||||
|
echo $$(realpath $(TARGET)) >> $(FILES)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ) $(TARGET)
|
7
user/diagdummy/block.c
Normal file
7
user/diagdummy/block.c
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include <ulib.h>
|
||||||
|
|
||||||
|
void diagdummy_block(void) {
|
||||||
|
uprintf("blocking...\n");
|
||||||
|
while(1) {
|
||||||
|
}
|
||||||
|
}
|
6
user/diagdummy/block.h
Normal file
6
user/diagdummy/block.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef DIAGDUMMY_BLOCK_H_
|
||||||
|
#define DIAGDUMMY_BLOCK_H_
|
||||||
|
|
||||||
|
void diagdummy_block(void);
|
||||||
|
|
||||||
|
#endif // DIAGDUMMY_BLOCK_H_
|
17
user/diagdummy/diagdummy.c
Normal file
17
user/diagdummy/diagdummy.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <ulib.h>
|
||||||
|
#include "block.h"
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
if (argslen() == 0) {
|
||||||
|
uprintf("diagdummy: no arguments\n");
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
char *cmd = args()[0];
|
||||||
|
|
||||||
|
if (string_strcmp(cmd, "block") == 0) {
|
||||||
|
diagdummy_block();
|
||||||
|
} else {
|
||||||
|
uprintf("diagdummy: unknown cmd %s\n", cmd);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
#include <ulib.h>
|
#include <ulib.h>
|
||||||
#include "interp.h"
|
#include "interp.h"
|
||||||
#include "runtime.h"
|
#include "runtime.h"
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
extern uint64_t PID;
|
extern uint64_t PID;
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ bool interp_readline(char *data, const char **bgptr, const char **endptr) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
|
bool interp_runstring(const char *string, InterpResult **res, bool logcmds, bool interactive) {
|
||||||
*res = &RES;
|
*res = &RES;
|
||||||
string_memset(RES.errmsg, 0, sizeof(RES.errmsg));
|
string_memset(RES.errmsg, 0, sizeof(RES.errmsg));
|
||||||
|
|
||||||
@ -230,17 +231,26 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
|
|||||||
|
|
||||||
processctl(app, PCTL_RUN, 0, 0, 0);
|
processctl(app, PCTL_RUN, 0, 0, 0);
|
||||||
|
|
||||||
|
uint8_t b;
|
||||||
while(processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
while(processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
||||||
|
if (interactive) {
|
||||||
|
int32_t nrd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, &b, 1);
|
||||||
|
if (nrd > 0 && b == C('S')) {
|
||||||
|
processctl(app, PCTL_KILL, 0, 0, 0);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
schedrelease();
|
schedrelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup: {
|
||||||
for (size_t j = 0; j < argslen1; j++) {
|
for (size_t j = 0; j < argslen1; j++) {
|
||||||
dlfree(args1[j]);
|
dlfree(args1[j]);
|
||||||
}
|
}
|
||||||
dlfree(args1);
|
dlfree(args1);
|
||||||
dlfree(appname);
|
dlfree(appname);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tz_free(&tz);
|
tz_free(&tz);
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,6 @@ typedef struct {
|
|||||||
Token *tokens;
|
Token *tokens;
|
||||||
} Tokenizer;
|
} Tokenizer;
|
||||||
|
|
||||||
bool interp_runstring(const char *string, InterpResult **res, bool logcmds);
|
bool interp_runstring(const char *string, InterpResult **res, bool logcmds, bool interactive);
|
||||||
|
|
||||||
#endif // TB_INTERP_H_
|
#endif // TB_INTERP_H_
|
||||||
|
7
user/tb/macros.h
Normal file
7
user/tb/macros.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef TB_MACROS_H_
|
||||||
|
#define TB_MACROS_H_
|
||||||
|
|
||||||
|
// keys
|
||||||
|
#define C(X) ((X)-'@')
|
||||||
|
|
||||||
|
#endif // TB_MACROS_H_
|
@ -2,9 +2,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <ulib.h>
|
#include <ulib.h>
|
||||||
#include "interp.h"
|
#include "interp.h"
|
||||||
|
#include "macros.h"
|
||||||
// keys
|
|
||||||
#define C(X) ((X)-'@')
|
|
||||||
|
|
||||||
#define LINEBUF_MAX 1024
|
#define LINEBUF_MAX 1024
|
||||||
|
|
||||||
@ -75,7 +73,7 @@ void do_file(char *filepath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InterpResult *res;
|
InterpResult *res;
|
||||||
bool ok = interp_runstring((const char *)buf, &res, CONFIG.logcmds);
|
bool ok = interp_runstring((const char *)buf, &res, CONFIG.logcmds, CONFIG.mode == MODE_INTERACTIVE);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
uprintf("Interpreter error:\n");
|
uprintf("Interpreter error:\n");
|
||||||
uprintf("%s\n", res->errmsg);
|
uprintf("%s\n", res->errmsg);
|
||||||
@ -130,7 +128,7 @@ void do_mode_interactive(void) {
|
|||||||
}
|
}
|
||||||
uprintf("\n");
|
uprintf("\n");
|
||||||
InterpResult *res;
|
InterpResult *res;
|
||||||
if (!interp_runstring(linebuf, &res, CONFIG.logcmds)) {
|
if (!interp_runstring(linebuf, &res, CONFIG.logcmds, CONFIG.mode == MODE_INTERACTIVE)) {
|
||||||
LOG(LOG_ERR, "%s\n", res->errmsg);
|
LOG(LOG_ERR, "%s\n", res->errmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user