3 #ifndef INCLUDE_P_SPP_H
4 #define INCLUDE_P_SPP_H
20 static char *cmd_to_str(
const char *
cmd) {
23 int ret = 0,
len = 0, outlen = 4096;
27 ret = fread (
out +
len, 1, 1023,
fd);
32 if (ret + 1024 > outlen) {
40 fprintf (stderr,
"Out of memory.\n");
64 eq = strchr (
buf,
' ');
70 fprintf (stderr,
"Invalid variable name '%s' at line %d\n",
buf,
state->lineno);
104 char *var, *
eq = strchr (
buf,
' ');
115 ret += atoi (
eq + 1);
116 snprintf (res,
sizeof (res),
"%d", ret);
125 char *
eq = strchr(
buf,
' ');
134 ret = var? atoi (var): 0;
135 ret -= atoi (
eq + 1);
145 fprintf (stderr,
"%.1000s\n",
buf);
163 fprintf (stderr,
"ERROR: %s (line=%d)\n",
buf,
state->lineno);
171 fprintf (stderr,
"WARNING: %s (line=%d)\n",
buf,
state->lineno);
180 char *
str = cmd_to_str (
buf);
192 incdir =
getenv(
"SPP_INCDIR");
211 state->echo[
state->ifl + 1] = (var && *var !=
'0' && *var !=
'\0') ? 1 : 0;
218 char *
eq = strchr(
buf,
' ');
239 if (
buf[
i] >=
'0' &&
buf[
i] <=
'9') {
244 sscanf(
buf +
i,
"%02x", &ch);
260 ptr = strchr(
buf,
' ');
263 fd = fopen (
buf,
"r");
266 while (!feof (
fd) &&
line--) {
267 if (!fgets (
b, 1023,
fd)) {
274 fprintf(stderr,
"Unable to open '%s'\n",
buf);
296 ptr = strchr (
buf,
' ');
301 if (strstr (ptr + 1, var)) {
316 if (
buf[-1] !=
';') {
317 fprintf (stderr,
"WARNING: invalid command: '%s' at line %d\n",
buf,
state->lineno);
328 spp_pipe_fd = popen (
buf,
"w");
359 int ret = 0,
len = 0;
365 ret = fread (
str +
len, 1, 1023, spp_pipe_fd);
366 if (ret + 1024 > outlen) {
370 fprintf (stderr,
"Out of memory.\n");
379 pclose (spp_pipe_fd);
390 fprintf (spp_pipe_fd,
"%s",
buf);
402 {
"getrandom", spp_getrandom },
403 {
"grepline", spp_grepline },
407 {
"switch", spp_switch },
408 {
"case", spp_case },
409 {
"endswitch", spp_endswitch },
410 {
"echo", spp_echo },
411 {
"error", spp_error },
412 {
"warning", spp_warning },
413 {
"trace", spp_trace },
414 {
"ifin", spp_ifin },
415 {
"ifnot", spp_ifnot },
416 {
"ifeq", spp_ifeq },
418 {
"else", spp_else },
419 {
"endif", spp_endif },
420 {
"pipe", spp_pipe },
421 {
"endpipe", spp_endpipe },
422 {
"include", spp_include },
423 {
"system", spp_system },
424 {
NULL, spp_default },
435 char *
eq = strchr (
arg,
'=');
446 {
"-I",
"add include directory", 1, spp_arg_i },
447 {
"-D",
"define value of variable", 1, spp_arg_d },
const lzma_allocator const uint8_t size_t uint8_t * out
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static ARG_CALLBACK(spp_arg_i)
static int spp_var_set(const char *var, const char *val)
static TAG_CALLBACK(spp_set)
static char * spp_switch_str
DLL_LOCAL struct Proc spp_proc
static char * spp_var_get(char *var)
static struct Arg spp_args[]
static struct Tag spp_tags[]
static PUT_CALLBACK(spp_fputs)
void out_printf(Output *out, char *str,...) __attribute__((format(printf
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
RZ_API int rz_sys_setenv(const char *key, const char *value)
Set an environment variable in the calling process.
RZ_API int rz_sys_getpid(void)
S_API int spp_file(const char *file, Output *out)
static const z80_opcode fd[]