more refactoring
This commit is contained in:
parent
50532638dc
commit
d7f116da59
|
@ -14,7 +14,7 @@ add_executable(decrypt_packets decrypt_packets.c utils.c)
|
|||
target_link_libraries(decrypt_packets ${SYLVERANT_LIBRARY})
|
||||
|
||||
# gen_qst_header
|
||||
add_executable(gen_qst_header gen_qst_header.c quests.c utils.c)
|
||||
add_executable(gen_qst_header gen_qst_header.c textconv.c quests.c utils.c)
|
||||
target_link_libraries(gen_qst_header ${SYLVERANT_LIBRARY} ${ICONV_LIBRARIES})
|
||||
target_compile_definitions(gen_qst_header PRIVATE ICONV_CONST=${ICONV_CONST})
|
||||
target_include_directories(gen_qst_header PRIVATE ${ICONV_INCLUDE_DIR})
|
||||
|
|
|
@ -3,35 +3,11 @@
|
|||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iconv.h>
|
||||
#include <sylverant/prs.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "quests.h"
|
||||
|
||||
int sjis_to_utf8(char *s, size_t length) {
|
||||
if (!s)
|
||||
return ERROR_INVALID_PARAMS;
|
||||
|
||||
iconv_t conv;
|
||||
size_t in_size, out_size;
|
||||
|
||||
char *outbuf = malloc(length);
|
||||
|
||||
in_size = length;
|
||||
out_size = length;
|
||||
char *in = s;
|
||||
char *out = outbuf;
|
||||
conv = iconv_open("SHIFT_JIS", "UTF-8");
|
||||
iconv(conv, &in, &in_size, &out, &out_size);
|
||||
iconv_close(conv);
|
||||
|
||||
memset(s, 0, length);
|
||||
memcpy(s, outbuf, length);
|
||||
free(outbuf);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
#include "textconv.h"
|
||||
|
||||
int write_qst_header(const char *filename, const QST_HEADER *header) {
|
||||
FILE *fp = fopen(filename, "wb");
|
||||
|
|
9
retvals.h
Normal file
9
retvals.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef RETVALS_H_INCLUDED
|
||||
#define RETVALS_H_INCLUDED
|
||||
|
||||
#define SUCCESS 0
|
||||
#define ERROR_INVALID_PARAMS 1
|
||||
#define ERROR_FILE_NOT_FOUND 2
|
||||
#define ERROR_CREATING_FILE 3
|
||||
|
||||
#endif
|
32
textconv.c
Normal file
32
textconv.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <iconv.h>
|
||||
|
||||
#include "textconv.h"
|
||||
#include "retvals.h"
|
||||
|
||||
int sjis_to_utf8(char *s, size_t length) {
|
||||
if (!s)
|
||||
return ERROR_INVALID_PARAMS;
|
||||
|
||||
iconv_t conv;
|
||||
size_t in_size, out_size;
|
||||
|
||||
char *outbuf = malloc(length);
|
||||
|
||||
in_size = length;
|
||||
out_size = length;
|
||||
char *in = s;
|
||||
char *out = outbuf;
|
||||
conv = iconv_open("SHIFT_JIS", "UTF-8");
|
||||
iconv(conv, &in, &in_size, &out, &out_size);
|
||||
iconv_close(conv);
|
||||
|
||||
memset(s, 0, length);
|
||||
memcpy(s, outbuf, length);
|
||||
free(outbuf);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
11
textconv.h
Normal file
11
textconv.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef TEXTCONV_H_INCLUDED
|
||||
#define TEXTCONV_H_INCLUDED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iconv.h>
|
||||
|
||||
#include "retvals.h"
|
||||
|
||||
int sjis_to_utf8(char *s, size_t length);
|
||||
|
||||
#endif
|
1
utils.c
1
utils.c
|
@ -4,6 +4,7 @@
|
|||
#include <malloc.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "retvals.h"
|
||||
|
||||
int read_file(const char *filename, uint8_t** out_file_data, uint32_t *out_file_size) {
|
||||
if (!out_file_size || !out_file_data)
|
||||
|
|
5
utils.h
5
utils.h
|
@ -3,10 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SUCCESS 0
|
||||
#define ERROR_INVALID_PARAMS 1
|
||||
#define ERROR_FILE_NOT_FOUND 2
|
||||
#define ERROR_CREATING_FILE 3
|
||||
#include "retvals.h"
|
||||
|
||||
int read_file(const char *filename, uint8_t** out_file_data, uint32_t *out_file_size);
|
||||
int get_filesize(const char *filename, size_t *out_size);
|
||||
|
|
Loading…
Reference in a new issue