Rizin
unix-like reverse engineering framework and cli tools
sh.h
Go to the documentation of this file.
1 /* SH */
2 
3 // TODO: use popen for {{pipe/endpipe}}
4 
5 #if 0
6 static char *eof = NULL;
7 static char *input = NULL;
8 #endif
9 
10 static TAG_CALLBACK(sh_default) {
11  //if (out != stdout) {
12  // pipe stdout to out fd
13  //}
14 #if 0
15  ptr = strstr(buf, "<<");
16  if (ptr) {
17  *ptr='\0';
18  for(ptr = ptr+2;*ptr==' ';ptr=ptr+1);
19  free(eof);
20  eof = strdup(ptr);
21  return;
22  }
23 
24  // printf("system(%s)\n", buf);
25  if (eof)
26 #endif
27 #if HAVE_FORK
28  int r = system (buf);
29  if (errno) {
30  printf ("system '%s' (%d) failed: %s\n", buf, r, strerror (errno));
31  }
32 #endif
33  return 0;
34 }
35 
36 static int sh_pipe_enabled = 0;
37 static char *sh_pipe_cmd = NULL;
38 
39 static TAG_CALLBACK(sh_pipe) {
40  sh_pipe_enabled = 1;
41  free (sh_pipe_cmd);
43  return 0;
44 }
45 
46 static TAG_CALLBACK(sh_endpipe) {
47  sh_pipe_enabled = 0;
48  free (sh_pipe_cmd);
49  sh_pipe_cmd = NULL;
50  return 0;
51 }
52 
53 static PUT_CALLBACK(sh_fputs) {
54  if (sh_pipe_enabled) {
55  char str[1024]; // XXX
56  sprintf (str, "echo '%s' | %s", buf, sh_pipe_cmd); // XXX
57 #if HAVE_FORK
58  int r = system (str);
59  if (errno) {
60  printf ("system '%s' (%d) failed: %s\n", str, r, strerror (errno));
61  }
62 #endif
63  } else {
64  out_printf (out, "%s", buf);
65  }
66  return 0;
67 }
68 
69 static struct Tag sh_tags[] = {
70  { "pipe", sh_pipe },
71  { "endpipe", sh_endpipe },
72  { NULL, sh_default },
73  { NULL }
74 };
75 
76 static struct Arg sh_args[] = {
77  { NULL }
78 };
79 
81  .name = "sh",
82  .tags = (struct Tag **)sh_tags,
83  .args = (struct Arg **)sh_args,
84  .eof = NULL,
85  .token = NULL,
86  .tag_pre = "{{",
87  .tag_post = "}}",
88  .fputs = sh_fputs,
89  .multiline = "\\\n",
90  .default_echo = 1,
91  .chop = 0,
92  .tag_begin = 0,
93 };
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
sprintf
Definition: kernel.h:365
int args
Definition: mipsasm.c:18
void out_printf(Output *out, char *str,...) __attribute__((format(printf
return strdup("=PC pc\n" "=SP r15\n" "=BP r14\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 pc .32 64 0\n" "gpr pr .32 68 0\n" "gpr sr .32 72 0\n" "gpr gbr .32 76 0\n" "gpr mach .32 80 0\n" "gpr macl .32 84 0\n")
static PUT_CALLBACK(sh_fputs)
Definition: sh.h:53
static struct Arg sh_args[]
Definition: sh.h:76
static int sh_pipe_enabled
Definition: sh.h:36
static struct Tag sh_tags[]
Definition: sh.h:69
DLL_LOCAL struct Proc sh_proc
Definition: sh.h:80
static TAG_CALLBACK(sh_default)
Definition: sh.h:10
static char * sh_pipe_cmd
Definition: sh.h:37
#define DLL_LOCAL
Definition: spp.h:69
Definition: spp.h:121
Definition: spp.h:128
const char * name
Definition: spp.h:129
Definition: spp.h:116
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)