Skip to content

Commit 546e3a6

Browse files
committed
Make mspack/system.h private, move useful macros to mspack/macros.h
1 parent c0d1d2d commit 546e3a6

File tree

11 files changed

+84
-60
lines changed

11 files changed

+84
-60
lines changed

cabextract/mspack/macros.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../libmspack/mspack/macros.h

cabextract/src/cabinfo.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@
2424
#include <string.h>
2525
#include <sys/types.h>
2626

27-
/* include <system.h> from libmspack for LD and EndGetI?? macros */
28-
#include <mspack/system.h>
29-
/* include <cab.h> from libmspack for cab structure offsets */
30-
#include <mspack/cab.h>
27+
/* include some headers from the cut-down copy of libmspack
28+
* - mspack.h for MSCAB_ATTRIB_?? defines
29+
* - macros.h for LD and EndGetI?? macros
30+
* - cab.h for cab structure offsets
31+
* cabinfo does not use the system-wide <mspack.h> nor does it
32+
* link with any libmspack functions. It's a standalone program.
33+
*/
34+
#include "mspack/mspack.h"
35+
#include "mspack/macros.h"
36+
#include "mspack/cab.h"
3137

3238
#if HAVE_FSEEKO
3339
# define FSEEK fseeko

libmspack/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-04-13 Stuart Caie <[email protected]>
2+
3+
* macros.h: new header for the D(), LD/LU and EndGet???() macros.
4+
Use this instead of system.h.
5+
16
2020-01-08 Stuart Caie <[email protected]>
27

38
* lzxd_decompress(): do not apply the E8 transformation on the

libmspack/examples/cabrip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdlib.h>
77
#include <sys/stat.h>
88
#include <mspack.h>
9-
#include <system.h>
9+
#include "mspack/macros.h"
1010

1111
#if HAVE_FSEEKO
1212
# define fseek fseeko

libmspack/mspack/macros.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* This file is part of libmspack.
2+
* (C) 2003-2020 Stuart Caie.
3+
*
4+
* libmspack is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU Lesser General Public License (LGPL) version 2.1
6+
*
7+
* For further details, see the file COPYING.LIB distributed with libmspack
8+
*/
9+
10+
#ifndef MSPACK_MACROS_H
11+
#define MSPACK_MACROS_H 1
12+
13+
/* define LD and LU as printf-format for signed and unsigned long offsets */
14+
#if HAVE_INTTYPES_H
15+
# include <inttypes.h>
16+
#else
17+
# define PRId64 "lld"
18+
# define PRIu64 "llu"
19+
# define PRId32 "ld"
20+
# define PRIu32 "lu"
21+
#endif
22+
23+
#if SIZEOF_OFF_T >= 8
24+
# define LD PRId64
25+
# define LU PRIu64
26+
#else
27+
# define LD PRId32
28+
# define LU PRIu32
29+
#endif
30+
31+
/* endian-neutral reading of little-endian data */
32+
#define __egi32(a,n) (((unsigned int) ((unsigned char *)(a))[n+3] << 24) | \
33+
((unsigned int) ((unsigned char *)(a))[n+2] << 16) | \
34+
((unsigned int) ((unsigned char *)(a))[n+1] << 8) | \
35+
((unsigned int) ((unsigned char *)(a))[n]))
36+
#define EndGetI64(a) (((unsigned long long int) __egi32(a,4) << 32) | __egi32(a,0))
37+
#define EndGetI32(a) __egi32(a,0)
38+
#define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
39+
40+
/* endian-neutral reading of big-endian data */
41+
#define EndGetM32(a) (((unsigned int) ((unsigned char *)(a))[0] << 24) | \
42+
((unsigned int) ((unsigned char *)(a))[1] << 16) | \
43+
((unsigned int) ((unsigned char *)(a))[2] << 8) | \
44+
((unsigned int) ((unsigned char *)(a))[3]))
45+
#define EndGetM16(a) ((((a)[0])<<8)|((a)[1]))
46+
47+
/* D(("formatstring", args)) prints debug messages if DEBUG defined */
48+
#if DEBUG
49+
/* http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html */
50+
# if __STDC_VERSION__ < 199901L
51+
# if __GNUC__ >= 2
52+
# define __func__ __FUNCTION__
53+
# else
54+
# define __func__ "<unknown>"
55+
# endif
56+
# endif
57+
# include <stdio.h>
58+
# define D(x) do { printf("%s:%d (%s) ",__FILE__, __LINE__, __func__); \
59+
printf x ; fputc('\n', stdout); fflush(stdout);} while (0);
60+
#else
61+
# define D(x)
62+
#endif
63+
64+
#endif

libmspack/mspack/system.h

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ extern "C" {
1818
#ifdef HAVE_CONFIG_H
1919
# include <config.h>
2020
#endif
21-
2221
#include <mspack.h>
22+
#include <macros.h>
2323

2424
/* assume <string.h> exists */
2525
#include <string.h>
@@ -31,71 +31,23 @@ extern "C" {
3131
# undef read
3232
#endif
3333

34-
/* Old GCCs don't have __func__, but __FUNCTION__:
35-
* http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html
36-
*/
37-
#if __STDC_VERSION__ < 199901L
38-
# if __GNUC__ >= 2
39-
# define __func__ __FUNCTION__
40-
# else
41-
# define __func__ "<unknown>"
42-
# endif
43-
#endif
44-
45-
#if DEBUG
46-
# include <stdio.h>
47-
# define D(x) do { printf("%s:%d (%s) ",__FILE__, __LINE__, __func__); \
48-
printf x ; fputc('\n', stdout); fflush(stdout);} while (0);
49-
#else
50-
# define D(x)
51-
#endif
52-
5334
/* CAB supports searching through files over 4GB in size, and the CHM file
5435
* format actively uses 64-bit offsets. These can only be fully supported
5536
* if the system the code runs on supports large files. If not, the library
5637
* will work as normal using only 32-bit arithmetic, but if an offset
5738
* greater than 2GB is detected, an error message indicating the library
5839
* can't support the file should be printed.
5940
*/
60-
#if HAVE_INTTYPES_H
61-
# include <inttypes.h>
62-
#else
63-
# define PRId64 "lld"
64-
# define PRIu64 "llu"
65-
# define PRId32 "ld"
66-
# define PRIu32 "lu"
67-
#endif
68-
6941
#include <limits.h>
7042
#if ((defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS >= 64) || \
7143
(defined(FILESIZEBITS) && FILESIZEBITS >= 64) || \
7244
defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE) || \
7345
SIZEOF_OFF_T >= 8)
7446
# define LARGEFILE_SUPPORT 1
75-
# define LD PRId64
76-
# define LU PRIu64
7747
#else
7848
extern const char *largefile_msg;
79-
# define LD PRId32
80-
# define LU PRIu32
8149
#endif
8250

83-
/* endian-neutral reading of little-endian data */
84-
#define __egi32(a,n) (((unsigned int) ((unsigned char *)(a))[n+3] << 24) | \
85-
((unsigned int) ((unsigned char *)(a))[n+2] << 16) | \
86-
((unsigned int) ((unsigned char *)(a))[n+1] << 8) | \
87-
((unsigned int) ((unsigned char *)(a))[n]))
88-
#define EndGetI64(a) (((unsigned long long int) __egi32(a,4) << 32) | __egi32(a,0))
89-
#define EndGetI32(a) __egi32(a,0)
90-
#define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
91-
92-
/* endian-neutral reading of big-endian data */
93-
#define EndGetM32(a) (((unsigned int) ((unsigned char *)(a))[0] << 24) | \
94-
((unsigned int) ((unsigned char *)(a))[1] << 16) | \
95-
((unsigned int) ((unsigned char *)(a))[2] << 8) | \
96-
((unsigned int) ((unsigned char *)(a))[3]))
97-
#define EndGetM16(a) ((((a)[0])<<8)|((a)[1]))
98-
9951
extern struct mspack_system *mspack_default_system;
10052

10153
/* returns the length of a file opened for reading */

libmspack/test/cabd_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <stdlib.h>
99
#include <string.h>
1010
#include <mspack.h>
11-
#include <system.h>
1211

1312
#define __tf3(x) #x
1413
#define __tf2(x) __tf3(x)

libmspack/test/chmd_find.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
#include <stdlib.h>
99
#include <string.h>
1010
#include <mspack.h>
11-
11+
#include "mspack/macros.h"
1212
#include <error.h>
13-
#include <system.h>
1413

1514
void find(struct mschm_decompressor *chmd, struct mschmd_header *chm,
1615
char *archive, char *filename, struct mschmd_file *compare)

libmspack/test/chmd_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <unistd.h>
1111

1212
#include <mspack.h>
13-
#include <system.h>
1413

1514
#define __tf3(x) #x
1615
#define __tf2(x) __tf3(x)

libmspack/test/chminfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <string.h>
99

1010
#include <mspack.h>
11-
#include <system.h>
11+
#include "mspack/macros.h"
1212

1313
#define FILENAME ".chminfo-temp"
1414

libmspack/test/kwajd_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <stdlib.h>
99
#include <string.h>
1010
#include <mspack.h>
11-
#include <system.h>
1211

1312
#define __tf3(x) #x
1413
#define __tf2(x) __tf3(x)

0 commit comments

Comments
 (0)