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/include/libg1m.h

187 lines
5.3 KiB
C
Raw Normal View History

2016-10-30 20:18:15 +01:00
/* ************************************************************************** */
/* _____ _ */
/* libg1m.h |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
2016-10-30 20:18:15 +01:00
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/10/31 00:14:27 |___/ */
2016-10-30 20:18:15 +01:00
/* */
/* ************************************************************************** */
#ifndef LIBG1M_H
# define LIBG1M_H
# include <stdio.h>
2016-11-03 01:16:21 +01:00
# include <stdint.h>
# include <time.h>
2016-10-30 20:18:15 +01:00
# ifdef __cplusplus
extern "C" {
# endif
/* ************************************************************************** */
/* Errors */
/* ************************************************************************** */
/* main enumeration */
typedef enum {
g1m_noerror,
2016-11-01 06:10:47 +01:00
/* no stream sent -- if lib made the libc calls, check errno */
2016-10-30 20:18:15 +01:00
g1m_error_nostream,
/* could not read from stream */
g1m_error_noread,
/* could not seek in stream */
g1m_error_noseek,
2016-11-19 02:47:36 +01:00
2016-10-30 20:18:15 +01:00
/* magic or control problem */
g1m_error_magic,
/* unexpected EOF */
g1m_error_eof,
2016-10-30 20:18:15 +01:00
/* memory allocation problem */
g1m_error_alloc,
2016-11-19 02:47:36 +01:00
/* operation not supported for this type */
g1m_error_op,
2016-10-30 20:18:15 +01:00
} g1m_error_t;
/* Message getting macro */
extern const char *g1m_error_strings[];
#define g1m_strerror(N) g1m_error_strings[N]
#define g1m_geterror(N) g1m_error_strings[N]
/* ************************************************************************** */
2016-11-03 01:16:21 +01:00
/* Useful types */
2016-10-30 20:18:15 +01:00
/* ************************************************************************** */
2016-11-03 01:16:21 +01:00
/* BCD number */
struct bcd {
/* the BCD value */
uint8_t BCDval[9];
/* and some 4-bytes alignment stuff */
uint8_t align[3];
};
/* FONTCHARACTER, CASIO's encoding */
typedef uint16_t FONTCHARACTER;
/* ************************************************************************** */
/* MCS-Related types */
/* ************************************************************************** */
/* MCS file type */
typedef enum {
2016-11-19 02:47:36 +01:00
g1m_mcstype_program = 0x01,
g1m_mcstype_list = 0x02,
g1m_mcstype_mat = 0x04,
g1m_mcstype_pict = 0x08,
g1m_mcstype_capt = 0x10,
g1m_mcstype_spreadsheet = 0x20
2016-11-03 01:16:21 +01:00
} g1m_mcsfile_type_t;
/* BCD matrix - real and complex */
2016-11-19 02:47:36 +01:00
typedef struct {
struct bcd real;
struct bcd imgn;
int used;
} g1m_mcs_cell_t;
2016-11-03 01:16:21 +01:00
/* mcs file */
typedef struct {
/* directory name */
char dirname[9];
/* file name */
2016-11-19 02:47:36 +01:00
char name[9];
2016-11-03 01:16:21 +01:00
/* file type */
2016-11-19 02:47:36 +01:00
int type;
2016-11-03 01:16:21 +01:00
/* for programs: the password */
char password[9];
/* for spreadsheets, lists and matrixes */
unsigned int columns, rows;
2016-11-19 02:47:36 +01:00
g1m_mcs_cell_t *cells;
2016-11-03 01:16:21 +01:00
/* for pictures and captures */
unsigned int width, height;
2016-11-19 02:47:36 +01:00
uint32_t **image; /* 0x0RGB */
uint32_t **second_image; /* 0x0RGB */
2016-11-03 01:16:21 +01:00
} g1m_mcsfile_t;
/* mcs list */
typedef struct {
2016-11-19 12:05:54 +01:00
int file_count;
int _files_size; /* used internally for reallocs */
g1m_mcsfile_t **files;
2016-11-03 01:16:21 +01:00
} g1m_mcs_t;
/* version */
typedef struct {
int major;
int minor;
int revision;
} g1m_version_t;
/* ************************************************************************** */
/* General types */
/* ************************************************************************** */
/* type */
typedef enum {
g1m_type_addin = 0x01,
g1m_type_mcs = 0x02,
g1m_type_eact = 0x04,
g1m_type_pict = 0x08
} g1m_type_t;
2016-10-30 20:18:15 +01:00
/* handle */
2016-11-03 01:16:21 +01:00
typedef struct {
/* g1m type */
g1m_type_t type;
/* is it a format adapted for fx-CG? */
int is_cg;
/* ADD-IN RELATED DATA */
/* internal name */
char internal_name[12];
/* version */
g1m_version_t version;
/* creation date */
time_t creation_date;
2016-10-30 20:18:15 +01:00
2016-11-03 01:16:21 +01:00
/* MCS RELATED DATA */
int part_count;
2016-11-19 02:47:36 +01:00
int _parts_size; /* used internally for reallocs */
g1m_mcs_t **parts;
2016-11-03 01:16:21 +01:00
/* TODO: pictures, e-activities */
} g1m_t;
/* ************************************************************************** */
/* Main functions */
/* ************************************************************************** */
2016-11-19 12:05:54 +01:00
/* open handles */
2016-10-30 20:18:15 +01:00
int g1m_open(g1m_t **handle, const char *path);
int g1m_fopen(g1m_t **handle, FILE *stream);
2016-11-19 12:05:54 +01:00
/* open MCS handle (this one is for `libp7`) */
2016-11-19 02:47:36 +01:00
int g1m_parse_mcsfile_content(g1m_mcsfile_t **handle, FILE *stream,
int raw_type, const char *filename, const char *dirname,
uint_fast32_t filesize);
2016-10-30 20:18:15 +01:00
2016-11-19 12:05:54 +01:00
/* free handles */
void g1m_free(g1m_t *handle);
void g1m_free_mcsfile(g1m_mcsfile_t *handle);
2016-11-03 01:16:21 +01:00
/* ************************************************************************** */
/* Utilities */
/* ************************************************************************** */
2016-11-19 02:47:36 +01:00
/* encoding characters */
int g1m_mbtofc(FONTCHARACTER *pfc, const char *s, size_t n);
int g1m_fctomb(char *s, FONTCHARACTER fc);
/* encoding strings */
2016-11-03 01:16:21 +01:00
size_t g1m_mbstofcs(FONTCHARACTER *dst, const char *src, size_t n);
size_t g1m_fcstombs(char *dst, const FONTCHARACTER *src, size_t n);
2016-10-30 20:18:15 +01:00
# ifdef __cplusplus
}
# endif
#endif /* LIBG1M_H */