Rizin
unix-like reverse engineering framework and cli tools
cpp.h File Reference

Go to the source code of this file.

Classes

struct  cpp_macro_t
 

Functions

static TAG_CALLBACK (cpp_default)
 
static TAG_CALLBACK (cpp_error)
 
static TAG_CALLBACK (cpp_warning)
 
static TAG_CALLBACK (cpp_if)
 
static TAG_CALLBACK (cpp_ifdef)
 
static TAG_CALLBACK (cpp_else)
 
static TAG_CALLBACK (cpp_ifndef)
 
static void cpp_macro_add (char *name, char *args, char *body)
 
static PUT_CALLBACK (cpp_fputs)
 
static TAG_CALLBACK (cpp_define)
 
static TAG_CALLBACK (cpp_endif)
 
static TAG_CALLBACK (cpp_include)
 
static ARG_CALLBACK (cpp_arg_i)
 
static ARG_CALLBACK (cpp_arg_d)
 

Variables

static struct cpp_macro_t cpp_macros [10]
 
static int cpp_macros_n = 0
 
DLL_LOCAL struct Tag cpp_tags []
 
static struct Arg cpp_args []
 
DLL_LOCAL struct Proc cpp_proc
 

Function Documentation

◆ ARG_CALLBACK() [1/2]

static ARG_CALLBACK ( cpp_arg_d  )
static

Definition at line 145 of file cpp.h.

145  {
146  // TODO: handle rz_sys_setenv==-1
147  char *eq = strchr (arg, '=');
148  if (eq) {
149  *eq = '\0';
150  rz_sys_setenv (arg, eq + 1);
151  } else {
152  rz_sys_setenv (arg, "");
153  }
154  return 0;
155 }
RZ_API int rz_sys_setenv(const char *key, const char *value)
Set an environment variable in the calling process.
Definition: sys.c:405

References eq, and rz_sys_setenv().

◆ ARG_CALLBACK() [2/2]

static ARG_CALLBACK ( cpp_arg_i  )
static

Definition at line 140 of file cpp.h.

140  {
141  printf("INCLUDEDIR(%s)\n", arg);
142  return 0;
143 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93

References printf().

◆ cpp_macro_add()

static void cpp_macro_add ( char *  name,
char *  args,
char *  body 
)
static

Definition at line 63 of file cpp.h.

63  {
64  char *ptr;
67  ptr = strchr (name, '(');
68  if (ptr) {
69  ptr[1] = '\0';
70  }
72  cpp_macros_n++;
73 }
static struct cpp_macro_t cpp_macros[10]
static int cpp_macros_n
Definition: cpp.h:61
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")
int args
Definition: mipsasm.c:18
char * body
Definition: cpp.h:58
char * args
Definition: cpp.h:57
char * name
Definition: cpp.h:56
Definition: z80asm.h:102

References args, cpp_macro_t::args, cpp_macro_t::body, cpp_macros, cpp_macros_n, cpp_macro_t::name, and strdup().

Referenced by TAG_CALLBACK().

◆ PUT_CALLBACK()

static PUT_CALLBACK ( cpp_fputs  )
static

Definition at line 75 of file cpp.h.

75  {
76  int i;
77  for (i = 0; i < cpp_macros_n; i++) {
78  if (strstr(buf, cpp_macros[i].name)) {
79  fprintf (stderr, "MACRO (%s) HIT\n",
80  cpp_macros[i].name);
81  }
82  }
83  out_printf (out, "%s", buf);
84  return 0;
85 }
lzma_index ** i
Definition: index.h:629
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
voidpf void * buf
Definition: ioapi.h:138
void out_printf(Output *out, char *str,...) __attribute__((format(printf

References cpp_macros, cpp_macros_n, i, out, and out_printf().

◆ TAG_CALLBACK() [1/10]

static TAG_CALLBACK ( cpp_default  )
static

Definition at line 3 of file cpp.h.

3  {
4  out_printf (out, "DEFAULT: (%s)\n", buf);
5  return 0;
6 }

References out, and out_printf().

◆ TAG_CALLBACK() [2/10]

static TAG_CALLBACK ( cpp_define  )
static

Definition at line 87 of file cpp.h.

87  {
88  char *eq = strchr (buf, ' ');
89  if (eq) {
90  char *ptr = eq + 1;
91  char *macro = strchr(buf, '(');
92  *eq = '\0';
93  if (macro) {
94  /*macro[0]='\0'; */
95  ptr = strchr (macro + 1, ')');
96  if (!ptr) {
97  fprintf(stderr, "Invalid syntax\n");
98  return 1;
99  }
100  ptr = ptr + 1;
101  fprintf(stderr, "REGISTER MACRO:\n");
102  fprintf(stderr, " name: %s\n", buf);
103  fprintf(stderr, " args: %s\n", macro);
104  fprintf(stderr, " body: %s\n", ptr+1);
105  cpp_macro_add(buf,macro,ptr+1);
106  /* TODO: Name is "BUF(". for funny strstr */
107  }
108  rz_sys_setenv (buf, ptr);
109  } else rz_sys_setenv (buf, "");
110  return 0;
111 }
static void cpp_macro_add(char *name, char *args, char *body)
Definition: cpp.h:63
Definition: z80asm.h:130

References cpp_macro_add(), eq, and rz_sys_setenv().

◆ TAG_CALLBACK() [3/10]

static TAG_CALLBACK ( cpp_else  )
static

Definition at line 44 of file cpp.h.

44  {
45  state->echo[state->ifl] = state->echo[state->ifl]? 0: 1;
46  return 0;
47 }
Definition: dis.h:43

◆ TAG_CALLBACK() [4/10]

static TAG_CALLBACK ( cpp_endif  )
static

Definition at line 113 of file cpp.h.

113  {
114  return -1;
115 }

◆ TAG_CALLBACK() [5/10]

static TAG_CALLBACK ( cpp_error  )
static

Definition at line 8 of file cpp.h.

8  {
9  out_printf (out, "\n");
10  if (state->echo[state->ifl] && buf) {
11  out_printf (out, "ERROR: %s (line=%d)\n", buf, state->lineno);
12  return -1;
13  }
14  return 0;
15 }

References out, and out_printf().

◆ TAG_CALLBACK() [6/10]

static TAG_CALLBACK ( cpp_if  )
static

Definition at line 25 of file cpp.h.

25  {
26  char *var = getenv (buf + ((*buf == '!') ? 1 : 0));
27  if (var && *var == '1') {
28  state->echo[state->ifl + 1] = 1;
29  } else {
30  state->echo[state->ifl + 1] = 0;
31  }
32  if (*buf == '!') {
33  state->echo[state->ifl + 1] = !!!state->echo[state->ifl + 1];
34  }
35  return 1;
36 }
char * getenv()

References getenv().

◆ TAG_CALLBACK() [7/10]

static TAG_CALLBACK ( cpp_ifdef  )
static

Definition at line 38 of file cpp.h.

38  {
39  char *var = getenv (buf);
40  state->echo[state->ifl + 1] = var? 1: 0;
41  return 1;
42 }

References getenv().

◆ TAG_CALLBACK() [8/10]

static TAG_CALLBACK ( cpp_ifndef  )
static

Definition at line 49 of file cpp.h.

49  {
50  cpp_ifdef (state, out, buf);
51  cpp_else (state, out, buf);
52  return 1;
53 }

References out.

◆ TAG_CALLBACK() [9/10]

static TAG_CALLBACK ( cpp_include  )
static

Definition at line 117 of file cpp.h.

117  {
118  if (state->echo[state->ifl]) {
119  spp_file (buf, out);
120  }
121  return 0;
122 }
S_API int spp_file(const char *file, Output *out)
Definition: spp.c:272

References out, and spp_file().

◆ TAG_CALLBACK() [10/10]

static TAG_CALLBACK ( cpp_warning  )
static

Definition at line 17 of file cpp.h.

17  {
18  out_printf (out,"\n");
19  if (state->echo[state->ifl] && buf != NULL) {
20  out_printf (out, "WARNING: line %d: %s\n", state->lineno, buf);
21  }
22  return 0;
23 }
#define NULL
Definition: cris-opc.c:27

References NULL, out, and out_printf().

Variable Documentation

◆ cpp_args

struct Arg cpp_args[]
static
Initial value:
= {
{ "-I", "add include directory", 1, cpp_arg_i },
{ "-D", "define value of variable", 1, cpp_arg_d },
{ NULL }
}

Definition at line 145 of file cpp.h.

◆ cpp_macros

struct cpp_macro_t cpp_macros[10]
static

Referenced by cpp_macro_add(), and PUT_CALLBACK().

◆ cpp_macros_n

int cpp_macros_n = 0
static

Definition at line 61 of file cpp.h.

Referenced by cpp_macro_add(), and PUT_CALLBACK().

◆ cpp_proc

DLL_LOCAL struct Proc cpp_proc
Initial value:
= {
.name = "cpp",
.tags = (struct Tag **)cpp_tags,
.args = (struct Arg **)cpp_args,
.token = " ",
.eof = NULL,
.tag_pre = "#",
.tag_post = "\n",
.multiline = "\\\n",
.default_echo = 1,
.fputs = cpp_fputs,
.chop = 0,
.tag_begin = 1,
}
static struct Arg cpp_args[]
Definition: cpp.h:157
DLL_LOCAL struct Tag cpp_tags[]
Definition: cpp.h:124
Definition: spp.h:121
Definition: spp.h:116

Definition at line 163 of file cpp.h.

◆ cpp_tags

DLL_LOCAL struct Tag cpp_tags[]
Initial value:
= {
{ "ifdef", cpp_ifdef },
{ "ifndef", cpp_ifndef },
{ "endif", cpp_endif },
{ "if", cpp_if },
{ "else", cpp_else },
{ "include", cpp_include },
{ "define", cpp_define },
{ "error", cpp_error },
{ "warning", cpp_warning },
{ NULL, cpp_default },
{ NULL }
}

Definition at line 124 of file cpp.h.