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