Browse Source

sjis fixes

vampirefrog 1 year ago
parent
commit
21c4b81794
2 changed files with 5 additions and 4 deletions
  1. 2
    2
      sjis.c
  2. 3
    2
      sjis2utf8.c

+ 2
- 2
sjis.c View File

@@ -23,7 +23,7 @@ int sjis_to_utf8(uint8_t *sjis_data, int sjis_len, uint8_t *utf8_data, int utf8_
23 23
 	int j = 0, last_byte = 0;
24 24
 	for(int i = 0; i < sjis_len; i++) {
25 25
 		char b = sjis_data[i];
26
-		if(SJIS_FIRST_CHAR(b)) {
26
+		if(last_byte == 0 && SJIS_FIRST_CHAR(b)) {
27 27
 			last_byte = b;
28 28
 		} else {
29 29
 			char buf[4];
@@ -48,7 +48,7 @@ int sjis_write_utf8(FILE *f, uint8_t *sjis_data, int sjis_len) {
48 48
 	int j = 0, last_byte = 0;
49 49
 	for(int i = 0; i < sjis_len; i++) {
50 50
 		char b = sjis_data[i];
51
-		if(SJIS_FIRST_CHAR(b)) {
51
+		if(last_byte == 0 && SJIS_FIRST_CHAR(b)) {
52 52
 			last_byte = b;
53 53
 		} else {
54 54
 			char buf[4];

+ 3
- 2
sjis2utf8.c View File

@@ -1,7 +1,8 @@
1
+#include <stdio.h>
2
+
1 3
 #include "sjis.h"
2 4
 #include "utf8.h"
3 5
 
4
-
5 6
 int main(int argc, char **argv) {
6 7
 	FILE *in = stdin, *out = stdout;
7 8
 	if(argc > 1) in = fopen(argv[1], "rb");
@@ -10,7 +11,7 @@ int main(int argc, char **argv) {
10 11
 	int last_byte = 0;
11 12
 	int b = 0;
12 13
 	while((b = fgetc(in)) != EOF) {
13
-		if(SJIS_FIRST_CHAR(b)) {
14
+		if(last_byte == 0 && SJIS_FIRST_CHAR(b)) {
14 15
 			last_byte = b;
15 16
 		} else {
16 17
 			utf8_fputc(sjis_char_to_unicode((last_byte << 8) | b), out);

Loading…
Cancel
Save