From f99423279cdb14cafbb6e5356530866ac0361721 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Sat, 25 Mar 2017 19:04:50 +0100 Subject: [PATCH] List & Matrix -> Cells format --- Makefile.vars | 1 - include/libg1m/format.h | 2 +- .../libg1m/format/mcs/{matrix.h => cells.h} | 30 ++++--- include/libg1m/format/mcs/list.h | 49 ---------- include/libg1m/format/std/mcs.h | 3 +- include/libg1m/formatutils.h | 2 +- include/libg1m/handle.h | 1 + include/libg1m/internals.h | 6 +- src/core/free.c | 4 +- src/decode/mcs/{matrix.c => cells.c} | 25 +++--- src/decode/mcs/list.c | 89 ------------------- src/decode/mcs/var.c | 8 +- src/decode/std/eact.c | 3 +- src/decode/std/mcs.c | 9 +- src/encode/addin.c | 6 +- src/encode/mcs/{matrix.c => cells.c} | 37 ++++---- src/encode/mcs/list.c | 81 ----------------- src/encode/mcs/var.c | 5 +- src/manage/handle.c | 8 +- src/manage/mcs.c | 12 ++- src/manage/mcsfile.c | 18 ++-- src/type/cas/datatype.c | 56 ++++++------ src/utils/extension.c | 4 +- src/utils/picture.c | 67 +++++++------- 24 files changed, 169 insertions(+), 357 deletions(-) rename include/libg1m/format/mcs/{matrix.h => cells.h} (68%) delete mode 100644 include/libg1m/format/mcs/list.h rename src/decode/mcs/{matrix.c => cells.c} (82%) delete mode 100644 src/decode/mcs/list.c rename src/encode/mcs/{matrix.c => cells.c} (71%) delete mode 100644 src/encode/mcs/list.c diff --git a/Makefile.vars b/Makefile.vars index 45148c8..9bf01da 100755 --- a/Makefile.vars +++ b/Makefile.vars @@ -134,7 +134,6 @@ endif # Look up the includes INC := $(shell find $(INCDIR) -name "*.h") - #******************************************************************************# # Look for manpages # #******************************************************************************# diff --git a/include/libg1m/format.h b/include/libg1m/format.h index 0b3369f..097c272 100644 --- a/include/libg1m/format.h +++ b/include/libg1m/format.h @@ -53,7 +53,7 @@ /* Followed by loads of zero, then, the content. The description of the rest * of the format is described in this header: */ -//# include +/*# include -- TODO */ /* ************************************************************************** */ /* The Casemul format */ /* ************************************************************************** */ diff --git a/include/libg1m/format/mcs/matrix.h b/include/libg1m/format/mcs/cells.h similarity index 68% rename from include/libg1m/format/mcs/matrix.h rename to include/libg1m/format/mcs/cells.h index 7521dc0..251e119 100644 --- a/include/libg1m/format/mcs/matrix.h +++ b/include/libg1m/format/mcs/cells.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/mcs/matrix.h -- description of the MCS matrix format. + * libg1m/format/mcs/cells.h -- description of the MCS cells format. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,19 +16,20 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_MCS_MATRIX_H -# define LIBG1M_FORMAT_MCS_MATRIX_H +#ifndef LIBG1M_FORMAT_MCS_CELLS_H +# define LIBG1M_FORMAT_MCS_CELLS_H # include # pragma pack(1) -/* Matrixes and vectors have exactly the same format; it's just that the OS - * refuses to have more that one row for vectors. +/* Lists, matrixes and vectors have exactly the same format. + * Lists only use the `height` (width is zero). + * Vectors are normal matrixes (the OS just won't use other rows). * - * They have this simple header: */ + * They have this header: */ -struct mcs_matheader { - /* undocumented */ - uint8_t undocumented[8]; +struct mcs_cellsheader { + /* undocumented: probably the title? */ + uint8_t title[8]; /* height */ uint16_t height; @@ -37,7 +38,10 @@ struct mcs_matheader { uint16_t width; /* re-undocumented */ - uint8_t undocumented2[4]; + uint8_t _undocumented[3]; + + /* undocumented byte (either 0x00 or 0x4F) */ + uint8_t _unknown; }; /* Then we have width*height BCD cells, which corresponds to the real parts, @@ -47,7 +51,9 @@ struct mcs_matheader { * first nibble set), it is followed by a list of the imaginary parts, that * has the same size that the real parts list, that is grouped the same way and * that contains actual things (and not crap) only if the complex bit is set - * on the real part. */ + * on the real part. + * + * Notice that imaginary parts in cells files require at least CASIOWIN 2.00. */ # pragma pack() -#endif /* LIBG1M_FORMAT_MCS_MATRIX_H */ +#endif /* LIBG1M_FORMAT_MCS_CELLS_H */ diff --git a/include/libg1m/format/mcs/list.h b/include/libg1m/format/mcs/list.h deleted file mode 100644 index 99b6fa8..0000000 --- a/include/libg1m/format/mcs/list.h +++ /dev/null @@ -1,49 +0,0 @@ -/* ***************************************************************************** - * libg1m/format/mcs/list.h -- description of the MCS list format. - * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey - * - * This file is part of libg1m. - * libg1m is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3.0 of the License, - * or (at your option) any later version. - * - * libg1m is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libg1m; if not, see . - * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_MCS_LIST_H -# define LIBG1M_FORMAT_MCS_LIST_H -# include -# pragma pack(1) - -/* Lists start with a header: */ - -struct mcs_listheader { - /* probably the title...? */ - uint8_t title[8]; - - /* the elements count */ - uint16_t element_count; - - /* undocumented (always 0?) */ - uint8_t undocumented[5]; - - /* undocumented (either 0x00 or 0x4F) */ - uint8_t undocumented2; -}; - -/* Then there is the list of real parts of the elements. - * If the complex bit is present on at least one of the elements (highest bit - * of the first nibble, which is the highest nibble of the exponent), then it - * is followed by the list of the imaginary parts of the elements. - * - * If the imaginary parts is here, only read the imaginary part of an element - * if his highest bit is set: it might contain complete crap! #Listbleed */ - -# pragma pack() -#endif /* LIBG1M_FORMAT_MCS_LIST_H */ diff --git a/include/libg1m/format/std/mcs.h b/include/libg1m/format/std/mcs.h index 6f83431..be54edc 100644 --- a/include/libg1m/format/std/mcs.h +++ b/include/libg1m/format/std/mcs.h @@ -73,8 +73,7 @@ struct mcs_fileheader { /* Beneath the file header, the file have different structures according to * their group name and MCS type. Pick your poison, once again! */ -# include -# include +# include # include # include # include diff --git a/include/libg1m/formatutils.h b/include/libg1m/formatutils.h index 0c2d730..bb56ba0 100644 --- a/include/libg1m/formatutils.h +++ b/include/libg1m/formatutils.h @@ -45,7 +45,7 @@ extern int g1m_maketype_std(const char *path, g1m_platform_t *platform, g1m_type_t *type); /* Standard Subheader */ -//# define g1m_subflag_check 0x0001 +/*# define g1m_subflag_check 0x0001*/ extern int g1m_maketype_sub(int raw_type, int raw_pf, unsigned int *flags, g1m_type_t *type, g1m_platform_t *platform); /* ************************************************************************** */ diff --git a/include/libg1m/handle.h b/include/libg1m/handle.h index d226ac4..0896a06 100644 --- a/include/libg1m/handle.h +++ b/include/libg1m/handle.h @@ -21,6 +21,7 @@ # include # include # include +# include /* ************************************************************************** */ /* Handle types and platforms */ diff --git a/include/libg1m/internals.h b/include/libg1m/internals.h index 064a36a..6bd2156 100644 --- a/include/libg1m/internals.h +++ b/include/libg1m/internals.h @@ -156,8 +156,7 @@ extern int g1m_encode_mcs_##NAME(const g1m_mcsfile_t *handle, \ g1m_buffer_t *buffer); G1M_MCSFUNC(var) -G1M_MCSFUNC(list) -G1M_MCSFUNC(matrix) +G1M_MCSFUNC(cells) G1M_MCSFUNC(picture) G1M_MCSFUNC(capture) G1M_MCSFUNC(program) @@ -193,8 +192,9 @@ G1M_ENCFUNC(addin) # define alloc_pixels(W, H) \ malloc(sizeof(uint32_t*) * (H) + sizeof(uint32_t) * (W) * (H)) # define prepare_pixels(I, W, H) { \ + unsigned int PIXPREP_y; \ uint32_t *PIXPREP_line = (uint32_t*)&(I)[(H)]; \ - for (unsigned int PIXPREP_y = 0; PIXPREP_y < (H); PIXPREP_y++) { \ + for (PIXPREP_y = 0; PIXPREP_y < (H); PIXPREP_y++) { \ (I)[PIXPREP_y] = PIXPREP_line; \ PIXPREP_line += (W); \ }} diff --git a/src/core/free.c b/src/core/free.c index da6a49c..be1c077 100644 --- a/src/core/free.c +++ b/src/core/free.c @@ -30,12 +30,14 @@ void g1m_free_line_content(g1m_line_t *line) { + int i; + if (line->type & (g1m_linetype_title | g1m_linetype_text | g1m_linetype_picture)) free(line->content); if (line->type & g1m_linetype_eact) { - for (int i = 0; i < line->count; i++) { + for (i = 0; i < line->count; i++) { g1m_free_line_content(line->lines[i]); free(line->lines[i]); } diff --git a/src/decode/mcs/matrix.c b/src/decode/mcs/cells.c similarity index 82% rename from src/decode/mcs/matrix.c rename to src/decode/mcs/cells.c index 2386f24..dd4cfeb 100644 --- a/src/decode/mcs/matrix.c +++ b/src/decode/mcs/cells.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * decode/mcs/matrix.c -- decode an MCS matrix. + * decode/mcs/cells.c -- decode an MCS cells tab. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -19,8 +19,8 @@ #include /** - * g1m_decode_mcs_matrix: - * Decode a matrix. + * g1m_decode_mcs_cells: + * Decode a cells tab. * * @arg handle the handle to make. * @arg buffer the buffer to read from. @@ -28,18 +28,18 @@ * @return the error code (0 if ok). */ -int g1m_decode_mcs_matrix(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, +int g1m_decode_mcs_cells(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, g1m_mcshead_t *head) { int err = g1m_error_alloc; + uint_fast32_t y, x; /* read header */ - DREAD(hd, mcs_matheader) - hd.width = be16toh(hd.width); - hd.height = be16toh(hd.height); + DREAD(hd, mcs_cellsheader) /* log info */ - uint_fast32_t w = hd.width, h = hd.height; + uint_fast32_t w = be16toh(hd.width), + h = (head->type & g1m_mcstype_list) ? 1 : be16toh(hd.height); log_info("Matrix size is %" PRIuFAST32 "*%" PRIuFAST32, w, h); /* make final head */ @@ -50,8 +50,7 @@ int g1m_decode_mcs_matrix(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, /* main copying loop */ g1m_mcscell_t **tab = (*handle)->cells; int one_imgn = 0; - for (uint_fast32_t y = 0; y < h; y++) - for (uint_fast32_t x = 0; x < w; x++) { + for (y = 0; y < h; y++) for (x = 0; x < w; x++) { /* read the cell */ g1m_bcd_t bcd; GDREAD(rawbcd, bcd) one_imgn |= g1m_bcd_frommcs(&rawbcd, &bcd); @@ -65,8 +64,7 @@ int g1m_decode_mcs_matrix(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, } /* check imaginary parts */ - if (one_imgn) for (uint_fast32_t y = 0; y < h; y++) - for (uint_fast32_t x = 0; x < w; x++) { + if (one_imgn) for (y = 0; y < h; y++) for (x = 0; x < w; x++) { g1m_bcd_t bcd; GDREAD(rawbcd, bcd) if (g1m_bcd_has_special(&tab[y][x].real)) { g1m_bcd_frommcs(&rawbcd, &bcd); @@ -77,8 +75,7 @@ int g1m_decode_mcs_matrix(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, #if LOGLEVEL <= ll_info /* logging loop */ char rbuf[G1M_BCD_GOODBUFSIZE], ibuf[G1M_BCD_GOODBUFSIZE]; - for (uint_fast32_t y = 0; y < h; y++) - for (uint_fast32_t x = 0; x < w; x++) { + for (y = 0; y < h; y++) for (x = 0; x < w; x++) { g1m_bcdtoa(&tab[y][x].real, rbuf, G1M_BCD_GOODBUFSIZE); if (g1m_bcd_has_special(&tab[y][x].real)) { diff --git a/src/decode/mcs/list.c b/src/decode/mcs/list.c deleted file mode 100644 index 85ad53c..0000000 --- a/src/decode/mcs/list.c +++ /dev/null @@ -1,89 +0,0 @@ -/* ***************************************************************************** - * decode/mcs/list.c -- decode an MCS list. - * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey - * - * This file is part of libg1m. - * libg1m is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3.0 of the License, - * or (at your option) any later version. - * - * libg1m is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libg1m; if not, see . - * ************************************************************************** */ -#include - -/** - * g1m_decode_mcs_list: - * Decode an List. - * - * @arg handle the handle to make. - * @arg buffer the buffer to read from. - * @arg head the pre-filled head to complete and use. - * @return the error code (0 if ok). - */ - -int g1m_decode_mcs_list(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, - g1m_mcshead_t *head) -{ - /* read header */ - DREAD(hd, mcs_listheader) - uint_fast16_t elcount = be16toh(hd.element_count); - log_info("Title is '%.8s'", hd.title); - - /* make final head */ - head->width = 1; - head->height = elcount; - int err = g1m_make_mcsfile(handle, head); - if (err) return (err); - - /* main copying loop */ - g1m_mcscell_t **tab = (*handle)->cells; int one_imgn = 0; - for (uint_fast32_t y = 0; y < elcount; y++) { - g1m_bcd_t bcd; GDREAD(rawbcd, bcd) - one_imgn |= g1m_bcd_frommcs(&rawbcd, &bcd); - - /* prepare index and store */ - tab[y][0] = (g1m_mcscell_t){ - .real = bcd, - .imgn = {}, - .flags = g1m_mcscellflag_used - }; - } - - /* main copying loop for imaginary parts */ - if (one_imgn) for (uint_fast32_t y = 0; y < elcount; y++) { - g1m_bcd_t bcd; GDREAD(rawbcd, bcd) - if (g1m_bcd_has_special(&tab[y][0].real)) { - g1m_bcd_frommcs(&rawbcd, &bcd); - tab[y][0].imgn = bcd; - } - } - -#if LOGLEVEL <= ll_info - /* logging loop */ - char rbuf[G1M_BCD_GOODBUFSIZE], ibuf[G1M_BCD_GOODBUFSIZE]; - for (uint_fast32_t y = 0; y < elcount; y++) { - g1m_bcdtoa(&tab[y][0].real, rbuf, G1M_BCD_GOODBUFSIZE); - if (g1m_bcd_has_special(&tab[y][0].real)) { - g1m_bcdtoa(&tab[y][0].imgn, ibuf, G1M_BCD_GOODBUFSIZE); - log_info("[%" PRIuFAST32 "] %si + %s", y, ibuf, rbuf); - } else - log_info("[%" PRIuFAST32 "] %s", y, rbuf); - } -#endif - - /* no error */ - return (0); - - /* in case */ -fail: - g1m_free_mcsfile(*handle); - *handle = NULL; - return (err); -} diff --git a/src/decode/mcs/var.c b/src/decode/mcs/var.c index 0d0ec5b..354c0be 100644 --- a/src/decode/mcs/var.c +++ b/src/decode/mcs/var.c @@ -31,9 +31,11 @@ int g1m_decode_mcs_var(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, g1m_mcshead_t *head) { - /* read the data */ uint_fast32_t length = head->size; - uint8_t buf[length]; + uint8_t *buf = alloca(length); + int i; + + /* read the data */ READ(buf, length) /* complete header */ @@ -44,7 +46,7 @@ int g1m_decode_mcs_var(g1m_mcsfile_t **handle, g1m_buffer_t *buffer, /* copy */ const mcs_bcd_t *b = (void*)buf; - for (int i = 0; i < head->count; i++) { + for (i = 0; i < head->count; i++) { g1m_bcd_frommcs(b++, &h->vars[i].real); g1m_bcd_frommcs(b++, &h->vars[i].imgn); h->vars[i].flags = g1m_mcscellflag_used; diff --git a/src/decode/std/eact.c b/src/decode/std/eact.c index a3a6751..158c6c5 100644 --- a/src/decode/std/eact.c +++ b/src/decode/std/eact.c @@ -39,6 +39,7 @@ static int eact_decode_content_eact(g1m_line_t *handle, uint8_t *buf, size_t bufsize) { int err; + unsigned long int i; /* initialize the handle */ handle->type = g1m_linetype_eact; @@ -76,7 +77,7 @@ static int eact_decode_content_eact(g1m_line_t *handle, uint8_t *buf, log_info("%" PRIu32 " lines to browse", ehd.line_count); if (ehd.line_count) lds[0].entry_offset = be32toh(lds[0].entry_offset << 8); - for (uint_fast32_t i = 0; i < ehd.line_count; i++) { + for (i = 0; i < ehd.line_count; i++) { /* allocate line */ g1m_line_t *line = malloc(sizeof(g1m_line_t)); err = g1m_error_alloc; diff --git a/src/decode/std/mcs.c b/src/decode/std/mcs.c index 7c6d743..7a0d394 100644 --- a/src/decode/std/mcs.c +++ b/src/decode/std/mcs.c @@ -37,9 +37,9 @@ struct mcs_corresp { #define TTERM {0, NULL} static struct mcs_corresp mcs_types[] = { {g1m_mcstype_program, FUNC(program)}, - {g1m_mcstype_list, FUNC(list)}, - {g1m_mcstype_mat, FUNC(matrix)}, - {g1m_mcstype_vct, FUNC(matrix)}, + {g1m_mcstype_list, FUNC(cells)}, + {g1m_mcstype_mat, FUNC(cells)}, + {g1m_mcstype_vct, FUNC(cells)}, {g1m_mcstype_spreadsheet, FUNC(spreadsheet)}, {g1m_mcstype_pict, FUNC(picture)}, {g1m_mcstype_capt, FUNC(capture)}, @@ -213,6 +213,7 @@ int g1m_decode_std_mcs(g1m_handle_t **h, g1m_buffer_t *buffer, int err = g1m_error_alloc; /* get number of subparts from the standard header */ uint_fast16_t num = std->number; + uint_fast32_t i; /* make the handle */ err = g1m_make_mcs(h, num); @@ -233,7 +234,7 @@ int g1m_decode_std_mcs(g1m_handle_t **h, g1m_buffer_t *buffer, log_info("%d mcs files to browse in that group", hd.subcount); /* foreach subpart */ - for (uint_fast32_t i = 0; i < hd.subcount; i++) { + for (i = 0; i < hd.subcount; i++) { /* get the part header */ GDREAD(fhd, mcs_fileheader) fhd.datalength = be32toh(fhd.datalength); diff --git a/src/encode/addin.c b/src/encode/addin.c index b0e4b24..e194e12 100644 --- a/src/encode/addin.c +++ b/src/encode/addin.c @@ -45,6 +45,8 @@ int g1m_announce_addin(g1m_handle_t *handle, size_t *size) int g1m_encode_addin(g1m_handle_t *handle, g1m_buffer_t *buffer) { + size_t i; uint8_t *b; + /* make the StandardHeader up */ size_t filesize; g1m_announce_addin(handle, &filesize); struct standard_header std = { @@ -56,8 +58,8 @@ int g1m_encode_addin(g1m_handle_t *handle, g1m_buffer_t *buffer) .number = 0xFFFF}; /* reverse it and output it */ - uint8_t *b = (void*)&std; - for (size_t i = 0; i < sizeof(struct standard_header); i++) b[i] = ~b[i]; + b = (void*)&std; + for (i = 0; i < sizeof(struct standard_header); i++) b[i] = ~b[i]; DWRITE(std) /* make the add-in subheader up and output it */ diff --git a/src/encode/mcs/matrix.c b/src/encode/mcs/cells.c similarity index 71% rename from src/encode/mcs/matrix.c rename to src/encode/mcs/cells.c index aff0259..0d84516 100644 --- a/src/encode/mcs/matrix.c +++ b/src/encode/mcs/cells.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * encode/mcs/matrix.c -- encode an MCS matrix. + * encode/mcs/cells.c -- encode an MCS cells tab. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -19,7 +19,7 @@ #include /** - * g1m_announce_mcs_matrix: + * g1m_announce_mcs_cells: * Announce a matrix's size. * * @arg handle the handle to make the size out of. @@ -27,16 +27,16 @@ * @return the error code (0 if ok). */ -int g1m_announce_mcs_matrix(const g1m_mcsfile_t *handle, size_t *sz) +int g1m_announce_mcs_cells(const g1m_mcsfile_t *handle, size_t *sz) { - /* base size of the matrix */ + unsigned int y, x; size_t content_size = handle->head.height * handle->head.width * sizeof(mcs_bcd_t); - *sz += sizeof(struct mcs_matheader) + content_size; + *sz += sizeof(struct mcs_cellsheader) + content_size; /* check if there's an imaginary part */ - for (unsigned int y = 0; y < handle->head.height; y++) - for (unsigned int x = 0; x < handle->head.width; x++) { + for (y = 0; y < handle->head.height; y++) + for (x = 0; x < handle->head.width; x++) { if (g1m_bcd_has_special(&handle->cells[y][x].real)) { *sz += content_size; return (0); @@ -48,7 +48,7 @@ int g1m_announce_mcs_matrix(const g1m_mcsfile_t *handle, size_t *sz) } /** - * g1m_encode_mcs_matrix: + * g1m_encode_mcs_cells: * Encode a matrix. * * @arg handle the handle to encode. @@ -56,19 +56,22 @@ int g1m_announce_mcs_matrix(const g1m_mcsfile_t *handle, size_t *sz) * @return the error code (0 if ok). */ -int g1m_encode_mcs_matrix(const g1m_mcsfile_t *handle, g1m_buffer_t *buffer) +int g1m_encode_mcs_cells(const g1m_mcsfile_t *handle, g1m_buffer_t *buffer) { - /* write the header */ - struct mcs_matheader hd = { + unsigned int y, x; + struct mcs_cellsheader hd = { .height = htobe16(handle->head.height), - .width = htobe16(handle->head.width), - .undocumented2 = {0} }; + .width = (handle->head.type & g1m_mcstype_list) ? 1 + : htobe16(handle->head.width), + ._undocumented = {0}}; + + /* write the header */ DWRITE(hd) /* write the real parts */ int one_imgn = 0; - for (unsigned int y = 0; y < handle->head.height; y++) - for (unsigned int x = 0; x < handle->head.width; x++) { + for (y = 0; y < handle->head.height; y++) + for (x = 0; x < handle->head.width; x++) { mcs_bcd_t rawbcd; g1m_bcd_tomcs(&handle->cells[y][x].real, &rawbcd); DWRITE(rawbcd) @@ -76,8 +79,8 @@ int g1m_encode_mcs_matrix(const g1m_mcsfile_t *handle, g1m_buffer_t *buffer) } /* write the imaginary parts */ - if (one_imgn) for (unsigned int y = 0; y < handle->head.height; y++) - for (unsigned int x = 0; x < handle->head.width; x++) { + if (one_imgn) for (y = 0; y < handle->head.height; y++) + for (x = 0; x < handle->head.width; x++) { mcs_bcd_t rawbcd; g1m_bcd_tomcs(&handle->cells[y][x].imgn, &rawbcd); DWRITE(rawbcd) } diff --git a/src/encode/mcs/list.c b/src/encode/mcs/list.c deleted file mode 100644 index e5281aa..0000000 --- a/src/encode/mcs/list.c +++ /dev/null @@ -1,81 +0,0 @@ -/* ***************************************************************************** - * encode/mcs/list.c -- encode an MCS list. - * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey - * - * This file is part of libg1m. - * libg1m is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3.0 of the License, - * or (at your option) any later version. - * - * libg1m is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libg1m; if not, see . - * ************************************************************************** */ -#include - -/** - * g1m_announce_mcs_list: - * Announce a list's size. - * - * @arg handle the handle to make the size out of. - * @arg sz the size to contribute to. - * @return the error code (0 if ok). - */ - -int g1m_announce_mcs_list(const g1m_mcsfile_t *handle, size_t *sz) -{ - /* base size of the list */ - size_t content_size = handle->head.height * sizeof(mcs_bcd_t); - *sz += sizeof(struct mcs_listheader) + content_size; - - /* check if there's at least one complex */ - for (unsigned int i = 0; i < handle->head.height; i++) - if (g1m_bcd_has_special(&handle->cells[i][0].real)) { - *sz += content_size; - return (0); - } - - /* no error! */ - return (0); -} - -/** - * g1m_encode_mcs_list: - * Encode a list. - * - * @arg handle the handle to make. - * @arg buffer the buffer to write to. - * @return the error code (0 if ok). - */ - -int g1m_encode_mcs_list(const g1m_mcsfile_t *handle, g1m_buffer_t *buffer) -{ - /* make the header */ - struct mcs_listheader hd = { - .element_count = htobe16(handle->head.height), - .undocumented = {0}}; - DWRITE(hd) - - /* write the real parts */ - int one_imgn = 0; - for (unsigned int i = 0; i < handle->head.height; i++) { - mcs_bcd_t rawbcd; g1m_bcd_tomcs(&handle->cells[i][0].real, &rawbcd); - DWRITE(rawbcd) - - one_imgn |= g1m_bcd_has_special(&handle->cells[i][0].real); - } - - /* write the imaginary parts */ - if (one_imgn) for (unsigned int i = 0; i < handle->head.height; i++) { - mcs_bcd_t rawbcd; g1m_bcd_tomcs(&handle->cells[i][0].imgn, &rawbcd); - DWRITE(rawbcd) - } - - /* no error */ - return (0); -} diff --git a/src/encode/mcs/var.c b/src/encode/mcs/var.c index c09ed07..fdaade7 100644 --- a/src/encode/mcs/var.c +++ b/src/encode/mcs/var.c @@ -44,7 +44,10 @@ int g1m_announce_mcs_var(const g1m_mcsfile_t *handle, size_t *sz) int g1m_encode_mcs_var(const g1m_mcsfile_t *handle, g1m_buffer_t *buffer) { - for (int i = 0; i < handle->head.count; i++) { + int i; + + /* encode each variable */ + for (i = 0; i < handle->head.count; i++) { /* write real and imaginary part */ mcs_bcd_t rawbcd; g1m_bcd_tomcs(&handle->vars[i].real, &rawbcd); DWRITE(rawbcd) diff --git a/src/manage/handle.c b/src/manage/handle.c index cb660cb..1bbd572 100644 --- a/src/manage/handle.c +++ b/src/manage/handle.c @@ -251,6 +251,8 @@ fail: void g1m_free(g1m_handle_t *handle) { + int i; + /* check if there is something to free */ if (!handle) return ; @@ -270,7 +272,7 @@ void g1m_free(g1m_handle_t *handle) /* foreach file in mcs */ g1m_mcsfile_t **files = handle->files; int file_count = handle->count; - for (int i = 0; i < file_count; i++) { + for (i = 0; i < file_count; i++) { /* free the file if exists */ if (files[i]) g1m_free_mcsfile(files[i]); } @@ -280,7 +282,7 @@ void g1m_free(g1m_handle_t *handle) /* messages time! */ if (handle->type & g1m_type_lang && handle->messages) { - for (int i = 0; i < handle->count; i++) + for (i = 0; i < handle->count; i++) free(handle->messages[i]); free(handle->messages); } @@ -288,7 +290,7 @@ void g1m_free(g1m_handle_t *handle) /* function keys time! */ if (handle->type & g1m_type_fkey && handle->fkeys) { - for (int i = 0; i < handle->count; i++) + for (i = 0; i < handle->count; i++) free(handle->fkeys[i]); free(handle->fkeys); } diff --git a/src/manage/mcs.c b/src/manage/mcs.c index e8195ef..fef55a5 100644 --- a/src/manage/mcs.c +++ b/src/manage/mcs.c @@ -37,10 +37,11 @@ int g1m_mcs_insert(g1m_handle_t *handle, g1m_mcsfile_t **tofile, const g1m_mcshead_t *head) { g1m_mcsfile_t **pfile = NULL; *tofile = NULL; + int i, istyp, err; /* look if this file isn't already in the tab */ - int istyp = g1m_mcshead_uses_id(head); - for (int i = 0; i < handle->count; i++) { + istyp = g1m_mcshead_uses_id(head); + for (i = 0; i < handle->count; i++) { g1m_mcsfile_t *file = handle->files[i]; if (!file) { pfile = &handle->files[i]; @@ -104,7 +105,7 @@ int g1m_mcs_insert(g1m_handle_t *handle, g1m_mcsfile_t **tofile, found:; /* make the file */ - int err = g1m_make_mcsfile(pfile, head); + err = g1m_make_mcsfile(pfile, head); if (err) return (err); /* return it */ @@ -126,11 +127,14 @@ found:; typedef int (*g1m_compare_mcsfiles_t)(const void*, const void*); int g1m_mcs_sort(g1m_handle_t *handle) { + int i; + + /* make checks */ if (handle->type != g1m_type_mcs) return (g1m_error_op); if (handle->platform != g1m_platform_fx) return (g1m_error_op); /* correct each head */ - for (int i = 0; i < handle->count; i++) { + for (i = 0; i < handle->count; i++) { int err = g1m_correct_mcsfile_head(&handle->files[i]->head); if (err) return (err); } diff --git a/src/manage/mcsfile.c b/src/manage/mcsfile.c index bde3120..f7610bf 100644 --- a/src/manage/mcsfile.c +++ b/src/manage/mcsfile.c @@ -32,6 +32,8 @@ int g1m_make_mcsfile(g1m_mcsfile_t **handle, const g1m_mcshead_t *rawhead) { + unsigned int y; int i, j; + /* allocate the handle */ *handle = malloc(sizeof(g1m_mcsfile_t)); if (!handle) return (g1m_error_alloc); @@ -54,7 +56,7 @@ int g1m_make_mcsfile(g1m_mcsfile_t **handle, const g1m_mcshead_t *rawhead) h->cells[0] = malloc(sizeof(g1m_mcscell_t) * wd * ht); if (!h->cells[0]) { free(h->cells); goto fail; } - for (unsigned int y = 1; y < ht; y++) + for (y = 1; y < ht; y++) h->cells[y] = &h->cells[0][h->head.width * y]; } break; @@ -82,10 +84,10 @@ int g1m_make_mcsfile(g1m_mcsfile_t **handle, const g1m_mcshead_t *rawhead) } /* allocate */ - for (int i = 0; i < head->count; i++) { + for (i = 0; i < head->count; i++) { h->pics[i] = alloc_pixels(head->width, head->height); if (!h->pics[i]) { - for (int j = 0; j < i; j++) + for (j = 0; j < i; j++) free(h->pics[j]); if (h->pics != &h->pic) free(h->pics); @@ -94,7 +96,7 @@ int g1m_make_mcsfile(g1m_mcsfile_t **handle, const g1m_mcshead_t *rawhead) } /* prepare */ - for (int i = 0; i < head->count; i++) + for (i = 0; i < head->count; i++) prepare_pixels(h->pics[i], head->width, head->height) break; @@ -129,11 +131,13 @@ fail: int g1m_prepare_mcsfile_heads(g1m_mcshead_t *head, g1m_mcshead_t *heads) { + int i; + /* check if the head is a multiple head */ if (~head->flags & g1m_mcsflag_multiple) return (g1m_error_op); /* copy the data in each head */ - for (int i = 0; i < head->count; i++) { + for (i = 0; i < head->count; i++) { heads[i] = *head; heads[i].flags &= ~g1m_mcsflag_multiple; } @@ -151,6 +155,8 @@ int g1m_prepare_mcsfile_heads(g1m_mcshead_t *head, g1m_mcshead_t *heads) void g1m_free_mcsfile(g1m_mcsfile_t *handle) { + int i; + /* check if exists */ if (!handle) return ; @@ -166,7 +172,7 @@ void g1m_free_mcsfile(g1m_mcsfile_t *handle) /* free the set of pixels */ case g1m_mcstype_pict: case g1m_mcstype_capt: - for (int i = 0; i < handle->head.count; i++) + for (i = 0; i < handle->head.count; i++) free(handle->pics[i]); if (handle->pics != &handle->pic) free(handle->pics); diff --git a/src/type/cas/datatype.c b/src/type/cas/datatype.c index dc34eff..b748ccc 100644 --- a/src/type/cas/datatype.c +++ b/src/type/cas/datatype.c @@ -65,34 +65,34 @@ static struct type_corresp cas_groups[] = { CAPT("DD", g1m_pictureformat_4bit_mono), /* not implemented yet */ - UNIMPLEMENTED("AA"), // dynamic graph functions - UNIMPLEMENTED("AD"), // variable memory - UNIMPLEMENTED("AL"), // all - UNIMPLEMENTED("AM"), // alpha variable memory - UNIMPLEMENTED("BU"), // backup - UNIMPLEMENTED("DM"), // defined memory - UNIMPLEMENTED("EN"), // one editor file - UNIMPLEMENTED("FN"), // set of editor files - UNIMPLEMENTED("FT"), // ??? (cafix) - UNIMPLEMENTED("F1"), // one function memory - UNIMPLEMENTED("F6"), // set of function memories - UNIMPLEMENTED("GA"), // set of graph functions - UNIMPLEMENTED("GF"), // graph zoom factor (graph function?) - UNIMPLEMENTED("GM"), // gmem (cafix) - UNIMPLEMENTED("GR"), // graph range - UNIMPLEMENTED("GT"), // function table - UNIMPLEMENTED("MA"), // set of matrices - UNIMPLEMENTED("PC"), // picture from 9xxx (cafix) - UNIMPLEMENTED("PD"), // polynomial equations - UNIMPLEMENTED("RF"), // ??? (cafix) - UNIMPLEMENTED("RR"), // ??? (cafix) - UNIMPLEMENTED("RT"), // recursion table - UNIMPLEMENTED("SD"), // simultaneous equations - UNIMPLEMENTED("SE"), // equation (cafix) - UNIMPLEMENTED("SR"), // linear regression data - UNIMPLEMENTED("SS"), // standard deviation data - UNIMPLEMENTED("TR"), // ??? (cafix) - UNIMPLEMENTED("WD"), // window data (cafix) + UNIMPLEMENTED("AA"), /* dynamic graph functions */ + UNIMPLEMENTED("AD"), /* variable memory */ + UNIMPLEMENTED("AL"), /* all */ + UNIMPLEMENTED("AM"), /* alpha variable memory */ + UNIMPLEMENTED("BU"), /* backup */ + UNIMPLEMENTED("DM"), /* defined memory */ + UNIMPLEMENTED("EN"), /* one editor file */ + UNIMPLEMENTED("FN"), /* set of editor files */ + UNIMPLEMENTED("FT"), /* ??? (cafix) */ + UNIMPLEMENTED("F1"), /* one function memory */ + UNIMPLEMENTED("F6"), /* set of function memories */ + UNIMPLEMENTED("GA"), /* set of graph functions */ + UNIMPLEMENTED("GF"), /* graph zoom factor (graph function?) */ + UNIMPLEMENTED("GM"), /* gmem (cafix) */ + UNIMPLEMENTED("GR"), /* graph range */ + UNIMPLEMENTED("GT"), /* function table */ + UNIMPLEMENTED("MA"), /* set of matrices */ + UNIMPLEMENTED("PC"), /* picture from 9xxx (cafix) */ + UNIMPLEMENTED("PD"), /* polynomial equations */ + UNIMPLEMENTED("RF"), /* ??? (cafix) */ + UNIMPLEMENTED("RR"), /* ??? (cafix) */ + UNIMPLEMENTED("RT"), /* recursion table */ + UNIMPLEMENTED("SD"), /* simultaneous equations */ + UNIMPLEMENTED("SE"), /* equation (cafix) */ + UNIMPLEMENTED("SR"), /* linear regression data */ + UNIMPLEMENTED("SS"), /* standard deviation data */ + UNIMPLEMENTED("TR"), /* ??? (cafix) */ + UNIMPLEMENTED("WD"), /* window data (cafix) */ /* terminating entry */ TTERM diff --git a/src/utils/extension.c b/src/utils/extension.c index 0be6c47..83098c2 100644 --- a/src/utils/extension.c +++ b/src/utils/extension.c @@ -31,6 +31,8 @@ int g1m_getext(const char *path, char *buf, size_t n) { + int i; + /* no size? */ if (!n) return (0); @@ -44,7 +46,7 @@ int g1m_getext(const char *path, char *buf, size_t n) /* copy it */ buf[n - 1] = 0; strncpy(buf, ext, n - 1); - for (int i = 0; buf[i]; i++) + for (i = 0; buf[i]; i++) buf[i] = tolower(buf[i]); /* return the size */ diff --git a/src/utils/picture.c b/src/utils/picture.c index 6997fab..47d692f 100644 --- a/src/utils/picture.c +++ b/src/utils/picture.c @@ -55,13 +55,15 @@ static const uint32_t prizm_colors[16] = { int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, const unsigned char *raw, unsigned int width, unsigned int height) { - int msk; const unsigned char *o, *g, *b, *r2; size_t off; + const unsigned char *o, *g, *b, *r2; /* pointers on the data */ + int msk; size_t off; /* mask and offset */ + unsigned int y, x, bx; /* coordinates */ switch (format) { case g1m_pictureformat_1bit: - for (unsigned int y = 0; y < height; y++) { + for (y = 0; y < height; y++) { msk = 0x80; - for (unsigned int x = 0; x < width; x++) { + for (x = 0; x < width; x++) { /* get pixel */ pixels[y][x] = (*raw & msk) ? 0x000000 : 0xFFFFFF; @@ -74,9 +76,9 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, break; case g1m_pictureformat_1bit_r: - for (unsigned int y = 0; y < height; y++) { + for (y = 0; y < height; y++) { msk = 0x80; - for (unsigned int x = 0; x < width; x++) { + for (x = 0; x < width; x++) { /* get pixel */ pixels[y][x] = (*raw & msk) ? 0xFFFFFF : 0x000000; @@ -92,8 +94,8 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, raw = &raw[(height * width / 2) * 2]; case g1m_pictureformat_1bit_packed: msk = 0x80; - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) { /* get pixel */ pixels[y][x] = (*raw & msk) ? 0x000000 : 0xFFFFFF; @@ -105,8 +107,8 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_1bit_packed_r: msk = 0x80; - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) { /* get pixel */ pixels[y][x] = (*raw & msk) ? 0xFFFFFF : 0x000000; @@ -117,10 +119,10 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, break; case g1m_pictureformat_1bit_old: - for (unsigned int bx = width - 8; bx != (unsigned int)-8; bx -= 8) - for (unsigned int y = height - 1; y != (unsigned int)-1; y--) { + for (bx = width - 8; bx != (unsigned int)-8; bx -= 8) + for (y = height - 1; y != (unsigned int)-1; y--) { msk = 0x80; - for (unsigned int x = bx; x < bx + 8; x++) { + for (x = bx; x < bx + 8; x++) { /* get pixel */ pixels[y][x] = (*raw & msk) ? 0x000000 : 0xFFFFFF; @@ -135,8 +137,8 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_2bit_dual: msk = 0x80; r2 = &raw[height * width / 8]; - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) { /* get pixel */ uint32_t val = (!!(*raw & msk) << 1) | !!(*r2 & msk); pixels[y][x] = dual2b_colors[val]; @@ -149,8 +151,8 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_4bit_code: msk = 0xF0; - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) { /* get pixel */ uint32_t px = *raw & msk; px = px | (px >> 4); pixels[y][x] = prizm_colors[px & 0x0F]; @@ -163,8 +165,8 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_4bit_rgb: msk = 0xF0; - for (unsigned int y = height - 1; y != (unsigned int)-1; y--) - for (unsigned int x = width - 1; x != (unsigned int)-1; x--) { + for (y = height - 1; y != (unsigned int)-1; y--) + for (x = width - 1; x != (unsigned int)-1; x--) { /* get pixel */ uint32_t val = *raw & msk; val |= val >> 4; uint32_t px = 0; @@ -181,10 +183,10 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_4bit_color:; off = height * width / 8; o = raw; g = &raw[off]; b = &raw[off * 2]; - for (unsigned int bx = width - 8; bx != (unsigned int)-8; bx -= 8) - for (unsigned int y = height - 1; y != (unsigned int)-1; y--) { + for (bx = width - 8; bx != (unsigned int)-8; bx -= 8) + for (y = height - 1; y != (unsigned int)-1; y--) { msk = 0x80; - for (unsigned int x = bx; x < bx + 8; x++) { + for (x = bx; x < bx + 8; x++) { /* get pixel */ if (*o & msk) pixels[y][x] = 0xFF8C00; /* orange */ else if (*g & msk) pixels[y][x] = 0x00FF00; /* green */ @@ -201,8 +203,8 @@ int g1m_decode_picture(uint32_t **pixels, g1m_pictureformat_t format, break; case g1m_pictureformat_16bit: - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) { /* get pixel */ uint32_t one = raw[0], two = raw[1]; uint32_t px = (one >> 3) << (16 + 3); @@ -242,13 +244,14 @@ int g1m_encode_picture(const uint32_t **pixels, g1m_pictureformat_t format, unsigned char *raw, unsigned int width, unsigned int height) { int msk; + unsigned int y, x; switch (format) { case g1m_pictureformat_1bit: memset(raw, 0, g1m_picturesize_1bit(width, height)); - for (unsigned int y = 0; y < height; y++) { + for (y = 0; y < height; y++) { msk = 0x80; - for (unsigned int x = 0; x < width; x++) { + for (x = 0; x < width; x++) { /* get pixel */ if (!pixels[y][x]) *raw |= msk; @@ -262,9 +265,9 @@ int g1m_encode_picture(const uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_1bit_r: memset(raw, 0, g1m_picturesize_1bit(width, height)); - for (unsigned int y = 0; y < height; y++) { + for (y = 0; y < height; y++) { msk = 0x80; - for (unsigned int x = 0; x < width; x++) { + for (x = 0; x < width; x++) { /* get pixel */ if (pixels[y][x]) *raw |= msk; @@ -278,8 +281,8 @@ int g1m_encode_picture(const uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_1bit_packed: msk = 0x80; - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) { /* set pixel */ if (pixels[y][x] & 0xFFFFFF) *raw = msk; @@ -291,8 +294,7 @@ int g1m_encode_picture(const uint32_t **pixels, g1m_pictureformat_t format, case g1m_pictureformat_4bit_code: msk = 0xF0; - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) for (x = 0; x < width; x++) { /* set pixel */ uint32_t color = 0; color |= !!(0xFF0000 & pixels[y][x]) << 2; @@ -307,8 +309,7 @@ int g1m_encode_picture(const uint32_t **pixels, g1m_pictureformat_t format, break; case g1m_pictureformat_16bit: - for (unsigned int y = 0; y < height; y++) - for (unsigned int x = 0; x < width; x++) { + for (y = 0; y < height; y++) for (x = 0; x < width; x++) { /* set pixel */ uint32_t r = (pixels[y][x] & (0x1F << 19)) >> 19; uint32_t g = (pixels[y][x] & (0x3F << 10)) >> 10;