From e04f31a31329354b3bddfc72ac259280c0c719d0 Mon Sep 17 00:00:00 2001 From: radare Date: Tue, 19 Mar 2019 17:34:02 +0100 Subject: [PATCH] Completely kill the msvc/ directory and the unix-specific includes workarounds --- libr/asm/arch/xap/dis.c | 2 - libr/asm/arch/z80/z80asm.h | 2 - libr/cons/pipe.c | 3 +- libr/cons/utf8.c | 2 +- libr/include/msvc/getopt.h | 74 ------------------------------ libr/include/msvc/sys/time.h | 1 - libr/include/msvc/unistd.h | 2 - libr/include/r_cons.h | 3 +- libr/include/r_getopt.h | 1 - libr/include/r_io.h | 1 - libr/include/r_util/r_cache.h | 2 - libr/io/p/io_gprobe.c | 3 +- libr/magic/ascmagic.c | 3 -- libr/magic/fsmagic.c | 3 -- libr/magic/magic.c | 9 ---- libr/magic/print.c | 3 -- libr/search/bytepat.c | 12 ++--- libr/search/old_xrefs.c | 1 - libr/socket/run.c | 1 - libr/socket/socket.c | 8 ---- libr/util/calc.c | 1 - libr/util/chmod.c | 3 +- libr/util/file.c | 3 +- libr/util/sys.c | 1 - libr/util/ubase64.c | 5 --- meson.build | 1 - shlr/java/class.c | 1 - shlr/meson.build | 3 -- shlr/qnx/include/core.h | 2 + shlr/qnx/include/packet.h | 3 +- shlr/spp/main.c | 1 + shlr/spp/meson.build | 46 +++++++++++++++++++ shlr/spp/p/cpp.h | 16 ++++--- shlr/spp/p/pod.h | 12 ++--- shlr/spp/p/sh.h | 12 +++-- shlr/spp/p/spp.h | 18 ++++---- shlr/spp/r_api.c | 27 +++++------ shlr/spp/r_api.h | 84 +++++++--------------------------- shlr/spp/spp.c | 54 +++++++++++----------- shlr/spp/spp.h | 85 ++++++++++++++++++++++++----------- shlr/zip/zip/zip_close.c | 5 +-- shlr/zip/zip/zip_fdopen.c | 1 - shlr/zip/zlib/gzguts.h | 3 +- shlr/zip/zlib/gzread.c | 1 - shlr/zip/zlib/zconf.h | 2 + sys/meson.py | 1 - sys/msvc.sh | 3 -- 47 files changed, 220 insertions(+), 310 deletions(-) delete mode 100644 libr/include/msvc/getopt.h delete mode 100644 libr/include/msvc/sys/time.h delete mode 100644 libr/include/msvc/unistd.h create mode 100644 shlr/spp/meson.build diff --git a/libr/asm/arch/xap/dis.c b/libr/asm/arch/xap/dis.c index 570694b7a8..733ddd5df2 100644 --- a/libr/asm/arch/xap/dis.c +++ b/libr/asm/arch/xap/dis.c @@ -3,8 +3,6 @@ #include #include #include -#include -//#include #include #define assert(x) if (!(x)) { eprintf("assert ##x##\n"); return; } #include diff --git a/libr/asm/arch/z80/z80asm.h b/libr/asm/arch/z80/z80asm.h index b50c782312..cfea1de077 100644 --- a/libr/asm/arch/z80/z80asm.h +++ b/libr/asm/arch/z80/z80asm.h @@ -28,8 +28,6 @@ #include #include #include -//#include -#include /* defines which are not function-specific */ #ifndef BUFLEN diff --git a/libr/cons/pipe.c b/libr/cons/pipe.c index 11fb574af7..4d977162be 100644 --- a/libr/cons/pipe.c +++ b/libr/cons/pipe.c @@ -1,7 +1,6 @@ -/* radare - LGPL - Copyright 2009-2016 - pancake */ +/* radare - LGPL - Copyright 2009-2019 - pancake */ #include -#include #include //TODO: cons_pipe should be using a stack pipe_push, pipe_pop diff --git a/libr/cons/utf8.c b/libr/cons/utf8.c index e8387951c0..048440afcc 100644 --- a/libr/cons/utf8.c +++ b/libr/cons/utf8.c @@ -2,9 +2,9 @@ // Copypasta from http://www.linuxquestions.org/questions/programming-9/get-cursor-position-in-c-947833/ #include + #if __UNIX__ #include -#include #include #include #include diff --git a/libr/include/msvc/getopt.h b/libr/include/msvc/getopt.h deleted file mode 100644 index e172d6f14c..0000000000 --- a/libr/include/msvc/getopt.h +++ /dev/null @@ -1,74 +0,0 @@ -#if 0 -// XXX dupe in libr/util/getopt.c - -#include -#include - -int opterr = 1, /* if error message should be printed */ -optind = 1, /* index into parent argv vector */ -optopt, /* character checked for validity */ -optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -/* - * getopt -- - * Parse argc/argv argument vector. - */ -int getopt (int nargc, char * const nargv[], const char *ostr) { - static char *place = EMSG; /* option letter processing */ - const char *oli; /* option letter list index */ - - if (optreset || !*place) { /* update scanning pointer */ - optreset = 0; - if (optind >= nargc || *(place = nargv[optind]) != '-') { - place = EMSG; - return (-1); - } - if (place[1] && *++place == '-') { /* found "--" */ - ++optind; - place = EMSG; - return (-1); - } - } /* option letter okay? */ - if ((optopt = (int)*place++) == (int)':' || - !(oli = strchr (ostr, optopt))) { - /* - * if the user didn't specify '-' as an option, - * assume it means -1. - */ - if (optopt == (int)'-') - return (-1); - if (!*place) - ++optind; - if (opterr && *ostr != ':') - (void)printf ("illegal option -- %c\n", optopt); - return (BADCH); - } - if (*++oli != ':') { /* don't need argument */ - optarg = NULL; - if (!*place) - ++optind; - } - else { /* need an argument */ - if (*place) /* no white space */ - optarg = place; - else if (nargc <= ++optind) { /* no arg */ - place = EMSG; - if (*ostr == ':') - return (BADARG); - if (opterr) - (void)printf ("option requires an argument -- %c\n", optopt); - return (BADCH); - } - else /* white space */ - optarg = nargv[optind]; - place = EMSG; - ++optind; - } - return (optopt); /* dump back option letter */ -} -#endif diff --git a/libr/include/msvc/sys/time.h b/libr/include/msvc/sys/time.h deleted file mode 100644 index c8572f78c4..0000000000 --- a/libr/include/msvc/sys/time.h +++ /dev/null @@ -1 +0,0 @@ -// fake file to build under msvc windows \ No newline at end of file diff --git a/libr/include/msvc/unistd.h b/libr/include/msvc/unistd.h deleted file mode 100644 index b74d84355b..0000000000 --- a/libr/include/msvc/unistd.h +++ /dev/null @@ -1,2 +0,0 @@ -//fake include file to avoid error on windows compilation. -#include diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index f98fca63f8..418c70a810 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -33,8 +33,9 @@ extern "C" { #if __WINDOWS__ #include #include -#endif +#else #include +#endif /* constants */ #define CONS_MAX_USER 102400 diff --git a/libr/include/r_getopt.h b/libr/include/r_getopt.h index 52f37e0c7c..5ef9d2f87f 100644 --- a/libr/include/r_getopt.h +++ b/libr/include/r_getopt.h @@ -8,7 +8,6 @@ of getopt to work on any operating system independently of the libc Duplicated code in here: * libr/util/getopt.c -* libr/include/msvc/getopt.h */ diff --git a/libr/include/r_io.h b/libr/include/r_io.h index 05eb2a98d9..444d5987e0 100644 --- a/libr/include/r_io.h +++ b/libr/include/r_io.h @@ -17,7 +17,6 @@ #if HAVE_PTRACE #if __sun -#include #include #else #if DEBUGGER && HAVE_PTRACE diff --git a/libr/include/r_util/r_cache.h b/libr/include/r_util/r_cache.h index b8b6bb7b7f..3cb69daa0a 100644 --- a/libr/include/r_util/r_cache.h +++ b/libr/include/r_util/r_cache.h @@ -5,8 +5,6 @@ extern "C" { #endif -#include - typedef struct r_cache_t { ut64 base; ut8 *buf; diff --git a/libr/io/p/io_gprobe.c b/libr/io/p/io_gprobe.c index e48442a928..df151f2239 100644 --- a/libr/io/p/io_gprobe.c +++ b/libr/io/p/io_gprobe.c @@ -5,9 +5,10 @@ #include #include +#if __UNIX__ #include #include -#include +#endif #define USE_OWNTIMER 1 #if USE_OWNTIMER diff --git a/libr/magic/ascmagic.c b/libr/magic/ascmagic.c index f8be96dc1c..259f5e9a12 100644 --- a/libr/magic/ascmagic.c +++ b/libr/magic/ascmagic.c @@ -46,9 +46,6 @@ #include #include #include -#ifdef HAVE_UNISTD_H -#include -#endif #include "names.h" #define MAXLINELEN 300 /* longest sane line length */ diff --git a/libr/magic/fsmagic.c b/libr/magic/fsmagic.c index de83e31248..551a4dc375 100644 --- a/libr/magic/fsmagic.c +++ b/libr/magic/fsmagic.c @@ -37,9 +37,6 @@ #include #include "file.h" #include -#ifdef HAVE_UNISTD_H -#include -#endif #include #include /* Since major is a function on SVR4, we cannot use `ifndef major'. */ diff --git a/libr/magic/magic.c b/libr/magic/magic.c index c1bcad46da..a12389542f 100644 --- a/libr/magic/magic.c +++ b/libr/magic/magic.c @@ -94,11 +94,6 @@ R_API int r_magic_errno(RMagic* m) { #else -#include -#include -#include -#include -#include #ifndef _MSC_VER #include /* for MAXPATHLEN */ #endif @@ -114,10 +109,6 @@ R_LIB_VERSION (r_magic); #endif #include /* for PIPE_BUF */ -#ifdef HAVE_UNISTD_H -#include /* for read() */ -#endif - #if __UNIX__ #include /* for byte swapping */ #else diff --git a/libr/magic/print.c b/libr/magic/print.c index 6129c051aa..6bbcebc352 100644 --- a/libr/magic/print.c +++ b/libr/magic/print.c @@ -39,9 +39,6 @@ #include #include #include -#ifdef HAVE_UNISTD_H -#include -#endif #include #define SZOF(a) (sizeof(a) / sizeof(a[0])) diff --git a/libr/search/bytepat.c b/libr/search/bytepat.c index 9d806b128b..d9457aaffb 100644 --- a/libr/search/bytepat.c +++ b/libr/search/bytepat.c @@ -1,12 +1,8 @@ -/* radare - LGPL - Copyright 2006-2018 - esteve, pancake */ +/* radare - LGPL - Copyright 2006-2019 - esteve, pancake */ -#include "r_search.h" -#include "r_util.h" -#include "r_util/r_print.h" - -#include -#include -#include +#include +#include +#include #define CTXMINB 5 #define BSIZE (1024*1024) diff --git a/libr/search/old_xrefs.c b/libr/search/old_xrefs.c index bcb5de8c08..fe0574f3fd 100644 --- a/libr/search/old_xrefs.c +++ b/libr/search/old_xrefs.c @@ -87,7 +87,6 @@ match value ffffffad (ffffad) at offset 0x454 #include #include #include -#include #include #include #include diff --git a/libr/socket/run.c b/libr/socket/run.c index 08b2e2349d..53a877dda8 100644 --- a/libr/socket/run.c +++ b/libr/socket/run.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/libr/socket/socket.c b/libr/socket/socket.c index 66de81367a..408bda1692 100644 --- a/libr/socket/socket.c +++ b/libr/socket/socket.c @@ -5,14 +5,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #if EMSCRIPTEN #define NETWORK_DISABLED 1 diff --git a/libr/util/calc.c b/libr/util/calc.c index d46b753896..397b8922ae 100644 --- a/libr/util/calc.c +++ b/libr/util/calc.c @@ -12,7 +12,6 @@ #include #include #include -#include /* accessors */ static inline RNumCalcValue Nset(ut64 v) { RNumCalcValue n; n.d = (double)v; n.n = v; return n; } diff --git a/libr/util/chmod.c b/libr/util/chmod.c index 33f49f1448..3e0cd5f2ff 100644 --- a/libr/util/chmod.c +++ b/libr/util/chmod.c @@ -1,10 +1,9 @@ -/* radare - LGPL - Copyright 2011-2012 - pancake */ +/* radare - LGPL - Copyright 2011-2019 - pancake */ #include #include #include #include -#include #include #if __UNIX__ diff --git a/libr/util/file.c b/libr/util/file.c index 8a835d581e..83a4029b12 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -3,14 +3,13 @@ #include "r_types.h" #include "r_util.h" #include -#include #include #include #include -#include #include #include #if __UNIX__ +#include #include #include #endif diff --git a/libr/util/sys.c b/libr/util/sys.c index 1094622293..536e21c5ce 100644 --- a/libr/util/sys.c +++ b/libr/util/sys.c @@ -56,7 +56,6 @@ int proc_pidpath(int pid, void * buffer, ut32 buffersize); # include # include # include -# include extern char **environ; #ifdef __HAIKU__ diff --git a/libr/util/ubase64.c b/libr/util/ubase64.c index f37f107d3a..765135d429 100644 --- a/libr/util/ubase64.c +++ b/libr/util/ubase64.c @@ -6,11 +6,6 @@ #include #include #include - -#if !defined(MINGW32) -#include -#endif - #include #define SZ 1024 diff --git a/meson.build b/meson.build index dc4d365c29..c2913f6e19 100644 --- a/meson.build +++ b/meson.build @@ -104,7 +104,6 @@ platform_deps = [] platform_inc = ['.', 'libr/include'] if host_machine.system() == 'windows' platform_deps = [cc.find_library('ws2_32')] - platform_inc += ['libr/include/msvc'] endif platform_inc = include_directories(platform_inc) diff --git a/shlr/java/class.c b/shlr/java/class.c index ffe52bb430..4d7b514531 100644 --- a/shlr/java/class.c +++ b/shlr/java/class.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/shlr/meson.build b/shlr/meson.build index 07e9130797..40b94e366e 100644 --- a/shlr/meson.build +++ b/shlr/meson.build @@ -182,15 +182,12 @@ sdb_dep = declare_dependency( include_directories: sdb_inc ) -sdb_platform_inc = [] - # Create sdb_version.h sdb_version = '1.2.0' run_command(py3_exe, '-c', 'with open("sdb/src/sdb_version.h", "w") as f: f.write("#define SDB_VERSION \"' + sdb_version + '\"")') sdb_exe = executable('sdb', 'sdb/src/main.c', include_directories: [ - sdb_platform_inc, include_directories(['sdb/src']) ], link_with: [libr2sdb], diff --git a/shlr/qnx/include/core.h b/shlr/qnx/include/core.h index 84a828ce4f..4aee53a22e 100644 --- a/shlr/qnx/include/core.h +++ b/shlr/qnx/include/core.h @@ -7,7 +7,9 @@ #include #include #include +#if __UNIX__ #include +#endif #include #include "libqnxr.h" diff --git a/shlr/qnx/include/packet.h b/shlr/qnx/include/packet.h index 630a932a45..939517fea4 100644 --- a/shlr/qnx/include/packet.h +++ b/shlr/qnx/include/packet.h @@ -3,7 +3,6 @@ #define PACKET_H #include -#include #include #include #include "libqnxr.h" @@ -13,6 +12,8 @@ #if !__CYGWIN__ && !defined(MSC_VER) #include #endif +#else +#include #endif int qnxr_send_nak (libqnxr_t *instance); diff --git a/shlr/spp/main.c b/shlr/spp/main.c index 78140b461a..210b72de06 100644 --- a/shlr/spp/main.c +++ b/shlr/spp/main.c @@ -1,6 +1,7 @@ /* MIT (C) pancake (at) nopcode (dot) org */ #include "spp.h" +#include "r_api.h" extern struct Proc *procs[]; extern struct Proc *proc; diff --git a/shlr/spp/meson.build b/shlr/spp/meson.build new file mode 100644 index 0000000000..04f78bbfb8 --- /dev/null +++ b/shlr/spp/meson.build @@ -0,0 +1,46 @@ +project('spp', 'c') +spp_version = '1.0.0' + +configure_file(input: 'config.def.h', + output: 'config.h', + copy: true) + +spp_files = [ + 'spp.c', + 's_api.c' +] + +libspp_static = static_library('spp', spp_files, + install: not meson.is_subproject() +) + +libspp = shared_library('spp', spp_files, + install: not meson.is_subproject(), + soversion: spp_version +) + +spp_static_dep = declare_dependency( + link_with: libspp_static, +) + +spp_dep = declare_dependency( + link_with: libspp +) + +pkgconfig_mod = import('pkgconfig') +pkgconfig_mod.generate(libspp, + version: spp_version, + name: 'spp', + subdirs: ['.'], + filebase: 'spp', + description: 'spp library' +) + +if not meson.is_subproject() + install_headers('spp.h') + + spp_exe = executable('spp', ['main.c'], + dependencies: spp_dep, + install: true + ) +endif diff --git a/shlr/spp/p/cpp.h b/shlr/spp/p/cpp.h index 3286de807a..14f2b60a98 100644 --- a/shlr/spp/p/cpp.h +++ b/shlr/spp/p/cpp.h @@ -1,23 +1,23 @@ /* CPP */ static TAG_CALLBACK(cpp_default) { - do_printf (out, "DEFAULT: (%s)\n", buf); + out_printf (out, "DEFAULT: (%s)\n", buf); return 0; } static TAG_CALLBACK(cpp_error) { - do_printf (out, "\n"); + out_printf (out, "\n"); if (state->echo[state->ifl] && buf) { - do_printf (out, "ERROR: %s (line=%d)\n", buf, state->lineno); + out_printf (out, "ERROR: %s (line=%d)\n", buf, state->lineno); return -1; } return 0; } static TAG_CALLBACK(cpp_warning) { - do_printf (out,"\n"); + out_printf (out,"\n"); if (state->echo[state->ifl] && buf != NULL) { - do_printf (out, "WARNING: line %d: %s\n", state->lineno, buf); + out_printf (out, "WARNING: line %d: %s\n", state->lineno, buf); } return 0; } @@ -80,7 +80,7 @@ static PUT_CALLBACK(cpp_fputs) { cpp_macros[i].name); } } - do_printf (out, "%s", buf); + out_printf (out, "%s", buf); return 0; } @@ -148,7 +148,9 @@ static ARG_CALLBACK(cpp_arg_d) { if (eq) { *eq = '\0'; r_sys_setenv (arg, eq + 1); - } else r_sys_setenv (arg, ""); + } else { + r_sys_setenv (arg, ""); + } return 0; } diff --git a/shlr/spp/p/pod.h b/shlr/spp/p/pod.h index e1b42536ae..fc6c03bc82 100644 --- a/shlr/spp/p/pod.h +++ b/shlr/spp/p/pod.h @@ -1,28 +1,28 @@ /* CPP */ static TAG_CALLBACK(pod_default) { - do_printf (out, "DEFAULT: (%s)\n", buf); + out_printf (out, "DEFAULT: (%s)\n", buf); return 0; } static TAG_CALLBACK(pod_cut) { - do_printf (out, "\n"); + out_printf (out, "\n"); state->echo[state->ifl] = 0; return 0; } static TAG_CALLBACK(pod_head1) { state->echo[state->ifl] = 1; - do_printf (out, "\n"); + out_printf (out, "\n"); if (!buf) { return 0; } - do_printf (out, "%s\n", buf); + out_printf (out, "%s\n", buf); int i, len = strlen (buf); for (i = 0; i < len; i++) { - do_printf (out, "%c", '='); + out_printf (out, "%c", '='); } - do_printf (out, "\n"); + out_printf (out, "\n"); return 0; } diff --git a/shlr/spp/p/sh.h b/shlr/spp/p/sh.h index 26bf1e0f6e..e8e7f0d636 100644 --- a/shlr/spp/p/sh.h +++ b/shlr/spp/p/sh.h @@ -25,7 +25,10 @@ static TAG_CALLBACK(sh_default) { if (eof) #endif #if HAVE_FORK - system (buf); + int r = system (buf); + if (errno) { + printf ("system '%s' (%d) failed: %s\n", buf, r, strerror (errno)); + } #endif return 0; } @@ -52,10 +55,13 @@ static PUT_CALLBACK(sh_fputs) { char str[1024]; // XXX sprintf (str, "echo '%s' | %s", buf, sh_pipe_cmd); // XXX #if HAVE_FORK - system (str); + int r = system (str); + if (errno) { + printf ("system '%s' (%d) failed: %s\n", str, r, strerror (errno)); + } #endif } else { - do_printf (out, "%s", buf); + out_printf (out, "%s", buf); } return 0; } diff --git a/shlr/spp/p/spp.h b/shlr/spp/p/spp.h index e6f10ddf2e..265dd84f06 100644 --- a/shlr/spp/p/spp.h +++ b/shlr/spp/p/spp.h @@ -1,6 +1,8 @@ /* Mini MCMS :: renamed to 'spp'? */ +#if __UNIX__ #include +#endif static char *spp_var_get(char *var) { return getenv(var); @@ -74,7 +76,7 @@ static TAG_CALLBACK(spp_get) { } var = spp_var_get (buf); if (var) { - do_printf (out, "%s", var); + out_printf (out, "%s", var); } return 0; } @@ -90,7 +92,7 @@ static TAG_CALLBACK(spp_getrandom) { if (max > 0) { max = (int)(rand () % max); } - do_printf (out, "%d", max); + out_printf (out, "%d", max); return 0; } @@ -145,7 +147,7 @@ static TAG_CALLBACK(spp_trace) { /* TODO: deprecate */ static TAG_CALLBACK(spp_echo) { if (state->echo[state->ifl]) { - do_printf (out, "%s", buf); + out_printf (out, "%s", buf); } // TODO: add variable replacement here?? not necessary, done by {{get}} return 0; @@ -173,7 +175,7 @@ static TAG_CALLBACK(spp_system) { } #if HAVE_SYSTEM char *str = cmd_to_str (buf); - do_printf (out, "%s", str); + out_printf (out, "%s", str); free(str); #endif return 0; @@ -237,7 +239,7 @@ static TAG_CALLBACK(spp_hex) { b = buf[i + 2]; buf[i + 2] = '\0'; sscanf(buf + i, "%02x", &ch); - do_printf (out, "%c", ch); + out_printf (out, "%c", ch); buf[i + 2] = b; buf = buf + 2; } @@ -264,7 +266,7 @@ static TAG_CALLBACK(spp_grepline) { } } fclose (fd); - do_printf (out, "%s", b); + out_printf (out, "%s", b); } else { fprintf(stderr, "Unable to open '%s'\n", buf); } @@ -369,7 +371,7 @@ static TAG_CALLBACK(spp_endpipe) { } } while (ret > 0); str[len] = '\0'; - do_printf (out, "%s", str); + out_printf (out, "%s", str); if (spp_pipe_fd) { pclose (spp_pipe_fd); } @@ -386,7 +388,7 @@ static PUT_CALLBACK(spp_fputs) { } else #endif { - do_printf (out, "%s", buf); + out_printf (out, "%s", buf); } return 0; } diff --git a/shlr/spp/r_api.c b/shlr/spp/r_api.c index 61155aaf7f..efb45ba92b 100644 --- a/shlr/spp/r_api.c +++ b/shlr/spp/r_api.c @@ -1,20 +1,19 @@ -/* radare - LGPL - Copyright 2013-2016 - pancake */ - -#if !HAVE_R_UTIL +/* radare - LGPL - Copyright 2013-2019 - pancake */ +#include "spp.h" #include "r_api.h" -RStrBuf *r_strbuf_new(const char *str) { - RStrBuf *s = R_NEW0 (RStrBuf); +SStrBuf *r_strbuf_new(const char *str) { + SStrBuf *s = R_NEW0 (SStrBuf); if (str) r_strbuf_set (s, str); return s; } -void r_strbuf_init(RStrBuf *sb) { - memset (sb, 0, sizeof (RStrBuf)); +void r_strbuf_init(SStrBuf *sb) { + memset (sb, 0, sizeof (SStrBuf)); } -bool r_strbuf_set(RStrBuf *sb, const char *s) { +bool r_strbuf_set(SStrBuf *sb, const char *s) { int l; if (!sb) return false; if (!s) { @@ -39,7 +38,7 @@ bool r_strbuf_set(RStrBuf *sb, const char *s) { return true; } -int r_strbuf_append(RStrBuf *sb, const char *s) { +int r_strbuf_append(SStrBuf *sb, const char *s) { int l = strlen (s); if (l < 1) { return false; @@ -72,16 +71,16 @@ int r_strbuf_append(RStrBuf *sb, const char *s) { return true; } -char *r_strbuf_get(RStrBuf *sb) { +char *r_strbuf_get(SStrBuf *sb) { return sb? (sb->ptr? sb->ptr: sb->buf) : NULL; } -void r_strbuf_free(RStrBuf *sb) { +void r_strbuf_free(SStrBuf *sb) { r_strbuf_fini (sb); free (sb); } -void r_strbuf_fini(RStrBuf *sb) { +void r_strbuf_fini(SStrBuf *sb) { if (sb && sb->ptr) R_FREE (sb->ptr); } @@ -101,9 +100,7 @@ int r_sys_setenv(const char *key, const char *value) { SetEnvironmentVariable (key, (LPSTR)value); return 0; // TODO. get ret #else -#warning r_sys_setenv : unimplemented for this platform +#warning s_sys_setenv : unimplemented for this platform return 0; #endif } - -#endif // NO_UTIL diff --git a/shlr/spp/r_api.h b/shlr/spp/r_api.h index 80c85a88f0..3d45ff56b1 100644 --- a/shlr/spp/r_api.h +++ b/shlr/spp/r_api.h @@ -1,72 +1,22 @@ -#if !HAVE_R_UTIL - -#ifndef R_STRBUF_H -#define R_STRBUF_H - -#include -#include -#include -#include -#include - -#ifdef R_API -#undef R_API -#endif -#if R_SWIG - #define R_API export -#elif R_INLINE - #define R_API inline -#else - #if defined(__GNUC__) && __GNUC__ >= 4 - #define R_API __attribute__((visibility("default"))) - #elif defined(_MSC_VER) - #define R_API __declspec(dllexport) - #else - #define R_API - #endif -#endif - -#if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__) - #define __BSD__ 0 - #define __UNIX__ 1 -#endif -#if __KFBSD__ || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) - #define __BSD__ 1 - #define __UNIX__ 1 -#endif -#if __WIN32__ || __CYGWIN__ || MINGW32 - #define __addr_t_defined - #include -#endif -#if __WIN32__ || MINGW32 && !__CYGWIN__ - #ifndef _MSC_VER - #include - #endif - typedef int socklen_t; - #undef USE_SOCKETS - #define __WINDOWS__ 1 - #undef __UNIX__ - #undef __BSD__ -#endif - -typedef struct { - int len; - char *ptr; - int ptrlen; - char buf[64]; -} RStrBuf; +#ifndef S_STRBUF_H +#define S_STRBUF_H #define R_FREE(x) { free(x); x = NULL; } #define R_NEW0(x) (x*)calloc(1,sizeof(x)) -#define R_STRBUF_SAFEGET(sb) (r_strbuf_get (sb) ? r_strbuf_get (sb) : "") -RStrBuf *r_strbuf_new(const char *s); -bool r_strbuf_set(RStrBuf *sb, const char *s); -int r_strbuf_append(RStrBuf *sb, const char *s); -char *r_strbuf_get(RStrBuf *sb); -void r_strbuf_free(RStrBuf *sb); -void r_strbuf_fini(RStrBuf *sb); -void r_strbuf_init(RStrBuf *sb); -#endif // R_STRBUF_H +#ifdef _MSC_VER +void out_printf(Output *out, char *str, ...); +#else +void out_printf(Output *out, char *str, ...) __attribute__ ((format (printf, 2, 3))); +#endif -#endif // NO_UTIL +SStrBuf *r_strbuf_new(const char *s); +bool r_strbuf_set(SStrBuf *sb, const char *s); +int r_strbuf_append(SStrBuf *sb, const char *s); +char *r_strbuf_get(SStrBuf *sb); +void r_strbuf_free(SStrBuf *sb); +void r_strbuf_fini(SStrBuf *sb); +void r_strbuf_init(SStrBuf *sb); +int r_sys_setenv(const char *key, const char *value); + +#endif diff --git a/shlr/spp/spp.c b/shlr/spp/spp.c index 7480323835..e6620749ce 100644 --- a/shlr/spp/spp.c +++ b/shlr/spp/spp.c @@ -1,9 +1,10 @@ -/* MIT (C) pancake (at) nopcode (dot) org - 2009-2017 */ +/* MIT (C) pancake (at) nopcode (dot) org - 2009-2019 */ #include "spp.h" +#include "r_api.h" #include "config.h" -R_API int spp_run(char *buf, Output *out) { +S_API int spp_run(char *buf, Output *out) { int i, ret = 0; char *tok; @@ -80,20 +81,6 @@ void lbuf_strcat(SppBuf *dst, char *src) { dst->lbuf_n += len; } -void do_printf(Output *out, char *str, ...) { - va_list ap; - va_start (ap, str); - if (out->fout) { - vfprintf (out->fout, str, ap); - } else { - char tmp[4096]; - vsnprintf (tmp, sizeof (tmp), str, ap); - tmp[sizeof (tmp) - 1] = 0; - r_strbuf_append (out->cout, tmp); - } - va_end (ap); -} - int do_fputs(Output *out, char *str) { int i; int printed = 0; @@ -115,7 +102,7 @@ int do_fputs(Output *out, char *str) { return printed; } -R_API void spp_eval(char *buf, Output *out) { +S_API void spp_eval(char *buf, Output *out) { char *ptr, *ptr2; char *ptrr = NULL; int delta; @@ -234,7 +221,7 @@ retry: } /* TODO: detect nesting */ -R_API void spp_io(FILE *in, Output *out) { +S_API void spp_io(FILE *in, Output *out) { char buf[4096]; int lines; if (!proc->buf.lbuf) { @@ -248,12 +235,15 @@ R_API void spp_io(FILE *in, Output *out) { proc->buf.lbuf_s = 1024; while (!feof (in)) { buf[0] = '\0'; // ??? - if (!fgets (buf, 1023, in)) break; + if (!fgets (buf, sizeof (buf) - 1, in)) { + break; + } if (feof (in)) break; lines = 1; if (!memcmp (buf, "#!", 2)) { - if (!fgets (buf, 1023, in)) break; - if (feof (in)) break; + if (!fgets (buf, sizeof (buf) - 1, in) || feof (in)) { + break; + } lines++; } if (proc->multiline) { @@ -279,7 +269,7 @@ R_API void spp_io(FILE *in, Output *out) { (void)do_fputs (out, proc->buf.lbuf); } -R_API int spp_file(const char *file, Output *out) { +S_API int spp_file(const char *file, Output *out) { FILE *in = fopen (file, "r"); D fprintf (stderr, "SPP-FILE(%s)\n", file); if (in) { @@ -291,21 +281,21 @@ R_API int spp_file(const char *file, Output *out) { return 0; } -R_API void spp_proc_list_kw() { +S_API void spp_proc_list_kw() { int i; for (i = 0; tags[i].name; i++) { printf ("%s\n", tags[i].name); } } -R_API void spp_proc_list() { +S_API void spp_proc_list() { int i; for (i=0; procs[i]; i++) { printf ("%s\n", procs[i]->name); } } -R_API void spp_proc_set(struct Proc *p, char *arg, int fail) { +S_API void spp_proc_set(struct Proc *p, char *arg, int fail) { int i, j; if (arg) for (j = 0; procs[j]; j++) { @@ -332,3 +322,17 @@ R_API void spp_proc_set(struct Proc *p, char *arg, int fail) { tags = (struct Tag*)proc->tags; } } + +void out_printf(Output *out, char *str, ...) { + va_list ap; + va_start (ap, str); + if (out->fout) { + vfprintf (out->fout, str, ap); + } else { + char tmp[4096]; + vsnprintf (tmp, sizeof (tmp), str, ap); + tmp[sizeof (tmp) - 1] = 0; + r_strbuf_append (out->cout, tmp); + } + va_end (ap); +} diff --git a/shlr/spp/spp.h b/shlr/spp/spp.h index 20d75093a0..d127c1c079 100644 --- a/shlr/spp/spp.h +++ b/shlr/spp/spp.h @@ -5,11 +5,47 @@ #include #include #include -#if HAVE_R_UTIL -#include +#include +#include + +#ifdef S_API +#undef S_API +#endif +#if R_SWIG + #define S_API export +#elif R_INLINE + #define S_API inline #else -#include "r_api.h" -int r_sys_setenv(const char *key, const char *value); + #if defined(__GNUC__) && __GNUC__ >= 4 + #define S_API __attribute__((visibility("default"))) + #elif defined(_MSC_VER) + #define S_API __declspec(dllexport) + #else + #define S_API + #endif +#endif + +#if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__) + #define __BSD__ 0 + #define __UNIX__ 1 +#endif +#if __KFBSD__ || defined(__NetBSD__) || defined(__OpenBSD__) + #define __BSD__ 1 + #define __UNIX__ 1 +#endif +#if __WIN32__ || __CYGWIN__ || MINGW32 + #define __addr_t_defined + #include +#endif +#if __WIN32__ || MINGW32 && !__CYGWIN__ || _MSC_VER + #ifndef _MSC_VER + #include + #endif + typedef int socklen_t; + #undef USE_SOCKETS + #define __WINDOWS__ 1 + #undef __UNIX__ + #undef __BSD__ #endif #ifdef __WINDOWS__ @@ -24,10 +60,6 @@ int r_sys_setenv(const char *key, const char *value); #define MAXIFL 128 -extern int ifl; -extern int echo[MAXIFL]; -extern int lineno; - #ifndef HAVE_FORK #define HAVE_FORK 1 #endif @@ -47,12 +79,19 @@ extern int lineno; #define GET_ARG(x,y,i) if (y[i][2]) x = y[i] + 2; else x = y[++i] #define DEFAULT_PROC(x) \ -DLL_LOCAL struct Tag *tags = (struct Tag *)&x##_tags; \ -DLL_LOCAL struct Arg *args = (struct Arg *)&x##_args; \ -DLL_LOCAL struct Proc *proc = &x##_proc; +struct Tag *tags = (struct Tag *)&x##_tags; \ +struct Arg *args = (struct Arg *)&x##_args; \ +struct Proc *proc = &x##_proc; + +typedef struct s_strbuf_t { + int len; + char *ptr; + int ptrlen; + char buf[64]; +} SStrBuf; typedef struct { - RStrBuf *cout; + SStrBuf *cout; FILE *fout; int size; } Output; @@ -101,22 +140,16 @@ struct Proc { int tag_begin; int default_echo; SppState state; - SppBuf buf; + SppBuf buf; }; -R_API int spp_file(const char *file, Output *out); -R_API int spp_run(char *buf, Output *out); -R_API void spp_eval(char *buf, Output *out); -R_API void spp_io(FILE *in, Output *out); -#ifdef _MSC_VER -void do_printf(Output *out, char *str, ...); -#else -void do_printf(Output *out, char *str, ...) __attribute__ ((format (printf, 2, 3))); -#endif - -R_API void spp_proc_list(void); -R_API void spp_proc_list_kw(void); -R_API void spp_proc_set(struct Proc *p, char *arg, int fail); +S_API int spp_file(const char *file, Output *out); +S_API int spp_run(char *buf, Output *out); +S_API void spp_eval(char *buf, Output *out); +S_API void spp_io(FILE *in, Output *out); +S_API void spp_proc_list(void); +S_API void spp_proc_list_kw(void); +S_API void spp_proc_set(struct Proc *p, char *arg, int fail); #if DEBUG #define D if (1) diff --git a/shlr/zip/zip/zip_close.c b/shlr/zip/zip/zip_close.c index 99b562ec16..9506d27fdf 100644 --- a/shlr/zip/zip/zip_close.c +++ b/shlr/zip/zip/zip_close.c @@ -42,14 +42,13 @@ #include #endif #include -#ifdef HAVE_UNISTD_H -#include -#endif #include #include #ifdef __WINDOWS__ #include #include +#else +#include #endif diff --git a/shlr/zip/zip/zip_fdopen.c b/shlr/zip/zip/zip_fdopen.c index 231a45c012..bda9aabac4 100644 --- a/shlr/zip/zip/zip_fdopen.c +++ b/shlr/zip/zip/zip_fdopen.c @@ -34,7 +34,6 @@ #include "zipint.h" -#include diff --git a/shlr/zip/zlib/gzguts.h b/shlr/zip/zlib/gzguts.h index 24c6566c01..03b3c33b22 100644 --- a/shlr/zip/zlib/gzguts.h +++ b/shlr/zip/zlib/gzguts.h @@ -19,7 +19,6 @@ #endif #include -#include #include "zlib.h" #ifdef STDC # include @@ -38,6 +37,8 @@ #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) # include +#else +#include #endif #if defined(_WIN32) || defined(__CYGWIN__) diff --git a/shlr/zip/zlib/gzread.c b/shlr/zip/zlib/gzread.c index 1463a0606c..f866e2121e 100644 --- a/shlr/zip/zlib/gzread.c +++ b/shlr/zip/zlib/gzread.c @@ -4,7 +4,6 @@ */ #include "gzguts.h" -#include /* Local functions */ local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); diff --git a/shlr/zip/zlib/zconf.h b/shlr/zip/zlib/zconf.h index 5e1d68a004..e593519439 100644 --- a/shlr/zip/zlib/zconf.h +++ b/shlr/zip/zlib/zconf.h @@ -472,7 +472,9 @@ typedef uLong FAR uLongf; #endif #ifndef Z_SOLO # if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +#ifndef _WIN32 # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +#endif # ifdef VMS # include /* for off_t */ # endif diff --git a/sys/meson.py b/sys/meson.py index 93d0b77141..a5123410bf 100755 --- a/sys/meson.py +++ b/sys/meson.py @@ -194,7 +194,6 @@ def win_dist_libr2(**path_fmt): copy(r'{ROOT}\libr\include\sdb\*.h', r'{DIST}\{R2_INCDIR}\sdb') copy(r'{ROOT}\libr\include\r_util\*.h', r'{DIST}\{R2_INCDIR}\r_util') copy(r'{ROOT}\libr\include\r_crypto\*.h', r'{DIST}\{R2_INCDIR}\r_crypto') - copytree(r'{ROOT}\libr\include\msvc', r'{DIST}\{R2_INCDIR}\msvc') makedirs(r'{DIST}\{R2_FORTUNES}') copy(r'{ROOT}\doc\fortunes.*', r'{DIST}\{R2_FORTUNES}') copytree(r'{ROOT}\libr\bin\d', r'{DIST}\{R2_SDB}\format', diff --git a/sys/msvc.sh b/sys/msvc.sh index 3f3fbbfc0c..7a96a7bcd8 100755 --- a/sys/msvc.sh +++ b/sys/msvc.sh @@ -22,9 +22,6 @@ IFS=${_IFS} # Use /FS to allow cl.exe to write to the same .pdb file CFLAGS="-FS" -# Include msvc directory to provide unistd.h and sys/time.h -INC_DIR=$(cygpath -aw $(pwd)/libr/include/msvc) -CFLAGS="${CFLAGS} -I\"${INC_DIR}\"" # export CCCL_OPTIONS="--cccl-verbose" export CFLAGS="${CFLAGS}"