1 /* -----------------------------------------------------------------------------
2  * This file is part of SWIG, which is licensed as a whole under version 3
3  * (or any later version) of the GNU General Public License. Some additional
4  * terms also apply to certain portions of SWIG. The full details of the SWIG
5  * license and copyrights can be found in the LICENSE and COPYRIGHT files
6  * included with the SWIG source code as distributed by the SWIG developers
7  * and at http://www.swig.org/legal.html.
8  *
9  * doh.h
10  *
11  *     This file describes of the externally visible functions in DOH.
12  * ----------------------------------------------------------------------------- */
13 
14 #ifndef _DOH_H
15 #define _DOH_H
16 
17 #ifndef MACSWIG
18 #include "swigconfig.h"
19 #endif
20 
21 #include <stdio.h>
22 #include <stdarg.h>
23 
24 /* Set the namespace prefix for DOH API functions. This can be used to control
25    visibility of the functions in libraries */
26 
27 /* Set this macro if you want to change DOH linkage. You would do this if you
28    wanted to hide DOH in a library using a different set of names.  Note: simply
29    change "Doh" to a new name. */
30 
31 /*
32 #define DOH_NAMESPACE(x) Doh ## x
33 */
34 
35 #ifdef DOH_NAMESPACE
36 
37 /* Namespace control.  These macros define all of the public API names in DOH */
38 
39 #define DohCheck           DOH_NAMESPACE(Check)
40 #define DohIntern          DOH_NAMESPACE(Intern)
41 #define DohDelete          DOH_NAMESPACE(Delete)
42 #define DohCopy            DOH_NAMESPACE(Copy)
43 #define DohClear           DOH_NAMESPACE(Clear)
44 #define DohStr             DOH_NAMESPACE(Str)
45 #define DohData            DOH_NAMESPACE(Data)
46 #define DohDump            DOH_NAMESPACE(Dump)
47 #define DohLen             DOH_NAMESPACE(Len)
48 #define DohHashval         DOH_NAMESPACE(Hashval)
49 #define DohCmp             DOH_NAMESPACE(Cmp)
50 #define DohEqual           DOH_NAMESPACE(Equal)
51 #define DohIncref          DOH_NAMESPACE(Incref)
52 #define DohCheckattr       DOH_NAMESPACE(Checkattr)
53 #define DohSetattr         DOH_NAMESPACE(Setattr)
54 #define DohDelattr         DOH_NAMESPACE(Delattr)
55 #define DohKeys            DOH_NAMESPACE(Keys)
56 #define DohGetInt          DOH_NAMESPACE(GetInt)
57 #define DohGetDouble       DOH_NAMESPACE(GetDouble)
58 #define DohGetChar         DOH_NAMESPACE(GetChar)
59 #define DohSetChar         DOH_NAMESPACE(SetChar)
60 #define DohSetInt          DOH_NAMESPACE(SetInt)
61 #define DohSetDouble       DOH_NAMESPACE(SetDouble)
62 #define DohSetVoid         DOH_NAMESPACE(SetVoid)
63 #define DohGetVoid         DOH_NAMESPACE(GetVoid)
64 #define DohGetitem         DOH_NAMESPACE(Getitem)
65 #define DohSetitem         DOH_NAMESPACE(Setitem)
66 #define DohDelitem         DOH_NAMESPACE(Delitem)
67 #define DohInsertitem      DOH_NAMESPACE(Insertitem)
68 #define DohDelslice        DOH_NAMESPACE(Delslice)
69 #define DohWrite           DOH_NAMESPACE(Write)
70 #define DohRead            DOH_NAMESPACE(Read)
71 #define DohSeek            DOH_NAMESPACE(Seek)
72 #define DohTell            DOH_NAMESPACE(Tell)
73 #define DohGetc            DOH_NAMESPACE(Getc)
74 #define DohPutc            DOH_NAMESPACE(Putc)
75 #define DohUngetc          DOH_NAMESPACE(Ungetc)
76 #define DohGetline         DOH_NAMESPACE(Getline)
77 #define DohSetline         DOH_NAMESPACE(Setline)
78 #define DohGetfile         DOH_NAMESPACE(Getfile)
79 #define DohSetfile         DOH_NAMESPACE(Setfile)
80 #define DohReplace         DOH_NAMESPACE(Replace)
81 #define DohChop            DOH_NAMESPACE(Chop)
82 #define DohGetmeta         DOH_NAMESPACE(Getmeta)
83 #define DohSetmeta         DOH_NAMESPACE(Setmeta)
84 #define DohDelmeta         DOH_NAMESPACE(Delmeta)
85 #define DohEncoding        DOH_NAMESPACE(Encoding)
86 #define DohPrintf          DOH_NAMESPACE(Printf)
87 #define DohvPrintf         DOH_NAMESPACE(vPrintf)
88 #define DohPrintv          DOH_NAMESPACE(Printv)
89 #define DohReadline        DOH_NAMESPACE(Readline)
90 #define DohIsMapping       DOH_NAMESPACE(IsMapping)
91 #define DohIsSequence      DOH_NAMESPACE(IsSequence)
92 #define DohIsString        DOH_NAMESPACE(IsString)
93 #define DohIsFile          DOH_NAMESPACE(IsFile)
94 #define DohNewString       DOH_NAMESPACE(NewString)
95 #define DohNewStringEmpty  DOH_NAMESPACE(NewStringEmpty)
96 #define DohNewStringWithSize  DOH_NAMESPACE(NewStringWithSize)
97 #define DohNewStringf      DOH_NAMESPACE(NewStringf)
98 #define DohStrcmp          DOH_NAMESPACE(Strcmp)
99 #define DohStrncmp         DOH_NAMESPACE(Strncmp)
100 #define DohStrstr          DOH_NAMESPACE(Strstr)
101 #define DohStrchr          DOH_NAMESPACE(Strchr)
102 #define DohNewFile         DOH_NAMESPACE(NewFile)
103 #define DohNewFileFromFile DOH_NAMESPACE(NewFileFromFile)
104 #define DohNewFileFromFd   DOH_NAMESPACE(NewFileFromFd)
105 #define DohFileErrorDisplay   DOH_NAMESPACE(FileErrorDisplay)
106 #define DohCopyto          DOH_NAMESPACE(Copyto)
107 #define DohNewList         DOH_NAMESPACE(NewList)
108 #define DohNewHash         DOH_NAMESPACE(NewHash)
109 #define DohNewVoid         DOH_NAMESPACE(NewVoid)
110 #define DohSplit           DOH_NAMESPACE(Split)
111 #define DohSplitLines      DOH_NAMESPACE(SplitLines)
112 #define DohNone            DOH_NAMESPACE(None)
113 #define DohCall            DOH_NAMESPACE(Call)
114 #define DohObjMalloc       DOH_NAMESPACE(ObjMalloc)
115 #define DohObjFree         DOH_NAMESPACE(ObjFree)
116 #define DohMemoryDebug     DOH_NAMESPACE(MemoryDebug)
117 #define DohStringType      DOH_NAMESPACE(StringType)
118 #define DohListType        DOH_NAMESPACE(ListType)
119 #define DohHashType        DOH_NAMESPACE(HashType)
120 #define DohFileType        DOH_NAMESPACE(FileType)
121 #define DohVoidType        DOH_NAMESPACE(VoidType)
122 #define DohIterator        DOH_NAMESPACE(Iterator)
123 #define DohFirst           DOH_NAMESPACE(First)
124 #define DohNext            DOH_NAMESPACE(Next)
125 #endif
126 
127 #define DOH_MAJOR_VERSION 0
128 #define DOH_MINOR_VERSION 1
129 
130 typedef void DOH;
131 
132 /*
133  * With dynamic typing, all DOH objects are technically of type 'void *'.
134  * However, to clarify the reading of source code, the following symbolic
135  * names are used.
136  */
137 
138 #define DOHString          DOH
139 #define DOHList            DOH
140 #define DOHHash            DOH
141 #define DOHFile            DOH
142 #define DOHVoid            DOH
143 #define DOHString_or_char  DOH
144 #define DOHObj_or_char     DOH
145 
146 typedef const DOHString_or_char * const_String_or_char_ptr;
147 typedef const DOHString_or_char * DOHconst_String_or_char_ptr;
148 
149 #define DOH_BEGIN          -1
150 #define DOH_END            -2
151 #define DOH_CUR            -3
152 #define DOH_CURRENT        -3
153 
154 /* Iterator objects */
155 
156 typedef struct {
157   void *key;			/* Current key (if any)       */
158   void *item;			/* Current item               */
159   void *object;			/* Object being iterated over */
160   void *_current;		/* Internal use */
161   int _index;			/* Internal use */
162 } DohIterator;
163 
164 /* Memory management */
165 
166 #ifndef DohMalloc
167 #define DohMalloc malloc
168 #endif
169 #ifndef DohRealloc
170 #define DohRealloc realloc
171 #endif
172 #ifndef DohFree
173 #define DohFree free
174 #endif
175 
176 extern int DohCheck(const DOH *ptr);	/* Check if a DOH object */
177 extern void DohIntern(DOH *);	/* Intern an object      */
178 
179 /* Basic object methods.  Common to most objects */
180 
181 extern void DohDelete(DOH *obj);	/* Delete an object      */
182 extern DOH *DohCopy(const DOH *obj);
183 extern void DohClear(DOH *obj);
184 extern DOHString *DohStr(const DOH *obj);
185 extern void *DohData(const DOH *obj);
186 extern int DohDump(const DOH *obj, DOHFile * out);
187 extern int DohLen(const DOH *obj);
188 extern int DohHashval(const DOH *obj);
189 extern int DohCmp(const DOH *obj1, const DOH *obj2);
190 extern int DohEqual(const DOH *obj1, const DOH *obj2);
191 extern void DohIncref(DOH *obj);
192 
193 /* Mapping methods */
194 
195 extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name);
196 extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char * value);
197 extern int DohDelattr(DOH *obj, const DOHString_or_char *name);
198 extern int DohCheckattr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *value);
199 extern DOH *DohKeys(DOH *obj);
200 extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
201 extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
202 extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
203 extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
204 extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
205 extern void DohSetChar(DOH *obj, const DOH *name, char *value);
206 extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name);
207 extern int DohGetFlag(DOH *obj, const DOHString_or_char *name);
208 extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr);
209 extern void DohSetFlag(DOH *obj, const DOHString_or_char *name);
210 extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
211 extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
212 
213 /* Sequence methods */
214 
215 extern DOH *DohGetitem(DOH *obj, int index);
216 extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char * value);
217 extern int DohDelitem(DOH *obj, int index);
218 extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char * value);
219 extern int DohDelslice(DOH *obj, int sindex, int eindex);
220 
221 /* File methods */
222 
223 extern int DohWrite(DOHFile * obj, const void *buffer, int length);
224 extern int DohRead(DOHFile * obj, void *buffer, int length);
225 extern int DohSeek(DOHFile * obj, long offset, int whence);
226 extern long DohTell(DOHFile * obj);
227 extern int DohGetc(DOHFile * obj);
228 extern int DohPutc(int ch, DOHFile * obj);
229 extern int DohUngetc(int ch, DOHFile * obj);
230 
231 
232 
233 /* Iterators */
234 extern DohIterator DohFirst(DOH *obj);
235 extern DohIterator DohNext(DohIterator x);
236 
237 /* Positional */
238 
239 extern int DohGetline(const DOH *obj);
240 extern void DohSetline(DOH *obj, int line);
241 extern DOH *DohGetfile(const DOH *obj);
242 extern void DohSetfile(DOH *obj, DOH *file);
243 
244   /* String Methods */
245 
246 extern int DohReplace(DOHString * src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
247 extern void DohChop(DOHString * src);
248 
249 /* Meta-variables */
250 extern DOH *DohGetmeta(DOH *, const DOH *);
251 extern int DohSetmeta(DOH *, const DOH *, const DOH *value);
252 extern int DohDelmeta(DOH *, const DOH *);
253 
254   /* Utility functions */
255 
256 extern void DohEncoding(const char *name, DOH *(*fn) (DOH *s));
257 extern int DohPrintf(DOHFile * obj, const char *format, ...);
258 extern int DohvPrintf(DOHFile * obj, const char *format, va_list ap);
259 extern int DohPrintv(DOHFile * obj, ...);
260 extern DOH *DohReadline(DOHFile * in);
261 
262   /* Miscellaneous */
263 
264 extern int DohIsMapping(const DOH *obj);
265 extern int DohIsSequence(const DOH *obj);
266 extern int DohIsString(const DOH *obj);
267 extern int DohIsFile(const DOH *obj);
268 
269 extern void DohSetMaxHashExpand(int count);
270 extern int DohGetMaxHashExpand(void);
271 extern void DohSetmark(DOH *obj, int x);
272 extern int DohGetmark(DOH *obj);
273 
274 /* -----------------------------------------------------------------------------
275  * Strings.
276  * ----------------------------------------------------------------------------- */
277 
278 extern DOHString *DohNewStringEmpty(void);
279 extern DOHString *DohNewString(const DOHString_or_char *c);
280 extern DOHString *DohNewStringWithSize(const DOHString_or_char *c, int len);
281 extern DOHString *DohNewStringf(const DOHString_or_char *fmt, ...);
282 
283 extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2);
284 extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n);
285 extern char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2);
286 extern char *DohStrchr(const DOHString_or_char *s1, int ch);
287 
288 /* String replacement flags */
289 
290 #define   DOH_REPLACE_ANY         0x01
291 #define   DOH_REPLACE_NOQUOTE     0x02
292 #define   DOH_REPLACE_NOCOMMENT   0x04
293 #define   DOH_REPLACE_ID          0x08
294 #define   DOH_REPLACE_FIRST       0x10
295 #define   DOH_REPLACE_ID_BEGIN    0x20
296 #define   DOH_REPLACE_ID_END      0x40
297 #define   DOH_REPLACE_NUMBER_END  0x80
298 
299 #define Replaceall(s,t,r)  DohReplace(s,t,r,DOH_REPLACE_ANY)
300 #define Replaceid(s,t,r)   DohReplace(s,t,r,DOH_REPLACE_ID)
301 
302 /* -----------------------------------------------------------------------------
303  * Files
304  * ----------------------------------------------------------------------------- */
305 
306 extern DOHFile *DohNewFile(DOHString *filename, const char *mode, DOHList *outfiles);
307 extern DOHFile *DohNewFileFromFile(FILE *f);
308 extern DOHFile *DohNewFileFromFd(int fd);
309 extern void DohFileErrorDisplay(DOHString * filename);
310 extern int DohCopyto(DOHFile * input, DOHFile * output);
311 extern void DohCloseAllOpenFiles(void);
312 
313 
314 /* -----------------------------------------------------------------------------
315  * List
316  * ----------------------------------------------------------------------------- */
317 
318 extern DOHList *DohNewList(void);
319 extern void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *));
320 
321 /* -----------------------------------------------------------------------------
322  * Hash
323  * ----------------------------------------------------------------------------- */
324 
325 extern DOHHash *DohNewHash(void);
326 
327 /* -----------------------------------------------------------------------------
328  * Void
329  * ----------------------------------------------------------------------------- */
330 
331 extern DOHVoid *DohNewVoid(void *ptr, void (*del) (void *));
332 extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits);
333 extern DOHList *DohSplitLines(DOHFile * input);
334 extern DOH *DohNone;
335 
336 /* Helper union for converting between function and object pointers. */
337 typedef union DohFuncPtr {
338   void* p;
339   DOH *(*func)(DOH *);
340 } DohFuncPtr_t;
341 
342 extern void DohMemoryDebug(void);
343 
344 #ifndef DOH_LONG_NAMES
345 /* Macros to invoke the above functions.  Includes the location of
346    the caller to simplify debugging if something goes wrong */
347 
348 #define Delete             DohDelete
349 #define Copy               DohCopy
350 #define Clear              DohClear
351 #define Str                DohStr
352 #define Dump               DohDump
353 #define Getattr            DohGetattr
354 #define Setattr            DohSetattr
355 #define Delattr            DohDelattr
356 #define Checkattr          DohCheckattr
357 #define Hashval            DohHashval
358 #define Getitem            DohGetitem
359 #define Setitem            DohSetitem
360 #define Delitem            DohDelitem
361 #define Insert             DohInsertitem
362 #define Delslice           DohDelslice
363 #define Append(s,x)        DohInsertitem(s,DOH_END,x)
364 #define Push(s,x)          DohInsertitem(s,DOH_BEGIN,x)
365 #define Len                DohLen
366 #define Data               DohData
367 #define Char               (char *) Data
368 #define Cmp                DohCmp
369 #define Equal              DohEqual
370 #define Setline            DohSetline
371 #define Getline            DohGetline
372 #define Setfile            DohSetfile
373 #define Getfile            DohGetfile
374 #define Write              DohWrite
375 #define Read               DohRead
376 #define Seek               DohSeek
377 #define Tell               DohTell
378 #define Printf             DohPrintf
379 #define Printv             DohPrintv
380 #define Getc               DohGetc
381 #define Putc               DohPutc
382 #define Ungetc             DohUngetc
383 
384 /* #define StringPutc         DohStringPutc */
385 /* #define StringGetc         DohStringGetc */
386 /* #define StringUngetc       DohStringUngetc */
387 /* #define StringAppend       Append */
388 /* #define StringLen          DohStringLen */
389 /* #define StringChar         DohStringChar */
390 /* #define StringEqual        DohStringEqual */
391 
392 #define vPrintf            DohvPrintf
393 #define GetInt             DohGetInt
394 #define GetDouble          DohGetDouble
395 #define GetChar            DohGetChar
396 #define GetVoid            DohGetVoid
397 #define GetFlagAttr        DohGetFlagAttr
398 #define GetFlag            DohGetFlag
399 #define SetInt             DohSetInt
400 #define SetDouble          DohSetDouble
401 #define SetChar            DohSetattr
402 #define SetVoid            DohSetVoid
403 #define SetFlagAttr        DohSetFlagAttr
404 #define SetFlag            DohSetFlag
405 #define UnsetFlag(o,n)     DohSetFlagAttr(o,n,NULL)
406 #define ClearFlag(o,n)     DohSetFlagAttr(o,n,"")
407 #define Readline           DohReadline
408 #define Replace            DohReplace
409 #define Chop               DohChop
410 #define Getmeta            DohGetmeta
411 #define Setmeta            DohSetmeta
412 #define Delmeta            DohDelmeta
413 #define NewString          DohNewString
414 #define NewStringEmpty     DohNewStringEmpty
415 #define NewStringWithSize  DohNewStringWithSize
416 #define NewStringf         DohNewStringf
417 #define NewHash            DohNewHash
418 #define NewList            DohNewList
419 #define NewFile            DohNewFile
420 #define NewFileFromFile    DohNewFileFromFile
421 #define NewFileFromFd      DohNewFileFromFd
422 #define FileErrorDisplay   DohFileErrorDisplay
423 #define NewVoid            DohNewVoid
424 #define Keys               DohKeys
425 #define Strcmp             DohStrcmp
426 #define Strncmp            DohStrncmp
427 #define Strstr             DohStrstr
428 #define Strchr             DohStrchr
429 #define Copyto             DohCopyto
430 #define CloseAllOpenFiles  DohCloseAllOpenFiles
431 #define Split              DohSplit
432 #define SplitLines         DohSplitLines
433 #define Setmark            DohSetmark
434 #define Getmark            DohGetmark
435 #define SetMaxHashExpand   DohSetMaxHashExpand
436 #define GetMaxHashExpand   DohGetMaxHashExpand
437 #define None               DohNone
438 #define Call               DohCall
439 #define First              DohFirst
440 #define Next               DohNext
441 #define Iterator           DohIterator
442 #define SortList           DohSortList
443 #endif
444 
445 #ifdef NIL
446 #undef NIL
447 #endif
448 
449 #define NIL  (char *) NULL
450 
451 
452 #endif				/* DOH_H */
453