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

110 lines
3.7 KiB
C

/* *****************************************************************************
* type/cas.c -- get the CAS type and data types 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 *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, 0}
static struct type_corresp cas_groups[] = {
/* not implemented yet types, described by Tom Wheeley and Tom Lynn */
{"AA", 0}, // dynamic graph functions
{"AD", 0}, // variable memory
{"AL", 0}, // all
{"AM", 0}, // alpha variable memory
{"BU", 0}, // backup
{"DM", 0}, // defined memory
{"DD", 0}, // screenshot
{"EN", 0}, // one editor file
{"FN", 0}, // set of editor files
{"F1", 0}, // one function memory
{"F6", 0}, // set of function memories
{"GA", 0}, // set of graph functions
{"GF", 0}, // graph zoom factor (graph function?)
{"GR", 0}, // graph range
{"GT", 0}, // function table
{"MA", 0}, // set of matrices
{"PD", 0}, // polynomial equations
{"P1", 0}, // one program
{"PZ", 0}, // set of programs
{"RT", 0}, // recursion table
{"SD", 0}, // simultaneous equations
{"SR", 0}, // linear regression data
{"SS", 0}, // standard deviation data
/* terminating entry */
TTERM
};
/* ************************************************************************** */
/* Main functions */
/* ************************************************************************** */
/**
* g1m_maketype_cas:
* Get the libg1m MCS type from raw CAS identification data.
*
* @arg head the head to fill.
* @arg datatype the data type string.
* @return the error (if any).
*/
int g1m_maketype_cas(g1m_mcshead_t *head, const char *datatype)
{
/* copy information */
memset(head, 0, sizeof(g1m_mcshead_t));
head->flags |= g1m_mcsinfo_cas;
memcpy(head->_datatype, datatype, 2);
head->_datatype[2] = 0;
/* look for correspondance */
struct type_corresp *c = cas_groups - 1;
while ((++c)->datatype) {
if (c->datatype && strncmp(datatype, c->datatype, 4))
continue;
break;
}
if (!c->type) 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);
}