home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / compsci / arcsgm.cpt / ARC SGML 1.0 / sgmlc / traceset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  22.2 KB  |  628 lines

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