cake
/
libp7
Archived
1
0
Fork 1

Corrected quirks and added MS-Windows cross-compilation utilities

This commit is contained in:
Thomas Touhey 2016-12-21 16:30:08 +01:00
parent b413c75a47
commit 037f3cb59a
42 changed files with 381 additions and 136 deletions

View File

@ -2,8 +2,7 @@
#******************************************************************************#
# Include variables and message subsystem #
#******************************************************************************#
include Makefile.vars
include Makefile.msg
include Makefile.vars Makefile.msg
#******************************************************************************#
# General targets #
@ -13,11 +12,11 @@ all: all-lib all-doc
# Mostly clean everything (remove everything but the end results).
mostlyclean: mostlyclean-lib mostlyclean-doc
mclean: mostlyclean
mclean: mostlyclean
# Clean everything.
clean: clean-lib clean-doc
fclean: clean
fclean: clean
# To original state.
mrproper: clean
@ -28,10 +27,11 @@ mrproper: clean
re: clean all
# Install everything.
install: install-lib $(if $(INSTALL_MANPAGES),install-doc)
install: install-lib $(if $(INSTALL_MANPAGES),install-doc) \
$(if $(INSTALL_DEVEL),install-cfgtool)
# Uninstall everything. (experimental)
uninstall: uninstall-lib uninstall-doc
uninstall: uninstall-lib uninstall-doc uninstall-cfgtool
# Reinstall everything. (experimental)
reinstall: uninstall install
@ -81,7 +81,7 @@ reinstall: uninstall install
# Library-specific targets #
#******************************************************************************#
# Make the library.
all-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR)
all-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR)
# Make a module object directory.
$(MODULES:%=$(OBJDIR)/%):
@ -100,30 +100,30 @@ $(eval $(call make-moduleobj-rule,$(mod))))
$(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS))
# Remove the objects directory.
mostlyclean-lib:
mostlyclean-lib:
$(call rmsg,Removing object directory.)
$(call qcmd,$(RM) -r $(OBJDIR))
mclean-lib: mostlyclean-lib
mclean-lib: mostlyclean-lib
# Clean and remove the built library.
clean-lib: mclean-lib
clean-lib: mclean-lib
$(call rmsg,Removing the library.)
$(call qcmd,$(RM) lib$(NAME).so.$(MAJOR))
# Remake the library.
re-lib: clean-lib all-lib
re-lib: clean-lib all-lib
# Install the library and development files.
install-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR)
LINK_TO_MAJOR := $(if $(INSTALL_DEVEL),$(if $(FOR_WINDOWS),,y))
install-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR)
$(call imsg,Installing the library.)
$(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)")
$(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" lib$(NAME).so.$(MAJOR))
$(if $(INSTALL_DEVEL),\
$(if $(LINK_TO_MAJOR),\
$(call imsg,Linking lib$(NAME).so to lib$(NAME).so.$(MAJOR).))
$(if $(INSTALL_DEVEL),\
$(call qcmd,$(LN) lib$(NAME).so.$(MAJOR) \
"$(ILIBDIR)/lib$(NAME).so"))
$(if $(LINK_TO_MAJOR),\
$(call qcmd,$(LN) lib$(NAME).so.$(MAJOR) "$(ILIBDIR)/lib$(NAME).so"))
$(if $(INSTALL_DEVEL),\
$(call imsg,Installing development files.))
@ -134,7 +134,7 @@ install-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR)
$(call qcmd,$(INST) -m 644 $(INCDIR)/$(i).h "$(IINCDIR)/$(i).h"$(\n))))
# Uninstall the library and development files. (experimental)
uninstall-lib: $(CHECKCFG)
uninstall-lib: $(CHECKCFG)
$(call rmsg,Uninstalling the library.)
$(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).a" "$(ILIBDIR)/lib$(NAME).so"*)
$(call rmsg,Uninstalling development files.)
@ -144,10 +144,39 @@ uninstall-lib: $(CHECKCFG)
.PHONY: all-lib mostlyclean-lib mclean-lib clean-lib re-lib
.PHONY: install-lib uninstall-lib
#******************************************************************************#
# Configuration tools-related #
#******************************************************************************#
# Install it.
install-cfgtool: $(CHECKCFG)
$(call imsg,Installing the configuration tool.)
$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")
$(call qcmd,tools/write-config \
--name=lib$(NAME) --version=$(VERSION) \
--author-name="$(AUTHOR)" --author-mail="$(AUTHOR_MAIL)" \
--incdir="$(OIINCDIR)" --libdir="$(OILIBDIR)" \
>"$(IBINDIR)/lib$(NAME)-config" \
&& chmod 755 "$(IBINDIR)/lib$(NAME)-config")
$(call imsg,Installing the pkg-config configuration.)
$(call qcmd,$(INST) -m 755 -d "$(IPKGDIR)")
$(call qcmd,tools/write-pkg-config \
--name=$(NAME) --version=$(VERSION) \
--description="$(DESCRIPTION)" \
--incdir="$(OIINCDIR)" --libdir="$(OILIBDIR)" \
>"$(IPKGDIR)/lib$(NAME).pc" \
&& chmod 644 "$(IPKGDIR)/lib$(NAME).pc")
# Uninstall it
uninstall-cfgtool: $(CHECKCFG)
$(call rmsg,Uninstalling configuration tool and package.)
$(call qcmd,$(RM) "$(IBINDIR)/lib$(NAME)-config" "$(IPKGDIR)/lib$(NAME).pc")
.PHONY: install-cfgtool uninstall-cfgtool
#******************************************************************************#
# Documentation-related #
#******************************************************************************#
# Make all manpages.
all-doc: $(foreach s,$(MAN_SECTIONS), $(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
all-doc: $(foreach s,$(MAN_SECTIONS), $(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
# Make manpages directories.
$(MAN_SECTIONS:%=$(MANDIR)/man%):
@ -162,17 +191,17 @@ $(foreach section, $(MAN_SECTIONS), \
$(eval $(call make-manpage-rule,$(section))))
# Mostly clean (do nothing, really)
mostlyclean-doc:
mclean-doc: mostlyclean-doc
mostlyclean-doc:
mclean-doc: mostlyclean-doc
# Remove all built manpages.
clean-doc:
clean-doc:
$(call rmsg,Removing manpages directory.)
$(call qcmd,$(RM) -r $(MANDIR))
# Remake all manpages.
# (I don't really know why some people would want to do that though)
re-doc: clean-doc all-doc
re-doc: clean-doc all-doc
# Install a manpages section.
define make-installmansection-rule
@ -187,7 +216,7 @@ $(foreach section, $(MAN_SECTIONS), \
$(eval $(call make-installmansection-rule,$(section))))
# Install manpages.
install-doc: $(CHECKCFG) $(MAN_SECTIONS:%=install-doc-%)
install-doc: $(CHECKCFG) $(MAN_SECTIONS:%=install-doc-%)
# Clean a manpages section.
define make-uninstall-doc-rule
@ -200,7 +229,7 @@ $(foreach sec,$(MAN_SECTIONS), \
$(eval $(call make-uninstall-doc-rule,$(sec))))
# Uninstall manpages
uninstall-doc: $(CHECKCFG) $(MAN_SECTIONS:%=uninstall-doc-%)
uninstall-doc: $(CHECKCFG) $(MAN_SECTIONS:%=uninstall-doc-%)
.PHONY: all-doc mostlyclean-doc mclean-doc clean-doc re-doc
.PHONY: install-doc uninstall-doc

View File

@ -42,16 +42,6 @@ define bcmd
$(call cmd,$1,$2,$3,$(color_green))
endef
# Remove command
define rcmd
$(call cmd,rm,$1,$2,$(color_red))
endef
# Install command
define icmd
$(call cmd,install,$1,$2,$(color_yellow))
endef
#******************************************************************************#
# Messages #
#******************************************************************************#
@ -64,3 +54,5 @@ endef
define imsg
$(call msg,$1,$(color_yellow))
endef
# End of file

View File

@ -2,13 +2,21 @@
#******************************************************************************#
# Include configuration #
#******************************************************************************#
# Do it
-include Makefile.cfg
# Correct target
TARGET := $(if $(TARGET),$(TARGET)-)
# Check if it is for MS-Windows (damn son)
FOR_WINDOWS := $(if $(findstring mingw,$(TARGET)),y)
#******************************************************************************#
# Project main information #
#******************************************************************************#
# Project name
NAME := p7
DESCRIPTION := Library for communicating with CASIO calculators
# Author information
AUTHOR := Thomas \"Cakeisalie5\" Touhey
@ -41,11 +49,21 @@
# Manpages directory - where the manpages will be put.
MANDIR := ./man
#******************************************************************************#
# Object names #
#******************************************************************************#
# Dynamic library name
SONAME := $(if $(FOR_WINDOWS),lib$(NAME).dll,lib$(NAME).so.$(MAJOR))
SONAMES := $(if $(FOR_WINDOWS),lib$(NAME).dll,lib$(NAME).so.*)
#******************************************************************************#
# Binary utilities #
#******************************************************************************#
# Package configuration
PKGCONFIG := $(TARGET)pkg-config
# C Compiler
CC := gcc
CC := $(TARGET)gcc
# - Check flags (for warnings enabling)
CWARN := -Wall -Wextra -Wno-unused-macros -Wno-vla
# - More flags (for profiling, ...)
@ -62,20 +80,25 @@ endif
-D LOGLEVEL="ll_$(LOG_LEVEL)" -D INIT_TRIES="$(INIT_TRIES)" \
-D AUTHOR="$(AUTHOR)" -D AUTHOR_MAIL="$(AUTHOR_MAIL)" \
-D LICENSE="$(LICENSE)" -D VERSION="$(VERSION)" \
$(shell $(PKGCONFIG) --cflags libusb-1.0 2>/dev/null) \
$(CMOREFLAGS)
# Linker
LD := gcc
# - Linker flags
LDFLAGS := -shared -lusb-1.0 \
LD := $(TARGET)gcc
# - Specific linker flags
LDFLAGS_Windows := -lws2_32
LDFLAGS_Linux := -Wl,-soname,$(SONAME) \
-e __lib$(NAME)_version \
-Wl,-soname,lib$(NAME).so.$(MAJOR) \
-Wl,-z,relro -Wl,-z,combreloc -Wl,-z,defs
# - Linker flags
LDFLAGS := -shared \
$(shell $(PKGCONFIG) --libs libusb-1.0 2>/dev/null) \
$(if $(FOR_WINDOWS),$(LDFLAGS_Windows),$(LDFLAGS_Linux))
# Symbolic link maker
LN := ln -sf
# Directory maker
MD := mkdir -p
# Symbolic link maker
LN := ln -sf
# File remover
RM := rm -f
# Documentation manager (manpages generator)
@ -125,10 +148,15 @@ $(eval $(call check-man,$(patsubst .%,%,$(suffix $(doc))),$(basename $(doc)))))
#******************************************************************************#
# Check for DESTDIR (add as prefix to installation root) #
#******************************************************************************#
# Save original library and include dir.
OIINCDIR := $(IINCDIR)
OILIBDIR := $(ILIBDIR)
# Make it.
define add-dest-dir
$1 = $(DESTDIR)$($1)
endef
$(if $(DESTDIR), $(foreach idir,ILIBDIR IINCDIR IMANDIR UDEVDIR, \
$(if $(DESTDIR), $(foreach idir,IBINDIR ILIBDIR IINCDIR IMANDIR IPKGDIR, \
$(eval $(call add-dest-dir,$(idir)))))
# END OF FILE

33
configure vendored
View File

@ -5,12 +5,17 @@ cd "$(dirname "$0")"
#******************************************************************************#
# Project variables
name="$(make -s getname)"
author="$(make -s getauthor)"
complete_author="$author <$(make -s getmail)>"
version="$(make -s getversion)"
# Author
author_name="$(make -s getauthor)"
author="$author <$(make -s getmail)>"
# Target
target=""
# Platform
platform="$(gcc --print-multiarch)"
platform="$(command -v gcc 1>/dev/null && gcc --print-multiarch)"
platform="$([ "$platform" ] && echo "/$platform")"
# Make options
@ -24,9 +29,11 @@ init_tries=5
# Installation directories
root=''
prefix='${root}/usr'
prefix_set=
bindir='${prefix}/bin'
libdir='${prefix}/lib'"$platform"
includedir='${prefix}/include'"$platform"
pkgdir='${libdir}/pkgconfig'
mandir='${prefix}/share/man'
# Installation options
@ -50,6 +57,7 @@ General options:
--maintainer enable maintainer mode
Build options:
--target=TARGET the target [$target]
--loglevel=LEVEL library log level [$loglevel]
--init-tries=TRIES default number of detection tries [$init_tries]
@ -63,11 +71,12 @@ Installation directories:
Fine tuning of the installation directories:
--bindir=DIR executables [$bindir]
--pkgdir=DIR pkg-config configurations directory [$pkgdir]
--libdir=DIR library files of the linker [$libdir]
--includedir=DIR include files for the compiler [$includedir]
--mandir=DIR man root [$mandir]
Report bugs to ${complete_author}.
Report bugs to ${author}.
EOF
exit 0
}
@ -78,7 +87,7 @@ exit 0
version() {
cat <<EOF
${name} configure script v${version}
Hand-written by ${author}.
Hand-written by ${author_name}.
This configure script is free software.
There is NO warranty; not even for MERCHANTABILITY or
@ -103,6 +112,7 @@ esac; done
# Parse arguments #
#******************************************************************************#
for arg ; do case "$arg" in
--target=*) target="${arg#*=}" ;;
--make-full-log) make_full_log=yes ;;
--maintainer) more_warnings=yes; loglevel=info ;;
--loglevel=*)
@ -131,16 +141,25 @@ got '$level'"
--root=*) root="${arg#*=}" ;;
--prefix=*) prefix="${arg#*=}" ;;
--bindir=*) bindir="${arg#*=}" ;;
--pkgdir=*) pkgdir="${arg#*=}" ;;
--libdir=*) libdir="${arg#*=}" ;;
--includedir=*) includedir="${arg#*=}" ;;
--mandir=*) mandir="${arg#*=}" ;;
*) echo "$arg: didn't read" ;;
esac; done
#******************************************************************************#
# Check for defaults #
#******************************************************************************#
# MS-Windows things
if [ ! $prefix_set ] && [ $(echo $target | grep mingw) ]; then
prefix='${root}/usr/'"$target"
fi
#******************************************************************************#
# Evaluate variables #
#******************************************************************************#
for var in prefix sysconfdir bindir libdir includedir mandir; do
for var in prefix sysconfdir bindir libdir pkgdir includedir mandir; do
eval $var'='$(eval 'echo $'$var)
done
@ -159,11 +178,13 @@ cat <<EOF
MORE_WARNINGS := $more_warnings
# Build options
TARGET := $target
LOG_LEVEL := $loglevel
INIT_TRIES := $init_tries
# Installation directories
IBINDIR := $bindir
IPKGDIR := $pkgdir
ILIBDIR := $libdir
IINCDIR := $includedir
IMANDIR := $mandir

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:36:52 |___/ */
/* */
/* ************************************************************************** */
#ifndef LIBP7_H
# define LIBP7_H
# include <stdint.h>
@ -96,15 +95,15 @@ void p7_exit(p7_handle_t *handle, int term);
/* Send file */
int p7_sendstream(p7_handle_t *handle, FILE *file, p7uint_t size,
const char *dirname, const char *filename, const char *devname,
int overwrite, int (*ow_conf)(void), void (*disp)(p7uint_t, p7uint_t));
int overwrite, int (*ow_conf)(void), void (*disp)(p7ushort_t, p7ushort_t));
int p7_sendfile(p7_handle_t *handle, FILE *file,
const char *dirname, const char *filename, const char *devname,
int overwrite, int (*ow_conf)(void), void (*disp)(p7uint_t, p7uint_t));
int overwrite, int (*ow_conf)(void), void (*disp)(p7ushort_t, p7ushort_t));
/* Request file */
int p7_reqfile(p7_handle_t *handle, FILE *file,
const char *dirname, const char *filename, const char *devname,
void (*disp)(p7uint_t, p7uint_t));
void (*disp)(p7ushort_t, p7ushort_t));
/* Delete distant file */
int p7_delfile(p7_handle_t *handle,

View File

@ -12,7 +12,30 @@
# include <libp7.h>
# include <libp7/packetio.h>
# include <libp7/custom.h>
#include <libusb-1.0/libusb.h>
# include <libp7/internals/stdio_ext.h>
# include <libusb.h>
/* ************************************************************************** */
/* Macros and platform-specific functions */
/* ************************************************************************** */
/* MS-Windows <3 (srsly) */
# if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) \
&& !defined(__WINDOWS__)
# define __WINDOWS__
# endif
/* Macros */
# ifndef min
# define min(A, B) ((A) < (B) ? (A) : (B))
# endif
# ifndef max
# define max(A, B) ((A) > (B) ? (A) : (B))
# endif
/* Platform-specific functions */
# ifdef __WINDOWS__
# define bzero(B, LEN) ((void)memset((B), 0, (LEN)))
# endif
/* ************************************************************************** */
/* Buffer sizes */
@ -147,6 +170,42 @@ int p7_send_check(p7_handle_t *handle);
/* active response */
# define response (*handle->_response)
/* ************************************************************************** */
/* Macros */
/* ************************************************************************** */
/* check if filename is ok */
# define chk_filename(F) \
if (!p7_validate_filename(F)) return (p7_error_filename)
/* check if dirname is ok */
# define chk_dirname(D) \
if ((D) && !p7_validate_dirname(D)) return (p7_error_dirname)
/* check if filestream is readable */
# define chk_isread(F) \
if (!(F) || !__freadable(F)) return (p7_error_noread)
/* check if filestream is writable */
# define chk_iswrite(F) \
if (!(F) || !__fwritable(F)) return (p7_error_nowrite)
/* check if filesize is ok */
# define chk_filesize(S) \
if (!(S)) return (p7_error_empty); \
if ((S) > UINT32_MAX) return (p7_error_fullmem)
/* check if handle is initialized */
# define chk_handle(H) \
if (!(H)) return (p7_error_uninitialized)
/* check if active */
# define chk_active(H) \
if (!(H)->_active) return (p7_error_active)
/* check if passive */
# define chk_passive(H) \
if ((H)->_active) return (p7_error_active)
/* ************************************************************************** */
/* Utilities */
/* ************************************************************************** */

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* _____ _ */
/* libp7/internals/stdio_ext.h |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/12/21 16:07:08 |___/ */
/* */
/* ************************************************************************** */
#ifndef LIBP7_INTERNALS_STDIO_EXT_H
# define LIBP7_INTERNALS_STDIO_EXT_H
/* MS-Windows stuff */
# if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) \
&& !defined(__WINDOWS__)
# define __WINDOWS__
# endif
/* Ever heard of how annoying it is to make something platform-agnostic? */
# if defined(__WINDOWS__)
# define __freadable(F) (1)
# define __fwritable(F) (1)
# else
# include <stdio_ext.h>
# endif
#endif /* LIBP7_INTERNALS_STDIO_EXT_H */

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:36:52 |___/ */
/* */
/* ************************************************************************** */
#ifndef LIBP7_PACKET_H
# define LIBP7_PACKET_H
# define MAX_COMMAND_ARGUMENT_SIZE 32

View File

@ -7,61 +7,23 @@
/* Last updated: 2016/10/13 07:36:52 |___/ */
/* */
/* ************************************************************************** */
#ifndef LIBP7_PACKETIO_H
# define LIBP7_PACKETIO_H
# include <libp7/packet.h>
# include <stdio_ext.h>
# define MAX_RAWDATA_SIZE 256
# ifdef __cplusplus
extern "C" {
# endif
/* ************************************************************************** */
/* Macros */
/* ************************************************************************** */
/* check if filename is ok */
# define chk_filename(F) \
if (!p7_validate_filename(F)) return (p7_error_filename)
/* check if dirname is ok */
# define chk_dirname(D) \
if ((D) && !p7_validate_dirname(D)) return (p7_error_dirname)
/* check if filestream is readable */
# define chk_isread(F) \
if (!(F) || !__freadable(F)) return (p7_error_noread)
/* check if filestream is writable */
# define chk_iswrite(F) \
if (!(F) || !__fwritable(F)) return (p7_error_nowrite)
/* check if filesize is ok */
# define chk_filesize(S) \
if (!(S)) return (p7_error_empty); \
if ((S) > UINT32_MAX) return (p7_error_fullmem)
/* check if handle is initialized */
# define chk_handle(H) \
if (!(H)) return (p7_error_uninitialized)
/* check if active */
# define chk_active(H) \
if (!(H)->_active) return (p7_error_active)
/* check if passive */
# define chk_passive(H) \
if ((H)->_active) return (p7_error_active)
/* ************************************************************************** */
/* Utilities */
/* ************************************************************************** */
/* send some data */
int p7_send_filestream(p7_handle_t *handle, FILE *stream, p7uint_t size,
int shift, void (*disp)(p7uint_t, p7uint_t));
int shift, void (*disp)(p7ushort_t, p7ushort_t));
/* get some data */
int p7_get_filestream(p7_handle_t *handle, FILE *stream, p7uint_t size,
int shift, void (*disp)(p7uint_t, p7uint_t));
int shift, void (*disp)(p7ushort_t, p7ushort_t));
/* ************************************************************************** */
/* Packet sending */

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <string.h>

View File

@ -7,12 +7,10 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define min(A, B) ((A) < (B) ? (A) : (B))
/**
* log_mem_hex:

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <unistd.h>
#define Q(x) #x

View File

@ -8,10 +8,11 @@
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#ifdef __linux__
# include <dirent.h>
# include <unistd.h>
# include <string.h>
# include <errno.h>
/**
* get_hex_from_file:
@ -210,3 +211,30 @@ not_found_yet:
._rstream_close = 1
}));
}
#else
/**
* p7_cinit:
* Initialize libp7 with char device.
*
* @arg handle the handle to create
* @arg active whether to start as active or not
* @arg check if starting as active, send initial check or not
* @arg path path to char device.
* @arg tries number of tries (0 means default).
* @return the error (0 if ok)
*/
int p7_cinit(p7_handle_t **handle, int active, int check,
const char *path, int tries)
{
(void)handle;
(void)active;
(void)check;
(void)path;
(void)tries;
return (p7_error_nocalc);
}
#endif

View File

@ -130,7 +130,10 @@ int p7_read(p7_stream_t *stream, void *dest, size_t size)
if (!recv) switch (errno) {
/* - timeout - */
case EINTR: /* alarm */
case ETIME: case ETIMEDOUT:
case ETIMEDOUT:
#ifdef ETIME
case ETIME:
#endif
log_error("timeout received");
return (p7_error_timeout);
@ -205,7 +208,10 @@ int p7_write(p7_stream_t *stream, const void *data, size_t size)
if (!sent) switch (errno) {
/* - timeout error - */
case EINTR: /* alarm */
case ETIME: case ETIMEDOUT:
case ETIMEDOUT:
#ifdef ETIME
case ETIME:
#endif
log_error("timeout received");
return (p7_error_timeout);

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <stdlib.h>
#include <string.h>

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <stdlib.h>
#include <string.h>

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <string.h>

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <string.h>

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/12/17 22:06:38 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**
@ -33,7 +32,7 @@ int p7_sendstream(p7_handle_t *handle,
FILE *file, p7uint_t size,
const char *dirname, const char *filename, const char *devname,
int overwrite, int (*ow_conf)(void),
void (*disp)(p7uint_t, p7uint_t))
void (*disp)(p7ushort_t, p7ushort_t))
{
int err;
@ -138,7 +137,7 @@ int p7_sendstream(p7_handle_t *handle,
int p7_sendfile(p7_handle_t *handle,
FILE *file, const char *dirname, const char *filename,
const char *devname, int overwrite, int (*ow_conf)(void),
void (*disp)(p7uint_t, p7uint_t))
void (*disp)(p7ushort_t, p7ushort_t))
{
/* check if filestream is seekable */
if (!file) {

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <ctype.h>

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**
@ -21,7 +20,7 @@
* @return the checksum
*/
unsigned int p7_checksum(unsigned char *packet, p7uint_t size)
unsigned int p7_checksum(unsigned char *packet, p7ushort_t size)
{
unsigned int sum = 0;
packet++; size -= 3; /* remove type and checksum fields */

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**

View File

@ -7,11 +7,9 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <stdlib.h>
#include <string.h>
#define min(A, B) ((A) < (B) ? (A) : (B))
/* number of buffers it will read from the file at a time */
#define BUFNUM 1024
@ -28,7 +26,7 @@
*/
int p7_send_filestream(p7_handle_t *handle, FILE *file, p7uint_t size,
int shift, void (*disp)(p7uint_t, p7uint_t))
int shift, void (*disp)(p7ushort_t, p7ushort_t))
{
int err = 0;
@ -112,7 +110,7 @@ fail:
*/
int p7_get_filestream(p7_handle_t *handle, FILE *file, p7uint_t size,
int shift, void (*disp)(p7uint_t, p7uint_t))
int shift, void (*disp)(p7ushort_t, p7ushort_t))
{
int err = 0;

View File

@ -7,7 +7,6 @@
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <ctype.h>

89
tools/write-config Executable file
View File

@ -0,0 +1,89 @@
#!/bin/sh
#******************************************************************************#
# Defaults #
#******************************************************************************#
# Project variables
name="libg1m"
version="<unknown version>"
# Author
author_name="Unknown name"
author_mail="unknown@mail"
# Directories
libdir=''
incdir=''
#******************************************************************************#
# Read arguments #
#******************************************************************************#
for arg ; do case "$arg" in
--name=*) name="${arg#*=}" ;;
--version=*) version="${arg#*=}" ;;
--author-name=*) author_name="${arg#*=}" ;;
--author-mail=*) author_mail="${arg#*=}" ;;
--libdir=*) libdir="${arg#*=}" ;;
--incdir=*) incdir="${arg#*=}" ;;
esac; done
#******************************************************************************#
# Write result #
#******************************************************************************#
cat <<_EOF
#!/bin/sh
cfgtool=\$(basename \$0)
#******************************************************************************#
# Help message #
#******************************************************************************#
usage() {
cat <<EOF
Usage: \$cfgtool [--help] [--version] [--cflags] [--libs]
Report bugs to ${author_name} <${author_mail}>.
EOF
exit 0
}
#******************************************************************************#
# Version message #
#******************************************************************************#
version() {
cat <<EOF
${name} configuration tool v${version}
Written by ${author_name}.
This configuration tool is public domain.
EOF
exit 0
}
#******************************************************************************#
# Check for help and version #
#******************************************************************************#
put_version=
put_help=
for arg ; do case "\$arg" in
--help|-h) put_help=1 ;;
--version|-v) put_version=1 ;;
esac; done
[ \$put_version ] && version
[ \$put_help ] && usage
#******************************************************************************#
# Parse arguments #
#******************************************************************************#
# Defaults
put_cflags=
put_libs=
for arg ; do case "\$arg" in
--cflags) put_cflags=y ;;
--libs) put_libs=y ;;
*) echo "\$arg: did not read" >&2 ;;
esac; done
# Put
[ \$put_cflags ] && echo "-I$incdir"
[ \$put_libs ] && echo "-L$libdir -lg1m"
[ \$put_cflags\$put_libs ] || usage
# End of file
_EOF

37
tools/write-pkg-config Executable file
View File

@ -0,0 +1,37 @@
#!/bin/sh
#******************************************************************************#
# Defaults #
#******************************************************************************#
# Project variables
name="name"
description="my description"
version="<unknown version>"
# Directories
libdir=''
incdir=''
#******************************************************************************#
# Read arguments #
#******************************************************************************#
for arg ; do case "$arg" in
--name=*) name="${arg#*=}" ;;
--description=*) description="${arg#*=}" ;;
--version=*) version="${arg#*=}" ;;
--libdir=*) libdir="${arg#*=}" ;;
--incdir=*) incdir="${arg#*=}" ;;
esac; done
#******************************************************************************#
# Write result #
#******************************************************************************#
cat <<EOF
includedir=$incdir
libdir=$libdir
Name: lib$name
Description: $description
Version: $version
Libs: -L\${libdir} -l$name
Cflags: -I\${includedir}
EOF