-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.h
150 lines (126 loc) · 4.56 KB
/
util.h
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
/*
* @(#)util.h
*
* Copyright 1997-1999, Wes Cherry (mailto:wesc@technosis.com)
* 2000-2005, Aaron Ardiri (mailto:aaron@ardiri.com)
* All rights reserved.
*
* 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, or (at your option)
* any 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, please write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Revisions:
* ==========
*
* pre 18-Jun-2000 <numerous developers>
* creation
* 18-Jun-2000 Aaron Ardiri
* GNU GPL documentation additions
*/
#ifndef __UTIL_H__
#define __UTIL_H__
#include <stdio.h>
#include <stdarg.h>
#include "std.h"
/*
* RMa add : Debug mode define
*/
#ifdef _DEBUG
#define HEXOUT 1
#endif
#ifdef __GNUC__
#define PRINTF_FORMATTING __attribute__ ((format(printf, 1, 2)))
#else
#define PRINTF_FORMATTING
#endif
/* Error() and ErrorLine() write a message to stderr and halt translation;
WarningLine() writes to stderr and returns. ErrorLine() and WarningLine()
add an indication of the current source file and line number to the message
given via the printf format etc arguments. */
VOID Error(const char *szFormat, ...) PRINTF_FORMATTING;
VOID ErrorLine(const char *szFormat, ...) PRINTF_FORMATTING;
VOID WarningLine(const char *szFormat, ...) PRINTF_FORMATTING;
/* The functions above are actually wrappers around this general purpose
diagnostic function. Generally there's no need to call this directly,
but in any case: fError distinguishes between error/warning, and if
position or position->szFilename is NULL then it's a non-localised
diagnostic, as for Error(). */
typedef struct FILELINE
{
char *szFilename;
FILE *fh;
int line;
}
FILELINE;
VOID Diagnostic(BOOL fError, const FILELINE *position,
const char *szFormat, va_list *args);
/*lint -function(exit,Error) */
/*lint -function(exit,ErrorLine) */
/*lint -function(exit,Diagnostic) */
BOOL FSzEqI(const char *sz1,
const char *sz2);
int WMin(int w1,
int w2);
int WMax(int w1,
int w2);
VOID EmitB(BYTE b);
VOID EmitW(unsigned short w);
VOID EmitL(unsigned long l);
VOID intstrncpy(p_int * dst,
const char *src,
int n);
/* Returns a pointer (which should be freed by the caller) to memory allocated
for a string constructed according to the somewhat printf-style formatted
arguments. The following sequences in szFormat are expanded:
%s inserts the corresponding char* argument;
%e considers the corresponding char* argument to be an extension
to be removed if the output string so far ends thus;
/ inserts / or \ as appropriate if the output string so far is
non-empty and doesn't already end in a directory separator. */
char *MakeFilename(const char *szFormat, ...);
/* Returns a pointer (which should be freed by the caller) to memory allocated
for a temporary filename (as returned by tmpnam()) string. Don't count on
rename() succeeding with this file: it's quite likely to be on a different
filesystem from the one you'd like it to be on. */
char *MakeTempFilename(void);
VOID OpenOutput(char *szBase,
int id);
VOID CloseOutput(void);
FILE *getOpenedOutputFile(void);
VOID SetOutFileDir(const char *sz);
VOID OpenResDBFile(const char *szFile);
VOID CloseResDBFile(void);
VOID OpenResFile(const char *szFile);
VOID CloseResFile(void);
VOID DumpBytes(void *pv,
int cb);
VOID PadBoundary(void);
VOID PadWordBoundary(void);
int IbOut(void);
void AddAccessPath(const char *path);
void FreeAccessPathsList(void);
/* Returns a pointer (which should be freed by the caller) to the full path
of the file found, and a file handle (which should be closed by the caller)
in returnFile. */
char *FindAndOpenFile(const char *szIn, const char *mode, FILE **returnFile);
void InitDependsList(void);
void AddEntryToDependsList(const char *filename);
void OutputDependsList(FILE *dependsFile, const char *szDependsTarget);
void FreeDependsList(void);
extern char rgbZero[];
#ifdef CW_PLUGIN
// XXX ncr
#undef feof
#define feof(f) MyFeof(f)
#endif
#endif