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

173 lines
4.6 KiB
C
Raw Normal View History

2016-12-01 13:34:10 +01:00
/* ************************************************************************** */
/* _____ _ */
/* utils/type.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/01 13:33:41 |___/ */
/* */
/* ************************************************************************** */
#include <libg1m/internals.h>
/* ************************************************************************** */
/* Local types */
/* ************************************************************************** */
2016-12-02 16:18:35 +01:00
/* Flags */
#define nochk_controlone 0x01
#define nochk_controltwo 0x02
2016-12-01 13:34:10 +01:00
/* Subtype correspondance type */
struct type_info {
/* identification */
const char *type;
/* info */
const char *info;
2016-12-02 16:18:35 +01:00
unsigned int flags;
2016-12-01 13:34:10 +01:00
/* actions */
int (*read)(g1m_t*, FILE*, struct standard_header*);
};
/* Main type correspondance type */
struct main_info {
/* identification */
const char *type;
/* subtypes */
struct type_info *subtypes;
};
/* ************************************************************************** */
/* Correspondances */
/* ************************************************************************** */
/* Common magic types */
#define magic_common "\x00\x10\x00\x10\x00"
#define cp_magic "\x00\x01\x00\x01\x00"
/* Main types */
static struct main_info types[] = {
/* USBPower (the most common one) */
{"USBPower", (struct type_info[]){
/* add-ins */
{"\xf3" magic_common,
"add-in", 0,
g1m_parse_addin},
{"\x2c" cp_magic,
"fx-CG add-in", 0,
g1m_parse_addin_cg},
/* MCS */
{"\x31" magic_common,
"mcs", 0,
g1m_parse_mcs},
{"\x62" magic_common,
"mcs (g2r)", 0,
g1m_parse_mcs},
{"\x75" magic_common,
"mcs (fx-CG)", 0,
g1m_parse_mcs},
/* Language */
{"\x12" magic_common,
"fx language file", 0,
g1m_parse_lang},
/* E-Activities */
{"\x49" magic_common,
"e-activity (document)", 0,
g1m_parse_eact},
/* Pictures */
{"\x7d" magic_common,
"fx-CG picture", 0,
g1m_parse_g3p},
{}
}},
/* Ly755 (Classpad-specific) */
{"Ly755 ", (struct type_info[]){
{"\x2c" cp_magic,
"fx-CG language file", 0,
g1m_parse_lang_cg},
{}
}},
/* CASIO (only used for c2p...?) */
{"CASIO\0\0\0", (struct type_info[]){
{"c2p\0\0\0",
"Classpad picture", nochk_controlone | nochk_controltwo,
g1m_parse_c2p},
{}
}},
/* Blank (hack) */
{"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", (struct type_info[]){
{"\xFF\xFF\xFF\xFF\xFF\xFF",
"CASIO archive", nochk_controlone | nochk_controltwo,
g1m_parse_g1s},
2016-12-17 00:46:48 +01:00
{"\xFF\xFF\xFF\xFF\xFF\xFF",
"Function keys file", 0,
g1m_parse_fkey},
{}
}},
/* terminating */
2016-12-01 13:34:10 +01:00
{}
};
/* ************************************************************************** */
/* Main functions */
/* ************************************************************************** */
/**
* g1m_get_type_info:
* Get type info.
*
* @arg main_id The main ID (at least 8 bytes).
* @arg subtype The subtype (at least 6 bytes).
* @arg info Pointer to the info string to set.
2016-12-02 16:18:35 +01:00
* @arg check_one Check first control byte.
* @arg check_two Check second control byte.
2016-12-01 13:34:10 +01:00
* @arg read Pointer to the read callback to set.
* @return If there was an error.
*/
int g1m_get_type_info(unsigned char *main_id, unsigned char *subtype,
2016-12-02 16:18:35 +01:00
const char **info, int *check_one, int *check_two,
int (**rd)(g1m_t*, FILE*, struct standard_header*))
2016-12-01 13:34:10 +01:00
{
/* look for main_id */
struct main_info *mt = types;
while (mt->type) {
if (!memcmp(mt->type, main_id, 8))
break ;
mt++;
}
if (!mt->type) {
log_fatal("Main ID not recognized:");
logm_info(main_id, 8);
return (1);
}
/* look for subtype */
struct type_info *sub = mt->subtypes;
while (sub->type) {
if (!memcmp(sub->type, subtype, 6))
break ;
sub++;
}
if (!sub->type) {
log_fatal("Type not managed (yet?):");
logm_info(subtype, 6);
return (1);
}
/* fill in info and return */
if (info) *info = sub->info;
if (rd) *rd = sub->read;
2016-12-02 16:18:35 +01:00
if (check_one) *check_one = ~sub->flags & nochk_controlone;
if (check_two) *check_two = ~sub->flags & nochk_controltwo;
2016-12-01 13:34:10 +01:00
return (0);
}