diff options
| -rw-r--r-- | configure.ac | 5 | ||||
| -rw-r--r-- | src/Makefile.am | 1 | ||||
| -rw-r--r-- | src/bin/Makefile.am | 2 | ||||
| -rw-r--r-- | src/bin/aplwc_repl.h | 3 | ||||
| -rw-r--r-- | src/bin/main.c | 2 | ||||
| -rw-r--r-- | src/include/Makefile.am | 8 | ||||
| -rw-r--r-- | src/include/os.h | 54 | ||||
| -rw-r--r-- | src/include/os/windows.h | 25 | ||||
| -rw-r--r-- | src/include/os/windows_main.h | 20 | ||||
| -rw-r--r-- | src/include/os_main.h | 31 | ||||
| -rw-r--r-- | src/lib/Makefile.am | 2 | ||||
| -rw-r--r-- | src/os/Makefile.am | 11 | ||||
| -rw-r--r-- | src/os/os.c | 24 | ||||
| -rw-r--r-- | src/os/os_main.c | 24 | ||||
| -rw-r--r-- | src/os/windows.c | 25 | ||||
| -rw-r--r-- | src/os/windows_main.c | 26 | ||||
| -rw-r--r-- | src/tools/Makefile.am | 8 | ||||
| -rw-r--r-- | src/tools/genboot.c | 5 | ||||
| -rw-r--r-- | src/tools/genunicode.c | 8 | ||||
| -rw-r--r-- | tests/Makefile.am | 8 | ||||
| -rw-r--r-- | tests/aplwc_errstr.c | 6 | ||||
| -rw-r--r-- | tests/aplwc_eval.c | 7 | ||||
| -rw-r--r-- | tests/aplwc_read.c | 7 | ||||
| -rw-r--r-- | tests/aplwc_utf8.c | 6 |
24 files changed, 284 insertions, 34 deletions
diff --git a/configure.ac b/configure.ac index a6ae456..86a12b7 100644 --- a/configure.ac +++ b/configure.ac @@ -34,6 +34,11 @@ AS_CASE([$build_mode], ] ) +AS_CASE([$host_os], + [mingw32], [AC_DEFINE([HOST_OS_WINDOWS], [1], [Host operating system is Windows])]) +AS_CASE([$build_os], + [mingw32], [AC_DEFINE([BUILD_OS_WINDOWS], [1], [Host operating system is Windows])]) + AC_CONFIG_FILES([ Makefile ]) diff --git a/src/Makefile.am b/src/Makefile.am index b4cd291..92b080f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,6 @@ include src/bin/Makefile.am include src/include/Makefile.am include src/lib/Makefile.am +include src/os/Makefile.am include src/tools/Makefile.am include src/unicode/Makefile.am diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index e4d2204..4ae24a6 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -5,4 +5,4 @@ aplwc_SOURCES = \ src/bin/main.c \ src/bin/util.c -aplwc_LDADD = libaplwc.la +aplwc_LDADD = libaplwc.la libos.la libosmain.la diff --git a/src/bin/aplwc_repl.h b/src/bin/aplwc_repl.h index 6fb4415..6d01de1 100644 --- a/src/bin/aplwc_repl.h +++ b/src/bin/aplwc_repl.h @@ -20,6 +20,9 @@ #ifndef APLWC_REPL_H #define APLWC_REPL_H +#include <os.h> +#include <os_main.h> + #include <assert.h> #include <limits.h> #include <stdint.h> diff --git a/src/bin/main.c b/src/bin/main.c index 5242cd5..04bb13a 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -79,7 +79,7 @@ my_setup_failsim(enum aplwc_failsim_parameter p, unsigned long def) } int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { struct aplwc_fns fns; struct aplwc *aplwc; diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 3f082fb..99326ea 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -1,2 +1,8 @@ +OS_HS = \ + src/include/os/windows.h + include_HEADERS += src/include/aplwc.h -noinst_HEADERS += src/include/aplwc_macros.h +noinst_HEADERS += src/include/aplwc_macros.h src/include/os.h $(OS_HS) + +src/include/os.h: $(OS_HS) + diff --git a/src/include/os.h b/src/include/os.h new file mode 100644 index 0000000..a56b79d --- /dev/null +++ b/src/include/os.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef OS_H +#define OS_H + +#include <config.h> + +enum OS { + OS_Windows, + OS_Unknown +}; + +#if BUILD_TARGET + +#ifdef BUILD_OS_WINDOWS +#define OS OS_Windows +#else +#error "Unexpected build os" +#endif + +#else + +#ifdef HOST_OS_WINDOWS +#define OS OS_Windows +#else +#error "Unexpected host os" +#endif + +#endif + +#if OS == OS_Windows +#include <os/windows.h> +#endif + +int getline(char **, size_t *, void *); + +#endif /* OS_H */ diff --git a/src/include/os/windows.h b/src/include/os/windows.h new file mode 100644 index 0000000..7d12e12 --- /dev/null +++ b/src/include/os/windows.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <stddef.h> +#include <stdio.h> +#include <assert.h> +#include <setjmp.h> +#include <stdlib.h> +#include <string.h> diff --git a/src/include/os/windows_main.h b/src/include/os/windows_main.h new file mode 100644 index 0000000..fad4151 --- /dev/null +++ b/src/include/os/windows_main.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +int main(int, char **); diff --git a/src/include/os_main.h b/src/include/os_main.h new file mode 100644 index 0000000..1aa3d55 --- /dev/null +++ b/src/include/os_main.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef OS_MAIN_H +#define OS_MAIN_H + +#if OS == OS_Windows +#include <os/windows_main.h> +#else +#error "Did you include <os.h> before including <os_main.h>?" /* There may also be a missing case */ +#endif + +int portable_main(int, char **); + +#endif /* OS_MAIN_H */ diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index b0f60f8..6a526e3 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -1,6 +1,7 @@ lib_LTLIBRARIES += libaplwc.la libaplwc_la_SOURCES = \ + src/os/os.c \ src/lib/aplwc_internal.h \ src/lib/eval.c \ src/lib/main.c \ @@ -11,6 +12,7 @@ libaplwc_la_SOURCES = \ src/lib/syntax.c \ src/lib/unicode.c +libaplwc_la_LIBADD = libos.la libaplwc_la_LDFLAGS = -version-info 0:0:0 EXTRA_DIST += src/lib/boot.aplwc diff --git a/src/os/Makefile.am b/src/os/Makefile.am new file mode 100644 index 0000000..46d9edf --- /dev/null +++ b/src/os/Makefile.am @@ -0,0 +1,11 @@ +noinst_LTLIBRARIES = libos.la libosmain.la + +libos_la_SOURCES = src/os/os.c +libos_la_LDFLAGS = -static + +libosmain_la_SOURCES = src/os/os_main.c +libosmain_la_LDFLAGS = -static + +src/os/os.c: src/os/windows.c + +src/os/os_main.c: src/os/windows_main.c diff --git a/src/os/os.c b/src/os/os.c new file mode 100644 index 0000000..2c4fcc6 --- /dev/null +++ b/src/os/os.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <os.h> + +#if OS == OS_Windows +#include "windows.c" +#endif diff --git a/src/os/os_main.c b/src/os/os_main.c new file mode 100644 index 0000000..1d35a78 --- /dev/null +++ b/src/os/os_main.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <os_main.h> + +#if OS == OS_Windows +#include "windows_main.c" +#endif diff --git a/src/os/windows.c b/src/os/windows.c new file mode 100644 index 0000000..88d8b27 --- /dev/null +++ b/src/os/windows.c @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <os.h> + +int getline(char **, size_t *, void *) +{ + return -1; +} diff --git a/src/os/windows_main.c b/src/os/windows_main.c new file mode 100644 index 0000000..dc30750 --- /dev/null +++ b/src/os/windows_main.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> + * + * This file is part of aplwc. + * + * Aplwc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Aplwc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with aplwc. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <os.h> + +int +main(int argc, char **argv) +{ + return portable_main(argc, argv); +} diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index 9f1d00a..8e995db 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -1,10 +1,10 @@ -genboot$(EXEEXT): src/tools/genboot.c +genboot$(EXEEXT): src/tools/genboot.c src/os/os.c src/os/os_main.c src/include/os.h src/include/os_main.h $(AM_V_CC) - $(AM_V_at)$(CC_FOR_BUILD) -o $@ $(top_srcdir)/src/tools/genboot.c + $(AM_V_at)$(CC_FOR_BUILD) -DBUILD_TARGET -I$(top_srcdir)/src/include/ -I. -o $@ $(top_srcdir)/src/tools/genboot.c $(top_srcdir)/src/os/os.c $(top_srcdir)/src/os/os_main.c -genunicode$(EXEEXT): src/tools/genunicode.c +genunicode$(EXEEXT): src/tools/genunicode.c src/os/os.c src/os/os_main.c src/include/os.h src/include/os_main.h $(AM_V_CC) - $(AM_V_at)$(CC_FOR_BUILD) -o $@ $(top_srcdir)/src/tools/genunicode.c + $(AM_V_at)$(CC_FOR_BUILD) -DBUILD_TARGET -I$(top_srcdir)/src/include/ -I. -o $@ $(top_srcdir)/src/tools/genunicode.c $(top_srcdir)/src/os/os.c $(top_srcdir)/src/os/os_main.c EXTRA_DIST += src/tools/genboot.c src/tools/genunicode.c CLEANFILES += genboot$(EXEEXT) genunicode$(EXEEXT) diff --git a/src/tools/genboot.c b/src/tools/genboot.c index 9d0a7e4..6433bf7 100644 --- a/src/tools/genboot.c +++ b/src/tools/genboot.c @@ -17,11 +17,10 @@ * along with aplwc. If not, see <https://www.gnu.org/licenses/>. */ -#include <stdio.h> -#include <assert.h> +#include <os.h> int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { FILE *f; int c, s; diff --git a/src/tools/genunicode.c b/src/tools/genunicode.c index 76f2c60..209984f 100644 --- a/src/tools/genunicode.c +++ b/src/tools/genunicode.c @@ -17,11 +17,7 @@ * along with aplwc. If not, see <https://www.gnu.org/licenses/>. */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <assert.h> -#include <setjmp.h> +#include <os.h> static char *files[] = { "DerivedCoreProperties.txt", @@ -51,7 +47,7 @@ static void parse_sep(FILE *); static jmp_buf env; int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { FILE *f; char *dir, *buf; diff --git a/tests/Makefile.am b/tests/Makefile.am index 5afdad4..b0d8f1d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,12 +4,12 @@ EXTRA_DIST += tests/scripts/simfail.sh check_PROGRAMS += testbin-aplwc_errstr testbin_aplwc_errstr_SOURCES = tests/aplwc_errstr.c -testbin_aplwc_errstr_LDADD = libaplwc.la +testbin_aplwc_errstr_LDADD = libaplwc.la libosmain.la TESTS += testbin-aplwc_errstr check_PROGRAMS += testbin-aplwc_utf8 testbin_aplwc_utf8_SOURCES= tests/aplwc_utf8.c -testbin_aplwc_utf8_LDADD = libaplwc.la +testbin_aplwc_utf8_LDADD = libaplwc.la libosmain.la TESTS += testbin-aplwc_utf8 TEST_EXTENSIONS += .txt @@ -18,7 +18,7 @@ EXTRA_DIST += $(TXT_LOG_COMPILER) check_PROGRAMS += testbin-aplwc_eval testbin_aplwc_eval_SOURCES= tests/aplwc_eval.c -testbin_aplwc_eval_LDADD = libaplwc.la +testbin_aplwc_eval_LDADD = libaplwc.la libosmain.la TEST_INPUTS += \ tests/aplwc_eval/good/1.txt \ tests/aplwc_eval/good/2.txt \ @@ -26,7 +26,7 @@ TEST_INPUTS += \ check_PROGRAMS += testbin-aplwc_read testbin_aplwc_read_SOURCES= tests/aplwc_read.c -testbin_aplwc_read_LDADD = libaplwc.la +testbin_aplwc_read_LDADD = libaplwc.la libosmain.la TEST_INPUTS += \ tests/aplwc_read/good/1.txt \ tests/aplwc_read/good/2.txt \ diff --git a/tests/aplwc_errstr.c b/tests/aplwc_errstr.c index d1e6a20..3ee41b4 100644 --- a/tests/aplwc_errstr.c +++ b/tests/aplwc_errstr.c @@ -17,8 +17,8 @@ * along with aplwc. If not, see <https://www.gnu.org/licenses/>. */ -#include <stdlib.h> -#include <string.h> +#include <os.h> +#include <os_main.h> #include <aplwc.h> static void * @@ -36,7 +36,7 @@ my_dealloc(void *p) } int -main(void) +portable_main(int argc, char *argv[]) { enum aplwc_rc ret; struct aplwc_fns fns; diff --git a/tests/aplwc_eval.c b/tests/aplwc_eval.c index deb1610..bb90104 100644 --- a/tests/aplwc_eval.c +++ b/tests/aplwc_eval.c @@ -17,9 +17,8 @@ * along with aplwc. If not, see <https://www.gnu.org/licenses/>. */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <os.h> +#include <os_main.h> #include <aplwc.h> static void * @@ -37,7 +36,7 @@ my_dealloc(void *p) } int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { char *input; struct aplwc *aplwc; diff --git a/tests/aplwc_read.c b/tests/aplwc_read.c index 902c9d2..9f299a5 100644 --- a/tests/aplwc_read.c +++ b/tests/aplwc_read.c @@ -17,9 +17,8 @@ * along with aplwc. If not, see <https://www.gnu.org/licenses/>. */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <os.h> +#include <os_main.h> #include <aplwc.h> static void * @@ -37,7 +36,7 @@ my_dealloc(void *p) } int -main(int argc, char *argv[]) +portable_main(int argc, char *argv[]) { struct aplwc_fns fns; char *input; diff --git a/tests/aplwc_utf8.c b/tests/aplwc_utf8.c index 7d14778..95c08a1 100644 --- a/tests/aplwc_utf8.c +++ b/tests/aplwc_utf8.c @@ -17,8 +17,8 @@ * along with aplwc. If not, see <https://www.gnu.org/licenses/>. */ -#include <stdlib.h> -#include <string.h> +#include <os.h> +#include <os_main.h> #include <aplwc.h> uint8_t bad1[] = {0xff,0}; @@ -51,7 +51,7 @@ my_dealloc(void *p) } int -main(void) +portable_main(int argc, char *argv[]) { struct aplwc *aplwc; AplwcLine line; |