cake
/
libg1m
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libg1m/src/parse/lang.c

98 lines
2.8 KiB
C
Raw Normal View History

/* ************************************************************************** */
/* _____ _ */
/* parse/lang.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/11/24 18:00:21 |___/ */
/* */
/* ************************************************************************** */
#include <libg1m/internals.h>
/**
* g1m_parse_lang:
* Parse fx language files.
*
* @arg handle the libg1m handle.
* @arg stream the stream to parse from.
* @return the error code (0 if ok).
*/
int g1m_parse_lang(g1m_t *handle, FILE *stream)
{
(void)handle;
(void)stream;
log_info("Language type isn't managed yet.");
return (0);
}
/**
* g1m_parse_lang_cg:
* Parse fx-CG language files.
*
* @arg handle the libg1m handle.
* @arg stream the stream to parse from.
* @return the error code (0 if ok).
*/
int g1m_parse_lang_cg(g1m_t *handle, FILE *stream)
{
(void)handle;
/* read the subheader */
DREAD(hd, g3l_subheader)
/* correct the endianness */
hd.message_zone_size = be32toh(hd.message_zone_size);
/* log */
log_info("internal name is '%.8s'", hd.internal_name);
log_info("language name is '%.16s'", hd.language_name);
log_info("language salutation is '%.16s'", hd.language_salutation);
log_info("version is '%.10s'", hd.version);
log_info("datetime is '%.14s'", hd.datetime);
log_info("g3l filename is '%.16s'", hd.g3l_filename);
/* read the languages header */
DREAD(lhd, g3l_lang_header)
logm_info(&lhd, sizeof(struct g3l_lang_header));
/* correct endianness */
lhd.num = be32toh(lhd.num);
/* log */
log_info("there are %d messages", lhd.num);
/* read the entire message zone */
size_t message_zone_size = hd.message_zone_size
- sizeof(struct g3l_lang_header);
uint8_t message_zone[message_zone_size];
READ(message_zone, message_zone_size)
/* get parts */
const uint_fast32_t num = lhd.num + 1;
uint32_t *offsets = (uint32_t*)message_zone;
uint8_t *messages = (uint8_t*)message_zone + num * sizeof(uint32_t);
/* read messages */
for (uint_fast32_t i = 0; i < num; i++) {
/* check if offset is valid */
if (offsets[i] == (uint32_t)-1) {
log_info("[#%ld] -", i);
continue ;
}
/* correct offset */
offsets[i] = be32toh(offsets[i]);
/* log */
log_info("[#%ld] message: '%s'", i, &messages[offsets[i]]);
}
/* parse footer */
DREAD(footer, g3l_footer)
/* TODO: check the checksum */
/* no error */
return (0);
}