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 * $Id: doh.h 11097 2009-01-30 10:27:37Z bhy $ 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 DohClose DOH_NAMESPACE(Close) 107#define DohCopyto DOH_NAMESPACE(Copyto) 108#define DohNewList DOH_NAMESPACE(NewList) 109#define DohNewHash DOH_NAMESPACE(NewHash) 110#define DohNewVoid DOH_NAMESPACE(NewVoid) 111#define DohSplit DOH_NAMESPACE(Split) 112#define DohSplitLines DOH_NAMESPACE(SplitLines) 113#define DohNone DOH_NAMESPACE(None) 114#define DohCall DOH_NAMESPACE(Call) 115#define DohObjMalloc DOH_NAMESPACE(ObjMalloc) 116#define DohObjFree DOH_NAMESPACE(ObjFree) 117#define DohMemoryDebug DOH_NAMESPACE(MemoryDebug) 118#define DohStringType DOH_NAMESPACE(StringType) 119#define DohListType DOH_NAMESPACE(ListType) 120#define DohHashType DOH_NAMESPACE(HashType) 121#define DohFileType DOH_NAMESPACE(FileType) 122#define DohVoidType DOH_NAMESPACE(VoidType) 123#define DohIterator DOH_NAMESPACE(Iterator) 124#define DohFirst DOH_NAMESPACE(First) 125#define DohNext DOH_NAMESPACE(Next) 126#endif 127 128#define DOH_MAJOR_VERSION 0 129#define DOH_MINOR_VERSION 1 130 131typedef void DOH; 132 133/* 134 * With dynamic typing, all DOH objects are technically of type 'void *'. 135 * However, to clarify the reading of source code, the following symbolic 136 * names are used. 137 */ 138 139#define DOHString DOH 140#define DOHList DOH 141#define DOHHash DOH 142#define DOHFile DOH 143#define DOHVoid DOH 144#define DOHString_or_char DOH 145#define DOHObj_or_char DOH 146 147typedef const DOHString_or_char * const_String_or_char_ptr; 148typedef const DOHString_or_char * DOHconst_String_or_char_ptr; 149 150#define DOH_BEGIN -1 151#define DOH_END -2 152#define DOH_CUR -3 153#define DOH_CURRENT -3 154 155/* Iterator objects */ 156 157typedef struct { 158 void *key; /* Current key (if any) */ 159 void *item; /* Current item */ 160 void *object; /* Object being iterated over */ 161 void *_current; /* Internal use */ 162 int _index; /* Internal use */ 163} DohIterator; 164 165/* Memory management */ 166 167#ifndef DohMalloc 168#define DohMalloc malloc 169#endif 170#ifndef DohRealloc 171#define DohRealloc realloc 172#endif 173#ifndef DohFree 174#define DohFree free 175#endif 176 177extern int DohCheck(const DOH *ptr); /* Check if a DOH object */ 178extern void DohIntern(DOH *); /* Intern an object */ 179 180/* Basic object methods. Common to most objects */ 181 182extern void DohDelete(DOH *obj); /* Delete an object */ 183extern DOH *DohCopy(const DOH *obj); 184extern void DohClear(DOH *obj); 185extern DOHString *DohStr(const DOH *obj); 186extern void *DohData(const DOH *obj); 187extern int DohDump(const DOH *obj, DOHFile * out); 188extern int DohLen(const DOH *obj); 189extern int DohHashval(const DOH *obj); 190extern int DohCmp(const DOH *obj1, const DOH *obj2); 191extern int DohEqual(const DOH *obj1, const DOH *obj2); 192extern void DohIncref(DOH *obj); 193 194/* Mapping methods */ 195 196extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name); 197extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char * value); 198extern int DohDelattr(DOH *obj, const DOHString_or_char *name); 199extern int DohCheckattr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *value); 200extern DOH *DohKeys(DOH *obj); 201extern int DohGetInt(DOH *obj, const DOHString_or_char *name); 202extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int); 203extern double DohGetDouble(DOH *obj, const DOHString_or_char *name); 204extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double); 205extern char *DohGetChar(DOH *obj, const DOHString_or_char *name); 206extern void DohSetChar(DOH *obj, const DOH *name, char *value); 207extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name); 208extern int DohGetFlag(DOH *obj, const DOHString_or_char *name); 209extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr); 210extern void DohSetFlag(DOH *obj, const DOHString_or_char *name); 211extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name); 212extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value); 213 214/* Sequence methods */ 215 216extern DOH *DohGetitem(DOH *obj, int index); 217extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char * value); 218extern int DohDelitem(DOH *obj, int index); 219extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char * value); 220extern int DohDelslice(DOH *obj, int sindex, int eindex); 221 222/* File methods */ 223 224extern int DohWrite(DOHFile * obj, void *buffer, int length); 225extern int DohRead(DOHFile * obj, void *buffer, int length); 226extern int DohSeek(DOHFile * obj, long offset, int whence); 227extern long DohTell(DOHFile * obj); 228extern int DohGetc(DOHFile * obj); 229extern int DohPutc(int ch, DOHFile * obj); 230extern int DohUngetc(int ch, DOHFile * obj); 231 232 233 234/* Iterators */ 235extern DohIterator DohFirst(DOH *obj); 236extern DohIterator DohNext(DohIterator x); 237 238/* Positional */ 239 240extern int DohGetline(const DOH *obj); 241extern void DohSetline(DOH *obj, int line); 242extern DOH *DohGetfile(const DOH *obj); 243extern void DohSetfile(DOH *obj, DOH *file); 244 245 /* String Methods */ 246 247extern int DohReplace(DOHString * src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags); 248extern void DohChop(DOHString * src); 249 250/* Meta-variables */ 251extern DOH *DohGetmeta(DOH *, const DOH *); 252extern int DohSetmeta(DOH *, const DOH *, const DOH *value); 253extern int DohDelmeta(DOH *, const DOH *); 254 255 /* Utility functions */ 256 257extern void DohEncoding(char *name, DOH *(*fn) (DOH *s)); 258extern int DohPrintf(DOHFile * obj, const char *format, ...); 259extern int DohvPrintf(DOHFile * obj, const char *format, va_list ap); 260extern int DohPrintv(DOHFile * obj, ...); 261extern DOH *DohReadline(DOHFile * in); 262 263 /* Miscellaneous */ 264 265extern int DohIsMapping(const DOH *obj); 266extern int DohIsSequence(const DOH *obj); 267extern int DohIsString(const DOH *obj); 268extern int DohIsFile(const DOH *obj); 269 270extern void DohSetmark(DOH *obj, int x); 271extern int DohGetmark(DOH *obj); 272 273/* ----------------------------------------------------------------------------- 274 * Strings. 275 * ----------------------------------------------------------------------------- */ 276 277extern DOHString *DohNewStringEmpty(void); 278extern DOHString *DohNewString(const DOH *c); 279extern DOHString *DohNewStringWithSize(const DOH *c, int len); 280extern DOHString *DohNewStringf(const DOH *fmt, ...); 281 282extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2); 283extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n); 284extern char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2); 285extern char *DohStrchr(const DOHString_or_char *s1, int ch); 286 287/* String replacement flags */ 288 289#define DOH_REPLACE_ANY 0x01 290#define DOH_REPLACE_NOQUOTE 0x02 291#define DOH_REPLACE_ID 0x04 292#define DOH_REPLACE_FIRST 0x08 293#define DOH_REPLACE_ID_BEGIN 0x10 294#define DOH_REPLACE_ID_END 0x20 295 296#define Replaceall(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ANY) 297#define Replaceid(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ID) 298 299/* ----------------------------------------------------------------------------- 300 * Files 301 * ----------------------------------------------------------------------------- */ 302 303extern DOHFile *DohNewFile(DOH *filename, const char *mode, DOHList *outfiles); 304extern DOHFile *DohNewFileFromFile(FILE *f); 305extern DOHFile *DohNewFileFromFd(int fd); 306extern void DohFileErrorDisplay(DOHString * filename); 307extern int DohClose(DOH *file); 308extern int DohCopyto(DOHFile * input, DOHFile * output); 309 310 311/* ----------------------------------------------------------------------------- 312 * List 313 * ----------------------------------------------------------------------------- */ 314 315extern DOHList *DohNewList(void); 316extern void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *)); 317 318/* ----------------------------------------------------------------------------- 319 * Hash 320 * ----------------------------------------------------------------------------- */ 321 322extern DOHHash *DohNewHash(void); 323 324/* ----------------------------------------------------------------------------- 325 * Void 326 * ----------------------------------------------------------------------------- */ 327 328extern DOHVoid *DohNewVoid(void *ptr, void (*del) (void *)); 329extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits); 330extern DOHList *DohSplitLines(DOHFile * input); 331extern DOH *DohNone; 332 333extern void DohMemoryDebug(void); 334 335#ifndef DOH_LONG_NAMES 336/* Macros to invoke the above functions. Includes the location of 337 the caller to simplify debugging if something goes wrong */ 338 339#define Delete DohDelete 340#define Copy DohCopy 341#define Clear DohClear 342#define Str DohStr 343#define Dump DohDump 344#define Getattr DohGetattr 345#define Setattr DohSetattr 346#define Delattr DohDelattr 347#define Checkattr DohCheckattr 348#define Hashval DohHashval 349#define Getitem DohGetitem 350#define Setitem DohSetitem 351#define Delitem DohDelitem 352#define Insert DohInsertitem 353#define Delslice DohDelslice 354#define Append(s,x) DohInsertitem(s,DOH_END,x) 355#define Push(s,x) DohInsertitem(s,DOH_BEGIN,x) 356#define Len DohLen 357#define Data DohData 358#define Char (char *) Data 359#define Cmp DohCmp 360#define Equal DohEqual 361#define Setline DohSetline 362#define Getline DohGetline 363#define Setfile DohSetfile 364#define Getfile DohGetfile 365#define Write DohWrite 366#define Read DohRead 367#define Seek DohSeek 368#define Tell DohTell 369#define Printf DohPrintf 370#define Printv DohPrintv 371#define Getc DohGetc 372#define Putc DohPutc 373#define Ungetc DohUngetc 374 375/* #define StringPutc DohStringPutc */ 376/* #define StringGetc DohStringGetc */ 377/* #define StringUngetc DohStringUngetc */ 378/* #define StringAppend Append */ 379/* #define StringLen DohStringLen */ 380/* #define StringChar DohStringChar */ 381/* #define StringEqual DohStringEqual */ 382 383#define Close DohClose 384#define vPrintf DohvPrintf 385#define GetInt DohGetInt 386#define GetDouble DohGetDouble 387#define GetChar DohGetChar 388#define GetVoid DohGetVoid 389#define GetFlagAttr DohGetFlagAttr 390#define GetFlag DohGetFlag 391#define SetInt DohSetInt 392#define SetDouble DohSetDouble 393#define SetChar DohSetattr 394#define SetVoid DohSetVoid 395#define SetFlagAttr DohSetFlagAttr 396#define SetFlag DohSetFlag 397#define UnsetFlag(o,n) DohSetFlagAttr(o,n,NULL) 398#define ClearFlag(o,n) DohSetFlagAttr(o,n,"") 399#define Readline DohReadline 400#define Replace DohReplace 401#define Chop DohChop 402#define Getmeta DohGetmeta 403#define Setmeta DohSetmeta 404#define Delmeta DohDelmeta 405#define NewString DohNewString 406#define NewStringEmpty DohNewStringEmpty 407#define NewStringWithSize DohNewStringWithSize 408#define NewStringf DohNewStringf 409#define NewHash DohNewHash 410#define NewList DohNewList 411#define NewFile DohNewFile 412#define NewFileFromFile DohNewFileFromFile 413#define NewFileFromFd DohNewFileFromFd 414#define FileErrorDisplay DohFileErrorDisplay 415#define Close DohClose 416#define NewVoid DohNewVoid 417#define Keys DohKeys 418#define Strcmp DohStrcmp 419#define Strncmp DohStrncmp 420#define Strstr DohStrstr 421#define Strchr DohStrchr 422#define Copyto DohCopyto 423#define Split DohSplit 424#define SplitLines DohSplitLines 425#define Setmark DohSetmark 426#define Getmark DohGetmark 427#define None DohNone 428#define Call DohCall 429#define First DohFirst 430#define Next DohNext 431#define Iterator DohIterator 432#define SortList DohSortList 433#endif 434 435#ifdef NIL 436#undef NIL 437#endif 438 439#define NIL (char *) NULL 440 441 442#endif /* DOH_H */ 443