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/caspro.c

93 lines
3.2 KiB
C

/* *****************************************************************************
* type/caspro.c -- get the newer CAS type out of raw 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>
/* ************************************************************************** */
/* Local types */
/* ************************************************************************** */
/* Correspondance type */
struct type_corresp {
/* identification */
const char *maintype;
const char *datatype;
/* libg1m MCS file type */
g1m_mcstype_t type;
};
/* ************************************************************************** */
/* Correspondances */
/* ************************************************************************** */
/* All correspondances. Remarks:
* - Correspondances with a NULL data type means the data type isn't to be
* read. */
#define TTERM {NULL, NULL, 0}
static struct type_corresp cas_types[] = {
{"TXT", "PG", g1m_mcstype_program},
{"VAL", "VM", g1m_mcstype_variable},
//{"VAL", "MT", g1m_mcstype_matrix},
/* terminating entry */
TTERM
};
/* ************************************************************************** */
/* Main functions */
/* ************************************************************************** */
/**
* g1m_maketype_caspro:
* Get the libg1m MCS type from raw CAS identification data.
*
* @arg head the head to fill.
* @arg maintype the main type string.
* @arg datatype the data type string.
* @return the error (if any).
*/
int g1m_maketype_caspro(g1m_mcshead_t *head,
const char *maintype, const char *datatype)
{
/* copy raw information */
head->flags |= g1m_mcsinfo_caspro;
memcpy(head->_maintype, maintype, 3);
head->_maintype[3] = 0;
memcpy(head->_datatype, datatype, 2);
head->_datatype[2] = 0;
/* look for correspondance */
struct type_corresp *c;
for (c = cas_types; c->datatype; c++) {
if ((!c->maintype || !strncmp(maintype, c->maintype, 3))
&& (!c->datatype || !strncmp(datatype, c->datatype, 2)))
break;
}
if (!c->maintype) goto notfound;
/* fill in info and return */
head->type = c->type;
return (0);
notfound:
log_info("Type with '%.4s' data string was not implemented or not "
"recognized.", datatype);
head->type = 0;
return (1);
}