Skip to content

Commit

Permalink
Fix #8653 - Fix spp build for iOS and enhance ios-sdk.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Oct 8, 2017
1 parent 637543c commit 5db2e67
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 180 deletions.
1 change: 1 addition & 0 deletions config-user.mk.acr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ INCLUDEDIR=@INCLUDEDIR@
HAVE_LIB_GMP=@HAVE_LIB_GMP@
USE_RPATH=@USE_RPATH@
HAVE_JEMALLOC=@HAVE_JEMALLOC@
HAVE_FORK=@HAVE_FORK@

MKPLUGINS=mk/stat.mk mk/sloc.mk

Expand Down
2 changes: 1 addition & 1 deletion shlr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,6 @@ spp-sync sync-spp:
git add spp

spp: spp-sync
CFLAGS=-fPIC $(MAKE) -C spp
CFLAGS="-DHAVE_FORK=${HAVE_FORK} -fPIC" $(MAKE) -C spp

.PHONY: spp
8 changes: 4 additions & 4 deletions shlr/spp/config.def.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#if !TARGET_OS_IPHONE
#include "p/sh.h"
#endif
#include "p/spp.h"
#include "p/acr.h"
#include "p/pod.h"
#include "p/cpp.h"

#ifdef HAVE_FORK
#define HAVE_FORK 1
#endif

struct Proc *procs[] = {
&spp_proc,
&cpp_proc,
&pod_proc,
&acr_proc,
#if !TARGET_OS_IPHONE
&sh_proc,
#endif
NULL
};

Expand Down
2 changes: 1 addition & 1 deletion shlr/spp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int main(int argc, char **argv) {
}

if (proc->eof)
proc->eof ("", &out);
proc->eof (&proc->state, "", &out);
if (out.fout) {
fclose (out.fout);
}
Expand Down
24 changes: 12 additions & 12 deletions shlr/spp/p/cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ static TAG_CALLBACK(cpp_default) {

static TAG_CALLBACK(cpp_error) {
do_printf (out,"\n");
if (echo[ifl] && buf != NULL) {
do_printf (out, "ERROR: %s (line=%d)\n", buf, lineno);
if (state->echo[state->ifl] && buf != NULL) {
do_printf (out, "ERROR: %s (line=%d)\n", buf, state->lineno);
return -1;
}
return 0;
}

static TAG_CALLBACK(cpp_warning) {
do_printf (out,"\n");
if (echo[ifl] && buf != NULL) {
do_printf (out, "WARNING: line %d: %s\n", lineno, buf);
if (state->echo[state->ifl] && buf != NULL) {
do_printf (out, "WARNING: line %d: %s\n", state->lineno, buf);
}
return 0;
}

static TAG_CALLBACK(cpp_if) {
char *var = getenv (buf + ((*buf == '!') ? 1 : 0));
if (var && *var=='1')
echo[ifl + 1] = 1;
else echo[ifl + 1] = 0;
if (*buf=='!') echo[ifl+1] = !!!echo[ifl+1];
state->echo[state->ifl + 1] = 1;
else state->echo[state->ifl + 1] = 0;
if (*buf=='!') state->echo[state->ifl + 1] = !!!state->echo[state->ifl + 1];
return 1;
}

static TAG_CALLBACK(cpp_ifdef) {
char *var = getenv (buf);
echo[ifl + 1] = var? 1: 0;
state->echo[state->ifl + 1] = var? 1: 0;
return 1;
}

static TAG_CALLBACK(cpp_else) {
echo[ifl] = echo[ifl]? 0: 1;
state->echo[state->ifl] = state->echo[state->ifl]? 0: 1;
return 0;
}

static TAG_CALLBACK(cpp_ifndef) {
cpp_ifdef (buf, out);
cpp_else (buf, out);
cpp_ifdef (state, buf, out);
cpp_else (state, buf, out);
return 1;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ static TAG_CALLBACK(cpp_endif) {
}

static TAG_CALLBACK(cpp_include) {
if (echo[ifl]) {
if (state->echo[state->ifl]) {
spp_file (buf, out);
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions shlr/spp/p/pod.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ static TAG_CALLBACK(pod_default) {

static TAG_CALLBACK(pod_cut) {
do_printf (out, "\n");
echo[ifl] = 0;
state->echo[state->ifl] = 0;
return 0;
}

static TAG_CALLBACK(pod_head1) {
echo[ifl] = 1;
state->echo[state->ifl] = 1;
do_printf (out, "\n");
if (!buf) {
return 0;
Expand Down
6 changes: 5 additions & 1 deletion shlr/spp/p/sh.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ static TAG_CALLBACK(sh_default) {
// printf("system(%s)\n", buf);
if (eof)
#endif
system(buf);
#if HAVE_FORK
system (buf);
#endif
return 0;
}

Expand All @@ -49,7 +51,9 @@ static PUT_CALLBACK(sh_fputs) {
if (sh_pipe_enabled) {
char str[1024]; // XXX
sprintf (str, "echo '%s' | %s", buf, sh_pipe_cmd); // XXX
#if HAVE_FORK
system (str);
#endif
} else {
do_printf (out, "%s", buf);
}
Expand Down
68 changes: 36 additions & 32 deletions shlr/spp/p/spp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static char *cmd_to_str(const char *cmd) {

static TAG_CALLBACK(spp_set) {
char *eq, *val = "";
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
for (eq=buf; eq[0]; eq++) {
Expand All @@ -50,14 +50,14 @@ static TAG_CALLBACK(spp_set) {
val = eq + 1;
}
if (spp_var_set (buf, val) == -1) {
fprintf (stderr, "Invalid variable name '%s' at line %d\n", buf, lineno);
fprintf (stderr, "Invalid variable name '%s' at line %d\n", buf, state->lineno);
}
return 0;
}

static TAG_CALLBACK(spp_get) {
char *var;
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
var = spp_var_get (buf);
Expand All @@ -69,7 +69,7 @@ static TAG_CALLBACK(spp_get) {

static TAG_CALLBACK(spp_getrandom) {
int max;
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
// XXX srsly? this is pretty bad random
Expand All @@ -86,7 +86,7 @@ static TAG_CALLBACK(spp_add) {
char res[32];
char *var, *eq = strchr (buf, ' ');
int ret = 0;
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
if (eq) {
Expand All @@ -108,7 +108,7 @@ static TAG_CALLBACK(spp_sub) {
char *eq = strchr(buf, ' ');
char *var;
int ret = 0;
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
if (eq) {
Expand All @@ -125,39 +125,43 @@ static TAG_CALLBACK(spp_sub) {

// XXX This method needs some love
static TAG_CALLBACK(spp_trace) {
if (echo[ifl]) {
fprintf (stderr, "%s\n", buf);
#if HAVE_FORK
char b[1024];
if (!state->echo[state->ifl]) {
return 0;
}
snprintf(b, 1023, "echo '%s' >&2 ", buf);
system(b);
#endif
return 0;
}

/* TODO: deprecate */
static TAG_CALLBACK(spp_echo) {
if (echo[ifl]) {
do_printf (out, "%s", buf);
}
if (!state->echo[state->ifl]) return 0;
do_printf (out, "%s", buf);
// TODO: add variable replacement here?? not necessary, done by {{get}}
return 0;
}

static TAG_CALLBACK(spp_error) {
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
fprintf (stderr, "ERROR: %s (line=%d)\n", buf, lineno);
fprintf (stderr, "ERROR: %s (line=%d)\n", buf, state->lineno);
return -1;
}

static TAG_CALLBACK(spp_warning) {
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
fprintf (stderr, "WARNING: %s (line=%d)\n", buf, lineno);
fprintf (stderr, "WARNING: %s (line=%d)\n", buf, state->lineno);
return 0;
}

static TAG_CALLBACK(spp_system) {
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
char *str = cmd_to_str (buf);
Expand All @@ -168,7 +172,7 @@ static TAG_CALLBACK(spp_system) {

static TAG_CALLBACK(spp_include) {
char *incdir;
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
incdir = getenv("SPP_INCDIR");
Expand All @@ -190,7 +194,7 @@ static TAG_CALLBACK(spp_include) {

static TAG_CALLBACK(spp_if) {
char *var = spp_var_get(buf);
echo[ifl + 1] = (var && *var != '0' && *var != '\0') ? 1 : 0;
state->echo[state->ifl + 1] = (var && *var != '0' && *var != '\0') ? 1 : 0;
return 1;
}

Expand All @@ -202,14 +206,14 @@ static TAG_CALLBACK(spp_ifeq) {
*eq = '\0';
value = spp_var_get(value);
if (value && !strcmp(value, eq+1)) {
echo[ifl+1] = 1;
} else echo[ifl+1] = 0;
state->echo[state->ifl + 1] = 1;
} else state->echo[state->ifl + 1] = 0;
//fprintf(stderr, "IFEQ(%s)(%s)=%d\n", buf, eq+1, echo[ifl]);
} else {
value = spp_var_get(buf);
if (!value || *value=='\0')
echo[ifl+1] = 1;
else echo[ifl+1] = 0;
state->echo[state->ifl + 1] = 1;
else state->echo[state->ifl + 1] = 0;
//fprintf(stderr, "IFEQ(%s)(%s)=%d\n", buf, value, echo[ifl]);
}
return 1;
Expand Down Expand Up @@ -238,7 +242,7 @@ static TAG_CALLBACK(spp_grepline) {
char *ptr;
int line;

if (!echo[ifl]) return 1;
if (!state->echo[state->ifl]) return 1;
ptr = strchr(buf, ' ');
if (ptr) {
*ptr= '\0';
Expand All @@ -257,28 +261,28 @@ static TAG_CALLBACK(spp_grepline) {
}

static TAG_CALLBACK(spp_else) {
echo[ifl] = echo[ifl] ? 0 : 1;
state->echo[state->ifl] = state->echo[state->ifl] ? 0 : 1;
return 0;
}

static TAG_CALLBACK(spp_ifnot) {
spp_if (buf, out);
spp_else (buf, out);
spp_if (state, buf, out);
spp_else (state, buf, out);
return 1;
}

static TAG_CALLBACK(spp_ifin) {
char *var, *ptr;
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 1;
}
ptr = strchr (buf, ' ');
echo[ifl + 1] = 0;
state->echo[state->ifl + 1] = 0;
if (ptr) {
*ptr='\0';
var = getenv(buf);
if (strstr (ptr + 1, var)) {
echo[ifl + 1] = 1;
state->echo[state->ifl + 1] = 1;
}
}
return 1;
Expand All @@ -289,11 +293,11 @@ static TAG_CALLBACK(spp_endif) {
}

static TAG_CALLBACK(spp_default) {
if (!echo[ifl]) {
if (!state->echo[state->ifl]) {
return 0;
}
if (buf[-1] != ';') { /* commented tag */
fprintf (stderr, "WARNING: invalid command: '%s' at line %d\n", buf, lineno);
fprintf (stderr, "WARNING: invalid command: '%s' at line %d\n", buf, state->lineno);
}
return 0;
}
Expand All @@ -318,7 +322,7 @@ static TAG_CALLBACK(spp_switch) {
}

static TAG_CALLBACK(spp_case) {
echo[ifl] = strcmp (buf, spp_switch_str)?0:1;
state->echo[state->ifl] = strcmp (buf, spp_switch_str)?0:1;
return 0;
}

Expand Down
2 changes: 0 additions & 2 deletions shlr/spp/r_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#include <windows.h>
#endif
#if __WIN32__ || MINGW32 && !__CYGWIN__
#ifndef _MSC_VER
#include <winsock.h>
#endif
typedef int socklen_t;
#undef USE_SOCKETS
#define __WINDOWS__ 1
Expand Down
Loading

0 comments on commit 5db2e67

Please sign in to comment.