248 lines
7.0 KiB
C
248 lines
7.0 KiB
C
/* ************************************************************************** */
|
|
/* _____ _ */
|
|
/* libg1m.h |_ _|__ _ _| |__ ___ _ _ */
|
|
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
|
|
/* | | (_) | |_| | | | | __/ |_| | */
|
|
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
|
/* Last updated: 2016/10/31 00:14:27 |___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#ifndef LIBG1M_H
|
|
# define LIBG1M_H
|
|
# include <libg1m/bcd.h>
|
|
# include <libg1m/fontcharacter.h>
|
|
# include <libg1m/color.h>
|
|
# include <stdio.h>
|
|
# include <stdint.h>
|
|
# include <time.h>
|
|
# ifdef __cplusplus
|
|
extern "C" {
|
|
# endif
|
|
# define g1m_ans 27
|
|
|
|
/* ************************************************************************** */
|
|
/* Errors */
|
|
/* ************************************************************************** */
|
|
/* main enumeration */
|
|
typedef enum {
|
|
g1m_noerror,
|
|
|
|
/* no stream sent -- if lib made the libc calls, check errno */
|
|
g1m_error_nostream,
|
|
/* could not read from stream */
|
|
g1m_error_noread,
|
|
/* could not seek in stream */
|
|
g1m_error_noseek,
|
|
|
|
/* magic or control problem */
|
|
g1m_error_magic,
|
|
/* unexpected EOF */
|
|
g1m_error_eof,
|
|
/* memory allocation problem */
|
|
g1m_error_alloc,
|
|
|
|
/* operation not supported for this type */
|
|
g1m_error_op,
|
|
} 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]
|
|
|
|
/* ************************************************************************** */
|
|
/* MCS-Related types */
|
|
/* ************************************************************************** */
|
|
/* BCD matrix - real and complex */
|
|
typedef struct {
|
|
struct bcd real;
|
|
struct bcd imgn;
|
|
int used;
|
|
} g1m_mcs_cell_t;
|
|
|
|
/* MCS file type */
|
|
# define g1m_mcstype_picture g1m_mcstype_pict
|
|
# define g1m_mcstype_capture g1m_mcstype_capt
|
|
# define g1m_mcstype_vector g1m_mcstype_vct
|
|
typedef enum {
|
|
g1m_mcstype_program = 0x01,
|
|
g1m_mcstype_list = 0x02,
|
|
g1m_mcstype_mat = 0x04,
|
|
g1m_mcstype_pict = 0x08,
|
|
g1m_mcstype_capt = 0x10,
|
|
g1m_mcstype_spreadsheet = 0x20,
|
|
g1m_mcstype_string = 0x40,
|
|
g1m_mcstype_setup = 0x80,
|
|
g1m_mcstype_alphamem = 0x100,
|
|
g1m_mcstype_vct = 0x200,
|
|
} g1m_mcsfile_type_t;
|
|
|
|
/* uses id */
|
|
# define g1m_mcstype_uses_id(T) ((T) & (\
|
|
g1m_mcstype_list | g1m_mcstype_mat | g1m_mcstype_vct | \
|
|
g1m_mcstype_pict | g1m_mcstype_capt | g1m_mcstype_string))
|
|
# define g1m_get_id_major(I) ((I) >> 5)
|
|
# define g1m_get_id_minor(I) ((I) & 31)
|
|
|
|
/* mcs file */
|
|
# define g1m_has_password(F) (F)->password[0]
|
|
# define g1m_remove_password(F) (F)->password[0] = 0
|
|
typedef struct {
|
|
/* file type */
|
|
unsigned int type;
|
|
|
|
/* file name or id */
|
|
char name[9];
|
|
int id;
|
|
|
|
/* for unknown files: the group and the directory */
|
|
char _group[17];
|
|
char _dirname[9];
|
|
|
|
/* content (useful when not read) */
|
|
char *content;
|
|
size_t content_size;
|
|
|
|
/* for programs: the password */
|
|
char password[9];
|
|
|
|
/* for spreadsheets, lists and matrixes */
|
|
unsigned int columns, rows;
|
|
g1m_mcs_cell_t **cells;
|
|
|
|
/* for pictures and captures */
|
|
unsigned int width, height;
|
|
uint32_t **image; /* 0x0RGB */
|
|
uint32_t **second_image; /* 0x0RGB */
|
|
} g1m_mcsfile_t;
|
|
|
|
/* version */
|
|
typedef struct {
|
|
int major;
|
|
int minor;
|
|
int revision;
|
|
} g1m_version_t;
|
|
|
|
/* ************************************************************************** */
|
|
/* E-activities related types */
|
|
/* ************************************************************************** */
|
|
/* line type */
|
|
# define g1m_linetype_pict g1m_linetype_picture
|
|
# define g1m_linetype_heading g1m_linetype_title
|
|
# define g1m_linetype_standard_heading g1m_linetype_title
|
|
typedef enum {
|
|
g1m_linetype_title = 0x01,
|
|
g1m_linetype_text = 0x02,
|
|
g1m_linetype_picture = 0x04,
|
|
g1m_linetype_eact = 0x08
|
|
} g1m_eact_line_type_t;
|
|
|
|
/* line */
|
|
typedef struct g1m_line_s {
|
|
int type;
|
|
|
|
/* for subcontents */
|
|
char name[17];
|
|
|
|
/* content */
|
|
char *content;
|
|
|
|
/* subcontents */
|
|
int count;
|
|
int _size;
|
|
struct g1m_line_s **lines;
|
|
} g1m_line_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
|
|
typedef enum {
|
|
g1m_type_addin = 0x01,
|
|
g1m_type_mcs = 0x02,
|
|
g1m_type_eact = 0x04,
|
|
g1m_type_pict = 0x08,
|
|
g1m_type_lang = 0x10,
|
|
g1m_type_fkey = 0x20,
|
|
g1m_type_storage = 0x40
|
|
} g1m_type_t;
|
|
|
|
/* platform */
|
|
typedef enum {
|
|
g1m_platform_none = 0x00,
|
|
g1m_platform_fx = 0x01,
|
|
g1m_platform_cp = 0x02,
|
|
g1m_platform_cg = 0x04
|
|
} g1m_platform_t;
|
|
|
|
/* handle */
|
|
typedef struct {
|
|
/* g1m type */
|
|
g1m_type_t type;
|
|
/* for what platform is this type made for? */
|
|
g1m_platform_t platform;
|
|
|
|
/* Add-in related data */
|
|
char title[17];
|
|
char internal_name[12];
|
|
g1m_version_t version;
|
|
time_t creation_date;
|
|
|
|
/* Tab-related properties */
|
|
int count;
|
|
int _size;
|
|
|
|
/* MCS list */
|
|
g1m_mcsfile_t **files;
|
|
|
|
/* Messages list */
|
|
char **messages;
|
|
|
|
/* Function keys */
|
|
uint32_t ***fkeys;
|
|
|
|
/* Picture-related data (also used for add-in icons */
|
|
int width, height;
|
|
uint32_t **pixels; /* 0x0RGB */
|
|
|
|
/* E-activities related data */
|
|
g1m_line_t *line;
|
|
g1m_line_t _linedata;
|
|
} g1m_t;
|
|
|
|
/* ************************************************************************** */
|
|
/* Main functions */
|
|
/* ************************************************************************** */
|
|
/* open handles */
|
|
int g1m_open(g1m_t **handle, const char *path);
|
|
int g1m_fopen(g1m_t **handle, const char *path, FILE *stream);
|
|
|
|
/* open MCS handle (this one is mainly for `libp7`) */
|
|
int g1m_parse_mcsfile_content(g1m_mcsfile_t **handle, FILE *stream,
|
|
int raw_type, const unsigned char *groupname,
|
|
const unsigned char *dirname, const unsigned char *filename,
|
|
uint_fast32_t filesize);
|
|
|
|
/* free handles */
|
|
void g1m_free(g1m_t *handle);
|
|
void g1m_free_mcsfile(g1m_mcsfile_t *handle);
|
|
|
|
/* ************************************************************************** */
|
|
/* MCS file manipulation */
|
|
/* ************************************************************************** */
|
|
/* add MCS files */
|
|
int g1m_putmcs_program(g1m_t *handle, g1m_mcsfile_t **pfile,
|
|
char *name, char *password, char *content);
|
|
int g1m_putmcs_capture(g1m_t *handle, g1m_mcsfile_t **pfile,
|
|
int id, int width, int height, uint32_t **pixels);
|
|
int g1m_putmcs_picture(g1m_t *handle, g1m_mcsfile_t **pfile,
|
|
int id, uint32_t **pixels_one, uint32_t **pixels_two);
|
|
|
|
# ifdef __cplusplus
|
|
}
|
|
# endif
|
|
#endif /* LIBG1M_H */
|