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

  1. /*****************************************************************************/
  2. /* SGMLAPI: SGML API for C                                                   */
  3. /* Author: Charles F. Goldfarb                                               */
  4. /******************************************************************************/
  5. #include "sgmlapi.h"          /* Text processor header for SGML interfacing. */
  6. #include "vmincl.h"           /* Include files for VM. */
  7. #include "vmxtrn.h"           /* Declarations for VM public variables. */
  8. /******************************************************************************/
  9. struct rcbde de = {0};        /* RCB for current data entity information. */
  10. struct rcbte te = {0};        /* RCB for calls to SGMLAPI (TP+ENV). */
  11. UNCH sgmlomsg[] =             /* Text for invalid option error message. */
  12.      "/d /e /f /g /mSGML.MSG /p1 /r /t3";
  13. /******************************************************************************/
  14. /* Secret public variable for use by markup validator (not in SGMLAPI.H). */
  15. int TPisVM = 0;               /* Set to 1 by TP if it is markup validator. */
  16. /******************************************************************************/
  17. void alset(struct ad *);      /* Set up to start processing att list. */
  18. void setndata(PNE);           /* Build ext data entity rcbde with entity text.*/
  19. /******************************************************************************/
  20. /* SGMLNEXT: Get the next RCB from SGML and transfer data to local variables.
  21. */
  22. int sgmlnext(void)
  23. {
  24.      loop:
  25.      sgml((struct ipbt *)0);
  26.      if (!suppsw)
  27.           getscbs(SGMLSCBS, SGMLES);
  28.      switch (RCBTYPE) {
  29.      case SGMLDAF:            /* Data found. */
  30.           if (suppsw) goto loop;
  31.           te.datalen = CDATALEN;
  32.           te.data = CDATA;
  33.           if (CDESW) return (TPCDATA);
  34.           /* else */ if (SDESW) return (TPSDATA);
  35.           /* else */ if (NDESW) {setndata(NEPTR); return(TPNDATA);}
  36.           /* else */ if (*te.data==tpsw.delnonch) {
  37.                te.nonsgml = te.data[1]-tpsw.addnonch;
  38.                return(TPNSGML);
  39.           }
  40.           /* else */ return(TPPCDATA);
  41.  
  42.      case SGMLSTG:            /* Start-tag found. */
  43.           memcpy( &tptags[++tpts][0] , GI, (UNS)*(GI-1) ); /* Stack the GI. */
  44.           if (suppsw) goto loop;
  45.           te.data = GI;
  46.           te.datalen = *(GI-1)-2;
  47.           te.gidata = GIDATA;
  48. #ifdef V2
  49.           te.format = FORMAT;
  50. #endif
  51.           if (ALPTR) {             /* Tag attributes will be processed. */
  52.                alptr = ALPTR;      /* Tag attributes are active att list. */
  53.                te.alcnt = AN;      /* Indicate number of attributes in list. */
  54.                te.pca = &te.ca;    /* Current attribute structure in rcbte. */
  55.                alset((struct ad *)0); /* Initialize for alnext processing. */
  56.           }
  57.           else te.alcnt = 0;
  58.           return(TPSTAG);
  59.  
  60.      case SGMLETG:            /* End-tag found. */
  61.           --tpts;             /* Destack the GI. */
  62.           if (suppsw) goto loop;
  63.           te.data = GI;
  64.           te.datalen = *(GI-1)-2;
  65.           te.gidata = GIDATA;
  66. #ifdef V2
  67.           te.format = FORMAT;
  68. #endif
  69.           return(TPETAG);
  70.  
  71.      case SGMLPIS:            /* Processing instruction: string. */
  72.           if (suppsw) goto loop;
  73.           te.datalen = PDATALEN;
  74.           te.data = PDATA;
  75.           return(PIESW ? TPPIENT : TPPI);
  76.  
  77.      case SGMLREF:            /* Record end found. */
  78.           if (suppsw) goto loop;
  79.           return(TPRE);
  80.  
  81.      case SGMLSDTD:           /* Document type definition started. */
  82.           eltrsw = 0;         /* Suppress GI stack trace in messages. */
  83.           if (!TPisVM || suppsw) goto loop;
  84.           te.datalen = DTYPELEN-2;
  85.           te.data = DOCTYPE+1;
  86.           return(TPSDTD);
  87.  
  88.      case SGMLEDTD:           /* Document type definition completed. */
  89.           eltrsw = eltrsv;    /* Restore GI stack trace in messages. */
  90.           if (suppsw) goto loop;
  91.           te.datalen = DTYPELEN-2;
  92.           te.data = DOCTYPE+1;
  93.           return(TPEDTD);
  94.  
  95.      case SGMLMV:             /* Markup validator information. */
  96.           if (!TPisVM) goto loop;
  97.           /* else */ return(TPMV);
  98.  
  99.      case SGMLEOD:            /* End of document. */
  100.           return(TPEOD);
  101.      }
  102.      return(TPEOD);           /* Avoid lint and TurboC warnings. */
  103. }
  104. /******************************************************************************/
  105. #include "sgmlsubs.c"         /* Subroutines for SGML API. */
  106. /******************************************************************************/
  107.