1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile xstring.h:
|
---|
4 | * header file for xstring.c. See notes there.
|
---|
5 | *
|
---|
6 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
7 | * numbering.
|
---|
8 | *
|
---|
9 | *@@include #define INCL_DOSDATETIME
|
---|
10 | *@@include #include <os2.h>
|
---|
11 | *@@include #include "helpers\xstring.h"
|
---|
12 | */
|
---|
13 |
|
---|
14 | /*
|
---|
15 | * Copyright (C) 1999-2000 Ulrich Mller.
|
---|
16 | * This file is part of the "XWorkplace helpers" source package.
|
---|
17 | * This is free software; you can redistribute it and/or modify
|
---|
18 | * it under the terms of the GNU General Public License as published
|
---|
19 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
20 | * "COPYING" file of the XWorkplace main distribution.
|
---|
21 | * This program is distributed in the hope that it will be useful,
|
---|
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
24 | * GNU General Public License for more details.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #if __cplusplus
|
---|
28 | extern "C" {
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #ifndef XSTRING_HEADER_INCLUDED
|
---|
32 | #define XSTRING_HEADER_INCLUDED
|
---|
33 |
|
---|
34 | #ifndef XWPENTRY
|
---|
35 | #error You must define XWPENTRY to contain the standard linkage for the XWPHelpers.
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | /*
|
---|
39 | *@@ XSTRING:
|
---|
40 | *
|
---|
41 | *@@added V0.9.6 (2000-11-01) [umoeller]
|
---|
42 | */
|
---|
43 |
|
---|
44 | typedef struct _XSTRING
|
---|
45 | {
|
---|
46 | PSZ psz; // ptr to string or NULL
|
---|
47 | ULONG ulLength; // length of *psz
|
---|
48 | ULONG cbAllocated; // memory allocated in *psz
|
---|
49 | // (>= ulLength + 1)
|
---|
50 | ULONG ulDelta; // allocation delta (0 = none)
|
---|
51 | // V0.9.9 (2001-03-07) [umoeller]
|
---|
52 |
|
---|
53 | // if memory debugging is enabled, enable the following
|
---|
54 | // extra fields globally... even if the caller doesn't
|
---|
55 | // want the replacement calls, the xstr* implementations
|
---|
56 | // are compiled with these fields, so they must always be
|
---|
57 | // present V0.9.14 (2001-08-01) [umoeller]
|
---|
58 | #if defined(__XWPMEMDEBUG__) // setup.h only
|
---|
59 | const char *file;
|
---|
60 | unsigned long line;
|
---|
61 | const char *function;
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | } XSTRING, *PXSTRING;
|
---|
65 |
|
---|
66 | #if defined(__DEBUG_MALLOC_ENABLED__) && !defined(DONT_REPLACE_XSTR_MALLOC) // setup.h, helpers\memdebug.c
|
---|
67 | #define xstrInit(a, b) xstrInitDebug((a), (b), __FILE__, __LINE__, __FUNCTION__)
|
---|
68 | void XWPENTRY xstrInitDebug(PXSTRING pxstr,
|
---|
69 | ULONG ulPreAllocate,
|
---|
70 | const char *file,
|
---|
71 | unsigned long line,
|
---|
72 | const char *function);
|
---|
73 | typedef void XWPENTRY XSTRINITDEBUG(PXSTRING pxstr,
|
---|
74 | ULONG ulPreAllocate,
|
---|
75 | const char *file,
|
---|
76 | unsigned long line,
|
---|
77 | const char *function);
|
---|
78 | typedef XSTRINITDEBUG *PXSTRINITDEBUG;
|
---|
79 | #else
|
---|
80 | void XWPENTRY xstrInit(PXSTRING pxstr, ULONG ulPreAllocate);
|
---|
81 | typedef void XWPENTRY XSTRINIT(PXSTRING pxstr, ULONG ulPreAllocate);
|
---|
82 | typedef XSTRINIT *PXSTRINIT;
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | /* void XWPENTRY xstrInit(PXSTRING pxstr, ULONG ulPreAllocate);
|
---|
86 | typedef void XWPENTRY XSTRINIT(PXSTRING pxstr, ULONG ulPreAllocate);
|
---|
87 | typedef XSTRINIT *PXSTRINIT; */
|
---|
88 |
|
---|
89 | void xstrInitSet2(PXSTRING pxstr, PSZ pszNew, ULONG ulNewLength);
|
---|
90 |
|
---|
91 | void XWPENTRY xstrInitSet(PXSTRING pxstr, PSZ pszNew);
|
---|
92 | typedef void XWPENTRY XSTRINITSET(PXSTRING pxstr, PSZ pszNew);
|
---|
93 | typedef XSTRINITSET *PXSTRINITSET;
|
---|
94 |
|
---|
95 | #if defined(__DEBUG_MALLOC_ENABLED__) && !defined(DONT_REPLACE_XSTR_MALLOC) // setup.h, helpers\memdebug.c
|
---|
96 | #define xstrInitCopy(a, b, c) xstrInitCopyDebug((a), (b), (c), __FILE__, __LINE__, __FUNCTION__)
|
---|
97 | void XWPENTRY xstrInitCopyDebug(PXSTRING pxstr,
|
---|
98 | const char *pcszSource,
|
---|
99 | ULONG ulExtraAllocate,
|
---|
100 | const char *file,
|
---|
101 | unsigned long line,
|
---|
102 | const char *function);
|
---|
103 | typedef void XWPENTRY XSTRINITCOPYDEBUG(PXSTRING pxstr,
|
---|
104 | const char *pcszSource,
|
---|
105 | ULONG ulExtraAllocate,
|
---|
106 | const char *file,
|
---|
107 | unsigned long line,
|
---|
108 | const char *function);
|
---|
109 | typedef XSTRINITCOPYDEBUG *PXSTRINITCOPYDEBUG;
|
---|
110 | #else
|
---|
111 | void XWPENTRY xstrInitCopy(PXSTRING pxstr, const char *pcszSource, ULONG ulExtraAllocate);
|
---|
112 | typedef void XWPENTRY XSTRINITCOPY(PXSTRING pxstr, const char *pcszSource, ULONG ulExtraAllocate);
|
---|
113 | typedef XSTRINITCOPY *PXSTRINITCOPY;
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | void XWPENTRY xstrClear(PXSTRING pxstr);
|
---|
117 | typedef void XWPENTRY XSTRCLEAR(PXSTRING pxstr);
|
---|
118 | typedef XSTRCLEAR *PXSTRCLEAR;
|
---|
119 |
|
---|
120 | ULONG XWPENTRY xstrReserve(PXSTRING pxstr, ULONG ulBytes);
|
---|
121 | typedef ULONG XWPENTRY XSTRRESERVE(PXSTRING pxstr, ULONG ulBytes);
|
---|
122 | typedef XSTRRESERVE *PXSTRRESERVE;
|
---|
123 |
|
---|
124 | void XWPENTRY xstrShrink(PXSTRING pxstr);
|
---|
125 | typedef void XWPENTRY XSTRSHRINK(PXSTRING pxstr);
|
---|
126 | typedef XSTRSHRINK *PXSTRSHRINK;
|
---|
127 |
|
---|
128 | PXSTRING XWPENTRY xstrCreate(ULONG ulPreAllocate);
|
---|
129 | typedef PXSTRING XWPENTRY XSTRCREATE(ULONG ulPreAllocate);
|
---|
130 | typedef XSTRCREATE *PXSTRCREATE;
|
---|
131 |
|
---|
132 | VOID XWPENTRY xstrFree(PXSTRING *ppxstr);
|
---|
133 | typedef VOID XWPENTRY XSTRFREE(PXSTRING *ppxstr);
|
---|
134 | typedef XSTRFREE *PXSTRFREE;
|
---|
135 |
|
---|
136 | ULONG XWPENTRY xstrset2(PXSTRING pxstr, PSZ pszNew, ULONG ulNewLength);
|
---|
137 |
|
---|
138 | ULONG XWPENTRY xstrset(PXSTRING pxstr, PSZ pszNew);
|
---|
139 | typedef ULONG XWPENTRY XSTRSET(PXSTRING pxstr, PSZ pszNew);
|
---|
140 | typedef XSTRSET *PXSTRSET;
|
---|
141 |
|
---|
142 | ULONG XWPENTRY xstrcpy(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength);
|
---|
143 | typedef ULONG XWPENTRY XSTRCPY(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength);
|
---|
144 | typedef XSTRCPY *PXSTRCPY;
|
---|
145 |
|
---|
146 | ULONG XWPENTRY xstrcpys(PXSTRING pxstr, const XSTRING *pcstrSource);
|
---|
147 | typedef ULONG XWPENTRY XSTRCPYS(PXSTRING pxstr, const XSTRING *pcstrSource);
|
---|
148 | typedef XSTRCPYS *PXSTRCPYS;
|
---|
149 |
|
---|
150 | ULONG XWPENTRY xstrcat(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength);
|
---|
151 | typedef ULONG XWPENTRY XSTRCAT(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength);
|
---|
152 | typedef XSTRCAT *PXSTRCAT;
|
---|
153 |
|
---|
154 | ULONG XWPENTRY xstrcatc(PXSTRING pxstr, CHAR c);
|
---|
155 | typedef ULONG XWPENTRY XSTRCATC(PXSTRING pxstr, CHAR c);
|
---|
156 | typedef XSTRCATC *PXSTRCATC;
|
---|
157 |
|
---|
158 | ULONG XWPENTRY xstrcats(PXSTRING pxstr, const XSTRING *pcstrSource);
|
---|
159 | typedef ULONG XWPENTRY XSTRCATS(PXSTRING pxstr, const XSTRING *pcstrSource);
|
---|
160 | typedef XSTRCATS *PXSTRCATS;
|
---|
161 |
|
---|
162 | /*
|
---|
163 | *@@ xstrIsString:
|
---|
164 | * returns TRUE if psz contains something.
|
---|
165 | *
|
---|
166 | *@@added V0.9.6 (2000-10-16) [umoeller]
|
---|
167 | */
|
---|
168 |
|
---|
169 | #define xstrIsString(psz) ( (psz != 0) && (*(psz) != 0) )
|
---|
170 |
|
---|
171 | ULONG XWPENTRY xstrrpl(PXSTRING pxstr,
|
---|
172 | ULONG ulFirstReplOfs,
|
---|
173 | ULONG cReplLen,
|
---|
174 | const char *pcszReplaceWith,
|
---|
175 | ULONG cReplaceWithLen);
|
---|
176 | typedef ULONG XWPENTRY XSTRRPL(PXSTRING pxstr,
|
---|
177 | ULONG ulFirstReplOfs,
|
---|
178 | ULONG cReplLen,
|
---|
179 | const char *pcszReplaceWith,
|
---|
180 | ULONG cReplaceWithLen);
|
---|
181 | typedef XSTRRPL *PXSTRRPL;
|
---|
182 |
|
---|
183 | PSZ XWPENTRY xstrFindWord(const XSTRING *pxstr,
|
---|
184 | ULONG ulOfs,
|
---|
185 | const XSTRING *pstrFind,
|
---|
186 | size_t *pShiftTable,
|
---|
187 | PBOOL pfRepeatFind,
|
---|
188 | const char *pcszBeginChars,
|
---|
189 | const char *pcszEndChars);
|
---|
190 | typedef PSZ XWPENTRY XSTRFINDWORD(const XSTRING *pxstr,
|
---|
191 | ULONG ulOfs,
|
---|
192 | const XSTRING *pstrFind,
|
---|
193 | size_t *pShiftTable,
|
---|
194 | PBOOL pfRepeatFind,
|
---|
195 | const char *pcszBeginChars,
|
---|
196 | const char *pcszEndChars);
|
---|
197 | typedef XSTRFINDWORD *PXSTRFINDWORD;
|
---|
198 |
|
---|
199 | ULONG XWPENTRY xstrFindReplace(PXSTRING pxstr,
|
---|
200 | PULONG pulOfs,
|
---|
201 | const XSTRING *pstrSearch,
|
---|
202 | const XSTRING *pstrReplace,
|
---|
203 | size_t *pShiftTable,
|
---|
204 | PBOOL pfRepeatFind);
|
---|
205 | typedef ULONG XWPENTRY XSTRFINDREPLACE(PXSTRING pxstr,
|
---|
206 | PULONG pulOfs,
|
---|
207 | const XSTRING *pstrSearch,
|
---|
208 | const XSTRING *pstrReplace,
|
---|
209 | size_t *pShiftTable,
|
---|
210 | PBOOL pfRepeatFind);
|
---|
211 | typedef XSTRFINDREPLACE *PXSTRFINDREPLACE;
|
---|
212 |
|
---|
213 | ULONG XWPENTRY xstrFindReplaceC(PXSTRING pxstr,
|
---|
214 | PULONG pulOfs,
|
---|
215 | const char *pcszSearch,
|
---|
216 | const char *pcszReplace);
|
---|
217 | typedef ULONG XWPENTRY XSTRFINDREPLACEC(PXSTRING pxstr,
|
---|
218 | PULONG pulOfs,
|
---|
219 | const char *pcszSearch,
|
---|
220 | const char *pcszReplace);
|
---|
221 | typedef XSTRFINDREPLACEC *PXSTRFINDREPLACEC;
|
---|
222 |
|
---|
223 | ULONG XWPENTRY xstrEncode(PXSTRING pxstr, const char *pcszEncode);
|
---|
224 | typedef ULONG XWPENTRY XSTRENCODE(PXSTRING pxstr, const char *pcszEncode);
|
---|
225 | typedef XSTRENCODE *PXSTRENCODE;
|
---|
226 |
|
---|
227 | ULONG XWPENTRY xstrDecode2(PXSTRING pxstr,
|
---|
228 | CHAR cKey);
|
---|
229 |
|
---|
230 | ULONG XWPENTRY xstrDecode(PXSTRING pxstr);
|
---|
231 | typedef ULONG XWPENTRY XSTRDECODE(PXSTRING pxstr);
|
---|
232 | typedef XSTRDECODE *PXSTRDECODE;
|
---|
233 |
|
---|
234 | // V0.9.9 (2001-01-29) [lafaix]: constants added
|
---|
235 | #define CRLF2LF TRUE
|
---|
236 | #define LF2CRLF FALSE
|
---|
237 |
|
---|
238 | VOID XWPENTRY xstrConvertLineFormat(PXSTRING pxstr, BOOL fToCFormat);
|
---|
239 | typedef VOID XWPENTRY XSTRCONVERTLINEFORMAT(PXSTRING pxstr, BOOL fToCFormat);
|
---|
240 | typedef XSTRCONVERTLINEFORMAT *PXSTRCONVERTLINEFORMAT;
|
---|
241 |
|
---|
242 | VOID XWPENTRY xstrPrintf(XSTRING *pstr, PCSZ pcszFormat, ...);
|
---|
243 | typedef VOID XWPENTRY XSTRPRINTF(XSTRING *pstr, PCSZ pcszFormat, ...);
|
---|
244 | typedef XSTRPRINTF *PXSTRPRINTF;
|
---|
245 |
|
---|
246 | VOID xstrCatf(XSTRING *pstr,
|
---|
247 | PCSZ pcszFormat,
|
---|
248 | ...);
|
---|
249 | #endif
|
---|
250 |
|
---|
251 | #if __cplusplus
|
---|
252 | }
|
---|
253 | #endif
|
---|
254 |
|
---|