summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c39
-rw-r--r--src/parser/parser_stmt.c26
-rw-r--r--src/repl/repl.c22
-rw-r--r--src/utils/utils.c30
-rw-r--r--src/zprep.h14
5 files changed, 86 insertions, 45 deletions
diff --git a/src/main.c b/src/main.c
index 3bf4832..e2b3cde 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,11 +56,14 @@ void print_usage()
int main(int argc, char **argv)
{
memset(&g_config, 0, sizeof(g_config));
-#ifdef _WIN32
- strcpy(g_config.cc, "gcc.exe");
-#else
- strcpy(g_config.cc, "gcc");
-#endif
+ if (z_is_windows())
+ {
+ strcpy(g_config.cc, "gcc.exe");
+ }
+ else
+ {
+ strcpy(g_config.cc, "gcc");
+ }
if (argc < 2)
{
@@ -346,14 +349,15 @@ int main(int argc, char **argv)
const char *thread_flag = g_parser_ctx->has_async ? "-lpthread" : "";
const char *math_flag = "-lm";
-#ifdef _WIN32
- // Windows might use different flags or none for math/threads
- math_flag = "";
- if (g_parser_ctx->has_async)
+ if (z_is_windows())
{
- thread_flag = "";
+ // Windows might use different flags or none for math/threads
+ math_flag = "";
+ if (g_parser_ctx->has_async)
+ {
+ thread_flag = "";
+ }
}
-#endif
// If using cosmocc, it handles these usually, but keeping them is okay for Linux targets
@@ -386,11 +390,14 @@ int main(int argc, char **argv)
if (g_config.mode_run)
{
char run_cmd[2048];
-#ifdef _WIN32
- sprintf(run_cmd, "%s", outfile);
-#else
- sprintf(run_cmd, "./%s", outfile);
-#endif
+ if (z_is_windows())
+ {
+ sprintf(run_cmd, "%s", outfile);
+ }
+ else
+ {
+ sprintf(run_cmd, "./%s", outfile);
+ }
ret = system(run_cmd);
remove(outfile);
zptr_plugin_mgr_cleanup();
diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c
index aba6f5e..303f6ac 100644
--- a/src/parser/parser_stmt.c
+++ b/src/parser/parser_stmt.c
@@ -3179,11 +3179,14 @@ char *run_comptime_block(ParserContext *ctx, Lexer *l)
char cmd[4096];
char bin[1024];
-#ifdef _WIN32
- sprintf(bin, "%s.exe", filename);
-#else
- sprintf(bin, "%s.bin", filename);
-#endif
+ if (z_is_windows())
+ {
+ sprintf(bin, "%s.exe", filename);
+ }
+ else
+ {
+ sprintf(bin, "%s.bin", filename);
+ }
sprintf(cmd, "%s %s -o %s", g_config.cc, filename, bin);
if (!g_config.verbose)
{
@@ -3199,11 +3202,14 @@ char *run_comptime_block(ParserContext *ctx, Lexer *l)
sprintf(out_file, "%s.out", filename);
// Platform-neutral execution
-#ifdef _WIN32
- sprintf(cmd, "%s > %s", bin, out_file);
-#else
- sprintf(cmd, "./%s > %s", bin, out_file);
-#endif
+ if (z_is_windows())
+ {
+ sprintf(cmd, "%s > %s", bin, out_file);
+ }
+ else
+ {
+ sprintf(cmd, "./%s > %s", bin, out_file);
+ }
if (system(cmd) != 0)
{
diff --git a/src/repl/repl.c b/src/repl/repl.c
index 274c14c..cb63293 100644
--- a/src/repl/repl.c
+++ b/src/repl/repl.c
@@ -28,12 +28,10 @@ void run_repl(const char *self_path)
char history_path[512];
const char *home = getenv("HOME");
-#ifdef _WIN32
- if (!home)
+ if (z_is_windows() && !home)
{
home = getenv("USERPROFILE");
}
-#endif
if (home)
{
snprintf(history_path, sizeof(history_path), "%s/.zprep_history", home);
@@ -273,10 +271,14 @@ void run_repl(const char *self_path)
{
tmpdir = getenv("TMP");
}
- if (!tmpdir)
+ if (!tmpdir && !z_is_windows())
{
tmpdir = "/tmp";
}
+ if (!tmpdir)
+ {
+ tmpdir = ".";
+ }
snprintf(edit_path, sizeof(edit_path), "%s/zprep_edit_%d.zc", tmpdir, rand());
FILE *f = fopen(edit_path, "w");
if (f)
@@ -658,10 +660,14 @@ void run_repl(const char *self_path)
{
tmpdir = getenv("TMP");
}
- if (!tmpdir)
+ if (!tmpdir && !z_is_windows())
{
tmpdir = "/tmp";
}
+ if (!tmpdir)
+ {
+ tmpdir = ".";
+ }
snprintf(tmp_path, sizeof(tmp_path), "%s/zprep_repl_type_%d.zc", tmpdir,
rand());
FILE *f = fopen(tmp_path, "w");
@@ -752,10 +758,14 @@ void run_repl(const char *self_path)
{
tmpdir = getenv("TMP");
}
- if (!tmpdir)
+ if (!tmpdir && !z_is_windows())
{
tmpdir = "/tmp";
}
+ if (!tmpdir)
+ {
+ tmpdir = ".";
+ }
snprintf(tmp_path, sizeof(tmp_path), "%s/zprep_repl_time_%d.zc", tmpdir,
rand());
FILE *f = fopen(tmp_path, "w");
diff --git a/src/utils/utils.c b/src/utils/utils.c
index 159326e..56a7690 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -671,14 +671,17 @@ void scan_build_directives(ParserContext *ctx, const char *src)
{
printf("[zprep] Downloading %s...\n", filename);
char cmd[8192];
-#ifdef _WIN32
- // On Windows, try curl which is often built-in now
- sprintf(cmd, "curl -s -L \"%s\" -o \"%s\"", url, filename);
-#else
- // Try wget, then curl.
- sprintf(cmd, "wget -q \"%s\" -O \"%s\" || curl -s -L \"%s\" -o \"%s\"", url,
- filename, url, filename);
-#endif
+ if (z_is_windows())
+ {
+ // On Windows, try curl which is often built-in now
+ sprintf(cmd, "curl -s -L \"%s\" -o \"%s\"", url, filename);
+ }
+ else
+ {
+ // Try wget, then curl.
+ sprintf(cmd, "wget -q \"%s\" -O \"%s\" || curl -s -L \"%s\" -o \"%s\"", url,
+ filename, url, filename);
+ }
if (system(cmd) != 0)
{
zwarn("Failed to download %s", url);
@@ -693,11 +696,12 @@ void scan_build_directives(ParserContext *ctx, const char *src)
libs++;
}
-#ifdef _WIN32
- zwarn("pkg-config is usually not available on Windows. Build directive "
- "'pkg-config:%s' might fail.",
- libs);
-#endif
+ if (z_is_windows())
+ {
+ zwarn("pkg-config is usually not available on Windows. Build directive "
+ "'pkg-config:%s' might fail.",
+ libs);
+ }
char cmd[4096];
sprintf(cmd, "pkg-config --cflags %s", libs);
diff --git a/src/zprep.h b/src/zprep.h
index ea38927..e7004ee 100644
--- a/src/zprep.h
+++ b/src/zprep.h
@@ -7,9 +7,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
+#ifdef __COSMOPOLITAN__
+#include "libc/dce.h"
+#define z_is_windows() IsWindows()
+#else
+#ifdef _WIN32
+#define z_is_windows() 1
+#else
+#define z_is_windows() 0
+#endif
+#endif
// **ZEN VERSION**
+#ifndef ZEN_VERSION
#define ZEN_VERSION "0.1.0"
+#endif
// ** ANSI COLORS **
#define COLOR_RESET "\033[0m"