cake
/
libg1m
Archived
1
0
Fork 0

Solved Casemul problems, by the look of it.

This commit is contained in:
Thomas Touhey 2017-03-08 13:49:49 +01:00
parent f210a8d0b1
commit dfca7ea255
2 changed files with 20 additions and 14 deletions

View File

@ -65,7 +65,7 @@ void g1m_free_mcsfile_content(g1m_mcsfile_t *handle)
}
/* free the images */
if (type & g1m_mcstype_pict) {
if ((type & (g1m_mcstype_pict | g1m_mcstype_capt))) {
for (int i = 0; i < handle->head.count; i++)
free(handle->pics[i]);
if (handle->pics != &handle->pic)

View File

@ -74,25 +74,29 @@ static int read_internal(g1m_buffer_t *buffer, uint32_t signature,
* @arg buffer the buffer to read from.
* @arg name the name buffer (13 bytes including '\0').
* @arg length the subheader+data length.
* @arg big_endian big endian?
* @return the error code.
*/
static int read_top(g1m_buffer_t *buffer, char *name, uint_fast32_t *length)
static int read_top(g1m_buffer_t *buffer, char *name, uint_fast32_t *length,
int big_endian)
{
/* read and check the name length */
uint32_t name_length; READ(&name_length, sizeof(uint32_t))
name_length = le32toh(name_length);
name_length = e32toh(name_length);
/* read the name and copy */
/* read the raw name */
uint8_t buf[name_length];
READ(buf, name_length)
name_length = max(name_length, 8);
/* copy to the real name */
if (name_length > 8) name_length = 8;
memcpy(name, buf, name_length);
name[name_length] = 0;
/* read the length and correct */
READ(length, sizeof(uint32_t))
*length = le32toh(*length);
*length = e32toh(*length);
/* no error! */
return (0);
@ -125,7 +129,7 @@ static int read_picture(g1m_mcsfile_t **pfile, g1m_buffer_t *buffer,
/* general record things */
char name[13]; uint_fast32_t record_length;
if ((err = read_top(buffer, name, &record_length))
if ((err = read_top(buffer, name, &record_length, big_endian))
|| (err = read_internal(buffer, MAKELONG('PI', 'CT'), VER)))
return (err);
@ -173,15 +177,14 @@ static int read_matrix(g1m_mcsfile_t **pfile, g1m_buffer_t *buffer,
int err; *pfile = NULL;
/* general record things */
char name[13]; uint_fast32_t record_length;
if ((err = read_top(buffer, name, &record_length))
if ((err = read_top(buffer, name, &record_length, big_endian))
|| (err = read_internal(buffer, MAKELONG('MT', 'RX'), VER)))
return (err);
/* read specific things */
DREAD(mtx, casemul_mtrx_header)
int width = le32toh(mtx.lines) & 0x7FFF,
height = le32toh(mtx.columns) & 0x7FFF;
log_info("%d*%d elements in matrix", width, height);
unsigned int width = e32toh(mtx.lines) & 0x7FFF,
height = e32toh(mtx.columns) & 0x7FFF;
/* read double tab */
unsigned int total = width * height;
@ -200,7 +203,8 @@ static int read_matrix(g1m_mcsfile_t **pfile, g1m_buffer_t *buffer,
/* read the matrix */
g1m_mcs_cell_t **cells = (*pfile)->cells;
for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) {
for (unsigned int y = 0; y < height; y++)
for (unsigned int x = 0; x < width; x++) {
/* read the bcd */
g1m_bcd_t bcd; g1m_bcd_fromdouble(*raw++, &bcd);
@ -239,7 +243,7 @@ static int read_list(g1m_mcsfile_t **pfile, g1m_buffer_t *buffer,
int err; *pfile = NULL;
/* general record things */
char name[13]; uint_fast32_t record_length;
if ((err = read_top(buffer, name, &record_length))
if ((err = read_top(buffer, name, &record_length, big_endian))
|| (err = read_internal(buffer, MAKELONG('LI', 'ST'), VER)))
return (err);
@ -335,6 +339,7 @@ int g1m_decode_casemul(g1m_t *handle, g1m_buffer_t *buffer)
src.lists;
if (!(handle->files = malloc(sizeof(g1m_mcsfile_t*) * handle->_size)))
return (g1m_error_alloc);
memset(handle->files, 0, sizeof(g1m_mcsfile_t*) * handle->_size);
/* read each program; TODO: put this in a function when token parsing
* is managed. */
@ -343,7 +348,7 @@ int g1m_decode_casemul(g1m_t *handle, g1m_buffer_t *buffer)
log_warn("Program content will be skipped!");
/* general record things */
char name[13]; uint_fast32_t record_length;
if ((err = read_top(buffer, name, &record_length))
if ((err = read_top(buffer, name, &record_length, big_endian))
|| (err = read_internal(buffer, MAKELONG('PR', 'OG'), VER)))
goto fail;
@ -386,6 +391,7 @@ int g1m_decode_casemul(g1m_t *handle, g1m_buffer_t *buffer)
log_warn("Should read compiled part here!");
/* no error! */
handle->platform &= ~g1m_platflag_be;
return (0);
fail:
g1m_free_mcs(handle);