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/internals.h

69 lines
2.9 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* libg1m/internals.h |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/10/31 00:14:27 |___/ */
/* */
/* ************************************************************************** */
#ifndef LIBG1M_INTERNALS_H
# define LIBG1M_INTERNALS_H
# include <libg1m.h>
# include <libg1m/format.h>
# include <libg1m/internals/log.h>
# include <string.h>
# include <endian.h>
# ifndef min
# define min(A, B) ((A) < (B) ? (A) : (B))
# endif
/* ************************************************************************** */
/* Macros and functions for parsing */
/* ************************************************************************** */
/* read with EOF check */
#define READ(TO, SZ) { \
size_t READ_size = fread(TO, 1, SZ, stream); \
if (READ_size < (SZ)) { \
log_info("READING failed: read %zu/%zu bytes, %zu missing.", \
READ_size, SZ, (SZ) - READ_size); \
return (g1m_error_eof); \
}}
/* read with EOF check, declare var before */
#define DREAD(NAM, STRUCT) \
struct STRUCT NAM; \
READ(&NAM, sizeof(struct STRUCT))
/* skip */
#define SKIP(SZ) \
if (g1m_parse_skip(stream, SZ, NULL)) return (g1m_error_eof);
/* skipping utility */
int g1m_parse_skip(FILE *stream, size_t size, uint_fast32_t *checksum);
/* ************************************************************************** */
/* Specific parsing functions */
/* ************************************************************************** */
int g1m_parse_g3p(g1m_t *handle, FILE *stream,
struct standard_header *std);
int g1m_parse_mcs(g1m_t *handle, FILE *stream, uint_fast16_t num);
int g1m_parse_eact(g1m_t * handle, FILE *stream);
int g1m_parse_addin(g1m_t *handle, FILE *stream);
int g1m_parse_addin_cg(g1m_t *handle, FILE *stream,
struct standard_header *std);
/* ************************************************************************** */
/* Main handle type */
/* ************************************************************************** */
/* Handle */
struct g1m {
int nothing_yet;
};
/* ************************************************************************** */
/* Utilities */
/* ************************************************************************** */
/* Parsing */
int g1m_parse(g1m_t *handle, FILE *stream);
#endif /* LIBG1M_INTERNALS_H */