aboutsummaryrefslogtreecommitdiff
path: root/lib/file/corresp/standard_sub.c
blob: 33d713c7a56a218bef5dbb89e7d08277380c271a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ****************************************************************************
 * file/corresp/standard_sub.c -- standard subheader types.
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of libcasio.
 * libcasio 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.
 *
 * libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#include "standard.h"

/* Platforms and types */
#define p_cp    0x00
#define p_cg    0x01
#define t_addin 0x01
#define t_fkey  0x02
#define t_lang  0x04

/* ************************************************************************* */
/*  Helpers                                                                  */
/* ************************************************************************* */
/* Type correspondance type */
struct type_info {
	/* identification */
	casio_uint32_t raw_platform;
	casio_uint32_t raw_type;

	/* types */
	casio_filefor_t platform;
	casio_filetype_t type;
};
/* ************************************************************************* */
/*  Correspondances                                                          */
/* ************************************************************************* */
/* Main types */
CASIO_LOCAL struct type_info types[] = {
	/* fx-CP types */
	{p_cp, t_addin, casio_filefor_cp, casio_filetype_addin},

	/* fx-CG types */
	{p_cg, t_addin, casio_filefor_cg, casio_filetype_addin},
	{p_cg, t_fkey,  casio_filefor_cg, casio_filetype_fkey},
	{p_cg, t_lang,  casio_filefor_cg, casio_filetype_lang},

	/* sentinel */
	{0, 0, 0, 0}
};

/**
 *	casio_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 CASIO_EXPORT casio_maketype_sub(casio_standard_subheader_t *sub,
	unsigned int *flags, casio_filetype_t *type, casio_filefor_t *platform)
{
	struct type_info *c;
	casio_uint32_t raw_type = sub->casio_standard_subheader_filetype;
	casio_uint32_t raw_pf   = sub->casio_standard_subheader_platform;

	/* look for the correspondance */
	for (c = types; c->platform
	 && (c->raw_type != raw_type || c->raw_platform != raw_pf); c++);
	if (!c->platform) return (casio_error_unknown);

	/* fill things */
	if (flags) *flags = 0;
	if (platform) *platform = c->platform;
	if (type) *type = c->type;
	return (0);
}