      SUBROUTINE PC.INCLUDE.SUB(OBJ)
*PRE-COMPILER
*
*DEV TRIAL RT
*BASIC
*N
*     PRECISION 6
*
************************************************************************
************************************************************************
***                                                                  ***
*** PICK PARSING PRE-COMPILER SYSTEM                                 ***
***                                                                  ***
*** COPYRIGHT 1988 MODULAR SOFTWARE                                  ***
***                P.O. BOX 204                                      ***
***                ATLANTA, GA  30291                                ***
***                (404) 964 - 7171                                  ***
***                                                                  ***
*** THIS PROGRAM IS PROPRIETARY TO MODULAR SOFTWARE AND MAY NOT BE   ***
*** USED, COPIED, EXAMINED, OR DISCLOSED WITHOUT A VALID LICENSE     ***
*** FROM MODULAR SOFTWARE.                                           ***
***                                                                  ***
************************************************************************
************************************************************************
*
*
* Subroutine to process INCLUDE and CHAIN type statements
*
* {$}INCLUDE {file} item
* {$}INSERT {file} item
* $CHAIN {file} item
*
* {$}INCLUDE item {FROM file}
* {$}INSERT item {FROM file}
* $CHAIN item {FROM file}
*
      $INCLUDE PC.COMMON
*
      IF INCLUDE.OPT THEN
         INCL.ID = 'INCL.' : PORT : '.' : PGM.NO : '.' : INCL.NO
         P.OBJ = INCLUDE.STR : ' ' : INCL.ID
         INCL.NO = INCL.NO + 1
      END
*
      INC.FLG = NO
      OO = ''
*
      I1 = DCOUNT(OBJ<1,1>,SVM)
      FOR I = I1 TO 1 STEP -1
         IF OBJ<1,1,I> = '' THEN
            OBJ = DELETE(OBJ,1,1,I)
         END
      NEXT I
*
      I.W = OCONV(OBJ<1,1,1>,'MCU')
      IF I.W = 'INCLUDE' OR I.W = '$INCLUDE' OR I.W = 'INSERT' OR I.W = '$INSERT' OR I.W = '$CHAIN' THEN
*
* Load the INC.PARM variable with each 'WORD' from the remaining
* include statement
*
         INC.CNT = 1
         INC.PARM = ''
*
         I1 = DCOUNT(OBJ<1,1>,SVM)
         FOR I = 1 TO I1
            BEGIN CASE
               CASE OBJ<1,1,I> = ''
               CASE TRIM(OBJ<1,1,I>) = ''
                  IF INC.PARM<INC.CNT> <> '' THEN
                     INC.CNT = INC.CNT + 1
                  END
               CASE YES
                  INC.PARM<INC.CNT> = INC.PARM<INC.CNT> : OBJ<1,1,I>
            END CASE
         NEXT I
*
         INC.FLG = YES
         BEGIN CASE
            CASE INC.PARM<1> <> 'INCLUDE' AND INC.PARM<1> <> '$INCLUDE' AND INC.PARM<1> <> 'INSERT' AND INC.PARM<1> <> '$INSERT' AND INC.PARM<1> <> '$CHAIN'
               INC.FLG = NO
            CASE DCOUNT(INC.PARM,AM) = 2
               INC.FILE = ''
               INC.ITEM = INC.PARM<2>
            CASE DCOUNT(INC.PARM,AM) = 3
               INC.FILE = INC.PARM<2>
               INC.ITEM = INC.PARM<3>
            CASE DCOUNT(INC.PARM,AM) = 4
               BEGIN CASE
                  CASE INC.PARM<3> = 'FROM'
                     INC.FILE = INC.PARM<4>
                     INC.ITEM = INC.PARM<2>
                  CASE YES
                     INC.FLG = NO
               END CASE
            CASE YES
               INC.FLG = NO
         END CASE
*
         IF INC.FLG THEN
*
            IF INCLUDE.OPT THEN
               CALL PC.1(INC.FILE,INC.ITEM,INCL.ID)
            END ELSE
*
               IF INC.FILE = '' THEN
                  READ INCL.DATA FROM SRC.FD , INC.ITEM ELSE
                     PRINT
                     CALL PC.PRINT("*** INCLUDE/INSERT/CHAIN item '" : INC.ITEM : "' not on file ***")
                     ERROR = YES
                  END
               END ELSE
                  OPEN INC.FILE TO INCL.FD THEN
                     READ INCL.DATA FROM INCL.FD , INC.ITEM ELSE
                        PRINT
                        CALL PC.PRINT("*** INCLUDE/INSERT/CHAIN item '" : INC.ITEM : "' not on file ***")
                        ERROR = YES
                     END
                  END ELSE
                     PRINT
                     CALL PC.PRINT("*** Unable to open '" : INC.FILE : "' INCLUDE/INSERT/CHAIN file ***")
                     ERROR = YES
                  END
               END
*
               IF NOT(ERROR) THEN
                  IF I.W = '$CHAIN' THEN
                     IF INC.FILE <> '' THEN
                        CHAIN.ID = INC.ITEM
                        CHAIN.FILE = INC.FILE
                     END ELSE
                        CHAIN.ID = INC.ITEM
                        CHAIN.FILE = ''
                     END
                  END
*
                  I1 = DCOUNT(INCL.DATA,AM)
                  FOR I = 1 TO I1 UNTIL CHAIN.ID # '' OR ERROR
                     IF NOT(MOD(I,10)) THEN
                        PRINT CR : LINE.NO(RECUR.LEVEL) 'R#4' : ' ' : I 'R#4' :
                     END
                     OBJ = INCL.DATA<I>
                     OBJ = OBJ[INDEX(OBJ,TRIM(OBJ)[1,1],1),32000]
                     C$$$ = TRIM(OBJ)[LEN(TRIM(OBJ)),1]
                     OBJ = OBJ[1,INDEX(OBJ,C$$$,COUNT(OBJ,C$$$))]
                     BEGIN CASE
                        CASE OBJ[1,1] = '*'
                        CASE OBJ[1,1] = '!'
                        CASE OBJ[1,3] = 'REM'
                        CASE YES
                           IF INDEX(OBJ,'INCLUDE',1) OR INDEX(OBJ,'INSERT',1) THEN
                              CALL PC.INCLUDE(OBJ)
                           END ELSE
                              S = OBJ
                              CALL PC.PARSE.ALT(S,OBJ)
                              CALL PC.THEN(OBJ)
                           END
                           J1 = DCOUNT(OBJ,AM)
                           FOR J = 1 TO J1
                              S = OBJ<J>
                              CALL PC.PARSE.ALT(S,I.OBJ)
                              IF I.OBJ <> '*' THEN
                                 OO<-1> = I.OBJ
                              END
                           NEXT J
                     END CASE
                  NEXT I
               END
            END
            PRINT CR : LINE.NO(RECUR.LEVEL) 'R#4' : SPACE(5) :
         END
      END ELSE
         IF OBJ<1,2> <> '' THEN
            OO<-1> = OBJ<1,2> : ' ' : OBJ<1,1>
         END ELSE
            OO<-1> = OBJ
         END
      END
*
      IF INCLUDE.OPT AND INC.FLG THEN
         OBJ = P.OBJ
      END ELSE
         OBJ = OO
      END
*
      RETURN
*
      CW = '(C) Copyright 1985-1989 Modular Software.  All rights reserved.'
   END
