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

181 lines
4.9 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
2016-11-21 10:26:52 +01:00
# include <libg1m/bcd.h>
# include <libg1m/fontcharacter.h>
# include <libg1m/color.h>
2016-10-30 20:18:15 +01:00
# 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[];
2016-11-20 02:13:36 +01:00
# define g1m_strerror(N) g1m_error_strings[N]
# define g1m_geterror(N) g1m_error_strings[N]
2016-10-30 20:18:15 +01:00
2016-11-03 01:16:21 +01:00
/* ************************************************************************** */
/* MCS-Related types */
/* ************************************************************************** */
/* MCS file type */
2016-11-20 02:13:36 +01:00
# define g1m_mcstype_picture g1m_mcstype_pict
# define g1m_mcstype_capture g1m_mcstype_capt
2016-11-03 01:16:21 +01:00
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 */
2016-11-20 02:17:14 +01:00
# define g1m_has_password(F) (F)->password[0]
2016-11-03 01:16:21 +01:00
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 and content */
2016-11-03 01:16:21 +01:00
char password[9];
char *content;
2016-11-03 01:16:21 +01:00
/* for spreadsheets, lists and matrixes */
unsigned int columns, rows;
2016-11-19 13:44:44 +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 */
# define g1m_type_pict g1m_type_picture
# define g1m_type_eactivity g1m_type_eact
# define g1m_type_add_in g1m_type_addin
2016-11-03 01:16:21 +01:00
typedef enum {
g1m_type_addin = 0x01,
g1m_type_mcs = 0x02,
g1m_type_eact = 0x04,
g1m_type_pict = 0x08,
g1m_type_lang = 0x10
2016-11-03 01:16:21 +01:00
} 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
/* tab-related vars */
int count;
int _size;
2016-11-03 01:16:21 +01:00
/* MCS RELATED DATA */
g1m_mcs_t **mcs;
2016-11-03 01:16:21 +01:00
/* MESSAGES RELATED DATA */
char **messages;
/* PICTURE RELATED DATA - also used for add-in icons */
int width, height;
uint32_t **pixels; /* 0x0RGB */
/* TODO: e-activities */
2016-11-03 01:16:21 +01:00
} 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-10-30 20:18:15 +01:00
# ifdef __cplusplus
}
# endif
#endif /* LIBG1M_H */