From c17f7a56cc0f034628c55cff27bb9f533c113b1c Mon Sep 17 00:00:00 2001 From: Nishi Date: Sat, 20 Jun 2026 03:04:36 +0900 Subject: [PATCH] MSVC support, Watcom is still recommended --- README | 1 + include/sj4core/sj_compat.h | 31 ++++++++++++++++++ include/sj4core/sj_rename.h | 2 ++ lib/sj4core/cl2knj.c | 2 +- lib/sj4core/sdepend.c | 2 +- src/sj4mkdic/file.c | 2 +- src/sj4mkdic/makedict.c | 4 +-- src/sj4mkdic/makeseg.c | 2 +- src/sj4mkdic/sj4mkdic.h | 1 + win32.sh | 63 +++++++++++++++++++++++++++---------- 10 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 include/sj4core/sj_compat.h diff --git a/README b/README index 7be8a1d..304191d 100644 --- a/README +++ b/README @@ -32,6 +32,7 @@ * Tested compilers GCC/Clang Debian GNU/Linux 13 Open Watcom 2.0 Windows 11 + Visual C++ 6.0 Windows 11 * Differences - Multiple contexts can be created in SJ4. SJ3's behavior of using diff --git a/include/sj4core/sj_compat.h b/include/sj4core/sj_compat.h new file mode 100644 index 0000000..e27399d --- /dev/null +++ b/include/sj4core/sj_compat.h @@ -0,0 +1,31 @@ +#ifndef __SJ4_COMPAT_H__ +#define __SJ4_COMPAT_H__ + +#include +#include +#include + +#if defined(_MSC_VER) + +#if defined(_MSC_VER) && _MSC_VER < 1900 +static int __inline sj4_snprintf(char* buffer, size_t count, const char* fmt, ...){ + int st; + va_list va; + + va_start(va, fmt); + st = vsprintf(buffer, fmt, va); + va_end(va); + + return st; +} +#else +#define sj4_snprintf snprintf +#endif + +#define sj4_strlcpy(x, y, z) strcpy((x), (y)) +#else +#define sj4_snprintf snprintf +#define sj4_strlcpy strlcpy +#endif + +#endif diff --git a/include/sj4core/sj_rename.h b/include/sj4core/sj_rename.h index 13c068a..d271963 100644 --- a/include/sj4core/sj_rename.h +++ b/include/sj4core/sj_rename.h @@ -436,4 +436,6 @@ #define termtbl Jtermtbl +#include + #endif diff --git a/lib/sj4core/cl2knj.c b/lib/sj4core/cl2knj.c index 74ee1a9..ea99dc3 100644 --- a/lib/sj4core/cl2knj.c +++ b/lib/sj4core/cl2knj.c @@ -62,7 +62,7 @@ int cl2knj(SJ4_CONTEXT u_char* yomi, int len, u_char* kouho) { } *ptr2 = 0; - strlcpy((char*)orgyomi, (char*)yomi, (int)(ptr1 - yomi) + 1); + sj4_strlcpy((char*)orgyomi, (char*)yomi, (int)(ptr1 - yomi) + 1); if(!hyomi[0]) return 0; diff --git a/lib/sj4core/sdepend.c b/lib/sj4core/sdepend.c index 1b1f7e4..469f87e 100644 --- a/lib/sj4core/sdepend.c +++ b/lib/sj4core/sdepend.c @@ -732,7 +732,7 @@ int set_stdypass(SJ4_CONTEXT char* pass) { static void set_comment(u_char* buf, char* comment) { - strlcpy((char*)buf + HEADERLENGTH, comment, COMMENTLENGTH); + sj4_strlcpy((char*)buf + HEADERLENGTH, comment, COMMENTLENGTH); } int set_dictcmnt(DictFile* dp, char* cmnt) { diff --git a/src/sj4mkdic/file.c b/src/sj4mkdic/file.c index 6291632..55ed457 100644 --- a/src/sj4mkdic/file.c +++ b/src/sj4mkdic/file.c @@ -66,7 +66,7 @@ FILE* Fopen(char* filename, char* type) { fl = (FileList*)Malloc(sizeof(*fl)); len = strlen(filename) + 1; fl->fname = Malloc(len); - strlcpy(fl->fname, filename, len); + sj4_strlcpy(fl->fname, filename, len); fl->fp = fp; fl->next = flist; diff --git a/src/sj4mkdic/makedict.c b/src/sj4mkdic/makedict.c index a310a7f..45a98a3 100644 --- a/src/sj4mkdic/makedict.c +++ b/src/sj4mkdic/makedict.c @@ -59,7 +59,7 @@ char* make_idxlist(char* name) { i = strlen(name); p = Zalloc(i + 2); - strlcpy(p, name, i + 2); + sj4_strlcpy(p, name, i + 2); return p; } char* get_idxlist(char* name) { @@ -180,7 +180,7 @@ void mark_file(FILE* out) { fputc('\n', out); Fclose(fp); } else { - strlcpy(pathname, idxtop, sizeof(pathname)); + sj4_strlcpy(pathname, idxtop, sizeof(pathname)); pos = infp ? Ftell(infp) : 0; } } diff --git a/src/sj4mkdic/makeseg.c b/src/sj4mkdic/makeseg.c index fd68148..ddea03e 100644 --- a/src/sj4mkdic/makeseg.c +++ b/src/sj4mkdic/makeseg.c @@ -430,7 +430,7 @@ void makehead(u_char* dict_name) { put4byte(header + VERSIONPOS, DICTVERSION); time(&i); p = header + COMMENTPOS; - snprintf((char*)p, sizeof(header) - COMMENTPOS, "%s : %s", dict_name, ctime(&i)); + sj4_snprintf((char*)p, sizeof(header) - COMMENTPOS, "%s : %s", dict_name, ctime(&i)); while(*p) { if(*p == '\n') { *p = 0; diff --git a/src/sj4mkdic/sj4mkdic.h b/src/sj4mkdic/sj4mkdic.h index ffb8a09..6a427f7 100644 --- a/src/sj4mkdic/sj4mkdic.h +++ b/src/sj4mkdic/sj4mkdic.h @@ -26,6 +26,7 @@ #include #include "sj4_dict_struct.h" +#include "sj_compat.h" /* char.c */ int cnvyomi(int); diff --git a/win32.sh b/win32.sh index 2d91145..ed409ea 100755 --- a/win32.sh +++ b/win32.sh @@ -1,26 +1,45 @@ #!/bin/sh -if [ "x$1" = "x" ]; then +cmp="$1" + +if [ "x$cmp" = "x" ]; then echo "Usage: $0 [watcom|msvc]" exit 1 fi -for i in lib/sj4core/*.c; do - if [ -f $i.obj ]; then - continue - fi - echo $i +if [ "$cmp" = "watcom" ]; then + : +elif [ "$cmp" = "msvc" ]; then + : +else + echo "Invalid target" + exit 1 +fi - if [ "$1" = "watcom" ]; then - cl /Iinclude/sj4common /Iinclude/sj4core /c /fo$i.obj $i || exit 1 - else - owcc -Iinclude/sj4common -Iinclude/sj4core -bnt -c -o $i.obj $i || exit 1 - fi -done +library() { + N=$1 -find lib/sj4core -name "*.obj" | while read a; do - echo "+$a" -done | xargs wlib -q -b -fo -n sj4core.lib + for i in lib/$N/*.c; do + if [ -f $i.obj ]; then + continue + fi + echo $i + + if [ "$cmp" = "watcom" ]; then + owcc -Iinclude/sj4common /Iinclude/sj4compat -Iinclude/$N -bnt -c -o $i.obj $i || exit 1 + elif [ "$cmp" = "msvc" ]; then + cl.exe /nologo /Iinclude/sj4common /Iinclude/sj4compat /Iinclude/$N /c /Fo$i.obj $i || exit 1 + fi + done + + if [ "$cmp" = "watcom" ]; then + find lib/$N -name "*.obj" | while read a; do + echo "+$a" + done | xargs wlib -q -b -fo -n $N.lib + elif [ "$cmp" = "msvc" ]; then + lib.exe /nologo /out:$N.lib lib/$N/*.obj + fi +} executable() { N=$1 @@ -30,11 +49,21 @@ executable() { continue fi echo $i - owcc -DUTF8 -DENGLISH -Iinclude/sj4common -Iinclude/sj4core -bnt -c -o $i.obj $i || exit 1 + if [ "$cmp" = "watcom" ]; then + owcc -DUTF8 -DENGLISH -Iinclude/sj4common -Iinclude/sj4core -bnt -c -o $i.obj $i || exit 1 + elif [ "$cmp" = "msvc" ]; then + cl.exe /nologo /DUTF8 /DENGLISH /Iinclude/sj4common /Iinclude/sj4core /c /Fo$i.obj $i || exit 1 + fi done - owcc -bnt -o $N.exe src/$N/*.obj $2 + if [ "$cmp" = "watcom" ]; then + owcc -bnt -o $N.exe src/$N/*.obj $2 + elif [ "$cmp" = "msvc" ]; then + cl.exe /nologo /Fe$N.exe src/$N/*.obj /link $2 + fi } +library sj4core + executable sj4mkdic executable sj4test sj4core.lib