Fixed installation.
This commit is contained in:
parent
aa937aca7b
commit
d520bb9685
130
Makefile
130
Makefile
|
@ -7,7 +7,7 @@ include Makefile.vars Makefile.msg
|
|||
|
||||
# Build everything.
|
||||
|
||||
all: all-lib all-utils
|
||||
all: all-lib all-utils $(if $(INSTALL_MANPAGES),all-man)
|
||||
|
||||
# Mostly clean everything (remove everything but the end results).
|
||||
|
||||
|
@ -33,12 +33,15 @@ mrproper: clean
|
|||
$(call qcmd,$(RM) $(INCDIR)/lib$(NAME)/config.h)
|
||||
|
||||
# Remake everything (clean and build).
|
||||
|
||||
re: clean all
|
||||
|
||||
# Install everything.
|
||||
install: install-lib
|
||||
|
||||
# Make a distribution tarball
|
||||
install: install-lib install-utils $(if $(INSTALL_MANPAGES),install-man)
|
||||
|
||||
# Make a distribution tarball.
|
||||
|
||||
dist: mrproper
|
||||
$(call bcmd,mkdir,lib$(NAME)-$(VERSION),\
|
||||
$(MD) .dist)
|
||||
|
@ -145,61 +148,60 @@ $(eval $(call make-obj-rule,$(src))))
|
|||
$(if $(FOR_WINDOWS),,y)))
|
||||
IWINDLL := $(if $(FOR_WINDOWS),$(if $(STATIC),,y))
|
||||
|
||||
install-lib: all-lib $(if $(INSTALL_DEVEL),install-cfgtool)
|
||||
$(call imsg,Installing the library.)
|
||||
$(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)")
|
||||
$(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" $(if $(STATIC),\
|
||||
$(if $(FOR_WINDOWS),lib$(L_NAME).lib,lib$(L_NAME).a),\
|
||||
$(if $(FOR_WINDOWS),lib$(NAME).dll.a,$(SONAME))))
|
||||
|
||||
$(if $(IWINDLL),$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)"))
|
||||
$(if $(IWINDLL),$(call qcmd,$(INST) -m 755 -t "$(IBINDIR)" \
|
||||
lib$(NAME).dll))
|
||||
|
||||
$(if $(LINK_TO_MAJOR),\
|
||||
$(call imsg,Linking lib$(NAME).so to lib$(NAME).so.$(MAJOR).))
|
||||
$(if $(LINK_TO_MAJOR),\
|
||||
$(call qcmd,$(LN) lib$(NAME).so.$(MAJOR) "$(ILIBDIR)/lib$(NAME).so"))
|
||||
|
||||
$(if $(INSTALL_DEVEL),\
|
||||
$(call imsg,Installing development files.))
|
||||
$(if $(INSTALL_DEVEL),\
|
||||
$(call qcmd,$(INST) -m 755 -d $(patsubst %,\
|
||||
"$(IINCDIR)/lib$(NAME)-$(VERSION)/%", $(sort $(dir $(INCp))))))
|
||||
$(if $(INSTALL_DEVEL),$(foreach i,$(INCp),\
|
||||
$(call qcmd,$(INST) -m 644 $(INCDIR)/$(i) \
|
||||
"$(IINCDIR)/lib$(NAME)-$(VERSION)/$(i)"$(\n))))
|
||||
|
||||
.PHONY: all-lib install-lib
|
||||
|
||||
# ---
|
||||
# Configuration tools related.
|
||||
# ---
|
||||
|
||||
install-cfgtool: $(CHECKCFG)
|
||||
install-lib-cfgtool:
|
||||
$(call imsg,Installing the configuration tool.)
|
||||
$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")
|
||||
$(call qcmd,tools/write-config \
|
||||
--name=$(NAME) --version=$(VERSION) --target="$(TARGET)" \
|
||||
--name=$(LIB) --version=$(VERSION) --target="$(TARGET)" \
|
||||
--maintainer="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \
|
||||
>"$(IBINDIR)/lib$(NAME)-config" \
|
||||
&& chmod 755 "$(IBINDIR)/lib$(NAME)-config")
|
||||
>"$(IBINDIR)/lib$(LIB)-config" \
|
||||
&& chmod 755 "$(IBINDIR)/lib$(LIB)-config")
|
||||
$(if $(TARGET),$(call qcmd,$(INST) -m 755 -d "$(HBINDIR)"))
|
||||
$(if $(TARGET),$(call qcmd,$(LN) -r \
|
||||
"$(IBINDIR)/lib$(NAME)-config" \
|
||||
"$(HBINDIR)/$(TARGET)lib$(NAME)-config"))
|
||||
|
||||
"$(IBINDIR)/lib$(LIB)-config" \
|
||||
"$(HBINDIR)/$(TARGET)lib$(LIB)-config"))
|
||||
|
||||
install-lib-pkgconfig:
|
||||
$(call imsg,Installing the pkg-config configuration.)
|
||||
$(call qcmd,$(INST) -m 755 -d "$(IPKGDIR)")
|
||||
$(call qcmd,tools/write-pkg-config \
|
||||
--name=$(NAME) --version=$(VERSION) \
|
||||
--name=$(LIB) --version=$(VERSION) \
|
||||
--deps="$(DEPS)" --deps.private="$(DEPS_PRIV)" \
|
||||
--description="$(DESCRIPTION)" \
|
||||
--incdir="$(OIINCDIR)/lib$(NAME)-$(VERSION)" --libdir="$(OILIBDIR)" \
|
||||
>"$(IPKGDIR)/lib$(NAME).pc" \
|
||||
&& chmod 644 "$(IPKGDIR)/lib$(NAME).pc")
|
||||
--incdir="$(OIINCDIR)/lib$(LIB)-$(VERSION)" --libdir="$(OILIBDIR)" \
|
||||
>"$(IPKGDIR)/lib$(LIB).pc" \
|
||||
&& chmod 644 "$(IPKGDIR)/lib$(LIB).pc")
|
||||
|
||||
.PHONY: install-cfgtool
|
||||
install-lib-shared:
|
||||
$(call imsg,Installing the library.)
|
||||
$(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)")
|
||||
$(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" $(if $(STATIC),\
|
||||
./build/$(if $(FOR_WINDOWS),lib$(LIB).lib,lib$(LIB).a),\
|
||||
./build/$(if $(FOR_WINDOWS),lib$(LIB).dll.a,$(L_SONAME))))
|
||||
|
||||
install-lib-dll:
|
||||
$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")
|
||||
$(call qcmd,$(INST) -m 755 -t "$(IBINDIR)" lib$(LIB).dll)
|
||||
|
||||
install-lib-link:
|
||||
$(call imsg,Linking lib$(LIB).so to lib$(LIB).so.$(MAJOR).)
|
||||
$(call qcmd,$(LN) lib$(LIB).so.$(MAJOR) "$(ILIBDIR)/lib$(LIB).so")
|
||||
|
||||
install-lib-headers:
|
||||
$(call imsg,Installing development files.)
|
||||
$(foreach d,$(sort $(dir $(patsubst %,lib$(LIB)-$(VERSION)/%, \
|
||||
$(L_INCp)))),$(call qcmd,$(INST) -m 755 -d "$(IINCDIR)/$(d)"$(\n)))
|
||||
$(foreach i,$(L_INCp),$(call qcmd,$(INST) -m 644 $(L_INCDIR)/$(i) \
|
||||
"$(IINCDIR)/lib$(LIB)-$(VERSION)/$(i)"$(\n)))
|
||||
|
||||
install-lib: $(CHECKCFG) all-lib install-lib-shared \
|
||||
$(if $(LINK_TO_MAJOR),install-lib-link) $(if $(IWINDLL),install-lib-dll) \
|
||||
$(if $(INSTALL_DEVEL),install-lib-cfgtool install-lib-pkgconfig \
|
||||
install-lib-headers)
|
||||
|
||||
.PHONY: all-lib install-lib install-lib-shared install-lib-link
|
||||
.PHONY: install-lib-dll install-lib-cfgtool install-lib-pkgconfig
|
||||
.PHONY: install-lib-headers
|
||||
|
||||
# ---
|
||||
# Utilities related.
|
||||
|
@ -207,7 +209,7 @@ $(eval $(call make-obj-rule,$(src))))
|
|||
|
||||
# Make the utilities.
|
||||
|
||||
all-utils: $(CHECKCFG) $(DEFAULT_UTILS:%=all-%)
|
||||
all-utils: $(CHECKCFG) $(DEFAULT_UTILS:%=all-%.exe)
|
||||
|
||||
# Make a utility.
|
||||
|
||||
|
@ -216,7 +218,7 @@ define make-util-rules
|
|||
$(if $(filter libcasio,$(U_DEPS_$1)),$(L_AS_DEP)) | ./build/
|
||||
$(call bcmd,ld,$$@,$(LD) -o $$@ $(U_OBJ_$1) $(U_LDFLAGS_$1))
|
||||
|
||||
all-$1: ./build/$1$(if $(FOR_WINDOWS),.exe)
|
||||
all-$1 all-$1.exe: ./build/$1$(if $(FOR_WINDOWS),.exe)
|
||||
endef
|
||||
$(foreach util,$(UTILS),\
|
||||
$(eval $(call make-util-rules,$(util))))
|
||||
|
@ -234,17 +236,24 @@ $(foreach util,$(UTILS),\
|
|||
$(foreach src,$(U_SRC_$(util)),\
|
||||
$(eval $(call make-util-obj-rules,$(util),$(src)))))
|
||||
|
||||
# Install utils.
|
||||
|
||||
install-utils: $(DEFAULT_UTILS:%=install-%)
|
||||
|
||||
# Install a utility.
|
||||
|
||||
define make-util-install-rule
|
||||
install-$1 install-$1.exe: $(CHECKCFG)
|
||||
install-$1 install-$1.exe: $(CHECKCFG) all-$1.exe
|
||||
$(call imsg,Installing $1$(if $(FOR_WINDOWS),.exe).)
|
||||
$(call qcmd,$(INSTALL) -m 755 -d "$(IBINDIR)")
|
||||
$(call qcmd,$(INSTALL) -m 755 -t "$(IBINDIR)" $1$(if $(FOR_WINDOWS),.exe))
|
||||
$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")
|
||||
$(call qcmd,$(INST) -m 755 -t "$(IBINDIR)" \
|
||||
./build/$1$(if $(FOR_WINDOWS),.exe))
|
||||
endef
|
||||
$(foreach util,$(UTILS),\
|
||||
$(eval $(call make-util-install-rule,$(util))))
|
||||
|
||||
.PHONY: all-utils $(foreach util,$(UTILS),all-$(util) install-$(util) \
|
||||
install-$(util).exe)
|
||||
.PHONY: all-utils install-utils $(foreach util,$(UTILS),\
|
||||
all-$(util) all-$(util).exe install-$(util) install-$(util).exe)
|
||||
|
||||
# ---
|
||||
# Manpages related.
|
||||
|
@ -253,7 +262,7 @@ endef
|
|||
# Produce the manpages.
|
||||
|
||||
all-man: $(foreach sec,$(M_SECTIONS),\
|
||||
$(M_PAGES_$(sec):%=$(M_MANDIR)/man$(sec)/%.$(sec).gz))
|
||||
$(M_PAGES_$(sec):%=$(M_MANDIR)/man$(sec)/%.$(sec)))
|
||||
|
||||
# Produce one page.
|
||||
|
||||
|
@ -268,6 +277,19 @@ $(foreach sec,$(M_SECTIONS),\
|
|||
$(foreach pg,$(M_PAGES_$(sec)),\
|
||||
$(eval $(call make-manpage-rules,$(sec),$(pg)))))
|
||||
|
||||
# Install the manpages.
|
||||
|
||||
install-man: $(CHECKCFG) all-man
|
||||
$(call imsg,Installing manpages.)
|
||||
$(foreach s,$(M_SECTIONS),$(call qcmd,$(INST) -m 755 \
|
||||
-d "$(IMANDIR)/man$(s)"$(\n)))
|
||||
$(foreach s,$(M_SECTIONS),$(foreach p,$(M_PAGES_$(s)),\
|
||||
$(call qcmd,$(INST) -m 644 $(M_MANDIR)/man$(s)/$(p).$(s) \
|
||||
"$(IMANDIR)/man$(s)/$(p).$(s)" && \
|
||||
$(GZIP) "$(IMANDIR)/man$(s)/$(p).$(s)"$(\n))))
|
||||
|
||||
.PHONY: all-man install-man
|
||||
|
||||
# ---
|
||||
# Documentation-related targets.
|
||||
# ---
|
||||
|
|
|
@ -90,7 +90,7 @@ endif
|
|||
RM := rm -f
|
||||
A2X := a2x
|
||||
INST := install
|
||||
GZIP := gzip -k -f
|
||||
GZIP := gzip -f
|
||||
|
||||
# ---
|
||||
# Dependencies definitions.
|
||||
|
@ -156,7 +156,7 @@ endif
|
|||
L_OBJDIRS := $(sort $(dir $(L_OBJ)))
|
||||
|
||||
L_INCp := $(patsubst $(L_INCDIR)/%,%,$(wildcard $(L_INCDIR)/*.h \
|
||||
$(L_INCDIR)/**/*.h))
|
||||
$(L_INCDIR)/**/*.h $(L_INCDIR)/**/**/*.h $(L_INCDIR)/**/**/**/*.h))
|
||||
L_INC := $(L_INCp:%=$(L_INCDIR)/%) \
|
||||
$(wildcard $(L_SRCDIR)/*.h $(L_SRCDIR)/**/*.h)
|
||||
|
||||
|
@ -217,10 +217,11 @@ define get-util-source
|
|||
$(U_SRCDIR)/$1/**/*.h))
|
||||
|
||||
U_CFLAGS_$1 := $(CFLAGS) $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_CFLAGS)) \
|
||||
-D BIN="$1$(if $(FOR_WINDOWS),.exe)" \
|
||||
-D MAINTAINER="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \
|
||||
-D DEFAULT_STORAGE="$(DEFAULT_STORAGE)" \
|
||||
-D DEFAULT_ZOOM="$(DEFAULT_ZOOM)"
|
||||
-D BIN="\"$1$(if $(FOR_WINDOWS),.exe)\"" \
|
||||
-D NAME="\"p7utils\"" -D VERSION="\"$(VERSION)\"" \
|
||||
-D MAINTAINER="\"$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>\"" \
|
||||
-D DEFAULT_STORAGE="\"$(DEFAULT_STORAGE)\"" \
|
||||
-D DEFAULT_ZOOM="\"$(DEFAULT_ZOOM)\""
|
||||
U_LIBS_$1 := $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_LIBS))
|
||||
|
||||
U_LDFLAGS_$1 := $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_LIBS))
|
||||
|
|
|
@ -51,10 +51,12 @@ hbindir='${hprefix}/bin'
|
|||
libdir='${prefix}/lib'"$platform"
|
||||
includedir='${prefix}/include'"$platform"
|
||||
pkgdir='${libdir}/pkgconfig'
|
||||
mandir='${prefix}/share/man'
|
||||
|
||||
# Installation options.
|
||||
|
||||
install_devel=yes
|
||||
install_manpages=yes
|
||||
|
||||
# Tweaks.
|
||||
|
||||
|
@ -93,7 +95,8 @@ Build options:
|
|||
--default-storage=STOR the default storage device for p7 [$default_storage]
|
||||
|
||||
Installation options:
|
||||
--no-devel should not install developement files
|
||||
--no-devel do not install developement files
|
||||
--no-manpages do not install manpages
|
||||
|
||||
Installation directories:
|
||||
--root=ROOT installation root [$root]
|
||||
|
@ -106,6 +109,7 @@ Fine tuning of the installation directories:
|
|||
--pkgdir=PKGDIR pkg-config configurations directory [$pkgdir]
|
||||
--libdir=LIBDIR library files of the linker [$libdir]
|
||||
--includedir=INCDIR include files for the compiler [$includedir]
|
||||
--mandir=MANDIR man root [$mandir]
|
||||
|
||||
Other tweaks:
|
||||
CFLAGS=CFLAGS some more compilation flags
|
||||
|
@ -191,6 +195,7 @@ got '$level'"
|
|||
# then set
|
||||
default_storage="$storage" ;;
|
||||
--no-devel) install_devel= ;;
|
||||
--no-manpages) install_manpages= ;;
|
||||
--root=*) root="${arg#*=}" ;;
|
||||
--hprefix=*) hprefix="${arg#*=}" ;;
|
||||
--prefix=*) prefix="${arg#*=}"; prefix_set=y ;;
|
||||
|
@ -199,6 +204,7 @@ got '$level'"
|
|||
--pkgdir=*) pkgdir="${arg#*=}" ;;
|
||||
--libdir=*) libdir="${arg#*=}" ;;
|
||||
--includedir=*) includedir="${arg#*=}" ;;
|
||||
--mandir=*) mandir="${arg#*=}" ;;
|
||||
CFLAGS=*) cflags="${arg#*=}" ;;
|
||||
LDFLAGS=*) ldflags="${arg#*=}" ;;
|
||||
*) echo "$arg: didn't read" ;;
|
||||
|
@ -223,7 +229,7 @@ fi;; esac
|
|||
|
||||
# Evaluate variables.
|
||||
|
||||
vars="prefix bindir libdir pkgdir includedir hprefix hbindir"
|
||||
vars="prefix bindir libdir pkgdir includedir hprefix hbindir mandir"
|
||||
for var in $vars; do
|
||||
eval $var'='$(eval 'echo $'$var)
|
||||
done
|
||||
|
@ -313,9 +319,11 @@ cat <<EOF
|
|||
IPKGDIR = $pkgdir
|
||||
ILIBDIR = $libdir
|
||||
IINCDIR = $includedir
|
||||
IMANDIR = $mandir
|
||||
|
||||
# Installation options
|
||||
INSTALL_DEVEL = $install_devel
|
||||
INSTALL_MANPAGES = $install_manpages
|
||||
|
||||
# Other tweaks
|
||||
CMOREFLAGS := $cflags
|
||||
|
|
|
@ -16,7 +16,7 @@ by CASIO for its graphical calculators, produced from the 90s to to this day.
|
|||
It is part of a project named the P7 project, and is a personal project of
|
||||
Thomas Touhey, also known as “Cakeisalie5”, from Planète Casio.
|
||||
|
||||
See more at <https://p7.planet-casio.com/>.
|
||||
Read more at <https://p7.planet-casio.com/>.
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
|
|
|
@ -0,0 +1,262 @@
|
|||
/* ****************************************************************************
|
||||
* cafix/args.c -- cafix command-line argument parsing.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************* */
|
||||
#include "main.h"
|
||||
#include <getopt.h>
|
||||
|
||||
/* Version message. */
|
||||
|
||||
static const char version_message[] =
|
||||
BIN " - from " NAME " v" VERSION
|
||||
" (licensed under GPLv2)\n"
|
||||
"Maintained by " MAINTAINER ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
"FITNESS FOR A PARTICULAR PURPOSE.";
|
||||
|
||||
static void put_version(void)
|
||||
{
|
||||
fputs(version_message, stderr);
|
||||
}
|
||||
|
||||
/* Help message. */
|
||||
|
||||
static const char help_begin[] =
|
||||
"Usage: " BIN " [OPTIONS]... [SOURCE | DESTPATH]\n"
|
||||
"\n"
|
||||
"Remake of the 90s utility known as the Calculator File-Xferer, made by\n"
|
||||
"Tom Lynn, and which used to work with the CFX-9850 GB PLUS and the \n"
|
||||
"CFX-9990GT, \"maybe other as well\".\n"
|
||||
"\n"
|
||||
"Available options:\n"
|
||||
" -h, --help Display this help page and exit.\n"
|
||||
" -v, --version Display the version message and exit.\n";
|
||||
|
||||
static const char help_loglevel_init[] =
|
||||
" --log <level> The library log level (default: %s).\n"
|
||||
" One of: %s";
|
||||
|
||||
static const char help_end[] =
|
||||
" -r, --receive Try to receive data.\n"
|
||||
" -s, --send Send a file.\n"
|
||||
" -rn, --rename Prompts for filename (must be combined with -s or -r).\n"
|
||||
" -c, --control Remote control mode.\n"
|
||||
"\n"
|
||||
"Report bugs to " MAINTAINER ".\n";
|
||||
|
||||
/**
|
||||
* put_loglevel:
|
||||
* Put a loglevel (for listing).
|
||||
*
|
||||
* @arg initialized if the list was initialized.
|
||||
* @arg level the level string.
|
||||
*/
|
||||
|
||||
static void put_loglevel(char **first, const char *level)
|
||||
{
|
||||
if (!*first) {
|
||||
*first = malloc(strlen(level) + 2);
|
||||
if (!*first)
|
||||
return ;
|
||||
strcpy(*first + 1, level);
|
||||
**first = 'F';
|
||||
return ;
|
||||
}
|
||||
|
||||
if (**first == 'F') {
|
||||
fprintf(stderr, help_loglevel_init, casio_getlog(), *first + 1);
|
||||
**first = 'N';
|
||||
}
|
||||
|
||||
fprintf(stderr, ", %s", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* put_help:
|
||||
* Put the help message on standard output.
|
||||
*/
|
||||
|
||||
static void put_help(void)
|
||||
{
|
||||
char *first;
|
||||
|
||||
/* Put the beginning. */
|
||||
|
||||
fputs(help_begin, stderr);
|
||||
|
||||
/* Put the loglevels. */
|
||||
|
||||
first = NULL;
|
||||
casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first);
|
||||
if (first && *first == 'N')
|
||||
fputc('\n', stderr);
|
||||
free(first);
|
||||
|
||||
/* Put the end. */
|
||||
|
||||
fputs(help_end, stderr);
|
||||
}
|
||||
|
||||
/* ---
|
||||
* Main argument parsing function.
|
||||
* --- */
|
||||
|
||||
/**
|
||||
* parse_args:
|
||||
* Args parsing main function.
|
||||
*
|
||||
* Was my very first experiment with getopt.
|
||||
* Then I took an arrow in the knee.
|
||||
*
|
||||
* @arg ac the arguments count
|
||||
* @arg av the arguments values
|
||||
* @arg args the parsed args pointer
|
||||
* @return if it was successfully parsed
|
||||
*/
|
||||
|
||||
int parse_args(int ac, char **av, args_t *args)
|
||||
{
|
||||
int c, help = 0, pm;
|
||||
const char *s_log = NULL;
|
||||
char **pv;
|
||||
char short_opts[] = "hvrsc";
|
||||
struct option long_opts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"log", required_argument, NULL, 'L'},
|
||||
{"receive", no_argument, NULL, 'r'},
|
||||
{"send", no_argument, NULL, 's'},
|
||||
{"rn", no_argument, NULL, 'R'},
|
||||
{"rename", no_argument, NULL, 'R'},
|
||||
{"control", no_argument, NULL, 'c'},
|
||||
|
||||
/* sentinel */
|
||||
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* Initialize the arguments. */
|
||||
|
||||
args->mode = 0; /* unknown menu. */
|
||||
args->should_rename = 0;
|
||||
args->filename = NULL;
|
||||
|
||||
/* Gather the options. */
|
||||
|
||||
opterr = 0;
|
||||
while ((c = getopt_long_only(ac, av, short_opts, long_opts, NULL)) != -1)
|
||||
switch (c) {
|
||||
/* Help and version message. */
|
||||
|
||||
case 'h':
|
||||
help = 1;
|
||||
break;
|
||||
case 'v':
|
||||
put_version();
|
||||
return (1);
|
||||
|
||||
/* Log level. */
|
||||
|
||||
case 'L':
|
||||
s_log = optarg;
|
||||
break;
|
||||
|
||||
/* Command. */
|
||||
|
||||
case 'r':
|
||||
if (args->mode != MODE_CONTROL)
|
||||
args->mode = MODE_RECEIVE;
|
||||
break;
|
||||
case 's':
|
||||
if (args->mode != MODE_CONTROL)
|
||||
args->mode = MODE_SEND;
|
||||
break;
|
||||
case 'c':
|
||||
args->mode = MODE_CONTROL;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
args->should_rename = 1;
|
||||
break;
|
||||
|
||||
/* In case of error. */
|
||||
|
||||
case '?':
|
||||
if (optopt == 'L')
|
||||
fprintf(stderr, "--log: expected an argument\n");
|
||||
else
|
||||
break;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Get the parameters. */
|
||||
|
||||
pm = ac - optind;
|
||||
pv = &av[optind];
|
||||
|
||||
if (help) {
|
||||
put_help();
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (args->mode == 0) {
|
||||
fprintf(stderr, "error: no command specified\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
switch (args->mode) {
|
||||
case MODE_SEND:
|
||||
if (pm != 1) {
|
||||
fprintf(stderr, "error: path of the file to send required\n");
|
||||
return (1);
|
||||
}
|
||||
args->filename = *pv;
|
||||
break;
|
||||
|
||||
case MODE_RECEIVE:
|
||||
if (pm != 1) {
|
||||
fprintf(stderr, "error: path of the file to receive required\n");
|
||||
return (1);
|
||||
}
|
||||
args->filename = *pv;
|
||||
break;
|
||||
|
||||
case MODE_CONTROL:
|
||||
if (pm) {
|
||||
fprintf(stderr, "error: too many parameters\n");
|
||||
return (1);
|
||||
}
|
||||
if (args->should_rename) {
|
||||
fprintf(stderr, "error: cannot rename and control\n");
|
||||
return (1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
args->filename = *pv;
|
||||
|
||||
/* Set the log level. */
|
||||
|
||||
if (s_log)
|
||||
casio_setlog(s_log);
|
||||
|
||||
/* Everything went well. */
|
||||
|
||||
return (0);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* p7servtest/client.c -- p7servtest virtual client.
|
||||
/* ****************************************************************************
|
||||
* cafix/main.c -- cafix main function.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
|
@ -15,37 +15,33 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
* ************************************************************************* */
|
||||
#include "main.h"
|
||||
|
||||
int run_client(int in, int out)
|
||||
/**
|
||||
* main:
|
||||
* Entry point.
|
||||
*/
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int err; casio_link_t *link = NULL;
|
||||
casio_stream_t *stream = NULL;
|
||||
args_t args;
|
||||
|
||||
/* make the stream */
|
||||
err = casio_open_stream_fd(&stream, in, out, 1, 1);
|
||||
if (err) {
|
||||
fprintf(stderr, "Client stream initialization has encountered "
|
||||
"an error: %s\n", casio_strerror(err));
|
||||
if (parse_args(ac, av, &args))
|
||||
return (1);
|
||||
|
||||
switch (args.mode) {
|
||||
case MODE_CONTROL:
|
||||
fprintf(stderr,
|
||||
"This mode prints \"doesn't work yet, sorry\" in the original\n"
|
||||
"cafix, so I don't know what the original author meant...\n"
|
||||
"sorry if you were expecting something cool to happen!\n");
|
||||
return (1);
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Temporarily unmanaged mode.\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* make the handle */
|
||||
err = casio_open_link(&link,
|
||||
CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK | CASIO_LINKFLAG_TERM,
|
||||
stream, NULL);
|
||||
if (err) {
|
||||
fprintf(stderr, "Client initialization has encountered an error: %s\n",
|
||||
casio_strerror(err));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* change working directory. */
|
||||
casio_seven_send_cmdfls_cwd(link, "oui", "fls0");
|
||||
casio_seven_send_cmdfls_cwd(link, "non", "fls0");
|
||||
|
||||
/* we're done. */
|
||||
casio_close_link(link);
|
||||
return (0);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* p7servtest/main.h -- p7servtest main header.
|
||||
/* ****************************************************************************
|
||||
* cafix/main.h -- cafix internals.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
|
@ -15,15 +15,30 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
# include <stdio.h>
|
||||
* ************************************************************************* */
|
||||
#ifndef MAIN_H
|
||||
# define MAIN_H 2018042501
|
||||
# include <errno.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <ctype.h>
|
||||
# include <libcasio.h>
|
||||
|
||||
int parse_args(int ac, char **av);
|
||||
/* Command-line arguments. */
|
||||
|
||||
int run_server(int in, int out);
|
||||
int run_client(int in, int out);
|
||||
# define MODE_SEND 1 /* send a file */
|
||||
# define MODE_RECEIVE 2 /* receive data */
|
||||
# define MODE_CONTROL 3 /* remote control */
|
||||
|
||||
typedef struct {
|
||||
int mode;
|
||||
int should_rename; /* should prompt to rename file */
|
||||
|
||||
const char *filename;
|
||||
} args_t;
|
||||
|
||||
/* Utilities. */
|
||||
|
||||
extern int parse_args(int ac, char **av, args_t *args);
|
||||
|
||||
#endif /* MAIN_H */
|
|
@ -23,22 +23,25 @@
|
|||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************** */
|
||||
/* Version message */
|
||||
/* ---
|
||||
* Help and version messages.
|
||||
* --- */
|
||||
|
||||
/* Version message. */
|
||||
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION)
|
||||
BIN " - from " NAME " v" VERSION
|
||||
" (licensed under GPLv2)\n"
|
||||
"Maintained by " QUOTE(MAINTAINER) ".\n"
|
||||
"Maintained by " MAINTAINER ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
"FITNESS FOR A PARTICULAR PURPOSE.";
|
||||
|
||||
/* Main help message */
|
||||
/* Main help message. */
|
||||
|
||||
static const char help_message[] =
|
||||
"Usage: " QUOTE(BIN) " [-v] [--help|-h] <addin.bin>\n"
|
||||
"Usage: " BIN " [-v] [--help|-h] <addin.bin>\n"
|
||||
" [-o <output>] [-i <icon>] [-n <name>]\n"
|
||||
" [--version <MM.mm.pppp>] [--internal <@ADDIN>]\n"
|
||||
" [--date <yyyy.MMdd.hhmm]\n"
|
||||
|
@ -58,11 +61,12 @@ static const char help_message[] =
|
|||
" --date <date> The application build date. 'yyyy.MMdd.hhmm' formatted.\n"
|
||||
" Default is the current time.\n"
|
||||
"\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".";
|
||||
"Report bugs to " MAINTAINER ".";
|
||||
|
||||
/* ---
|
||||
* Main argument parsing function.
|
||||
* --- */
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* parse_args:
|
||||
* Args parsing main function.
|
||||
|
@ -78,16 +82,12 @@ static const char help_message[] =
|
|||
|
||||
int parse_args(int ac, char **av, args_t *args)
|
||||
{
|
||||
/* initialize args */
|
||||
static char name[9];
|
||||
*args = (args_t){
|
||||
.outfile = "addin.g1a", .iconfile = NULL,
|
||||
.name = name, .intname = "@ADDIN",
|
||||
.version = {0, 0, 0}, .date = time(NULL)};
|
||||
|
||||
/* define options */
|
||||
const char *short_options = "hvo:i:n:";
|
||||
struct option long_options[] = {
|
||||
const char *s_ver = NULL, *s_date = NULL, *p, *e;
|
||||
int i, c, pc, help = 0;
|
||||
char **pv;
|
||||
const char *short_opts = "hvo:i:n:";
|
||||
struct option long_opts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", required_argument, NULL, 'V'},
|
||||
{"internal", required_argument, NULL, 'I'},
|
||||
|
@ -95,100 +95,157 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
{NULL, 0, NULL, 0},
|
||||
};
|
||||
|
||||
/* Initialize the arguments. */
|
||||
|
||||
args->outfile = "addin.g1a";
|
||||
args->iconfile = NULL;
|
||||
args->name = name;
|
||||
args->intname = "@ADDIN";
|
||||
args->version.casio_version_major = 0;
|
||||
args->version.casio_version_minor = 0;
|
||||
args->version.casio_version_zone = casio_version_zone_none;
|
||||
args->version.casio_version_math = casio_version_math_all;
|
||||
args->version.casio_version_status = casio_version_status_standard;
|
||||
args->version.casio_version_platform = casio_version_platform_special;
|
||||
args->date = time(NULL);
|
||||
|
||||
/* get all options */
|
||||
int c; opterr = 0;
|
||||
int help = 0;
|
||||
const char *s_ver = NULL, *s_date = NULL;
|
||||
while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1)
|
||||
opterr = 0;
|
||||
while ((c = getopt_long(ac, av, short_opts, long_opts, NULL)) != -1)
|
||||
switch (c) {
|
||||
/* help, version */
|
||||
case 'h': help = 1; break;
|
||||
case 'v': puts(version_message); return (0); break;
|
||||
/* Help and version flags. */
|
||||
|
||||
/* general options */
|
||||
case 'o': args->outfile = optarg; break;
|
||||
case 'i': args->iconfile = optarg; break;
|
||||
case 'h':
|
||||
help = 1;
|
||||
break;
|
||||
case 'v':
|
||||
puts(version_message);
|
||||
return (1);
|
||||
|
||||
/* build options */
|
||||
case 'n': args->name = optarg; break;
|
||||
case 'V': s_ver = optarg; break;
|
||||
case 'I': args->intname = optarg; break;
|
||||
case 'D': s_date = optarg; break;
|
||||
/* General options. */
|
||||
|
||||
case 'o':
|
||||
args->outfile = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
args->iconfile = optarg;
|
||||
break;
|
||||
|
||||
/* Build options. */
|
||||
|
||||
case 'n':
|
||||
args->name = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
s_ver = optarg;
|
||||
break;
|
||||
case 'I':
|
||||
args->intname = optarg;
|
||||
break;
|
||||
case 'D':
|
||||
s_date = optarg;
|
||||
break;
|
||||
|
||||
/* in case of error */
|
||||
case '?': switch (optopt) {
|
||||
case 'o': err("-o: expected an argument"); break;
|
||||
case 'i': err("-i: expected an argument"); break;
|
||||
case 'n': err("-n: expected an argument"); break;
|
||||
case 'V': err("--version: expected an argument"); break;
|
||||
case 'I': err("--internal: expected an argument"); break;
|
||||
case 'D': err("--date: expected an argument"); break;
|
||||
} break;
|
||||
case '?':
|
||||
switch (optopt) {
|
||||
case 'o':
|
||||
err("-o: expected an argument");
|
||||
return (1);
|
||||
case 'i':
|
||||
err("-i: expected an argument");
|
||||
return (1);
|
||||
case 'n':
|
||||
err("-n: expected an argument");
|
||||
return (1);
|
||||
case 'V':
|
||||
err("--version: expected an argument");
|
||||
return (1);
|
||||
case 'I':
|
||||
err("--internal: expected an argument");
|
||||
return (1);
|
||||
case 'D':
|
||||
err("--date: expected an argument");
|
||||
return (1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* get non-option arguments (subcommand and parameters) */
|
||||
int pc = ac - optind; char **pv = &av[optind];
|
||||
if (pc != 1) help = 1;
|
||||
/* Get parameters. */
|
||||
|
||||
pc = ac - optind;
|
||||
pv = &av[optind];
|
||||
|
||||
if (pc != 1)
|
||||
help = 1;
|
||||
args->infile = pv[0];
|
||||
|
||||
/* put help */
|
||||
if (help) { puts(help_message); return (0); }
|
||||
/* Put the help message. */
|
||||
|
||||
/* get name */
|
||||
const char *p = strrchr(pv[0], '/');
|
||||
if (!p) p = pv[0];
|
||||
/* TODO: MS-Windows */
|
||||
const char *e = strrchr(p, '.');
|
||||
if (help) {
|
||||
puts(help_message);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Get the name.
|
||||
* TODO: manage MS-Windows like paths. */
|
||||
|
||||
p = strrchr(pv[0], '/');
|
||||
if (!p)
|
||||
p = pv[0];
|
||||
|
||||
e = strrchr(p, '.');
|
||||
name[0] = 0;
|
||||
for (int i = 0; p < e && i < 8; p++) {
|
||||
if (isupper(*p)) {
|
||||
name[i++] = *p;
|
||||
name[i] = 0;
|
||||
}
|
||||
} if (!name[0])
|
||||
}
|
||||
if (!name[0])
|
||||
strcpy(name, "ADDIN");
|
||||
|
||||
/* check internal name */
|
||||
/* Check the internal name. */
|
||||
|
||||
if (args->intname[0] != '@') {
|
||||
err("internal name should start with an '@'");
|
||||
return (0);
|
||||
} for (int i = 1; args->intname[i]; i++) {
|
||||
return (1);
|
||||
} for (i = 1; args->intname[i]; i++) {
|
||||
if (i >= 8) {
|
||||
err("internal name should be up to 8 characters only!");
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (!isupper(args->intname[i])) {
|
||||
err("internal name should be an '@' then up to seven uppercase "
|
||||
"letters!");
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* get version */
|
||||
/* Get the version. */
|
||||
|
||||
if (s_ver) {
|
||||
if (g1m_check_version(s_ver)) {
|
||||
if (casio_check_version(s_ver)) {
|
||||
err("version string '%s' does not have "
|
||||
"expected format 'MM.mm.ffff'", s_ver);
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* decode! */
|
||||
g1m_decode_version(s_ver, &args->version);
|
||||
casio_decode_version(&args->version, s_ver);
|
||||
}
|
||||
|
||||
/* get date */
|
||||
/* Get the date. */
|
||||
|
||||
if (s_date) {
|
||||
if (g1m_check_date(s_date)) {
|
||||
if (casio_decode_date(&args->date, s_date)) {
|
||||
err("date string '%s' does not have "
|
||||
"expected format 'yyyy.MMdd.hhmm'", s_date);
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* decode! */
|
||||
g1m_decode_date(s_date, &args->date);
|
||||
}
|
||||
|
||||
/* everything went well */
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
#include <magick/MagickCore.h>
|
||||
#include <MagickCore/MagickCore.h>
|
||||
|
||||
/**
|
||||
* open_icon:
|
||||
|
@ -30,15 +30,21 @@
|
|||
|
||||
int open_icon(const char *path, uint32_t **icon)
|
||||
{
|
||||
int ret = 1;
|
||||
int ret = 1, i;
|
||||
unsigned int width, height;
|
||||
size_t x, y;
|
||||
float r, g, b;
|
||||
Image *images = NULL, *image = NULL;
|
||||
ImageInfo *info = NULL;
|
||||
ExceptionInfo *exception = NULL;
|
||||
const Quantum *pixels;
|
||||
|
||||
/* Initialize. */
|
||||
|
||||
/* initialize */
|
||||
MagickCoreGenesis("g1a-wrapper", MagickTrue);
|
||||
|
||||
/* read source image and image info */
|
||||
/* Read source image and image info. */
|
||||
|
||||
exception = AcquireExceptionInfo();
|
||||
info = CloneImageInfo((ImageInfo*)NULL);
|
||||
strcpy(info->filename, path);
|
||||
|
@ -48,47 +54,58 @@ int open_icon(const char *path, uint32_t **icon)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
/* get the first frame */
|
||||
image = RemoveFirstImageFromList(&images);
|
||||
if (!image) goto fail;
|
||||
/* Get the first frame. */
|
||||
|
||||
/* check the dimensions */
|
||||
unsigned int width = image->columns, height = image->rows;
|
||||
image = RemoveFirstImageFromList(&images);
|
||||
if (!image)
|
||||
goto fail;
|
||||
|
||||
/* Check the dimensions. */
|
||||
|
||||
width = image->columns;
|
||||
height = image->rows;
|
||||
if (width != 30 || height < 17 || height > 19) {
|
||||
err("icon must be between 30x17 and 30x19 pixels, is %ux%u",
|
||||
width, height);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* get the pixels */
|
||||
const Quantum *pixels = GetVirtualPixels(image, 0, 0, width, height,
|
||||
exception);
|
||||
/* Get access to the pixels. */
|
||||
|
||||
pixels = GetVirtualPixels(image, 0, 0, width, height, exception);
|
||||
if (!pixels) {
|
||||
err("unable to access icon pixels.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* skip the first line */
|
||||
if (height == 19) pixels += width * 4;
|
||||
/* Skip the first line. */
|
||||
|
||||
/* get the pixels */
|
||||
for (size_t y = 0; y < 17; y++) for (size_t x = 0; x < 30; x++) {
|
||||
/* get the total */
|
||||
float r = *pixels++;
|
||||
float g = *pixels++;
|
||||
float b = *pixels++;
|
||||
if (height == 19)
|
||||
pixels += width * 4;
|
||||
|
||||
/* Get the pixels. */
|
||||
|
||||
for (y = 0; y < 17; y++) for (x = 0; x < 30; x++) {
|
||||
/* Calculate and check the total. */
|
||||
|
||||
r = *pixels++;
|
||||
g = *pixels++;
|
||||
b = *pixels++;
|
||||
pixels++;
|
||||
|
||||
/* check the total */
|
||||
icon[y][x] = (r + g + b > 0x198) ? 0xFFFFFF : 0x000000;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
fail:
|
||||
if (info) DestroyImageInfo(info);
|
||||
if (exception) DestroyExceptionInfo(exception);
|
||||
if (image) DestroyImage(image);
|
||||
if (images) DestroyImage(images);
|
||||
if (info)
|
||||
DestroyImageInfo(info);
|
||||
if (exception)
|
||||
DestroyExceptionInfo(exception);
|
||||
if (image)
|
||||
DestroyImage(image);
|
||||
if (images)
|
||||
DestroyImage(images);
|
||||
MagickCoreTerminus();
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <libg1m.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
|
@ -36,15 +35,19 @@
|
|||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int ret = 1; FILE *in = NULL;
|
||||
g1m_handle_t *handle = NULL;
|
||||
|
||||
/* Parse args */
|
||||
int ret = 1, err; FILE *in = NULL;
|
||||
casio_file_t *handle = NULL;
|
||||
unsigned char *p;
|
||||
long off; size_t sz;
|
||||
args_t args;
|
||||
if (!parse_args(ac, av, &args))
|
||||
return (0);
|
||||
|
||||
/* get file length */
|
||||
/* Parse the arguments. */
|
||||
|
||||
if (parse_args(ac, av, &args))
|
||||
return (1);
|
||||
|
||||
/* Get file length. */
|
||||
|
||||
in = fopen(args.infile, "r");
|
||||
if (!in) {
|
||||
err("couldn't open input file: %s", strerror(errno));
|
||||
|
@ -54,28 +57,31 @@ int main(int ac, char **av)
|
|||
err("couldn't seek in file.");
|
||||
goto fail;
|
||||
}
|
||||
long off = ftell(in);
|
||||
off = ftell(in);
|
||||
if (off < 0L)
|
||||
goto fail;
|
||||
size_t sz = (off < 0) ? SIZE_MAX : (size_t)off;
|
||||
sz = (off < 0) ? SIZE_MAX : (size_t)off;
|
||||
if (fseek(in, 0L, SEEK_SET))
|
||||
goto fail;
|
||||
|
||||
/* make the handle */
|
||||
int err = g1m_make_addin(&handle, g1m_platform_fx, sz,
|
||||
/* Make the handle. */
|
||||
|
||||
err = casio_make_addin(&handle, casio_filefor_fx, sz,
|
||||
args.name, args.intname, &args.version, &args.date);
|
||||
if (err) {
|
||||
err("couldn't make libg1m handle: %s", g1m_strerror(err));
|
||||
err("couldn't make libg1m handle: %s", casio_strerror(err));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* decode the icon */
|
||||
open_icon(args.iconfile, handle->icon_unsel);
|
||||
open_icon(args.iconfile, handle->casio_file_icon_unsel);
|
||||
|
||||
/* copy the file content */
|
||||
unsigned char *p = handle->content;
|
||||
p = handle->casio_file_content;
|
||||
while (sz) {
|
||||
size_t rd = fread(p, 1, sz, in);
|
||||
size_t rd;
|
||||
|
||||
rd = fread(p, 1, sz, in);
|
||||
if (!rd) {
|
||||
err("couldn't read binary data: %s", strerror(errno));
|
||||
goto fail;
|
||||
|
@ -84,17 +90,20 @@ int main(int ac, char **av)
|
|||
}
|
||||
|
||||
/* encode */
|
||||
err = g1m_write(handle, args.outfile);
|
||||
err = casio_write_file(handle, args.outfile);
|
||||
if (err) {
|
||||
err("couldn't write to output file: %s",
|
||||
err == g1m_error_nostream ? strerror(errno) : g1m_strerror(err));
|
||||
err == casio_error_nostream ? strerror(errno)
|
||||
: casio_strerror(err));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* we're good */
|
||||
ret = 0;
|
||||
fail:
|
||||
if (in) fclose(in);
|
||||
if (handle) g1m_free(handle);
|
||||
if (in)
|
||||
fclose(in);
|
||||
if (handle)
|
||||
casio_free_file(handle);
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
@ -18,27 +18,26 @@
|
|||
* ************************************************************************** */
|
||||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
# define Q(x) #x
|
||||
# define QUOTE(x) Q(x)
|
||||
# include <stdio.h>
|
||||
# include <libg1m.h>
|
||||
# include <libcasio.h>
|
||||
# define warn(M, ...) \
|
||||
fprintf(stderr, "g1a-wrapper: warning: " M "\n", ##__VA_ARGS__)
|
||||
# define err(M, ...) \
|
||||
fprintf(stderr, "g1a-wrapper: error: " M "\n", ##__VA_ARGS__)
|
||||
|
||||
/* Arguments */
|
||||
typedef struct {
|
||||
/* general options */
|
||||
/* General options. */
|
||||
|
||||
const char *infile; /* path to the input file */
|
||||
const char *outfile; /* default: addin.g1a */
|
||||
const char *iconfile; /* icon file, default is blank */
|
||||
|
||||
/* build options */
|
||||
const char *name; /* default: truncated output filename */
|
||||
const char *intname; /* default: @ADDIN */
|
||||
g1m_version_t version; /* default: 00.00.0000 */
|
||||
time_t date; /* default: current time */
|
||||
/* Build options. */
|
||||
|
||||
const char *name; /* default: truncated output filename */
|
||||
const char *intname; /* default: @ADDIN */
|
||||
casio_version_t version; /* default: 00.00.0000 */
|
||||
time_t date; /* default: current time */
|
||||
} args_t;
|
||||
|
||||
/* Command-line arguments parsing function */
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <getopt.h>
|
||||
#define Q(x) #x
|
||||
#define QUOTE(x) Q(x)
|
||||
|
||||
/* ---
|
||||
* Help and version messages.
|
||||
|
@ -42,13 +40,13 @@ static const char *help_loglevel_init =
|
|||
|
||||
static const char *help_end =
|
||||
"\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".\n";
|
||||
"Report bugs to " MAINTAINER ".\n";
|
||||
|
||||
/* Version message. */
|
||||
|
||||
static const char *version_message =
|
||||
"mcsfile - from p7utils v" QUOTE(VERSION) " (licensed under GPLv2)\n"
|
||||
"Maintained by " QUOTE(MAINTAINER) ".\n"
|
||||
BIN " - from " NAME " v" VERSION " (licensed under GPLv2)\n"
|
||||
"Maintained by " MAINTAINER ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
|
|
132
src/p7/args.c
132
src/p7/args.c
|
@ -23,26 +23,30 @@
|
|||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************** */
|
||||
/* ---
|
||||
* Help and version messages.
|
||||
* --- */
|
||||
|
||||
/* Version message */
|
||||
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION)
|
||||
BIN " - from " NAME " v" VERSION
|
||||
" (licensed under GPLv2)\n"
|
||||
"Maintained by " QUOTE(MAINTAINER) ".\n"
|
||||
"Maintained by " MAINTAINER ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
"FITNESS FOR A PARTICULAR PURPOSE.";
|
||||
|
||||
/* Parts */
|
||||
|
||||
#define FOOT \
|
||||
"\nType \"" QUOTE(BIN) " --help\" for other subcommands and general options."
|
||||
"\nType \"" BIN " --help\" for other subcommands and general options."
|
||||
|
||||
/* Sending help message */
|
||||
|
||||
static const char help_send[] =
|
||||
"Usage: " QUOTE(BIN) " send [-f] [-o <on-calc filename>]\n"
|
||||
"Usage: " BIN " send [-f] [-o <on-calc filename>]\n"
|
||||
" [-d <on-calc directory>] [-#] <local file>\n"
|
||||
"Send a file to the calculator.\n"
|
||||
"\n"
|
||||
|
@ -56,8 +60,9 @@ static const char help_send[] =
|
|||
FOOT;
|
||||
|
||||
/* Getting help message */
|
||||
|
||||
static const char help_get[] =
|
||||
"Usage: " QUOTE(BIN) " get [-o <local file>]\n"
|
||||
"Usage: " BIN " get [-o <local file>]\n"
|
||||
" [-d <on-calc directory>] <on-calc filename>\n"
|
||||
"Request a file from the calculator.\n"
|
||||
"\n"
|
||||
|
@ -69,8 +74,9 @@ static const char help_get[] =
|
|||
FOOT;
|
||||
|
||||
/* Copying help message */
|
||||
|
||||
static const char help_copy[] =
|
||||
"Usage: " QUOTE(BIN) " copy [-d <source directory]\n"
|
||||
"Usage: " BIN " copy [-d <source directory]\n"
|
||||
" [-t <destination directory>] <source file> <dest file>\n"
|
||||
"Copies a file into the other on the calculator.\n"
|
||||
"\n"
|
||||
|
@ -80,8 +86,9 @@ static const char help_copy[] =
|
|||
FOOT;
|
||||
|
||||
/* Deleting help message */
|
||||
|
||||
static const char help_del[] =
|
||||
"Usage: " QUOTE(BIN) " delete [-d <on-calc directory] <on-calc filename>\n"
|
||||
"Usage: " BIN " delete [-d <on-calc directory] <on-calc filename>\n"
|
||||
"Delete a file on the calculator.\n"
|
||||
"\n"
|
||||
"Options are:\n"
|
||||
|
@ -90,38 +97,44 @@ static const char help_del[] =
|
|||
FOOT;
|
||||
|
||||
/* Listing help message */
|
||||
|
||||
static const char help_list[] =
|
||||
"Usage: " QUOTE(BIN) " list\n"
|
||||
"Usage: " BIN " list\n"
|
||||
"List files on the distant filesystem.\n"
|
||||
FOOT;
|
||||
|
||||
/* Resetting help message */
|
||||
|
||||
static const char help_reset[] =
|
||||
"Usage: " QUOTE(BIN) " reset\n"
|
||||
"Usage: " BIN " reset\n"
|
||||
"Reset the distant filesystem.\n"
|
||||
FOOT;
|
||||
|
||||
/* Optimizing help message */
|
||||
|
||||
static const char help_optimize[] =
|
||||
"Usage: " QUOTE(BIN) " optimize\n"
|
||||
"Usage: " BIN " optimize\n"
|
||||
"Optimize the distant filesystem.\n"
|
||||
FOOT;
|
||||
|
||||
/* Dumping help message */
|
||||
|
||||
static const char help_info[] =
|
||||
"Usage: " QUOTE(BIN) " info\n"
|
||||
"Usage: " BIN " info\n"
|
||||
"Dump information about the calculator.\n"
|
||||
FOOT;
|
||||
|
||||
/* List serial devices */
|
||||
|
||||
static const char help_listcom[] =
|
||||
"Usage: " QUOTE(BIN) " list-devices\n"
|
||||
"Usage: " BIN " list-devices\n"
|
||||
"List serial devices.\n"
|
||||
FOOT;
|
||||
|
||||
/* Idle */
|
||||
|
||||
static const char help_idle[] =
|
||||
"Usage: " QUOTE(BIN) " idle|laze\n"
|
||||
"Usage: " BIN " idle|laze\n"
|
||||
"Only initialize or end the communication.\n"
|
||||
"\n"
|
||||
"This subcommand is useful when used with `--no-init` and/or `--no-exit`.\n"
|
||||
|
@ -130,16 +143,20 @@ static const char help_idle[] =
|
|||
FOOT;
|
||||
|
||||
/* Unlock */
|
||||
|
||||
static const char help_unlock[] =
|
||||
"Usage: " QUOTE(BIN) " unlock\n"
|
||||
"Usage: " BIN " unlock\n"
|
||||
"Unlock examination mode.\n"
|
||||
FOOT;
|
||||
/* ************************************************************************** */
|
||||
/* Help helpers */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/* ---
|
||||
* Help helpers.
|
||||
* --- */
|
||||
|
||||
/* Main help message parts */
|
||||
|
||||
static const char help_main_part0[] =
|
||||
"Usage: " QUOTE(BIN) " [--version|-v] [--help|-h] [--no-init] [--no-exit]\n"
|
||||
"Usage: " BIN " [--version|-v] [--help|-h] [--no-init] [--no-exit]\n"
|
||||
" [--storage <fls0>] [--com <device>]\n"
|
||||
" <subcommand> [options...]\n"
|
||||
"\n"
|
||||
|
@ -163,7 +180,7 @@ static const char help_main_part0[] =
|
|||
" If this option isn't used, the program will look for a\n"
|
||||
" calculator connected using direct USB.\n"
|
||||
" --storage <abc0> The storage device with which to interact (fls0, crd0).\n"
|
||||
" Default storage device is '" QUOTE(DEFAULT_STORAGE) "'.\n"
|
||||
" Default storage device is '" DEFAULT_STORAGE "'.\n"
|
||||
" --no-exit Does not terminate connection when action is completed.\n"
|
||||
" --no-init Does not initialize connection (should only be used\n"
|
||||
" when --no-exit was used last time p7 was called).\n"
|
||||
|
@ -180,8 +197,8 @@ static const char help_main_loglevel_init[] =
|
|||
static const char help_main_part1[] =
|
||||
" --reset Reset the default communication settings (9600N2).\n"
|
||||
"\n"
|
||||
"Type \"" QUOTE(BIN) " <subcommand> --help\" for some help about the subcommand.\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".\n";
|
||||
"Type \"" BIN " <subcommand> --help\" for some help about the subcommand.\n"
|
||||
"Report bugs to " MAINTAINER ".\n";
|
||||
|
||||
/**
|
||||
* put_loglevel:
|
||||
|
@ -233,10 +250,13 @@ static void put_main_help(void)
|
|||
|
||||
fputs(help_main_part1, stdout);
|
||||
}
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
/* useful macros */
|
||||
|
||||
/* ---
|
||||
* Main argument parsing function.
|
||||
* --- */
|
||||
|
||||
/* Useful macros. */
|
||||
|
||||
#define sub_init(CMD, NARGS) \
|
||||
args->menu = mn_##CMD; \
|
||||
if (help || aac != 1 + (NARGS)) { \
|
||||
|
@ -262,8 +282,8 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
int c, help = 0, rst = 0;
|
||||
const char *s_out = NULL, *s_dir = NULL, *s_todir = NULL;
|
||||
const char *s_use = NULL, *s_set = NULL, *s_log = NULL;
|
||||
char short_options[] = "hvfo:d:t:#";
|
||||
struct option long_options[] = {
|
||||
char short_opts[] = "hvfo:d:t:#";
|
||||
struct option long_opts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"com", required_argument, NULL, 'c'},
|
||||
|
@ -295,7 +315,7 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
args->local = NULL;
|
||||
args->force = 0;
|
||||
args->com = 0;
|
||||
args->storage = QUOTE(DEFAULT_STORAGE);
|
||||
args->storage = DEFAULT_STORAGE;
|
||||
args->initflags = CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK
|
||||
| CASIO_LINKFLAG_TERM;
|
||||
args->use = NULL;
|
||||
|
@ -304,7 +324,7 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
|
||||
/* get all options */
|
||||
opterr = 0;
|
||||
while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) {
|
||||
while ((c = getopt_long(ac, av, short_opts, long_opts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
/* help */
|
||||
case 'h': help = 1; break;
|
||||
|
@ -341,15 +361,15 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
/* in case of error */
|
||||
case '?':
|
||||
if (optopt == 'o')
|
||||
log("-o, --output: expected an argument\n");
|
||||
fprintf(stderr, "-o, --output: expected an argument\n");
|
||||
else if (optopt == 'd')
|
||||
log("-d, --directory: expected an argument\n");
|
||||
fprintf(stderr, "-d, --directory: expected an argument\n");
|
||||
else if (optopt == 't')
|
||||
log("-t, --to: expected an argument\n");
|
||||
fprintf(stderr, "-t, --to: expected an argument\n");
|
||||
else if (optopt == 'c')
|
||||
log("--com: expected an argument\n");
|
||||
fprintf(stderr, "--com: expected an argument\n");
|
||||
else if (optopt == 's')
|
||||
log("--storage: expected an argument\n");
|
||||
fprintf(stderr, "--storage: expected an argument\n");
|
||||
else
|
||||
break;
|
||||
return (0);
|
||||
|
@ -423,22 +443,24 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
sub_init(unlock, 0)
|
||||
} else {
|
||||
/* unknown subcommand ! */
|
||||
log("Unknown subcommand '%s'.\n", aav[0]);
|
||||
fprintf(stderr, "Unknown subcommand '%s'.\n", aav[0]);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* check string lengths */
|
||||
int noerror = 0;
|
||||
if (args->filename && strnlen(args->filename, 13) == 13)
|
||||
log("On-calc filename must have 12 chars or less!\n");
|
||||
else if (args->newname && strnlen(args->newname, 13) == 13)
|
||||
log("Destination filename must have 12 chars or less!\n");
|
||||
else if (args->dirname && strnlen(args->dirname, 9) == 9)
|
||||
log("On-calc directory name must have 8 chars or less!\n");
|
||||
else if (args->newdir && strnlen(args->newdir, 9) == 9)
|
||||
log("Destination directory name must have 8 chars or less!\n");
|
||||
else if (strnlen(args->storage, 5) != 4)
|
||||
log("Storage device (%s) should be 4 chars long!\n", args->storage);
|
||||
if (args->filename && !memchr(args->filename, '\0', 13))
|
||||
fprintf(stderr, "On-calc filename must have 12 chars or less!\n");
|
||||
else if (args->newname && !memchr(args->newname, '\0', 13))
|
||||
fprintf(stderr, "Destination filename must have 12 chars or less!\n");
|
||||
else if (args->dirname && !memchr(args->dirname, '\0', 9))
|
||||
fprintf(stderr, "On-calc directory name must have 8 chars or less!\n");
|
||||
else if (args->newdir && !memchr(args->newdir, '\0', 9))
|
||||
fprintf(stderr,
|
||||
"Destination directory name must have 8 chars or less!\n");
|
||||
else if (!memchr(args->storage, '\0', 5))
|
||||
fprintf(stderr, "Storage device (%s) should be 4 chars long!\n",
|
||||
args->storage);
|
||||
else
|
||||
noerror = 1;
|
||||
if (!noerror) return (0);
|
||||
|
@ -447,8 +469,8 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
if (s_use) {
|
||||
if (args->com) args->use = &args->_use;
|
||||
if (casio_make_attrs(&args->_use, s_use)) {
|
||||
log("--use: invalid format!\n");
|
||||
log("--use: expected <speed><parity><stopbits>, "
|
||||
fprintf(stderr, "--use: invalid format!\n");
|
||||
fprintf(stderr, "--use: expected <speed><parity><stopbits>, "
|
||||
"e.g. 9600N2 or 115200E1!\n");
|
||||
return (0);
|
||||
}
|
||||
|
@ -461,8 +483,8 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
args->do_the_set = 1;
|
||||
if (args->com) args->set = &args->_set;
|
||||
if (casio_make_attrs(&args->_set, s_set)) {
|
||||
log("--set: invalid format!\n");
|
||||
log("--set: expected <speed><parity><stopbits>, "
|
||||
fprintf(stderr, "--set: invalid format!\n");
|
||||
fprintf(stderr, "--set: expected <speed><parity><stopbits>, "
|
||||
"e.g. 9600N2 or 115200E1!\n");
|
||||
return (0);
|
||||
}
|
||||
|
@ -473,7 +495,8 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
if (fpmode[0] == 'w' && !strcmp(args->localpath, "-"))
|
||||
args->local = stdout;
|
||||
else if (!(args->local = fopen(args->localpath, fpmode))) {
|
||||
log("Could not open local file : %s\n", strerror(errno));
|
||||
fprintf(stderr, "Could not open local file : %s\n",
|
||||
strerror(errno));
|
||||
if (fpmode[0] == 'w')
|
||||
remove(args->localpath);
|
||||
return (0);
|
||||
|
@ -481,7 +504,8 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
}
|
||||
|
||||
/* set the log level */
|
||||
if (s_log) casio_setlog(s_log);
|
||||
if (s_log)
|
||||
casio_setlog(s_log);
|
||||
|
||||
/* everything went well */
|
||||
return (1);
|
||||
|
|
|
@ -36,13 +36,14 @@ int dump(casio_link_t *handle)
|
|||
|
||||
/* Wiped out things */
|
||||
if (info->casio_link_info_wiped & casio_link_info_wiped_preprog)
|
||||
log("Warning: Preprogrammed ROM information looks wiped out!\n");
|
||||
fprintf(stderr,
|
||||
"Warning: Preprogrammed ROM information looks wiped out!\n");
|
||||
if (info->casio_link_info_wiped & casio_link_info_wiped_bootcode)
|
||||
log("Warning: Bootcode information looks wiped out!\n");
|
||||
fprintf(stderr, "Warning: Bootcode information looks wiped out!\n");
|
||||
if (info->casio_link_info_wiped & casio_link_info_wiped_os)
|
||||
log("Warning: OS information looks wiped out!\n");
|
||||
fprintf(stderr, "Warning: OS information looks wiped out!\n");
|
||||
if (!info->casio_link_info_username[0])
|
||||
log("Warning: Username is not set.\n");
|
||||
fprintf(stderr, "Warning: Username is not set.\n");
|
||||
|
||||
/* main information */
|
||||
printf("CPU ID (probably out of date): %s\n", info->casio_link_info_cpuid);
|
||||
|
|
|
@ -54,7 +54,7 @@ static const char error_unsupported_device[] =
|
|||
static const char error_unplanned[] =
|
||||
"The calculator didn't act as planned.\n"
|
||||
"Stop receive mode on calculator and start it again before re-running " \
|
||||
QUOTE(BIN) ".\n"
|
||||
BIN ".\n"
|
||||
"Error was: %s\n";
|
||||
|
||||
/* Requested file didn't exist. */
|
||||
|
@ -202,13 +202,13 @@ int main(int ac, char **av)
|
|||
/* display error */
|
||||
switch (err) {
|
||||
case casio_error_nocalc:
|
||||
log(error_noconnexion);
|
||||
fprintf(stderr, error_noconnexion);
|
||||
break;
|
||||
case casio_error_noaccess:
|
||||
log(error_noaccess);
|
||||
fprintf(stderr, error_noaccess);
|
||||
break;
|
||||
default:
|
||||
log(error_unplanned, casio_strerror(err));
|
||||
fprintf(stderr, error_unplanned, casio_strerror(err));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -328,20 +328,20 @@ fail:
|
|||
/* put the error string */
|
||||
switch (err) {
|
||||
case casio_error_fullmem:
|
||||
log(error_nospace); break;
|
||||
fprintf(stderr, error_nospace); break;
|
||||
case casio_error_empty:
|
||||
log(error_empty); break;
|
||||
fprintf(stderr, error_empty); break;
|
||||
case casio_error_notfound:
|
||||
log(error_noexists); break;
|
||||
fprintf(stderr, error_noexists); break;
|
||||
case casio_error_nocalc:
|
||||
log(error_disconnected); break;
|
||||
fprintf(stderr, error_disconnected); break;
|
||||
#if 0
|
||||
case casio_error_unsupported:
|
||||
log(error_unsupported); break;
|
||||
fprintf(stderr, error_unsupported); break;
|
||||
case casio_error_unsupported_device:
|
||||
log(error_unsupported_device, args.storage); break;
|
||||
fprintf(stderr, error_unsupported_device, args.storage); break;
|
||||
#endif
|
||||
default: log(error_unplanned, casio_strerror(err));
|
||||
default: fprintf(stderr, error_unplanned, casio_strerror(err));
|
||||
}
|
||||
|
||||
/* that doesn't mean you shouldn't exit, heh. */
|
||||
|
|
|
@ -18,11 +18,8 @@
|
|||
* ************************************************************************** */
|
||||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
# define Q(x) #x
|
||||
# define QUOTE(x) Q(x)
|
||||
# include <stdio.h>
|
||||
# include <libcasio.h>
|
||||
# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__)
|
||||
|
||||
/* Menus */
|
||||
typedef enum {
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
/* ************************************************************************* */
|
||||
/* The version message - that's when the President comes in */
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n"
|
||||
"Maintained by " QUOTE(MAINTAINER) ".\n"
|
||||
BIN " - from " NAME " v" VERSION " (licensed under GPLv2)\n"
|
||||
"Maintained by " MAINTAINER ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
|
@ -37,10 +37,14 @@ QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n
|
|||
|
||||
/* Main help message */
|
||||
static const char help_main0[] =
|
||||
"Usage: " QUOTE(BIN) " [--version|-v] [--help|-h] [--com <device>]\n"
|
||||
"Usage: " BIN " [--version|-v] [--help|-h] [--com <device>]\n"
|
||||
" [--no-prepare] [--uexe <path>]\n"
|
||||
" <subcommand> [options...]\n"
|
||||
"\n"
|
||||
"This program interacts with a CASIO calculator's firmware.\n"
|
||||
"Keep in mind that using it is dangerous and could easily brick your\n"
|
||||
"calculator if you aren't careful enough.\n"
|
||||
"\n"
|
||||
"Subcommands you can use are :\n"
|
||||
" prepare-only Set-up the update program, but leave it for other programs\n"
|
||||
" to interact with it.\n"
|
||||
|
@ -64,23 +68,23 @@ static const char help_main1[] =
|
|||
" -u, --uexe <path> Use a custom update program.\n"
|
||||
" If `--no-prepare` is not given, this option is required.\n"
|
||||
"\n"
|
||||
"Type \"" QUOTE(BIN) " <subcommand> --help\" for some help about a subcommand.\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".";
|
||||
"Type \"" BIN " <subcommand> --help\" for some help about a subcommand.\n"
|
||||
"Report bugs to " MAINTAINER ".";
|
||||
|
||||
/* Subcommands help messages footer */
|
||||
#define FOOT \
|
||||
"\nType \"" QUOTE(BIN) " --help\" for other subcommands and general options."
|
||||
"\nType \"" BIN " --help\" for other subcommands and general options."
|
||||
|
||||
/* Help message for prepare subcommand */
|
||||
static const char help_prepare_only[] =
|
||||
"Usage: " QUOTE(BIN) " prepare-only\n"
|
||||
"Usage: " BIN " prepare-only\n"
|
||||
"Send the P7 server on the calculator for further operations.\n"
|
||||
"This must be used before any other p7os operation.\n"
|
||||
FOOT;
|
||||
|
||||
/* Help message for get subcommand */
|
||||
static const char help_get[] =
|
||||
"Usage: " QUOTE(BIN) " get [-o <os.bin>]\n"
|
||||
"Usage: " BIN " get [-o <os.bin>]\n"
|
||||
"Get the calculator OS image.\n"
|
||||
"\n"
|
||||
"Options are :\n"
|
||||
|
@ -89,7 +93,7 @@ FOOT;
|
|||
|
||||
/* Help message for flash subcommand. */
|
||||
static const char help_flash[] =
|
||||
"Usage: " QUOTE(BIN) " flash <rom.bin>\n"
|
||||
"Usage: " BIN " flash <rom.bin>\n"
|
||||
"Flash the calculator's OS image.\n"
|
||||
FOOT;
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -19,23 +19,27 @@
|
|||
#include "main.h"
|
||||
|
||||
/* Couldn't initialize connexion to calculator. */
|
||||
|
||||
static const char error_noconnexion[] =
|
||||
"Could not connect to the calculator.\n"
|
||||
"- Is it plugged in and in Receive mode/OS Update?\n"
|
||||
"- Have you tried changing the cable ?\n";
|
||||
|
||||
/* Calculator was found but program wasn't allowed to communicate with it. */
|
||||
|
||||
static const char error_noaccess[] =
|
||||
"Could not get access to the calculator.\n"
|
||||
"Install the appropriate udev rule, or run as root.\n";
|
||||
|
||||
/* The calculator acted in a weird way. */
|
||||
|
||||
static const char error_unplanned[] =
|
||||
"The calculator didn't act as planned: %s.\n"
|
||||
"Stop receive mode on calculator and start it again before re-running " \
|
||||
QUOTE(BIN) ".\n";
|
||||
BIN ".\n";
|
||||
|
||||
/* Unsupported operation -> OS Update, not receive mode! */
|
||||
|
||||
static const char error_unsupported[] =
|
||||
"Required operation was unsupported by the calculator.\n"
|
||||
"If you did not prepare, perhaps you should prepare?\n";
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
# define MAIN_H
|
||||
# include <stdio.h>
|
||||
# include <libcasio.h>
|
||||
# define Q(x) #x
|
||||
# define QUOTE(x) Q(x)
|
||||
# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__)
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
|
|
@ -35,9 +35,13 @@ int open_link(casio_link_t **link, args_t *args,
|
|||
int err;
|
||||
|
||||
/* Open the link. */
|
||||
if (args->com) err = casio_open_com(link, flags, args->com, attrs);
|
||||
else err = casio_open_usb(link, flags);
|
||||
if (err) return (err);
|
||||
|
||||
if (args->com)
|
||||
err = casio_open_com(link, flags, args->com, attrs);
|
||||
else
|
||||
err = casio_open_usb(link, flags);
|
||||
if (err)
|
||||
return (err);
|
||||
|
||||
/* XXX: `--set`, `--use`? */
|
||||
return (0);
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
/* ************************************************************************* */
|
||||
/* Version message */
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n"
|
||||
"Maintained by " QUOTE(MAINTAINER) ".\n"
|
||||
BIN " - from " NAME " v" VERSION " (licensed under GPLv2)\n"
|
||||
"Maintained by " MAINTAINER ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
|
@ -35,7 +35,7 @@ QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n
|
|||
|
||||
/* Help message */
|
||||
static const char help_main0[] =
|
||||
"Usage: " QUOTE(BIN) " [--help|-h] [--version|-v]\n"
|
||||
"Usage: " BIN " [--help|-h] [--version|-v]\n"
|
||||
"\n"
|
||||
"Displays the streamed screen from a CASIO fx calculator.\n"
|
||||
"\n"
|
||||
|
@ -49,9 +49,9 @@ static const char help_log[] =
|
|||
|
||||
static const char help_main1[] =
|
||||
" -z ZOOM Change the zoom (1 to 16)\n"
|
||||
" By default, the zoom will be " QUOTE(DEFAULT_ZOOM) ".\n"
|
||||
" By default, the zoom will be " DEFAULT_ZOOM ".\n"
|
||||
"\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".\n";
|
||||
"Report bugs to " MAINTAINER ".\n";
|
||||
/* ************************************************************************* */
|
||||
/* Main function */
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -38,7 +38,7 @@ static const char error_noaccess[] =
|
|||
static const char error_unplanned[] =
|
||||
"The calculator didn't act as planned.\n"
|
||||
"Stop receive mode on calculator and start it again before re-running " \
|
||||
QUOTE(BIN) ".\n"
|
||||
BIN ".\n"
|
||||
"Error was: %s\n";
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
# include <string.h>
|
||||
# include <libcasio.h>
|
||||
|
||||
# define Q(x) #x
|
||||
# define QUOTE(x) Q(x)
|
||||
|
||||
/* Prototypes. */
|
||||
|
||||
int parse_args(int ac, char **av, int *zoom);
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/* *****************************************************************************
|
||||
* p7servtest/args.c -- p7servtest command-line argument parsing utility.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <getopt.h>
|
||||
#define Q(x) #x
|
||||
#define QUOTE(x) Q(x)
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************** */
|
||||
/* Version message */
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION)
|
||||
" (licensed under GPLv2)\n"
|
||||
"Maintained by " QUOTE(MAINTAINER) ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
"FITNESS FOR A PARTICULAR PURPOSE.";
|
||||
|
||||
/* Main help message */
|
||||
static const char help_main[] =
|
||||
"Usage: " QUOTE(BIN) " [--help] [--version]\n"
|
||||
"\n"
|
||||
"This utility is only there to test the libcasio server feature.\n"
|
||||
"It should not be used in production for anything else.\n"
|
||||
"\n"
|
||||
"General options:\n"
|
||||
" -h, --help Display the help page of the (sub)command and quit.\n"
|
||||
" -v, --version Display the version message and quit.\n"
|
||||
"\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".";
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main args parsing function */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* parse_args:
|
||||
* Args parsing main function.
|
||||
*
|
||||
* @arg ac the arguments count.
|
||||
* @arg av the arguments values.
|
||||
* @return if execution should stop after this call.
|
||||
*/
|
||||
|
||||
int parse_args(int ac, char **av)
|
||||
{
|
||||
/* define options */
|
||||
const char shopts[] = "hv";
|
||||
const struct option longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* get all options */
|
||||
int c; opterr = 0;
|
||||
int help = 0, version = 0;
|
||||
while ((c = getopt_long(ac, av, shopts, longopts, NULL)) >= 0) switch (c) {
|
||||
case 'h': help = 1; break;
|
||||
case 'v': version = 1; break;
|
||||
|
||||
case '?': break;
|
||||
}
|
||||
|
||||
/* get parameters */
|
||||
int pc = ac - optind;
|
||||
if (pc) help = 1;
|
||||
|
||||
/* print help or version */
|
||||
if (help) {
|
||||
puts(help_main);
|
||||
return (1);
|
||||
} else if (version) {
|
||||
puts(version_message);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* no problem */
|
||||
return (0);
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/* *****************************************************************************
|
||||
* p7servtest/main.c -- p7servtest main source.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* init:
|
||||
* Let's go baby.
|
||||
*
|
||||
* @arg sin the server input.
|
||||
* @arg sout the server output.
|
||||
* @arg cin the client input.
|
||||
* @arg cout the client output.
|
||||
*/
|
||||
|
||||
static void init(int sin, int sout, int cin, int cout)
|
||||
{
|
||||
/* everybody do the fork */
|
||||
pid_t pid = fork();
|
||||
if (pid == (pid_t)-1)
|
||||
return ;
|
||||
|
||||
/* yay */
|
||||
if (!pid) run_server(sin, sout);
|
||||
else {
|
||||
sleep(1);
|
||||
run_client(cin, cout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* main:
|
||||
* A handful of feet.
|
||||
*
|
||||
* @arg ac the arguments count.
|
||||
* @arg av the arguments values.
|
||||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
/* parse the arguments */
|
||||
if (parse_args(ac, av))
|
||||
return (0);
|
||||
|
||||
/* create the pipes */
|
||||
int fds1[2], fds2[2];
|
||||
if (pipe(fds1)) {
|
||||
fprintf(stderr,
|
||||
"Unable to make the first set of pipes (server to client)\n");
|
||||
return (1);
|
||||
}
|
||||
if (pipe(fds2)) {
|
||||
fprintf(stderr,
|
||||
"Unable to make the second set of pipes (client to server)\n");
|
||||
close(fds1[0]);
|
||||
close(fds1[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* initialize. */
|
||||
init(fds1[0], fds2[1], fds2[0], fds1[1]);
|
||||
|
||||
/* everything went well. */
|
||||
return (0);
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
/* *****************************************************************************
|
||||
* p7servtest/server.c -- p7servtest virtual server.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Server callbacks */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* directory_exists:
|
||||
* Check if a directory exists.
|
||||
*
|
||||
* @arg cookie the cookie.
|
||||
* @arg dirname the directory.
|
||||
* @arg devname the devname.
|
||||
* @return the error (0 if ok).
|
||||
*/
|
||||
|
||||
static int directory_exists(void *cookie, const char *dirname)
|
||||
{
|
||||
(void)cookie;
|
||||
|
||||
/* check directory name */
|
||||
if (!strcmp(dirname, "oui"))
|
||||
return (0);
|
||||
else return (casio_error_notfound);
|
||||
}
|
||||
/* ************************************************************************** */
|
||||
/* Server configuration */
|
||||
/* ************************************************************************** */
|
||||
/* the server information */
|
||||
static casio_link_info_t server_information = {
|
||||
/* main calculator information */
|
||||
.casio_link_info_cpuid = "The CPU ID, wow!",
|
||||
.casio_link_info_hwid = "TESTSERV",
|
||||
.casio_link_info_product_id = "OMGOMGOMGOMGOMGO",
|
||||
|
||||
/* system configuration */
|
||||
.casio_link_info_username = "Cow",
|
||||
|
||||
/* wiped things */
|
||||
.casio_link_info_wiped =
|
||||
casio_link_info_wiped_preprog | casio_link_info_wiped_bootcode,
|
||||
|
||||
/* flash ROM and RAM information */
|
||||
.casio_link_info_flash_rom_capacity = 8 * 1024 * 1024,
|
||||
.casio_link_info_ram_capacity = 256 * 1024,
|
||||
|
||||
/* OS information */
|
||||
.casio_link_info_os_offset = 0x80000000,
|
||||
.casio_link_info_os_size = 0x100000,
|
||||
.casio_link_info_os_version = {
|
||||
.casio_version_major = 2, .casio_version_minor = 9,
|
||||
.casio_version_zone = casio_version_zone_fr,
|
||||
.casio_version_math = casio_version_math_all,
|
||||
.casio_version_status = casio_version_status_standard,
|
||||
.casio_version_platform = casio_version_platform_special
|
||||
},
|
||||
};
|
||||
|
||||
/* the server filesystems */
|
||||
static casio_filesystem_t server_filesystems[] = {
|
||||
/* main filesystem: the flash */ {
|
||||
.casio_filesystem_name = "fls0",
|
||||
.casio_filesystem_directory_exists = directory_exists
|
||||
},
|
||||
{NULL}
|
||||
};
|
||||
/* ************************************************************************** */
|
||||
/* Server functions */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* run_server:
|
||||
* Run the server!
|
||||
*
|
||||
* @arg in the input.
|
||||
* @arg out the output.
|
||||
*/
|
||||
|
||||
int run_server(int in, int out)
|
||||
{
|
||||
int err; casio_link_t *handle = NULL;
|
||||
casio_stream_t *stream = NULL;
|
||||
|
||||
/* make the stream */
|
||||
err = casio_open_stream_fd(stream, in, out, 1, 1);
|
||||
if (err) {
|
||||
fprintf(stderr, "Server stream initialization has encountered "
|
||||
"an error: %s\n", p7_strerror(err));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* make the handle */
|
||||
err = casio_open_link(&handle, 0, stream, NULL);
|
||||
if (err) {
|
||||
fprintf(stderr, "Server initialization has encountered an error: %s\n",
|
||||
p7_strerror(err));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* protect and serve */
|
||||
casio_serve(handle, &server_information, server_filesystems);
|
||||
casio_close_link(handle);
|
||||
return (0);
|
||||
}
|
Reference in New Issue