home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 10 / Fresh_Fish_10_2352.bin / new / dev / lang / sgmls / src / traceset.c < prev    next >
C/C++ Source or Header  |  1994-07-10  |  16KB  |  463 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, %lu:%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, %lu:%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