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/type/sub.c

95 lines
3.1 KiB
C

/* *****************************************************************************
* type/sub.c -- extract the file type out of raw substd identification data.
* 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 <ctype.h>
/* ************************************************************************** */
/* Local types */
/* ************************************************************************** */
/* Type correspondance type */
struct type_info {
/* identification */
int raw_platform;
int raw_type;
/* types */
g1m_platform_t platform;
g1m_type_t type;
};
/* ************************************************************************** */
/* Correspondances */
/* ************************************************************************** */
/* Terminate type list */
#define TTERM {0, 0, 0, 0}
/* Platforms and types */
#define p_cp 0x00
#define p_cg 0x01
#define t_addin 0x01
#define t_fkey 0x02
#define t_lang 0x04
/* Main types */
static struct type_info types[] = {
/* fx-CP types */
{p_cp, t_addin, g1m_platform_cp, g1m_type_addin},
/* fx-CG types */
{p_cg, t_addin, g1m_platform_cg, g1m_type_addin},
{p_cg, t_fkey, g1m_platform_cg, g1m_type_fkey},
{p_cg, t_lang, g1m_platform_cg, g1m_type_lang},
/* sentinel */
TTERM
};
/* ************************************************************************** */
/* Main functions */
/* ************************************************************************** */
/**
* g1m_maketype_sub:
* Get type info from Standard Subheader.
*
* @arg raw_type The raw type.
* @arg raw_pf The raw platform.
* @arg flags The flags to set.
* @arg type The type to get.
* @arg platform The platform to get.
* @return If there was an error.
*/
int g1m_maketype_sub(int raw_type, int raw_pf, unsigned int *flags,
g1m_type_t *type, g1m_platform_t *platform)
{
/* look for the correspondance */
struct type_info *c = types - 1;
while ((++c)->platform) {
if (c->raw_type == raw_type && c->raw_platform == raw_pf)
break;
}
if (!c->platform) return (g1m_error_unknown);
/* fill things */
if (flags) *flags = 0;
if (platform) *platform = c->platform;
if (type) *type = c->type;
return (0);
}