WIP Windows fix

This commit is contained in:
Nishi 2026-06-25 20:18:21 +09:00
commit 5d268b1f36
7 changed files with 64 additions and 21 deletions

View file

@ -36,7 +36,6 @@ elseif(SJ4_EMBED)
endif()
sj4_library(sj4rkcv)
sj4_library(sj4ime)
if(NOT SJ4_GLOBAL)
sj4_library(sj4lib)
@ -46,6 +45,11 @@ if(NOT SJ4_GLOBAL)
endif()
endif()
if(NOT SJ4_GLOBAL)
sj4_library(sj4ime)
target_link_libraries(sj4ime PUBLIC sj4lib)
endif()
if(SJ4_BUILD_TOOLS OR (NOT CMAKE_BINARY_DIR MATCHES CMAKE_CURRENT_SOURCE_DIR AND NOT SJ4_BUILD_ONLY_LIB))
file(GLOB_RECURSE SJ4MKDIC_SRCS src/sj4mkdic/**.c)
add_executable(sj4mkdic ${SJ4MKDIC_SRCS})

18
include/sj4ime/sj4ime.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef __SJ4IME_H__
#define __SJ4IME_H__
#include <sj4lib.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct sj4ime Sj4Ime;
Sj4Ime* sj4_ime(int charset, const char* dict);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,4 +0,0 @@
#ifndef __SJ_IME_H__
#define __SJ_IME_H__
#endif

View file

@ -1 +1,19 @@
#include <sj_ime.h>
#include <sj4ime.h>
#include <stdlib.h>
struct sj4ime {
Sj4Lib* lib;
};
Sj4Ime* sj4_ime(int charset, const char* dict) {
Sj4Ime* ime;
if((ime = calloc(1, sizeof(*ime))) == NULL) return NULL;
if((ime->lib = sj4_open(charset, dict)) == NULL) {
free(ime);
return NULL;
}
}

View file

@ -209,12 +209,13 @@ void output_knj(FILE* fp, u_char* p, int l) {
}
#ifdef UTF8
to[TO(to, euc, strlen(euc))] = 0;
if(fp == stdout || fp == stderr) {
to[TO(to, euc, strlen(euc))] = 0;
fputs(to, fp);
#else
fputs(euc, fp);
fputs(to, fp);
} else
#endif
fputs(euc, fp);
}
void output_str(FILE* fp, char* p) {
@ -302,15 +303,18 @@ void output_yomi(FILE* fp, u_char* p) {
i = yomi2zen(*p++);
#ifdef UTF8
euc[0] = (i >> 8) & 0xff;
euc[1] = i & 0xff;
if(fp == stdout || fp == stderr) {
euc[0] = (i >> 8) & 0xff;
euc[1] = i & 0xff;
to[TO(to, euc, 2)] = 0;
to[TO(to, euc, 2)] = 0;
fputs(to, fp);
#else
fputc((i >> 8) & 0xff, fp);
fputc(i & 0xff, fp);
fputs(to, fp);
} else
#endif
{
fputc((i >> 8) & 0xff, fp);
fputc(i & 0xff, fp);
}
}
}

View file

@ -110,8 +110,6 @@ readchar() {
}
if((cod = unicode_to_eucjp(n)) == -1) {
code = n;
return '[';
}
@ -156,6 +154,8 @@ skip_blank() {
return c;
}
#include "sj_charset.h"
static int
readhinsi() {
static int c = 0;
@ -175,8 +175,6 @@ retry:
}
for(i = 0; !Isblank(c);) {
int j = 0, k;
if(c == '\n' || c == ':')
break;
if(Isillegal(c))

View file

@ -8,6 +8,7 @@
#else
#define CHARSET SJ4UTF8
#endif
#define CHARSET SJ4UTF8
int main(int argc, char** argv) {
char c[8 * 1024];
@ -39,7 +40,11 @@ int main(int argc, char** argv) {
while((strlen(c) - i) > 0 && (n = sj4_getkan(ctx, c + i, strlen(c + i), &kouho)) != 0) {
printf(">");
do {
#ifdef _WIN32
printf(" %s", kouho.buffer.sjis);
#else
printf(" %s", kouho.buffer.utf8);
#endif
} while(sj4_nextkan(ctx) != 0);
printf("\n");