Rizin
unix-like reverse engineering framework and cli tools
spp.h
Go to the documentation of this file.
1 #ifndef _INCLUDE_SPP_H_
2 #define _INCLUDE_SPP_H_
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdarg.h>
8 #include <stdbool.h>
9 #include <errno.h>
10 
11 #ifndef VERSION
12 #define VERSION "1.2.0"
13 #endif
14 
15 #ifdef S_API
16 #undef S_API
17 #endif
18 #if RZ_SWIG
19  #define S_API export
20 #elif RZ_INLINE
21  #define S_API inline
22 #else
23  #if defined(__GNUC__) && __GNUC__ >= 4
24  #define S_API __attribute__((visibility("default")))
25  #elif defined(_MSC_VER)
26  #define S_API __declspec(dllexport)
27  #else
28  #define S_API
29  #endif
30 #endif
31 
32 #if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__)
33  #define __BSD__ 0
34  #define __UNIX__ 1
35 #endif
36 #if __KFBSD__ || defined(__NetBSD__) || defined(__OpenBSD__)
37  #define __BSD__ 1
38  #define __UNIX__ 1
39 #endif
40 #if __WIN32__ || __CYGWIN__ || MINGW32
41  #define __addr_t_defined
42  #include <windows.h>
43 #endif
44 #if __WIN32__ || MINGW32 && !__CYGWIN__ || _MSC_VER
45  #ifndef _MSC_VER
46  #include <winsock.h>
47  #endif
48  typedef int socklen_t;
49  #undef USE_SOCKETS
50  #define __WINDOWS__ 1
51  #undef __UNIX__
52  #undef __BSD__
53 #endif
54 
55 #ifdef __WINDOWS__
56 #include <io.h>
57 #define popen _popen
58 #define pclose _pclose
59 #define srandom srand
60 #define snprintf _snprintf
61 #endif
62 
63 #define MAXIFL 128
64 
65 #ifndef DLL_LOCAL
66 #ifdef _MSC_VER
67 #define DLL_LOCAL
68 #else
69 #define DLL_LOCAL __attribute__ ((visibility ("hidden")))
70 #endif
71 #endif
72 
73 #define GET_ARG(x,y,i) if (y[i][2]) x = y[i] + 2; else x = y[++i]
74 
75 #define DEFAULT_PROC(x) \
76 struct Tag *tags = (struct Tag *)&x##_tags; \
77 struct Arg *args = (struct Arg *)&x##_args; \
78 struct Proc *proc = &x##_proc;
79 
80 #if USE_R2
81 #include <rz_util.h>
82 #define SStrBuf RzStrBuf
83 #else
84 typedef struct s_strbuf_t {
85  int len;
86  char *ptr;
87  int ptrlen;
88  char buf[64];
90 #endif
91 
92 typedef struct {
95  int size;
96 } Output;
97 
98 typedef struct SppState {
99  int lineno;
100  int echo[MAXIFL];
101  int ifl;
103 
104 typedef struct SppBuf {
105  char *lbuf;
106  int lbuf_s;
107  int lbuf_n;
109 
110 #define ARG_CALLBACK(x) int x (char *arg)
111 /* XXX swap arguments ?? */
112 #define TAG_CALLBACK(x) int x (SppState *state, Output *out, char *buf)
113 #define PUT_CALLBACK(x) int x (Output *out, char *buf)
114 #define IS_SPACE(x) ((x==' ')||(x=='\t')||(x=='\r')||(x=='\n'))
115 
116 typedef struct Tag {
117  const char *name;
118  TAG_CALLBACK((*callback));
120 
121 typedef struct Arg {
122  const char *flag;
123  const char *desc;
124  int has_arg;
125  ARG_CALLBACK((*callback));
127 
128 typedef struct Proc {
129  const char *name;
130  struct Tag **tags;
131  struct Arg **args;
132  TAG_CALLBACK ((*eof));
133  PUT_CALLBACK ((*fputs));
134  char *tag_pre;
135  char *tag_post;
136  char *token;
137  char *multiline;
138  int chop;
144 
145 typedef struct spp_t {
148 } Spp;
149 
150 S_API int spp_file(const char *file, Output *out);
151 S_API int spp_run(char *buf, Output *out);
152 S_API void spp_eval(char *buf, Output *out);
153 S_API void spp_proc_eval(SppProc *p, char *buf, Output *out);
154 S_API void spp_io(FILE *in, Output *out);
155 S_API void spp_proc_list(void);
156 S_API void spp_proc_list_kw(void);
157 S_API void spp_proc_set(SppProc *p, const char *arg, int fail);
158 
160 S_API char *spp_parse(Spp *s, const char *input);
162 
163 #if DEBUG
164 #define D if (1)
165 #else
166 #define D if (0)
167 #endif
168 
169 #ifndef HAVE_FORK
170 #define HAVE_FORK 1
171 #endif
172 
173 #endif
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
voidpf void * buf
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
string FILE
Definition: benchmark.py:21
static RzSocket * s
Definition: rtr.c:28
unsigned int socklen_t
Definition: sftypes.h:219
#define S_API
Definition: spp.h:28
S_API void spp_proc_eval(SppProc *p, char *buf, Output *out)
Definition: spp.c:113
S_API void spp_eval(char *buf, Output *out)
Definition: spp.c:109
struct Proc SppProc
struct s_strbuf_t SStrBuf
S_API int spp_run(char *buf, Output *out)
Definition: spp.c:11
S_API void spp_free(Spp *s)
S_API void spp_proc_set(SppProc *p, const char *arg, int fail)
Definition: spp.c:298
S_API int spp_file(const char *file, Output *out)
Definition: spp.c:272
S_API char * spp_parse(Spp *s, const char *input)
#define MAXIFL
Definition: spp.h:63
S_API void spp_proc_list_kw(void)
Definition: spp.c:284
struct Arg SppArg
struct Tag SppTag
struct SppBuf SppBuf
S_API void spp_proc_list(void)
Definition: spp.c:291
struct SppState SppState
S_API Spp * spp_new(SppProc *proc)
S_API void spp_io(FILE *in, Output *out)
Definition: spp.c:224
struct spp_t Spp
Definition: spp.h:121
const char * desc
Definition: spp.h:123
int has_arg
Definition: spp.h:124
const char * flag
Definition: spp.h:122
ARG_CALLBACK((*callback))
Definition: spp.h:92
int size
Definition: spp.h:95
SStrBuf * cout
Definition: spp.h:93
FILE * fout
Definition: spp.h:94
Definition: spp.h:128
TAG_CALLBACK((*eof))
SppState state
Definition: spp.h:141
SppBuf buf
Definition: spp.h:142
int default_echo
Definition: spp.h:140
char * tag_pre
Definition: spp.h:134
char * multiline
Definition: spp.h:137
struct Tag ** tags
Definition: spp.h:130
char * token
Definition: spp.h:136
const char * name
Definition: spp.h:129
PUT_CALLBACK((*fputs))
int chop
Definition: spp.h:138
int tag_begin
Definition: spp.h:139
char * tag_post
Definition: spp.h:135
struct Arg ** args
Definition: spp.h:131
Definition: spp.h:104
int lbuf_s
Definition: spp.h:106
int lbuf_n
Definition: spp.h:107
char * lbuf
Definition: spp.h:105
Definition: spp.h:98
int ifl
Definition: spp.h:101
int echo[MAXIFL]
Definition: spp.h:100
int lineno
Definition: spp.h:99
Definition: spp.h:116
const char * name
Definition: spp.h:117
TAG_CALLBACK((*callback))
Definition: gzappend.c:170
Definition: spp.h:84
int len
Definition: spp.h:85
char * ptr
Definition: spp.h:86
int ptrlen
Definition: spp.h:87
Definition: spp.h:145
SppProc * proc
Definition: spp.h:146
Output * out
Definition: spp.h:147
struct Proc * proc
#define fail(test)
Definition: tests.h:29
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)