Commit 89b8b8c1248b4eb67ff4bdc23e3babc8ada8938b

Thomas de Grivel 2023-12-13T23:56:40

win32

diff --git a/config.subr b/config.subr
index 01465a9..79d3bf4 100644
--- a/config.subr
+++ b/config.subr
@@ -86,7 +86,7 @@ config_have_stat_mtim() {
 
 config_gnu() {
     if grep -q _GNU_SOURCE /usr/include/features.h 2>/dev/null; then
-	CFLAGS="$CFLAGS -D_GNU_SOURCE"
+	CFLAGS="$CFLAGS -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_BSD_SOURCE"
     fi
 }
 
diff --git a/libc3/facts.c b/libc3/facts.c
index 335a6da..2e86b23 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -288,7 +288,7 @@ sw facts_load_file (s_facts *facts, const s_str *path)
   assert(facts);
   assert(path);
   buf_init(&buf, false, sizeof(b), b);
-  if (! (fp = fopen(path->ptr.ps8, "r"))) {
+  if (! (fp = fopen(path->ptr.ps8, "rb"))) {
     warn("facts_load_file: %s", path->ptr.ps8);
     return -1;
   }
diff --git a/libc3/file.c b/libc3/file.c
index 3e29edb..fddcc6c 100644
--- a/libc3/file.c
+++ b/libc3/file.c
@@ -60,11 +60,11 @@ sw file_copy_1 (const char *from, const char *to)
   sw r;
   sw saved_errno;
   sw w;
-  if ((fd_from = open(from, O_RDONLY)) < 0) {
+  if ((fd_from = open(from, O_RDONLY | O_BINARY)) < 0) {
     warn("cp: %s", from);
     return -1;
   }
-  if ((fd_to = open(to, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
+  if ((fd_to = open(to, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)) < 0) {
     warn("cp: %s", to);
     goto error;
   }
diff --git a/test/buf_file_test.c b/test/buf_file_test.c
index 82a2d40..8d31f65 100644
--- a/test/buf_file_test.c
+++ b/test/buf_file_test.c
@@ -50,8 +50,8 @@ TEST_CASE(buf_file_open_r_refill)
   s_buf buf;
   FILE *fp;
   sw i = 64;
-  test_context("buf_file_open_r_refill(/dev/zero)");
-  fp = fopen("/dev/zero", "r");
+  test_context("buf_file_open_r_refill(zero)");
+  fp = fopen("zero", "r");
   assert(fp);
   buf_init(&buf, false, sizeof(bu), bu);
   buf_file_open_r(&buf, fp);
diff --git a/test/facts_test.c b/test/facts_test.c
index fb324c4..2feb119 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -301,7 +301,7 @@ TEST_CASE(facts_log_add)
   s_fact fact[24];
   s_facts facts;
   FILE *fp;
-  fp = fopen("facts_test_log_add.facts", "w");
+  fp = fopen("facts_test_log_add.facts", "wb");
   facts_init(&facts);
   facts.log = log_new();
   log_open(facts.log, fp);
@@ -352,7 +352,7 @@ TEST_CASE(facts_log_remove)
   s_fact fact[24];
   s_facts facts;
   FILE *fp;
-  fp = fopen("facts_test_log_remove.facts", "w");
+  fp = fopen("facts_test_log_remove.facts", "wb");
   facts_init(&facts);
   facts.log = log_new();
   log_open(facts.log, fp);
@@ -449,7 +449,7 @@ TEST_CASE(facts_open_file)
   s_str path;
   if (file_copy_1("facts_test_open_file.1.in.facts",
                   "facts_test_open_file.1.facts")) {
-    fprintf(stderr, "%s:%i: %s: file_copy_1", __FILE__, __LINE__,
+    fprintf(stderr, "%s:%i: %s: file_copy_1\n", __FILE__, __LINE__,
             __func__);
     exit(1);
   }
diff --git a/test/ic3_test b/test/ic3_test
index f04ca74..d2938bc 100755
--- a/test/ic3_test
+++ b/test/ic3_test
@@ -42,11 +42,11 @@ for TARGET in $TARGETS; do
     RESULT=test_ok
     $IC3 < ${TARGET}.in > ${TARGET}.out 2>&1
     echo $? > ${TARGET}.ret
-    if ! diff -au ${TARGET}.out.expected ${TARGET}.out > ${TARGET}.diff
+    if ! diff -abu ${TARGET}.out.expected ${TARGET}.out > ${TARGET}.diff
     then
         RESULT=test_ko
     fi
-    if ! diff -au ${TARGET}.ret.expected ${TARGET}.ret >> ${TARGET}.diff
+    if ! diff -abu ${TARGET}.ret.expected ${TARGET}.ret >> ${TARGET}.diff
     then
         RESULT=test_ko
     fi
diff --git a/test/test.c b/test/test.c
index 3a8afd6..7aa4048 100644
--- a/test/test.c
+++ b/test/test.c
@@ -35,6 +35,8 @@ char         g_test_targets_env[TARGETS_MAX * TARGET_NAME_MAX];
 char        *g_test_targets_env_v[TARGETS_MAX + 1];
 const char **g_test_targets = {NULL};
 
+static char * test_strsep (char **p, const char *delim);
+
 void test_clean (void)
 {
 }
@@ -110,7 +112,7 @@ void test_init (int argc, char **argv)
       memcpy(target, env_target, len + 1);
       ap = g_test_targets_env_v;
       while (ap < g_test_targets_env_v + TARGETS_MAX &&
-             (*ap = strsep(&target, " \t")) != NULL)
+             (*ap = test_strsep(&target, " \t")) != NULL)
         if (**ap != '\0')
           ap++;
       *ap = NULL;
@@ -168,6 +170,24 @@ void test_summary (void)
          TEST_COLOR_RESET);
 }
 
+static char * test_strsep (char **p, const char *delim)
+{
+  char *d;
+  char *start;
+  if (! p || ! *p || ! delim)
+    return NULL;
+  d = start = *p;
+  while (*d && ! strchr(delim, *d))
+    d++;
+  if (*d) {
+    *d = 0;
+    *p = d + 1;
+  }
+  else
+    *p = d;
+  return start;
+}
+
 int test_target (const char *target)
 {
   const char **i;
diff --git a/test/zero b/test/zero
new file mode 100644
index 0000000..06d7405
Binary files /dev/null and b/test/zero differ
diff --git a/win32/Makefile b/win32/Makefile
new file mode 100644
index 0000000..b56af2f
--- /dev/null
+++ b/win32/Makefile
@@ -0,0 +1,55 @@
+
+DEST = c3-${C3_VERSION}.win32.tmp
+
+release: c3-${C3_VERSION}.win32.zip
+
+c3-${C3_VERSION}.win32.zip: c3-${C3_VERSION}.win32
+	rm -f c3-${C3_VERSION}.win32.zip
+	zip -r c3-${C3_VERSION}.win32.zip c3-${C3_VERSION}.win32
+
+c3-${C3_VERSION}.win32:
+	rm -rf ${DEST}
+	mkdir -p ${DEST}/test/ic3
+	cp -a ../README.md ${DEST}
+	cp -a ../libffi/.libs/libffi-8.dll ${DEST}
+	cp -a ../libffi/.libs/libffi-8.dll ${DEST}/test
+	cp -a ../libc3/.libs/libc3*-0.dll ${DEST}
+	cp -a ../libc3/.libs/libc3*-0.dll ${DEST}/test
+	cp -a ../libc3/window/.libs/libc3_window*-0.dll ${DEST}
+	cp -a ../libc3/window/cairo/.libs/libc3_window_cairo*-0.dll ${DEST}
+#	cp -a /mingw32/bin/libgcc_s_seh-1.dll ${DEST}
+	cp -a /mingw32/bin/libcairo-2.dll ${DEST}
+	cp -a ../libc3/window/cairo/win32/.libs/libc3_window_cairo_win32*-0.dll ${DEST}
+	cp -a ../libc3/window/cairo/win32/demo/.libs/c3_window_cairo_win32_demo.exe ${DEST}
+	cp -a /mingw32/bin/libxkbcommon-0.dll ${DEST}
+	cp -a /mingw32/bin/libwinpthread-1.dll ${DEST}
+	cp -a /mingw32/bin/libstdc++-6.dll ${DEST}
+	cp -a /mingw32/bin/libfontconfig-1.dll ${DEST}
+	cp -a /mingw32/bin/libfreetype-6.dll ${DEST}
+	cp -a /mingw32/bin/libpixman-1-0.dll ${DEST}
+	cp -a /mingw32/bin/zlib1.dll ${DEST}
+	cp -a /mingw32/bin/libpng16-16.dll ${DEST}
+	cp -a /mingw32/bin/libexpat-1.dll ${DEST}
+	cp -a /mingw32/bin/libiconv-2.dll ${DEST}
+	cp -a /mingw32/bin/libintl-8.dll ${DEST}
+	cp -a /mingw32/bin/libbz2-1.dll ${DEST}
+	cp -a /mingw32/bin/libbrotlidec.dll ${DEST}
+	cp -a /mingw32/bin/libharfbuzz-0.dll ${DEST}
+	cp -a /mingw32/bin/libbrotlicommon.dll ${DEST}
+	cp -a /mingw32/bin/libglib-2.0-0.dll ${DEST}
+	cp -a /mingw32/bin/libgraphite2.dll ${DEST}
+	cp -a /mingw32/bin/libpcre2-8-0.dll ${DEST}
+	cp -a ../lib ${DEST}/
+	cp -a ../c3s/.libs/c3s*.exe ${DEST}
+	cp -a ../ic3/.libs/ic3*.exe ${DEST}
+	cp -a ../test/.libs/libc3*.exe ${DEST}/test
+	cp -a ../test/ic3_test ${DEST}/test
+	cp -a ../test/*.facts ${DEST}/test
+	cp -a ../test/ic3/*.in ../test/ic3/*.expected ${DEST}/test/ic3
+	rm -rf c3-${C3_VERSION}.win32.old
+	mv c3-${C3_VERSION}.win32 c3-${C3_VERSION}.win32.old
+	mv ${DEST} c3-${C3_VERSION}.win32
+
+.PHONY: c3-${C3_VERSION}.win32 release
+
+include config.mk
diff --git a/win32/configure b/win32/configure
new file mode 100644
index 0000000..05c2502
--- /dev/null
+++ b/win32/configure
@@ -0,0 +1,23 @@
+#!/bin/sh
+## c3
+## Copyright 2022,2023 kmx.io <contact@kmx.io>
+##
+## Permission is hereby granted to use this software granted the above
+## copyright notice and this permission paragraph are included in all
+## copies and substantial portions of this software.
+##
+## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+## THIS SOFTWARE.
+
+set -e
+
+export SRC_TOP="$(dirname "$(pwd)")"
+
+. ../config.subr
+
+C3_VERSION="$(cat ../c3.version)"
+echo "C3_VERSION = $C3_VERSION" >> ${CONFIG_MK}
+
+update_config_mk