#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 8192 #define CGIPLUS_DOCS_MAX 32 #define DEFAULT_FILE_TYPE ".wasdoc" #define DEFAULT_TOC_SCHEMA "1" #define DEFAULT_TOC2 1 #define DEFAULT_TOC_COLS 2 #define DEFAULT_IDX_COLS 2 #define DEFAULT_NAVIGATE 2 #define DEFAULT_PAGINATE 1 #define DEFAULT_ICON_BACK "↩︎" #define DEFAULT_ICON_FORW "↪︎" #define DEFAULT_ICON_NEXT "↘︎" #define DEFAULT_ICON_PREV "↖︎" #define DEFAULT_ICON_TOP "↑︎" #define DEFAULT_NOTE "Note" #define CONDITION_MAX 8 #define FLAG_MAX 64 #define FRAGID_SIZE 256 #define SPAWN_LOGNAM "WASDOC_SPAWN" #define STACK_MAX 1024 /* initial HTML memory allocation more than the size of the text */ #define EXP_FACTOR 2.2 #define SUSPEND_SUSPEND 1 #define SUSPEND_DYNAMIC_STATIC 2 #define SUSPEND_SINGLE_MULTIPLE 3 #define SUSPEND_SERVER 4 #define TOCFLAG_EMPTY 0 #define TOCFLAG_NOTOC1 1 #define TOCFLAG_NOTOC2 2 #define TOCFLAG_NONE 3 #define TOCFLAG_FORCE2 4 #define TOCFLAG_XREF 9 #define NOTE_BEGIN 1 #define NOTE_HEADING 2 #define NOTE_TEXT 3 #define BFLAG_CENTER 0x01 #define FI_LI __FILE__,__LINE__ #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 ENDTAG(p1) \ (*(USHORTPTR)p1 == '||' || *(USHORTPTR)p1 == '|!' || \ *(USHORTPTR)p1 == '| ' || *(USHORTPTR)p1 == '|\n' || \ *(USHORTPTR)p1 == '|\t' || *(USHORTPTR)p1 == '|\0') 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 */ 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 */ hparse, /* location when parsing HTML */ hsize, /* size of HTML memory allocation */ hzsize, /* size before the 'zptr' triggers */ 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__ */ 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 */ setNavigate, /* navigation symbols top and bottom major sections */ setPaginate, /* automatic pagination */ setTabMargin, /* table margin indicator */ setToc2, /* secondary table of content after each

*/ 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 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, /* memory allocated for HTML */ *text; /* memory allocated for source text */ char dname [256], /* source file directory name */ fragid [FRAGID_SIZE], /* fragment supplied with request path */ 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 */ idxParam [256], /* parameter to |index|..| */ mainh [256], /* document main heading */ oname [128], /* name of file being output when chunked */ output [256], /* CLI output specification */ pinfo [256], /* path info (possibly munged) */ 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 CgiDoc (); 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* 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); 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*, char*); int renderInsertNote (struct wasdoc_st*); int renderInsertTag (struct wasdoc_st*, char*); int renderInsertText (struct wasdoc_st*, char*, int); 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); 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); int navig8AnchorHeadings (struct wasdoc_st*); int navig8Paginate (struct wasdoc_st*); char* navig8ChunkFrag (struct wasdoc_st*, int); int navig8ChunkOut (struct wasdoc_st*); char* navig8HeadingMain (char*, char*, int); char* navig8ChunkPath (struct wasdoc_st*, int); char* navig8GetHeadingId (char*, char*); int navig8Heading0 (char*); int navig8Heading9 (char*); char* navig8HeadingText (char*, char*, int); char* navig8IdFrag (char*, char*, int); int navig8Index (struct wasdoc_st*); int navig8InsertArrows (struct wasdoc_st*, int, int); char* navig8JustText (char*, char*, int); int navig8ReferAll (struct wasdoc_st*); int navig8ReferAt (struct wasdoc_st*, int); char* navig8ReferBackward (struct wasdoc_st*, char*); char* navig8ReferForward (struct wasdoc_st*, char*, int); int navig8ReferText (struct wasdoc_st*, char*, char*, int); int navig8RevertH (struct wasdoc_st*); char* navig8SkipHeadingId (char*); char* navig8Source (struct wasdoc_st*, char*); int navig8SubTOC (struct wasdoc_st*); int navig8TOC (struct wasdoc_st*); void dbugIf (char*, char*, int); char* dbugMax (char*); void dbugThis (char*, int, char*, ...); void wasDocStatistics (struct wasdoc_st*, int); int wasDocInsertAt (struct wasdoc_st*, int, int, char*, int); void wasDocInsertStatus (struct wasdoc_st*, int, int); int wasDocHtmlBuffer (struct wasdoc_st*, int); int wasDocHtmlCat (struct wasdoc_st*, char*, int); int wasDocHtmlPrint (struct wasdoc_st*, const char *, ...); void wasDocInsight (struct wasdoc_st*, char*, ...); void wasDocInsightAt (struct wasdoc_st*); int wasDocWrite (struct wasdoc_st*, char*, int); 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 */