MSVC support, Watcom is still recommended

This commit is contained in:
Nishi 2026-06-20 03:04:36 +09:00
commit c17f7a56cc
10 changed files with 87 additions and 23 deletions

1
README
View file

@ -32,6 +32,7 @@
* Tested compilers * Tested compilers
GCC/Clang Debian GNU/Linux 13 GCC/Clang Debian GNU/Linux 13
Open Watcom 2.0 Windows 11 Open Watcom 2.0 Windows 11
Visual C++ 6.0 Windows 11
* Differences * Differences
- Multiple contexts can be created in SJ4. SJ3's behavior of using - Multiple contexts can be created in SJ4. SJ3's behavior of using

View file

@ -0,0 +1,31 @@
#ifndef __SJ4_COMPAT_H__
#define __SJ4_COMPAT_H__
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
#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

View file

@ -436,4 +436,6 @@
#define termtbl Jtermtbl #define termtbl Jtermtbl
#include <sj_compat.h>
#endif #endif

View file

@ -62,7 +62,7 @@ int cl2knj(SJ4_CONTEXT u_char* yomi, int len, u_char* kouho) {
} }
*ptr2 = 0; *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; if(!hyomi[0]) return 0;

View file

@ -732,7 +732,7 @@ int set_stdypass(SJ4_CONTEXT char* pass) {
static void static void
set_comment(u_char* buf, char* comment) { 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) { int set_dictcmnt(DictFile* dp, char* cmnt) {

View file

@ -66,7 +66,7 @@ FILE* Fopen(char* filename, char* type) {
fl = (FileList*)Malloc(sizeof(*fl)); fl = (FileList*)Malloc(sizeof(*fl));
len = strlen(filename) + 1; len = strlen(filename) + 1;
fl->fname = Malloc(len); fl->fname = Malloc(len);
strlcpy(fl->fname, filename, len); sj4_strlcpy(fl->fname, filename, len);
fl->fp = fp; fl->fp = fp;
fl->next = flist; fl->next = flist;

View file

@ -59,7 +59,7 @@ char* make_idxlist(char* name) {
i = strlen(name); i = strlen(name);
p = Zalloc(i + 2); p = Zalloc(i + 2);
strlcpy(p, name, i + 2); sj4_strlcpy(p, name, i + 2);
return p; return p;
} }
char* get_idxlist(char* name) { char* get_idxlist(char* name) {
@ -180,7 +180,7 @@ void mark_file(FILE* out) {
fputc('\n', out); fputc('\n', out);
Fclose(fp); Fclose(fp);
} else { } else {
strlcpy(pathname, idxtop, sizeof(pathname)); sj4_strlcpy(pathname, idxtop, sizeof(pathname));
pos = infp ? Ftell(infp) : 0; pos = infp ? Ftell(infp) : 0;
} }
} }

View file

@ -430,7 +430,7 @@ void makehead(u_char* dict_name) {
put4byte(header + VERSIONPOS, DICTVERSION); put4byte(header + VERSIONPOS, DICTVERSION);
time(&i); time(&i);
p = header + COMMENTPOS; 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) { while(*p) {
if(*p == '\n') { if(*p == '\n') {
*p = 0; *p = 0;

View file

@ -26,6 +26,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "sj4_dict_struct.h" #include "sj4_dict_struct.h"
#include "sj_compat.h"
/* char.c */ /* char.c */
int cnvyomi(int); int cnvyomi(int);

View file

@ -1,26 +1,45 @@
#!/bin/sh #!/bin/sh
if [ "x$1" = "x" ]; then cmp="$1"
if [ "x$cmp" = "x" ]; then
echo "Usage: $0 [watcom|msvc]" echo "Usage: $0 [watcom|msvc]"
exit 1 exit 1
fi fi
for i in lib/sj4core/*.c; do if [ "$cmp" = "watcom" ]; then
:
elif [ "$cmp" = "msvc" ]; then
:
else
echo "Invalid target"
exit 1
fi
library() {
N=$1
for i in lib/$N/*.c; do
if [ -f $i.obj ]; then if [ -f $i.obj ]; then
continue continue
fi fi
echo $i echo $i
if [ "$1" = "watcom" ]; then if [ "$cmp" = "watcom" ]; then
cl /Iinclude/sj4common /Iinclude/sj4core /c /fo$i.obj $i || exit 1 owcc -Iinclude/sj4common /Iinclude/sj4compat -Iinclude/$N -bnt -c -o $i.obj $i || exit 1
else elif [ "$cmp" = "msvc" ]; then
owcc -Iinclude/sj4common -Iinclude/sj4core -bnt -c -o $i.obj $i || exit 1 cl.exe /nologo /Iinclude/sj4common /Iinclude/sj4compat /Iinclude/$N /c /Fo$i.obj $i || exit 1
fi fi
done done
find lib/sj4core -name "*.obj" | while read a; do if [ "$cmp" = "watcom" ]; then
find lib/$N -name "*.obj" | while read a; do
echo "+$a" echo "+$a"
done | xargs wlib -q -b -fo -n sj4core.lib done | xargs wlib -q -b -fo -n $N.lib
elif [ "$cmp" = "msvc" ]; then
lib.exe /nologo /out:$N.lib lib/$N/*.obj
fi
}
executable() { executable() {
N=$1 N=$1
@ -30,11 +49,21 @@ executable() {
continue continue
fi fi
echo $i echo $i
if [ "$cmp" = "watcom" ]; then
owcc -DUTF8 -DENGLISH -Iinclude/sj4common -Iinclude/sj4core -bnt -c -o $i.obj $i || exit 1 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 done
if [ "$cmp" = "watcom" ]; then
owcc -bnt -o $N.exe src/$N/*.obj $2 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 sj4mkdic
executable sj4test sj4core.lib executable sj4test sj4core.lib