299 lines
8.9 KiB
C
299 lines
8.9 KiB
C
/* *****************************************************************************
|
|
* libg1m.h -- libg1m main public header.
|
|
* 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/>.
|
|
*
|
|
* WARNING: Do NOT include this header using <libg1m-(version)/libg1m.h>!
|
|
*
|
|
* Compile using one of these:
|
|
* libg1m-config --cflags
|
|
* pkg-config libg1m --cflags
|
|
*
|
|
* and include using <libg1m.h>.
|
|
* ************************************************************************** */
|
|
#ifndef LIBG1M_H
|
|
# define LIBG1M_H
|
|
# include <libg1m/config.h>
|
|
# include <libg1m/buffer.h>
|
|
# include <libg1m/bcd.h>
|
|
# include <libg1m/color.h>
|
|
# include <libfontcharacter.h>
|
|
# include <stdio.h>
|
|
# include <stdint.h>
|
|
# include <time.h>
|
|
# ifdef __cplusplus
|
|
extern "C" {
|
|
# endif
|
|
# define g1m_theta 27
|
|
# define g1m_r 28
|
|
# define g1m_ans 29
|
|
|
|
/* ************************************************************************** */
|
|
/* Errors */
|
|
/* ************************************************************************** */
|
|
/* WARNING: Whenever you add/remove errors, think about updating core/strerror!
|
|
* ---
|
|
* First, the none error. */
|
|
# define g1m_noerror 0x00
|
|
|
|
/* Then, the miscallenous errors */
|
|
# define g1m_error_alloc 0x01
|
|
# define g1m_error_op 0x02
|
|
|
|
/* Then, the stream errors */
|
|
# define g1m_error_nostream 0x10
|
|
# define g1m_error_noread 0x11
|
|
# define g1m_error_noseek 0x12
|
|
|
|
/* Then, the decoding errors */
|
|
# define g1m_error_magic 0x20
|
|
# define g1m_error_eof 0x21
|
|
# define g1m_error_wrong_type 0x22
|
|
|
|
/* Error type -- for compatibility with old programs using enum */
|
|
typedef int 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 g1m_mcs_cell_s {
|
|
g1m_bcd_t real;
|
|
g1m_bcd_t imgn;
|
|
int used;
|
|
} g1m_mcs_cell_t;
|
|
|
|
/* MCS file type */
|
|
typedef unsigned int g1m_mcsfile_type_t;
|
|
# define g1m_mcstype_unknown 0x000
|
|
# define g1m_mcstype_program 0x001
|
|
# define g1m_mcstype_list 0x002
|
|
# define g1m_mcstype_mat 0x004
|
|
# define g1m_mcstype_pict 0x008
|
|
# define g1m_mcstype_capt 0x010
|
|
# define g1m_mcstype_spreadsheet 0x020
|
|
# define g1m_mcstype_string 0x040
|
|
# define g1m_mcstype_setup 0x080
|
|
# define g1m_mcstype_alphamem 0x100
|
|
# define g1m_mcstype_vct 0x200
|
|
|
|
/* MCS file type aliases */
|
|
# define g1m_mcstype_picture g1m_mcstype_pict
|
|
# define g1m_mcstype_capture g1m_mcstype_capt
|
|
# define g1m_mcstype_vector g1m_mcstype_vct
|
|
|
|
/* 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 g1m_mcsfile_s {
|
|
/* 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;
|
|
|
|
/* variables */
|
|
g1m_mcs_cell_t *vars;
|
|
|
|
/* for pictures and captures */
|
|
unsigned int width, height;
|
|
uint32_t **image; /* 0x0RGB */
|
|
uint32_t **second_image; /* 0x0RGB */
|
|
} g1m_mcsfile_t;
|
|
|
|
/* version */
|
|
typedef struct g1m_version_s {
|
|
int major;
|
|
int minor;
|
|
int revision;
|
|
} g1m_version_t;
|
|
|
|
/* ************************************************************************** */
|
|
/* Storage files */
|
|
/* ************************************************************************** */
|
|
/* storage file type */
|
|
typedef unsigned int g1m_filetype_t;
|
|
# define g1m_filetype_directory 0x01
|
|
# define g1m_filetype_generic 0x02
|
|
|
|
/* storage file structure */
|
|
typedef struct g1m_file_s {
|
|
/* meta info */
|
|
unsigned int type;
|
|
struct g1m_file_s *parent;
|
|
int deleted;
|
|
|
|
/* content */
|
|
void *content;
|
|
} g1m_file_t;
|
|
|
|
/* ************************************************************************** */
|
|
/* E-activities related types */
|
|
/* ************************************************************************** */
|
|
/* Line type */
|
|
typedef unsigned int g1m_eact_line_type_t;
|
|
# define g1m_linetype_title 0x01
|
|
# define g1m_linetype_text 0x02
|
|
# define g1m_linetype_picture 0x04
|
|
# define g1m_linetype_eact 0x08
|
|
|
|
/* Line type aliases */
|
|
# define g1m_linetype_pict g1m_linetype_picture
|
|
# define g1m_linetype_heading g1m_linetype_title
|
|
# define g1m_linetype_standard_heading g1m_linetype_title
|
|
|
|
/* 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 */
|
|
/* ************************************************************************** */
|
|
/* General type */
|
|
typedef unsigned int g1m_type_t;
|
|
# define g1m_type_addin 0x01
|
|
# define g1m_type_mcs 0x02
|
|
# define g1m_type_eact 0x04
|
|
# define g1m_type_picture 0x08
|
|
# define g1m_type_lang 0x10
|
|
# define g1m_type_fkey 0x20
|
|
# define g1m_type_storage 0x40
|
|
|
|
/* General type aliases */
|
|
# define g1m_type_pict g1m_type_picture
|
|
# define g1m_type_eactivity g1m_type_eact
|
|
# define g1m_type_add_in g1m_type_addin
|
|
|
|
/* Platform */
|
|
typedef unsigned int g1m_platform_t;
|
|
# define g1m_platform_none 0x00
|
|
# define g1m_platform_fx 0x01
|
|
# define g1m_platform_cp 0x02
|
|
# define g1m_platform_cg 0x04
|
|
|
|
/* 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;
|
|
|
|
/* Storage files list */
|
|
g1m_file_t **sfiles;
|
|
|
|
/* 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,
|
|
g1m_type_t expected_type);
|
|
int g1m_fopen(g1m_t **handle, const char *path, FILE *stream,
|
|
g1m_type_t expected_type);
|
|
|
|
/* open MCS handle (this one is mainly for `libp7`) */
|
|
int g1m_decode_mcsfile_content(g1m_mcsfile_t **handle, g1m_buffer_t *buffer,
|
|
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 */
|