home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / sgml / unix / sgmlc / traceset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-03  |  19.7 KB  |  446 lines

  1. /******************************************************************************/
  2. /* C88 call to environ() replaced with call to (non-ANSI) getenv().           */
  3. /******************************************************************************/
  4. /* Traceend and tracegi: changed HITS to %08x.                                */
  5. /* TO DO: Revise all pointer formats (%04x) to work with far pointers also.   */
  6. /******************************************************************************/
  7. #include "sgmlincl.h"         /* #INCLUDE statements for SGML parser. */
  8. /******************************************************************************/
  9. /*lint -library                  Ignore failure to use library functions. */
  10. #include <stdio.h>            /* Stream I/O functions. */
  11. /*lint -restore                  End of library function declarations. */
  12. /******************************************************************************/
  13. /* Trace variables.
  14. */
  15. int  trace = 0;               /* Switch: 1=trace state transitions; 0=don't. */
  16. int atrace = 0;               /* Switch: 1=trace attribute activity; 0=don't. */
  17. int ctrace = 0;               /* Switch: 1=trace context checking; 0=don't. */
  18. int dtrace = 0;               /* Switch: 1=trace declaration parsing; 0=don't.*/
  19. int etrace = 0;               /* Switch: 1=trace entity activity; 0=don't.*/
  20. int gtrace = 0;               /* Switch: 1=trace group creations; 0=don't. */
  21. int itrace = 0;               /* Switch: 1=trace ID activity; 0=don't. */
  22. int mtrace = 0;               /* Switch: 1=trace MS activity; 0=don't. */
  23. int ntrace = 0;               /* Switch: 1=trace notation activity; 0=don't. */
  24. UNCH emd[] = "EMD";           /* For "EMD" parameter type in dtrace calls. */
  25. UNCH estype1[] =              /* For estore values in trace messages. */
  26.      " TMMMSEIXCNFPDLK";
  27. UNCH estype2[] =              /* For estore values in trace messages. */
  28.      "  DS            ";
  29. /******************************************************************************/
  30. #define TESTENV(name) (getenv(name)!=0)
  31. /******************************************************************************/
  32. /* TRACESET: Set switches for tracing body of document.
  33.              If any environment value has been
  34.              set for a switch, the switch is set to 1.
  35. */
  36. void traceset()
  37. {
  38.       trace = TESTENV("T");
  39.      atrace = TESTENV("A");
  40.      ctrace = TESTENV("C");
  41.      dtrace = TESTENV("D");
  42.      etrace = TESTENV("E");
  43.      gtrace = TESTENV("G");
  44.      itrace = TESTENV("I");
  45.      mtrace = TESTENV("M");
  46.      ntrace = TESTENV("N");
  47.  
  48.      if (trace||atrace||ctrace||dtrace||etrace||gtrace||itrace||mtrace||ntrace)
  49.           printf(
  50. "\nTRACESET: state=%d;att=%d;con=%d;dcl=%d;ent=%d;grp=%d;id=%d;ms=%d;dcn=%d.",
  51.              trace,   atrace,ctrace,dtrace,etrace,gtrace,itrace,mtrace,ntrace);
  52. }
  53. /******************************************************************************/
  54. /* TRACEPRO: Set switches for tracing prolog.  If any environment value has been
  55.              set for a switch, the switch is set to 1.
  56. */
  57. void tracepro()
  58. {
  59.       trace = TESTENV("PT");
  60.      atrace = TESTENV("PA");
  61.      dtrace = TESTENV("PD");
  62.      etrace = TESTENV("PE");
  63.      gtrace = TESTENV("PG");
  64.      mtrace = TESTENV("PM");
  65.      ntrace = TESTENV("PN");
  66.  
  67.      if (trace||atrace||dtrace||etrace||gtrace||mtrace||ntrace) printf(
  68. "\nTRACEPRO: state=%d; att=%d; dcl=%d; ent=%d; grp=%d; ms=%d;  dcn=%d.",
  69.              trace,    atrace, dtrace, etrace, gtrace, mtrace, ntrace);
  70. }
  71. /******************************************************************************/
  72. /* TRACEPCB: Trace character just parsed and other pcb data.
  73. */
  74. void tracepcb(pcb)
  75. struct parse *pcb;
  76. {
  77.      printf ("\n%-8s %2u-%2u-%2u-%2u from %c [%3d] in %s, %d:%d.",
  78.             pcb->pname, pcb->state, pcb->input, pcb->action,
  79.             pcb->newstate, ZAPEOL(*FPOS), *FPOS, ENTITY+1, RCNT,
  80.             RSCC+FPOS+1-FBUF);
  81. }
  82. /******************************************************************************/
  83. /* TRACETKN: Trace character just read during token parse.
  84. */
  85. void tracetkn(scope, lextoke)
  86. int scope;
  87. UNCH lextoke[];               /* Lexical table for token and name parses. */
  88. {
  89.      printf("\nTOKEN    %2d-%2d       from %c [%3d] in %s, %d:%d.",
  90.             scope, lextoke[*FPOS],
  91.             ZAPEOL(*FPOS), *FPOS, ENTITY+1, RCNT,
  92.             RSCC+FPOS+1-FBUF);
  93. }
  94. /******************************************************************************/
  95. /* TRACEGML: Trace state of main SGML driver routine.
  96. */
  97. void tracegml(scb, pss, conactsw, conact)
  98. struct restate *scb;
  99. int pss, conactsw, conact;
  100. {
  101.   printf("\nSGML%02d   %2d-%2d-%2d-%2d in main driver; conactsw=%d; conact=%d.",
  102.          pss, scb[pss].sstate, scb[pss].sinput, scb[pss].saction,
  103.          scb[pss].snext, conactsw, conact);
  104. }
  105. /******************************************************************************/
  106. /* TRACEVAL: Trace parse of an attribute value that is a token list.
  107. */
  108. void traceval(pcb, atype, aval, tokencnt)
  109. struct parse *pcb;
  110. UNS atype;                    /* Type of token list expected. */
  111. UNCH *aval;                   /* Value string to be parsed as token list. */
  112. int tokencnt;                 /* Number of tokens found in attribute value. */
  113. {
  114.      printf("\n%-8s %2d-%2d-%2d-%2d at %04x, atype=%02x, tokencnt=%d: ",
  115.             pcb->pname, pcb->state, pcb->input, pcb->action,
  116.             pcb->newstate, aval, atype, tokencnt);
  117.      printf("%s", aval);
  118. }
  119. /******************************************************************************/
  120. /* TRACESTK: Trace entry just placed on tag stack.
  121. */
  122. void tracestk(pts, ts2, etictr)
  123. struct tag *pts;              /* Stack entry for this tag. */
  124. int ts2;                      /* Stack depth. */
  125. int etictr;                   /* Number of "netok" tags on stack. */
  126. {
  127.      printf("\nSTACK    %s begun; stack depth %d; tflag=%02x; etictr=%d",
  128.             pts->tetd->etdgi+1, ts2, pts->tflags, etictr);
  129.      printf(" srm=%s.", pts->tsrm!=SRMNULL ? pts->tsrm[0]->ename+1 : "#EMPTY");
  130. }
  131. /******************************************************************************/
  132. /* TRACEDSK: Trace entry just removed from tag stack.
  133. */
  134. void tracedsk(pts, ptso, ts3, etictr)
  135. struct tag *pts;              /* Stack entry for new open tag. */
  136. struct tag *ptso;             /* Stack entry for tag just ended. */
  137. int ts3;                      /* Stack depth. */
  138. int etictr;                   /* Number of "netok" tags on stack. */
  139. {
  140.      printf(
  141. "\nDESTACK  %s ended; otflag=%02x; %s resumed; depth=%d; tflag=%02x; etictr=%d",
  142.            ptso->tetd->etdgi+1, ptso->tflags,
  143.            pts->tetd->etdgi+1, ts3, pts->tflags, etictr);
  144.      printf(" srm=%s.", pts->tsrm!=SRMNULL ? pts->tsrm[0]->ename+1 : "#EMPTY");
  145. }
  146. /******************************************************************************/
  147. /* TRACECON: Trace interactions between content parse and stag/context
  148.              processing.
  149. */
  150. void tracecon(etagimct, dostag, datarc, pcb, conrefsw, didreq)
  151. int etagimct;                 /* Implicitly ended elements left on stack. */
  152. int dostag;                   /* 1=retry newetd instead of parsing; 0=parse. */
  153. int datarc;                   /* Return code for data: DAF_ or REF_ or zero. */
  154. struct parse *pcb;            /* Parse control block for this parse. */
  155. int conrefsw;                 /* 1=content reference att specified; 0=no. */
  156. int didreq;                   /* 1=required implied empty tag processed; 0=no.*/
  157. {
  158.      printf("\nCONTENT  etagimct=%d dostag=%d datarc=%d pname=%s action=%d \
  159. conrefsw=%d didreq=%d",
  160.            etagimct, dostag, datarc, pcb->pname, pcb->action, conrefsw, didreq);
  161. }
  162. /******************************************************************************/
  163. /* TRACESTG: Trace start-tag context validation input and results.
  164. */
  165. void tracestg(curetd, dataret, rc, nextetd, mexts)
  166. struct etd *curetd;           /* The etd for this tag. */
  167. int dataret;                  /* Data pending: DAF_ REF_ 0=not #PCDATA. */
  168. int rc;                       /* Return code from context or other test. */
  169. struct etd *nextetd;          /* The etd for a forced start-tag (if rc==2). */
  170. int mexts;                    /* >0=stack level of minus grp; -1=plus; 0=none.*/
  171. {
  172.     printf("\nSTARTTAG newetd=%04x; dataret=%d; rc=%d; nextetd=%04x; mexts=%d.",
  173.            curetd, dataret, rc, nextetd, mexts);
  174. }
  175. /******************************************************************************/
  176. /* TRACEETG: Trace end-tag matching test on stack.
  177. */
  178. void traceetg(pts, curetd, tsl, etagimct)
  179. struct tag *pts;              /* Stack entry for this tag. */
  180. struct etd *curetd;           /* The etd for this tag. */
  181. int tsl;                      /* Temporary stack level for looping. */
  182. int etagimct;                 /* Num of implicitly ended tags left on stack. */
  183. {
  184.      printf(
  185. "\nENDTAG   tsl=%d; newetd=%04x; stacketd=%04x; tflags=%02x; etagimct=%d.",
  186.             tsl, curetd, pts->tetd, pts->tflags, etagimct);
  187. }
  188. /******************************************************************************/
  189. /* TRACEECB: Trace entity control block activity.
  190. */
  191. void traceecb(action, p)
  192. UNCH *action;
  193. struct entity *p;
  194. {
  195.      printf("\n%-8s (es=%d) type %c%c entity %s at %04x containing ",
  196.            action, es, estype1[p->estore], estype2[p->estore], p->ename+1, p);
  197.      if (p->estore==ESS || p->estore==ESE) printf("%s tag.",
  198.           p->etx.e==ETDNULL ? "null" : p->etx.e->etdgi+1);
  199.      else if (p->estore==ESN && strcmp(action, "ENTDEF")) traceesn(p->etx.n);
  200.      else if (p->etx.x==0) printf("[NOTHING]");
  201.      else printf("%s", *(p->etx.c+1)  ? p->etx.c+1 : "[EMPTY]");
  202. }
  203. /******************************************************************************/
  204. /* TRACEDCN: Trace data content notation activity.
  205. */
  206. void tracedcn(p)
  207. struct dcncb *p;
  208. {
  209.      printf(
  210. "\nDCN      dcn=%04x; adl=%04x; notation is %s=>%s",
  211.             p, p->adl, p->ename+1,
  212.             (p->dcnid!=0) ? ((char *)p->dcnid)+1 : "[UNDEFINED]"
  213.      );
  214.      if (p->adl) traceadl(p->adl);
  215. }
  216. /******************************************************************************/
  217. /* TRACEESN: Print a data entity control block.
  218. */
  219. void traceesn(p)
  220. PNE p;
  221. {
  222.      printf("\nESN      Entity name is %s; entity type is %s.",
  223.             (NEENAME(p)!=0) ? ((STRING)NEENAME(p))+1 : "[UNDEFINED]",
  224.          /* NEXTYPE(p)); */
  225.             (NEXTYPE(p)==1 ? "CDATA" : (NEXTYPE(p)==2 ? "NDATA" : "SDATA")));
  226.      printf("\n         System ID is %s",
  227.             (NEID(p)!=0) ? ((STRING)NEID(p))+1 : "[UNDEFINED]");
  228.      if (p->nedcn!=0) tracedcn(p->nedcn);
  229. }
  230. /******************************************************************************/
  231. /* TRACESRM: Print the members of a short reference map.
  232. */
  233. void tracesrm(action, pg, gi)
  234. UNCH *action;
  235. TECB pg;
  236. UNCH *gi;
  237. {
  238.      int i = 0;               /* Loop counter. */
  239.  
  240.      if (pg==SRMNULL) printf("\n%-8s SHORTREF table empty for %s.", action, gi);
  241.      else {
  242.           printf("\n%-8s %s at %04x mapped for %s.",
  243.                  action, pg[0]->ename+1, pg, gi ? gi : "definition");
  244.           while (++i<=lex.s.dtb[0].mapdata) if (pg[i])
  245.                printf("\n%14s%02u %04x %s", "SR", i, pg[i], pg[i]->ename+1);
  246.      }
  247. }
  248. /******************************************************************************/
  249. /* TRACEADL: Print an attribute definition list.
  250. */
  251. void traceadl(al)
  252. struct ad al[];
  253. {
  254.      int i=0;
  255.  
  256.      printf("\nADLIST   %04x %d membe%s; %d attribut%s",
  257.            al, ADN, ADN==1 ? "r" : "rs", AN, AN==1 ? "e" : "es");
  258.      while (++i<=ADN) {
  259.           printf(
  260.                (BITOFF(ADFLAGS(i), AGROUP) && ADTYPE(i)<=ANOTEGRP)
  261.               ? "\n          %04x %-8s %02x %02x %2d %2d %04x %04x"
  262.               :       "\n    %04x %-8s %02x %02x %2d %2d %04x %04x ",
  263.                &al[i], ADNAME(i), ADFLAGS(i), ADTYPE(i), ADNUM(i),
  264.                ADLEN(i), ADVAL(i), ADDATA(i).x
  265.           );
  266.           if (ADVAL(i)) {
  267.           /*   write(stdout, ADVAL(i)+1, *ADVAL(i)-2); */
  268.                printf("%.*s", *ADVAL(i)-2, ADVAL(i)+1);
  269.                if (ADTYPE(i)==AENTITY && ADDATA(i).n!=0) {
  270.                     printf("=>");
  271.                     traceesn(ADDATA(i).n);
  272.                }
  273.                else if (ADTYPE(i)==ANOTEGRP)
  274.                     printf("=>%s", (ADDATA(i).x!=0) ?
  275.                           ((STRING)ADDATA(i).x)+1 : "[UNDEFINED]");
  276.           }
  277.           else printf("[%s]", GET(ADFLAGS(i), AREQ)     ? "REQUIRED" :
  278.                              (GET(ADFLAGS(i), ACURRENT) ? "CURRENT"  :
  279.                                                        "NULL"));
  280.      }
  281.     printf("\n");
  282. }
  283. /******************************************************************************/
  284. /* TRACEMOD: Print the members of a model.
  285. */
  286. void tracemod(pg)
  287. struct thdr pg[];
  288. {
  289.      int i=0;
  290.  
  291.      printf("\nMODEL    %04x %02x %d", &pg[0], pg[0].ttype, pg[0].tu.tnum);
  292.      while (++i <= pg[0].tu.tnum) {
  293.           if (GET(pg[i].ttype, TTMASK)==TTETD)
  294.                printf("\n                      %04x %02x %s",
  295.                       &pg[i], pg[i].ttype, pg[i].tu.thetd->etdgi+1);
  296.           else if (GET(pg[i].ttype, TTMASK)==TTCHARS)
  297.                printf("\n                      %04x %02x %s",
  298.                       &pg[i], pg[i].ttype, "#PCDATA");
  299.           else printf("\n         %04x %02x %d",
  300.                &pg[i], pg[i].ttype, pg[i].tu.tnum);
  301.      }
  302.      printf("\n");
  303. }
  304. /******************************************************************************/
  305. /* TRACEGRP: Print the members of a name (i.e., etd) group.
  306. */
  307. void tracegrp(pg)
  308. struct etd *pg[];
  309. {
  310.      int i = -1;              /* Loop counter. */
  311.  
  312.      printf("\nETDGRP   %04x", pg);
  313.      while (pg[++i]!=0) printf("\n         %04x %s", pg[i], pg[i]->etdgi+1);
  314. }
  315. /******************************************************************************/
  316. /* TRACENGR: Print the members of a notation (i.e., dcncb) group.
  317. */
  318. void tracengr(pg)
  319. struct dcncb *pg[];
  320. {
  321.      int i = -1;              /* Loop counter. */
  322.  
  323.      printf("\nDCNGRP   %04x", pg);
  324.      while (pg[++i]!=0) printf("\n         %04x %s", pg[i], pg[i]->ename+1);
  325. }
  326. /******************************************************************************/
  327. /* TRACEETD: Print an element type definition.
  328. */
  329. void traceetd(p)
  330. struct etd *p;                /* Pointer to an etd. */
  331. {
  332.      printf(
  333. "\nETD      etd=%04x %s min=%02x cmod=%04x ttype=%02x mex=%04x, pex=%04x, ",
  334.             p, p->etdgi+1, p->etdmin, p->etdmod,
  335.             p->etdmod->ttype, p->etdmex, p->etdpex
  336.      );
  337.      printf("adl=%04x, srm=%s.", p->adl,
  338.             (p->etdsrm==SRMNULL) ? "#EMPTY" : (p->etdsrm)
  339.                                  ? p->etdsrm[0]->ename+1 : "#CURRENT"
  340.      );
  341. }
  342. /******************************************************************************/
  343. /* TRACEID: Print an ID control block.
  344. */
  345. void traceid(action, p)
  346. UNCH *action;
  347. struct id *p;                 /* Pointer to an ID. */
  348. {
  349.      printf("\n%-8s %s at %04x is ", action, p->idname+1, p);
  350.      if (p->idl) printf("ID of %s in %s, %d:%d; ", p->idl->letdgi+1,
  351.                         p->idl->lename+1, p->idl->lrcnt, p->idl->lccnt);
  352.      else printf("an undefined ID; ");
  353.      printf("hits=%08lx last ref=%04x", idrefl, p->idrl);
  354. }
  355. /******************************************************************************/
  356. /* TRACEMD: Trace a markup declaration parameter.
  357. */
  358. void tracemd(parmid)
  359. UNCH *parmid;                 /* Parameter identifier. */
  360. {
  361.      printf("\nMDPARM   %-8s for %-8s, token %02d, type %02u, %s.",
  362.            mdname, subdcl ? subdcl : "[NONE]", parmno, pcbmd.action, parmid);
  363. }
  364. /******************************************************************************/
  365. /* TRACEMAP: Trace a map search.
  366. */
  367. void tracemap(mapnm, key, data)
  368. UNCH *mapnm;                  /* Name in map being searched. */
  369. UNCH *key;                    /* Search key. */
  370. int data;                     /* Data associated with key in map. */
  371. {
  372.      printf("\nMAPSRCH  %s == %-8s=>%d", key, mapnm, data);
  373. }
  374. /******************************************************************************/
  375. /* TRACEMS: Trace marked section activity.
  376. */
  377. void tracems(action, code, mslevel, msplevel)
  378. int action;                   /* 1=began new level; 0=resumed previous. */
  379. int code;
  380. int mslevel;                  /* Nesting level of marked sections. */
  381. int msplevel;                 /* Nested MS levels subject to special parse. */
  382. {
  383.      printf("\nMS%c      %2d                 %s nesting level %d (msp %d).",
  384.           (action ? ' ' : 'E'), code, (action ? "began" : "resumed"),
  385.           mslevel, msplevel);
  386. }
  387. /******************************************************************************/
  388. #define STATUX tags[ts].status/* Token status: RCHIT RCMISS RCEND RCREQ RCNREQ*/
  389. #define M      pos[0].g       /* Index of current token in model. */
  390. #define P      pos[0].t       /* Index of current group in pos. */
  391. #define G      pos[P].g       /* Index of current group in model. */
  392. #define T      pos[P].t       /* Index of current token in its group. */
  393. #define H      pos[P].h       /* Hit bits for current group's tokens (1=hit). */
  394. #define GHDR   mod[G]         /* Current group header. */
  395. #define TOKEN  mod[M]         /* Current token. */
  396. #define TTYPE (GET(TOKEN.ttype, TTMASK))  /* Token type of current token. */
  397. #define TOCC  (GET(TOKEN.ttype, TOREP))   /* Occurrence for current token. */
  398. #define GTYPE (GET(GHDR.ttype, TTMASK))   /* Token type of current group. */
  399. #define GOCC  (GET(GHDR.ttype, TOREP))    /* Occurrence for current group. */
  400. #define GNUM  GHDR.tu.tnum                /* Number of tokens in current grp. */
  401. /******************************************************************************/
  402. /* TRACEGI: Trace GI testing stages in CONTEXT.C processing.
  403. */
  404. void tracegi(stagenm, gi, mod, pos, Tstart)
  405. UNCH *stagenm;
  406. struct etd *gi;               /* ETD of new GI. */
  407. struct thdr mod[];            /* Model of current open element. */
  408. struct mpos pos[];            /* Position in open element's model. */
  409. int Tstart;                   /* Initial T for this group. */
  410. {
  411.      int i = 0;               /* Loop counter. */
  412.  
  413.      printf("\n%-10s %d:", stagenm, P);
  414.      while (++i<=P) printf(" %d-%d", pos[i].g, pos[i].t);
  415.      printf(" (%u) gocc=%02x gtype=%02x gnum=%d H=%08lx status=%d Tstart=%d",
  416.             M, GOCC, GTYPE, GNUM, H, STATUX, Tstart);
  417.      printf("\n=>%-8s tocc=%02x ttype=%02x thetd=%04x (%s) gietd=%04x (%s)",
  418.           tags[ts].tetd->etdgi+1, TOCC, TTYPE, TOKEN.tu.thetd,
  419.           (TTYPE ? (TTYPE==TTETD ? TOKEN.tu.thetd->etdgi+1 : "#GROUP")
  420.           : "#PCDATA"), gi, (gi==ETDCDATA ?  "#PCDATA" : gi->etdgi+1));
  421. }
  422. /******************************************************************************/
  423. /* TRACEEND: Trace testing for end of group in CONTEXT.C processing.
  424. */
  425. void traceend(stagenm, mod, pos, rc, opt, Tstart)
  426. UNCH *stagenm;
  427. struct thdr mod[];            /* Model of current open element. */
  428. struct mpos pos[];            /* Position in open element's model. */
  429. int rc;                       /* Return code: RCNREQ RCHIT RCMISS RCEND */
  430. int opt;                      /* ALLHIT parm: 1=test optionals; 0=ignore. */
  431. int Tstart;                   /* Initial T for this group. */
  432. {
  433.      int i = 0;               /* Loop counter. */
  434.  
  435.      printf("\n%-10s %d:", stagenm, P);
  436.      while (++i<=P) printf(" %d-%d", pos[i].g, pos[i].t);
  437.      printf(" (%u) gocc=%02x gtype=%02x gnum=%d H=%08lx status=%d Tstart=%d",
  438.             M, GOCC, GTYPE, GNUM, H, STATUX, Tstart);
  439.      printf("\n=>%-8s tocc=%02x ttype=%02x thetd=%04x (%s)",
  440.            tags[ts].tetd->etdgi+1, TOCC, TTYPE, TOKEN.tu.thetd, (TTYPE ?
  441.            (TTYPE==TTETD ? TOKEN.tu.thetd->etdgi+1 : "#GROUP") : "#PCDATA"));
  442.      printf(" rc=%d offbitT=%d allhit=%d",
  443.            rc, offbit(H, (int)T, GNUM), allhit(&GHDR, H, 0, opt));
  444. }
  445. /******************************************************************************/
  446.