cake
/
libp7
Archived
1
0
Fork 1

Enhanced project organization

This commit is contained in:
Thomas Touhey 2016-08-21 14:30:52 +02:00
parent 29330e3bae
commit 6120f1f2c7
11 changed files with 315 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/Makefile.cfg
/obj
/libp7.a
/man

View File

@ -12,6 +12,7 @@ include Makefile.vars
# DEDUCED VARS
ALLOBJ = $(foreach mod,$(MODULES),$(SRC_$(mod):%=$(OBJDIR)/$(mod)/%.o))
ALLMAN = $(foreach s,$(MAN_SECTIONS),$(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
# TARGETS
## General targets
@ -47,7 +48,44 @@ fclean: clean
## - Remake library
re: fclean all
# PHONY
.PHONY: all clean fclean re
## - Install library
install:
$(INST) -D -m 644 lib$(NAME).a $(ILIBDIR)/lib$(NAME).a
$(INST) -D -m 644 $(INCDIR)/lib$(NAME).h $(IINCDIR)/lib$(NAME).h
## Documentation related
## - Make manpages directories
$(MAN_SECTIONS:%=$(MANDIR)/man%):
$(MD) $@
## - Make-A-Manpage
define make-manpage-rule
$(MANDIR)/man$1/%.$1: $(DOCDIR)/%.$1.txt | $(MANDIR)/man$1
$(A2X) -f manpage -D $$| $$<
endef
$(foreach section, $(MAN_SECTIONS), \
$(eval $(call make-manpage-rule,$(section))))
## - Make all manpages
all-doc: $(ALLMAN)
## - Remove all manpages
clean-doc:
$(RM) $(ALLMAN)
## - Install-A-Manpage
define make-installmanpage-rule
install-$1-%:| $(MANDIR)/man$1/%.$1
$(INST) -D -m 644 $(MANDIR)/man$1/$$*.$1 $(IMANDIR)/man$1/$$*.$1
$(GZIP) $(IMANDIR)/man$1/$$*.$1
endef
$(foreach section, $(MAN_SECTIONS), \
$(eval $(call make-installmanpage-rule,$(section))))
## - Install manpages
install-doc: $(foreach s,$(MAN_SECTIONS),$(MAN_$(s):%=install-$(s)-%))
## PHONY
.PHONY: all clean fclean re install
# END OF FILE

View File

@ -21,6 +21,10 @@ include Makefile.cfg
SRCDIR = ./src
## Objects directory
OBJDIR = ./obj
## Documentation directory
DOCDIR = ./doc
## Manpages directory
MANDIR = ./man
# MODULES
MODULES = core utils packet protocol
@ -37,6 +41,14 @@ include Makefile.cfg
SRC_protocol = start term \
getusername sendfile reqfile
# MAN SECTIONS
MAN_SECTIONS = 3
# MAN PAGES
MAN_3 = libp7 \
p7_init p7_geterror p7_error \
p7_sendfile p7_reqfile
# BINARY UTILITIES
## Compiler
CC = clang
@ -51,5 +63,11 @@ include Makefile.cfg
MD = mkdir -p
## File remover
RM = rm -f
## Documentation creator
A2X = a2x
## Installer
INST = install
## GZipper
GZIP = gzip -f
# END OF FILE

View File

@ -1,8 +1,8 @@
# libp7 - what is left to do
## In a close future
- Correct sendfile and reqfile so that they take filestreams and file sizes ;
- Make that they check for non-readable (until the end?)/non-writable streams ;
- Finish the termination packet reception details ;
- Add install target for library ;
- Make manpages and add making and installing targets for them ;
## Furthermore
- Write clearer docs about all of this beside the manpages ;

6
configure vendored
View File

@ -14,6 +14,7 @@ loglevel=none
prefix=/usr
libdir='$(IPREFIX)/lib/'"$(gcc --print-multiarch)"
includedir='$(IPREFIX)/include/'"$(gcc --print-multiarch)"
mandir='$(IPREFIX)/share/man'
# Help
usage() {
@ -31,6 +32,7 @@ Installation directories:
Fine tuning of the installation directories:
--libdir=DIR library files of the linker [$libdir]
--includedir=DIR include files for the compiler [$includedir]
--mandir=DIR man root [$mandir]
EOF
exit 0
@ -58,6 +60,8 @@ none]" && continue
libdir=${arg#*=} ;;
--includedir=*)
includedir=${arg#*=} ;;
--mandir=*)
mandir=${arg#*=} ;;
*) echo "$0: '$arg': DIDN'T READ LOL" ;;
esac
done
@ -74,6 +78,7 @@ fi
exec 3>&1 1>Makefile.cfg
cat <<EOF
#!/usr/bin/make -f
# Makefile configuration generated by ./configure
# - Build options
LOG_LEVEL = $loglevel
@ -81,6 +86,7 @@ LOG_LEVEL = $loglevel
IPREFIX = $prefix
ILIBDIR = $libdir
IINCDIR = $includedir
IMANDIR = $mandir
EOF
exec 1>&3 3>&-

44
doc/libp7.3.txt Normal file
View File

@ -0,0 +1,44 @@
LIBP7(3)
========
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
libp7 - implementation of casio's communication protocol 7.00
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
if (!p7_init()) {
printf("Couldn't initialize libp7 : %s\n", p7_geterror());
return (3);
}
p7_start();
FILE *fp = fopen("myaddin.g1a", "r");
p7_sendfile(fp, NULL, "myaddin.g1a", "fls0", 1, NULL);
p7_term();
----
DESCRIPTION
-----------
libp7 implements casio's communication protocol 7.00, which allows users to
send and receive files and information from their calculators.
For now, libp7 only implements simple file operations.
SEE ALSO
--------
*p7_init*(3),
*p7_error*(3),
*p7_geterror*(3),
*p7_sendfile*(3),
*p7_reqfile*(3)

65
doc/p7_error.3.txt Normal file
View File

@ -0,0 +1,65 @@
P7_ERROR(3)
===========
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
p7_error - code of last libp7 error
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
switch (p7_error) {
case ...:
break;
}
----
DESCRIPTION
-----------
p7_error is a global variable containing last error code. It is set whenever
libp7 functions return a "not worked" code (0), and can be used to get more
information about what happened.
This variable can contain the following :
*p7_error_uninitialized*::
User forgot to call p7_init !
*p7_error_libusb*::
An unknown error has occured from libusb. Logs could provide a little
more info.
*p7_error_nocalc*::
Calculator isn't connected (or has been disconnected). Could also be because
the end user forgot to put his calculator in receive mode.
*p7_error_timeout*::
Calculator has timed out.
*p7_error_noseek*::
Provided file stream wasn't seekable (which is required).
*p7_error_filename*::
Provided filename was missing or incorrect (12 chars max !).
*p7_error_dirname*::
Provided directory name was incorrect (8 chars max !).
*p7_error_overwrite_impossible*::
Overwrite was denied by the calculator (the device name was probably
incorrect).
*p7_error_fullmem*::
File was too large for the left memory.
*p7_error_denied_overwrite*::
User denied overwrite (with or without callback)
*p7_error_internal*::
An internal error has occured. Logs should provide a little more info.
*p7_error_unknown*::
An unknown error has occured (the calculator probably didn't act as
planned). This might be because user should end and restart receive mode on
his calculator.
SEE ALSO
--------
*libp7*(3),
*p7_geterror*(3)

30
doc/p7_geterror.3.txt Normal file
View File

@ -0,0 +1,30 @@
P7_GETERROR(3)
==============
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
p7_geterror - Get error string of the last libp7 error
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
printf("Couldn't do action : %s\n", p7_geterror());
return (3);
----
DESCRIPTION
-----------
p7_geterror provides a quick way to display error strings to the end user. To
handle this yourself, you should use *p7_error*(3) directly.
SEE ALSO
--------
*libp7*(3),
*p7_error*(3)

33
doc/p7_init.3.txt Normal file
View File

@ -0,0 +1,33 @@
P7_INIT(3)
==========
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
p7_init - initialize libp7
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
if (!p7_init()) {
printf("Couldn't initialize libp7 : %s\n", p7_geterror());
return (3);
}
----
DESCRIPTION
-----------
p7_init must be called before any other function from libp7. Its return value
indicates if initialization went alright (1) or not (0).
SEE ALSO
--------
*libp7*(3),
*p7_error*(3),
*p7_geterror*(3)

35
doc/p7_reqfile.3.txt Normal file
View File

@ -0,0 +1,35 @@
P7_REQFILE(3)
=============
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
p7_reqfile - Request a file from the calculator
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
int p7_reqfile(FILE *file, char *dirname, char *filename, char *devname);
FILE *fp = fopen("myaddin.g1a", "w");
p7_reqfile(fp, NULL, "myaddin.g1a", "fls0");
----
DESCRIPTION
-----------
p7_reqfile requests a file from the calculator and writes its content into the
given file stream. File stream *must* be writable.
If directory name is NULL, file will be put at root.
SEE ALSO
--------
*libp7*(3),
*p7_sendfile*(3),
*p7_error*(3)

41
doc/p7_sendfile.3.txt Normal file
View File

@ -0,0 +1,41 @@
P7_SENDFILE(3)
==============
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
p7_sendfile - Send a file to the calculator
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
int p7_sendfile(FILE *file, char *dirname, char *filename, char *devname,
int overwrite, int (*ow_conf)(void));
FILE *fp = fopen("myaddin.g1a", "r");
p7_sendfile(fp, "dir", "myaddin.g1a", "fls0", 1, NULL);
----
DESCRIPTION
-----------
p7_sendfile sends a file stream to the calculator. File stream *must* be
seekable and readable.
If directory name is NULL, file will be put at root.
In case the file exists on the calculator :
- if "ow_conf" is not NULL, the function will be called. If it returns 0, then
the file is not overwritten, otherwise, it is.
- if it is, then "overwrite" will be interpreted as the response of ow_conf.
SEE ALSO
--------
*libp7*(3),
*p7_reqfile*(3),
*p7_error*(3)