aboutsummaryrefslogtreecommitdiff
path: root/saga/yslib.h
blob: b5bc464d2c230ceb1d6bbedf63d22aa384294514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2004 The ScummVM project
 *
 * The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */
#ifndef YSLIB_MAIN_H__
#define YSLIB_MAIN_H__

namespace Saga {

enum YS_ERROR_STATES {

	YS_E_SUCCESS = 0,
	YS_E_FAILURE,
	YS_E_MEM
};

enum YS_CONFIRM_STATES {

	YS_CONFIRM_NO = 0,
	YS_CONFIRM_YES,
	YS_CONFIRM_CANCEL
};

/* General purpose quantity-comparison function */
typedef int (YS_COMPARE_FUNC) (const void *, const void *);

/* General-purpose utility macros 
\*------------------------------------------------------------------*/

/* Ignore a parameter (Supress warnings) */
#define YS_IGNORE_PARAM( param ) ( void )( param )

/* Calculate the number of elements in an array */
#define YS_NELEMS( arr ) (( sizeof arr ) / ( sizeof *arr ))

#define YS_DUMMY_DECL		/* C99 permits statements before declarations */

#define YS_REG_FUNC( arr ) YS_DUMMY_DECL
#define YS_FUNC __func__

#define YS_FLEX_ARRAY
#define YS_FLEX_ARRAY_MOD 0

/* Minimum and maximum of two values */
#define YS_MIN(a,b) (((a) < (b)) ? (a) : (b))
#define YS_MAX(a,b) (((a) > (b)) ? (a) : (b))

/* Minimum and maximum of two objects, convert to lvalue */
#define YS_LV_MIN(a,b) (*((a) < (b)) ? &(a) : &(b))
#define YS_LV_MAX(a,b) (*((a) < (b)) ? &(a) : &(b))

#define YS_ABS(n) ((n < 0) ? -n : n)

/* ys_binread.c : Binary input functions (buffer oriented)
\*------------------------------------------------------------------*/

/* #define YS_ASSUME_2S_COMP */

/* Read a 4CC ( Four characater code ) */
void
ys_read_4cc(char *fourcc,
    const unsigned char *data_p, const unsigned char **data_pp);

/* Read 8 bit unsigned integer */
unsigned int ys_read_u8(const unsigned char *, const unsigned char **);

/* Read 8 bit signed integer */
int ys_read_s8(const unsigned char *, const unsigned char **);

/* Read 16 bit unsigned integer, big-endian */
unsigned int ys_read_u16_be(const unsigned char *, const unsigned char **);

/* Read 16 bit unsigned integer, little-endian */
unsigned int ys_read_u16_le(const unsigned char *, const unsigned char **);

/* Read 16 bit signed integer, 2's complement, big-endian */
int ys_read_s16_be(const unsigned char *, const unsigned char **);

/* Read 16 bit signed integer, 2's complement, little-endian */
int ys_read_s16_le(const unsigned char *, const unsigned char **);

/* Read 24 bit unsigned integer, big-endian */
unsigned long ys_read_u24_be(const unsigned char *, const unsigned char **);

/* Read 24 bit unsigned integer, little-endian */
unsigned long ys_read_u24_le(const unsigned char *, const unsigned char **);

/* Read 24 bit signed integer, 2's complement, big-endian */
long ys_read_s24_be(const unsigned char *, const unsigned char **);

/* Read 24 bit signed integer, 2's complement, little-endian */
long ys_read_s24_le(const unsigned char *, const unsigned char **);

/* Read 32 bit unsigned integer, big-endian */
unsigned long ys_read_u32_be(const unsigned char *, const unsigned char **);

/* Read 32 bit unsigned integer, little-endian */
unsigned long ys_read_u32_le(const unsigned char *, const unsigned char **);

/* Read 32 bit signed integer, 2's complement, big-endian */
long ys_read_s32_be(const unsigned char *, const unsigned char **);

/* Read 32 bit signed integer, 2's complement, little-endian */
long ys_read_s32_le(const unsigned char *, const unsigned char **);

/* ys_binwrite.c : Binary output functions ( buffer oriented ) 
\*------------------------------------------------------------------*/

void ys_write_u8(unsigned int, unsigned char *, unsigned char **);

/* Write 16 bit unsigned integer, big-endian */
void ys_write_u16_be(unsigned int, unsigned char *, unsigned char **);

/* Write 16 bit unsigned integer, little-endian */
void ys_write_u16_le(unsigned int, unsigned char *, unsigned char **);

/* Write 16 bit signed integer, 2's complement, big-endian */
void ys_write_s16_be(int, unsigned char *, unsigned char **);

/* Write 16 bit signed integer, 2's complement, little-endian */
void ys_write_s16_le(int, unsigned char *, unsigned char **);

/* Write 24 bit unsigned integer, big-endian */
void ys_write_u24_be(unsigned long, unsigned char *, unsigned char **);

/* Write 24 bit unsigned integer, little-endian */
void ys_write_u24_le(unsigned long, unsigned char *, unsigned char **);

/* Write 24 bit signed integer, 2's complement, big-endian */
void ys_write_s24_be(long, unsigned char *, unsigned char **);

/* Write 24 bit signed integer, 2's complement, little-endian */
void ys_write_s24_le(long, unsigned char *, unsigned char **);

/* Write 32 bit unsigned integer, big-endian */
void ys_write_u32_be(unsigned long, unsigned char *, unsigned char **);

/* Write 32 bit unsigned integer, little-endian */
void ys_write_u32_le(unsigned long, unsigned char *, unsigned char **);

/* Write 32 bit signed integer, 2's complement, big-endian */
void ys_write_s32_be(long, unsigned char *, unsigned char **);

/* Write 32 bit signed integer, 2's complement, little-endian */
void ys_write_s32_le(long, unsigned char *, unsigned char **);


/* ys_file.c     : File management functions
\*------------------------------------------------------------------*/
int ys_get_filesize(FILE *, unsigned long *, int *);

/* Shared declarations for list modules
\*------------------------------------------------------------------*/
enum YS_WALK_DIRECTIONS {
	YS_WALK_BACKWARD = 0,
	YS_WALK_FORWARD
};

/* ys_dl_list.c  : Doubly-linked list functions
\*------------------------------------------------------------------*/
typedef struct ys_dl_node_tag YS_DL_NODE;
typedef struct ys_dl_node_tag YS_DL_LIST;

struct ys_dl_node_tag {
	void *data;
	struct ys_dl_node_tag *next;
	struct ys_dl_node_tag *prev;
};

YS_DL_LIST *ys_dll_create(void);
void ys_dll_destroy(YS_DL_LIST *);

void *ys_dll_get_data(YS_DL_NODE *);

YS_DL_NODE *ys_dll_head(YS_DL_LIST *);
YS_DL_NODE *ys_dll_tail(YS_DL_LIST *);
YS_DL_NODE *ys_dll_next(YS_DL_NODE *);
YS_DL_NODE *ys_dll_prev(YS_DL_NODE *);

YS_DL_NODE *ys_dll_add_head(YS_DL_LIST *, void *, size_t);
YS_DL_NODE *ys_dll_add_tail(YS_DL_LIST *, void *, size_t);

#define ys_dll_preinsert  ys_dll_add_tail
#define ys_dll_postinsert ys_dll_add_head

YS_DL_NODE *ys_dll_insert(YS_DL_LIST *, void *, size_t, YS_COMPARE_FUNC *);
int ys_dll_delete(YS_DL_NODE *);
void ys_dll_delete_all(YS_DL_LIST *);

YS_DL_NODE *ys_dll_replace(YS_DL_NODE *, void *, size_t);

int ys_dll_reorder_up(YS_DL_LIST *, YS_DL_NODE *, YS_COMPARE_FUNC *);
int ys_dll_reorder_down(YS_DL_LIST *, YS_DL_NODE *, YS_COMPARE_FUNC *);

int ys_dll_foreach(YS_DL_LIST *,
    int, void *, int (*)(void *, void *), YS_DL_NODE **);


} // End of namespace Saga

#endif				/* YSLIB_MAIN_H__ */