home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / linuxdoc-sgml-1.1 / sgmls-1.1 / traceset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  15.6 KB  |  466 lines

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