cake
/
libcasio
Archived
1
1
Fork 0

Made progress on SCSI communications with the G90

This commit is contained in:
Thomas Touhey 2018-05-14 21:55:17 +02:00
parent fb550a68b6
commit 1a1d119cb2
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
75 changed files with 1837 additions and 771 deletions

View File

@ -115,16 +115,27 @@
# endif
/* ---
* Warn if the result is unused.
* Various function attributes.
* --- */
/* To do that, we'll use the `casio_attr_wur` attribute. */
/* Warn if the result is unused.
* To do that, we'll use the `CASIO_WUR` attribute. */
# if CASIO_GNUC_PREREQ(4, 0)
# define casio_attr_wur __attribute__((warn_unused_result))
# define CASIO_WUR __attribute__((warn_unused_result))
# elif CASIO_MSC_PREREQ(17, 0)
# include <sal.h>
# define casio_attr_wur _Check_return_
# define CASIO_WUR _Check_return_
# else
# define CASIO_WUR
# endif
/* Warn if the function is deprecated. */
# if CASIO_GNUC_PREREQ(3, 0)
# define CASIO_DEPRECATED __attribute__((deprecated))
# else
# define CASIO_DEPRECATED
# endif
# include "cdefs/integers.h"

View File

@ -32,6 +32,7 @@ typedef int casio_error_t;
# define casio_error_none 0x00
# define casio_error_success 0x00
# define casio_error_ok 0x00
# define casio_noerror 0x00
/* Miscallaneous errors. */
@ -42,6 +43,8 @@ typedef int casio_error_t;
# define casio_error_arg 0x04 /* an argument was invalid. */
# define casio_error_invalid 0x04 /* (alias) */
# define casio_error_lock 0x05 /* mutex is locked */
# define casio_error_iter 0x06 /* iteration has ended */
# define casio_error_end 0x06 /* (alias) */
/* Stream errors. */

88
include/libcasio/iter.h Normal file
View File

@ -0,0 +1,88 @@
/* ****************************************************************************
* libcasio/iter.h -- libcasio iterators.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_ITER_H
# define LIBCASIO_ITER_H 2018050901
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
/* Many things in libcasio work with iterators. This is the centralized
* iterator interface. */
struct casio_iter_s;
typedef struct casio_iter_s casio_iter_t;
/* ---
* Define something.
* --- */
/* The way this is done:
*
* When `casio_next()` is called, if there was a previous element,
* the `casio_nextfree_t` callback, if not NULL, will be called to free
* it, then in all cases, the `casio_next_t` callback will be called to
* get the next element. If the `casio_next_t` callback returns
* `casio_error_iter`, all following calls to `casio_next()` with this
* iterator won't call the callbacks and directly return the same error.
*
* When `casio_end()` is called, the `casio_end_t` callback, if not NULL,
* will be called. */
typedef int CASIO_EXPORT casio_next_t
OF((void *casio__cookie, void **casio__ptr));
typedef void CASIO_EXPORT casio_nextfree_t
OF((void *casio__cookie, void *casio__ptr));
typedef void CASIO_EXPORT casio_end_t
OF((void *casio__cookie));
typedef struct casio_iter_funcs_s {
casio_next_t *casio_iterfunc_next;
casio_nextfree_t *casio_iterfunc_nextfree;
casio_end_t *casio_iterfunc_end;
} casio_iter_funcs_t;
/* ---
* Functions.
* --- */
CASIO_BEGIN_DECLS
/* Start an iterator with `casio_iter_<whatever>(&iter, <other data>)`,
* with `iter` being of the `casio_iter_t *` type.
* Get the next element through `casio_next_<whatever>(iter, &ptr)`,
* which is usually a macro or function defined as
* `casio_next(iter, (void **)(PTRP))`.
* Then end the iterator using `casio_end(iter)`.
*
* Beware: any time you use `casio_next()` or `casio_end()`, the previous
* element might be free'd or re-used, so if you are interested in what is
* in it, copy the data before using one of the previous functions. */
CASIO_EXTERN int CASIO_EXPORT casio_iter
OF((casio_iter_t **casio__iterp, void *casio__cookie,
casio_iter_funcs_t const *casio__funcs));
CASIO_EXTERN int CASIO_EXPORT casio_next
OF((casio_iter_t *casio__iter, void **casio__ptr));
CASIO_EXTERN void CASIO_EXPORT casio_end
OF((casio_iter_t *casio__iter));
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif

View File

@ -167,19 +167,6 @@ CASIO_EXTERN void CASIO_EXPORT casio_unlock_link
CASIO_EXTERN const casio_link_info_t* CASIO_EXPORT casio_get_link_info
OF((casio_link_t *casio__handle));
/* ---
* Run servers.
* --- */
/* Run a Protocol 7.00 server. */
typedef int CASIO_EXPORT casio_seven_server_func_t
OF((void *casio__cookie, casio_link_t *casio__handle));
CASIO_EXTERN int CASIO_EXPORT casio_seven_serve
OF((casio_link_t *casio__handle,
casio_seven_server_func_t **casio__callbacks, void *casio__cookie));
/* ---
* General-purpose link operations.
* --- */

View File

@ -19,6 +19,7 @@
#ifndef LIBCASIO_LOG_H
# define LIBCASIO_LOG_H
# include "cdefs.h"
# include "iter.h"
CASIO_BEGIN_NAMESPACE
CASIO_BEGIN_DECLS
@ -29,14 +30,21 @@ CASIO_EXTERN void CASIO_EXPORT casio_setlog
CASIO_EXTERN const char* CASIO_EXPORT casio_getlog
OF((void));
/* List log levels */
/* List log levels (deprecated interface) */
typedef void casio_log_list_t OF((void *casio__cookie,
const char *casio__str));
CASIO_EXTERN void CASIO_EXPORT casio_listlog
CASIO_EXTERN CASIO_DEPRECATED void CASIO_EXPORT casio_listlog
OF((casio_log_list_t *casio__callback, void *casio__cookie));
/* List log levels (new interface).
* This iterator yields strings (`const char *`). */
CASIO_EXTERN int CASIO_EXPORT casio_iter_log
OF((casio_iter_t **casio__iter));
# define casio_next_log(ITER, PTRP) (casio_next((ITER), (void **)(PTRP)))
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_LOG_H */

View File

@ -20,6 +20,7 @@
# define LIBCASIO_MCS_H
# include "cdefs.h"
# include "mcsfile.h"
# include "iter.h"
CASIO_BEGIN_NAMESPACE
/* Forward structure declarations (don't mind). */
@ -54,12 +55,8 @@ typedef int CASIO_EXPORT casio_mcs_put_t
typedef int CASIO_EXPORT casio_mcs_delete_t
OF((void *casio__cookie, casio_mcshead_t *casio__mcshead));
typedef void CASIO_EXPORT casio_mcslist_t
OF((void *casio__cookie, const casio_mcshead_t *casio__mcshead));
typedef int CASIO_EXPORT casio_mcs_list_t
OF((void *casio__cookie, casio_mcslist_t *casio__mcslist,
void *casio__mcslist_cookie));
typedef int CASIO_EXPORT casio_mcs_iter_t
OF((void *casio__cookie, casio_iter_t **casio__iter));
typedef int CASIO_EXPORT casio_mcs_close_t
OF((void *casio__cookie));
@ -68,7 +65,7 @@ struct casio_mcsfuncs_s {
casio_mcs_get_t *casio_mcsfuncs_get;
casio_mcs_put_t *casio_mcsfuncs_put;
casio_mcs_delete_t *casio_mcsfuncs_delete;
casio_mcs_list_t *casio_mcsfuncs_list;
casio_mcs_iter_t *casio_mcsfuncs_iter;
casio_mcs_close_t *casio_mcsfuncs_close;
};
@ -108,12 +105,23 @@ CASIO_EXTERN int CASIO_EXPORT casio_transfer_mcsfile
CASIO_EXTERN int CASIO_EXPORT casio_delete_mcsfile
OF((casio_mcs_t *casio__mcs, casio_mcshead_t *casio__mcshead));
/* List MCS files. */
/* List MCS files (the deprecated way). */
CASIO_EXTERN int CASIO_EXPORT casio_list_mcsfiles
typedef void CASIO_EXPORT casio_mcslist_t
OF((void *casio__cookie, const casio_mcshead_t *casio__mcshead));
CASIO_EXTERN CASIO_DEPRECATED int CASIO_EXPORT casio_list_mcsfiles
OF((casio_mcs_t *casio__mcs, casio_mcslist_t *casio__mcslist,
void *casio__mcookie));
/* Iterate on MCS entries. */
CASIO_EXTERN int CASIO_EXPORT casio_iter_mcsfiles
OF((casio_mcs_t *casio__mcs, casio_iter_t **casio__iter));
# define casio_next_mcshead(ITER, MCSFILEP) \
(casio_next((ITER), (void **)(casio_mcshead_t **)(MCSFILEP)))
/* Make a temporary main memory. */
CASIO_EXTERN int CASIO_EXPORT casio_open_local_mcs

View File

@ -448,6 +448,36 @@ CASIO_EXTERN int CASIO_EXPORT casio_seven_open_data_stream
casio_link_t *casio__link, casio_off_t casio__size,
casio_link_progress_t *casio__disp, void *casio__dcookie));
/* Server-related functions.
* Put the link in server mode and process a command.
*
* `casio_seven_start_server()` does the following:
* - if active, send a swap and become passive;
* - if already passive, wait for the initial check to ACK and become
* ready to process requests.
*
* `casio_seven_process_request()` returns:
* - an error if the link isn't correct (valid, protocol 7, passive);
* - 0 if the next command has been fetched successfully,
* - `casio_error_iter` if the counterpart has finished sending commands;
* - `casio_error_unknown` otherwise. */
CASIO_EXTERN int CASIO_EXPORT casio_seven_start_server
OF((casio_link_t *casio__handle));
CASIO_EXTERN int CASIO_EXPORT casio_seven_get_next_request
OF((casio_link_t *casio__handle));
/* Passive function that takes control of the execution thread and makes
* a server with callbacks. */
typedef int CASIO_EXPORT casio_seven_server_func_t
OF((void *casio__cookie, casio_link_t *casio__handle));
CASIO_EXTERN int CASIO_EXPORT casio_seven_serve
OF((casio_link_t *casio__handle,
casio_seven_server_func_t * const *casio__callbacks,
void *casio__cookie));
/* ---
* Protocol 7.00 high-level abstractions.
* --- */

View File

@ -29,7 +29,8 @@
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
/* forward structure declarations (don't mind) */
/* Forward structure declarations (don't mind). */
struct casio_stream_s;
typedef struct casio_stream_s casio_stream_t;
struct casio_streamfuncs_s;
@ -41,9 +42,10 @@ typedef struct casio_timeouts_s casio_timeouts_t;
struct casio_scsi_s;
typedef struct casio_scsi_s casio_scsi_t;
/* ************************************************************************* */
/* Stream */
/* ************************************************************************* */
/* ---
* Stream.
* --- */
/* The stream is a private structure that has more or less all of the features
* that the libc FILE interface has, but has more and is cross-platform.
* It is basically what libcasio uses to communicate with the calculator.
@ -149,9 +151,10 @@ struct casio_streamfuncs_s {
(casio_stream_write_t*)(CASIO__WRITE), \
(casio_stream_seek_t*)(CASIO__SEEK), NULL, NULL}
/* ************************************************************************* */
/* Stream settings values and flags */
/* ************************************************************************* */
/* ---
* Stream serial settings ad flags.
* --- */
/* Here are the different baud speeds you can encounter, in bauds.
* Note that one speed is not supported by all models. */
@ -213,9 +216,11 @@ struct casio_streamfuncs_s {
# define CASIO_XOFFMASK 0x0100
# define CASIO_XOFFCTL_DISABLE 0x0000 /* disable XOFF */
# define CASIO_XOFFCTL_ENABLE 0x0100 /* enable XOFF */
/* ************************************************************************* */
/* Stream settings */
/* ************************************************************************* */
/* ---
* Stream settings.
* --- */
/* Here is the stream settings structure: */
struct casio_streamattrs_s {
@ -246,9 +251,11 @@ struct casio_timeouts_s {
/* This structure will be sent to your `settm` callback, usually after a state
* change in the communication. Also, all timeouts are in milliseconds (ms). */
/* ************************************************************************* */
/* SCSI request */
/* ************************************************************************* */
/* ---
* SCSI requests.
* --- */
/* CASIO's fx-CG devices, also known as Prizms or Graph 90+E, use SCSI along
* with Protocol 7.00 to communicate with the PC for things like file
* transferring or screenstreaming (which use vendor-specific command slots).
@ -279,12 +286,12 @@ struct casio_timeouts_s {
* `status` is the status byte returned by the device. */
struct casio_scsi_s {
void *casio_scsi_cmd;
unsigned int casio_scsi_cmd_len;
int casio_scsi_direction;
void *casio_scsi_data;
int casio_scsi_data_len;
int casio_scsi_status;
void *casio_scsi_cmd;
size_t casio_scsi_cmd_len;
int casio_scsi_direction;
void *casio_scsi_data;
size_t casio_scsi_data_len;
int casio_scsi_status;
};
/* It will be sent to the `scsi` callback of the stream. */

View File

@ -27,7 +27,8 @@ const char* CASIO_EXPORT casio_error_strings[128] = {
"a memory allocation has failed",
"this operation is unsupported",
"an argument was invalid",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"no more elements in the iterator",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* Stream errors. */

View File

@ -18,16 +18,19 @@
* ************************************************************************* */
#include "standard.h"
/* ************************************************************************* */
/* Helpers */
/* ************************************************************************* */
/* ---
* Helpers.
* --- */
/* Flags */
#define f_c1 casio_stdflag_check1
#define f_c2 casio_stdflag_check2
#define f_sub casio_stdflag_sub
#define f_pic casio_stdflag_pic
/* Subtype correspondance type */
struct type_info {
/* identification */
const char *type;
@ -42,6 +45,7 @@ struct type_info {
};
/* Main type correspondance type */
struct main_info {
/* identification */
const char *type;
@ -51,6 +55,7 @@ struct main_info {
};
/* Extension correspondance type */
struct ext_corresp {
/* identification */
const char *ext;
@ -61,9 +66,11 @@ struct ext_corresp {
unsigned int libtype;
unsigned int flags;
};
/* ************************************************************************* */
/* Main correspondances */
/* ************************************************************************* */
/* ---
* Main correspondances.
* --- */
#define magic_common "\x00\x10\x00\x10\x00"
#define cp_magic "\x00\x01\x00\x01\x00"
#define blank "\xFF\xFF\xFF\xFF\xFF\xFF"
@ -165,9 +172,11 @@ CASIO_LOCAL struct ext_corresp ext_types[] = {
/* sentinel */
{NULL, NULL, 0, 0, 0}
};
/* ************************************************************************* */
/* Get the type information */
/* ************************************************************************* */
/* ---
* Get the type information.
* --- */
/**
* casio_maketype_std:
* Get the standard header type information.

View File

@ -19,15 +19,17 @@
#include "standard.h"
/* Platforms and types */
#define p_cp 0x00
#define p_cg 0x01
#define t_addin 0x01
#define t_fkey 0x02
#define t_lang 0x04
/* ************************************************************************* */
/* Helpers */
/* ************************************************************************* */
/* ---
* Helpers.
* --- */
/* Type correspondance type */
struct type_info {
/* identification */
@ -38,9 +40,11 @@ struct type_info {
casio_filefor_t platform;
casio_filetype_t type;
};
/* ************************************************************************* */
/* Correspondances */
/* ************************************************************************* */
/* ---
* Correspondances.
* --- */
/* Main types */
CASIO_LOCAL struct type_info types[] = {
/* fx-CP types */

View File

@ -18,13 +18,16 @@
* ************************************************************************* */
#include "file.h"
/* ************************************************************************* */
/* Check using extensions */
/* ************************************************************************* */
/* Decode function */
/* ---
* Check using extensions.
* --- */
/* Decode function. */
typedef int decode_func OF((casio_file_t**, casio_stream_t*));
/* Correspondance type */
/* Correspondance type. */
struct corresp {
/* extension */
const char *ext;
@ -38,9 +41,7 @@ struct corresp {
/* Correspondances */
CASIO_LOCAL struct corresp correspondances[] = {
#if 0
{"g1s", casio_type_storage, casio_decode_storage},
#endif
{"g1s", casio_filetype_storage, casio_decode_storage},
/* terminating entry */
{NULL, 0, NULL}
@ -74,9 +75,11 @@ CASIO_LOCAL int lookup_extension(const char *path, casio_filetype_t types,
*func = c->decode;
return (0);
}
/* ************************************************************************* */
/* Main decoding function */
/* ************************************************************************* */
/* ---
* Main decoding function.
* --- */
/**
* casio_decode:
* Decode a file.

View File

@ -102,9 +102,10 @@ fail:
return (err);
}
/* ************************************************************************* */
/* Public decoding functions */
/* ************************************************************************* */
/* ---
* Public decoding functions.
* --- */
/**
* casio_decode_cas:
* Decode a CAS file.

View File

@ -28,9 +28,10 @@
#define htoe32(N) ((big_endian) ? htobe32(N) : htole32(N))
#define VER htoe32(0x00000100) /* 1.00 */
/* ************************************************************************* */
/* MAKELONG */
/* ************************************************************************* */
/* ---
* MAKELONG
* --- */
/* This utility comes from Microsoft Windows.
* It makes a 32-bit integer out of two 16-bit integers. */
@ -66,9 +67,11 @@ CASIO_LOCAL casio_uint32_t makelong_be(casio_uint16_t one, casio_uint16_t two)
# undef MAKELONG
#endif
#define MAKELONG(A, B) ((big_endian) ? makelong_be(A, B) : makelong_le(A, B))
/* ************************************************************************* */
/* Utilities */
/* ************************************************************************* */
/* ---
* Utilities.
* --- */
/**
* read_internal:
* Read the internal headers, and check them.
@ -148,9 +151,11 @@ CASIO_LOCAL int read_top(casio_stream_t *buffer, char *name,
/* no error! */
return (0);
}
/* ************************************************************************* */
/* Intermediate functions */
/* ************************************************************************* */
/* ---
* Intermediate functions.
* --- */
/**
* read_picture:
* Read a picture record and content.
@ -365,9 +370,11 @@ fail:
casio_free(tab);
return (0);
}
/* ************************************************************************* */
/* Main function */
/* ************************************************************************* */
/* ---
* Main function.
* --- */
/**
* casio_decode_casemul:
* Decode a CasEmul file.

View File

@ -21,9 +21,10 @@
# include "../file.h"
# include <libcasio/format.h>
/* ************************************************************************* */
/* Main decoding utilities */
/* ************************************************************************* */
/* ---
* Main decoding utilities.
* --- */
/* Main decoding functions with expected types. */
CASIO_EXTERN int CASIO_EXPORT casio_decode_std
OF((casio_file_t **casio__handle,
@ -41,9 +42,11 @@ CASIO_EXTERN int CASIO_EXPORT casio_decode_cas
OF((casio_file_t **casio__handle, casio_stream_t *casio__buffer));
CASIO_EXTERN int CASIO_EXPORT casio_decode_grc
OF((casio_file_t **casio__handle, casio_stream_t *casio__buffer));
/* ************************************************************************* */
/* "Standard"-specific decoding functions */
/* ************************************************************************* */
/* ---
* "Standard"-specific decoding functions.
* --- */
/* Schemes */
# define CASIO_STDFUNC(CASIO__NAME) \
CASIO_EXTERN int CASIO_EXPORT casio_decode_std_##CASIO__NAME \

View File

@ -28,9 +28,10 @@
DREAD(NAM, TYPE) \
obf(&NAM, sizeof(struct TYPE)); }
/* ************************************************************************* */
/* Obfuscation-related functions */
/* ************************************************************************* */
/* ---
* Obfuscation-related functions.
* --- */
/**
* obf:
* Obfuscate AND de-obfuscate a string.
@ -51,9 +52,11 @@ CASIO_LOCAL void obf(unsigned char *s, size_t n)
while (n--)
*s++ ^= ~24;
}
/* ************************************************************************* */
/* File header */
/* ************************************************************************* */
/* ---
* File header.
* --- */
static unsigned char header[] =
"\xD5\xD7\x1F" "f" "FX-INTERFACE - YELLOW COMPUTING" /* 35 */

View File

@ -20,9 +20,10 @@
#include "../corresp/standard.h"
#define FUNC(NAME) casio_decode_std_##NAME
/* ************************************************************************* */
/* Getting the decoding function */
/* ************************************************************************* */
/* ---
* Getting the decoding function.
* --- */
/* Correspondance type */
typedef int decode_func ();
struct decode_corresp {
@ -90,9 +91,11 @@ CASIO_LOCAL int find_decode_function(casio_filefor_t platform,
*rd = c->decode;
return (0);
}
/* ************************************************************************* */
/* Main standard header decoding function */
/* ************************************************************************* */
/* ---
* Main standard header decoding function.
* --- */
/**
* casio_decode_std:
* Decode a file with standard header.

View File

@ -18,9 +18,10 @@
* ************************************************************************* */
#include "../decode.h"
/* ************************************************************************* */
/* Add-in for the fx-9860G (G1A) */
/* ************************************************************************* */
/* ---
* Add-in for the fx-9860G (G1A).
* --- */
/**
* casio_decode_std_addin:
* Decodes a "normal" add-in (after Standard Header).
@ -85,9 +86,11 @@ fail:
casio_free_file(*h); *h = NULL;
return (err);
}
/* ************************************************************************* */
/* Add-in for the fx-CP/Classpad (C1A) */
/* ************************************************************************* */
/* ---
* Add-in for the fx-CP/Classpad (C1A).
* --- */
/**
* casio_decode_std_cp_addin:
* Decode fx-CP add-in.
@ -155,9 +158,11 @@ fail:
casio_free_file(*h); *h = NULL;
return (err);
}
/* ************************************************************************* */
/* Add-in for the fx-CG/Prizm (G3A) */
/* ************************************************************************* */
/* ---
* Add-in for the fx-CG/Prizm (G3A).
* --- */
/**
* casio_decode_std_cg_addin:
* Decode fx-CG add-in.

View File

@ -18,10 +18,12 @@
* ************************************************************************* */
#include "../decode.h"
/* ************************************************************************* */
/* Content parsing */
/* ************************************************************************* */
/* line content parsing function prototype */
/* ---
* Content parsing.
* --- */
/* Line content parsing function prototype. */
static int eact_decode_line(casio_line_t *handle, uint8_t *buf, size_t size,
uint_fast8_t type);
@ -133,25 +135,29 @@ fail:
return (err);
}
/* ************************************************************************* */
/* Content Type correspondance list */
/* ************************************************************************* */
/* Correspondance type */
/* ---
* Content Type correspondance list.
* --- */
/* Correspondance type. */
struct eact_content_type_corresp {
const char *type;
int (*decode)(casio_line_t*, uint8_t*, size_t);
};
/* Correspondance list */
/* Correspondance list. */
static struct eact_content_type_corresp eact_content_types[] = {
{"@EACT\0\0", eact_decode_content_eact},
{}
};
/* ************************************************************************* */
/* Line parsing */
/* ************************************************************************* */
/* ---
* Line parsing.
* --- */
/**
* eact_decode_line_content:
* Decodes an E-Activity content.
@ -371,10 +377,13 @@ static int eact_decode_line_code(casio_line_t *handle, uint8_t *buf,
mem((ll_info, buf, size));
return (0);
}
/* ************************************************************************* */
/* Line Type correspondance list */
/* ************************************************************************* */
/* Correspondance type */
/* ---
* Line Type correspondance list.
* --- */
/* Correspondance type. */
struct eact_line_type_corresp {
int rawtype;
@ -382,7 +391,8 @@ struct eact_line_type_corresp {
const char *info;
};
/* All correspondances */
/* All correspondances. */
static struct eact_line_type_corresp eact_line_types[] = {
{casio_eact_ltype_calc, eact_decode_line_calculation,
"calculation"},
@ -434,9 +444,11 @@ static int eact_decode_line(casio_line_t *handle, uint8_t *buf, size_t size,
msg((ll_info, "line type is '%s' (0x%02x)", linetype->info, type));
return ((*linetype->decode)(handle, buf, size));
}
/* ************************************************************************* */
/* Main parsing functions */
/* ************************************************************************* */
/* ---
* Main parsing functions.
* --- */
/**
* casio_decode_std_eact:
* Decodes an EACT.

View File

@ -18,9 +18,10 @@
* ************************************************************************* */
#include "../decode.h"
/* ************************************************************************* */
/* Utilities */
/* ************************************************************************* */
/* ---
* Utilities.
* --- */
/**
* fkeydup:
* "Duplicate" function key.
@ -58,9 +59,11 @@ CASIO_LOCAL casio_pixel_t **fkeydup3(unsigned char *fkey)
FKEY3_WIDTH, FKEY3_HEIGHT);
return (pixels);
}
/* ************************************************************************* */
/* Decoding fx function keys file (G1N) */
/* ************************************************************************* */
/* ---
* Decoding fx function keys file (G1N).
* --- */
/**
* casio_decode_std_fkey:
* Decode fx function keys files.
@ -127,9 +130,11 @@ fail:
casio_free_file(*h); *h = NULL;
return (err);
}
/* ************************************************************************* */
/* Decoding fx-CG/Prizm function keys file (G3N) */
/* ************************************************************************* */
/* ---
* Decoding fx-CG/Prizm function keys file (G3N).
* --- */
/**
* casio_decode_std_cg_fkey:
* Decode fx-CG key files.

View File

@ -53,9 +53,11 @@ CASIO_LOCAL int decode_lang_entry(casio_file_t *handle,
msg((ll_info, "[#%d] '%s'", id, str));
return (0);
}
/* ************************************************************************* */
/* fx language files parsing */
/* ************************************************************************* */
/* ---
* fx language files parsing.
* --- */
/**
* casio_decode_std_lang:
* Decode fx language files.

View File

@ -19,9 +19,10 @@
#include "../decode.h"
#include <zlib.h>
/* ************************************************************************* */
/* Obfuscation-related functions */
/* ************************************************************************* */
/* ---
* Obfuscation-related functions.
* --- */
/**
* g3p_deobfuscate:
* De-obfuscate the image data.
@ -37,9 +38,11 @@ CASIO_LOCAL void g3p_deobfuscate(unsigned char *buf, size_t n)
*buf++ = (byte << 5) | (byte >> 3);
}
}
/* ************************************************************************* */
/* Prizm Picture decoding function */
/* ************************************************************************* */
/* ---
* Prizm Picture decoding function.
* --- */
/**
* casio_decode_std_g3p:
* Decode a G3P file.
@ -64,8 +67,11 @@ int CASIO_EXPORT casio_decode_std_g3p(casio_file_t **h, casio_stream_t *buffer,
casio_uint8_t *defbuf = NULL, *infbuf = NULL;
casio_file_t *handle;
*h = NULL; (void)pic;
/* read the image header */
*h = NULL;
(void)pic;
/* Read the image header. */
DREAD(ihd)
width = be16toh(ihd.casio_prizm_picture_subheader_width);
height = be16toh(ihd.casio_prizm_picture_subheader_height);
@ -81,37 +87,42 @@ int CASIO_EXPORT casio_decode_std_g3p(casio_file_t **h, casio_stream_t *buffer,
rawcol));
err = casio_error_magic; goto fail;
}
msg((ll_info, "Picture format: %s", coldesc));
gen = be16toh(ihd.casio_prizm_picture_subheader_generator_id);
msg((ll_info, "Generator ID: 0x%04X", gen));
msg((ll_info, "-"));
/* read deflated image */
/* Read the deflated image. */
deflated_size = be32toh(ihd.casio_prizm_picture_subheader_data_size)
- 6; /* FIXME: dangerous */
msg((ll_info, "Reading %" CASIO_PRIuSIZE "B of deflated data",
deflated_size));
err = casio_error_alloc;
if (!(defbuf = casio_alloc(deflated_size, 1))) goto fail;
if (!(defbuf = casio_alloc(deflated_size, 1)))
goto fail;
READ(defbuf, deflated_size)
/* unobfuscate if required */
/* Unobfuscate if required. */
if (std->casio_standard_header_obfuscated0) {
msg((ll_info, "Is obfuscated, let's deobfuscate!"));
g3p_deobfuscate(defbuf, deflated_size);
}
/* make the destination buffer */
/* Make the destination buffer. */
rawsize = casio_get_picture_size(NULL, picfmt, width, height);
err = casio_error_alloc;
if (!(infbuf = casio_alloc(rawsize, 1))) goto fail;
if (!(infbuf = casio_alloc(rawsize, 1)))
goto fail;
/* uncompress */
inflated_size = (uLong)rawsize;
z_err = uncompress(infbuf, &inflated_size,
defbuf, (uLong)deflated_size);
z_err = uncompress(infbuf, &inflated_size, defbuf, (uLong)deflated_size);
if (z_err) {
msg((ll_fatal, "Zlib error: error #%d", z_err));
msg((ll_fatal, "Zlib error %d: %s", z_err, zError(err)));
err = casio_error_magic;
goto fail;
}
@ -151,9 +162,11 @@ fail:
casio_free(infbuf); casio_free(defbuf);
return (err);
}
/* ************************************************************************* */
/* Classpad Picture decoding function */
/* ************************************************************************* */
/* ---
* Classpad Picture decoding function.
* --- */
/**
* casio_decode_std_c2p:
* Decode Classpad images.

View File

@ -1,6 +1,6 @@
/* ****************************************************************************
* mcs/local/list.c -- list files in a local main memory.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
* file/decode/decode.c -- decode a "standard" CASIO file.
* Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
@ -16,35 +16,24 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "local.h"
#include "decode.h"
/**
* casio_localmcs_list:
* List files in a local main memory.
* casio_decode_storage:
* Decode a fx-9860G storage memory.
*
* @arg cookie the local main memory cookie.
* @arg mcslist the listing callback.
* @arg mcookie the callback cookie.
* @arg handlep the handle to create.
* @arg buffer the buffer to read from.
*/
int CASIO_EXPORT casio_localmcs_list(localmcs_t *cookie,
casio_mcslist_t *mcslist, void *mcookie)
int CASIO_EXPORT casio_decode_storage(casio_file_t **handlep,
casio_stream_t *buffer)
{
int i, count = cookie->localmcs_count;
/* TODO: code this function. */
for (i = 0; count && i < cookie->localmcs_size; i++) {
casio_mcsfile_t *file = cookie->localmcs_files[i];
(void)handlep;
(void)buffer;
/* Check that the file exists. */
if (!file) continue;
/* Decrement the count, so that we don't have to go to the end. */
count--;
/* Call back the callback. */
(*mcslist)(mcookie, &file->casio_mcsfile_head);
}
/* Everything went well :) */
return (0);
msg((ll_info, "storage memory decoding is not available yet."));
return (casio_error_op);
}

View File

@ -21,10 +21,12 @@
# include "../internals.h"
# include "decode/decode.h"
/* ************************************************************************* */
/* Macros for interacting with the buffer */
/* ************************************************************************* */
/* ---
* Macros for interacting with the buffer.
* --- */
/* Read from a stream. */
# define READ(CASIO__TO, CASIO__SZ) /* normal read */ { \
int READ_err = casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
if (READ_err) return (READ_err); }
@ -35,12 +37,14 @@
goto fail;
/* Read using size of the object. */
# define DREAD(CASIO__TO) \
READ(&CASIO__TO, sizeof(CASIO__TO))
# define GDREAD(CASIO__TO) \
GREAD(&CASIO__TO, sizeof(CASIO__TO))
/* Skip. */
# define SKIP(CASIO__SZ) { \
int SKIP_err = casio_skip(buffer, CASIO__SZ); \
if (SKIP_err) return (SKIP_err); }
@ -49,14 +53,17 @@
if (err) goto fail; }
/* Write. */
# define WRITE(CASIO__BUF, CASIO__SZ) { \
int WRITE_err = casio_write(buffer, (CASIO__BUF), (CASIO__SZ)); \
if (WRITE_err) return (WRITE_err); }
# define DWRITE(CASIO__OBJECT) \
WRITE(&(CASIO__OBJECT), sizeof(CASIO__OBJECT))
/* ************************************************************************* */
/* Picture utilities */
/* ************************************************************************* */
/* ---
* Picture utilities.
* --- */
# define alloc_pixels(W, H) \
casio_alloc(sizeof(casio_pixel_t*) * \
(H) + sizeof(casio_pixel_t) * (W) * (H), 1)

View File

@ -23,9 +23,10 @@
return (casio_error_alloc); \
handle = *h; memset(handle, 0, sizeof(casio_file_t))
/* ************************************************************************* */
/* Make a handle */
/* ************************************************************************* */
/* ---
* Make a handle.
* --- */
/**
* casio_make_picture:
* Make a picture handle.
@ -262,9 +263,11 @@ fail:
casio_free_file(*h); *h = NULL;
return (casio_error_alloc);
}
/* ************************************************************************* */
/* Free a handle */
/* ************************************************************************* */
/* ---
* Free a handle.
* --- */
/**
* casio_free_file:
* Free a handle and its data.

View File

@ -63,6 +63,7 @@ int CASIO_EXPORT casio_open_usb(casio_link_t **handle, unsigned long flags,
switch ((err = casio_open_seven_scsi(&ns, stream))) {
case 0:
msg((ll_info, "Using stream over SCSI commands."));
stream = ns;
break;

View File

@ -24,9 +24,10 @@
#include <stdlib.h>
#include <string.h>
/* ************************************************************************* */
/* Logging */
/* ************************************************************************* */
/* ---
* Logging.
* --- */
/**
* getowstring:
* Get overwrite string (useful for logging).
@ -46,10 +47,13 @@ CASIO_LOCAL const char* getowstring(casio_seven_ow_t code)
if (code > 0x02) return ("<unknown overwriting mode>");
return (moo[code]);
}
/* ************************************************************************* */
/* Macros */
/* ************************************************************************* */
/* if command is not supported, return */
/* ---
* Macros.
* --- */
/* if command is not supported, return. */
#define CHECK_IF_COMMAND_IS_SUPPORTED(N) \
if (!command_is_supported(N)) \
return (casio_error_op);
@ -147,9 +151,11 @@ int CASIO_EXPORT casio_seven_send_cmd_data(casio_link_t *handle,
return (casio_seven_send_ext(handle,
casio_seven_type_cmd, subtype, buf, buflen, 1));
}
/* ************************************************************************* */
/* Typical MCS command */
/* ************************************************************************* */
/* ---
* Typical MCS command.
* --- */
/**
* casio_seven_send_typical_mcs_command:
* Send a typical MCS command.
@ -174,9 +180,11 @@ int CASIO_EXPORT casio_seven_send_typical_mcs_command(casio_link_t *handle,
head->casio_mcshead_dirname, head->casio_mcshead_name,
head->casio_mcshead_group, NULL, NULL, NULL));
}
/* ************************************************************************* */
/* Special commands */
/* ************************************************************************* */
/* ---
* Special commands.
* --- */
/**
* casio_seven_send_cmdsys_setlink:
* Set link settings.
@ -240,10 +248,13 @@ int CASIO_EXPORT casio_seven_send_cmdosu_upandrun(casio_link_t *handle,
return (casio_seven_send_ext(handle, casio_seven_type_cmd,
casio_seven_cmdosu_upandrun, buf, 24, 1));
}
/* ************************************************************************* */
/* Decode incoming packet */
/* ************************************************************************* */
/* macro to copy an argument into the packet */
/* ---
* Decode incoming packet.
* --- */
/* Macro to copy an argument into the packet. */
#define cpy_arg(I) { \
size_t ALEN = arglengths[I]; \
memcpy(packet->casio_seven_packet__argsdata[I], p, ALEN); \

View File

@ -20,9 +20,10 @@
* ************************************************************************* */
#include "data.h"
/* ************************************************************************* */
/* Main functions */
/* ************************************************************************* */
/* ---
* Main functions.
* --- */
/**
* casio_seven_send_data_packet:
* Send data packet.
@ -109,9 +110,11 @@ int CASIO_EXPORT casio_seven_unshift(casio_link_t *handle)
/* then return */
return (0);
}
/* ************************************************************************* */
/* Decode a data packet data */
/* ************************************************************************* */
/* ---
* Decode data from a data packet.
* --- */
/**
* casio_seven_decode_data:
* Get data from data packet data field.
@ -135,6 +138,7 @@ int CASIO_EXPORT casio_seven_decode_data(casio_link_t *handle,
* data packet, without any need for an answer from the other part.
* This is a preferable method of identifying these strangly
* formatted data packets. */
if (packet->casio_seven_packet_code < 0x70
|| packet->casio_seven_packet_code > 0x7F) {
/* total number */

View File

@ -23,9 +23,10 @@
#define BUFNUM 64
#define BUFSIZE (ONEBUF * BUFNUM)
/* ************************************************************************* */
/* Buffer version */
/* ************************************************************************* */
/* ---
* Buffer version.
* --- */
/**
* casio_seven_send_buffer:
* Part of the packet flows where data is sent.
@ -190,9 +191,11 @@ int CASIO_EXPORT casio_seven_get_buffer(casio_link_t *handle,
fail:
return (err);
}
/* ************************************************************************* */
/* Data version */
/* ************************************************************************* */
/* ---
* Data version.
* --- */
/**
* casio_seven_send_data:
* Part of the packet flow where data is sent - buffer version.

View File

@ -24,6 +24,7 @@
#define BUFSIZE CASIO_SEVEN_MAX_RAWDATA_SIZE
/* Cookie structure. */
typedef struct {
int _faulty, _read;
@ -38,9 +39,11 @@ typedef struct {
unsigned char _reserved[8];
unsigned char _current[BUFSIZE];
} seven_data_cookie_t;
/* ************************************************************************* */
/* Callbacks */
/* ************************************************************************* */
/* ---
* Callbacks.
* --- */
/**
* casio_seven_data_read:
* Read data from the calculator, using Protocol 7.00 data flow.
@ -288,9 +291,11 @@ fail:
casio_free(cookie);
return (err);
}
/* ************************************************************************* */
/* Opening functions */
/* ************************************************************************* */
/* ---
* Opening functions.
* --- */
CASIO_LOCAL const casio_streamfuncs_t seven_data_callbacks =
casio_stream_callbacks_for_virtual(casio_seven_data_close,
casio_seven_data_read, casio_seven_data_write, NULL);

View File

@ -29,9 +29,11 @@ typedef struct {
const char *model;
casio_seven_env_t env;
} env_corresp_t;
/* ************************************************************************* */
/* Main data */
/* ************************************************************************* */
/* ---
* Main data.
* --- */
/* mask bits */
#define MASK_ALL 1
#define MASK_RESET 2
@ -189,14 +191,14 @@ CASIO_LOCAL env_corresp_t known_environments[] = {
MASK_ALL | MASK_RESET | MASK_MCS}},
{"Gy49000F", {"Graph 25+E (modified fx-7400GII-2)",
MASK_ALL | MASK_RESET | MASK_MCS}},
{"Gy363004", {"fx-9860G (Graph 85)",
MASK_ALL | MASK_RESET | MASK_MCS | MASK_FLS}},
{"Gy362006", {"fx-9750GII (Graph 25+Pro)",
MASK_ALL | MASK_RESET | MASK_MCS}},
{"Gy362007", {"fx-9750GII-2 (Graph 35+ SH4)",
MASK_ALL | MASK_RESET | MASK_MCS}},
{"Gy36200F", {"Graph 35+E (modified fx-9750GII-2)",
MASK_ALL | MASK_RESET | MASK_MCS}},
{"Gy363004", {"fx-9860G (Graph 85)",
MASK_ALL | MASK_RESET | MASK_MCS | MASK_FLS}},
{"Gy363006", {"fx-9860GII (Graph 75 SH3)",
MASK_ALL | MASK_RESET | MASK_MCS | MASK_FLS
| MASK_OSUPDATE_1}},
@ -211,9 +213,11 @@ CASIO_LOCAL env_corresp_t known_environments[] = {
{NULL, {"Default environment", MASK_ALL | MASK_MCS | MASK_FLS}}
};
/* ************************************************************************* */
/* Internal functions */
/* ************************************************************************* */
/* ---
* Internal functions.
* --- */
/**
* casio_seven_getenv:
* Get the environment type.

View File

@ -19,20 +19,21 @@
#include "../link.h"
#include <string.h>
/* ************************************************************************* */
/* Raw layout of an extended ack data */
/* ************************************************************************* */
/* ---
* Raw layout of an extended ack data.
* --- */
typedef struct {
/* hardware identifier - ASCII */
unsigned char hwid[8];
/* processor identifier - ASCII */
unsigned char cpuid[16];
/* preprogrammed ROM capacity - ASCII-hex (Ko) */
/* preprogrammed ROM capacity - ASCII-dec (Ko) */
unsigned char preprog_rom_capacity[8];
/* flash ROM capacity - ASCII-hex (Ko) */
/* flash ROM capacity - ASCII-dec (Ko) */
unsigned char flash_rom_capacity[8];
/* RAM capacity - ASCII-hex (Ko) */
/* RAM capacity - ASCII-dec (Ko) */
unsigned char ram_capacity[8];
/* preprogrammed ROM version - "xx.xx.xxxx" + 0xff bytes */
@ -56,13 +57,14 @@ typedef struct {
unsigned char protocol_version[4];
/* product ID */
unsigned char product_id[16];
/* name set by user in SYSTEM */
/* name set by user in SYSTEM (if not in exam mode) */
unsigned char username[16];
} packetdata_ackext_t;
/* ************************************************************************* */
/* Utilities */
/* ************************************************************************* */
/* ---
* Utilities.
* --- */
/**
* version_of_string:
* Get version from 16-bytes char buffer.
@ -92,9 +94,11 @@ CASIO_LOCAL void string_of_version(unsigned char *data,
casio_encode_version((char*)data, ver);
memset(&data[10], '\xFF', 6);
}
/* ************************************************************************* */
/* Send ACK packets */
/* ************************************************************************* */
/* ---
* Send ACK packets.
* --- */
/**
* casio_seven_send_eack:
* Sends an extended ack.
@ -157,9 +161,10 @@ int CASIO_EXPORT casio_seven_send_eack(casio_link_t *handle,
sizeof(packetdata_ackext_t), 1));
}
/* ************************************************************************* */
/* Decode an ACK packet */
/* ************************************************************************* */
/* ---
* Decode an ACK packet.
* --- */
/**
* cpy_string:
* Copy a string terminated with 0xFFs, with a maximum size.

View File

@ -107,7 +107,6 @@ CASIO_LOCAL int seven_scsi_read(seven_scsi_cookie_t *cookie,
do {
casio_uint8_t *to;
size_t avail;
/* casio_uint16_t activity; */
/* Polling loop. */
@ -116,6 +115,8 @@ CASIO_LOCAL int seven_scsi_read(seven_scsi_cookie_t *cookie,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
casio_uint8_t poll_data[16];
msg((ll_info, "Polling available data using command C0..."));
/* Send the polling command, extract the data. */
scsi.casio_scsi_cmd = poll_command;
@ -127,13 +128,16 @@ CASIO_LOCAL int seven_scsi_read(seven_scsi_cookie_t *cookie,
if ((err = casio_scsi_request(cookie->stream, &scsi)))
return (err);
avail = (poll_data[7] << 8) | poll_data[8];
/* activity = (poll_data[10] << 8) | poll_data[11]; */
mem((ll_info, poll_data, 16));
avail = (poll_data[6] << 8) | poll_data[7];
/* Check if there are some bytes to get. */
if (!avail) {
/* FIXME: delay and check the timeout!!! */
msg((ll_info, "No available data, sleeping for 1 second."));
casio_sleep(1000);
/* FIXME: check the timeout!!! */
continue;
}
@ -208,6 +212,8 @@ CASIO_LOCAL int seven_scsi_write(seven_scsi_cookie_t *cookie,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
casio_uint8_t poll_data[16];
msg((ll_info, "Polling the activity using command C0..."));
/* Poll to check the activity. */
scsi.casio_scsi_cmd = poll_command;
@ -219,14 +225,16 @@ CASIO_LOCAL int seven_scsi_write(seven_scsi_cookie_t *cookie,
if ((err = casio_scsi_request(cookie->stream, &scsi)))
return (err);
#if 0
activity = (poll_data[10] << 8) | poll_data[11];
if (activity == 0x100) {
if (activity == 0x1000) {
/* The calculator is busy.
* FIXME: delay and check the timeout!! */
continue;
}
#endif
break;
}
@ -238,6 +246,8 @@ CASIO_LOCAL int seven_scsi_write(seven_scsi_cookie_t *cookie,
casio_uint8_t send_command[16] = {0xC2,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
msg((ll_info, "Sending the data using command C2..."));
send_command[6] = (to_send >> 8) & 0xFF;
send_command[7] = to_send & 0xFF;

View File

@ -36,9 +36,11 @@
handle->casio_link_flags = \
( handle->casio_link_flags & ~casio_linkflag_sendalt) | \
(~handle->casio_link_flags & casio_linkflag_sendalt);
/* ************************************************************************* */
/* Main functions */
/* ************************************************************************* */
/* ---
* Main functions.
* --- */
/**
* casio_seven_send_buf:
* Send a buffer.
@ -206,9 +208,11 @@ int CASIO_EXPORT casio_seven_send_again(casio_link_t *handle)
/* send it */
return (casio_seven_send_buf(handle, NULL, 0, 1));
}
/* ************************************************************************* */
/* Special packets */
/* ************************************************************************* */
/* ---
* Special packets.
* --- */
/**
* casio_seven_send_err_resend:
* Resend the resend error.

154
lib/link/seven/server.c Normal file
View File

@ -0,0 +1,154 @@
/* ****************************************************************************
* link/usage/server/seven.c -- serving a Protocol 7.00 server.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../link.h"
/* ---
* New-style server requests and responses.
* --- */
/**
* casio_seven_start_server:
* Become passive when active.
*
* @arg handle the link handle.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_seven_start_server(casio_link_t *handle)
{
int err;
/* Make checks. */
if (!handle)
return (casio_error_init);
if (handle->casio_link_flags & casio_linkflag_ended)
return (casio_error_init);
/* If active, we just want to send a swap and become passive. */
if (handle->casio_link_flags & casio_linkflag_active) {
if ((err = casio_seven_send_swp(handle)))
return (err);
return (0);
}
/* We are passive, so we want to wait for the initial check from
* the counterpart and ACK it. If the received packet is not an
* initial check, we don't respond, just like the calculator.
*
* TODO: and if the start packet is in the middle of a packet? */
do {
if ((err = casio_seven_receive(handle, 0)))
return (err);
} while (response.casio_seven_packet_type != casio_seven_type_chk
|| !response.casio_seven_packet_initial);
err = casio_seven_send_ack(handle, 1);
if (err) return (err);
return (0);
}
/**
* casio_seven_get_next_request:
* Get the next request if server.
*
* @arg handle the link handle.
* @return the error.
*/
int CASIO_EXPORT casio_seven_get_next_request(casio_link_t *handle)
{
int err;
/* TODO: check if the last action was receive, and if it is not
* the case, receive? */
if (response.casio_seven_packet_type != casio_seven_type_cmd) {
if (response.casio_seven_packet_type == casio_seven_type_end)
return (casio_seven_send_ack(handle, 0));
if (response.casio_seven_packet_type == casio_seven_type_swp)
return (casio_error_iter);
if ((err = casio_seven_send_err(handle, casio_seven_err_other)))
return (err);
}
return (0);
}
/* ---
* Old-style server using the new-style utilities.
* --- */
/**
* casio_seven_serve:
* Take control of the execution thread to make a passive server.
*
* @arg handle the link handle.
* @arg callbacks the callbacks.
* @arg cookie i suppose that's just the way that cookie crumbles.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_seven_serve(casio_link_t *handle,
casio_seven_server_func_t * const *callbacks, void *cookie)
{
int err;
if ((err = casio_seven_start_server(handle)) && err != casio_error_active)
return (err);
while (1) {
/* Check if the next element is a command. */
switch (casio_seven_get_next_request(handle)) {
case 0:
break;
case casio_error_iter:
return (0);
default:
return (err);
}
/* Check if the callback exists. */
if (!callbacks[response.casio_seven_packet_code]) {
err = casio_seven_send_err(handle, casio_seven_err_other);
if (err)
return (err);
continue;
}
/* Call the callback. */
err = (*callbacks[response.casio_seven_packet_code])(cookie, handle);
if (err) {
if (err != casio_error_unknown)
return (err);
err = casio_seven_send_err(handle, casio_seven_err_other);
if (err)
return (err);
continue;
}
}
return (0);
}

View File

@ -20,9 +20,10 @@
* ************************************************************************* */
#include "seven_mcs.h"
/* ************************************************************************* */
/* Protocol 7.00 MCS file gathering */
/* ************************************************************************* */
/* ---
* Protocol 7.00 MCS file gathering.
* --- */
struct thecookie {
int _called;
int _err;
@ -91,9 +92,11 @@ CASIO_LOCAL int get_setup_entry(casio_setup_t *setup, casio_link_t *handle)
/* Once the setup has been fed, send the ACK. */
return (casio_seven_send_ack(handle, 1));
}
/* ************************************************************************* */
/* File request function */
/* ************************************************************************* */
/* ---
* File request function.
* --- */
/**
* request_file:
* Request a file.
@ -141,9 +144,11 @@ CASIO_LOCAL int request_file(sevenmcs_t *cookie,
/* Check if the function was called. */
return (thecookie._called ? thecookie._err : casio_error_unknown);
}
/* ************************************************************************* */
/* Special types */
/* ************************************************************************* */
/* ---
* Special types.
* --- */
/**
* request_alphamem:
* Get the alpha memory.
@ -241,9 +246,11 @@ fail:
*mcsfile = NULL;
return (err);
}
/* ************************************************************************* */
/* Main function */
/* ************************************************************************* */
/* ---
* Main function.
* --- */
/**
* casio_sevenmcs_get:
* Get a file from a Protocol 7.00 main memory interface.

211
lib/link/seven_mcs/iter.c Normal file
View File

@ -0,0 +1,211 @@
/* ****************************************************************************
* link/seven_mcs/iter.c -- iterate on files on a protocol seven main memory.
* Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "seven_mcs.h"
#define IS_ALPHA 0
#define IS_SETUP 1
#define IS_OTHER 2
struct thecookie {
casio_link_t *handle;
int status;
casio_mcshead_t head;
};
/* Alpha memory and settings are two special entries that are not explicitely
* listed and got/sent as files, we ought to make an abstraction powerful
* enough to treat them as they are. */
const casio_mcshead_t casio_sevenmcs_list_alpha_entry = {
0, casio_mcstype_alphamem, 0,
/* count: */ 29, 0, 0, 0,
/* rawtype: */ 0x00, 0, 0,
/* name: */ "ALPHA MEM", "",
/* group: */ "ALPHA MEM",
/* dirname: */ "$GLOBAL",
"", ""
};
const casio_mcshead_t casio_sevenmcs_list_setup_entry = {
0, casio_mcstype_setup, 0,
0, 0, 0, 100,
/* rawtype: */ 0x14, 0, 0,
/* name: */ "SETUP", "",
/* group: */ "SETUP",
/* dirname: */ "$GLOBAL",
"", ""
};
/**
* next_entry:
* Get the next file.
*
* @arg cookie the iterator cookie.
* @arg ptr the pointer to set.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int next_entry(struct thecookie *cookie, void **ptr)
{
int err;
casio_link_t *handle = cookie->handle;
casio_mcshead_t *head = &cookie->head;
/* The pointer will always be on the head contained in the cookie. */
*ptr = head;
/* Special file. */
if (cookie->status == IS_ALPHA) {
cookie->status++;
memcpy(head, &casio_sevenmcs_list_alpha_entry, sizeof(*head));
return (0);
}
if (cookie->status == IS_SETUP) {
cookie->status++;
memcpy(head, &casio_sevenmcs_list_setup_entry, sizeof(*head));
return (0);
}
/* Main loop. */
while (1) {
/* Get the next request. */
err = casio_seven_get_next_request(handle);
if (err) { /* `casio_error_iter` included */
*ptr = NULL;
return (err);
}
/* Copy the raw information. */
head->casio_mcshead_flags = casio_mcsfor_mcs;
head->casio_mcshead_size = response.casio_seven_packet_filesize;
head->casio_mcshead_rawtype = response.casio_seven_packet_mcstype;
if (response.casio_seven_packet_args[0]) {
strncpy(head->casio_mcshead_dirname,
response.casio_seven_packet_args[0], 8);
head->casio_mcshead_dirname[8] = 0;
} else
head->casio_mcshead_dirname[0] = 0;
if (response.casio_seven_packet_args[1]) {
strncpy(head->casio_mcshead_name,
response.casio_seven_packet_args[1], 12);
head->casio_mcshead_name[12] = 0;
} else
head->casio_mcshead_name[0] = 0;
if (response.casio_seven_packet_args[2]) {
strncpy(head->casio_mcshead_group,
response.casio_seven_packet_args[2], 16);
head->casio_mcshead_group[16] = 0;
} else
head->casio_mcshead_group[0] = 0;
casio_correct_mcshead(head, 0);
/* Send an ACK. */
if ((err = casio_seven_send_ack(handle, 1)))
return (err);
/* Check if it is a file we want to ignore. */
if (head->casio_mcshead_type
& (casio_mcstype_alpha | casio_mcstype_setup))
continue;
break;
}
/* The head is ready, and `*ptr` is already filled (since the beginning
* of the function), so let's send this! */
return (0);
}
/**
* free_cookie:
* Free the cookie.
*
* @arg cookie the cookie.
*/
CASIO_LOCAL void free_cookie(struct thecookie *cookie)
{
int err;
/* Try to empty the iterator until we're active */
while (!casio_seven_get_next_request(cookie->handle)
&& !casio_seven_send_ack(cookie->handle, 1));
/* Free the cookie. */
casio_free(cookie);
}
/* The functions structure. */
CASIO_LOCAL casio_iter_funcs_t funcs = {
(casio_next_t *)next_entry,
NULL,
(casio_end_t *)free_cookie
};
/**
* casio_sevenmcs_iter:
* Iterate on a Protocol 7.00 MCS.
*
* @arg cookie the cookie.
* @arg iterp the iterator to create.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_sevenmcs_iter(sevenmcs_t *cookie,
casio_iter_t **iterp)
{
casio_link_t *handle = cookie->sevenmcs_link;
struct thecookie *itercookie;
int err;
/* Allocate the cookie. */
itercookie = casio_alloc(sizeof(*cookie), 1);
if (!itercookie)
return (casio_error_alloc);
itercookie->handle = handle;
itercookie->status = IS_ALPHA;
/* Prepare the link. */
if ((err = casio_seven_send_cmdmcs_reqallinfo(handle))
|| (err = casio_seven_start_server(handle))) {
casio_free(cookie);
return (err);
}
/* We're good, let's create the iterator. */
return (casio_iter(iterp, itercookie, &funcs));
}

View File

@ -1,133 +0,0 @@
/* ****************************************************************************
* link/seven_mcs/list.c -- list files on a protocol seven main memory.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "seven_mcs.h"
struct thecookie {
casio_mcslist_t *_mcslist;
void *_mcookie;
};
/**
* file_info:
* The file information callback.
*
* @arg cookie the cookie.
* @arg handle the link handle.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int file_info(struct thecookie *cookie, casio_link_t *handle)
{
casio_mcshead_t head;
/* Copy the raw information. */
head.casio_mcshead_flags = casio_mcsfor_mcs;
head.casio_mcshead_size = response.casio_seven_packet_filesize;
head.casio_mcshead_rawtype = response.casio_seven_packet_mcstype;
if (response.casio_seven_packet_args[0]) {
strncpy(head.casio_mcshead_dirname,
response.casio_seven_packet_args[0], 8);
head.casio_mcshead_dirname[8] = 0;
} else head.casio_mcshead_dirname[0] = 0;
if (response.casio_seven_packet_args[1]) {
strncpy(head.casio_mcshead_name,
response.casio_seven_packet_args[1], 12);
head.casio_mcshead_name[12] = 0;
} else head.casio_mcshead_name[0] = 0;
if (response.casio_seven_packet_args[2]) {
strncpy(head.casio_mcshead_group,
response.casio_seven_packet_args[2], 16);
head.casio_mcshead_group[16] = 0;
} else head.casio_mcshead_group[0] = 0;
/* Try to make abstract information out of the raw information. */
casio_correct_mcshead(&head, 0);
/* If these are not special files we want to ignore,
* return this head to the user, and end the command response. */
if (!(head.casio_mcshead_type
& (casio_mcstype_alpha | casio_mcstype_setup)))
(*cookie->_mcslist)(cookie->_mcookie, &head);
/* Don't forget the ack! */
return (casio_seven_send_ack(handle, 1));
}
/* Alpha memory and settings are two special entries that are not explicitely
* listed and got/sent as files, we ought to make an abstraction powerful
* enough to treat them as they are. */
const casio_mcshead_t CASIO_EXPORT casio_sevenmcs_list_alpha_entry = {
0, casio_mcstype_alphamem, 0,
/* count: */ 29, 0, 0, 0,
/* rawtype: */ 0x00, 0, 0,
/* name: */ "ALPHA MEM", "",
/* group: */ "ALPHA MEM",
/* dirname: */ "$GLOBAL",
"", ""
};
const casio_mcshead_t CASIO_EXPORT casio_sevenmcs_list_setup_entry = {
0, casio_mcstype_setup, 0,
0, 0, 0, 100,
/* rawtype: */ 0x14, 0, 0,
/* name: */ "SETUP", "",
/* group: */ "SETUP",
/* dirname: */ "$GLOBAL",
"", ""
};
/**
* casio_sevenmcs_list:
* List a Protocol 7.00 MCS.
*
* @arg cookie the cookie.
* @arg mcslist the listing callback.
* @arg mcookie the listing callback cookie.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_sevenmcs_list(sevenmcs_t *cookie,
casio_mcslist_t *mcslist, void *mcookie)
{
int err; casio_link_t *handle = cookie->sevenmcs_link;
struct thecookie thecookie;
msg((ll_info, "Sending the file info transfer all request."));
err = casio_seven_send_cmdmcs_reqallinfo(handle);
if (err) return (err);
if (response.casio_seven_packet_type != casio_seven_type_ack)
return (casio_error_unknown);
/* Prepare the cookie. */
thecookie._mcslist = mcslist;
thecookie._mcookie = mcookie;
/* Call the callbacks with the default entries. */
(*mcslist)(mcookie, &casio_sevenmcs_list_alpha_entry);
(*mcslist)(mcookie, &casio_sevenmcs_list_setup_entry);
msg((ll_info, "Preparing the callbacks and running the server."));
memset(handle->casio_link_seven_callbacks, 0,
256 * sizeof(casio_seven_server_func_t*));
handle->casio_link_seven_callbacks[casio_seven_cmdmcs_fileinfo] =
(casio_seven_server_func_t*)&file_info;
err = casio_seven_serve(handle, handle->casio_link_seven_callbacks,
&thecookie);
return (err);
}

View File

@ -18,9 +18,10 @@
* ************************************************************************* */
#include "seven_mcs.h"
/* ************************************************************************* */
/* Close callback */
/* ************************************************************************* */
/* ---
* Close callback.
* --- */
/**
* casio_sevenmcs_close:
* Close a Protocol 7.00 MCS cookie.
@ -38,14 +39,16 @@ CASIO_LOCAL int casio_sevenmcs_close(sevenmcs_t *cookie)
/* Callbacks. */
CASIO_LOCAL casio_mcsfuncs_t seven_mcs_funcs = {
(casio_mcs_get_t*)&casio_sevenmcs_get,
/* (casio_mcs_put_t*)&casio_sevenmcs_put, */ NULL,
(casio_mcs_delete_t*)&casio_sevenmcs_delete,
(casio_mcs_list_t*)&casio_sevenmcs_list,
(casio_mcs_close_t*)&casio_sevenmcs_close};
/* ************************************************************************* */
/* Main opening function */
/* ************************************************************************* */
(casio_mcs_get_t *)&casio_sevenmcs_get,
/* (casio_mcs_put_t *)&casio_sevenmcs_put, */ NULL,
(casio_mcs_delete_t *)&casio_sevenmcs_delete,
(casio_mcs_iter_t *)&casio_sevenmcs_iter,
(casio_mcs_close_t *)&casio_sevenmcs_close};
/* ---
* Main opening function.
* --- */
/**
* casio_open_seven_mcs:
* Open a Protocol 7.00 MCS interface.

View File

@ -34,9 +34,8 @@ CASIO_EXTERN int CASIO_EXPORT casio_sevenmcs_put
CASIO_EXTERN int CASIO_EXPORT casio_sevenmcs_delete
OF((sevenmcs_t *casio__cookie, casio_mcshead_t *casio__mcshead));
CASIO_EXTERN int CASIO_EXPORT casio_sevenmcs_list
OF((sevenmcs_t *casio__cookie, casio_mcslist_t *casio__mcslist,
void *casio__mcslist_cookie));
CASIO_EXTERN int CASIO_EXPORT casio_sevenmcs_iter
OF((sevenmcs_t *casio__cookie, casio_iter_t **casio__iterp));
/* Other globals. */

View File

@ -1,88 +0,0 @@
/* ****************************************************************************
* link/usage/server/seven.c -- serving a Protocol 7.00 server.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../usage.h"
/**
* casio_seven_serve:
* Serve a Protocol 7.00 server.
*
* @arg handle the link handle.
* @arg callbacks the server callbacks (256 entries).
* @arg cookie the server cookie.
* @return the error.
*/
int CASIO_EXPORT casio_seven_serve(casio_link_t *handle,
casio_seven_server_func_t **callbacks, void *cookie)
{
int err;
/* Make checks. */
chk_handle(handle);
chk_seven(handle);
if (handle->casio_link_flags & casio_linkflag_active) {
err = casio_seven_send_swp(handle);
if (err) return (err);
} else {
/* Initial check. */
do {
if ((err = casio_seven_receive(handle, 0)))
return (err);
} while (response.casio_seven_packet_type != casio_seven_type_chk
|| !response.casio_seven_packet_initial);
/* Ack and start! */
err = casio_seven_send_ack(handle, 1);
if (err) return (err);
}
/* Main loop. */
while (1) {
/* Check command packet. */
if (response.casio_seven_packet_type != casio_seven_type_cmd) {
if (response.casio_seven_packet_type == casio_seven_type_end)
return (casio_seven_send_ack(handle, 0));
if (response.casio_seven_packet_type == casio_seven_type_swp)
break;
err = casio_seven_send_err(handle, casio_seven_err_other);
if (err) return (err);
}
/* Check if the callback exists. */
if (!callbacks[response.casio_seven_packet_code]) {
err = casio_seven_send_err(handle, casio_seven_err_other);
if (err) return (err);
continue;
}
/* Call the callback. */
err = (*callbacks[response.casio_seven_packet_code])(cookie, handle);
if (err) {
if (err != casio_error_unknown) return (err);
err = casio_seven_send_err(handle, casio_seven_err_other);
if (err) return (err);
continue;
}
}
/* Ack and disconnect. */
return (0);
}

View File

@ -20,59 +20,73 @@
# define LOCAL_LINK_USAGE_H 1
# include "../link.h"
/* ************************************************************************* */
/* Quick-checking macros. */
/* ************************************************************************* */
/* ---
* Quick-checking macros.
* --- */
/* Check that the handle exists. */
# define chk_handle_exists(CASIO__H) \
if (!(CASIO__H)) return (casio_error_init);
/* Check that the handle exists and is usable. */
# define chk_handle(CASIO__H) \
chk_handle_exists(CASIO__H) \
if ((CASIO__H)->casio_link_flags & casio_linkflag_ended) \
return (casio_error_init);
/* Check that the protocol we're using is for Protocol Seven. */
# define chk_seven(CASIO__H) /* TODO */
/* Check that the handle is active. */
# define chk_active(CASIO__H) \
if (~(CASIO__H)->casio_link_flags & casio_linkflag_active) \
return (casio_error_active);
/* Check that the handle is passive. */
# define chk_passive(CASIO__H) \
if ((CASIO__H)->casio_link_flags & casio_linkflag_active) \
return (casio_error_active);
/* Check that the file name is correct. */
# define chk_filename(CASIO__FN) /* TODO */
/* Check that the filename is there and ok. */
# define chk_required_filename(CASIO__FN) \
if (!(CASIO__FN)) return (casio_error_invalid);
/* Check that the directory name is ok. */
# define chk_dirname(CASIO__DN) /* TODO */
/* Check that the MCS request head is ok. */
# define chk_head(CASIO__HD) \
casio_correct_mcsfile_head(CASIO__HD); \
if (!(CASIO__HD)->casio_mcshead_name[0]) return (casio_error_invalid); \
if (!(CASIO__HD)->casio_mcshead_group[0]) return (casio_error_invalid);
/* Check if the buffer is readable. */
# define chk_bufread(CASIO__BUF) /* TODO */
/* Check if the buffer is writable. */
# define chk_bufwrite(CASIO__BUF) /* TODO */
/* Check that the memory buffer is valid and not empty. */
# define chk_mem(CASIO__MEM) \
if (!(CASIO__MEM)) return (casio_error_nostream);
/* Check if the file is not empty. */
# define chk_filesize(CASIO__SZ) \
if (!(casio_off_t)(CASIO__SZ)) return (casio_error_empty);

View File

@ -61,22 +61,3 @@ casio_loglevel_t CASIO_EXPORT casio_loglevel_fromstring(const char *string)
return (casio_loglevel_none);
}
#endif
/**
* casio_listlog:
* List log levels.
*
* @arg callback the callback.
* @arg cookie the callback cookie.
*/
void CASIO_EXPORT casio_listlog(casio_log_list_t *callback, void *cookie)
{
(*callback)(cookie, "none");
#if !defined(LIBCASIO_DISABLED_LOG)
(*callback)(cookie, "info");
(*callback)(cookie, "warn");
(*callback)(cookie, "error");
(*callback)(cookie, "fatal");
#endif
}

90
lib/log/iter.c Normal file
View File

@ -0,0 +1,90 @@
/* ****************************************************************************
* log/iter.c -- iterate on log levels.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "log.h"
CASIO_LOCAL const char *log_levels[] = {
"none",
#if !defined(LIBCASIO_DISABLED_LOG)
"info",
"warn",
"error",
"fatal",
#endif
NULL
};
/* `next_log()`: next log level. */
CASIO_LOCAL int CASIO_EXPORT next_log(const char **cookie, const char **level)
{
if (!*cookie)
return (casio_error_iter);
*level = *cookie++;
return (0);
}
/* `end_log_iter()`: end the iteration log. */
CASIO_LOCAL int CASIO_EXPORT end_log_iter(const char **cookie)
{
free(cookie);
return (0);
}
/* Functions. */
CASIO_LOCAL casio_iter_funcs_t log_funcs = {
(casio_next_t *)next_log,
NULL,
(casio_end_t *)end_log_iter
};
/* `casio_iter_log()`: make a loglevels iterator. */
int CASIO_EXPORT casio_iter_log(casio_iter_t **iterp)
{
const char **ptr;
ptr = malloc(sizeof(*ptr));
if (!ptr)
return (casio_error_alloc);
*ptr = "none";
return (casio_iter(iterp, ptr, &log_funcs));
}
/* ---
* List logs, per compatibility.
* --- */
/* `casio_listlog()`: list log levels. */
void CASIO_EXPORT casio_listlog(casio_log_list_t *callback, void *cookie)
{
casio_iter_t *iter;
const char *level;
if (casio_iter_log(&iter))
return ;
while (casio_next_log(iter, &level))
(*callback)(cookie, level);
casio_end(iter);
}

View File

@ -62,10 +62,13 @@ typedef int casio_loglevel_t;
# if defined(LIBCASIO_DISABLED_FILE) && !defined(LIBCASIO_DISABLED_LOG)
# define LIBCASIO_DISABLED_LOG
# endif
/* ************************************************************************* */
/* Log utilities */
/* ************************************************************************* */
/* ---
* Log utilities.
* --- */
/* Main functions */
# if defined(LIBCASIO_DISABLED_LOG)
# define msg(CASIO__ARGS)
# define mem(CASIO__ARGS)
@ -129,6 +132,7 @@ CASIO_EXTERN void CASIO_EXPORT casio_log_prefix
OF((casio_loglevel_t casio__loglevel, const char *casio__func));
# if defined(__STDC__) && __STDC__
CASIO_EXTERN void CASIO_EXPORT casio_log_msg
(casio_loglevel_t casio__loglevel, const char *casio__func,
const char *casio__format, ...);
@ -136,8 +140,10 @@ CASIO_EXTERN void CASIO_EXPORT casio_log_mem
(casio_loglevel_t casio__loglevel, const char *casio__func,
const void *casio__m, size_t casio__n);
# else
CASIO_EXTERN void CASIO_EXPORT casio_log_msg();
CASIO_EXTERN void CASIO_EXPORT casio_log_mem();
# endif
# endif

View File

@ -32,10 +32,11 @@ void CASIO_EXPORT casio_log_prefix(casio_loglevel_t loglevel, const char *func)
{
if (func && !strncmp(func, "casio_", 6))
func = &func[6];
if (func) fprintf(stderr, "[libcasio %5s] %s: ",
casio_loglevel_tostring(loglevel), func);
else fprintf(stderr, "[libcasio %5s] ",
casio_loglevel_tostring(loglevel));
if (func)
fprintf(stderr, "\r[libcasio %5s] %s: ",
casio_loglevel_tostring(loglevel), func);
else
fprintf(stderr, "\r[libcasio %5s] ", casio_loglevel_tostring(loglevel));
}
/**

View File

@ -18,9 +18,30 @@
* ************************************************************************* */
#include "mcs.h"
/**
* casio_iter_mcsfiles:
* Get an iterator to iterate on MCS file entries (heads).
*
* @arg mcs the main memory interface.
* @arg iter the iterator to make.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_iter_mcsfiles(casio_mcs_t *mcs, casio_iter_t **iterp)
{
casio_mcs_iter_t *func;
if (!mcs)
return (casio_error_invalid);
func = mcs->casio_mcs_funcs.casio_mcsfuncs_iter;
if (!func)
return (casio_error_op);
return ((*func)(mcs->casio_mcs_cookie, iterp));
}
/**
* casio_list_mcsfiles:
* List an MCS file.
* List MCS files on a main memory interface (deprecated function).
*
* @arg mcs the main memory interface.
* @arg list the listing callback.
@ -31,10 +52,24 @@
int CASIO_EXPORT casio_list_mcsfiles(casio_mcs_t *mcs,
casio_mcslist_t *list, void *cookie)
{
casio_mcs_list_t *func;
casio_iter_t *iter;
casio_mcshead_t *head;
int err;
if (!mcs) return (casio_error_invalid);
func = mcs->casio_mcs_funcs.casio_mcsfuncs_list;
if (!func) return (casio_error_op);
return ((*func)(mcs->casio_mcs_cookie, list, cookie));
if ((err = casio_iter_mcsfiles(mcs, &iter)))
return (err);
while (1) {
if ((err = casio_next_mcshead(iter, &head))) {
casio_end(iter);
if (err == casio_error_stopped)
break;
return (err);
}
(*list)(cookie, head);
}
return (0);
}

View File

@ -75,8 +75,7 @@ int CASIO_EXPORT casio_localmcs_find(localmcs_t *cookie,
memcpy(newindex, cookie->localmcs_files,
cookie->localmcs_size * sizeof(casio_mcsfile_t*));
/* Initialize the new entries.
* (XXX: this shouldn't be necessary, should we remove it?) */
/* Initialize the new entries. */
memset(&newindex[cookie->localmcs_size], 0,
(newsize - cookie->localmcs_size) * sizeof(casio_mcsfile_t*));

88
lib/mcs/local/iter.c Normal file
View File

@ -0,0 +1,88 @@
/* ****************************************************************************
* mcs/local/iter.c -- iterate on heads in a local main memory.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "local.h"
typedef struct localmcs_iter_s {
localmcs_t *mcs;
int id;
} localmcs_iter_t;
/**
* next_mcsfile:
* Get the next element.
*
* @arg cookie the iteration cookie.
* @arg nextp the next element to get.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int CASIO_EXPORT next_mcsfile(localmcs_iter_t *cookie,
void **nextp)
{
casio_mcsfile_t *file;
if (cookie->id >= cookie->mcs->localmcs_count)
return (casio_error_iter);
file = cookie->mcs->localmcs_files[cookie->id++];
*nextp = &file->casio_mcsfile_head;
return (0);
}
/**
* end_iter:
* End the iterator.
*
* @arg cookie the iteration cookie.
* @return the error code (0 if ok).
*/
CASIO_LOCAL void CASIO_EXPORT end_iter(localmcs_iter_t *cookie)
{
free(cookie);
}
/**
* casio_localmcs_iter:
* Iterate on files in a local main memory.
*
* @arg cookie the local main memory cookie.
* @arg iterp the iterator to make.
* @return the error code (0 if ok).
*/
CASIO_LOCAL casio_iter_funcs_t const casio_localmcs_iter_funcs = {
(casio_next_t *)next_mcsfile,
NULL,
(casio_end_t *)end_iter
};
int CASIO_EXPORT casio_localmcs_iter(localmcs_t *cookie, casio_iter_t **iterp)
{
localmcs_iter_t *icookie;
icookie = casio_alloc(1, sizeof(*icookie));
if (!cookie)
return (casio_error_alloc);
icookie->mcs = cookie;
icookie->id = 0;
return (casio_iter(iterp, icookie, &casio_localmcs_iter_funcs));
}

View File

@ -46,8 +46,7 @@ CASIO_EXTERN int CASIO_EXPORT casio_localmcs_put
CASIO_EXTERN int CASIO_EXPORT casio_localmcs_delete
OF((localmcs_t *casio__cookie, casio_mcshead_t *casio__mcshead));
CASIO_EXTERN int CASIO_EXPORT casio_localmcs_list
OF((localmcs_t *casio__cookie, casio_mcslist_t *casio__mcslist,
void *casio__mcslist_cookie));
CASIO_EXTERN int CASIO_EXPORT casio_localmcs_iter
OF((localmcs_t *cookie, casio_iter_t **iterp));
#endif /* LOCAL_MCS_LOCAL_H */

View File

@ -18,9 +18,10 @@
* ************************************************************************* */
#include "local.h"
/* ************************************************************************* */
/* Close callback, not Close Kombat */
/* ************************************************************************* */
/* ---
* Close callback, not Close Kombat
* --- */
/**
* casio_localmcs_close:
* Close a local main memory.
@ -45,15 +46,18 @@ CASIO_LOCAL int casio_localmcs_close(localmcs_t *cookie)
}
/* Callbacks */
CASIO_LOCAL casio_mcsfuncs_t funcs = {
(casio_mcs_get_t*)&casio_localmcs_get,
(casio_mcs_put_t*)&casio_localmcs_put,
(casio_mcs_delete_t*)&casio_localmcs_delete,
(casio_mcs_list_t*)&casio_localmcs_list,
(casio_mcs_iter_t*)&casio_localmcs_iter,
(casio_mcs_close_t*)&casio_localmcs_close};
/* ************************************************************************* */
/* Main opening function */
/* ************************************************************************* */
/* ---
* Main opening function.
* --- */
/**
* casio_open_local_mcs:
* Open a local main memory.

View File

@ -24,23 +24,27 @@
#define FUNC(NAME) &casio_decode_caspart_##NAME
#define HFUNC(NAME) &casio_decode_cashpart_##NAME
/* ************************************************************************* */
/* Type correspondance list */
/* ************************************************************************* */
/* Part parsing function type */
/* ---
* Type correspondance list.
* --- */
/* Part parsing function type. */
typedef int decode_func ();
typedef int cas_decode_function OF((casio_mcsfile_t*, casio_stream_t*));
typedef int cas_heads_decode_function OF((casio_mcshead_t *head,
casio_mcshead_t *heads, casio_stream_t *buffer));
/* Correspondance type */
/* Correspondance type. */
struct cas_corresp {
unsigned int type;
cas_decode_function *decode;
cas_heads_decode_function *hdecode;
};
/* All correspondances */
/* All correspondances. */
#define TTERM {0, NULL, NULL}
CASIO_LOCAL struct cas_corresp cas_types[] = {
{casio_mcstype_var, FUNC(var), NULL},
@ -72,9 +76,11 @@ CASIO_LOCAL decode_func *lookup_cas_decode(casio_mcstype_t type, int heads)
/* return the function */
return (heads ? (decode_func*)c->hdecode : (decode_func*)c->decode);
}
/* ************************************************************************* */
/* Head decoding functions */
/* ************************************************************************* */
/* ---
* Head decoding functions.
* --- */
/**
* decode_cas50:
* Decode a CASIOLINK Protocol header.
@ -216,9 +222,11 @@ int CASIO_EXPORT casio_decode_casfile_head(casio_mcshead_t *head,
/* no error! */
return (0);
}
/* ************************************************************************* */
/* Part decoding functions */
/* ************************************************************************* */
/* ---
* Part decoding functions.
* --- */
/**
* casio_decode_casfile_part:
* Decode a CASIOLINK Protocol content part.

View File

@ -18,9 +18,10 @@
* ************************************************************************* */
#include "../decode.h"
/* ************************************************************************* */
/* Internal function */
/* ************************************************************************* */
/* ---
* Internal function.
* --- */
/**
* decode_cell:
* Read a cell.
@ -64,9 +65,11 @@ CASIO_LOCAL int decode_cell(casio_stream_t *buffer, casio_mcscell_t *cell,
/* no prob'! */
return (0);
}
/* ************************************************************************* */
/* Cell-reading CAS part decoding functions */
/* ************************************************************************* */
/* ---
* Cell-reading CAS part decoding functions.
* --- */
/**
* casio_decode_caspart_matrix:
* Decode a CAS matrix part.

View File

@ -20,10 +20,12 @@
# define LOCAL_MCSFILE_DECODE_H 1
# include "../mcsfile.h"
/* ************************************************************************* */
/* MCS files specific decoding functions */
/* ************************************************************************* */
/* ---
* MCS files specific decoding functions.
* --- */
/* Schemes. */
# define CASIO_MCSFUNC(CASIO__NAME) \
extern int casio_decode_mcs_##CASIO__NAME \
OF((casio_mcsfile_t **casio__handle, casio_stream_t *casio__buffer, \
@ -37,10 +39,13 @@ CASIO_MCSFUNC(program)
CASIO_MCSFUNC(setup)
CASIO_MCSFUNC(spreadsheet)
CASIO_MCSFUNC(string)
/* ************************************************************************* */
/* CAS-specific decoding functions */
/* ************************************************************************* */
/* ---
* CAS-specific decoding functions.
* --- */
/* Schemes. */
# define CASIO_CASFUNC(CASIO__NAME) \
extern int casio_decode_caspart_##CASIO__NAME \
OF((casio_mcsfile_t *casio__handle, casio_stream_t *casio__buffer));

View File

@ -19,20 +19,24 @@
#include "decode.h"
#define FUNC(NAME) casio_decode_mcs_##NAME
/* ************************************************************************* */
/* Type correspondance list */
/* ************************************************************************* */
/* MCS file parsing function type */
/* ---
* Type correspondance list.
* --- */
/* MCS file parsing function type. */
typedef int mcs_decode_func_t OF((casio_mcsfile_t**, casio_stream_t*,
casio_mcshead_t*));
/* Correspondance type */
struct mcs_corresp {
casio_mcstype_t type;
mcs_decode_func_t *decode;
};
/* All correspondances */
#define TTERM {0, NULL}
CASIO_LOCAL struct mcs_corresp mcs_types[] = {
{casio_mcstype_program, FUNC(program)},
@ -67,9 +71,11 @@ CASIO_LOCAL mcs_decode_func_t *lookup_mcsfile_decode(casio_mcstype_t type)
/* return the function */
return (c->decode);
}
/* ************************************************************************* */
/* Head decoding function */
/* ************************************************************************* */
/* ---
* Head decoding function.
* --- */
/**
* casio_decode_mcsfile_head:
* Decode MCS file head.
@ -114,9 +120,11 @@ int CASIO_EXPORT casio_decode_mcsfile_head(casio_mcshead_t *head,
/* everything went well! */
return (0);
}
/* ************************************************************************* */
/* File decoding functions */
/* ************************************************************************* */
/* ---
* File decoding functions.
* --- */
/**
* casio_decode_mcsfile:
* Decode MCS file content.

View File

@ -40,23 +40,25 @@ int CASIO_EXPORT casio_decode_mcs_spreadsheet(casio_mcsfile_t **h,
unsigned long rows = 0, cols = 0;
unsigned long x, y;
/* read header */
/* Read the header. */
GDREAD(hd)
if (hd.casio_mcs_spreadsheet_header_has_subheader != 0x01)
return (0);
/* read subheader */
/* Read the subheader. */
GDREAD(shd)
colcount = hd.casio_mcs_spreadsheet_header_column_count;
colcount = be32toh(colcount << 8);
shd.casio_mcs_spreadsheet_subheader_defs_size =
be32toh(shd.casio_mcs_spreadsheet_subheader_defs_size);
/* prepare */
/* Prepare. */
cells = casio_alloc(1000 * colcount, sizeof(casio_mcscell_t));
memset(cells, 0, sizeof(casio_mcscell_t) * 1000 * colcount);
/* log some info */
msg((ll_info, "%lu columns to read!", colcount));
if (colcount) {
@ -107,10 +109,13 @@ int CASIO_EXPORT casio_decode_mcs_spreadsheet(casio_mcsfile_t **h,
}
}
/* we have max rows and columns, increment to have sizes */
rows++, cols++;
/* We have max rows and columns, increment to have sizes. */
rows++;
cols++;
/* Create final tab. */
/* create final tab */
head->casio_mcshead_width = 0; head->casio_mcshead_height = 0;
if (cells_count) {
head->casio_mcshead_width = cols;
@ -120,13 +125,13 @@ int CASIO_EXPORT casio_decode_mcs_spreadsheet(casio_mcsfile_t **h,
if (err) return (err);
handle = *h;
/* main copying loop */
/* Main copying loop. */
tab = handle->casio_mcsfile_cells;
for (y = 0; y < head->casio_mcshead_height; y++)
for (x = 0; x < head->casio_mcshead_width; x++)
tab[y][x] = cells[x * 1000 + y];
/* end */
err = 0;
fail:
casio_free(cells);

View File

@ -34,18 +34,25 @@ int CASIO_EXPORT casio_decode_mcs_string(casio_mcsfile_t **h,
int err; unsigned char *str = NULL;
unsigned long length = head->casio_mcshead_size;
/* print content */
/* Print the content. */
msg((ll_info, "String MCS file is not managed yet. Content:"));
str = casio_alloc(length, 1);
if (!str) { err = casio_error_alloc; goto fail; }
if (!str) {
err = casio_error_alloc;
goto fail;
}
GREAD(str, length)
mem((ll_info, str, length));
/* make the file */
/* XXX: store it some day? */
/* Make the file. */
err = casio_make_mcsfile(h, head);
if (err) goto fail;
/* end */
err = 0;
fail:
casio_free(str);

View File

@ -17,6 +17,7 @@
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../decode.h"
#define MAX_VAR_NUMBER 30 /* if more than 30 one day, augment this… */
/**
* casio_decode_mcs_var:
@ -31,32 +32,45 @@
int CASIO_EXPORT casio_decode_mcs_var(casio_mcsfile_t **handle,
casio_stream_t *buffer, casio_mcshead_t *head)
{
int err;
int err, num;
unsigned long length = head->casio_mcshead_size;
unsigned char *buf = alloca(length);
unsigned char buf[MAX_VAR_NUMBER * sizeof(casio_mcsbcd_t)];
const casio_mcsbcd_t *b;
casio_mcsfile_t *h;
int i;
/* read the data */
/* Get the number of elements. */
num = length / (2 * sizeof(casio_mcsbcd_t));
if (num > MAX_VAR_NUMBER)
num = MAX_VAR_NUMBER;
length = num * 2 * sizeof(casio_mcsbcd_t);
/* Read the data. */
READ(buf, length)
/* complete header */
head->casio_mcshead_count = length / (2 * sizeof(casio_mcsbcd_t));
/* Complete header */
head->casio_mcshead_count = num;
err = casio_make_mcsfile(handle, head);
if (err) return (err);
if (err)
return (err);
h = *handle;
/* check the count */
ifmsg(head->casio_mcshead_count, (ll_info, "Is a single variable!"));
/* Check the count. */
ifmsg(head->casio_mcshead_count == 1, (ll_info, "Is a single variable!"));
/* Copy and decode the variables. */
/* copy */
for (b = (void*)buf, i = 0; i < head->casio_mcshead_count; i++) {
casio_bcd_frommcs(&h->casio_mcsfile_vars[i].casio_mcscell_real, b++);
casio_bcd_frommcs(&h->casio_mcsfile_vars[i].casio_mcscell_imgn, b++);
h->casio_mcsfile_vars[i].casio_mcscell_flags = casio_mcscellflag_used;
}
/* no problem, woop woop */
/* No problem, woop woop. */
return (0);
}

View File

@ -20,10 +20,12 @@
# define LOCAL_MCSFILE_H 1
# include "../internals.h"
/* ************************************************************************* */
/* Macros for interacting with the buffer */
/* ************************************************************************* */
/* ---
* Macros for interacting with the buffer.
* --- */
/* Read from a stream. */
# define READ(CASIO__TO, CASIO__SZ) /* normal read */ { \
int READ_err = casio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
if (READ_err) return (READ_err); }
@ -34,12 +36,14 @@
goto fail;
/* Read using size of the object. */
# define DREAD(CASIO__TO) \
READ(&CASIO__TO, sizeof(CASIO__TO))
# define GDREAD(CASIO__TO) \
GREAD(&CASIO__TO, sizeof(CASIO__TO))
/* Skip. */
# define SKIP(CASIO__SZ) { \
int SKIP_err = casio_skip(buffer, CASIO__SZ); \
if (SKIP_err) return (SKIP_err); }
@ -48,14 +52,17 @@
if (err) goto fail; }
/* Write. */
# define WRITE(CASIO__BUF, CASIO__SZ) { \
int WRITE_err = casio_write(buffer, (CASIO__BUF), (CASIO__SZ)); \
if (WRITE_err) return (WRITE_err); }
# define DWRITE(CASIO__OBJECT) \
WRITE(&(CASIO__OBJECT), sizeof(CASIO__OBJECT))
/* ************************************************************************* */
/* Picture utilities */
/* ************************************************************************* */
/* ---
* Picture utilities.
* --- */
# define alloc_pixels(W, H) \
casio_alloc(sizeof(casio_pixel_t*) \
* (H) + sizeof(casio_pixel_t) * (W) * (H), 1)

View File

@ -18,10 +18,12 @@
* ************************************************************************* */
#include "ref.h"
/* ************************************************************************* */
/* Local types */
/* ************************************************************************* */
/* ---
* Local types.
* --- */
/* Correspondance type */
struct app_corresp {
/* identification */
const char *name;
@ -30,6 +32,7 @@ struct app_corresp {
};
/* Extension */
struct ext_corresp {
/* identification */
int value;
@ -40,9 +43,11 @@ struct ext_corresp {
/* app correspondances */
const struct app_corresp *apps;
};
/* ************************************************************************* */
/* Correspondances */
/* ************************************************************************* */
/* ---
* Correspondances.
* --- */
/* App correspondances. Remarks:
* - Correspondances with a NULL data type means the data type isn't to be
* read. */
@ -82,9 +87,11 @@ CASIO_LOCAL const struct ext_corresp apps[] = {
/* (sentinel) */
{0, 0, NULL}
};
/* ************************************************************************* */
/* Main functions */
/* ************************************************************************* */
/* ---
* Main functions.
* --- */
/**
* casio_check_cas_app:
* Get the CAS application from raw CASDYN identification data.

View File

@ -18,16 +18,19 @@
* ************************************************************************* */
#include "ref.h"
/* ************************************************************************* */
/* Local types */
/* ************************************************************************* */
/* Flags */
/* ---
* Local types.
* --- */
/* Flags. */
#define mult 0x0001
#define noarg 0x0000
#define arg 0x0002
#define arg_is_num 0x0000
/* Correspondance type */
struct type_corresp {
/* identification */
const char *datatype;
@ -37,9 +40,11 @@ struct type_corresp {
casio_mcstype_t type;
casio_pictureformat_t picformat;
};
/* ************************************************************************* */
/* Correspondances */
/* ************************************************************************* */
/* ---
* Correspondances.
* --- */
/* All correspondances found by Tom Wheeley, Tom Lynn (creators of CaS),
* and Göran Weinholt (creator of Cafix). */
@ -47,6 +52,7 @@ struct type_corresp {
#define CAPT(S, PT) {S, noarg, casio_mcstype_capture, PT}
#define UNIMPLEMENTED(S) {S, noarg, 0, 0}
#define TTERM {NULL, noarg, 0, 0}
CASIO_LOCAL const struct type_corresp cas_groups[] = {
/* basic things */
BASIC("LT", casio_mcstype_list),
@ -101,9 +107,10 @@ CASIO_LOCAL const struct type_corresp cas_groups[] = {
TTERM
};
/* ************************************************************************* */
/* Main functions */
/* ************************************************************************* */
/* ---
* Main functions.
* --- */
/**
* get_number:
* Get number from string.

View File

@ -18,10 +18,12 @@
* ************************************************************************* */
#include "ref.h"
/* ************************************************************************* */
/* Local types */
/* ************************************************************************* */
/* Type flags */
/* ---
* Local types.
* --- */
/* Type flags. */
#define noarg 0x0000
#define arg 0x0001
#define arg_is_num 0x0002
@ -29,7 +31,8 @@
#define weight_by_gid 0x0004
#define groupable 0x0008
/* Correspondance type */
/* Correspondance type. */
struct type_corresp {
/* identification */
unsigned int rawtype;
@ -44,7 +47,8 @@ struct type_corresp {
casio_mcstype_t type;
};
/* Group correspondance type */
/* Group correspondance type. */
struct group_corresp {
/* identification */
const char *name; /* NULL = don't check */
@ -53,9 +57,11 @@ struct group_corresp {
/* types */
const struct type_corresp *types;
};
/* ************************************************************************* */
/* Correspondances */
/* ************************************************************************* */
/* ---
* Correspondances.
* --- */
/* All correspondances. Some remarks:
* - I think files with "PROGRAM" group are split because it was originally
* planned they would be in groups like 'PROGRAM <name>', like for captures
@ -263,9 +269,11 @@ CASIO_LOCAL const struct group_corresp mcs_groups[] = {
/* terminating entry */
{NULL, 0, NULL}
};
/* ************************************************************************* */
/* Main functions */
/* ************************************************************************* */
/* ---
* Main functions.
* --- */
/**
* get_number:
* Get number from string.
@ -451,9 +459,11 @@ found:
/* no error */
return (0);
}
/* ************************************************************************* */
/* Compare function */
/* ************************************************************************* */
/* ---
* Compare functions.
* --- */
/**
* find_offset_in_group:
* Find offset in a group.
@ -498,18 +508,25 @@ CASIO_LOCAL int find_offset_in_group(const struct group_corresp *g,
int CASIO_EXPORT casio_compare_mcsfiles(casio_mcshead_t *first,
casio_mcshead_t *second)
{
/* find the group correspondance */
int offset1 = -1, offset2 = -1;
const struct group_corresp *g; for (g = mcs_groups; g->types; g++) {
const struct group_corresp *g;
for (g = mcs_groups; g->types; g++) {
/* get offsets */
if (offset1 >= -1) offset1 = find_offset_in_group(g, first);
if (offset2 >= -1) offset2 = find_offset_in_group(g, second);
if (offset1 >= -1)
offset1 = find_offset_in_group(g, first);
if (offset2 >= -1)
offset2 = find_offset_in_group(g, second);
/* check if the first one corresponds */
if (offset1 < 0 && offset2 < 0) continue;
if (offset1 == offset2) break;
if (offset1 < offset2) return (-1);
if (offset1 > offset2) return (1);
if (offset1 < 0 && offset2 < 0)
continue;
if (offset1 == offset2)
break;
if (offset1 < offset2)
return (-1);
if (offset1 > offset2)
return (1);
}
/* so they're equal, huh... */

View File

@ -30,28 +30,27 @@ CASIO_LOCAL casio_uint32_t dual2b_colors[] = {
/* prizm colors. */
CASIO_LOCAL const casio_uint32_t prizm_colors[16] = {
/* [casio_color_black] = */ casio_pixel(0, 0, 0),
/* [casio_color_blue] = */ casio_pixel(0, 0, 255),
/* [casio_color_green] = */ casio_pixel(0, 255, 0),
/* [casio_color_cyan] = */ casio_pixel(0, 255, 255),
/* [casio_color_red] = */ 0xff0000,
/* [casio_color_magenta] = */ 0xff00ff,
/* [casio_color_yellow] = */ 0xffff00,
/* [casio_color_white] = */ 0xffffff,
/* [casio_color_black] = */ casio_pixel( 0, 0, 0),
/* [casio_color_blue] = */ casio_pixel( 0, 0, 255),
/* [casio_color_green] = */ casio_pixel( 0, 255, 0),
/* [casio_color_cyan] = */ casio_pixel( 0, 255, 255),
/* [casio_color_red] = */ casio_pixel(255, 0, 0),
/* [casio_color_magenta] = */ casio_pixel(255, 0, 255),
/* [casio_color_yellow] = */ casio_pixel(255, 255, 0),
/* [casio_color_white] = */ casio_pixel(255, 255, 255)
/* RESERVED */
};
/* Colors used in Casemul pictures. */
CASIO_LOCAL const casio_uint32_t casemul_colors[256] = {
0xFFFFFF, /* white */
0xFF8000, /* orange */
0x00FF00, /* green */
0x0000FF /* blue */
/* other colours are black, i.e. 0x00000000 */
/* white */ casio_pixel(255, 255, 255),
/* orange */ casio_pixel(255, 128, 0),
/* green */ casio_pixel( 0, 255, 0),
/* blue */ casio_pixel( 0, 0, 255)
/* other colours are black, i.e. casio_pixel(0, 0, 0) == 0x000000 */
};
/* ************************************************************************* */
/* Picture decoding */
/* ************************************************************************* */
/**
* casio_decode_picture:
* Decode a picture.
@ -221,11 +220,14 @@ int CASIO_EXPORT casio_decode_picture(casio_pixel_t **pixels,
for (y = height - 1; y != (unsigned int)-1; y--) {
msk = 0x80;
for (x = bx; x < bx + 8; x++) {
/* get pixel */
if (*o & msk) pixels[y][x] = 0xFF8C00; /* orange */
else if (*g & msk) pixels[y][x] = 0x00FF00; /* green */
else if (*b & msk) pixels[y][x] = 0x0000FF; /* blue */
else pixels[y][x] = 0xFFFFFF; /* white */
if (*o & msk) /* Orange! */
casio_set_pixel(pixels[y][x], 255, 140, 0);
else if (*g & msk) /* Green! */
casio_set_pixel(pixels[y][x], 0, 255, 0);
else if (*b & msk) /* Blue! */
casio_set_pixel(pixels[y][x], 0, 0, 255);
else /* White! */
casio_set_pixel(pixels[y][x], 255, 255, 255);
/* go to next */
msk >>= 1;

View File

@ -18,9 +18,10 @@
* ************************************************************************* */
#include "stream.h"
/* ************************************************************************* */
/* Manage attributes */
/* ************************************************************************* */
/* ---
* Manage attributes.
* --- */
/**
* casio_make_attrs:
* Make attributes from a string.
@ -77,9 +78,11 @@ int CASIO_EXPORT casio_make_attrs(casio_streamattrs_t *attrs, const char *raw)
: CASIO_PARENB | CASIO_PARODD;
return (0);
}
/* ************************************************************************* */
/* Set the attributes of a stream */
/* ************************************************************************* */
/* ---
* Set the attributes of a stream.
* --- */
/**
* casio_init_attrs:
* Initialize the attributes.

View File

@ -28,15 +28,17 @@
# define __fwritable(F) (1)
# endif
/* cookie structure */
/* Cookie structure. */
typedef struct {
int _rstream_cl, _wstream_cl;
FILE *_rstream, *_wstream;
} file_cookie_t;
/* ************************************************************************* */
/* Callbacks */
/* ************************************************************************* */
/* ---
* Callbacks.
* --- */
/**
* casio_file_read:
* Read from a FILE.
@ -214,9 +216,11 @@ CASIO_LOCAL int casio_file_close(file_cookie_t *cookie)
casio_free(cookie);
return (0);
}
/* ************************************************************************* */
/* Opening functions */
/* ************************************************************************* */
/* ---
* Opening functions.
* --- */
CASIO_LOCAL const casio_streamfuncs_t casio_file_callbacks =
casio_stream_callbacks_for_virtual(casio_file_close, casio_file_read,
casio_file_write, casio_file_seek);

View File

@ -29,7 +29,7 @@
* [0x55, 0x53, 0x42, 0x43] (USBC)
* - Tag (4B): answerer will echo this field to us in the associated CSW.
* Used by BrandonW: [0x41, 0x42, 0x43, 0x44] (ABCD)
* - Data Transfer Length (4B):
* - Data Transfer Length (4B): what is to come as data.
* - Flags (1B):
* - Bit 7 (128): direction, 0 for host to device, 1 for device to host.
* - Other bits: reserved or obsolete, set to zero (0).
@ -44,12 +44,28 @@
* [0x55, 0x53, 0x42, 0x53] (USBS)
* - Tag (4B): echo the field from the CBW.
* Used by BrandonW: [0x41, 0x42, 0x43, 0x44] (ABCD)
* - Data Residue (4B):
* - Data Residue (4B):
* - Status (1B): success or failure.
* - 0: command passed (good).
* - 1: command failed (bad).
* - 2: phase error. */
struct cbw {
casio_uint8_t signature[4];
casio_uint8_t tag[4];
casio_uint8_t data_length[4];
casio_uint8_t flags;
casio_uint8_t lun;
casio_uint8_t cmd_len;
};
struct csw {
casio_uint8_t signature[4];
casio_uint8_t tag[4];
casio_uint8_t residue[4];
casio_uint8_t status;
};
/**
* casio_libusb_scsi_request:
* Make an SCSI request on a libusb connected device, using CBW.
@ -58,10 +74,164 @@
int CASIO_EXPORT casio_libusb_scsi_request(cookie_libusb_t *cookie,
casio_scsi_t *request)
{
unsigned char cmd[32];
struct cbw *cbw;
struct csw csw;
int sent, recv, libusberr;
/* Prepare and send the request. */
/* TODO */
return (casio_error_op);
memset(cmd, 0, 32);
cbw = (void *)&cmd[0];
cbw->signature[0] = 'U';
cbw->signature[1] = 'S';
cbw->signature[2] = 'B';
cbw->signature[3] = 'C';
cbw->tag[0] = 'A';
cbw->tag[1] = 'B';
cbw->tag[2] = 'C';
cbw->tag[3] = 'D';
cbw->data_length[0] = request->casio_scsi_data_len & 0xFF;
cbw->data_length[1] = (request->casio_scsi_data_len >> 8) & 0xFF;
cbw->data_length[2] = 0;
cbw->data_length[3] = 0;
cbw->flags = request->casio_scsi_data_len && request->casio_scsi_direction
== CASIO_SCSI_DIREC_FROM_DEV ? 128 : 0;
cbw->lun = 0;
cbw->cmd_len = request->casio_scsi_cmd_len;
memcpy(&cmd[15], request->casio_scsi_cmd, request->casio_scsi_cmd_len);
libusberr = libusb_bulk_transfer(cookie->_handle, ENDPOINT_OUT,
cmd, 31, &sent, cookie->tmwrite);
switch (libusberr) {
case 0: break;
case LIBUSB_ERROR_PIPE:
case LIBUSB_ERROR_NO_DEVICE:
case LIBUSB_ERROR_IO:
msg((ll_error, "The calculator is not here anymore :("));
return (casio_error_nocalc);
default:
msg((ll_fatal, "libusb error was %d: %s", libusberr,
libusb_strerror(libusberr)));
return (casio_error_unknown);
}
/* Send or receive the data. */
if (!request->casio_scsi_data_len) {
/* Nothing, no data is sent. */
} else if (request->casio_scsi_direction == CASIO_SCSI_DIREC_FROM_DEV) {
int left = (int)request->casio_scsi_data_len;
unsigned char *data = (unsigned char *)request->casio_scsi_data;
/* Data is received. */
while (left) {
libusberr = libusb_bulk_transfer(cookie->_handle, ENDPOINT_IN,
data, (int)left, &recv, cookie->tmread);
switch (libusberr) {
case 0:
break;
case LIBUSB_ERROR_PIPE:
case LIBUSB_ERROR_NO_DEVICE:
case LIBUSB_ERROR_IO:
msg((ll_error, "The calculator is not here anymore :("));
return (casio_error_nocalc);
case LIBUSB_ERROR_TIMEOUT:
return (casio_error_timeout);
default:
msg((ll_fatal, "libusb error was %d: %s", libusberr,
libusb_strerror(libusberr)));
return (casio_error_unknown);
}
data += recv;
left -= recv;
}
} else {
int left = (int)request->casio_scsi_data_len;
unsigned char *data = (unsigned char *)request->casio_scsi_data;
msg((ll_info, "Sending %d bytes.", left));
/* Data is sent. */
while (left) {
libusberr = libusb_bulk_transfer(cookie->_handle, ENDPOINT_OUT,
data, (int)left, &sent, cookie->tmwrite);
switch (libusberr) {
case 0:
break;
case LIBUSB_ERROR_PIPE:
case LIBUSB_ERROR_NO_DEVICE:
case LIBUSB_ERROR_IO:
msg((ll_error, "The calculator is not here anymore :("));
return (casio_error_nocalc);
case LIBUSB_ERROR_TIMEOUT:
return (casio_error_timeout);
default:
msg((ll_fatal, "libusb error was %d: %s", libusberr,
libusb_strerror(libusberr)));
return (casio_error_unknown);
}
data += sent;
left -= sent;
}
}
/* Get the status. */
{
int left = 13;
unsigned char *data = (void *)&csw;
do {
libusberr = libusb_bulk_transfer(cookie->_handle, ENDPOINT_IN,
data, (int)left, &recv, cookie->tmread);
switch (libusberr) {
case 0:
break;
case LIBUSB_ERROR_PIPE:
case LIBUSB_ERROR_NO_DEVICE:
case LIBUSB_ERROR_IO:
msg((ll_error, "The calculator is not here anymore :("));
return (casio_error_nocalc);
case LIBUSB_ERROR_TIMEOUT:
return (casio_error_timeout);
default:
msg((ll_fatal, "libusb error was %d: %s", libusberr,
libusb_strerror(libusberr)));
return (casio_error_unknown);
}
data += recv;
left -= recv;
} while (left);
}
/* Check the status block itself. */
if (memcmp(csw.signature, "USBS", 4)
|| memcmp(csw.tag, cbw->tag, 4))
return (casio_error_unknown);
/* TODO: check if csw->status is good and find the error to return
* if not */
/* We're good! */
return (0);
}
#endif

View File

@ -26,9 +26,10 @@ typedef struct {
size_t _left;
} limited_cookie_t;
/* ************************************************************************* */
/* Callbacks */
/* ************************************************************************* */
/* ---
* Callbacks.
* --- */
/**
* casio_limited_read:
* Read from a limited stream.
@ -87,9 +88,10 @@ CASIO_LOCAL const casio_streamfuncs_t casio_limited_callbacks =
casio_stream_callbacks_for_virtual(casio_limited_close,
casio_limited_read, NULL, NULL);
/* ************************************************************************* */
/* Main functions */
/* ************************************************************************* */
/* ---
* Main functions.
* --- */
/**
* casio_open_limited:
* Open a limited stream.

View File

@ -24,9 +24,10 @@ typedef struct {
casio_off_t _size, _offset;
} memory_cookie_t;
/* ************************************************************************* */
/* Callbacks */
/* ************************************************************************* */
/* ---
* Callbacks.
* --- */
/**
* casio_memory_read:
* Read from a memory area.
@ -145,9 +146,10 @@ CASIO_LOCAL const casio_streamfuncs_t casio_memory_callbacks =
casio_stream_callbacks_for_virtual(casio_memory_close,
casio_memory_read, casio_memory_write, casio_memory_seek);
/* ************************************************************************* */
/* Opening functions */
/* ************************************************************************* */
/* ---
* Opening functions.
* --- */
/**
* casio_open_memory:
* Open a FILE stream.

View File

@ -17,8 +17,6 @@
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "stream.h"
#define checknot(CASIO__COND, CASIO__ERR) \
{ if (CASIO__COND) {err = CASIO__ERR; goto fail;}}
/**
* casio_open_stream:
@ -40,36 +38,50 @@ int CASIO_EXPORT casio_open_stream(casio_stream_t **pstream,
int err; casio_stream_t *stream = NULL;
casio_streamfuncs_t *c;
/* allocate the stream */
*pstream = casio_alloc(1, sizeof(casio_stream_t));
stream = *pstream;
checknot(stream == NULL, casio_error_alloc)
/* Allocate the stream. */
/* initialize the stream callbacks */
*pstream = casio_alloc(1, sizeof(casio_stream_t));
if (!(stream = *pstream)) {
err = casio_error_alloc;
goto fail;
}
/* Initialize the stream callbacks. */
stream->casio_stream_mode = 0;
c = &stream->casio_stream_callbacks;
memset(c, 0, sizeof(casio_streamfuncs_t));
c->casio_streamfuncs_close = callbacks->casio_streamfuncs_close;
c->casio_streamfuncs_settm = callbacks->casio_streamfuncs_settm;
if (mode & CASIO_OPENMODE_READ)
if ((mode & CASIO_OPENMODE_READ) && callbacks->casio_streamfuncs_read) {
stream->casio_stream_mode |= CASIO_OPENMODE_READ;
c->casio_streamfuncs_read = callbacks->casio_streamfuncs_read;
if (mode & CASIO_OPENMODE_WRITE)
}
if ((mode & CASIO_OPENMODE_WRITE) && callbacks->casio_streamfuncs_write) {
stream->casio_stream_mode |= CASIO_OPENMODE_WRITE;
c->casio_streamfuncs_write = callbacks->casio_streamfuncs_write;
}
if (mode & (CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE))
c->casio_streamfuncs_seek = callbacks->casio_streamfuncs_seek;
if (mode & CASIO_OPENMODE_SERIAL)
c->casio_streamfuncs_setattrs = callbacks->casio_streamfuncs_setattrs;
if (mode & CASIO_OPENMODE_SCSI)
c->casio_streamfuncs_scsi = callbacks->casio_streamfuncs_scsi;
/* initialize the stream properties */
stream->casio_stream_mode = mode;
if ((mode & CASIO_OPENMODE_SERIAL)
&& callbacks->casio_streamfuncs_setattrs) {
stream->casio_stream_mode |= CASIO_OPENMODE_SERIAL;
c->casio_streamfuncs_setattrs = callbacks->casio_streamfuncs_setattrs;
}
if ((mode & CASIO_OPENMODE_SCSI) && callbacks->casio_streamfuncs_scsi) {
stream->casio_stream_mode |= CASIO_OPENMODE_SCSI;
c->casio_streamfuncs_scsi = callbacks->casio_streamfuncs_scsi;
}
/* Initialize the stream properties. */
stream->casio_stream_cookie = cookie;
stream->casio_stream_offset = ioff;
stream->casio_stream_lasterr = 0;
casio_init_attrs(stream);
casio_init_timeouts(stream);
/* no error! */
err = 0;
fail:
if (err) {

View File

@ -19,9 +19,10 @@
#include "../internals.h"
#include <ctype.h>
/* ************************************************************************* */
/* ASCII-HEX utilities */
/* ************************************************************************* */
/* ---
* ASCII-HEX (base16) utilities.
* --- */
/**
* casio_putascii:
* Put a number in ASCII-hex, in a n-dimensionned field.
@ -61,9 +62,11 @@ unsigned long CASIO_EXPORT casio_getascii(const unsigned char *p, int n)
}
return (i);
}
/* ************************************************************************* */
/* BIN-HEX to BIN-DEC (BCD) utilities */
/* ************************************************************************* */
/* ---
* BIN-HEX to BIN-DEC (BCD) utilities.
* --- */
/**
* casio_getdec:
* Get decimal of hex.

130
lib/utils/iter.c Normal file
View File

@ -0,0 +1,130 @@
/* ****************************************************************************
* utils/iter.c -- iterator internals.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include <libcasio.h>
/* Internal structure of an iterator. */
struct casio_iter_s {
int stopped, has_last;
void *last;
void *cookie;
casio_next_t *next;
casio_nextfree_t *nextfree;
casio_end_t *end;
};
/* `default_next()`: default next function. */
CASIO_LOCAL int default_next(void *cookie, void **ptr)
{
(void)cookie;
(void)ptr;
return (casio_error_iter);
}
/* `default_nextfree()`: default nextfree function. */
CASIO_LOCAL void default_nextfree(void *cookie, void *ptr)
{
/* Do not free. */
(void)cookie;
(void)ptr;
}
/* `default_end()`: default iterator end function. */
CASIO_LOCAL void default_end(void *cookie)
{
(void)cookie;
}
/* `casio_iter()`: create an iterator. */
int CASIO_EXPORT casio_iter(casio_iter_t **iterp, void *cookie,
casio_iter_funcs_t const *funcs)
{
casio_iter_t *iter;
/* Allocate the iterator. */
iter = casio_alloc(1, sizeof(*iter));
if (!iter) {
if (funcs->casio_iterfunc_end)
(*funcs->casio_iterfunc_end)(cookie);
return (casio_error_alloc);
}
/* Prepare the iterator. */
iter->stopped = 0;
iter->has_last = 0;
iter->cookie = cookie;
iter->next = funcs->casio_iterfunc_next;
if (!iter->next)
iter->next = &default_next;
iter->nextfree = funcs->casio_iterfunc_nextfree;
if (!iter->nextfree)
iter->nextfree = &default_nextfree;
iter->end = funcs->casio_iterfunc_end;
if (!iter->end)
iter->end = &default_end;
*iterp = iter;
return (0);
}
/* `casio_next()`: get the next element from an iterator. */
int CASIO_EXPORT casio_next(casio_iter_t *iter, void **ptrp)
{
int err;
if (iter->stopped)
return (casio_error_iter);
if (iter->has_last) {
(*iter->nextfree)(iter->cookie, iter->last);
iter->has_last = 0;
}
err = (*iter->next)(iter->cookie, ptrp);
if (err == casio_error_iter) {
iter->stopped = 1;
return (err);
} else if (err)
return (err);
iter->has_last = 1;
iter->last = *ptrp;
return (0);
}
/* `casio_end()`: end and free the iterator. */
void CASIO_EXPORT casio_end(casio_iter_t *iter)
{
if (iter->has_last) {
(*iter->nextfree)(iter->cookie, iter->last);
iter->has_last = 0;
}
(*iter->end)(iter->cookie);
casio_free(iter);
}

View File

@ -18,9 +18,10 @@
* ************************************************************************* */
#include "../internals.h"
/* ************************************************************************* */
/* Microsoft Windows environment */
/* ************************************************************************* */
/* ---
* Microsoft Windows environment.
* --- */
#if defined(__WINDOWS__)
# define default_callback &casio_winsleep
# include <windows.h>
@ -29,9 +30,11 @@ CASIO_LOCAL void casio_winsleep(unsigned long ms)
{
Sleep(ms);
}
/* ************************************************************************* */
/* UNIX environments */
/* ************************************************************************* */
/* ---
* UNIX-like environments.
* --- */
#elif defined(__unix__) || defined(__unix)
# define default_callback &casio_unixsleep
# include <unistd.h>
@ -42,15 +45,18 @@ CASIO_LOCAL void casio_unixsleep(unsigned long ms)
struct timespec requested_timestamp;
requested_timestamp.tv_sec = ms / 1000;
requested_timestamp.tv_nsec = ms * 1000;
requested_timestamp.tv_nsec = (ms % 1000) * 1000000;
nanosleep(&requested_timestamp, NULL);
}
/* ************************************************************************* */
/* Default and main function */
/* ************************************************************************* */
/* ---
* Default and main function.
* --- */
#else
# define default_callback NULL
#endif
CASIO_LOCAL casio_sleep_t *casio_sleep_callback = default_callback;
/**

View File

@ -19,9 +19,10 @@
#include "../main.h"
#include <string.h>
/* ************************************************************************* */
/* Main function */
/* ************************************************************************* */
/* ---
* Main function.
* --- */
/**
* osdisp:
* Nice little loading bar.
@ -73,9 +74,11 @@ void osdisp(void *vcookie, unsigned int id, unsigned int total)
fputs("\x1B""8", stdout);
fflush(stdout);
}
/* ************************************************************************* */
/* Initialization, miscallaneous actions */
/* ************************************************************************* */
/* ---
* Initialization, miscallaneous actions.
* --- */
/**
* osdisp_init:
* Initialize a display cookie.

View File

@ -21,10 +21,12 @@
#include <ctype.h>
#include <getopt.h>
/* ************************************************************************* */
/* Help and version messages */
/* ************************************************************************* */
/* ---
* Help and version messages.
* --- */
/* Version message */
static const char version_message[] =
BIN " - from " NAME " v" VERSION " (licensed under GPLv2)\n"
"Maintained by " MAINTAINER ".\n"
@ -34,6 +36,7 @@ BIN " - from " NAME " v" VERSION " (licensed under GPLv2)\n"
"FITNESS FOR A PARTICULAR PURPOSE.";
/* Help message */
static const char help_main0[] =
"Usage: " BIN " [--help|-h] [--version|-v]\n"
"\n"
@ -52,9 +55,11 @@ static const char help_main1[] =
" By default, the zoom will be " DEFAULT_ZOOM ".\n"
"\n"
"Report bugs to " MAINTAINER ".\n";
/* ************************************************************************* */
/* Main function */
/* ************************************************************************* */
/* ---
* Main function.
* --- */
/**
* put_loglevel:
* Put a loglevel (for listing).

View File

@ -54,13 +54,17 @@ cat <<_EOF
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
*
* This file is GENERATED from the options you pass to the configure script.
* This file is *GENERATED* from the options you pass to the configure script.
* It shall not be modified by the user after its generation, as this could
* lead to unresolved symbols! If you want another configuration, then you
* will have to build the library again, with your different configuration.
* ************************************************************************* */
#ifndef LIBCASIO_CONFIG_H
# define LIBCASIO_CONFIG_H
/* Version and maintainer related macros.
* Generated from the variables in \`Makefile.vars\`. */
# define LIBCASIO_VERSION "${version}"
# define LIBCASIO_VERNUM ${version_num}
# define LIBCASIO_MAJOR ${version_major}
@ -74,7 +78,8 @@ _EOF
# File part
if [ "$no_file" ]; then cat <<_EOF
/* FILE interface is disabled */
/* Standard FILE interface is disabled. */
# define LIBCASIO_DISABLED_FILE 1
_EOF
@ -82,7 +87,8 @@ fi
# libusb part
if [ "$no_libusb" ]; then cat <<_EOF
/* libusb is disabled */
/* libusb support is disabled. */
# define LIBCASIO_DISABLED_LIBUSB 1
_EOF
@ -90,7 +96,8 @@ fi
# disable logging
if [ "$no_log" ]; then cat <<_EOF
/* logging is disabled */
/* Logging is disabled. */
# define LIBCASIO_DISABLED_LOG 1
_EOF