[0001] [0002] [0003] [0004] [0005] [0006] [0007] [0008] [0009] [0010] [0011] [0012] [0013] [0014] [0015] [0016] [0017] [0018] [0019] [0020] [0021] [0022] [0023] [0024] [0025] [0026] [0027] [0028] [0029] [0030] [0031] [0032] [0033] [0034] [0035] [0036] [0037] [0038] [0039] [0040] [0041] [0042] [0043] [0044] [0045] [0046] [0047] [0048] [0049] [0050] [0051] [0052] [0053] [0054] [0055] [0056] [0057] [0058] [0059] [0060] [0061] [0062] [0063] [0064] [0065] [0066] [0067] [0068] [0069] [0070] [0071] [0072] [0073] [0074] [0075] [0076] [0077] [0078] [0079] [0080] [0081] [0082] [0083] [0084] [0085] [0086] [0087] [0088] [0089] [0090] [0091] [0092] [0093] [0094] [0095] [0096] [0097] [0098] [0099] [0100] [0101] [0102] [0103] [0104] [0105] [0106] [0107] [0108] [0109] [0110] [0111] [0112] [0113] [0114] [0115] [0116] [0117] [0118] [0119] [0120] [0121] [0122] [0123] [0124] [0125] [0126] [0127] [0128] [0129] [0130] [0131] [0132] [0133] [0134] [0135] [0136] [0137] [0138] [0139] [0140] [0141] [0142] [0143] [0144] [0145] [0146] [0147] [0148] [0149]
/*****************************************************************************/ /* StrDsc.h */ /*****************************************************************************/ #ifndef STRDSC_H_LOADED #define STRDSC_H_LOADED 1 /* application related header files */ #include "wasd.h" /*******************/ /* data structures */ /*******************/ #pragma member_alignment __save #pragma member_alignment typedef struct StrDscStruct STR_DSC; struct StrDscStruct { /* pointer-to-self */ STR_DSC* itself; /* bit vector */ unsigned long flags; /* size of storage (maximum capacity) */ unsigned long size; /* current length of used storage */ unsigned long length; /* reallocate (plus) these bytes rather than link to new descriptor */ unsigned long realloc; /* pointer to storage */ char *pointer; /* request pointer (for memory allocation) */ REQUEST_STRUCT *rqptr; /* allow these (STR_DSC) descriptors to be linked together */ struct StrDscStruct *flink, *blink; }; #pragma member_alignment __restore /*************/ /* constants */ /*************/ /* descriptor itself has been allocated */ #define STR_DSC_FLAG_DYNAMIC 0x00000001 /* storage pointer is to allocated memory */ #define STR_DSC_FLAG_STORAGE 0x00000002 /* storage pointer is to storage external to the descriptor */ #define STR_DSC_FLAG_EXTERNAL 0x00000004 /* descriptor is a 'collection' (list) of discrete buffers */ #define STR_DSC_FLAG_COLLECTION 0x00000008 /* descriptor storage has been frozen (allocate another) */ #define STR_DSC_FLAG_FROZEN 0x00000100 /* descriptor storage has been 'noted' in some way */ #define STR_DSC_FLAG_NOTED 0x00000200 /* bits to indicate flags are actually flags (perhaps :-) */ #define STR_DSC_FLAG_FLAG 0x0aa00000 /**********/ /* macros */ /**********/ /* check if this structure makes sense */ #define STR_DSC_SANITY(ptr) \ (((ptr)->itself == ((STR_DSC*)~(unsigned long)ptr)) && \ (((ptr)->flags & STR_DSC_FLAG_FLAG) == STR_DSC_FLAG_FLAG) && \ !((ptr)->flags & ~(STR_DSC_FLAG_FLAG | \ STR_DSC_FLAG_DYNAMIC | \ STR_DSC_FLAG_STORAGE | \ STR_DSC_FLAG_EXTERNAL | \ STR_DSC_FLAG_COLLECTION | \ STR_DSC_FLAG_FROZEN | \ STR_DSC_FLAG_NOTED)) && \ !(((ptr)->flags & STR_DSC_FLAG_STORAGE) && \ ((ptr)->flags & STR_DSC_FLAG_EXTERNAL))) /* for descriptors allocated on automatic storage (function stack) */ #define STR_DSC_AUTO(name) STR_DSC name = { 0, 0, 0, 0, 0, 0, 0, 0, 0 } #define STR_DSC_FLAGS(ptr) ((ptr)->flags) #define STR_DSC_LEN(ptr) ((ptr)->length) #define STR_DSC_NEXT(ptr) ((ptr)->flink) #define STR_DSC_SIZE(ptr) ((ptr)->size) #define STR_DSC_PREV(ptr) ((ptr)->blink) #define STR_DSC_PTR(ptr) ((ptr)->pointer) #define STR_DSC_RQPTR(ptr) ((ptr)->rqptr) #define STR_DSC_ZERO(ptr) { memset(ptr,0,sizeof(STR_DSC)); } /* grow the allocated memory by this amount when required */ #define STR_DSC_REALLOC(ptr,grow) (ptr)->realloc = grow; #define STR_DSC_GROW(ptr,grow) (ptr)->realloc = grow; /* set/test if the descriptor is frozen */ #define STR_DSC_IS_FROZEN(ptr) ((ptr)->flags & STR_DSC_FLAG_FROZEN) #define STR_DSC_SET_FROZEN(ptr) (ptr)->flags |= STR_DSC_FLAG_FROZEN; /* if the descriptor is using storage external to itself */ #define STR_DSC_IS_EXTERNAL(ptr) ((ptr)->flags & STR_DSC_FLAG_EXTERNAL) /* if the descriptor is 'noted' in some way */ #define STR_DSC_IS_NOTED(ptr) ((ptr)->flags & STR_DSC_FLAG_NOTED) #define STR_DSC_SET_NOTED(ptr) (ptr)->flags |= STR_DSC_FLAG_NOTED; #define STR_DSC_RESET_NOTED(ptr) (ptr)->flags &= ~STR_DSC_FLAG_NOTED; #define STR_DSC_DEFAULT_SIZE 256 /* wrapper on a simple for(;;) loop */ #define STR_DSC_ITERATE(ptr,dsc) for(ptr=dsc;ptr;ptr=ptr->flink) /***********************/ /* function prototypes */ /***********************/ STR_DSC* StrDscBegin (REQUEST_STRUCT*, STR_DSC*, int); STR_DSC* StrDscBuffer (STR_DSC*); STR_DSC* StrDscBuild (STR_DSC*, STR_DSC*, char*); STR_DSC* StrDscBuildHtmlEscape (STR_DSC*, STR_DSC*, char*); StrDscChunk (STR_DSC*, int); STR_DSC* StrDscChunkNew (REQUEST_STRUCT*, int); STR_DSC* StrDscColIfNotBegin (REQUEST_STRUCT*, STR_DSC*, int); StrDscDebug (STR_DSC*, char*); StrDscEnd (STR_DSC*, char*, int); STR_DSC* StrDscDup (STR_DSC*, STR_DSC*); STR_DSC* StrDscExternal (REQUEST_STRUCT*, STR_DSC*, char*, int); STR_DSC* StrDscFreeze (STR_DSC*); STR_DSC* StrDscIfNotBegin (REQUEST_STRUCT*, STR_DSC*, int); int StrDscLength (STR_DSC*); STR_DSC* StrDscNewLine (STR_DSC*); StrDscNoContent (STR_DSC*); int StrDscRealloc (REQUEST_STRUCT*, STR_DSC*, int, char*, int); BOOL StrDscSame (STR_DSC*, STR_DSC*, BOOL); StrDscSwap (STR_DSC*, STR_DSC*); StrDscStorageSwap (STR_DSC*, STR_DSC*); STR_DSC* StrDscTail (STR_DSC*); STR_DSC* StrDscTailFrozen (STR_DSC*); STR_DSC* StrDscText (REQUEST_STRUCT*, STR_DSC*, char*, int); STR_DSC* StrDscThis (REQUEST_STRUCT*, STR_DSC*, char*, int); StrDscWatchNotHeap (char*, int); void StrDscZero (STR_DSC*); #endif /* STRDSC_H_LOADED */ /*****************************************************************************/