#ifndef WASDOC_H #define WASDOC_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __VAX #include #else #include #endif #ifdef __VAX #define EOVERFLOW 88 int vsnprintf(char *__s, __size_t __n, const char *__format, __va_list __ap); #endif #ifdef __VAX #define USE_INT64 0 #else #define USE_INT64 1 #endif #ifndef USHORTPTR #define USHORTPTR __unaligned ushort* #define ULONGPTR __unaligned ulong* #if USE_INT64 #define INT64PTR __unaligned __int64* #define UINT64PTR __unaligned unsigned __int64* #endif #endif /* demonstrated to be an order of magnitude faster than memcmp() */ #define MATCH0(ptr1,ptr2,len) (memcmp(ptr1,ptr2,len) == 0) #define MATCH1(ptr1,ptr2) (*(char*)(ptr1) == *(char*)(ptr2)) #define MATCH2(ptr1,ptr2) (*(USHORTPTR)(ptr1) == *(USHORTPTR)(ptr2)) #define MATCH3(ptr1,ptr2) ((*(ULONGPTR)(ptr1) & 0x00ffffff) == \ (*(ULONGPTR)(ptr2) & 0x00ffffff)) #define MATCH4(ptr1,ptr2) (*(ULONGPTR)(ptr1) == *(ULONGPTR)(ptr2)) #if USE_INT64 #define MATCH5(ptr1,ptr2) ((*(UINT64PTR)(ptr1) & 0x000000ffffffffff) == \ (*(UINT64PTR)(ptr2) & 0x000000ffffffffff)) #define MATCH6(ptr1,ptr2) ((*(UINT64PTR)(ptr1) & 0x0000ffffffffffff) == \ (*(UINT64PTR)(ptr2) & 0x0000ffffffffffff)) #define MATCH7(ptr1,ptr2) ((*(UINT64PTR)(ptr1) & 0x00ffffffffffffff) == \ (*(UINT64PTR)(ptr2) & 0x00ffffffffffffff)) #define MATCH8(ptr1,ptr2) (*(UINT64PTR)(ptr1) == *(UINT64PTR )(ptr2)) #else #define MATCH5(ptr1,ptr2) ((((ULONGPTR)(ptr1))[0] == ((ULONGPTR)(ptr2))[0]) && \ ((((ULONGPTR)(ptr1))[1] & 0x000000ff) == \ (((ULONGPTR)(ptr2))[1] & 0x000000ff))) #define MATCH6(ptr1,ptr2) ((((ULONGPTR)(ptr1))[0] == ((ULONGPTR)(ptr2))[0]) && \ ((((ULONGPTR)(ptr1))[1] & 0x0000ffff) == \ (((ULONGPTR)(ptr2))[1] & 0x0000ffff))) #define MATCH7(ptr1,ptr2) ((((ULONGPTR)(ptr1))[0] == ((ULONGPTR)(ptr2))[0]) && \ ((((ULONGPTR)(ptr1))[1] & 0x00ffffff) == \ (((ULONGPTR)(ptr2))[1] & 0x00ffffff))) #define MATCH8(ptr1,ptr2) ((((ULONGPTR)(ptr1))[0] == ((ULONGPTR)(ptr2))[0]) && \ (((ULONGPTR)(ptr1))[1] == ((ULONGPTR)(ptr2))[1])) #endif #define MATCH9(ptr1,ptr2) (MATCH8(ptr1,ptr2) && \ MATCH1(((char*)ptr1)+8,((char*)ptr2)+8)) #define MATCH10(ptr1,ptr2) (MATCH8(ptr1,ptr2) && \ MATCH2(((char*)ptr1)+8,((char*)ptr2)+8)) #define MATCH11(ptr1,ptr2) (MATCH8(ptr1,ptr2) && \ MATCH3(((char*)ptr1)+8,((char*)ptr2)+8)) #define MATCH12(ptr1,ptr2) (MATCH8(ptr1,ptr2) && \ MATCH4(((char*)ptr1)+8,((char*)ptr2)+8)) #define HTML_INCREMENT 32768 #define LIST_INCREMENT 16384 #define CGIPLUS_DOCS_MAX 32 #define DEFAULT_FILE_TYPE ".wasdoc" #define DEFAULT_IDX_COLS 2 #define DEFAULT_IDX_SORT 1 #define DEFAULT_NAVIGATE 2 #define DEFAULT_PAGINATE 1 #define DEFAULT_TOC_SCHEMA "1" #define DEFAULT_TOC2 1 #define DEFAULT_TOC2_COLS 2 #define DEFAULT_TOC_COLS 2 #define DEFAULT_ICON_BACK "↩︎" #define DEFAULT_ICON_FORW "↪︎" #define DEFAULT_ICON_NEXT "↘︎" #define DEFAULT_ICON_PREV "↖︎" #define DEFAULT_ICON_TOP "↑︎" #define DEFAULT_FOUND_IN " in " #define DEFAULT_NOTE "Note" /* upper then lower case characters used to collate the document index */ #define DEFAULT_COLLATE_EN \ "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz" #define CONDITION_MAX 8 #define FLAG_MAX 64 #define ACCESS_LOGNAM "WASDOC_ACCESS" #define SPAWN_LOGNAM "WASDOC_SPAWN" #define STACK_MAX 1024 /* ORed bits */ #define INSERT_ASIS 0x01 /* raw */ #define INSERT_HESC 0x02 /* escape HTML */ #define INSERT_BESC 0x04 /* backslash escape */ #define INSERT_ANID 0x08 /* alphnumeric ID */ #define NOTE_BEGIN 1 #define NOTE_HEADING 2 #define NOTE_TEXT 3 #define BFLAG_CENTER 0x01 /* sentinal values suppressing specified behaviours */ #define SECTION_NO_INDEX 998 #define SECTION_NOT_IN 999 #define FI_LI __FILE__,__LINE__ #define EXIT_FI_LI(status) \ { printf("%s:%d\n",FI_LI); fflush(stdout); exit(status); } #define SET_FI_LI(ptr) \ { ptr->fiptr = __FILE__; ptr->linum = __LINE__; } #define GOTO_FI_LI(ptr,target) \ { ptr->fiptr = __FILE__; ptr->linum = __LINE__; goto target; } #define RETURN_FI_LI(ptr,err) \ { ptr->fiptr = __FILE__; ptr->linum = __LINE__; return (err); } #define DOC_PUT(p1,p2,p3) { \ p1->hlength = p3 - p1->html; \ p1->tparse = p2 - p1->text; } #define DOC_TPUT(p1,p2) { \ p1->tparse = p2 - p1->text; } #define DOC_GET(p1,p2,p3,p4) { \ p2 = p1->text + p1->tparse; \ p3 = p1->html + p1->hlength; \ p4 = p1->html + p1->hzsize; } #define DOC_HTML(p1,p2,p3) { \ p2 = p1->html + p1->hlength; \ p3 = p1->html + p1->hzsize; } #define DOC_TGET(p1,p2) { \ p2 = p1->text + p1->tparse; } #define TPUT(p1,p2) { \ p1->tparse = p2 - p1->text; } #define TGET(p1,p2) { \ p2 = p1->text + p1->tparse; } #define HPUT(p1,p2) { \ p1->hlength = p2 - p1->html; } #define HGET(p1,p2) { \ p2 = p1->html + p1->hlength; } #define ENDTAG(p1) \ (*(USHORTPTR)p1 == '||' || *(USHORTPTR)p1 == '|!' || \ *(USHORTPTR)p1 == '| ' || *(USHORTPTR)p1 == '|\n' || \ *(USHORTPTR)p1 == '|\t' || *(USHORTPTR)p1 == '|\0') /* true if there is less than 20% of the buffer remaining */ #define HMORE(dptr) (dptr->hlength >= dptr->hmore) /* append one character to the HTML document */ #define HONE(dptr,aptr) dptr->html[dptr->hlength++] = *aptr++; struct wasdoc_st { int asis, /* source text rendered absolutely as-is */ bfindex, /* block flag stack index */ chunked, /* divide the document into chunks */ chunkTotal, /* total number of chunks in document */ clength, /* length pointed by chunk */ conLevel, /* index into conditional stack */ drawStyle, /* drawing style needs to be inserted */ errorValue, /* most recent error (VMS status) value */ finalH1, /* number of the final major section */ flagCount, /* number of flags currently set */ ftlength, /* source file type length */ ftotal, /* total files in source */ hlength, /* length of rendered HTML document */ hlength1, /* length of first pass HTML document */ hmore, /* length before more memory should be allocated */ hparse, /* location when parsing HTML */ hsize, /* size of HTML memory allocation */ insight, /* processing insightful :-) messages */ insight2doc, /* force CLI insights to document */ insightAt, /* insight@ has been enabled */ isDynamic, /* document is dynamic (CGI, CGIplus) */ isStatic, /* document is static (a file) */ linum, /* line number from __LINE__ */ llength, /* length of list of headings */ lsize, /* size of list of headings */ noescape, /* HTML escaping currently disabled */ notable, /* there is a note in-progress */ pchunk, /* trailing section number on path */ proLength, /* length of document prologue (e.g. style) */ rowlight, /* highlight alternate table rows from here-on */ setIdxCols, /* index in this many colums */ setIdxSort, /* sort index entries */ setNavigate, /* navigation symbols top and bottom major sections */ setPaginate, /* automatic pagination */ setTabMargin, /* table margin indicator */ setToc2, /* secondary table of content after each

*/ setToc2Cols, /* secondary table of content in this many colums */ setToc2ColsWidth, /* width of the columns (percentage) */ setToc2NextCols, /* number of the NEXT columns */ setToc2NextColsWidth, /* width of the NEXT columns (percentage) */ setTocCols, /* table of content in this many colums */ sourceFile, /* source file name has been output */ spawnAuth, /* <0 spawn is not allowed, >0 is allowed */ stindex, /* closure stack index */ styled, /* style sheet has been set */ table, /* '|' has special meaning inside a table */ tlength, /* length of source text */ tparse, /* location when parsing source text */ tsize; /* size of source text memory allocation */ int digit6 [1+6], /* working storage */ section [1+6]; /* heading counter 1..6 */ int conditional [1+CONDITION_MAX]; /* if-elif-else-endif */ char *chunk, /* pointer into the HTML when chunking */ *fiptr, /* pointer to __FILE__ */ *html, /* currently processed HTML */ *html1, /* HTML from first pass */ *list, /* list of headings */ *text; /* memory allocated for source text */ char dname [256], /* source file directory name */ ftype [64], /* source file type (e.g. ".text") */ iconBack [32], /* history back icon HTML entity */ iconForw [32], /* history forward icon HTML entity */ iconNext [32], /* next section icon HTML entity */ iconPrev [32], /* previous section icon HTML entity */ iconTop [32], /* top of document icon HTML entity */ idxCollate [256], /* upper and lower case characters to index */ idxParam [256], /* parameter to |index|..| */ oname [128], /* name of file being output when chunked */ output [256], /* CLI output specification */ pass2At [256], /* contains pass2 error location details */ pinfo [256], /* path info (possibly munged) */ setFoundIn [64], /* this "in" that */ setNote [64], /* default |note| heading */ setTocForm [256], /* table of content format */ statistics [128], /* resources expended conditioning */ title [128], /* document title */ tfname [96], /* source file name */ uri [256]; /* path to be included if chunked */ char *flags [FLAG_MAX], /* array of flag strings */ *cstack [STACK_MAX], /* stack of closure text (e.g. "

") */ *tstack [STACK_MAX]; /* stack of source text lines */ int bflag [STACK_MAX]; /* block of text flag (e.g. centered) */ ushort spawnMbx; /* channel to spawned output mailbox */ ulong spawnOutLength, /* length of process output buffer content */ spawnPID, /* PID of spawned subprocess */ spawnOutSize, /* size of process output buffer */ spawnOutStatus, /* subprocess output read status */ spawnStatus; /* spawned subprocess completion status */ char *spawnOutPtr; /* pointer to allocated memory buffer */ struct _iosb spawnIOsb; /* subprocess output read I/O status block */ }; void CgiAccess (struct wasdoc_st*); void CgiDoc (); int CgiNeedsUpdate (struct wasdoc_st*); void CgiRequest (); void CgiInitHTML (struct wasdoc_st*); int CgiWriteOut (char*, int); void CliDoc (int, char*[]); void CliOptions (int, char*[]); int CliWriteFile (struct wasdoc_st*, char*, int); void drawAdHoc (char*); char drawCharAbove (char*, char*, char*); char drawCharBelow (char*, char*, char*); char* drawReadFile (char*); char* drawDiagram (char*, int); char* drawStyle (); int drawThis (struct wasdoc_st*); char* drawDebugLine (char*); void* FreeDoc (struct wasdoc_st*); struct wasdoc_st* InitDoc (char*, char*, char*, char*); char* StatTimer (int); int ProcessDirectory (struct wasdoc_st*); int ProcessFile (struct wasdoc_st*, char*); char* renderBufferStyle (char*, char*, char*); int renderCondition (struct wasdoc_st*); int renderErrorReport (struct wasdoc_st*, char*, ...); char* renderFlag (struct wasdoc_st*, char*, int); void renderFragment (struct wasdoc_st*); int renderGetEscaped (char*, char*, int); int renderGetParam (struct wasdoc_st*, char*, int); char* renderGetSyi (struct wasdoc_st*, char*); int renderInsertHeading (struct wasdoc_st*); int renderInsertOther (struct wasdoc_st*, char*); int renderIncludeFile (struct wasdoc_st*, char*); int renderInsertFile (struct wasdoc_st*, char*, int); int renderInsertLink (struct wasdoc_st*, char*); int renderInsertLinkIn (struct wasdoc_st*, char*, int); int renderInsertNote (struct wasdoc_st*); int renderInsertTag (struct wasdoc_st*, char*); int renderInsertUrl (struct wasdoc_st*, char*); void renderInsightSource (struct wasdoc_st*, char*); void renderInsightTag (struct wasdoc_st*); void renderInsightStack (struct wasdoc_st*); char* renderLine (struct wasdoc_st*); char* renderLineEscape (char *tptr); char* renderNumericId (int*); int renderParse (struct wasdoc_st*); int renderSet (struct wasdoc_st*, char*); int renderStyle (struct wasdoc_st*, char*); char* renderSource (struct wasdoc_st*); char* renderTag (char *tptr); char* renderTrnLnm (struct wasdoc_st*, char*, int); void dbugIf (char*, char*, int); void wasDocAsIs (struct wasdoc_st*, char*); void wasDocBugcheck (char*, int); int wasDocChunkOut (struct wasdoc_st*); void wasDocEntify (struct wasdoc_st*, char*); void wasDocHtmlShuffle (struct wasdoc_st*); char* dbugAll (char*); char* dbugMax (char*); char* dbugString (char*, int); void dbugThis (char*, int, char*, ...); void wasDocStatistics (struct wasdoc_st*, int); void wasDocInsertStatus (struct wasdoc_st*, int); int wasDocPrintf (struct wasdoc_st*, const char *, ...); void wasDocInsight (struct wasdoc_st*, char*, ...); void wasDocInsightAt (struct wasdoc_st*); void wasDocMoreHtml (struct wasdoc_st*); void wasDocMoreFinal (struct wasdoc_st*); char* renderTrimWhite (struct wasdoc_st*); int wasDocWrite (struct wasdoc_st*, char*, int); int pass2 (struct wasdoc_st*); char* pass2chunk (struct wasdoc_st*, int); int pass2dollar2 (struct wasdoc_st*, char*); char* pass2entry (char*, int); int pass2extra (struct wasdoc_st*, char*); int pass2find (struct wasdoc_st*, char*); char* pass2foundin (struct wasdoc_st *docptr, char*); int pass2heading (struct wasdoc_st*, char*); int pass2idx (struct wasdoc_st *docptr); int pass2isort (const void*, const void*); int pass2link (struct wasdoc_st*, char*); char* pass2linkid (char*, char*); void pass2dlist (struct wasdoc_st*); void pass2list (struct wasdoc_st*); void pass2navigate (struct wasdoc_st*, int); int pass2noidx (char*); int pass2notin (char*); int pass2numeric (char*); char* pass2parent (char*); char* pass2strip (char*); int pass2toc1 (struct wasdoc_st*); int pass2toc2 (struct wasdoc_st*, char*); int spawnAuth (struct wasdoc_st*); int SpawnCommand (struct wasdoc_st*, char*, char*); void SpawnOutAst (struct wasdoc_st*); void SpawnWake (); int testCondition (struct wasdoc_st*, char*, char*); char* testMatch (struct wasdoc_st*, char*, char*); char* testRegex (struct wasdoc_st*, char*, char*); int testTime (struct wasdoc_st*, char*); int sys$gettim (void*); #endif /* WASDOC_H */