Skip to content

Commit

Permalink
Add CMake support; MSPACK_ERROR() to mspack API
Browse files Browse the repository at this point in the history
Adds CMake tooling for libmspack to the project.
This attempts to replicate every feature available in the autotools
tooling and includes support for building on Windows.

Adds a mspack-version.h header file, generated from mspack-version.h.in.
mspack-version.h is to be installed alongside mspack.h so that application
developers can use the version numbers and strings in the event that the API
is modified and the application must maintain backwards compatibility.

Adds error handling to autogen.sh.

Reformats libmspack's README as Markdown.

Adds mspack_error_msg() and MSPACK_ERROR() macro to mspack.h API.
The new API is a cross between the cab_error() function previously found
in cabextract and error_msg() found in test/error.h.  This removes the
need the examples to depend on test/error.h, a header not exported by
any build target, and removes the code duplication with cabextract.

Fixes __func__ macro for Windows.
  • Loading branch information
micahsnyder committed Mar 9, 2020
1 parent c0d1d2d commit 752c94c
Show file tree
Hide file tree
Showing 78 changed files with 2,533 additions and 273 deletions.
6 changes: 5 additions & 1 deletion cabextract/autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
# Runs the autoreconf tool, creating the configure script

autoreconf -i -W all
echo you can now run ./configure
rc=$?; if [[ $rc != 0 ]]; then
echo "Error: Failed to generate autojunk!"; exit $rc
else
echo "You can now run ./configure"
fi
2 changes: 1 addition & 1 deletion cabextract/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#endif

#ifdef HAVE_CONFIG_H
# include <config.h>
# include "config.h"
#endif

#if !defined __STDC__ || !__STDC__
Expand Down
2 changes: 1 addition & 1 deletion cabextract/getopt1.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Boston, MA 02111-1307, USA. */

#ifdef HAVE_CONFIG_H
#include <config.h>
#include "config.h"
#endif

#include "getopt.h"
Expand Down
4 changes: 2 additions & 2 deletions cabextract/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */

#ifdef HAVE_CONFIG_H
# include <config.h>
# include "config.h"
#endif

#include <sys/types.h>
#include <stdlib.h>
#include <string.h>

#include <md5.h>
#include "md5.h"

#ifdef _LIBC
# include <endian.h>
Expand Down
54 changes: 13 additions & 41 deletions cabextract/src/cabextract.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define _GNU_SOURCE 1

#if HAVE_CONFIG_H
# include <config.h>
# include "config.h"
#endif

#include <sys/types.h>
Expand Down Expand Up @@ -76,8 +76,12 @@

#include "getopt.h"

#include <mspack.h>
#include <md5.h>
#include "mspack.h"
#include "md5.h"

#if !defined(S_ISDIR)
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#endif

/* structures and global variables */
struct option optlist[] = {
Expand Down Expand Up @@ -184,7 +188,6 @@ static void forget_files(struct file_mem **fml);
static void add_filter(char *arg);
static void free_filters();
static int ensure_filepath(char *path);
static char *cab_error(struct mscab_decompressor *cd);

static struct mspack_file *cabx_open(struct mspack_system *this,
const char *filename, int mode);
Expand Down Expand Up @@ -409,7 +412,7 @@ static int process_cabinet(char *basename) {
/* search the file for cabinets */
if (!(basecab = cabd->search(cabd, basename))) {
if (cabd->last_error(cabd)) {
fprintf(stderr, "%s: %s\n", basename, cab_error(cabd));
fprintf(stderr, "%s: %s\n", basename, MSPACK_ERROR(cabd));
}
else {
fprintf(stderr, "%s: no valid cabinets found\n", basename);
Expand Down Expand Up @@ -489,7 +492,7 @@ static int process_cabinet(char *basename) {
else if (args.test) {
if (cabd->extract(cabd, file, TEST_FNAME)) {
/* file failed to extract */
printf(" %s failed (%s)\n", name, cab_error(cabd));
printf(" %s failed (%s)\n", name, MSPACK_ERROR(cabd));
errors++;
}
else {
Expand All @@ -516,7 +519,7 @@ static int process_cabinet(char *basename) {
/* extracting to stdout */
if (cabd->extract(cabd, file, STDOUT_FNAME)) {
fprintf(stderr, "%s(%s): %s\n", STDOUT_FNAME, name,
cab_error(cabd));
MSPACK_ERROR(cabd));
errors++;
}
}
Expand All @@ -530,7 +533,7 @@ static int process_cabinet(char *basename) {
}
else {
if (cabd->extract(cabd, file, name)) {
fprintf(stderr, "%s: %s\n", name, cab_error(cabd));
fprintf(stderr, "%s: %s\n", name, MSPACK_ERROR(cabd));
errors++;
}
else {
Expand Down Expand Up @@ -580,7 +583,7 @@ static void load_spanning_cabinets(struct mscabd_cabinet *basecab,
}
if (!(cab2 = cabd->open(cabd,name)) || cabd->prepend(cabd, cab, cab2)) {
fprintf(stderr, "%s: can't prepend %s: %s\n", basename,
cab->prevname, cab_error(cabd));
cab->prevname, MSPACK_ERROR(cabd));
if (cab2) cabd->close(cabd, cab2);
break;
}
Expand All @@ -600,7 +603,7 @@ static void load_spanning_cabinets(struct mscabd_cabinet *basecab,
}
if (!(cab2 = cabd->open(cabd,name)) || cabd->append(cabd, cab, cab2)) {
fprintf(stderr, "%s: can't append %s: %s\n", basename,
cab->nextname, cab_error(cabd));
cab->nextname, MSPACK_ERROR(cabd));
if (cab2) cabd->close(cabd, cab2);
break;
}
Expand Down Expand Up @@ -1136,37 +1139,6 @@ static int ensure_filepath(char *path) {
return 1;
}

/**
* Returns a string with an error message appropriate for the last error
* of the CAB decompressor.
*
* @param cd the CAB decompressor.
* @return a constant string with an appropriate error message.
*/
static char *cab_error(struct mscab_decompressor *cd) {
switch (cd->last_error(cd)) {
case MSPACK_ERR_OPEN:
return errno ? strerror(errno) : "file open error";
case MSPACK_ERR_READ:
return errno ? strerror(errno) : "file read error";
case MSPACK_ERR_WRITE:
return errno ? strerror(errno) : "file write error";
case MSPACK_ERR_SEEK:
return errno ? strerror(errno) : "file seek error";
case MSPACK_ERR_NOMEMORY:
return "out of memory";
case MSPACK_ERR_SIGNATURE:
return "bad CAB signature";
case MSPACK_ERR_DATAFORMAT:
return "error in CAB data format";
case MSPACK_ERR_CHECKSUM:
return "checksum error";
case MSPACK_ERR_DECRUNCH:
return "decompression error";
}
return "unknown error";
}

struct mspack_file_p {
FILE *fh;
const char *name;
Expand Down
6 changes: 3 additions & 3 deletions cabextract/src/cabinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

/* include <system.h> from libmspack for LD and EndGetI?? macros */
#include <mspack/system.h>
#include "mspack/system.h"
/* include <cab.h> from libmspack for cab structure offsets */
#include <mspack/cab.h>
#include "mspack/cab.h"

#if HAVE_FSEEKO
# define FSEEK fseeko
Expand Down
116 changes: 97 additions & 19 deletions libmspack/.gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,100 @@
# Logs
*.log

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake

# http://www.gnu.org/software/automake
.deps
.dirstamp
.libs
INSTALL
/Makefile
Makefile.in
aclocal.m4
ar-lib
/ar-lib
/mdate-sh
/py-compile
/test-driver
/ylwrap

# http://www.gnu.org/software/autoconf
autom4te.cache
compile
config.*
configure
depcomp
install-sh
lib*.la
libmspack-*.tar.gz
libmspack.pc
libtool
ltmain.sh
m4
missing
stamp-h1
test-driver
test-suite.log
/autoscan.log
/autoscan-*.log
/aclocal.m4
/compile
/config.guess
/config.h.in
/config.log
/config.status
/config.sub
/configure
/configure.scan
/depcomp
/install-sh
/missing
/stamp-h1

# https://www.gnu.org/software/libtool/
/ltmain.sh

# http://www.gnu.org/software/texinfo
/texinfo.tex

# http://www.gnu.org/software/m4/
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
Loading

0 comments on commit 752c94c

Please sign in to comment.