//    MASTER
  /* This KIT reads headers directly from CMS files if no FILEDEF exists */
NEEDS "USINGCMS"


GET "NLIBHDR"

GLOBAL $(
USINGCMS:135                    // UUUUUUUUUUUUUUUUUUUUUUUU
CHBUF:300; PRSOURCE:310
PPTRACE:327; OPTION:328
FORMTREE:350; PLIST:352
TREEP:367; TREEVEC:368
CHARCODE:390; REPORTCOUNT:391; REPORTMAX:392
SOURCESTREAM:393; SYSPRINT:394; OCODE:395
UPPER:396      //  $$$$$
UNASKII:397 // $$$$$
COMPILEAE:245
SAVESPACESIZE:282
$)

LET CHARCODE(CH) = CH  // THE DEFAULT SETTING OF CHARCODE

AND EBCDICTOASCII(CH) = CH=21->#XA, ASKII(CH)
AND UNASKII(CH) = CH!TABLE
               #X00,#X01,#X02,#X03,#X37,#X2D,#X2E,#X2F,
               #X16,#X05,#X25,#X0B,#X0C,#X0D,#X0E,#X0F,
               #X10,#X11,#X12,#X13,#X3C,#X3D,#X32,#X26,
               #X18,#X19,#X3F,#X27,#X1C,#X1D,#X1E,#X1F,
               #X40,#X5A,#X7F,#X7B,#X5B,#X6C,#X50,#X7D,
               #X4D,#X5D,#X5C,#X4E,#X6B,#X60,#X4B,#X61,
               #XF0,#XF1,#XF2,#XF3,#XF4,#XF5,#XF6,#XF7,
               #XF8,#XF9,#X7A,#X5E,#X4C,#X7E,#X6E,#X6F,
               #X7C,#XC1,#XC2,#XC3,#XC4,#XC5,#XC6,#XC7,
               #XC8,#XC9,#XD1,#XD2,#XD3,#XD4,#XD5,#XD6,
               #XD7,#XD8,#XD9,#XE2,#XE3,#XE4,#XE5,#XE6,
               #XE7,#XE8,#XE9,#XAD,#XE0,#XBD,#X71,#X6D,
               #X79,#X81,#X82,#X83,#X84,#X85,#X86,#X87,
               #X88,#X89,#X91,#X92,#X93,#X94,#X95,#X96,
               #X97,#X98,#X99,#XA2,#XA3,#XA4,#XA5,#XA6,
               #XA7,#XA8,#XA9,#X8B,#X4F,#X9B,#X5F,#X07,
               #X00,#X01,#X02,#X03,#X37,#X2D,#X2E,#X2F,
               #X16,#X05,#X25,#X0B,#X0C,#X0D,#X0E,#X0F,
               #X10,#X11,#X12,#X13,#X3C,#X3D,#X32,#X26,
               #X18,#X19,#X3F,#X27,#X1C,#X1D,#X1E,#X1F,
               #X40,#X5A,#X7F,#X7B,#X5B,#X6C,#X50,#X7D,
               #X4D,#X5D,#X5C,#X4E,#X6B,#X60,#X4B,#X61,
               #XF0,#XF1,#XF2,#XF3,#XF4,#XF5,#XF6,#XF7,
               #XF8,#XF9,#X7A,#X5E,#X4C,#X7E,#X6E,#X6F,
               #X7C,#XC1,#XC2,#XC3,#XC4,#XC5,#XC6,#XC7,
               #XC8,#XC9,#XD1,#XD2,#XD3,#XD4,#XD5,#XD6,
               #XD7,#XD8,#XD9,#XE2,#XE3,#XE4,#XE5,#XE6,
               #XE7,#XE8,#XE9,#XAD,#XE0,#XBD,#X71,#X6D,
               #X79,#X81,#X82,#X83,#X84,#X85,#X86,#X87,
               #X88,#X89,#X91,#X92,#X93,#X94,#X95,#X96,
               #X97,#X98,#X99,#XA2,#XA3,#XA4,#XA5,#XA6,
               #XA7,#XA8,#XA9,#X8B,#X4F,#X9B,#X5F,#X07


 AND ASKII(C) = C!TABLE
   /* EBCDIC 00-07 */  #000, #001, #002, #003,    0, #011,    0, #177,
   /* EBCDIC 08-0F */     0,    0,    0, #013, #014, #015, #016, #017,
   /* EBCDIC 10-17 */  #020, #021, #022, #023,    0,    0, #010,    0,
   /* EBCDIC 18-1F */  #030, #031,    0,    0, #034, #035, #036, #037,
   /* EBCDIC 20-27 */     0,    0,    0,    0,    0, #012, #027, #033,
   /* EBCDIC 28-2F */     0,    0,    0,    0,    0, #005, #006, #007,
   /* EBCDIC 30-37 */     0,    0, #026,    0,    0,    0,    0, #004,
   /* EBCDIC 38-3F */     0,    0,    0,    0, #024, #025,    0, #032,
   /* EBCDIC 40-47 */  #040,    0,    0,    0,    0,    0,    0,    0,
   /* EBCDIC 48-4F */     0,    0,    0, #056, #074, #050, #053, #174,
   /* EBCDIC 50-57 */  #046,    0,    0,    0,    0,    0,    0,    0,
   /* EBCDIC 58-5F */     0,    0, #041, #044, #052, #051, #073, #176,
   /* EBCDIC 60-67 */  #055, #057,    0,    0,    0,    0,    0,    0,
   /* EBCDIC 68-6F */     0,    0,    0, #054, #045, #137, #076, #077,
   /* EBCDIC 70-77 */     0, #136,    0,    0,    0,    0,    0,    0,
   /* EBCDIC 78-7F */     0, #140, #072, #043, #100, #047, #075, #042,
   /* EBCDIC 80-87 */     0, #141, #142, #143, #144, #145, #146, #147,
   /* EBCDIC 88-8F */  #150, #151,    0, #173,    0,    0,    0,    0,
   /* EBCDIC 90-97 */     0, #152, #153, #154, #155, #156, #157, #160,
   /* EBCDIC 98-9F */  #161, #162,    0, #175,    0,    0,    0,    0,
   /* EBCDIC A0-A7 */     0,    0, #163, #164, #165, #166, #167, #170,
   /* EBCDIC A8-AF */  #171, #172,    0,    0,    0, #133,    0,    0,
   /* EBCDIC B0-B7 */     0,    0,    0,    0,    0,    0,    0,    0,
   /* EBCDIC B8-BF */     0,    0,    0,    0,    0, #135,    0,    0,
   /* EBCDIC C0-C7 */     0, #101, #102, #103, #104, #105, #106, #107,
   /* EBCDIC C8-CF */  #110, #111,    0,    0,    0,    0,    0,    0,
   /* EBCDIC D0-D7 */     0, #112, #113, #114, #115, #116, #117, #120,
   /* EBCDIC D8-DF */  #121, #122,    0,    0,    0,    0,    0,    0,
   /* EBCDIC E0-E7 */  #134,    0, #123, #124, #125, #126, #127, #130,
   /* EBCDIC E8-EF */  #131, #132,    0,    0,    0,    0,    0,    0,
   /* EBCDIC F0-F7 */  #060, #061, #062, #063, #064, #065, #066, #067,
   /* EBCDIC F8-FF */  #070, #071,    0,    0,    0,    0,    0, #134


AND UPPER360(CH) = 'a'<=CH<='z' -> CH LOGOR #X40, CH

AND UPPER(CH) = UPPER360(CH)    // FOR 360/370 COMPILATION

LET START(PARM) BE
$(1
USINGCMS(0)                  // UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
SYSPRINT := FINDOUTPUT("SYSPRINT")
SELECTOUTPUT(SYSPRINT)

WRITES("*NBCPL - RL 8086 Version")

$( LET OPT = VEC 20
   AND TREESIZE = 5500
   OPTION := OPT
   SAVESPACESIZE := 2
   PPTRACE := FALSE
   PRSOURCE := FALSE
   FOR I = 0 TO 20 DO OPT!I := FALSE

SOURCESTREAM := FINDINPUT("OPTIONS")

UNLESS SOURCESTREAM=0 DO
$(P LET CH = 0
    AND N = 0
    SELECTINPUT(SOURCESTREAM)
    WRITES("*NOPTIONS  ")

    $( CH := RDCH()
    L: IF CH='*N' LOGOR CH=ENDSTREAMCH BREAK
       WRCH(CH)
       IF CH='P' DO N := 1
       IF CH='T' DO N := 2
       IF CH='C' DO N := 3
       IF CH='M' DO N := 4
       IF CH='N' DO N := 5
       IF CH='O' DO N := 6
       IF CH='A' DO CHARCODE := EBCDICTOASCII
       IF CH='S' DO PRSOURCE := TRUE
       IF CH='E' DO PPTRACE := TRUE
       IF CH='L' DO  $( TREESIZE := READN()
                        WRITEN(TREESIZE)
                        CH := TERMINATOR
                        GOTO L  $)
       IF CH='Z' DO $( SAVESPACESIZE := READN()
                     WRITEN(SAVESPACESIZE)
                     CH := TERMINATOR
                     GOTO L $)
       OPTION!N := TRUE
                 $) REPEAT

    NEWLINE()
    ENDREAD()  $)P

   REPORTMAX := 20
   REPORTCOUNT := 0




SOURCESTREAM := FINDINPUT("SYSIN")
IF SOURCESTREAM=0 THEN $( WRITES("*NNO SOURCESTREAM CONNECTED -*
                                  * COMPILATION ABORTED")
                          STOP(8)
                       $)
SELECTINPUT(SOURCESTREAM)

OCODE := FINDOUTPUT("OCODE")
IF OCODE=0 DO OCODE := SYSPRINT
USINGCMS("BCPLHDR")                // UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

$(2 LET COMP(V, TREEMAX) BE
    $(C LET B = VEC 63
        CHBUF := B

      $(3 TREEP, TREEVEC := V+TREEMAX, V

        $( LET A = FORMTREE()
           IF A=0 BREAK

           WRITEF("*NTREE SIZE %N*N", TREEMAX+TREEVEC-TREEP)

           IF OPTION!2 DO $( WRITES('AE TREE*N')
                             PLIST(A, 0, 20)
                             NEWLINE()  $)


           UNLESS REPORTCOUNT=0 DO STOP(8)

           UNLESS OPTION!3 DO
                  $( SELECTOUTPUT(OCODE)
                     COMPILEAE(A)
                     SELECTOUTPUT(SYSPRINT)  $)

      $)3 REPEAT
    $)C

   APTOVEC(COMP, TREESIZE)

   ENDREAD()
   IF OPTION!4 DO MAPSTORE()
   WRITES('*NPHASE 1 COMPLETE*N')
   UNLESS REPORTCOUNT=0 DO STOP(8)
   STOP(0)   $)1         // UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
.