Split misc.c into two files
[deark.git] / src / deark.h
blob6c218292eab7290ea2093597517aaaca54649575
1 // This file is part of Deark.
2 // Copyright (C) 2016-2017 Jason Summers
3 // See the file COPYING for terms of use.
5 // Definitions visible to everything.
7 #ifdef DEARK_H_INC
8 #error "deark.h included multiple times"
9 #endif
10 #define DEARK_H_INC
12 #ifndef DEARK_CONFIG_H_INC
13 // .c files that don't need any non-default system headers don't have to
14 // explicitly #include deark-config.h.
15 #include "deark-config.h"
16 #endif
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdarg.h>
22 #if !DE_USE_WINDOWS_INTTYPES
23 #include <inttypes.h>
24 #endif
26 #ifdef DE_USE_CONFIG2_H
27 #include "deark-config2.h"
28 #else
29 // In-line default deark-config2.h:
31 #ifdef _MSC_VER
32 #pragma warning(error:4013) // Calling undeclared function = error
33 #endif
35 #ifdef __GNUC__
36 #define de_gnuc_attribute __attribute__
37 #endif
39 #endif
41 #ifndef de_gnuc_attribute
42 #define de_gnuc_attribute(x)
43 #endif
45 #if DE_USE_WINDOWS_INTTYPES
47 #define i64 __int64
48 #define u64 unsigned __int64
49 #define i32 int
50 #define u32 unsigned int
51 #define i16 short
52 #define u16 unsigned short
53 #define u8 unsigned char
54 #define I64_FMT "I64d"
55 #define U64_FMT "I64u"
56 #define U64_FMTx "I64x"
57 #define U64_FMTo "I64o"
59 #else
61 #define i64 int64_t
62 #define u64 uint64_t
63 #define i32 int32_t
64 #define u32 uint32_t
65 #define i16 int16_t
66 #define u16 uint16_t
67 #define u8 unsigned char
68 #define I64_FMT PRId64
69 #define U64_FMT PRIu64
70 #define U64_FMTx PRIx64
71 #define U64_FMTo PRIo64
73 #endif
75 // UI = unsigned int (%u format). It will not be redefined.
76 #define UI unsigned int
78 #define DE_CHAR_TIMES "\xc3\x97"
79 #define DE_CHAR_RIGHTARROW "\xe2\x86\x92"
80 #define DE_CHAR_LEQ "\xe2\x89\xa4"
81 #define DE_CHAR_GEQ "\xe2\x89\xa5"
83 struct deark_struct;
84 typedef struct deark_struct deark;
86 char *de_get_version_string(char *buf, size_t bufsize);
87 unsigned int de_get_version_int(void);
88 void de_exitprocess(int s);
90 void *de_malloc(deark *c, i64 n);
91 void *de_mallocarray(deark *c, i64 nmemb, size_t membsize);
92 void *de_realloc(deark *c, void *m, i64 oldsize, i64 newsize);
93 void *de_reallocarray(deark *c, void *m, i64 oldnmemb, size_t membsize,
94 i64 newnmemb);
95 void de_free(deark *c, void *m);
96 char *de_strdup(deark *c, const char *s);
97 int de_atoi(const char *string);
98 i64 de_strtoll(const char *string, char **endptr, int base);
99 i64 de_atoi64(const char *string);
100 int de_strcasecmp(const char *a, const char *b);
101 int de_strncasecmp(const char *a, const char *b, size_t n);
102 void de_vsnprintf(char *buf, size_t buflen, const char *fmt, va_list ap);
103 void de_snprintf(char *buf, size_t buflen, const char *fmt, ...)
104 de_gnuc_attribute ((format (printf, 3, 4)));
106 // Used with de_stdoptions_enum::DE_STDOPT_EXTRACT_POLICY
107 #define DE_EXTRACTPOLICY_DEFAULT 0
108 #define DE_EXTRACTPOLICY_MAINONLY 1
109 #define DE_EXTRACTPOLICY_AUXONLY 2
111 // Used with de_stdoptions_enum::DE_STDOPT_OVERWRITE_MODE
112 #define DE_OVERWRITEMODE_DEFAULT 0
113 #define DE_OVERWRITEMODE_NEVER 1
114 #define DE_OVERWRITEMODE_STANDARD 2
116 #define DE_MSGTYPE_MESSAGE 0U
117 #define DE_MSGTYPE_WARNING 1U
118 #define DE_MSGTYPE_ERROR 2U
119 #define DE_MSGTYPE_DEBUG 3U
120 // The low bits of 'flags' are the message type.
121 typedef void (*de_msgfn_type)(deark *c, unsigned int flags, const char *s);
123 #define DE_MSGCODE_HL 0x1000U
124 #define DE_MSGCODE_UNHL 0x1100U
125 #define DE_MSGCODE_RGBSAMPLE 0x2000U
126 typedef void (*de_specialmsgfn_type)(deark *c, unsigned int flags, unsigned int code,
127 u32 param1);
129 typedef void (*de_fatalerrorfn_type)(deark *c);
131 // Used by de_set_output_style()
132 #define DE_OUTPUTSTYLE_DIRECT 0
133 #define DE_OUTPUTSTYLE_ARCHIVE 1
134 #define DE_OUTPUTSTYLE_STDOUT 2
135 #define DE_ARCHIVEFMT_ZIP 1
136 #define DE_ARCHIVEFMT_TAR 2
138 void de_puts(deark *c, unsigned int flags, const char *s);
139 void de_printf(deark *c, unsigned int flags, const char *fmt, ...)
140 de_gnuc_attribute ((format (printf, 3, 4)));
142 void de_utf8_to_ascii(const char *src, char *dst, size_t dstlen, unsigned int flags);