[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]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164]
[0165]
[0166]
[0167]
[0168]
[0169]
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184]
[0185]
[0186]
[0187]
[0188]
[0189]
[0190]
[0191]
[0192]
[0193]
[0194]
[0195]
[0196]
[0197]
[0198]
[0199]
[0200]
[0201]
[0202]
[0203]
[0204]
[0205]
[0206]
[0207]
[0208]
[0209]
[0210]
[0211]
[0212]
[0213]
[0214]
[0215]
[0216]
[0217]
[0218]
[0219]
[0220]
[0221]
[0222]
[0223]
[0224]
[0225]
[0226]
[0227]
[0228]
[0229]
[0230]
[0231]
[0232]
[0233]
[0234]
[0235]
[0236]
[0237]
[0238]
[0239]
[0240]
[0241]
[0242]
[0243]
[0244]
[0245]
[0246]
[0247]
[0248]
[0249]
[0250]
[0251]
[0252]
[0253]
[0254]
[0255]
[0256]
[0257]
[0258]
[0259]
[0260]
[0261]
[0262]
[0263]
[0264]
[0265]
[0266]
[0267]
[0268]
[0269]
[0270]
[0271]
[0272]
[0273]
[0274]
[0275]
[0276]
[0277]
[0278]
[0279]
[0280]
[0281]
[0282]
[0283]
[0284]
[0285]
[0286]
[0287]
[0288]
[0289]
[0290]
[0291]
[0292]
[0293]
[0294]
[0295]
[0296]
[0297]
[0298]
[0299]
[0300]
[0301]
[0302]
[0303]
[0304]
[0305]
[0306]
[0307]
[0308]
[0309]
[0310]
[0311]
[0312]
[0313]
[0314]
[0315]
[0316]
[0317]
[0318]
[0319]
[0320]
[0321]
[0322]
[0323]
[0324]
[0325]
[0326]
[0327]
[0328]
[0329]
[0330]
[0331]
[0332]
[0333]
[0334]
[0335]
[0336]
[0337]
[0338]
[0339]
[0340]
[0341]
[0342]
[0343]
[0344]
[0345]
[0346]
[0347]
[0348]
[0349]
[0350]
[0351]
[0352]
[0353]
[0354]
[0355]
[0356]
[0357]
[0358]
[0359]
[0360]
[0361]
[0362]
[0363]
[0364]
[0365]
[0366]
[0367]
[0368]
[0369]
[0370]
[0371]
[0372]
[0373]
[0374]
[0375]
[0376]
[0377]
[0378]
[0379]
[0380]
[0381]
[0382]
[0383]
[0384]
[0385]
[0386]
[0387]
[0388]
[0389]
[0390]
[0391]
[0392]
[0393]
[0394]
[0395]
[0396]
[0397]
[0398]
[0399]
[0400]
[0401]
[0402]
[0403]
[0404]
[0405]
[0406]
[0407]
[0408]
[0409]
[0410]
[0411]
[0412]
[0413]
[0414]
#ifndef WASDOC_H
#define WASDOC_H

#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <ints.h>
#include <memory.h>
#include <string.h>
#include <stat.h>
#include <time.h>
#include <types.h>
#include <unistd.h>

#include <libdtdef.h>
#include <lib$routines.h>
#include <ssdef.h>
#include <stsdef.h>

#ifndef __VAX
#include <iosbdef.h>
#else
#include <iosbdef4vax.h>
#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 "&#8617;&#xFE0E;"
#define DEFAULT_ICON_FORW "&#8618;&#xFE0E;"
#define DEFAULT_ICON_NEXT "&#8600;&#xFE0E;"
#define DEFAULT_ICON_PREV "&#8598;&#xFE0E;"
#define DEFAULT_ICON_TOP  "&#8593;&#xFE0E;"

#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 <h1> */
        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. "</p>") */
         *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);

int CliCheckDir (char*);
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 */