From a0d4750431b8b3328eb4b0d87c03f9d83a54812d Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Wed, 11 Mar 2020 16:23:14 +0800 Subject: [PATCH] commit czmod --- czmod.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 czmod.c diff --git a/czmod.c b/czmod.c new file mode 100644 index 0000000..2cdfde9 --- /dev/null +++ b/czmod.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +#include + +#include "imembase.c" + + +//---------------------------------------------------------------------- +// INLINE +//---------------------------------------------------------------------- +#ifndef INLINE +#if defined(__GNUC__) + +#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) +#define INLINE __inline__ __attribute__((always_inline)) +#else +#define INLINE __inline__ +#endif + +#elif (defined(_MSC_VER) || defined(__WATCOMC__)) +#define INLINE __inline +#else +#define INLINE +#endif +#endif + +#if (!defined(__cplusplus)) && (!defined(inline)) +#define inline INLINE +#endif + + +//--------------------------------------------------------------------- +// get environ +//--------------------------------------------------------------------- +static ib_string* os_getenv(const char *name) +{ + char *p = getenv(name); + if (p == NULL) { + return NULL; + } + ib_string *text = ib_string_new(); + ib_string_assign(text, p); + return text; +} + + +//--------------------------------------------------------------------- +// get data file +//--------------------------------------------------------------------- +static inline const char *get_data_file(void) +{ + static ib_string *text = NULL; + if (text != NULL) { + return text->ptr; + } + text = os_getenv("_ZL_DATA"); + if (text) { + return text->ptr; + } + text = os_getenv("HOME"); + if (text == NULL) { + text = os_getenv("USERPROFILE"); + } + if (text == NULL) { + return NULL; + } + ib_string_append(text, "/.zlua"); + return text->ptr; +} + +int main(int argc, char *argv[]) +{ + if (argc <= 1) { + printf("Hello, World !!\n"); + printf("data: %s\n", get_data_file()); + return 0; + } + if (strcmp(argv[1], "--add") == 0) { + if (argc >= 3) { + } + } + return 0; +} + +