Skip to content

Commit 752c94c

Browse files
committed
Add CMake support; MSPACK_ERROR() to mspack API
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.
1 parent c0d1d2d commit 752c94c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2533
-273
lines changed

cabextract/autogen.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
# Runs the autoreconf tool, creating the configure script
33

44
autoreconf -i -W all
5-
echo you can now run ./configure
5+
rc=$?; if [[ $rc != 0 ]]; then
6+
echo "Error: Failed to generate autojunk!"; exit $rc
7+
else
8+
echo "You can now run ./configure"
9+
fi

cabextract/getopt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#endif
2929

3030
#ifdef HAVE_CONFIG_H
31-
# include <config.h>
31+
# include "config.h"
3232
#endif
3333

3434
#if !defined __STDC__ || !__STDC__

cabextract/getopt1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Boston, MA 02111-1307, USA. */
2020

2121
#ifdef HAVE_CONFIG_H
22-
#include <config.h>
22+
#include "config.h"
2323
#endif
2424

2525
#include "getopt.h"

cabextract/md5.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
/* Written by Ulrich Drepper <[email protected]>, 1995. */
2222

2323
#ifdef HAVE_CONFIG_H
24-
# include <config.h>
24+
# include "config.h"
2525
#endif
2626

2727
#include <sys/types.h>
2828
#include <stdlib.h>
2929
#include <string.h>
3030

31-
#include <md5.h>
31+
#include "md5.h"
3232

3333
#ifdef _LIBC
3434
# include <endian.h>

cabextract/src/cabextract.c

+13-41
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define _GNU_SOURCE 1
2424

2525
#if HAVE_CONFIG_H
26-
# include <config.h>
26+
# include "config.h"
2727
#endif
2828

2929
#include <sys/types.h>
@@ -76,8 +76,12 @@
7676

7777
#include "getopt.h"
7878

79-
#include <mspack.h>
80-
#include <md5.h>
79+
#include "mspack.h"
80+
#include "md5.h"
81+
82+
#if !defined(S_ISDIR)
83+
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
84+
#endif
8185

8286
/* structures and global variables */
8387
struct option optlist[] = {
@@ -184,7 +188,6 @@ static void forget_files(struct file_mem **fml);
184188
static void add_filter(char *arg);
185189
static void free_filters();
186190
static int ensure_filepath(char *path);
187-
static char *cab_error(struct mscab_decompressor *cd);
188191

189192
static struct mspack_file *cabx_open(struct mspack_system *this,
190193
const char *filename, int mode);
@@ -409,7 +412,7 @@ static int process_cabinet(char *basename) {
409412
/* search the file for cabinets */
410413
if (!(basecab = cabd->search(cabd, basename))) {
411414
if (cabd->last_error(cabd)) {
412-
fprintf(stderr, "%s: %s\n", basename, cab_error(cabd));
415+
fprintf(stderr, "%s: %s\n", basename, MSPACK_ERROR(cabd));
413416
}
414417
else {
415418
fprintf(stderr, "%s: no valid cabinets found\n", basename);
@@ -489,7 +492,7 @@ static int process_cabinet(char *basename) {
489492
else if (args.test) {
490493
if (cabd->extract(cabd, file, TEST_FNAME)) {
491494
/* file failed to extract */
492-
printf(" %s failed (%s)\n", name, cab_error(cabd));
495+
printf(" %s failed (%s)\n", name, MSPACK_ERROR(cabd));
493496
errors++;
494497
}
495498
else {
@@ -516,7 +519,7 @@ static int process_cabinet(char *basename) {
516519
/* extracting to stdout */
517520
if (cabd->extract(cabd, file, STDOUT_FNAME)) {
518521
fprintf(stderr, "%s(%s): %s\n", STDOUT_FNAME, name,
519-
cab_error(cabd));
522+
MSPACK_ERROR(cabd));
520523
errors++;
521524
}
522525
}
@@ -530,7 +533,7 @@ static int process_cabinet(char *basename) {
530533
}
531534
else {
532535
if (cabd->extract(cabd, file, name)) {
533-
fprintf(stderr, "%s: %s\n", name, cab_error(cabd));
536+
fprintf(stderr, "%s: %s\n", name, MSPACK_ERROR(cabd));
534537
errors++;
535538
}
536539
else {
@@ -580,7 +583,7 @@ static void load_spanning_cabinets(struct mscabd_cabinet *basecab,
580583
}
581584
if (!(cab2 = cabd->open(cabd,name)) || cabd->prepend(cabd, cab, cab2)) {
582585
fprintf(stderr, "%s: can't prepend %s: %s\n", basename,
583-
cab->prevname, cab_error(cabd));
586+
cab->prevname, MSPACK_ERROR(cabd));
584587
if (cab2) cabd->close(cabd, cab2);
585588
break;
586589
}
@@ -600,7 +603,7 @@ static void load_spanning_cabinets(struct mscabd_cabinet *basecab,
600603
}
601604
if (!(cab2 = cabd->open(cabd,name)) || cabd->append(cabd, cab, cab2)) {
602605
fprintf(stderr, "%s: can't append %s: %s\n", basename,
603-
cab->nextname, cab_error(cabd));
606+
cab->nextname, MSPACK_ERROR(cabd));
604607
if (cab2) cabd->close(cabd, cab2);
605608
break;
606609
}
@@ -1136,37 +1139,6 @@ static int ensure_filepath(char *path) {
11361139
return 1;
11371140
}
11381141

1139-
/**
1140-
* Returns a string with an error message appropriate for the last error
1141-
* of the CAB decompressor.
1142-
*
1143-
* @param cd the CAB decompressor.
1144-
* @return a constant string with an appropriate error message.
1145-
*/
1146-
static char *cab_error(struct mscab_decompressor *cd) {
1147-
switch (cd->last_error(cd)) {
1148-
case MSPACK_ERR_OPEN:
1149-
return errno ? strerror(errno) : "file open error";
1150-
case MSPACK_ERR_READ:
1151-
return errno ? strerror(errno) : "file read error";
1152-
case MSPACK_ERR_WRITE:
1153-
return errno ? strerror(errno) : "file write error";
1154-
case MSPACK_ERR_SEEK:
1155-
return errno ? strerror(errno) : "file seek error";
1156-
case MSPACK_ERR_NOMEMORY:
1157-
return "out of memory";
1158-
case MSPACK_ERR_SIGNATURE:
1159-
return "bad CAB signature";
1160-
case MSPACK_ERR_DATAFORMAT:
1161-
return "error in CAB data format";
1162-
case MSPACK_ERR_CHECKSUM:
1163-
return "checksum error";
1164-
case MSPACK_ERR_DECRUNCH:
1165-
return "decompression error";
1166-
}
1167-
return "unknown error";
1168-
}
1169-
11701142
struct mspack_file_p {
11711143
FILE *fh;
11721144
const char *name;

cabextract/src/cabinfo.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
*/
1818

1919
#ifdef HAVE_CONFIG_H
20-
# include <config.h>
20+
# include "config.h"
2121
#endif
2222
#include <stdio.h>
2323
#include <stdlib.h>
2424
#include <string.h>
2525
#include <sys/types.h>
2626

2727
/* include <system.h> from libmspack for LD and EndGetI?? macros */
28-
#include <mspack/system.h>
28+
#include "mspack/system.h"
2929
/* include <cab.h> from libmspack for cab structure offsets */
30-
#include <mspack/cab.h>
30+
#include "mspack/cab.h"
3131

3232
#if HAVE_FSEEKO
3333
# define FSEEK fseeko

libmspack/.gitignore

+97-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,100 @@
1+
# Logs
2+
*.log
3+
4+
# Prerequisites
5+
*.d
6+
7+
# Object files
8+
*.o
9+
*.ko
10+
*.obj
11+
*.elf
12+
13+
# Linker output
14+
*.ilk
15+
*.map
16+
*.exp
17+
18+
# Precompiled Headers
19+
*.gch
20+
*.pch
21+
22+
# Libraries
23+
*.lib
24+
*.a
25+
*.la
26+
*.lo
27+
28+
# Shared objects (inc. Windows DLLs)
29+
*.dll
30+
*.so
31+
*.so.*
32+
*.dylib
33+
34+
# Executables
35+
*.exe
36+
*.out
37+
*.app
38+
*.i*86
39+
*.x86_64
40+
*.hex
41+
42+
# Debug files
43+
*.dSYM/
44+
*.su
45+
*.idb
46+
*.pdb
47+
48+
# CMake
49+
CMakeLists.txt.user
50+
CMakeCache.txt
51+
CMakeFiles
52+
CMakeScripts
53+
Testing
54+
Makefile
55+
cmake_install.cmake
56+
install_manifest.txt
57+
compile_commands.json
58+
CTestTestfile.cmake
59+
60+
# http://www.gnu.org/software/automake
61+
.deps
62+
.dirstamp
163
.libs
2-
INSTALL
3-
/Makefile
464
Makefile.in
5-
aclocal.m4
6-
ar-lib
65+
/ar-lib
66+
/mdate-sh
67+
/py-compile
68+
/test-driver
69+
/ylwrap
70+
71+
# http://www.gnu.org/software/autoconf
772
autom4te.cache
8-
compile
9-
config.*
10-
configure
11-
depcomp
12-
install-sh
13-
lib*.la
14-
libmspack-*.tar.gz
15-
libmspack.pc
16-
libtool
17-
ltmain.sh
18-
m4
19-
missing
20-
stamp-h1
21-
test-driver
22-
test-suite.log
73+
/autoscan.log
74+
/autoscan-*.log
75+
/aclocal.m4
76+
/compile
77+
/config.guess
78+
/config.h.in
79+
/config.log
80+
/config.status
81+
/config.sub
82+
/configure
83+
/configure.scan
84+
/depcomp
85+
/install-sh
86+
/missing
87+
/stamp-h1
88+
89+
# https://www.gnu.org/software/libtool/
90+
/ltmain.sh
91+
92+
# http://www.gnu.org/software/texinfo
93+
/texinfo.tex
94+
95+
# http://www.gnu.org/software/m4/
96+
m4/libtool.m4
97+
m4/ltoptions.m4
98+
m4/ltsugar.m4
99+
m4/ltversion.m4
100+
m4/lt~obsolete.m4

0 commit comments

Comments
 (0)