PageRenderTime 55ms CodeModel.GetById 17ms app.highlight 34ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-24/SWIG/Source/DOH/doh.h

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