94 lines
2.9 KiB
C
94 lines
2.9 KiB
C
/* *****************************************************************************
|
|
* decode/std/mcs.c -- decode an MCS archive file.
|
|
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
* ************************************************************************** */
|
|
#include <libg1m/internals.h>
|
|
#include <stdlib.h>
|
|
|
|
/**
|
|
* g1m_decode_std_mcs:
|
|
* Decode an MCS file, after the Standard Header.
|
|
*
|
|
* @arg h the handle to make.
|
|
* @arg buffer the buffer to read from.
|
|
* @arg num number of sizes.
|
|
* @return the error code (0 if ok).
|
|
*/
|
|
|
|
int g1m_decode_std_mcs(g1m_handle_t **h, g1m_buffer_t *buffer,
|
|
struct standard_header *std)
|
|
{
|
|
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);
|
|
if (err) return (err);
|
|
g1m_handle_t *handle = *h;
|
|
|
|
/* read all of the parts */
|
|
log_info("%" PRIuFAST16 " total mcs files to browse", num);
|
|
for (handle->g1m_handle_count = 0; handle->g1m_handle_count < (int)num;) {
|
|
/* get the subheader */
|
|
GDREAD(hd, mcs_subheader)
|
|
|
|
/* correct endianess */
|
|
hd.subcount = be32toh(hd.subcount);
|
|
|
|
/* log info about part */
|
|
log_info("New group! Group name is '%.16s'.", hd.intname);
|
|
log_info("%d mcs files to browse in that group", hd.subcount);
|
|
|
|
/* foreach subpart */
|
|
for (i = 0; i < hd.subcount; i++) {
|
|
/* get the part header */
|
|
GDREAD(fhd, mcs_fileheader)
|
|
fhd.datalength = be32toh(fhd.datalength);
|
|
|
|
/* log info about the subpart */
|
|
log_info("[%" PRIuFAST32 "] directory name is '%.8s'",
|
|
i, fhd.dirname);
|
|
log_info("[%" PRIuFAST32 "] filename is '%.8s'", i, fhd.filename);
|
|
log_info("[%" PRIuFAST32 "] data length is %" PRIu32,
|
|
i, fhd.datalength);
|
|
|
|
/* decode the head */
|
|
g1m_mcshead_t head;
|
|
g1m_decode_mcsfile_head(&head, fhd.filetype, hd.intname,
|
|
fhd.dirname, fhd.filename, fhd.datalength);
|
|
|
|
/* decode */
|
|
handle->g1m_handle_files[handle->g1m_handle_count] = NULL;
|
|
err = g1m_decode_mcsfile(
|
|
&handle->g1m_handle_files[handle->g1m_handle_count],
|
|
&head, buffer);
|
|
if (err) goto fail;
|
|
handle->g1m_handle_count++;
|
|
}
|
|
}
|
|
|
|
/* no error */
|
|
return (0);
|
|
|
|
/* was error! */
|
|
fail:
|
|
g1m_free(*h); *h = NULL;
|
|
return (err);
|
|
}
|