PiDP-8/I Software

Hex Artifact Content
Log In

Artifact d89c73d611d83a379f142fb3d079cbe05725e33bfa48b501bd10445f6021e890:


0000: 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 40  #!/usr/bin/env @
0010: 50 59 43 4d 44 40 0a 23 20 2d 2a 2d 20 63 6f 64  PYCMD@.# -*- cod
0020: 69 6e 67 3a 20 75 74 66 2d 38 20 2d 2a 2d 0a 23  ing: utf-8 -*-.#
0030: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0040: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0050: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0060: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0070: 23 23 23 23 23 23 23 0a 23 20 73 69 6d 68 2d 6f  #######.# simh-o
0080: 73 38 2d 73 63 72 69 70 74 2e 70 79 20 4c 69 62  s8-script.py Lib
0090: 72 61 72 79 20 66 6f 72 20 73 63 72 69 70 74 69  rary for scripti
00a0: 6e 67 20 4f 53 2f 38 20 75 6e 64 65 72 20 53 49  ng OS/8 under SI
00b0: 4d 48 0a 23 20 43 6f 6e 74 61 69 6e 73 20 76 61  MH.# Contains va
00c0: 6c 69 64 61 74 6f 72 73 20 61 6e 64 20 63 61 6c  lidators and cal
00d0: 6c 65 72 73 20 66 6f 72 20 6f 73 38 20 61 6e 64  lers for os8 and
00e0: 20 73 69 6d 68 20 63 6f 6d 6d 61 6e 64 73 20 74   simh commands t
00f0: 6f 20 6d 61 6b 65 0a 23 20 69 74 20 65 61 73 69  o make.# it easi
0100: 65 72 20 74 6f 20 63 72 65 61 74 65 20 73 63 72  er to create scr
0110: 69 70 74 73 2e 0a 23 0a 23 20 43 6f 70 79 72 69  ipts..#.# Copyri
0120: 67 68 74 20 c2 a9 20 32 30 31 37 2d 32 30 31 39  ght © 2017-2019
0130: 20 62 79 20 4a 6f 6e 61 74 68 61 6e 20 54 72 69   by Jonathan Tri
0140: 74 65 73 2c 20 57 69 6c 6c 69 61 6d 20 43 61 74  tes, William Cat
0150: 74 65 79 2c 20 61 6e 64 0a 23 20 57 61 72 72 65  tey, and.# Warre
0160: 6e 20 59 6f 75 6e 67 2e 0a 23 0a 23 20 50 65 72  n Young..#.# Per
0170: 6d 69 73 73 69 6f 6e 20 69 73 20 68 65 72 65 62  mission is hereb
0180: 79 20 67 72 61 6e 74 65 64 2c 20 66 72 65 65 20  y granted, free 
0190: 6f 66 20 63 68 61 72 67 65 2c 20 74 6f 20 61 6e  of charge, to an
01a0: 79 20 70 65 72 73 6f 6e 20 6f 62 74 61 69 6e 69  y person obtaini
01b0: 6e 67 0a 23 20 61 20 63 6f 70 79 20 6f 66 20 74  ng.# a copy of t
01c0: 68 69 73 20 73 6f 66 74 77 61 72 65 20 61 6e 64  his software and
01d0: 20 61 73 73 6f 63 69 61 74 65 64 20 64 6f 63 75   associated docu
01e0: 6d 65 6e 74 61 74 69 6f 6e 20 66 69 6c 65 73 20  mentation files 
01f0: 28 74 68 65 0a 23 20 22 53 6f 66 74 77 61 72 65  (the.# "Software
0200: 22 29 2c 20 74 6f 20 64 65 61 6c 20 69 6e 20 74  "), to deal in t
0210: 68 65 20 53 6f 66 74 77 61 72 65 20 77 69 74 68  he Software with
0220: 6f 75 74 20 72 65 73 74 72 69 63 74 69 6f 6e 2c  out restriction,
0230: 20 69 6e 63 6c 75 64 69 6e 67 0a 23 20 77 69 74   including.# wit
0240: 68 6f 75 74 20 6c 69 6d 69 74 61 74 69 6f 6e 20  hout limitation 
0250: 74 68 65 20 72 69 67 68 74 73 20 74 6f 20 75 73  the rights to us
0260: 65 2c 20 63 6f 70 79 2c 20 6d 6f 64 69 66 79 2c  e, copy, modify,
0270: 20 6d 65 72 67 65 2c 20 70 75 62 6c 69 73 68 2c   merge, publish,
0280: 0a 23 20 64 69 73 74 72 69 62 75 74 65 2c 20 73  .# distribute, s
0290: 75 62 6c 69 63 65 6e 73 65 2c 20 61 6e 64 2f 6f  ublicense, and/o
02a0: 72 20 73 65 6c 6c 20 63 6f 70 69 65 73 20 6f 66  r sell copies of
02b0: 20 74 68 65 20 53 6f 66 74 77 61 72 65 2c 20 61   the Software, a
02c0: 6e 64 20 74 6f 0a 23 20 70 65 72 6d 69 74 20 70  nd to.# permit p
02d0: 65 72 73 6f 6e 73 20 74 6f 20 77 68 6f 6d 20 74  ersons to whom t
02e0: 68 65 20 53 6f 66 74 77 61 72 65 20 69 73 20 66  he Software is f
02f0: 75 72 6e 69 73 68 65 64 20 74 6f 20 64 6f 20 73  urnished to do s
0300: 6f 2c 20 73 75 62 6a 65 63 74 20 74 6f 0a 23 20  o, subject to.# 
0310: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f  the following co
0320: 6e 64 69 74 69 6f 6e 73 3a 0a 23 0a 23 20 54 68  nditions:.#.# Th
0330: 65 20 61 62 6f 76 65 20 63 6f 70 79 72 69 67 68  e above copyrigh
0340: 74 20 6e 6f 74 69 63 65 20 61 6e 64 20 74 68 69  t notice and thi
0350: 73 20 70 65 72 6d 69 73 73 69 6f 6e 20 6e 6f 74  s permission not
0360: 69 63 65 20 73 68 61 6c 6c 20 62 65 0a 23 20 69  ice shall be.# i
0370: 6e 63 6c 75 64 65 64 20 69 6e 20 61 6c 6c 20 63  ncluded in all c
0380: 6f 70 69 65 73 20 6f 72 20 73 75 62 73 74 61 6e  opies or substan
0390: 74 69 61 6c 20 70 6f 72 74 69 6f 6e 73 20 6f 66  tial portions of
03a0: 20 74 68 65 20 53 6f 66 74 77 61 72 65 2e 0a 23   the Software..#
03b0: 0a 23 20 54 48 45 20 53 4f 46 54 57 41 52 45 20  .# THE SOFTWARE 
03c0: 49 53 20 50 52 4f 56 49 44 45 44 20 22 41 53 20  IS PROVIDED "AS 
03d0: 49 53 22 2c 20 57 49 54 48 4f 55 54 20 57 41 52  IS", WITHOUT WAR
03e0: 52 41 4e 54 59 20 4f 46 20 41 4e 59 20 4b 49 4e  RANTY OF ANY KIN
03f0: 44 2c 0a 23 20 45 58 50 52 45 53 53 20 4f 52 20  D,.# EXPRESS OR 
0400: 49 4d 50 4c 49 45 44 2c 20 49 4e 43 4c 55 44 49  IMPLIED, INCLUDI
0410: 4e 47 20 42 55 54 20 4e 4f 54 20 4c 49 4d 49 54  NG BUT NOT LIMIT
0420: 45 44 20 54 4f 20 54 48 45 20 57 41 52 52 41 4e  ED TO THE WARRAN
0430: 54 49 45 53 20 4f 46 0a 23 20 4d 45 52 43 48 41  TIES OF.# MERCHA
0440: 4e 54 41 42 49 4c 49 54 59 2c 20 46 49 54 4e 45  NTABILITY, FITNE
0450: 53 53 20 46 4f 52 20 41 20 50 41 52 54 49 43 55  SS FOR A PARTICU
0460: 4c 41 52 20 50 55 52 50 4f 53 45 20 41 4e 44 20  LAR PURPOSE AND 
0470: 4e 4f 4e 49 4e 46 52 49 4e 47 45 4d 45 4e 54 2e  NONINFRINGEMENT.
0480: 0a 23 20 49 4e 20 4e 4f 20 45 56 45 4e 54 20 53  .# IN NO EVENT S
0490: 48 41 4c 4c 20 54 48 45 20 41 55 54 48 4f 52 53  HALL THE AUTHORS
04a0: 20 4c 49 53 54 45 44 20 41 42 4f 56 45 20 42 45   LISTED ABOVE BE
04b0: 20 4c 49 41 42 4c 45 20 46 4f 52 20 41 4e 59 20   LIABLE FOR ANY 
04c0: 43 4c 41 49 4d 2c 0a 23 20 44 41 4d 41 47 45 53  CLAIM,.# DAMAGES
04d0: 20 4f 52 20 4f 54 48 45 52 20 4c 49 41 42 49 4c   OR OTHER LIABIL
04e0: 49 54 59 2c 20 57 48 45 54 48 45 52 20 49 4e 20  ITY, WHETHER IN 
04f0: 41 4e 20 41 43 54 49 4f 4e 20 4f 46 20 43 4f 4e  AN ACTION OF CON
0500: 54 52 41 43 54 2c 20 54 4f 52 54 0a 23 20 4f 52  TRACT, TORT.# OR
0510: 20 4f 54 48 45 52 57 49 53 45 2c 20 41 52 49 53   OTHERWISE, ARIS
0520: 49 4e 47 20 46 52 4f 4d 2c 20 4f 55 54 20 4f 46  ING FROM, OUT OF
0530: 20 4f 52 20 49 4e 20 43 4f 4e 4e 45 43 54 49 4f   OR IN CONNECTIO
0540: 4e 20 57 49 54 48 20 54 48 45 20 53 4f 46 54 57  N WITH THE SOFTW
0550: 41 52 45 0a 23 20 4f 52 20 54 48 45 20 55 53 45  ARE.# OR THE USE
0560: 20 4f 52 20 4f 54 48 45 52 20 44 45 41 4c 49 4e   OR OTHER DEALIN
0570: 47 53 20 49 4e 20 54 48 45 20 53 4f 46 54 57 41  GS IN THE SOFTWA
0580: 52 45 2e 0a 23 0a 23 20 45 78 63 65 70 74 20 61  RE..#.# Except a
0590: 73 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 74  s contained in t
05a0: 68 69 73 20 6e 6f 74 69 63 65 2c 20 74 68 65 20  his notice, the 
05b0: 6e 61 6d 65 73 20 6f 66 20 74 68 65 20 61 75 74  names of the aut
05c0: 68 6f 72 73 20 61 62 6f 76 65 0a 23 20 73 68 61  hors above.# sha
05d0: 6c 6c 20 6e 6f 74 20 62 65 20 75 73 65 64 20 69  ll not be used i
05e0: 6e 20 61 64 76 65 72 74 69 73 69 6e 67 20 6f 72  n advertising or
05f0: 20 6f 74 68 65 72 77 69 73 65 20 74 6f 20 70 72   otherwise to pr
0600: 6f 6d 6f 74 65 20 74 68 65 20 73 61 6c 65 2c 0a  omote the sale,.
0610: 23 20 75 73 65 20 6f 72 20 6f 74 68 65 72 20 64  # use or other d
0620: 65 61 6c 69 6e 67 73 20 69 6e 20 74 68 69 73 20  ealings in this 
0630: 53 6f 66 74 77 61 72 65 20 77 69 74 68 6f 75 74  Software without
0640: 20 70 72 69 6f 72 20 77 72 69 74 74 65 6e 0a 23   prior written.#
0650: 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 66   authorization f
0660: 72 6f 6d 20 74 68 6f 73 65 20 61 75 74 68 6f 72  rom those author
0670: 73 2e 0a 23 23 23 23 23 23 23 23 23 23 23 23 23  s..#############
0680: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0690: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
06a0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
06b0: 23 23 23 23 23 23 23 23 23 23 23 0a 0a 23 20 42  ###########..# B
06c0: 72 69 6e 67 20 69 6e 20 6a 75 73 74 20 74 68 65  ring in just the
06d0: 20 62 61 73 69 63 73 20 73 6f 20 77 65 20 63 61   basics so we ca
06e0: 6e 20 62 72 69 6e 67 20 69 6e 20 6f 75 72 20 6c  n bring in our l
06f0: 6f 63 61 6c 20 6d 6f 64 75 6c 65 73 0a 69 6d 70  ocal modules.imp
0700: 6f 72 74 20 6f 73 0a 69 6d 70 6f 72 74 20 73 79  ort os.import sy
0710: 73 0a 69 6d 70 6f 72 74 20 74 65 6d 70 66 69 6c  s.import tempfil
0720: 65 0a 69 6d 70 6f 72 74 20 74 69 6d 65 0a 73 79  e.import time.sy
0730: 73 2e 70 61 74 68 2e 69 6e 73 65 72 74 20 28 30  s.path.insert (0
0740: 2c 20 6f 73 2e 70 61 74 68 2e 64 69 72 6e 61 6d  , os.path.dirnam
0750: 65 20 28 5f 5f 66 69 6c 65 5f 5f 29 20 2b 20 27  e (__file__) + '
0760: 2f 2e 2e 2f 6c 69 62 27 29 0a 73 79 73 2e 70 61  /../lib').sys.pa
0770: 74 68 2e 69 6e 73 65 72 74 20 28 30 2c 20 6f 73  th.insert (0, os
0780: 2e 67 65 74 63 77 64 20 28 29 20 2b 20 27 2f 6c  .getcwd () + '/l
0790: 69 62 27 29 0a 0a 23 20 50 79 74 68 6f 6e 20 63  ib')..# Python c
07a0: 6f 72 65 20 6d 6f 64 75 6c 65 73 20 77 65 20 75  ore modules we u
07b0: 73 65 0a 69 6d 70 6f 72 74 20 72 65 0a 66 72 6f  se.import re.fro
07c0: 6d 20 73 74 72 69 6e 67 20 69 6d 70 6f 72 74 20  m string import 
07d0: 54 65 6d 70 6c 61 74 65 0a 69 6d 70 6f 72 74 20  Template.import 
07e0: 73 68 75 74 69 6c 0a 69 6d 70 6f 72 74 20 73 75  shutil.import su
07f0: 62 70 72 6f 63 65 73 73 0a 0a 23 20 4f 75 72 20  bprocess..# Our 
0800: 6c 6f 63 61 6c 20 6d 6f 64 75 6c 65 73 0a 66 72  local modules.fr
0810: 6f 6d 20 70 69 64 70 38 69 20 69 6d 70 6f 72 74  om pidp8i import
0820: 20 2a 0a 66 72 6f 6d 20 73 69 6d 68 20 69 6d 70   *.from simh imp
0830: 6f 72 74 20 2a 0a 0a 23 20 53 63 72 69 70 74 20  ort *..# Script 
0840: 4c 61 6e 67 75 61 67 65 20 56 65 72 73 69 6f 6e  Language Version
0850: 0a 23 20 55 70 64 61 74 65 20 74 68 69 73 20 76  .# Update this v
0860: 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20 61 73  ersion number as
0870: 20 74 68 65 20 6c 61 6e 67 75 61 67 65 20 65 76   the language ev
0880: 6f 6c 76 65 73 2e 0a 23 20 56 65 72 73 69 6f 6e  olves..# Version
0890: 20 31 2e 30 20 69 73 20 74 68 65 20 66 69 72 73   1.0 is the firs
08a0: 74 20 70 75 62 6c 69 63 20 76 65 72 73 69 6f 6e  t public version
08b0: 2e 0a 4c 41 4e 47 5f 56 45 52 53 49 4f 4e 20 3d  ..LANG_VERSION =
08c0: 20 22 31 2e 30 22 0a 0a 23 20 45 72 72 6f 72 20   "1.0"..# Error 
08d0: 43 6c 61 73 73 20 44 65 66 69 6e 69 74 69 6f 6e  Class Definition
08e0: 73 20 23 23 23 23 23 23 23 23 23 23 23 23 23 23  s ##############
08f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0900: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0910: 0a 23 20 45 6e 61 62 6c 65 73 20 75 73 20 74 6f  .# Enables us to
0920: 20 75 73 65 20 65 78 63 65 70 74 69 6f 6e 73 20   use exceptions 
0930: 66 72 6f 6d 20 77 69 74 68 69 6e 20 74 68 69 73  from within this
0940: 20 6d 6f 64 75 6c 65 2e 0a 0a 63 6c 61 73 73 20   module...class 
0950: 45 72 72 6f 72 28 45 78 63 65 70 74 69 6f 6e 29  Error(Exception)
0960: 3a 0a 20 20 22 22 22 42 61 73 65 20 43 6c 61 73  :.  """Base Clas
0970: 73 20 66 6f 72 20 65 78 63 65 70 74 69 6f 6e 73  s for exceptions
0980: 20 69 6e 20 74 68 69 73 20 6d 6f 64 75 6c 65 2e   in this module.
0990: 22 22 22 0a 20 20 70 61 73 73 0a 0a 63 6c 61 73  """.  pass..clas
09a0: 73 20 49 6e 70 75 74 45 72 72 6f 72 28 45 72 72  s InputError(Err
09b0: 6f 72 29 3a 0a 20 20 22 22 22 45 78 63 65 70 74  or):.  """Except
09c0: 69 6f 6e 20 72 61 69 73 65 64 20 66 6f 72 20 65  ion raised for e
09d0: 72 72 6f 72 73 20 69 6e 20 74 68 65 20 69 6e 70  rrors in the inp
09e0: 75 74 2e 0a 0a 20 20 41 74 74 72 69 62 75 74 65  ut...  Attribute
09f0: 73 3a 0a 20 20 65 78 70 72 20 2d 2d 20 69 6e 70  s:.  expr -- inp
0a00: 75 74 20 65 78 70 72 65 73 73 69 6f 6e 20 69 6e  ut expression in
0a10: 20 77 68 69 63 68 20 74 68 65 20 65 72 72 6f 72   which the error
0a20: 20 6f 63 63 75 72 72 65 64 0a 20 20 6d 73 67 20   occurred.  msg 
0a30: 20 2d 2d 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20   -- explanation 
0a40: 6f 66 20 74 68 65 20 65 72 72 6f 72 0a 20 20 22  of the error.  "
0a50: 22 22 0a 0a 20 20 64 65 66 20 5f 5f 69 6e 69 74  ""..  def __init
0a60: 5f 5f 28 73 65 6c 66 2c 20 6d 73 67 29 3a 0a 20  __(self, msg):. 
0a70: 20 20 20 73 65 6c 66 2e 6d 73 67 20 3d 20 6d 73     self.msg = ms
0a80: 67 0a 0a 20 20 64 65 66 20 5f 5f 73 74 72 5f 5f  g..  def __str__
0a90: 28 73 65 6c 66 29 3a 0a 20 20 20 20 72 65 74 75  (self):.    retu
0aa0: 72 6e 20 73 65 6c 66 2e 6d 73 67 0a 0a 20 20 20  rn self.msg..   
0ab0: 20 20 20 0a 23 20 50 72 69 76 61 74 65 20 67 6c     .# Private gl
0ac0: 6f 62 61 6c 73 20 23 23 23 23 23 23 23 23 23 23  obals ##########
0ad0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0ae0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
0af0: 23 23 23 23 23 23 23 23 23 23 23 23 0a 23 20 56  ############.# V
0b00: 69 73 69 62 6c 65 20 77 69 74 68 69 6e 20 74 68  isible within th
0b10: 69 73 20 66 69 6c 65 2c 20 62 75 74 20 6e 6f 74  is file, but not
0b20: 20 74 6f 20 74 68 65 20 6f 75 74 73 69 64 65 2e   to the outside.
0b30: 0a 0a 23 20 49 64 65 6e 74 69 66 79 20 61 20 62  ..# Identify a b
0b40: 65 67 69 6e 20 65 6e 61 62 6c 65 64 2f 6e 6f 74  egin enabled/not
0b50: 5f 64 69 73 61 62 6c 65 64 20 63 6f 6d 6d 61 6e  _disabled comman
0b60: 64 2e 20 67 72 6f 75 70 28 31 29 20 63 6f 6e 74  d. group(1) cont
0b70: 61 69 6e 73 20 65 69 74 68 65 72 20 74 68 65 20  ains either the 
0b80: 65 6e 61 62 6c 65 64 20 6f 72 0a 23 20 64 69 73  enabled or.# dis
0b90: 61 62 6c 65 64 20 66 6c 61 67 2e 20 50 75 74 20  abled flag. Put 
0ba0: 74 68 65 20 72 65 73 74 20 6f 66 20 74 68 65 20  the rest of the 
0bb0: 6c 69 6e 65 20 69 6e 20 67 72 6f 75 70 28 32 29  line in group(2)
0bc0: 0a 5f 62 65 67 69 6e 5f 65 6e 5f 64 69 73 5f 63  ._begin_en_dis_c
0bd0: 6f 6d 6d 5f 72 65 20 3d 20 72 65 2e 63 6f 6d 70  omm_re = re.comp
0be0: 69 6c 65 20 28 72 22 5e 62 65 67 69 6e 5c 73 2b  ile (r"^begin\s+
0bf0: 28 65 6e 61 62 6c 65 64 7c 64 65 66 61 75 6c 74  (enabled|default
0c00: 7c 76 65 72 73 69 6f 6e 29 5c 73 2b 28 2e 2b 29  |version)\s+(.+)
0c10: 24 22 29 0a 20 20 0a 23 20 49 64 65 6e 74 69 66  $").  .# Identif
0c20: 79 20 61 6e 20 65 6e 64 20 65 6e 61 62 6c 65 64  y an end enabled
0c30: 2f 6e 6f 74 5f 64 69 73 61 62 6c 65 64 20 63 6f  /not_disabled co
0c40: 6d 6d 61 6e 64 2e 20 67 72 6f 75 70 28 31 29 20  mmand. group(1) 
0c50: 63 6f 6e 74 61 69 6e 73 20 65 69 74 68 65 72 20  contains either 
0c60: 74 68 65 20 65 6e 61 62 6c 65 64 20 6f 72 0a 23  the enabled or.#
0c70: 20 64 69 73 61 62 6c 65 64 20 66 6c 61 67 2e 20   disabled flag. 
0c80: 50 75 74 20 74 68 65 20 72 65 73 74 20 6f 66 20  Put the rest of 
0c90: 74 68 65 20 6c 69 6e 65 20 69 6e 20 67 72 6f 75  the line in grou
0ca0: 70 28 32 29 0a 5f 65 6e 64 5f 65 6e 5f 64 69 73  p(2)._end_en_dis
0cb0: 5f 63 6f 6d 6d 5f 72 65 20 3d 20 72 65 2e 63 6f  _comm_re = re.co
0cc0: 6d 70 69 6c 65 20 28 72 22 5e 65 6e 64 5c 73 2b  mpile (r"^end\s+
0cd0: 28 65 6e 61 62 6c 65 64 7c 64 65 66 61 75 6c 74  (enabled|default
0ce0: 7c 76 65 72 73 69 6f 6e 29 5c 73 2b 28 2e 2b 29  |version)\s+(.+)
0cf0: 24 22 29 0a 20 20 0a 23 20 49 64 65 6e 74 69 66  $").  .# Identif
0d00: 79 20 61 6e 20 65 6e 64 20 63 6f 6d 6d 20 61 6e  y an end comm an
0d10: 64 20 70 75 74 20 74 68 65 20 72 65 73 74 20 6f  d put the rest o
0d20: 66 20 74 68 65 20 6c 69 6e 65 20 69 6e 20 67 72  f the line in gr
0d30: 6f 75 70 28 31 29 0a 5f 65 6e 64 5f 63 6f 6d 6d  oup(1)._end_comm
0d40: 5f 72 65 20 3d 20 72 65 2e 63 6f 6d 70 69 6c 65  _re = re.compile
0d50: 20 28 72 22 5e 65 6e 64 5c 73 2b 28 2e 2b 29 3f   (r"^end\s+(.+)?
0d60: 24 22 29 0a 20 20 0a 23 20 49 64 65 6e 74 69 66  $").  .# Identif
0d70: 79 20 61 6e 20 65 6e 64 20 6f 70 74 69 6f 6e 20  y an end option 
0d80: 63 6f 6d 6d 61 6e 64 20 61 6e 64 20 70 75 74 20  command and put 
0d90: 74 68 65 20 72 65 73 74 20 6f 66 20 74 68 65 20  the rest of the 
0da0: 6c 69 6e 65 20 69 6e 20 67 72 6f 75 70 28 31 29  line in group(1)
0db0: 0a 5f 65 6e 64 5f 6f 70 74 69 6f 6e 5f 63 6f 6d  ._end_option_com
0dc0: 6d 5f 72 65 20 3d 20 72 65 2e 63 6f 6d 70 69 6c  m_re = re.compil
0dd0: 65 20 28 72 22 5e 65 6e 64 5c 73 2b 6f 70 74 69  e (r"^end\s+opti
0de0: 6f 6e 5c 73 2b 28 2e 2b 29 24 22 29 0a 0a 23 20  on\s+(.+)$")..# 
0df0: 41 20 76 61 6c 69 64 20 76 65 72 73 69 6f 6e 20  A valid version 
0e00: 73 70 65 63 0a 5f 76 65 72 73 69 6f 6e 5f 70 61  spec._version_pa
0e10: 72 73 65 5f 72 65 20 3d 20 72 65 2e 63 6f 6d 70  rse_re = re.comp
0e20: 69 6c 65 20 28 72 22 5e 28 28 5c 64 2b 5c 2e 29  ile (r"^((\d+\.)
0e30: 2a 29 3f 28 5c 64 2b 29 3f 24 22 29 0a 20 20 0a  *)?(\d+)?$").  .
0e40: 23 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 44 45  # Name of the DE
0e50: 43 74 61 70 65 20 69 6d 61 67 65 20 66 69 6c 65  Ctape image file
0e60: 20 77 65 20 63 72 65 61 74 65 0a 5f 6e 65 77 5f   we create._new_
0e70: 73 79 73 5f 74 61 70 65 5f 70 72 65 66 69 78 20  sys_tape_prefix 
0e80: 3d 20 22 73 79 73 74 65 6d 22 0a 0a 23 20 50 61  = "system"..# Pa
0e90: 72 73 65 72 20 72 65 67 65 78 70 73 20 75 73 65  rser regexps use
0ea0: 64 20 69 6e 20 70 61 74 63 68 65 72 0a 5f 63 6f  d in patcher._co
0eb0: 6d 5f 6f 73 38 5f 70 61 72 73 65 5f 73 74 72 20  m_os8_parse_str 
0ec0: 3d 20 72 22 5e 5c 2e 28 5b 61 2d 7a 41 2d 5a 5d  = r"^\.([a-zA-Z]
0ed0: 2b 29 5c 73 2a 28 2e 2a 29 24 22 0a 5f 63 6f 6d  +)\s*(.*)$"._com
0ee0: 5f 6f 73 38 5f 70 61 72 73 65 20 3d 20 72 65 2e  _os8_parse = re.
0ef0: 63 6f 6d 70 69 6c 65 28 5f 63 6f 6d 5f 6f 73 38  compile(_com_os8
0f00: 5f 70 61 72 73 65 5f 73 74 72 29 0a 5f 63 6f 6d  _parse_str)._com
0f10: 5f 73 70 6c 69 74 5f 73 74 72 20 3d 20 72 22 5e  _split_str = r"^
0f20: 28 5b 61 2d 7a 41 2d 5a 5d 2b 29 5c 73 2a 28 2e  ([a-zA-Z]+)\s*(.
0f30: 2a 29 24 22 0a 5f 63 6f 6d 5f 73 70 6c 69 74 5f  *)$"._com_split_
0f40: 70 61 72 73 65 20 3d 20 72 65 2e 63 6f 6d 70 69  parse = re.compi
0f50: 6c 65 28 5f 63 6f 6d 5f 73 70 6c 69 74 5f 73 74  le(_com_split_st
0f60: 72 29 0a 5f 6f 64 74 5f 70 61 72 73 65 5f 73 74  r)._odt_parse_st
0f70: 72 20 3d 20 72 22 5e 28 5b 30 2d 37 5d 2b 29 5c  r = r"^([0-7]+)\
0f80: 73 2a 2f 5c 73 2a 28 5c 53 2b 29 5c 73 2b 28 5b  s*/\s*(\S+)\s+([
0f90: 30 2d 37 3b 5d 2b 29 22 0a 5f 6f 64 74 5f 70 61  0-7;]+)"._odt_pa
0fa0: 72 73 65 20 3d 20 72 65 2e 63 6f 6d 70 69 6c 65  rse = re.compile
0fb0: 28 5f 6f 64 74 5f 70 61 72 73 65 5f 73 74 72 29  (_odt_parse_str)
0fc0: 0a 0a 23 20 50 75 74 20 63 6f 6d 6d 61 6e 64 20  ..# Put command 
0fd0: 6b 65 79 77 6f 72 64 20 69 6e 20 67 72 6f 75 70  keyword in group
0fe0: 28 31 29 20 61 6e 64 20 74 68 65 20 72 65 73 74  (1) and the rest
0ff0: 20 69 73 20 69 6e 20 67 72 6f 75 70 28 33 29 0a   is in group(3).
1000: 5f 63 6f 6d 6d 5f 72 65 5f 73 74 72 20 3d 20 72  _comm_re_str = r
1010: 22 5e 28 5c 53 2b 29 28 5c 73 2b 28 2e 2b 29 29  "^(\S+)(\s+(.+))
1020: 3f 24 22 0a 5f 63 6f 6d 6d 5f 72 65 20 3d 20 72  ?$"._comm_re = r
1030: 65 2e 63 6f 6d 70 69 6c 65 28 5f 63 6f 6d 6d 5f  e.compile(_comm_
1040: 72 65 5f 73 74 72 29 0a 0a 23 20 49 64 65 6e 74  re_str)..# Ident
1050: 69 66 79 20 61 6e 20 65 6e 64 20 63 6f 6d 6d 20  ify an end comm 
1060: 61 6e 64 20 70 75 74 20 74 68 65 20 72 65 73 74  and put the rest
1070: 20 6f 66 20 74 68 65 20 6c 69 6e 65 20 69 6e 20   of the line in 
1080: 67 72 6f 75 70 28 31 29 0a 5f 65 6e 64 5f 63 6f  group(1)._end_co
1090: 6d 6d 5f 72 65 20 3d 20 72 65 2e 63 6f 6d 70 69  mm_re = re.compi
10a0: 6c 65 20 28 72 22 5e 65 6e 64 5c 73 2b 28 2e 2b  le (r"^end\s+(.+
10b0: 29 3f 24 22 29 0a 0a 23 20 49 64 65 6e 74 69 66  )?$")..# Identif
10c0: 79 20 61 6e 20 65 6e 64 20 6f 70 74 69 6f 6e 20  y an end option 
10d0: 63 6f 6d 6d 61 6e 64 20 61 6e 64 20 70 75 74 20  command and put 
10e0: 74 68 65 20 72 65 73 74 20 6f 66 20 74 68 65 20  the rest of the 
10f0: 6c 69 6e 65 20 69 6e 20 67 72 6f 75 70 28 31 29  line in group(1)
1100: 0a 5f 65 6e 64 5f 6f 70 74 69 6f 6e 5f 63 6f 6d  ._end_option_com
1110: 6d 5f 72 65 20 3d 20 72 65 2e 63 6f 6d 70 69 6c  m_re = re.compil
1120: 65 20 28 72 22 5e 65 6e 64 5c 73 2b 6f 70 74 69  e (r"^end\s+opti
1130: 6f 6e 5c 73 2b 28 2e 2b 29 24 22 29 0a 0a 23 20  on\s+(.+)$")..# 
1140: 49 64 65 6e 74 69 66 79 20 61 20 62 65 67 69 6e  Identify a begin
1150: 20 63 6f 6d 6d 61 6e 64 20 61 6e 64 20 70 75 74   command and put
1160: 20 74 68 65 20 72 65 73 74 20 6f 66 20 74 68 65   the rest of the
1170: 20 6c 69 6e 65 20 69 6e 20 67 72 6f 75 70 28 31   line in group(1
1180: 29 0a 5f 62 65 67 69 6e 5f 6f 70 74 69 6f 6e 5f  )._begin_option_
1190: 63 6f 6d 6d 5f 72 65 20 3d 20 72 65 2e 63 6f 6d  comm_re = re.com
11a0: 70 69 6c 65 20 28 72 22 5e 62 65 67 69 6e 5c 73  pile (r"^begin\s
11b0: 2b 6f 70 74 69 6f 6e 5c 73 2b 28 2e 2b 29 24 22  +option\s+(.+)$"
11c0: 29 0a 0a 23 20 50 61 72 73 65 20 61 6e 20 61 72  )..# Parse an ar
11d0: 67 75 6d 65 6e 74 20 73 74 72 69 6e 67 20 69 6e  gument string in
11e0: 74 6f 20 61 20 73 79 73 20 64 65 76 69 63 65 20  to a sys device 
11f0: 77 69 74 68 0a 23 20 64 65 76 69 63 65 20 6e 61  with.# device na
1200: 6d 65 20 69 6e 20 67 72 6f 75 70 28 31 29 2c 20  me in group(1), 
1210: 75 6e 69 74 20 6e 75 6d 62 65 72 20 69 6e 20 67  unit number in g
1220: 72 6f 75 70 28 32 29 0a 23 20 57 65 20 70 75 74  roup(2).# We put
1230: 20 61 6c 6c 20 62 6f 6f 74 61 62 6c 65 20 64 65   all bootable de
1240: 76 69 63 65 73 20 69 6e 74 6f 20 74 68 69 73 20  vices into this 
1250: 73 74 72 69 6e 67 20 73 6f 20 74 68 61 74 20 77  string so that w
1260: 68 65 6e 0a 23 20 77 65 20 61 64 64 20 6d 6f 72  hen.# we add mor
1270: 65 20 64 65 76 69 63 65 73 2c 20 66 6f 72 20 65  e devices, for e
1280: 78 61 6d 70 6c 65 20 72 6c 20 66 6f 72 20 52 4c  xample rl for RL
1290: 30 31 2c 20 77 65 20 63 68 61 6e 67 65 20 6f 6e  01, we change on
12a0: 65 0a 23 20 73 74 72 69 6e 67 20 6e 6f 74 20 6d  e.# string not m
12b0: 61 6e 79 2e 0a 5f 73 69 6d 68 5f 62 6f 6f 74 5f  any.._simh_boot_
12c0: 64 65 76 5f 73 74 72 20 3d 20 72 22 28 72 6b 7c  dev_str = r"(rk|
12d0: 74 64 7c 64 74 7c 72 78 29 28 5c 64 2a 29 22 0a  td|dt|rx)(\d*)".
12e0: 5f 73 69 6d 68 5f 62 6f 6f 74 5f 72 65 20 3d 20  _simh_boot_re = 
12f0: 72 65 2e 63 6f 6d 70 69 6c 65 28 22 5e 22 20 2b  re.compile("^" +
1300: 20 5f 73 69 6d 68 5f 62 6f 6f 74 5f 64 65 76 5f   _simh_boot_dev_
1310: 73 74 72 20 2b 20 22 24 22 29 0a 0a 23 20 50 61  str + "$")..# Pa
1320: 72 73 65 20 61 6e 20 61 72 67 75 6d 65 6e 74 20  rse an argument 
1330: 73 74 72 69 6e 67 20 66 6f 72 20 6d 6f 75 6e 74  string for mount
1340: 20 69 6e 74 6f 20 53 49 4d 48 20 64 65 76 69 63   into SIMH devic
1350: 65 0a 23 20 64 65 76 69 63 65 20 6e 61 6d 65 20  e.# device name 
1360: 69 6e 20 67 72 6f 75 70 28 31 29 2c 20 75 6e 69  in group(1), uni
1370: 74 20 6e 75 6d 62 65 72 20 69 6e 20 67 72 6f 75  t number in grou
1380: 70 28 32 29 0a 23 20 41 6e 64 20 74 68 65 20 72  p(2).# And the r
1390: 65 73 74 20 69 6e 20 67 72 6f 75 70 20 28 33 29  est in group (3)
13a0: 0a 5f 6d 6f 75 6e 74 5f 72 65 67 65 78 5f 73 74  ._mount_regex_st
13b0: 72 20 3d 20 22 5e 22 20 2b 20 5f 73 69 6d 68 5f  r = "^" + _simh_
13c0: 62 6f 6f 74 5f 64 65 76 5f 73 74 72 20 2b 20 72  boot_dev_str + r
13d0: 22 5c 73 2b 28 2e 2b 29 24 22 0a 5f 6d 6f 75 6e  "\s+(.+)$"._moun
13e0: 74 5f 72 65 20 3d 20 72 65 2e 63 6f 6d 70 69 6c  t_re = re.compil
13f0: 65 28 5f 6d 6f 75 6e 74 5f 72 65 67 65 78 5f 73  e(_mount_regex_s
1400: 74 72 29 0a 0a 23 20 4d 61 70 20 6f 66 20 53 49  tr)..# Map of SI
1410: 4d 48 20 64 65 76 69 63 65 20 6e 61 6d 65 73 20  MH device names 
1420: 74 6f 20 4f 53 2f 38 20 64 65 76 69 63 65 20 6e  to OS/8 device n
1430: 61 6d 65 20 70 72 65 66 69 78 65 73 2e 0a 5f 6f  ame prefixes.._o
1440: 73 38 5f 66 72 6f 6d 5f 73 69 6d 68 5f 64 65 76  s8_from_simh_dev
1450: 20 3d 20 7b 22 72 6b 22 20 3a 20 22 52 4b 22 2c   = {"rk" : "RK",
1460: 20 22 74 64 22 20 3a 20 22 44 54 41 22 2c 20 22   "td" : "DTA", "
1470: 64 74 22 20 3a 20 22 44 54 41 22 2c 20 22 72 78  dt" : "DTA", "rx
1480: 22 20 3a 20 22 52 58 22 7d 0a 0a 5f 6f 73 38 5f  " : "RX"}.._os8_
1490: 70 61 72 74 69 74 69 6f 6e 73 20 3d 20 7b 22 52  partitions = {"R
14a0: 4b 22 3a 20 5b 22 41 22 2c 20 22 42 22 5d 7d 0a  K": ["A", "B"]}.
14b0: 0a 23 20 4f 53 2f 38 20 66 69 6c 65 20 6e 61 6d  .# OS/8 file nam
14c0: 65 20 6d 61 74 63 68 69 6e 67 20 72 65 67 65 78  e matching regex
14d0: 0a 5f 6f 73 38 5f 66 69 6c 65 5f 72 65 20 3d 20  ._os8_file_re = 
14e0: 72 65 2e 63 6f 6d 70 69 6c 65 28 72 22 28 5c 53  re.compile(r"(\S
14f0: 2b 29 3a 28 5c 53 2b 29 3f 22 29 0a 0a 23 20 52  +):(\S+)?")..# R
1500: 65 67 75 6c 61 72 20 65 78 70 72 65 73 73 69 6f  egular expressio
1510: 6e 20 66 6f 72 20 73 79 6e 74 61 78 20 63 68 65  n for syntax che
1520: 63 6b 69 6e 67 20 69 6e 73 69 64 65 20 46 4f 54  cking inside FOT
1530: 50 0a 23 20 44 65 73 74 69 6e 61 74 69 6f 6e 20  P.# Destination 
1540: 69 73 20 69 6e 20 67 72 6f 75 70 28 31 29 2c 20  is in group(1), 
1550: 53 6f 75 72 63 65 20 69 73 20 69 6e 20 67 72 6f  Source is in gro
1560: 75 70 28 33 29 0a 5f 66 6f 74 70 5f 72 65 20 3d  up(3)._fotp_re =
1570: 20 72 65 2e 63 6f 6d 70 69 6c 65 20 28 72 22 5e   re.compile (r"^
1580: 28 28 5c 53 2b 3a 29 3f 5c 53 2b 29 3c 28 28 5c  ((\S+:)?\S+)<((\
1590: 53 2b 3a 29 3f 5c 53 2b 29 24 22 29 0a 0a 23 20  S+:)?\S+)$")..# 
15a0: 52 65 67 75 6c 61 72 20 65 78 70 72 65 73 73 69  Regular expressi
15b0: 6f 6e 20 66 6f 72 20 64 65 74 65 63 74 69 6e 67  on for detecting
15c0: 20 74 68 65 20 32 20 61 72 67 20 61 6e 64 20 33   the 2 arg and 3
15d0: 20 61 72 67 20 66 6f 72 6d 73 0a 23 20 6f 66 20   arg forms.# of 
15e0: 74 68 65 20 22 70 61 6c 38 22 20 73 63 72 69 70  the "pal8" scrip
15f0: 74 20 63 6f 6d 6d 61 6e 64 2e 0a 0a 23 20 4f 53  t command...# OS
1600: 2f 38 20 6e 61 6d 65 20 72 65 67 65 78 20 74 65  /8 name regex te
1610: 6d 70 6c 61 74 65 3a 0a 23 20 4f 70 74 69 6f 6e  mplate:.# Option
1620: 61 6c 20 64 65 76 69 63 65 20 73 70 65 63 2c 20  al device spec, 
1630: 69 2e 65 2e 20 44 54 41 30 3a 0a 23 20 46 69 6c  i.e. DTA0:.# Fil
1640: 65 20 73 70 65 63 20 77 69 74 68 20 61 20 73 70  e spec with a sp
1650: 65 63 69 66 69 63 20 65 78 74 65 6e 73 69 6f 6e  ecific extension
1660: 20 6f 72 20 6e 6f 20 65 78 74 65 6e 73 69 6f 6e   or no extension
1670: 2e 0a 0a 5f 6f 73 38 5f 66 73 70 65 63 20 3d 20  ..._os8_fspec = 
1680: 54 65 6d 70 6c 61 74 65 20 28 72 22 28 28 5c 53  Template (r"((\S
1690: 2b 3a 29 3f 28 5b 41 2d 5a 30 2d 39 5d 7b 31 2c  +:)?([A-Z0-9]{1,
16a0: 36 7d 7c 5b 41 2d 5a 30 2d 39 5d 7b 31 2c 36 7d  6}|[A-Z0-9]{1,6}
16b0: 5c 2e 24 65 78 74 29 29 22 29 0a 5f 6f 73 38 5f  \.$ext))")._os8_
16c0: 42 4e 5f 66 73 70 65 63 20 3d 20 5f 6f 73 38 5f  BN_fspec = _os8_
16d0: 66 73 70 65 63 2e 73 75 62 73 74 69 74 75 74 65  fspec.substitute
16e0: 28 65 78 74 3d 22 42 4e 22 29 0a 5f 6f 73 38 5f  (ext="BN")._os8_
16f0: 50 41 5f 66 73 70 65 63 20 3d 20 5f 6f 73 38 5f  PA_fspec = _os8_
1700: 66 73 70 65 63 2e 73 75 62 73 74 69 74 75 74 65  fspec.substitute
1710: 28 65 78 74 3d 22 50 41 22 29 0a 5f 6f 73 38 5f  (ext="PA")._os8_
1720: 4c 53 5f 66 73 70 65 63 20 3d 20 5f 6f 73 38 5f  LS_fspec = _os8_
1730: 66 73 70 65 63 2e 73 75 62 73 74 69 74 75 74 65  fspec.substitute
1740: 28 65 78 74 3d 22 4c 53 22 29 0a 0a 23 20 52 65  (ext="LS")..# Re
1750: 67 65 78 20 74 6f 20 70 61 72 73 65 20 61 20 76  gex to parse a v
1760: 61 6c 69 64 20 4f 53 2f 38 20 6f 70 74 69 6f 6e  alid OS/8 option
1770: 20 73 74 72 69 6e 67 20 65 69 74 68 65 72 20 77   string either w
1780: 69 74 68 20 73 6c 61 73 68 20 6f 72 20 70 61 72  ith slash or par
1790: 65 6e 73 2e 0a 5f 6f 70 74 5f 73 74 72 20 3d 20  ens.._opt_str = 
17a0: 72 22 28 28 2f 5b 41 2d 5a 30 2d 39 5d 29 2b 7c  r"((/[A-Z0-9])+|
17b0: 5c 28 5b 41 2d 5a 30 2d 39 5d 2b 5c 29 29 3f 22  \([A-Z0-9]+\))?"
17c0: 0a 0a 23 20 52 65 67 75 6c 61 72 20 65 78 70 72  ..# Regular expr
17d0: 65 73 73 69 6f 6e 20 66 6f 72 20 73 79 6e 74 61  ession for synta
17e0: 78 20 63 68 65 63 6b 69 6e 67 20 69 6e 73 69 64  x checking insid
17f0: 65 20 41 42 53 4c 44 52 0a 23 20 46 49 58 4d 45  e ABSLDR.# FIXME
1800: 3a 20 55 73 65 20 28 61 6e 64 20 74 65 73 74 29  : Use (and test)
1810: 20 5f 6f 70 74 5f 73 74 72 20 66 6f 72 20 66 75   _opt_str for fu
1820: 6c 6c 20 4f 53 2f 38 20 4f 70 74 69 6f 6e 20 73  ll OS/8 Option s
1830: 70 65 63 20 63 6f 6d 70 61 74 69 62 69 6c 69 74  pec compatibilit
1840: 79 0a 23 20 4f 6e 65 20 6f 72 20 6d 6f 72 65 20  y.# One or more 
1850: 4f 53 2f 38 20 62 69 6e 61 72 79 20 66 69 6c 65  OS/8 binary file
1860: 73 20 61 6e 64 20 6f 70 74 69 6f 6e 61 6c 20 61  s and optional a
1870: 72 67 73 20 62 65 67 69 6e 6e 69 6e 67 20 77 69  rgs beginning wi
1880: 74 68 20 61 20 73 6c 61 73 68 2e 0a 0a 5f 61 62  th a slash..._ab
1890: 73 6c 64 72 5f 72 65 20 3d 20 72 65 2e 63 6f 6d  sldr_re = re.com
18a0: 70 69 6c 65 20 28 22 5e 22 20 2b 20 5f 6f 73 38  pile ("^" + _os8
18b0: 5f 42 4e 5f 66 73 70 65 63 20 2b 20 22 28 2c 22  _BN_fspec + "(,"
18c0: 20 2b 20 5f 6f 73 38 5f 42 4e 5f 66 73 70 65 63   + _os8_BN_fspec
18d0: 20 2b 20 72 22 29 2a 28 2f 5c 53 29 2a 24 22 29   + r")*(/\S)*$")
18e0: 0a 0a 23 20 52 65 67 75 6c 61 72 20 65 78 70 72  ..# Regular expr
18f0: 65 73 73 69 6f 6e 73 20 66 6f 72 20 73 79 6e 74  essions for synt
1900: 61 78 20 63 68 65 63 6b 69 6e 67 20 66 6f 72 20  ax checking for 
1910: 63 70 74 6f 20 61 6e 64 20 63 70 66 72 6f 6d 2e  cpto and cpfrom.
1920: 0a 23 20 4d 61 79 20 62 65 20 3c 73 6f 75 72 63  .# May be <sourc
1930: 65 3e 20 77 68 65 72 65 20 64 65 73 74 69 6e 61  e> where destina
1940: 74 69 6f 6e 20 61 6e 64 20 64 65 66 61 75 6c 74  tion and default
1950: 20 6f 70 74 69 6f 6e 20 2f 41 20 69 73 20 69 6d   option /A is im
1960: 70 6c 69 65 64 2e 0a 23 20 4f 72 20 3c 73 6f 75  plied..# Or <sou
1970: 72 63 65 3e 20 3c 6f 70 74 69 6f 6e 3e 20 77 68  rce> <option> wh
1980: 65 72 65 20 64 65 73 74 69 6e 61 74 69 6f 6e 20  ere destination 
1990: 69 73 20 69 6d 70 6c 69 65 64 20 61 6e 64 20 6f  is implied and o
19a0: 70 74 69 6f 6e 20 69 73 20 73 65 74 2e 0a 23 20  ption is set..# 
19b0: 4f 72 20 3c 73 6f 75 72 63 65 3e 20 3c 64 65 73  Or <source> <des
19c0: 74 69 6e 61 74 69 6f 6e 3e 20 77 68 65 72 65 20  tination> where 
19d0: 6f 70 74 69 6f 6e 20 2f 41 20 69 73 20 69 6d 70  option /A is imp
19e0: 6c 69 65 64 2e 0a 23 20 4f 72 20 3c 73 6f 75 72  lied..# Or <sour
19f0: 63 65 3e 20 3c 64 65 73 74 69 6e 61 74 69 6f 6e  ce> <destination
1a00: 3e 20 3c 6f 70 74 69 6f 6e 3e 20 61 72 65 20 65  > <option> are e
1a10: 78 70 6c 69 63 69 74 2e 0a 23 20 56 61 6c 69 64  xplicit..# Valid
1a20: 20 6f 70 74 69 6f 6e 73 20 61 72 65 20 22 2f 41   options are "/A
1a30: 22 2c 20 22 2f 49 22 2c 20 61 6e 64 20 22 2f 42  ", "/I", and "/B
1a40: 22 0a 23 20 55 73 65 20 74 77 6f 20 72 65 67 65  ".# Use two rege
1a50: 78 27 73 20 69 6e 20 6f 72 64 65 72 3a 0a 23 20  x's in order:.# 
1a60: 3c 73 6f 75 72 63 65 3e 20 69 6e 20 67 72 6f 75  <source> in grou
1a70: 70 20 31 2c 20 3c 64 65 73 74 3e 20 69 6e 20 67  p 1, <dest> in g
1a80: 72 6f 75 70 20 32 2e 0a 23 20 4f 70 74 69 6f 6e  roup 2..# Option
1a90: 20 69 73 20 6f 6e 65 20 6f 66 20 2f 49 20 2f 42   is one of /I /B
1aa0: 20 2f 41 20 69 6e 20 67 72 6f 75 70 20 34 2e 0a   /A in group 4..
1ab0: 0a 23 20 73 6f 75 72 63 65 20 69 6e 20 67 72 6f  .# source in gro
1ac0: 75 70 20 31 2c 20 6f 70 74 69 6f 6e 20 69 6e 20  up 1, option in 
1ad0: 67 72 6f 75 70 20 33 2e 0a 5f 66 72 6f 6d 5f 74  group 3.._from_t
1ae0: 6f 5f 72 65 5f 31 20 3d 20 72 65 2e 63 6f 6d 70  o_re_1 = re.comp
1af0: 69 6c 65 20 28 72 22 5e 28 5c 53 2b 29 28 5c 73  ile (r"^(\S+)(\s
1b00: 2b 28 2f 5b 41 49 42 5d 29 29 3f 24 22 29 0a 23  +(/[AIB]))?$").#
1b10: 20 73 6f 75 72 63 65 20 69 6e 20 67 72 6f 75 70   source in group
1b20: 20 31 2c 20 64 65 73 74 69 6e 61 74 69 6f 6e 20   1, destination 
1b30: 69 6e 20 67 72 6f 75 70 20 32 2c 20 6f 70 74 69  in group 2, opti
1b40: 6f 6e 20 69 6e 20 67 72 6f 75 70 20 34 2e 0a 5f  on in group 4.._
1b50: 66 72 6f 6d 5f 74 6f 5f 72 65 5f 32 20 3d 20 72  from_to_re_2 = r
1b60: 65 2e 63 6f 6d 70 69 6c 65 20 28 72 22 5e 28 5c  e.compile (r"^(\
1b70: 53 2b 29 5c 73 2b 28 5c 53 2b 29 28 5c 73 2b 28  S+)\s+(\S+)(\s+(
1b80: 2f 5b 41 49 42 5d 29 29 3f 24 22 29 0a 0a 23 20  /[AIB]))?$")..# 
1b90: 41 72 72 61 79 20 6f 66 20 72 65 67 75 6c 61 72  Array of regular
1ba0: 20 65 78 70 72 65 73 73 69 6f 6e 73 20 66 6f 72   expressions for
1bb0: 20 73 79 6e 74 61 78 20 63 68 65 63 6b 69 6e 67   syntax checking
1bc0: 20 69 6e 73 69 64 65 20 42 55 49 4c 44 0a 5f 62   inside BUILD._b
1bd0: 75 69 6c 64 5f 63 6f 6d 6d 5f 72 65 67 73 20 3d  uild_comm_regs =
1be0: 20 7b 22 4c 4f 41 44 22 20 20 3a 20 72 65 2e 63   {"LOAD"  : re.c
1bf0: 6f 6d 70 69 6c 65 28 72 22 5e 28 5c 53 2b 3a 29  ompile(r"^(\S+:)
1c00: 3f 5c 53 2b 28 2e 42 4e 29 3f 24 22 29 2c 0a 20  ?\S+(.BN)?$"),. 
1c10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1c20: 20 20 20 22 55 4e 4c 4f 41 44 22 3a 20 72 65 2e     "UNLOAD": re.
1c30: 63 6f 6d 70 69 6c 65 28 72 22 5e 5c 53 2b 28 2c  compile(r"^\S+(,
1c40: 5c 53 2b 29 3f 24 22 29 2c 0a 20 20 20 20 20 20  \S+)?$"),.      
1c50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 49                "I
1c60: 4e 53 45 52 54 22 3a 20 72 65 2e 63 6f 6d 70 69  NSERT": re.compi
1c70: 6c 65 28 72 22 5e 5c 53 2b 2c 5c 53 2b 28 2c 5c  le(r"^\S+,\S+(,\
1c80: 53 2b 29 3f 24 22 29 2c 0a 20 20 20 20 20 20 20  S+)?$"),.       
1c90: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 44 45               "DE
1ca0: 4c 45 54 45 22 3a 20 72 65 2e 63 6f 6d 70 69 6c  LETE": re.compil
1cb0: 65 28 72 22 5e 5c 53 2b 28 2c 5c 53 2b 29 3f 24  e(r"^\S+(,\S+)?$
1cc0: 22 29 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20  "),.            
1cd0: 20 20 20 20 20 20 20 20 22 53 59 53 54 45 4d 22          "SYSTEM"
1ce0: 3a 20 72 65 2e 63 6f 6d 70 69 6c 65 28 72 22 5e  : re.compile(r"^
1cf0: 5c 53 2b 24 22 29 2c 0a 20 20 20 20 20 20 20 20  \S+$"),.        
1d00: 20 20 20 20 20 20 20 20 20 20 20 20 22 44 53 4b              "DSK
1d10: 22 20 20 20 3a 20 72 65 2e 63 6f 6d 70 69 6c 65  "   : re.compile
1d20: 28 72 22 5e 28 5c 53 2b 3a 29 3f 5c 53 2b 24 22  (r"^(\S+:)?\S+$"
1d30: 29 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  ),.             
1d40: 20 20 20 20 20 20 20 22 42 55 49 4c 44 22 20 3a         "BUILD" :
1d50: 20 72 65 2e 63 6f 6d 70 69 6c 65 28 72 22 5e 28   re.compile(r"^(
1d60: 5c 53 2b 28 2e 42 4e 29 3f 29 5c 73 2b 28 5c 53  \S+(.BN)?)\s+(\S
1d70: 2b 28 2e 42 4e 29 3f 29 24 22 29 2c 0a 20 20 20  +(.BN)?)$"),.   
1d80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1d90: 20 22 50 52 49 4e 54 22 20 3a 20 4e 6f 6e 65 2c   "PRINT" : None,
1da0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
1db0: 20 20 20 20 20 22 42 4f 4f 54 22 20 20 3a 20 4e       "BOOT"  : N
1dc0: 6f 6e 65 2c 0a 20 20 20 20 20 20 20 20 20 20 20  one,.           
1dd0: 20 20 20 20 20 20 20 20 20 22 65 6e 64 22 20 20           "end"  
1de0: 20 3a 20 4e 6f 6e 65 7d 0a 0a 0a 23 20 50 61 72   : None}...# Par
1df0: 73 65 20 74 77 6f 20 77 68 69 74 73 70 61 63 65  se two whitspace
1e00: 20 73 65 70 61 72 61 74 65 64 20 61 72 67 75 6d   separated argum
1e10: 65 6e 74 73 20 69 6e 74 6f 20 67 72 6f 75 70 28  ents into group(
1e20: 31 29 20 61 6e 64 20 67 72 6f 75 70 28 32 29 0a  1) and group(2).
1e30: 5f 74 77 6f 5f 61 72 67 73 5f 72 65 20 3d 20 72  _two_args_re = r
1e40: 65 2e 63 6f 6d 70 69 6c 65 28 72 22 5e 28 5c 53  e.compile(r"^(\S
1e50: 2b 29 5c 73 2b 28 5c 53 2b 29 24 22 29 0a 0a 5f  +)\s+(\S+)$").._
1e60: 72 78 5f 73 65 74 74 69 6e 67 73 20 3d 20 5b 22  rx_settings = ["
1e70: 72 78 30 31 22 2c 20 22 72 78 30 32 22 2c 20 22  rx01", "rx02", "
1e80: 52 58 38 45 22 2c 20 22 52 58 32 38 22 5d 0a 5f  RX8E", "RX28"]._
1e90: 74 61 70 65 5f 73 65 74 74 69 6e 67 73 20 3d 20  tape_settings = 
1ea0: 5b 22 74 64 22 2c 20 22 64 74 22 5d 0a 5f 74 74  ["td", "dt"]._tt
1eb0: 69 5f 73 65 74 74 69 6e 67 73 20 3d 20 5b 22 4b  i_settings = ["K
1ec0: 53 52 22 2c 20 22 37 62 22 5d 0a 5f 63 6f 6e 66  SR", "7b"]._conf
1ed0: 69 67 75 72 61 62 6c 65 73 20 3d 20 7b 22 72 78  igurables = {"rx
1ee0: 22 3a 20 5f 72 78 5f 73 65 74 74 69 6e 67 73 2c  ": _rx_settings,
1ef0: 20 22 74 61 70 65 22 3a 20 5f 74 61 70 65 5f 73   "tape": _tape_s
1f00: 65 74 74 69 6e 67 73 2c 0a 20 20 20 20 20 20 20  ettings,.       
1f10: 20 20 20 20 20 20 20 20 20 20 20 22 74 74 69 22             "tti"
1f20: 3a 20 5f 74 74 69 5f 73 65 74 74 69 6e 67 73 7d  : _tti_settings}
1f30: 0a 0a 23 20 4d 61 74 63 68 65 73 20 69 66 20 74  ..# Matches if t
1f40: 68 65 20 73 74 72 69 6e 67 20 62 65 67 69 6e 73  he string begins
1f50: 20 77 69 74 68 20 61 20 64 6f 6c 6c 61 72 20 73   with a dollar s
1f60: 69 67 6e 2c 20 61 6e 64 20 68 61 73 20 61 74 20  ign, and has at 
1f70: 6c 65 61 73 74 0a 23 20 6f 6e 65 20 73 6c 61 73  least.# one slas
1f80: 68 2c 20 72 65 74 75 72 6e 69 6e 67 20 74 68 65  h, returning the
1f90: 20 73 74 72 69 6e 67 20 62 65 74 77 65 65 6e 20   string between 
1fa0: 74 68 65 20 64 6f 6c 6c 61 72 20 73 69 67 6e 20  the dollar sign 
1fb0: 61 6e 64 20 74 68 65 0a 23 20 66 69 72 73 74 20  and the.# first 
1fc0: 73 6c 61 73 68 20 69 6e 20 67 72 6f 75 70 20 31  slash in group 1
1fd0: 20 61 6e 64 20 74 68 65 20 72 65 73 74 20 69 6e   and the rest in
1fe0: 20 67 72 6f 75 70 20 32 2e 0a 23 20 4e 6f 20 77   group 2..# No w
1ff0: 68 69 74 65 73 70 61 63 65 20 69 6e 20 74 68 65  hitespace in the
2000: 20 73 74 72 69 6e 67 2e 0a 5f 65 78 70 61 6e 64   string.._expand
2010: 61 62 6c 65 5f 72 65 20 3d 20 72 65 2e 63 6f 6d  able_re = re.com
2020: 70 69 6c 65 20 28 72 22 5e 5c 24 28 5b 5e 2f 5c  pile (r"^\$([^/\
2030: 73 5d 2b 29 2f 28 5c 53 2a 29 24 22 29 0a 0a 23  s]+)/(\S*)$")..#
2040: 20 50 61 72 73 65 20 61 6e 20 65 78 69 74 20 61   Parse an exit a
2050: 72 67 20 66 6f 72 20 61 6e 20 69 6e 74 65 67 65  rg for an intege
2060: 72 20 6f 72 20 61 6e 20 69 6e 74 65 67 65 72 20  r or an integer 
2070: 69 6e 20 70 61 72 65 6e 74 68 65 73 65 73 0a 5f  in parentheses._
2080: 65 78 69 74 5f 61 72 67 5f 72 65 20 3d 20 72 65  exit_arg_re = re
2090: 2e 63 6f 6d 70 69 6c 65 20 28 72 22 5e 28 5c 73  .compile (r"^(\s
20a0: 2a 5b 2b 2d 5d 3f 5c 73 2a 5c 64 2b 29 7c 5c 73  *[+-]?\s*\d+)|\s
20b0: 2a 5c 28 5c 73 2a 28 5b 2b 2d 5d 3f 5c 73 2a 5c  *\(\s*([+-]?\s*\
20c0: 64 2b 29 5c 73 2a 5c 29 5c 73 2a 24 22 29 0a 0a  d+)\s*\)\s*$")..
20d0: 23 20 4f 70 74 69 6f 6e 73 20 65 6e 61 62 6c 65  # Options enable
20e0: 64 2f 6e 6f 74 5f 64 69 73 61 62 6c 65 64 20 66  d/not_disabled f
20f0: 6f 72 20 63 6f 6e 64 69 74 69 6f 6e 61 6c 20 65  or conditional e
2100: 78 65 63 75 74 69 6f 6e 20 69 6e 20 73 63 72 69  xecution in scri
2110: 70 74 73 2e 0a 23 0a 23 20 45 61 72 6c 69 65 72  pts..#.# Earlier
2120: 20 63 6f 64 65 20 61 6c 6c 6f 77 65 64 20 2d 2d   code allowed --
2130: 65 6e 61 62 6c 65 20 61 6e 64 20 2d 2d 64 69 73  enable and --dis
2140: 61 62 6c 65 2e 20 57 65 20 69 6e 74 65 72 66 61  able. We interfa
2150: 63 65 20 74 6f 20 69 74 2e 0a 23 20 57 65 20 6d  ce to it..# We m
2160: 61 69 6e 74 61 69 6e 20 74 77 6f 20 61 72 72 61  aintain two arra
2170: 79 73 3a 20 6f 70 74 69 6f 6e 73 5f 65 6e 61 62  ys: options_enab
2180: 6c 65 20 61 6e 64 20 6f 70 74 69 6f 6e 73 5f 64  le and options_d
2190: 69 73 61 62 6c 65 64 20 66 6f 72 20 74 68 6f 73  isabled for thos
21a0: 65 0a 23 20 74 77 6f 20 61 72 67 75 6d 65 6e 74  e.# two argument
21b0: 20 63 6f 6e 73 74 72 75 63 74 73 2e 0a 23 0a 23   constructs..#.#
21c0: 20 41 72 67 75 6d 65 6e 74 20 70 61 72 73 69 6e   Argument parsin
21d0: 67 20 6f 66 20 72 65 70 65 61 74 65 64 20 65 6e  g of repeated en
21e0: 61 62 6c 65 20 61 6e 64 20 64 69 73 61 62 6c 65  able and disable
21f0: 20 61 72 67 75 6d 65 6e 74 73 20 69 73 20 61 73   arguments is as
2200: 20 66 6f 6c 6c 6f 77 73 3a 0a 23 20 2d 2d 65 6e   follows:.# --en
2210: 61 62 6c 65 20 6c 6f 6f 6b 73 20 6f 6e 20 6f 70  able looks on op
2220: 74 69 6f 6e 73 5f 64 69 73 61 62 6c 65 64 20 61  tions_disabled a
2230: 6e 64 20 69 66 20 70 72 65 73 65 6e 74 20 72 65  nd if present re
2240: 6d 6f 76 65 73 20 69 74 2c 20 74 68 65 6e 20 61  moves it, then a
2250: 64 64 73 0a 23 20 74 6f 20 6f 70 74 69 6f 6e 73  dds.# to options
2260: 5f 65 6e 61 62 6c 65 64 2e 0a 23 20 2d 2d 64 69  _enabled..# --di
2270: 73 61 62 6c 65 20 6c 6f 6f 6b 73 20 6f 6e 20 6f  sable looks on o
2280: 70 74 69 6f 6e 73 5f 65 6e 61 62 6c 65 64 20 61  ptions_enabled a
2290: 6e 64 20 69 66 20 70 72 65 73 65 6e 74 20 72 65  nd if present re
22a0: 6d 6f 76 65 73 20 69 74 2c 20 74 68 65 6e 20 61  moves it, then a
22b0: 64 64 73 0a 23 20 74 6f 20 6f 70 74 69 6f 6e 73  dds.# to options
22c0: 5f 65 6e 61 62 6c 65 64 2e 0a 23 0a 23 20 4c 61  _enabled..#.# La
22d0: 73 74 20 73 65 65 6e 20 65 6e 61 62 6c 65 2f 64  st seen enable/d
22e0: 69 73 61 62 6c 65 20 63 6f 6d 6d 61 6e 64 20 6c  isable command l
22f0: 69 6e 65 20 6f 72 20 65 78 65 63 75 74 65 64 20  ine or executed 
2300: 63 6f 6d 6d 61 6e 64 20 66 6f 72 20 61 0a 23 20  command for a.# 
2310: 70 61 72 74 69 63 75 6c 61 72 20 6f 70 74 69 6f  particular optio
2320: 6e 20 77 69 6e 73 2e 0a 23 0a 23 20 53 63 72 69  n wins..#.# Scri
2330: 70 74 73 20 68 61 76 65 20 65 6e 61 62 6c 65 2f  pts have enable/
2340: 64 69 73 61 62 6c 65 20 63 6f 6d 6d 61 6e 64 73  disable commands
2350: 20 74 68 61 74 20 61 72 65 20 72 75 6e 2d 74 69   that are run-ti
2360: 6d 65 0a 23 20 63 68 61 6e 67 65 72 73 20 6f 66  me.# changers of
2370: 20 74 68 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66   the contents of
2380: 20 6f 70 74 69 6f 6e 73 5f 65 6e 61 62 6c 65 64   options_enabled
2390: 20 61 6e 64 20 6f 70 74 69 6f 6e 73 5f 64 69 73   and options_dis
23a0: 61 62 6c 65 64 2e 0a 23 0a 23 20 57 68 65 6e 20  abled..#.# When 
23b0: 77 65 20 72 75 6e 20 61 20 73 63 72 69 70 74 20  we run a script 
23c0: 77 65 20 68 61 76 65 20 62 65 67 69 6e 2f 65 6e  we have begin/en
23d0: 64 20 62 6c 6f 63 6b 73 20 66 6f 72 20 65 6e 61  d blocks for ena
23e0: 62 6c 65 64 2f 6e 6f 74 5f 64 69 73 61 62 6c 65  bled/not_disable
23f0: 64 20 6f 70 74 69 6f 6e 73 3a 0a 23 20 22 62 65  d options:.# "be
2400: 67 69 6e 20 65 6e 61 62 6c 65 64 20 3c 6f 70 74  gin enabled <opt
2410: 69 6f 6e 20 6e 61 6d 65 3e 22 20 2e 2e 2e 20 22  ion name>" ... "
2420: 65 6e 64 20 65 6e 61 62 6c 65 64 20 3c 6f 70 74  end enabled <opt
2430: 69 6f 6e 20 6e 61 6d 65 3e 0a 23 20 22 62 65 67  ion name>.# "beg
2440: 69 6e 20 6e 6f 74 5f 64 69 73 61 62 6c 65 64 20  in not_disabled 
2450: 3c 6f 70 74 69 6f 6e 20 6e 61 6d 65 3e 22 20 2e  <option name>" .
2460: 2e 2e 20 22 65 6e 64 20 6e 6f 74 5f 64 69 73 61  .. "end not_disa
2470: 62 6c 65 64 20 3c 6f 70 74 69 6f 6e 20 6e 61 6d  bled <option nam
2480: 65 3e 0a 23 0a 23 20 54 68 65 20 65 6e 61 62 6c  e>.#.# The enabl
2490: 65 64 20 62 6c 6f 63 6b 20 6c 6f 6f 6b 73 20 66  ed block looks f
24a0: 6f 72 20 61 6e 20 65 78 70 6c 69 63 69 74 20 65  or an explicit e
24b0: 6e 61 62 6c 65 6d 65 6e 74 20 6f 6e 20 74 68 65  nablement on the
24c0: 20 6f 70 74 69 6f 6e 73 5f 65 6e 61 62 6c 65 64   options_enabled
24d0: 0a 23 20 6c 69 73 74 2e 20 49 66 20 6e 6f 6e 65  .# list. If none
24e0: 20 69 73 20 66 6f 75 6e 64 20 77 65 20 64 65 66   is found we def
24f0: 61 75 6c 74 20 74 6f 20 69 67 6e 6f 72 69 6e 67  ault to ignoring
2500: 20 74 68 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66   the contents of
2510: 20 74 68 65 20 62 6c 6f 63 6b 2e 0a 23 0a 23 20   the block..#.# 
2520: 54 68 65 20 6e 6f 74 5f 64 69 73 61 62 6c 65 64  The not_disabled
2530: 20 62 6c 6f 63 6b 20 6c 6f 6f 6b 73 20 66 6f 72   block looks for
2540: 20 61 6e 20 65 78 70 6c 69 63 69 74 20 64 69 73   an explicit dis
2550: 61 62 6c 65 6d 65 6e 74 20 6f 6e 20 74 68 65 0a  ablement on the.
2560: 23 20 6f 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c  # options_disabl
2570: 65 64 20 6c 69 73 2e 20 20 49 66 20 66 6f 75 6e  ed lis.  If foun
2580: 64 2c 20 74 68 65 20 62 6c 6f 63 6b 20 69 73 20  d, the block is 
2590: 69 67 6e 6f 72 65 64 2e 20 4f 74 68 65 72 77 69  ignored. Otherwi
25a0: 73 65 0a 23 20 74 68 65 20 62 6c 6f 63 6b 20 64  se.# the block d
25b0: 65 66 61 75 6c 74 73 20 74 6f 20 62 65 69 6e 67  efaults to being
25c0: 20 65 78 65 63 75 74 65 64 2e 0a 23 0a 23 20 62   executed..#.# b
25d0: 65 67 69 6e 2f 65 6e 64 20 62 6c 6f 63 6b 73 20  egin/end blocks 
25e0: 63 61 6e 20 62 65 20 6e 65 73 74 65 64 2e 20 20  can be nested.  
25f0: 57 65 20 74 72 61 63 6b 20 74 68 65 20 6e 65 73  We track the nes
2600: 74 69 6e 67 20 77 69 74 68 20 6f 70 74 69 6f 6e  ting with option
2610: 73 5f 73 74 61 63 6b 2e 0a 23 20 54 65 73 74 69  s_stack..# Testi
2620: 6e 67 20 66 6f 72 20 6f 70 74 69 6f 6e 73 20 68  ng for options h
2630: 61 70 70 65 6e 73 20 77 68 65 6e 20 74 68 65 20  appens when the 
2640: 62 65 67 69 6e 20 63 6f 6d 6d 61 6e 64 20 69 73  begin command is
2650: 20 65 76 61 6c 75 61 74 65 64 2e 0a 23 20 53 6f   evaluated..# So
2660: 20 63 68 61 6e 67 69 6e 67 20 61 6e 20 65 6e 61   changing an ena
2670: 62 6c 65 2f 64 69 73 61 62 6c 65 20 6f 70 74 69  ble/disable opti
2680: 6f 6e 20 69 6e 73 69 64 65 20 61 20 62 65 67 69  on inside a begi
2690: 6e 2f 65 6e 64 20 62 6c 6f 63 6b 0a 23 20 74 61  n/end block.# ta
26a0: 6b 65 73 20 65 66 66 65 63 74 20 61 74 20 74 68  kes effect at th
26b0: 65 20 6e 65 78 74 20 62 65 67 69 6e 20 73 74 61  e next begin sta
26c0: 74 65 6d 65 6e 74 2e 20 0a 23 20 59 6f 75 20 63  tement. .# You c
26d0: 61 6e 20 77 72 69 74 65 20 61 20 73 63 72 69 70  an write a scrip
26e0: 74 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 23 20  t as follows:.# 
26f0: 65 6e 61 62 6c 65 20 66 6f 6f 0a 23 20 62 65 67  enable foo.# beg
2700: 69 6e 20 65 6e 61 62 6c 65 64 20 66 6f 6f 0a 23  in enabled foo.#
2710: 20 23 20 43 6f 6d 6d 61 6e 64 73 20 74 6f 20 65   # Commands to e
2720: 78 65 63 75 74 65 64 0a 23 20 64 69 73 61 62 6c  xecuted.# disabl
2730: 65 20 66 6f 6f 0a 23 20 23 20 43 6f 6d 6d 61 6e  e foo.# # Comman
2740: 64 73 20 73 74 69 6c 6c 20 62 65 69 6e 67 20 65  ds still being e
2750: 78 65 63 75 74 65 64 2e 0a 23 20 62 65 67 69 6e  xecuted..# begin
2760: 20 65 6e 61 62 6c 65 64 20 66 6f 6f 0a 23 20 23   enabled foo.# #
2770: 20 43 6f 6d 6d 61 6e 64 73 20 74 6f 20 69 67 6e   Commands to ign
2780: 6f 72 65 0a 23 20 65 6e 64 20 65 6e 61 62 6c 65  ore.# end enable
2790: 64 20 66 6f 6f 0a 23 20 65 6e 64 20 65 6e 61 62  d foo.# end enab
27a0: 6c 65 64 20 66 6f 6f 0a 0a 23 20 4c 6f 63 61 6c  led foo..# Local
27b0: 20 72 6f 75 74 69 6e 65 20 74 6f 20 70 65 72 66   routine to perf
27c0: 6f 72 6d 20 61 20 73 61 76 65 20 6f 66 20 61 20  orm a save of a 
27d0: 70 72 65 2d 65 78 69 73 74 69 6e 67 20 66 69 6c  pre-existing fil
27e0: 65 0a 23 20 62 65 63 61 75 73 65 20 77 65 20 64  e.# because we d
27f0: 6f 20 74 68 69 73 20 69 6e 20 61 20 63 6f 75 70  o this in a coup
2800: 6c 65 20 70 6c 61 63 65 73 0a 0a 64 65 66 20 73  le places..def s
2810: 61 76 65 5f 69 66 5f 6e 65 65 64 65 64 28 70 61  ave_if_needed(pa
2820: 74 68 29 3a 0a 20 20 69 66 20 6f 73 2e 70 61 74  th):.  if os.pat
2830: 68 2e 69 73 66 69 6c 65 28 70 61 74 68 29 3a 0a  h.isfile(path):.
2840: 20 20 20 20 73 61 76 65 5f 70 61 74 68 20 3d 20      save_path = 
2850: 70 61 74 68 20 2b 20 22 2e 73 61 76 65 22 0a 20  path + ".save". 
2860: 20 20 20 70 72 69 6e 74 28 22 50 72 65 2d 65 78     print("Pre-ex
2870: 69 73 74 69 6e 67 20 22 20 2b 20 70 61 74 68 20  isting " + path 
2880: 2b 20 22 20 66 6f 75 6e 64 2e 20 20 53 61 76 69  + " found.  Savi
2890: 6e 67 20 61 73 20 22 20 2b 20 70 61 74 68 20 2b  ng as " + path +
28a0: 20 22 2e 73 61 76 65 22 29 0a 20 20 20 20 69 66   ".save").    if
28b0: 20 6f 73 2e 70 61 74 68 2e 69 73 66 69 6c 65 28   os.path.isfile(
28c0: 73 61 76 65 5f 70 61 74 68 29 3a 0a 20 20 20 20  save_path):.    
28d0: 20 20 70 72 69 6e 74 28 22 4f 76 65 72 77 72 69    print("Overwri
28e0: 74 69 6e 67 20 6f 6c 64 20 22 20 2b 20 70 61 74  ting old " + pat
28f0: 68 20 2b 20 22 2e 73 61 76 65 22 29 0a 20 20 20  h + ".save").   
2900: 20 20 20 6f 73 2e 72 65 6d 6f 76 65 28 73 61 76     os.remove(sav
2910: 65 5f 70 61 74 68 29 0a 20 20 20 20 6f 73 2e 72  e_path).    os.r
2920: 65 6e 61 6d 65 28 70 61 74 68 2c 20 73 61 76 65  ename(path, save
2930: 5f 70 61 74 68 29 0a 20 20 0a 64 65 66 20 76 65  _path).  .def ve
2940: 72 73 69 6f 6e 5f 74 6f 5f 61 72 72 61 79 20 28  rsion_to_array (
2950: 76 65 72 73 69 6f 6e 29 3a 0a 20 20 76 65 72 73  version):.  vers
2960: 5f 61 72 72 61 79 20 3d 20 5b 5d 0a 20 20 74 68  _array = [].  th
2970: 69 73 5f 73 74 72 20 3d 20 22 22 0a 0a 20 20 66  is_str = ""..  f
2980: 6f 72 20 63 20 69 6e 20 76 65 72 73 69 6f 6e 3a  or c in version:
2990: 0a 20 20 20 20 69 66 20 63 20 21 3d 20 22 2e 22  .    if c != "."
29a0: 3a 0a 20 20 20 20 20 20 74 68 69 73 5f 73 74 72  :.      this_str
29b0: 20 2b 3d 20 63 0a 20 20 20 20 65 6c 73 65 3a 0a   += c.    else:.
29c0: 20 20 20 20 20 20 76 65 72 73 5f 61 72 72 61 79        vers_array
29d0: 2e 61 70 70 65 6e 64 28 74 68 69 73 5f 73 74 72  .append(this_str
29e0: 29 0a 20 20 20 20 20 20 74 68 69 73 5f 73 74 72  ).      this_str
29f0: 20 3d 20 22 22 0a 20 20 69 66 20 74 68 69 73 5f   = "".  if this_
2a00: 73 74 72 20 21 3d 20 22 22 3a 20 76 65 72 73 5f  str != "": vers_
2a10: 61 72 72 61 79 2e 61 70 70 65 6e 64 28 74 68 69  array.append(thi
2a20: 73 5f 73 74 72 29 0a 20 20 72 65 74 75 72 6e 20  s_str).  return 
2a30: 76 65 72 73 5f 61 72 72 61 79 0a 0a 0a 63 6c 61  vers_array...cla
2a40: 73 73 20 6f 73 38 73 63 72 69 70 74 3a 0a 20 20  ss os8script:.  
2a50: 23 20 43 6f 6e 74 61 69 6e 73 20 61 20 73 69 6d  # Contains a sim
2a60: 68 20 6f 62 6a 65 63 74 2c 20 6f 74 68 65 72 20  h object, other 
2a70: 67 6c 6f 62 61 6c 20 73 74 61 74 65 20 61 6e 64  global state and
2a80: 20 6d 65 74 68 6f 64 73 0a 20 20 23 20 66 6f 72   methods.  # for
2a90: 20 72 75 6e 6e 69 6e 67 20 4f 53 2f 38 20 73 63   running OS/8 sc
2aa0: 72 69 70 74 73 20 75 6e 64 65 72 20 73 69 6d 68  ripts under simh
2ab0: 2e 0a 20 20 23 23 23 23 20 67 6c 6f 62 61 6c 73  ..  #### globals
2ac0: 20 61 6e 64 20 63 6f 6e 73 74 61 6e 74 73 20 23   and constants #
2ad0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
2ae0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
2af0: 23 23 23 23 23 23 23 23 23 23 0a 0a 20 20 23 20  ##########..  # 
2b00: 52 65 70 6c 69 65 73 20 74 68 61 74 20 70 61 6c  Replies that pal
2b10: 38 20 61 64 64 73 2e 0a 20 20 5f 70 61 6c 38 5f  8 adds..  _pal8_
2b20: 72 65 70 5f 61 64 64 73 20 3d 20 5b 0a 20 20 20  rep_adds = [.   
2b30: 20 23 20 50 72 6f 6d 70 74 73 20 63 6f 6d 65 20   # Prompts come 
2b40: 66 72 6f 6d 20 74 68 65 20 65 78 69 73 74 69 6e  from the existin
2b50: 67 20 5f 6f 73 38 5f 72 65 70 6c 69 65 73 0a 20  g _os8_replies. 
2b60: 20 20 20 23 20 53 74 61 74 75 73 3a 0a 20 20 20     # Status:.   
2b70: 20 5b 22 45 52 52 4f 52 53 20 44 45 54 45 43 54   ["ERRORS DETECT
2b80: 45 44 22 2c 20 22 45 52 52 4f 52 53 20 44 45 54  ED", "ERRORS DET
2b90: 45 43 54 45 44 3a 20 22 2c 20 46 61 6c 73 65 5d  ECTED: ", False]
2ba0: 2c 0a 20 20 20 20 5b 22 4c 49 4e 4b 53 20 47 45  ,.    ["LINKS GE
2bb0: 4e 45 52 41 54 45 44 22 2c 20 22 4c 49 4e 4b 53  NERATED", "LINKS
2bc0: 20 47 45 4e 45 52 41 54 45 44 3a 20 22 2c 20 46   GENERATED: ", F
2bd0: 61 6c 73 65 5d 2c 0a 20 20 20 20 23 20 45 72 72  alse],.    # Err
2be0: 6f 72 73 3a 0a 20 20 20 20 5b 22 42 75 66 66 65  ors:.    ["Buffe
2bf0: 72 20 45 78 63 65 65 64 65 64 22 2c 20 72 22 42  r Exceeded", r"B
2c00: 45 5c 73 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 54 72  E\s+\S+.*\r", Tr
2c10: 75 65 5d 2c 0a 20 20 20 20 5b 22 43 72 65 66 20  ue],.    ["Cref 
2c20: 6e 6f 74 20 46 6f 75 6e 64 22 2c 20 72 22 43 46  not Found", r"CF
2c30: 5c 73 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 46 61 6c  \s+\S+.*\r", Fal
2c40: 73 65 5d 2c 0a 20 20 20 20 5b 22 44 65 76 69 63  se],.    ["Devic
2c50: 65 20 45 72 72 6f 72 22 2c 20 72 22 44 45 5c 73  e Error", r"DE\s
2c60: 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 54 72 75 65 5d  +\S+.*\r", True]
2c70: 2c 0a 20 20 20 20 5b 22 44 65 76 69 63 65 20 46  ,.    ["Device F
2c80: 75 6c 6c 22 2c 20 72 22 44 46 5c 72 22 2c 20 54  ull", r"DF\r", T
2c90: 72 75 65 5d 2c 0a 20 20 20 20 5b 22 49 6c 6c 65  rue],.    ["Ille
2ca0: 67 61 6c 20 43 68 61 72 61 63 74 65 72 22 2c 20  gal Character", 
2cb0: 72 22 49 43 5c 73 2b 5c 53 2b 2e 2a 5c 72 22 2c  r"IC\s+\S+.*\r",
2cc0: 20 46 61 6c 73 65 5d 2c 0a 20 20 20 20 5b 22 49   False],.    ["I
2cd0: 6c 6c 65 67 61 6c 20 72 65 2d 44 65 66 69 6e 69  llegal re-Defini
2ce0: 74 69 6f 6e 22 2c 20 72 22 49 44 5c 73 2b 5c 53  tion", r"ID\s+\S
2cf0: 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73 65 5d 2c 0a  +.*\r", False],.
2d00: 20 20 20 20 5b 22 49 6c 6c 65 67 61 6c 20 45 71      ["Illegal Eq
2d10: 75 61 6c 73 22 2c 20 72 22 49 45 5c 73 2b 5c 53  uals", r"IE\s+\S
2d20: 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73 65 5d 2c 0a  +.*\r", False],.
2d30: 20 20 20 20 5b 22 49 6c 6c 65 67 61 6c 20 49 6e      ["Illegal In
2d40: 64 69 72 65 63 74 22 2c 20 72 22 49 49 5c 73 2b  direct", r"II\s+
2d50: 5c 53 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73 65 5d  \S+.*\r", False]
2d60: 2c 0a 20 20 20 20 5b 22 49 6c 6c 65 67 61 6c 20  ,.    ["Illegal 
2d70: 50 73 65 75 64 6f 4f 70 22 2c 20 72 22 49 50 5c  PseudoOp", r"IP\
2d80: 73 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73  s+\S+.*\r", Fals
2d90: 65 5d 2c 0a 20 20 20 20 5b 22 49 6c 6c 65 67 61  e],.    ["Illega
2da0: 6c 20 70 61 67 65 20 5a 65 72 6f 20 72 65 66 65  l page Zero refe
2db0: 72 65 6e 63 65 22 2c 20 72 22 49 5a 5c 73 2b 5c  rence", r"IZ\s+\
2dc0: 53 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73 65 5d 2c  S+.*\r", False],
2dd0: 0a 20 20 20 20 5b 22 4c 6f 61 64 65 72 20 6e 6f  .    ["Loader no
2de0: 74 20 66 6f 75 6e 44 22 2c 20 72 22 4c 44 5c 73  t founD", r"LD\s
2df0: 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73 65  +\S+.*\r", False
2e00: 5d 2c 0a 20 20 20 20 5b 22 4c 69 6e 6b 20 47 65  ],.    ["Link Ge
2e10: 6e 65 72 61 74 65 64 22 2c 20 72 22 4c 47 5c 73  nerated", r"LG\s
2e20: 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73 65  +\S+.*\r", False
2e30: 5d 2c 0a 20 20 20 20 5b 22 63 75 72 72 65 6e 74  ],.    ["current
2e40: 20 50 61 67 65 20 45 78 63 65 65 64 65 64 22 2c   Page Exceeded",
2e50: 20 72 22 50 45 5c 73 2b 5c 53 2b 2e 2a 5c 72 22   r"PE\s+\S+.*\r"
2e60: 2c 20 46 61 6c 73 65 5d 2c 0a 20 20 20 20 5b 22  , False],.    ["
2e70: 50 48 61 73 65 20 45 72 72 6f 72 22 2c 20 72 22  PHase Error", r"
2e80: 50 48 5c 73 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 46  PH\s+\S+.*\r", F
2e90: 61 6c 73 65 5d 2c 0a 20 20 20 20 5b 22 52 65 20  alse],.    ["Re 
2ea0: 44 65 66 69 6e 69 74 69 6f 6e 22 2c 20 72 22 52  Definition", r"R
2eb0: 44 5c 73 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 46 61  D\s+\S+.*\r", Fa
2ec0: 6c 73 65 5d 2c 0a 20 20 20 20 5b 22 53 79 6d 62  lse],.    ["Symb
2ed0: 6f 6c 20 74 61 62 6c 65 20 45 78 63 65 65 64 65  ol table Exceede
2ee0: 64 22 2c 20 72 22 53 45 5c 73 2b 5c 53 2b 2e 2a  d", r"SE\s+\S+.*
2ef0: 5c 72 22 2c 20 46 61 6c 73 65 5d 2c 0a 20 20 20  \r", False],.   
2f00: 20 5b 22 55 6e 64 65 66 69 6e 65 64 20 4f 72 69   ["Undefined Ori
2f10: 67 69 6e 22 2c 20 72 22 55 4f 5c 73 2b 5c 53 2b  gin", r"UO\s+\S+
2f20: 2e 2a 5c 72 22 2c 20 46 61 6c 73 65 5d 2c 0a 20  .*\r", False],. 
2f30: 20 20 20 5b 22 55 6e 64 65 66 69 6e 65 64 20 53     ["Undefined S
2f40: 79 6d 62 6f 6c 22 2c 20 72 22 55 53 5c 73 2b 5c  ymbol", r"US\s+\
2f50: 53 2e 2a 5c 72 22 2c 20 46 61 6c 73 65 5d 2c 0a  S.*\r", False],.
2f60: 20 20 20 20 5b 22 70 61 67 65 20 5a 65 72 6f 20      ["page Zero 
2f70: 45 78 63 65 65 64 65 64 22 2c 20 72 22 5a 45 5c  Exceeded", r"ZE\
2f80: 73 2b 5c 53 2b 2e 2a 5c 72 22 2c 20 46 61 6c 73  s+\S+.*\r", Fals
2f90: 65 5d 2c 0a 20 20 20 20 5b 22 4e 4f 54 20 46 4f  e],.    ["NOT FO
2fa0: 55 4e 44 22 2c 20 72 22 5c 53 2b 20 4e 4f 54 20  UND", r"\S+ NOT 
2fb0: 46 4f 55 4e 44 22 2c 20 46 61 6c 73 65 5d 2c 0a  FOUND", False],.
2fc0: 20 20 5d 0a 20 20 0a 20 20 5f 62 75 69 6c 64 5f    ].  .  _build_
2fd0: 72 65 70 5f 61 64 64 73 20 3d 20 5b 0a 20 20 20  rep_adds = [.   
2fe0: 20 23 20 50 72 6f 6d 70 74 73 3a 0a 20 20 20 20   # Prompts:.    
2ff0: 23 20 41 64 64 20 74 68 65 20 42 55 49 4c 44 20  # Add the BUILD 
3000: 70 72 6f 6d 70 74 0a 20 20 20 20 23 20 53 75 62  prompt.    # Sub
3010: 74 6c 65 20 70 6f 69 6e 74 3a 20 20 44 6f 6c 6c  tle point:  Doll
3020: 61 72 20 73 69 67 6e 20 61 70 70 65 61 72 73 20  ar sign appears 
3030: 69 6e 20 61 6c 6c 20 6b 69 6e 64 73 20 6f 66 20  in all kinds of 
3040: 6f 75 74 70 75 74 0a 20 20 20 20 23 20 73 6f 20  output.    # so 
3050: 77 65 20 74 72 79 20 74 6f 20 6d 69 6e 69 6d 69  we try to minimi
3060: 7a 65 20 77 68 65 72 65 20 77 65 20 6c 6f 6f 6b  ze where we look
3070: 20 66 6f 72 20 69 74 20 73 6f 20 61 73 20 74 6f   for it so as to
3080: 20 61 76 6f 69 64 0a 20 20 20 20 23 20 63 6f 6e   avoid.    # con
3090: 66 75 73 69 6e 67 20 70 65 78 70 65 63 74 2e 0a  fusing pexpect..
30a0: 20 20 20 20 5b 22 42 55 49 4c 44 20 50 72 6f 6d      ["BUILD Prom
30b0: 70 74 22 2c 20 22 5c 6e 5c 5c 24 24 22 2c 20 54  pt", "\n\\$$", T
30c0: 72 75 65 5d 2c 0a 20 20 20 20 23 20 53 74 61 74  rue],.    # Stat
30d0: 75 73 3a 0a 20 20 20 20 5b 22 53 59 53 20 42 55  us:.    ["SYS BU
30e0: 49 4c 54 22 2c 20 22 53 59 53 20 42 55 49 4c 54  ILT", "SYS BUILT
30f0: 22 2c 20 46 61 6c 73 65 5d 2c 0a 20 20 20 20 5b  ", False],.    [
3100: 22 57 52 49 54 45 20 5a 45 52 4f 20 44 49 52 45  "WRITE ZERO DIRE
3110: 43 54 3f 22 2c 20 22 57 52 49 54 45 20 5a 45 52  CT?", "WRITE ZER
3120: 4f 20 44 49 52 45 43 54 5c 5c 3f 22 2c 20 46 61  O DIRECT\\?", Fa
3130: 6c 73 65 5d 2c 0a 20 20 20 20 5b 22 4c 4f 41 44  lse],.    ["LOAD
3140: 20 4f 53 38 22 2c 20 22 4c 4f 41 44 20 4f 53 2f   OS8", "LOAD OS/
3150: 38 3a 20 22 2c 20 46 61 6c 73 65 5d 2c 0a 20 20  8: ", False],.  
3160: 20 20 5b 22 4c 4f 41 44 20 43 44 22 2c 20 22 4c    ["LOAD CD", "L
3170: 4f 41 44 20 43 44 3a 20 22 2c 20 46 61 6c 73 65  OAD CD: ", False
3180: 5d 2c 0a 20 20 20 20 23 20 45 72 72 6f 72 73 3a  ],.    # Errors:
3190: 0a 20 20 20 20 5b 22 42 41 44 20 41 52 47 22 2c  .    ["BAD ARG",
31a0: 20 22 5c 5c 3f 42 41 44 20 41 52 47 22 2c 20 46   "\\?BAD ARG", F
31b0: 61 6c 73 65 5d 2c 0a 20 20 20 20 5b 22 42 41 44  alse],.    ["BAD
31c0: 20 49 4e 50 55 54 22 2c 20 22 5c 5c 3f 42 41 44   INPUT", "\\?BAD
31d0: 20 49 4e 50 55 54 22 2c 20 46 61 6c 73 65 5d 2c   INPUT", False],
31e0: 0a 20 20 20 20 5b 22 42 41 44 20 4c 4f 41 44 22  .    ["BAD LOAD"
31f0: 2c 20 22 5c 5c 3f 42 41 44 20 4c 4f 41 44 22 2c  , "\\?BAD LOAD",
3200: 20 46 61 6c 73 65 5d 2c 0a 20 20 20 20 5b 22 42   False],.    ["B
3210: 41 44 20 4f 52 49 47 49 4e 22 2c 20 22 5c 5c 3f  AD ORIGIN", "\\?
3220: 42 41 44 20 4f 52 49 47 49 4e 22 2c 20 46 61 6c  BAD ORIGIN", Fal
3230: 73 65 5d 2c 0a 20 20 20 20 5b 22 43 4f 52 45 22  se],.    ["CORE"
3240: 2c 20 22 5c 5c 3f 43 4f 52 45 22 2c 20 46 61 6c  , "\\?CORE", Fal
3250: 73 65 5d 2c 0a 20 20 20 20 5b 22 44 53 4b 22 2c  se],.    ["DSK",
3260: 20 22 5c 5c 3f 44 53 4b 22 2c 20 46 61 6c 73 65   "\\?DSK", False
3270: 5d 2c 0a 20 20 20 20 5b 22 48 41 4e 44 4c 45 52  ],.    ["HANDLER
3280: 53 22 2c 20 22 5c 5c 3f 48 41 4e 44 4c 45 52 53  S", "\\?HANDLERS
3290: 22 2c 20 46 61 6c 73 65 5d 2c 0a 20 20 20 20 5b  ", False],.    [
32a0: 22 49 2f 4f 20 45 52 52 22 2c 20 22 49 2f 4f 20  "I/O ERR", "I/O 
32b0: 45 52 52 22 2c 20 46 61 6c 73 65 5d 2c 0a 20 20  ERR", False],.  
32c0: 20 20 5b 22 4e 41 4d 45 22 2c 20 22 5c 5c 3f 4e    ["NAME", "\\?N
32d0: 41 4d 45 22 2c 20 46 61 6c 73 65 5d 2c 0a 20 20  AME", False],.  
32e0: 20 20 5b 22 4e 4f 20 52 4f 4f 4d 22 2c 20 22 4e    ["NO ROOM", "N
32f0: 4f 20 52 4f 4f 4d 22 2c 20 46 61 6c 73 65 5d 2c  O ROOM", False],
3300: 0a 20 20 20 20 5b 22 53 59 53 20 4e 4f 54 20 46  .    ["SYS NOT F
3310: 4f 55 4e 44 22 2c 20 22 53 59 53 20 4e 4f 54 20  OUND", "SYS NOT 
3320: 46 4f 55 4e 44 22 2c 20 46 61 6c 73 65 5d 2c 0a  FOUND", False],.
3330: 20 20 20 20 5b 22 50 4c 41 54 22 2c 20 22 5c 5c      ["PLAT", "\\
3340: 3f 50 4c 41 54 22 2c 20 46 61 6c 73 65 5d 2c 0a  ?PLAT", False],.
3350: 20 20 20 20 5b 22 53 59 4e 54 41 58 22 2c 20 22      ["SYNTAX", "
3360: 5c 5c 3f 53 59 4e 54 41 58 22 2c 20 46 61 6c 73  \\?SYNTAX", Fals
3370: 65 5d 2c 0a 20 20 20 20 5b 22 53 59 53 22 2c 20  e],.    ["SYS", 
3380: 22 5c 5c 3f 53 59 53 22 2c 20 46 61 6c 73 65 5d  "\\?SYS", False]
3390: 2c 0a 20 20 20 20 5b 22 53 59 53 20 45 52 52 22  ,.    ["SYS ERR"
33a0: 2c 20 22 53 59 53 20 45 52 52 22 2c 20 46 61 6c  , "SYS ERR", Fal
33b0: 73 65 5d 2c 0a 20 20 20 20 5b 22 46 69 6c 65 20  se],.    ["File 
33c0: 4e 4f 54 20 46 4f 55 4e 44 22 2c 20 72 22 5c 53  NOT FOUND", r"\S
33d0: 2b 20 4e 4f 54 20 46 4f 55 4e 44 22 2c 20 46 61  + NOT FOUND", Fa
33e0: 6c 73 65 5d 0a 20 20 5d 0a 0a 20 20 5f 6f 63 6f  lse].  ]..  _oco
33f0: 6d 70 5f 72 65 70 5f 61 64 64 73 20 3d 20 5b 0a  mp_rep_adds = [.
3400: 20 20 20 20 5b 22 4e 4f 54 48 49 4e 47 20 4f 55      ["NOTHING OU
3410: 54 50 55 54 22 2c 20 22 4e 4f 54 48 49 4e 47 20  TPUT", "NOTHING 
3420: 4f 55 54 50 55 54 22 2c 20 46 61 6c 73 65 5d 2c  OUTPUT", False],
3430: 0a 20 20 20 20 5b 22 52 45 4c 41 54 49 56 45 20  .    ["RELATIVE 
3440: 42 4c 4f 43 4b 22 2c 20 22 52 45 4c 41 54 49 56  BLOCK", "RELATIV
3450: 45 20 42 4c 4f 43 4b 22 2c 20 46 61 6c 73 65 5d  E BLOCK", False]
3460: 2c 0a 20 20 20 20 5b 22 55 53 45 52 20 45 52 52  ,.    ["USER ERR
3470: 4f 52 22 2c 20 22 55 53 45 52 20 45 52 52 4f 52  OR", "USER ERROR
3480: 22 2c 20 46 61 6c 73 65 5d 2c 0a 20 20 5d 0a 0a  ", False],.  ]..
3490: 20 20 23 23 23 23 20 69 6e 74 65 72 6e 5f 72 65    #### intern_re
34a0: 70 6c 69 65 73 20 23 23 23 23 23 23 23 23 23 23  plies ##########
34b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
34c0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
34d0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
34e0: 23 23 23 23 0a 20 20 23 20 54 65 61 63 68 20 74  ####.  # Teach t
34f0: 68 65 20 6f 73 38 73 63 72 69 70 74 20 6f 62 6a  he os8script obj
3500: 65 63 74 20 61 62 6f 75 74 20 61 6e 6f 74 68 65  ect about anothe
3510: 72 20 73 65 74 20 6f 66 20 72 65 70 6c 69 65 73  r set of replies
3520: 2e 0a 20 20 23 20 52 65 74 75 72 6e 20 54 72 75  ..  # Return Tru
3530: 65 20 69 66 20 73 75 63 63 65 73 73 66 75 6c 2c  e if successful,
3540: 20 46 61 6c 73 65 20 69 66 20 74 68 65 20 72 65   False if the re
3550: 70 6c 69 65 73 20 6f 66 20 74 68 61 74 20 6e 61  plies of that na
3560: 6d 65 20 61 72 65 20 61 6c 72 65 61 64 79 20 69  me are already i
3570: 6e 20 70 6c 61 63 65 0a 20 20 23 20 49 66 20 77  n place.  # If w
3580: 69 74 68 5f 6f 73 38 20 69 73 20 54 72 75 65 2c  ith_os8 is True,
3590: 20 61 70 70 65 6e 64 20 74 68 65 20 73 69 6d 68   append the simh
35a0: 20 5f 6f 73 38 5f 72 65 70 6c 69 65 73 20 61 72   _os8_replies ar
35b0: 72 61 79 2e 0a 20 20 0a 20 20 64 65 66 20 69 6e  ray..  .  def in
35c0: 74 65 72 6e 5f 72 65 70 6c 69 65 73 20 28 73 65  tern_replies (se
35d0: 6c 66 2c 20 6e 61 6d 65 2c 20 72 65 70 6c 69 65  lf, name, replie
35e0: 73 2c 20 77 69 74 68 5f 6f 73 38 29 3a 0a 20 20  s, with_os8):.  
35f0: 20 20 69 66 20 6e 61 6d 65 20 69 6e 20 73 65 6c    if name in sel
3600: 66 2e 72 65 70 6c 69 65 73 3a 20 72 65 74 75 72  f.replies: retur
3610: 6e 20 46 61 6c 73 65 0a 20 20 20 20 73 65 6c 66  n False.    self
3620: 2e 72 65 70 6c 69 65 73 5b 6e 61 6d 65 5d 20 3d  .replies[name] =
3630: 20 72 65 70 6c 69 65 73 0a 20 20 20 20 69 66 20   replies.    if 
3640: 77 69 74 68 5f 6f 73 38 3a 20 73 65 6c 66 2e 72  with_os8: self.r
3650: 65 70 6c 69 65 73 5b 6e 61 6d 65 5d 2e 65 78 74  eplies[name].ext
3660: 65 6e 64 28 73 65 6c 66 2e 73 69 6d 68 2e 5f 6f  end(self.simh._o
3670: 73 38 5f 72 65 70 6c 69 65 73 29 0a 20 20 20 20  s8_replies).    
3680: 23 20 43 72 65 61 74 65 20 74 68 65 20 70 72 65  # Create the pre
3690: 2d 63 6f 6d 70 69 6c 65 64 20 72 65 67 65 78 20  -compiled regex 
36a0: 61 72 72 61 79 20 74 6f 6f 2e 0a 20 20 20 20 73  array too..    s
36b0: 65 6c 66 2e 72 65 70 6c 69 65 73 5f 72 65 78 5b  elf.replies_rex[
36c0: 6e 61 6d 65 5d 20 3d 20 5b 5d 0a 20 20 20 20 66  name] = [].    f
36d0: 6f 72 20 69 74 65 6d 20 69 6e 20 73 65 6c 66 2e  or item in self.
36e0: 72 65 70 6c 69 65 73 5b 6e 61 6d 65 5d 3a 0a 20  replies[name]:. 
36f0: 20 20 20 20 20 73 65 6c 66 2e 72 65 70 6c 69 65       self.replie
3700: 73 5f 72 65 78 5b 6e 61 6d 65 5d 2e 61 70 70 65  s_rex[name].appe
3710: 6e 64 28 72 65 2e 63 6f 6d 70 69 6c 65 28 69 74  nd(re.compile(it
3720: 65 6d 5b 31 5d 2e 65 6e 63 6f 64 65 28 29 29 29  em[1].encode()))
3730: 0a 20 20 20 20 72 65 74 75 72 6e 20 54 72 75 65  .    return True
3740: 0a 0a 20 20 64 65 66 20 5f 5f 69 6e 69 74 5f 5f  ..  def __init__
3750: 20 28 73 65 6c 66 2c 20 73 69 6d 68 2c 20 65 6e   (self, simh, en
3760: 61 62 6c 65 64 5f 6f 70 74 69 6f 6e 73 2c 20 64  abled_options, d
3770: 69 73 61 62 6c 65 64 5f 6f 70 74 69 6f 6e 73 2c  isabled_options,
3780: 20 76 65 72 62 6f 73 65 3d 46 61 6c 73 65 2c 20   verbose=False, 
3790: 64 65 62 75 67 3d 54 72 75 65 29 3a 0a 20 20 20  debug=True):.   
37a0: 20 73 65 6c 66 2e 6c 61 6e 67 5f 76 65 72 73 69   self.lang_versi
37b0: 6f 6e 20 3d 20 4c 41 4e 47 5f 56 45 52 53 49 4f  on = LANG_VERSIO
37c0: 4e 0a 20 20 20 20 73 65 6c 66 2e 76 65 72 62 6f  N.    self.verbo
37d0: 73 65 20 3d 20 76 65 72 62 6f 73 65 0a 20 20 20  se = verbose.   
37e0: 20 73 65 6c 66 2e 64 65 62 75 67 20 3d 20 64 65   self.debug = de
37f0: 62 75 67 0a 20 20 20 20 73 65 6c 66 2e 73 69 6d  bug.    self.sim
3800: 68 20 3d 20 73 69 6d 68 0a 20 20 20 20 73 65 6c  h = simh.    sel
3810: 66 2e 6f 70 74 69 6f 6e 73 5f 65 6e 61 62 6c 65  f.options_enable
3820: 64 20 3d 20 65 6e 61 62 6c 65 64 5f 6f 70 74 69  d = enabled_opti
3830: 6f 6e 73 0a 20 20 20 20 73 65 6c 66 2e 6f 70 74  ons.    self.opt
3840: 69 6f 6e 73 5f 64 69 73 61 62 6c 65 64 20 3d 20  ions_disabled = 
3850: 64 69 73 61 62 6c 65 64 5f 6f 70 74 69 6f 6e 73  disabled_options
3860: 0a 20 20 20 20 0a 20 20 20 20 23 20 44 6f 20 77  .    .    # Do w
3870: 65 20 6e 65 65 64 20 73 65 70 61 72 61 74 65 20  e need separate 
3880: 73 74 61 63 6b 73 20 66 6f 72 20 65 6e 61 62 6c  stacks for enabl
3890: 65 64 2f 64 69 73 61 62 6c 65 64 20 6f 70 74 69  ed/disabled opti
38a0: 6f 6e 73 3f 0a 20 20 20 20 73 65 6c 66 2e 6f 70  ons?.    self.op
38b0: 74 69 6f 6e 73 5f 73 74 61 63 6b 20 3d 20 5b 5d  tions_stack = []
38c0: 0a 20 20 20 20 23 20 4c 69 73 74 20 6f 66 20 73  .    # List of s
38d0: 63 72 61 74 63 68 20 66 69 6c 65 73 20 74 6f 20  cratch files to 
38e0: 64 65 6c 65 74 65 20 77 68 65 6e 20 77 65 20 61  delete when we a
38f0: 72 65 20 64 6f 6e 65 20 77 69 74 68 20 61 6c 6c  re done with all
3900: 20 73 63 72 69 70 74 20 72 75 6e 73 2e 0a 20 20   script runs..  
3910: 20 20 73 65 6c 66 2e 73 63 72 61 74 63 68 5f 6c    self.scratch_l
3920: 69 73 74 20 3d 20 5b 5d 0a 20 20 20 20 73 65 6c  ist = [].    sel
3930: 66 2e 62 6f 6f 74 65 64 20 3d 20 46 61 6c 73 65  f.booted = False
3940: 0a 20 20 20 20 23 20 49 6e 69 74 69 61 6c 20 6c  .    # Initial l
3950: 69 6e 65 20 63 6f 75 6e 74 20 73 74 61 63 6b 20  ine count stack 
3960: 68 61 73 20 61 20 73 69 6e 67 6c 65 20 65 6c 65  has a single ele
3970: 6d 65 6e 74 2c 20 76 61 6c 75 65 20 30 0a 20 20  ment, value 0.  
3980: 20 20 23 20 49 6e 20 74 68 69 73 20 77 61 79 20    # In this way 
3990: 77 65 20 67 65 74 20 67 72 61 63 65 66 75 6c 20  we get graceful 
39a0: 6f 70 65 72 61 74 69 6f 6e 20 77 68 65 6e 20 74  operation when t
39b0: 68 65 20 41 50 49 0a 20 20 20 20 23 20 69 73 20  he API.    # is 
39c0: 63 61 6c 6c 65 64 20 64 69 72 65 63 74 6c 79 20  called directly 
39d0: 77 69 74 68 6f 75 74 20 68 61 76 69 6e 67 20 6f  without having o
39e0: 70 65 6e 65 64 20 61 20 73 63 72 69 70 74 20 66  pened a script f
39f0: 69 6c 65 2e 0a 20 20 20 20 73 65 6c 66 2e 6c 69  ile..    self.li
3a00: 6e 65 5f 63 74 5f 73 74 61 63 6b 20 3d 20 5b 30  ne_ct_stack = [0
3a10: 5d 0a 0a 20 20 20 20 23 20 43 72 65 61 74 65 20  ]..    # Create 
3a20: 74 68 65 20 74 61 62 6c 65 20 6f 66 20 72 65 70  the table of rep
3a30: 6c 79 20 74 61 62 6c 65 73 2e 0a 20 20 20 20 23  ly tables..    #
3a40: 20 45 6e 61 62 6c 65 20 61 63 63 65 73 73 20 74   Enable access t
3a50: 6f 20 74 68 65 20 73 69 6d 68 20 61 6e 64 20 6f  o the simh and o
3a60: 73 38 20 74 61 62 6c 65 73 20 74 68 72 6f 75 67  s8 tables throug
3a70: 68 20 74 68 69 73 20 69 6e 74 65 72 66 61 63 65  h this interface
3a80: 2e 0a 20 20 20 20 73 65 6c 66 2e 72 65 70 6c 69  ..    self.repli
3a90: 65 73 20 3d 20 7b 22 73 69 6d 68 22 3a 20 73 65  es = {"simh": se
3aa0: 6c 66 2e 73 69 6d 68 2e 5f 73 69 6d 68 5f 72 65  lf.simh._simh_re
3ab0: 70 6c 69 65 73 2c 20 22 6f 73 38 22 3a 20 73 65  plies, "os8": se
3ac0: 6c 66 2e 73 69 6d 68 2e 5f 6f 73 38 5f 72 65 70  lf.simh._os8_rep
3ad0: 6c 69 65 73 7d 0a 20 20 20 20 73 65 6c 66 2e 72  lies}.    self.r
3ae0: 65 70 6c 69 65 73 5f 72 65 78 20 3d 20 7b 22 73  eplies_rex = {"s
3af0: 69 6d 68 22 3a 20 73 65 6c 66 2e 73 69 6d 68 2e  imh": self.simh.
3b00: 5f 73 69 6d 68 5f 72 65 70 6c 69 65 73 5f 72 65  _simh_replies_re
3b10: 78 2c 20 22 6f 73 38 22 3a 20 73 65 6c 66 2e 73  x, "os8": self.s
3b20: 69 6d 68 2e 5f 6f 73 38 5f 72 65 70 6c 69 65 73  imh._os8_replies
3b30: 5f 72 65 78 7d 0a 20 20 20 20 0a 20 20 20 20 23  _rex}.    .    #
3b40: 20 50 65 72 66 6f 72 6d 20 69 6e 74 65 72 6e 5f   Perform intern_
3b50: 72 65 70 6c 69 65 73 20 6f 6e 20 61 6c 6c 20 6b  replies on all k
3b60: 6e 6f 77 6e 20 73 75 62 2d 63 6f 6d 6d 61 6e 64  nown sub-command
3b70: 73 2e 0a 20 20 20 20 73 65 6c 66 2e 69 6e 74 65  s..    self.inte
3b80: 72 6e 5f 72 65 70 6c 69 65 73 28 22 62 75 69 6c  rn_replies("buil
3b90: 64 22 2c 20 73 65 6c 66 2e 5f 62 75 69 6c 64 5f  d", self._build_
3ba0: 72 65 70 5f 61 64 64 73 2c 20 54 72 75 65 29 0a  rep_adds, True).
3bb0: 20 20 20 20 73 65 6c 66 2e 69 6e 74 65 72 6e 5f      self.intern_
3bc0: 72 65 70 6c 69 65 73 28 22 70 61 6c 38 22 2c 20  replies("pal8", 
3bd0: 73 65 6c 66 2e 5f 70 61 6c 38 5f 72 65 70 5f 61  self._pal8_rep_a
3be0: 64 64 73 2c 20 54 72 75 65 29 0a 20 20 20 20 73  dds, True).    s
3bf0: 65 6c 66 2e 69 6e 74 65 72 6e 5f 72 65 70 6c 69  elf.intern_repli
3c00: 65 73 28 22 6f 63 6f 6d 70 22 2c 20 73 65 6c 66  es("ocomp", self
3c10: 2e 5f 6f 63 6f 6d 70 5f 72 65 70 5f 61 64 64 73  ._ocomp_rep_adds
3c20: 2c 20 54 72 75 65 29 0a 0a 0a 20 20 23 23 23 23  , True)...  ####
3c30: 20 70 61 74 68 5f 65 78 70 61 6e 64 20 23 23 23   path_expand ###
3c40: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
3c50: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
3c60: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
3c70: 23 23 23 23 0a 20 20 23 20 53 69 6d 70 6c 65 20  ####.  # Simple 
3c80: 6d 69 6e 64 65 64 20 76 61 72 69 61 62 6c 65 20  minded variable 
3c90: 73 75 62 73 74 69 74 75 74 69 6f 6e 20 69 6e 20  substitution in 
3ca0: 61 20 70 61 74 68 2e 0a 20 20 23 20 41 20 70 61  a path..  # A pa
3cb0: 74 68 20 62 65 67 69 6e 6e 69 6e 67 20 77 69 74  th beginning wit
3cc0: 68 20 61 20 64 6f 6c 6c 61 72 20 73 69 67 6e 20  h a dollar sign 
3cd0: 70 61 72 73 65 73 20 74 68 65 20 63 68 61 72 61  parses the chara
3ce0: 63 74 65 72 73 20 62 65 74 77 65 65 6e 0a 20 20  cters between.  
3cf0: 23 20 74 68 65 20 64 6f 6c 6c 61 72 20 73 69 67  # the dollar sig
3d00: 6e 20 61 6e 64 20 74 68 65 20 66 69 72 73 74 20  n and the first 
3d10: 73 6c 61 73 68 20 73 65 65 6e 20 62 65 63 6f 6d  slash seen becom
3d20: 65 73 20 61 20 6e 61 6d 65 20 74 6f 0a 20 20 23  es a name to.  #
3d30: 20 65 78 70 61 6e 64 20 77 69 74 68 20 61 20 63   expand with a c
3d40: 6f 75 70 6c 65 20 6c 6f 63 61 6c 20 6e 61 6d 65  ouple local name
3d50: 73 3a 20 24 68 6f 6d 65 20 61 6e 64 20 74 68 65  s: $home and the
3d60: 20 61 6e 63 68 6f 72 20 64 69 72 65 63 74 6f 72   anchor director
3d70: 69 65 73 0a 20 20 23 20 64 65 66 69 6e 65 64 20  ies.  # defined 
3d80: 69 6e 20 6c 69 62 2f 70 69 64 70 38 69 2f 64 69  in lib/pidp8i/di
3d90: 72 73 2e 70 79 2e 0a 20 20 23 20 52 65 74 75 72  rs.py..  # Retur
3da0: 6e 73 20 4e 6f 6e 65 20 69 66 20 74 68 65 20 65  ns None if the e
3db0: 78 70 61 6e 73 69 6f 6e 20 66 61 69 6c 73 2e 20  xpansion fails. 
3dc0: 20 54 68 61 74 20 73 69 67 6e 61 6c 73 20 74 68   That signals th
3dd0: 65 20 63 61 6c 6c 65 72 20 74 6f 20 66 61 69 6c  e caller to fail
3de0: 2e 0a 0a 20 20 64 65 66 20 70 61 74 68 5f 65 78  ...  def path_ex
3df0: 70 61 6e 64 20 28 73 65 6c 66 2c 20 70 61 74 68  pand (self, path
3e00: 29 3a 0a 20 20 20 20 6d 20 3d 20 72 65 2e 6d 61  ):.    m = re.ma
3e10: 74 63 68 28 5f 65 78 70 61 6e 64 61 62 6c 65 5f  tch(_expandable_
3e20: 72 65 2c 20 70 61 74 68 29 0a 20 20 20 20 69 66  re, path).    if
3e30: 20 6d 20 3d 3d 20 4e 6f 6e 65 3a 20 72 65 74 75   m == None: retu
3e40: 72 6e 20 70 61 74 68 0a 20 20 20 20 76 61 72 20  rn path.    var 
3e50: 3d 20 6d 2e 67 72 6f 75 70 28 31 29 0a 0a 20 20  = m.group(1)..  
3e60: 20 20 76 61 6c 20 3d 20 67 65 74 61 74 74 72 20    val = getattr 
3e70: 28 64 69 72 73 2c 20 76 61 72 2c 20 4e 6f 6e 65  (dirs, var, None
3e80: 29 0a 20 20 20 20 69 66 20 76 61 6c 20 21 3d 20  ).    if val != 
3e90: 4e 6f 6e 65 3a 0a 20 20 20 20 20 20 72 65 74 75  None:.      retu
3ea0: 72 6e 20 6f 73 2e 70 61 74 68 2e 6a 6f 69 6e 28  rn os.path.join(
3eb0: 76 61 6c 2c 6d 2e 67 72 6f 75 70 28 32 29 29 0a  val,m.group(2)).
3ec0: 20 20 20 20 65 6c 73 65 3a 0a 20 20 20 20 20 20      else:.      
3ed0: 70 72 69 6e 74 28 22 41 74 20 6c 69 6e 65 20 22  print("At line "
3ee0: 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65   + str(self.line
3ef0: 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20  _ct_stack[0]) + 
3f00: 5c 0a 20 20 20 20 20 20 20 20 22 3a 20 7b 24 22  \.        ": {$"
3f10: 20 2b 20 76 61 72 20 2b 20 22 7d 20 69 73 20 6e   + var + "} is n
3f20: 6f 74 20 61 20 76 61 6c 69 64 20 70 61 74 68 20  ot a valid path 
3f30: 65 78 70 61 6e 73 69 6f 6e 20 69 6e 20 22 20 2b  expansion in " +
3f40: 20 70 61 74 68 29 0a 20 20 20 20 20 20 72 65 74   path).      ret
3f50: 75 72 6e 20 4e 6f 6e 65 0a 20 20 20 20 0a 0a 20  urn None.    .. 
3f60: 20 23 23 23 23 20 70 72 69 6e 74 5f 65 78 70 61   #### print_expa
3f70: 6e 64 20 23 23 23 23 23 23 23 23 23 23 23 23 23  nd #############
3f80: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
3f90: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
3fa0: 23 23 23 23 23 23 23 23 23 0a 20 20 23 20 43 6c  #########.  # Cl
3fb0: 6f 73 65 20 6b 69 6e 20 74 6f 20 70 61 74 68 5f  ose kin to path_
3fc0: 65 78 70 61 6e 64 2e 20 20 54 61 6b 65 73 20 61  expand.  Takes a
3fd0: 20 73 74 72 69 6e 67 20 74 68 61 74 20 6d 61 79   string that may
3fe0: 20 6e 61 6d 65 20 61 20 70 61 74 68 0a 20 20 23   name a path.  #
3ff0: 20 73 75 62 73 74 69 74 75 74 69 6f 6e 20 6f 72   substitution or
4000: 20 74 68 65 20 6d 61 67 69 63 20 24 76 65 72 73   the magic $vers
4010: 69 6f 6e 20 76 61 6c 75 65 20 61 6e 64 20 70 65  ion value and pe
4020: 72 66 6f 72 6d 73 20 74 68 65 20 61 70 70 72 6f  rforms the appro
4030: 70 72 69 61 74 65 0a 20 20 23 20 76 61 6c 75 65  priate.  # value
4040: 20 73 75 62 73 74 69 74 75 74 69 6f 6e 2e 0a 0a   substitution...
4050: 20 20 64 65 66 20 70 72 69 6e 74 5f 65 78 70 61    def print_expa
4060: 6e 64 20 28 73 65 6c 66 2c 73 74 72 29 3a 0a 20  nd (self,str):. 
4070: 20 20 20 65 6e 64 20 3d 20 73 74 72 2e 66 69 6e     end = str.fin
4080: 64 28 22 24 22 29 0a 20 20 20 20 69 66 20 65 6e  d("$").    if en
4090: 64 20 3d 3d 20 2d 31 3a 20 72 65 74 75 72 6e 20  d == -1: return 
40a0: 73 74 72 0a 0a 20 20 20 20 6d 20 3d 20 72 65 2e  str..    m = re.
40b0: 66 69 6e 64 61 6c 6c 28 72 22 5c 24 5c 53 2b 22  findall(r"\$\S+"
40c0: 2c 73 74 72 29 0a 20 20 20 20 69 66 20 6d 20 3d  ,str).    if m =
40d0: 3d 20 4e 6f 6e 65 3a 20 72 65 74 75 72 6e 20 73  = None: return s
40e0: 74 72 0a 0a 20 20 20 20 6f 75 74 73 74 72 20 3d  tr..    outstr =
40f0: 20 22 22 0a 20 20 20 20 73 74 61 72 74 20 3d 20   "".    start = 
4100: 30 0a 0a 20 20 20 20 66 6f 72 20 6e 61 6d 65 20  0..    for name 
4110: 69 6e 20 6d 3a 0a 20 20 20 20 20 20 65 6e 64 20  in m:.      end 
4120: 3d 20 73 74 72 2e 69 6e 64 65 78 28 6e 61 6d 65  = str.index(name
4130: 2c 20 73 74 61 72 74 29 0a 20 20 20 20 20 20 6f  , start).      o
4140: 75 74 73 74 72 20 2b 3d 20 73 74 72 5b 73 74 61  utstr += str[sta
4150: 72 74 3a 65 6e 64 5d 0a 0a 20 20 20 20 20 20 73  rt:end]..      s
4160: 75 62 20 3d 20 67 65 74 61 74 74 72 20 28 64 69  ub = getattr (di
4170: 72 73 2c 20 6e 61 6d 65 5b 31 3a 5d 2c 20 4e 6f  rs, name[1:], No
4180: 6e 65 29 0a 20 20 20 20 20 20 69 66 20 73 75 62  ne).      if sub
4190: 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20   == None:.      
41a0: 20 20 69 66 20 6e 61 6d 65 20 3d 3d 20 22 24 76    if name == "$v
41b0: 65 72 73 69 6f 6e 22 3a 20 73 75 62 20 3d 20 73  ersion": sub = s
41c0: 65 6c 66 2e 6c 61 6e 67 5f 76 65 72 73 69 6f 6e  elf.lang_version
41d0: 0a 20 20 20 20 20 20 20 20 65 6c 73 65 3a 20 73  .        else: s
41e0: 75 62 20 3d 20 6e 61 6d 65 0a 0a 20 20 20 20 20  ub = name..     
41f0: 20 6f 75 74 73 74 72 20 2b 3d 20 73 75 62 0a 20   outstr += sub. 
4200: 20 20 20 20 20 73 74 61 72 74 20 3d 20 65 6e 64       start = end
4210: 20 2b 20 6c 65 6e 28 6e 61 6d 65 29 0a 0a 20 20   + len(name)..  
4220: 20 20 72 65 74 75 72 6e 20 6f 75 74 73 74 72 0a    return outstr.
4230: 20 20 20 20 20 20 0a 0a 20 20 23 23 23 23 20 76        ..  #### v
4240: 65 72 73 69 6f 6e 5f 74 65 73 74 20 23 23 23 23  ersion_test ####
4250: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
4260: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
4270: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
4280: 23 23 0a 20 20 23 20 43 6f 6d 70 61 72 65 20 65  ##.  # Compare e
4290: 61 63 68 20 63 6f 6d 70 6f 6e 65 6e 74 20 6f 66  ach component of
42a0: 20 74 68 65 20 76 65 72 73 69 6f 6e 20 74 65 73   the version tes
42b0: 74 20 61 67 61 69 6e 73 20 74 68 65 20 61 63 74  t agains the act
42c0: 75 61 6c 20 76 65 72 73 69 6f 6e 0a 20 20 23 20  ual version.  # 
42d0: 52 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 61  Return true if a
42e0: 63 74 75 61 6c 20 76 65 72 73 69 6f 6e 20 69 73  ctual version is
42f0: 20 67 72 65 61 74 65 72 20 74 68 61 6e 20 6f 72   greater than or
4300: 20 65 71 75 61 6c 20 74 6f 20 74 68 65 20 74 65   equal to the te
4310: 73 74 0a 20 20 23 20 76 65 72 73 69 6f 6e 2e 0a  st.  # version..
4320: 20 20 23 20 43 61 6c 6c 65 72 20 76 61 6c 69 64    # Caller valid
4330: 61 74 65 73 20 74 65 73 74 20 77 69 74 68 20 5f  ates test with _
4340: 76 65 72 73 69 6f 6e 5f 70 61 72 73 65 5f 72 65  version_parse_re
4350: 20 73 6f 20 77 65 20 6f 6e 6c 79 0a 20 20 23 20   so we only.  # 
4360: 6e 65 65 64 20 74 6f 20 72 65 74 75 72 6e 20 54  need to return T
4370: 72 75 65 20 6f 72 20 46 61 6c 73 65 2c 20 6e 6f  rue or False, no
4380: 74 20 65 72 72 6f 72 2e 0a 20 20 0a 20 20 64 65  t error..  .  de
4390: 66 20 76 65 72 73 69 6f 6e 5f 74 65 73 74 20 28  f version_test (
43a0: 73 65 6c 66 2c 20 74 65 73 74 29 3a 0a 20 20 20  self, test):.   
43b0: 20 74 65 73 74 5f 61 72 72 61 79 20 3d 20 76 65   test_array = ve
43c0: 72 73 69 6f 6e 5f 74 6f 5f 61 72 72 61 79 28 74  rsion_to_array(t
43d0: 65 73 74 29 0a 20 20 20 20 76 65 72 73 69 6f 6e  est).    version
43e0: 5f 61 72 72 61 79 20 3d 20 76 65 72 73 69 6f 6e  _array = version
43f0: 5f 74 6f 5f 61 72 72 61 79 28 73 65 6c 66 2e 6c  _to_array(self.l
4400: 61 6e 67 5f 76 65 72 73 69 6f 6e 29 0a 20 20 20  ang_version).   
4410: 20 0a 20 20 20 20 69 64 78 20 3d 20 30 0a 20 20   .    idx = 0.  
4420: 20 20 65 6e 64 70 6f 69 6e 74 20 3d 20 6c 65 6e    endpoint = len
4430: 28 74 65 73 74 5f 61 72 72 61 79 29 0a 0a 20 20  (test_array)..  
4440: 20 20 77 68 69 6c 65 20 69 64 78 20 3c 20 65 6e    while idx < en
4450: 64 70 6f 69 6e 74 3a 0a 20 20 20 20 20 20 23 20  dpoint:.      # 
4460: 49 66 20 76 65 72 73 69 6f 6e 20 68 61 73 20 6d  If version has m
4470: 6f 72 65 20 64 69 67 69 74 73 20 74 68 61 6e 20  ore digits than 
4480: 74 65 73 74 2c 20 74 68 65 20 67 72 65 61 74 65  test, the greate
4490: 72 20 74 68 61 6e 20 74 65 73 74 20 73 75 63 63  r than test succ
44a0: 65 65 64 73 2e 0a 20 20 20 20 20 20 69 66 20 69  eeds..      if i
44b0: 64 78 20 3e 3d 20 6c 65 6e 28 76 65 72 73 69 6f  dx >= len(versio
44c0: 6e 5f 61 72 72 61 79 29 3a 0a 20 20 20 20 20 20  n_array):.      
44d0: 20 20 20 20 20 76 65 72 73 5f 69 74 65 6d 20 3d       vers_item =
44e0: 20 22 30 22 0a 20 20 20 20 20 20 65 6c 73 65 3a   "0".      else:
44f0: 0a 20 20 20 20 20 20 20 20 20 76 65 72 73 5f 69  .         vers_i
4500: 74 65 6d 20 3d 20 76 65 72 73 69 6f 6e 5f 61 72  tem = version_ar
4510: 72 61 79 5b 69 64 78 5d 0a 20 20 20 20 20 20 74  ray[idx].      t
4520: 65 73 74 5f 69 74 65 6d 20 3d 20 74 65 73 74 5f  est_item = test_
4530: 61 72 72 61 79 5b 69 64 78 5d 0a 20 20 20 20 20  array[idx].     
4540: 20 69 66 20 73 65 6c 66 2e 64 65 62 75 67 3a 0a   if self.debug:.
4550: 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22 76          print("v
4560: 65 72 73 69 6f 6e 5f 74 65 73 74 3a 20 76 65 72  ersion_test: ver
4570: 73 5f 69 74 65 6d 3a 20 22 20 2b 20 76 65 72 73  s_item: " + vers
4580: 5f 69 74 65 6d 20 2b 20 5c 0a 20 20 20 20 20 20  _item + \.      
4590: 20 20 20 20 20 22 2c 20 74 65 73 74 5f 69 74 65       ", test_ite
45a0: 6d 3a 20 22 20 2b 20 74 65 73 74 5f 69 74 65 6d  m: " + test_item
45b0: 29 0a 0a 20 20 20 20 20 20 76 65 72 73 5f 6e 75  )..      vers_nu
45c0: 6d 20 3d 20 69 6e 74 28 76 65 72 73 5f 69 74 65  m = int(vers_ite
45d0: 6d 29 0a 20 20 20 20 20 20 74 65 73 74 5f 6e 75  m).      test_nu
45e0: 6d 20 3d 20 69 6e 74 28 74 65 73 74 5f 69 74 65  m = int(test_ite
45f0: 6d 29 0a 0a 20 20 20 20 20 20 23 20 46 69 72 73  m)..      # Firs
4600: 74 20 74 69 6d 65 20 76 65 72 73 69 6f 6e 20 63  t time version c
4610: 6f 6d 70 6f 6e 65 74 20 67 72 65 61 74 65 72 20  omponet greater 
4620: 74 68 61 6e 20 74 65 73 74 20 2d 3e 20 73 75 63  than test -> suc
4630: 63 65 73 73 2e 0a 20 20 20 20 20 20 69 66 20 76  cess..      if v
4640: 65 72 73 5f 6e 75 6d 20 3e 20 74 65 73 74 5f 6e  ers_num > test_n
4650: 75 6d 3a 0a 20 20 20 20 20 20 20 20 69 66 20 73  um:.        if s
4660: 65 6c 66 2e 64 65 62 75 67 3a 0a 20 20 20 20 20  elf.debug:.     
4670: 20 20 20 20 20 70 72 69 6e 74 28 22 76 65 72 73       print("vers
4680: 69 6f 6e 5f 74 65 73 74 3a 20 53 75 63 63 65 73  ion_test: Succes
4690: 73 3a 20 76 65 72 73 69 6f 6e 20 67 72 65 61 74  s: version great
46a0: 65 72 20 74 68 61 6e 20 74 65 73 74 2e 22 29 0a  er than test.").
46b0: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 54          return T
46c0: 72 75 65 0a 20 20 20 20 20 20 23 20 46 69 72 73  rue.      # Firs
46d0: 74 20 74 69 6d 65 20 76 65 72 73 69 6f 6e 20 63  t time version c
46e0: 6f 6d 70 6f 6e 65 6e 74 20 6c 65 73 73 20 74 68  omponent less th
46f0: 61 6e 20 74 65 73 74 20 2d 3e 20 66 61 69 6c 75  an test -> failu
4700: 72 65 2e 0a 20 20 20 20 20 20 65 6c 69 66 20 74  re..      elif t
4710: 65 73 74 5f 6e 75 6d 20 3e 20 76 65 72 73 5f 6e  est_num > vers_n
4720: 75 6d 3a 0a 20 20 20 20 20 20 20 20 69 66 20 73  um:.        if s
4730: 65 6c 66 2e 64 65 62 75 67 3a 20 70 72 69 6e 74  elf.debug: print
4740: 28 22 76 65 72 73 69 6f 6e 5f 74 65 73 74 3a 20  ("version_test: 
4750: 46 61 69 6c 73 20 6f 6e 20 73 75 62 20 63 6f 6d  Fails on sub com
4760: 70 61 72 65 2e 22 29 0a 20 20 20 20 20 20 20 20  pare.").        
4770: 72 65 74 75 72 6e 20 46 61 6c 73 65 0a 20 20 20  return False.   
4780: 20 20 20 23 4f 74 68 65 72 77 69 73 65 20 69 73     #Otherwise is
4790: 20 65 71 75 61 6c 2e 20 4b 65 65 70 20 67 6f 69   equal. Keep goi
47a0: 6e 67 2e 0a 0a 20 20 20 20 20 20 69 64 78 20 2b  ng...      idx +
47b0: 3d 20 31 0a 20 20 20 20 23 20 4d 61 64 65 20 69  = 1.    # Made i
47c0: 74 20 61 6c 6c 20 74 68 65 20 77 61 79 20 74 68  t all the way th
47d0: 72 6f 75 67 68 2e 20 54 65 73 74 20 73 75 63 63  rough. Test succ
47e0: 65 65 64 73 2e 0a 20 20 20 20 69 66 20 73 65 6c  eeds..    if sel
47f0: 66 2e 64 65 62 75 67 3a 0a 20 20 20 20 20 20 70  f.debug:.      p
4800: 72 69 6e 74 28 22 76 65 72 73 69 6f 6e 5f 74 65  rint("version_te
4810: 73 74 3a 20 53 75 63 63 65 73 73 2e 20 4d 61 64  st: Success. Mad
4820: 65 20 69 74 20 74 68 72 75 20 74 65 73 74 20 73  e it thru test s
4830: 74 72 69 6e 67 2e 22 29 0a 20 20 20 20 72 65 74  tring.").    ret
4840: 75 72 6e 20 54 72 75 65 0a 0a 20 20 20 20 20 20  urn True..      
4850: 20 20 20 20 0a 20 20 23 23 23 23 20 62 61 73 69      .  #### basi
4860: 63 5f 6c 69 6e 65 5f 70 61 72 73 65 20 23 23 23  c_line_parse ###
4870: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
4880: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
4890: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20 20  #############.  
48a0: 23 20 52 65 74 75 72 6e 73 20 73 74 72 69 70 70  # Returns stripp
48b0: 65 64 20 6c 69 6e 65 20 61 6e 64 20 61 6e 79 20  ed line and any 
48c0: 6f 74 68 65 72 20 63 6c 65 61 6e 75 70 20 77 65  other cleanup we
48d0: 20 77 61 6e 74 2e 0a 20 20 23 20 52 65 74 75 72   want..  # Retur
48e0: 6e 73 20 4e 6f 6e 65 20 69 66 20 77 65 20 73 68  ns None if we sh
48f0: 6f 75 6c 64 20 6a 75 73 74 20 27 63 6f 6e 74 69  ould just 'conti
4900: 6e 75 65 27 20 6f 6e 20 74 6f 20 74 68 65 20 6e  nue' on to the n
4910: 65 78 74 20 6c 69 6e 65 2e 0a 20 20 23 20 46 69  ext line..  # Fi
4920: 6c 74 65 72 73 20 6f 75 74 20 63 6f 6d 6d 65 6e  lters out commen
4930: 74 73 2e 0a 20 20 23 20 50 72 6f 63 65 73 73 65  ts..  # Processe
4940: 73 20 74 68 65 20 6f 70 74 69 6f 6e 20 62 65 67  s the option beg
4950: 69 6e 2f 65 6e 64 20 62 6c 6f 63 6b 73 2e 0a 20  in/end blocks.. 
4960: 20 0a 20 20 64 65 66 20 62 61 73 69 63 5f 6c 69   .  def basic_li
4970: 6e 65 5f 70 61 72 73 65 20 28 73 65 6c 66 2c 20  ne_parse (self, 
4980: 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f 66 69 6c  line, script_fil
4990: 65 29 3a 0a 20 20 20 20 73 65 6c 66 2e 6c 69 6e  e):.    self.lin
49a0: 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 20 2b 3d  e_ct_stack[0] +=
49b0: 20 31 0a 20 20 20 20 72 65 74 76 61 6c 20 3d 20   1.    retval = 
49c0: 6c 69 6e 65 2e 73 74 72 69 70 28 29 0a 20 20 20  line.strip().   
49d0: 20 69 66 20 72 65 74 76 61 6c 20 3d 3d 20 22 22   if retval == ""
49e0: 3a 20 72 65 74 75 72 6e 20 4e 6f 6e 65 0a 20 20  : return None.  
49f0: 20 20 65 6c 69 66 20 72 65 74 76 61 6c 5b 30 5d    elif retval[0]
4a00: 20 3d 3d 20 22 23 22 3a 20 72 65 74 75 72 6e 20   == "#": return 
4a10: 4e 6f 6e 65 0a 20 20 20 20 23 20 46 69 72 73 74  None.    # First
4a20: 20 74 65 73 74 20 69 66 20 77 65 20 61 72 65 20   test if we are 
4a30: 69 6e 20 61 20 62 65 67 69 6e 20 6f 70 74 69 6f  in a begin optio
4a40: 6e 20 62 6c 6f 63 6b 0a 20 20 20 20 6d 20 3d 20  n block.    m = 
4a50: 72 65 2e 6d 61 74 63 68 20 28 5f 62 65 67 69 6e  re.match (_begin
4a60: 5f 65 6e 5f 64 69 73 5f 63 6f 6d 6d 5f 72 65 2c  _en_dis_comm_re,
4a70: 20 72 65 74 76 61 6c 29 0a 20 20 20 20 69 66 20   retval).    if 
4a80: 6d 20 21 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20  m != None:.     
4a90: 20 65 6e 5f 64 69 73 20 3d 20 6d 2e 67 72 6f 75   en_dis = m.grou
4aa0: 70 28 31 29 0a 20 20 20 20 20 20 72 65 73 74 20  p(1).      rest 
4ab0: 3d 20 6d 2e 67 72 6f 75 70 28 32 29 0a 20 20 20  = m.group(2).   
4ac0: 20 20 20 69 66 20 73 65 6c 66 2e 76 65 72 62 6f     if self.verbo
4ad0: 73 65 3a 20 70 72 69 6e 74 28 22 4c 69 6e 65 20  se: print("Line 
4ae0: 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e  " + str(self.lin
4af0: 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b  e_ct_stack[0]) +
4b00: 20 5c 0a 20 20 20 20 20 20 20 20 20 22 3a 20 64   \.         ": d
4b10: 6f 69 6e 67 5f 62 65 67 69 6e 5f 6f 70 74 69 6f  oing_begin_optio
4b20: 6e 3a 20 22 20 2b 20 65 6e 5f 64 69 73 20 2b 20  n: " + en_dis + 
4b30: 22 20 22 20 2b 20 72 65 73 74 29 0a 20 20 20 20  " " + rest).    
4b40: 20 20 69 66 20 73 65 6c 66 2e 64 65 62 75 67 3a    if self.debug:
4b50: 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22  .        print("
4b60: 6f 70 74 69 6f 6e 73 5f 65 6e 61 62 6c 65 64 3a  options_enabled:
4b70: 20 22 20 2b 20 73 74 72 20 28 73 65 6c 66 2e 6f   " + str (self.o
4b80: 70 74 69 6f 6e 73 5f 65 6e 61 62 6c 65 64 29 29  ptions_enabled))
4b90: 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22  .        print("
4ba0: 6f 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c 65 64  options_disabled
4bb0: 3a 20 22 20 2b 20 73 74 72 20 28 73 65 6c 66 2e  : " + str (self.
4bc0: 6f 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c 65 64  options_disabled
4bd0: 29 29 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74  )).        print
4be0: 28 22 6f 70 74 69 6f 6e 73 5f 73 74 61 63 6b 3a  ("options_stack:
4bf0: 20 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6f 70   " + str(self.op
4c00: 74 69 6f 6e 73 5f 73 74 61 63 6b 29 29 0a 0a 20  tions_stack)).. 
4c10: 20 20 20 20 20 76 65 72 73 5f 6d 61 74 63 68 20       vers_match 
4c20: 3d 20 46 61 6c 73 65 0a 20 20 20 20 20 20 69 66  = False.      if
4c30: 20 65 6e 5f 64 69 73 20 3d 3d 20 22 76 65 72 73   en_dis == "vers
4c40: 69 6f 6e 22 3a 0a 20 20 20 20 20 20 20 20 23 20  ion":.        # 
4c50: 43 68 65 63 6b 20 66 6f 72 20 6d 61 6c 2d 66 6f  Check for mal-fo
4c60: 72 6d 65 64 20 76 65 72 73 69 6f 6e 20 6d 61 74  rmed version mat
4c70: 63 68 20 66 69 72 73 74 0a 20 20 20 20 20 20 20  ch first.       
4c80: 20 69 66 20 72 65 2e 6d 61 74 63 68 20 28 5f 76   if re.match (_v
4c90: 65 72 73 69 6f 6e 5f 70 61 72 73 65 5f 72 65 2c  ersion_parse_re,
4ca0: 20 72 65 73 74 29 20 3d 3d 20 4e 6f 6e 65 3a 0a   rest) == None:.
4cb0: 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74 28            print(
4cc0: 22 4d 61 6c 2d 66 6f 72 6d 65 64 20 76 65 72 73  "Mal-formed vers
4cd0: 69 6f 6e 20 6d 61 74 63 68 20 73 74 72 69 6e 67  ion match string
4ce0: 20 7b 22 20 2b 20 72 65 73 74 20 2b 20 22 7d 20   {" + rest + "} 
4cf0: 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20  at line " + \.  
4d00: 20 20 20 20 20 20 20 20 20 20 73 74 72 28 73 65            str(se
4d10: 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b  lf.line_ct_stack
4d20: 5b 30 5d 29 20 2b 20 22 2e 20 49 67 6e 6f 72 69  [0]) + ". Ignori
4d30: 6e 67 20 74 68 69 73 20 62 6c 6f 63 6b 2e 22 29  ng this block.")
4d40: 0a 20 20 20 20 20 20 20 20 20 20 73 65 6c 66 2e  .          self.
4d50: 69 67 6e 6f 72 65 5f 74 6f 5f 73 75 62 63 6f 6d  ignore_to_subcom
4d60: 6d 5f 65 6e 64 20 28 72 65 74 76 61 6c 2c 20 73  m_end (retval, s
4d70: 63 72 69 70 74 5f 66 69 6c 65 2c 20 65 6e 5f 64  cript_file, en_d
4d80: 69 73 20 2b 20 22 20 22 20 2b 20 72 65 73 74 29  is + " " + rest)
4d90: 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72  .          retur
4da0: 6e 20 4e 6f 6e 65 0a 20 20 20 20 20 20 20 20 76  n None.        v
4db0: 65 72 73 5f 6d 61 74 63 68 20 3d 20 73 65 6c 66  ers_match = self
4dc0: 2e 76 65 72 73 69 6f 6e 5f 74 65 73 74 20 28 72  .version_test (r
4dd0: 65 73 74 29 0a 20 20 20 20 20 20 20 20 69 66 20  est).        if 
4de0: 76 65 72 73 5f 6d 61 74 63 68 3a 0a 20 20 20 20  vers_match:.    
4df0: 20 20 20 20 20 20 23 20 42 6c 6f 63 6b 20 69 73        # Block is
4e00: 20 61 63 74 69 76 65 2e 20 57 65 20 70 75 73 68   active. We push
4e10: 20 69 74 20 6f 6e 74 6f 20 74 68 65 20 73 74 61   it onto the sta
4e20: 63 6b 0a 20 20 20 20 20 20 20 20 20 20 69 66 20  ck.          if 
4e30: 73 65 6c 66 2e 64 65 62 75 67 3a 0a 20 20 20 20  self.debug:.    
4e40: 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22 50          print("P
4e50: 75 73 68 69 6e 67 20 76 65 72 73 69 6f 6e 20 65  ushing version e
4e60: 6e 61 62 6c 65 64 20 62 6c 6f 63 6b 20 22 20 2b  nabled block " +
4e70: 20 72 65 73 74 20 2b 20 5c 0a 20 20 20 20 20 20   rest + \.      
4e80: 20 20 20 20 20 20 20 20 20 20 22 20 6f 6e 74 6f            " onto
4e90: 20 6f 70 74 69 6f 6e 73 5f 73 74 61 63 6b 22 29   options_stack")
4ea0: 0a 20 20 20 20 20 20 20 20 20 20 73 65 6c 66 2e  .          self.
4eb0: 6f 70 74 69 6f 6e 73 5f 73 74 61 63 6b 2e 69 6e  options_stack.in
4ec0: 73 65 72 74 28 30 2c 20 72 65 73 74 29 0a 20 20  sert(0, rest).  
4ed0: 20 20 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e          if self.
4ee0: 64 65 62 75 67 3a 20 70 72 69 6e 74 28 22 20 6e  debug: print(" n
4ef0: 65 77 20 6f 70 74 69 6f 6e 73 5f 73 74 61 63 6b  ew options_stack
4f00: 3a 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  : " + \.        
4f10: 20 20 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6f        str(self.o
4f20: 70 74 69 6f 6e 73 5f 73 74 61 63 6b 29 29 0a 20  ptions_stack)). 
4f30: 20 20 20 20 20 20 20 65 6c 73 65 3a 0a 20 20 20         else:.   
4f40: 20 20 20 20 20 20 20 23 20 4f 70 74 69 6f 6e 20         # Option 
4f50: 69 73 20 69 6e 61 63 74 69 76 65 2e 20 20 49 67  is inactive.  Ig
4f60: 6e 6f 72 65 20 61 6c 6c 20 73 75 62 73 65 71 65  nore all subseqe
4f70: 6e 74 20 6c 69 6e 65 73 0a 20 20 20 20 20 20 20  nt lines.       
4f80: 20 20 20 23 20 75 6e 74 69 6c 20 77 65 20 67 65     # until we ge
4f90: 74 20 74 6f 20 61 6e 20 65 6e 64 20 63 6f 6d 6d  t to an end comm
4fa0: 61 6e 64 20 74 68 61 74 20 6d 61 74 63 68 65 73  and that matches
4fb0: 20 6f 75 72 20 6f 70 74 69 6f 6e 2e 0a 20 20 20   our option..   
4fc0: 20 20 20 20 20 20 20 73 65 6c 66 2e 69 67 6e 6f         self.igno
4fd0: 72 65 5f 74 6f 5f 73 75 62 63 6f 6d 6d 5f 65 6e  re_to_subcomm_en
4fe0: 64 20 28 72 65 74 76 61 6c 2c 20 73 63 72 69 70  d (retval, scrip
4ff0: 74 5f 66 69 6c 65 2c 20 65 6e 5f 64 69 73 20 2b  t_file, en_dis +
5000: 20 22 20 22 20 2b 20 72 65 73 74 29 0a 20 20 20   " " + rest).   
5010: 20 20 20 20 20 72 65 74 75 72 6e 20 4e 6f 6e 65       return None
5020: 0a 20 20 20 20 20 20 20 20 0a 20 20 20 20 20 20  .        .      
5030: 65 6c 69 66 20 65 6e 5f 64 69 73 20 3d 3d 20 22  elif en_dis == "
5040: 65 6e 61 62 6c 65 64 22 3a 0a 20 20 20 20 20 20  enabled":.      
5050: 20 20 69 66 20 72 65 73 74 20 69 6e 20 73 65 6c    if rest in sel
5060: 66 2e 6f 70 74 69 6f 6e 73 5f 65 6e 61 62 6c 65  f.options_enable
5070: 64 3a 0a 20 20 20 20 20 20 20 20 20 20 23 20 42  d:.          # B
5080: 6c 6f 63 6b 20 69 73 20 61 63 74 69 76 65 2e 20  lock is active. 
5090: 57 65 20 70 75 73 68 20 69 74 20 6f 6e 74 6f 20  We push it onto 
50a0: 74 68 65 20 73 74 61 63 6b 0a 20 20 20 20 20 20  the stack.      
50b0: 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65 62 75      if self.debu
50c0: 67 3a 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  g:.             
50d0: 20 70 72 69 6e 74 28 22 50 75 73 68 69 6e 67 20   print("Pushing 
50e0: 65 6e 61 62 6c 65 64 20 62 6c 6f 63 6b 20 22 20  enabled block " 
50f0: 2b 20 72 65 73 74 20 2b 20 22 20 6f 6e 74 6f 20  + rest + " onto 
5100: 6f 70 74 69 6f 6e 73 5f 73 74 61 63 6b 22 29 0a  options_stack").
5110: 20 20 20 20 20 20 20 20 20 20 73 65 6c 66 2e 6f            self.o
5120: 70 74 69 6f 6e 73 5f 73 74 61 63 6b 2e 69 6e 73  ptions_stack.ins
5130: 65 72 74 28 30 2c 20 72 65 73 74 29 0a 20 20 20  ert(0, rest).   
5140: 20 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 64         if self.d
5150: 65 62 75 67 3a 0a 20 20 20 20 20 20 20 20 20 20  ebug:.          
5160: 20 20 70 72 69 6e 74 28 22 6e 65 77 20 6f 70 74    print("new opt
5170: 69 6f 6e 73 5f 73 74 61 63 6b 3a 20 22 20 2b 20  ions_stack: " + 
5180: 73 74 72 28 73 65 6c 66 2e 6f 70 74 69 6f 6e 73  str(self.options
5190: 5f 73 74 61 63 6b 29 29 0a 20 20 20 20 20 20 20  _stack)).       
51a0: 20 65 6c 73 65 3a 0a 20 20 20 20 20 20 20 20 20   else:.         
51b0: 20 23 20 4f 70 74 69 6f 6e 20 69 73 20 69 6e 61   # Option is ina
51c0: 63 74 69 76 65 2e 20 20 49 67 6e 6f 72 65 20 61  ctive.  Ignore a
51d0: 6c 6c 20 73 75 62 73 65 71 65 6e 74 20 6c 69 6e  ll subseqent lin
51e0: 65 73 0a 20 20 20 20 20 20 20 20 20 20 23 20 75  es.          # u
51f0: 6e 74 69 6c 20 77 65 20 67 65 74 20 74 6f 20 61  ntil we get to a
5200: 6e 20 65 6e 64 20 63 6f 6d 6d 61 6e 64 20 74 68  n end command th
5210: 61 74 20 6d 61 74 63 68 65 73 20 6f 75 72 20 6f  at matches our o
5220: 70 74 69 6f 6e 2e 0a 20 20 20 20 20 20 20 20 20  ption..         
5230: 20 73 65 6c 66 2e 69 67 6e 6f 72 65 5f 74 6f 5f   self.ignore_to_
5240: 73 75 62 63 6f 6d 6d 5f 65 6e 64 20 28 72 65 74  subcomm_end (ret
5250: 76 61 6c 2c 20 73 63 72 69 70 74 5f 66 69 6c 65  val, script_file
5260: 2c 20 65 6e 5f 64 69 73 20 2b 20 22 20 22 20 2b  , en_dis + " " +
5270: 20 72 65 73 74 29 0a 0a 20 20 20 20 20 20 20 20   rest)..        
5280: 72 65 74 75 72 6e 20 4e 6f 6e 65 0a 20 20 20 20  return None.    
5290: 20 20 23 20 6f 6e 6c 79 20 6f 74 68 65 72 20 63    # only other c
52a0: 68 6f 69 63 65 20 69 73 20 64 69 73 61 62 6c 65  hoice is disable
52b0: 64 20 62 65 63 61 75 73 65 20 6f 66 20 6f 75 72  d because of our
52c0: 20 72 65 67 65 78 2e 0a 20 20 20 20 20 20 65 6c   regex..      el
52d0: 73 65 3a 0a 20 20 20 20 20 20 20 20 69 66 20 72  se:.        if r
52e0: 65 73 74 20 6e 6f 74 20 69 6e 20 73 65 6c 66 2e  est not in self.
52f0: 6f 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c 65 64  options_disabled
5300: 3a 0a 20 20 20 20 20 20 20 20 20 20 23 20 42 6c  :.          # Bl
5310: 6f 63 6b 20 64 65 66 61 75 6c 74 73 20 74 6f 20  ock defaults to 
5320: 61 63 74 69 76 65 2e 20 57 65 20 70 75 73 68 20  active. We push 
5330: 69 74 20 6f 6e 74 6f 20 74 68 65 20 73 74 61 63  it onto the stac
5340: 6b 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 73  k.          if s
5350: 65 6c 66 2e 64 65 62 75 67 3a 0a 20 20 20 20 20  elf.debug:.     
5360: 20 20 20 20 20 20 20 70 72 69 6e 74 28 22 50 75         print("Pu
5370: 73 68 69 6e 67 20 6e 6f 74 5f 64 69 73 61 62 6c  shing not_disabl
5380: 65 64 20 62 6c 6f 63 6b 20 22 20 2b 20 72 65 73  ed block " + res
5390: 74 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 20 20  t + \.          
53a0: 20 20 20 20 20 20 22 20 6f 6e 74 6f 20 6f 70 74        " onto opt
53b0: 69 6f 6e 73 5f 73 74 61 63 6b 22 29 0a 20 20 20  ions_stack").   
53c0: 20 20 20 20 20 20 20 73 65 6c 66 2e 6f 70 74 69         self.opti
53d0: 6f 6e 73 5f 73 74 61 63 6b 2e 69 6e 73 65 72 74  ons_stack.insert
53e0: 28 30 2c 20 72 65 73 74 29 0a 20 20 20 20 20 20  (0, rest).      
53f0: 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65 62 75      if self.debu
5400: 67 3a 0a 20 20 20 20 20 20 20 20 20 20 20 20 70  g:.            p
5410: 72 69 6e 74 28 22 6e 65 77 20 6f 70 74 69 6f 6e  rint("new option
5420: 73 5f 73 74 61 63 6b 3a 20 22 20 2b 20 73 74 72  s_stack: " + str
5430: 28 73 65 6c 66 2e 6f 70 74 69 6f 6e 73 5f 73 74  (self.options_st
5440: 61 63 6b 29 29 0a 20 20 20 20 20 20 20 20 65 6c  ack)).        el
5450: 73 65 3a 0a 20 20 20 20 20 20 20 20 20 20 23 20  se:.          # 
5460: 42 6c 6f 63 6b 20 69 73 20 69 6e 61 63 74 69 76  Block is inactiv
5470: 65 2e 20 20 49 67 6e 6f 72 65 20 61 6c 6c 20 73  e.  Ignore all s
5480: 75 62 73 65 71 65 6e 74 20 6c 69 6e 65 73 0a 20  ubseqent lines. 
5490: 20 20 20 20 20 20 20 20 20 23 20 75 6e 74 69 6c           # until
54a0: 20 77 65 20 67 65 74 20 74 6f 20 61 6e 20 65 6e   we get to an en
54b0: 64 20 63 6f 6d 6d 61 6e 64 20 74 68 61 74 20 6d  d command that m
54c0: 61 74 63 68 65 73 20 6f 75 72 20 6f 70 74 69 6f  atches our optio
54d0: 6e 2e 0a 20 20 20 20 20 20 20 20 20 20 73 65 6c  n..          sel
54e0: 66 2e 69 67 6e 6f 72 65 5f 74 6f 5f 73 75 62 63  f.ignore_to_subc
54f0: 6f 6d 6d 5f 65 6e 64 20 28 72 65 74 76 61 6c 2c  omm_end (retval,
5500: 20 73 63 72 69 70 74 5f 66 69 6c 65 2c 20 65 6e   script_file, en
5510: 5f 64 69 73 20 2b 20 22 20 22 20 2b 20 72 65 73  _dis + " " + res
5520: 74 29 0a 20 20 20 20 20 20 20 20 72 65 74 75 72  t).        retur
5530: 6e 20 4e 6f 6e 65 0a 20 20 0a 20 20 20 20 6d 20  n None.  .    m 
5540: 3d 20 72 65 2e 6d 61 74 63 68 28 5f 65 6e 64 5f  = re.match(_end_
5550: 65 6e 5f 64 69 73 5f 63 6f 6d 6d 5f 72 65 2c 20  en_dis_comm_re, 
5560: 72 65 74 76 61 6c 29 0a 20 20 20 20 69 66 20 6d  retval).    if m
5570: 20 21 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20   != None:.      
5580: 72 65 73 74 20 3d 20 6d 2e 67 72 6f 75 70 28 32  rest = m.group(2
5590: 29 0a 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e  ).      if self.
55a0: 76 65 72 62 6f 73 65 3a 0a 20 20 20 20 20 20 20  verbose:.       
55b0: 20 70 72 69 6e 74 28 22 4c 69 6e 65 20 22 20 2b   print("Line " +
55c0: 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63   str(self.line_c
55d0: 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 3a  t_stack[0]) + ":
55e0: 20 65 6e 64 20 72 65 73 74 20 3d 20 22 20 2b 20   end rest = " + 
55f0: 72 65 73 74 29 0a 20 20 20 20 20 20 69 66 20 28  rest).      if (
5600: 72 65 73 74 20 3d 3d 20 4e 6f 6e 65 20 6f 72 20  rest == None or 
5610: 72 65 73 74 20 3d 3d 20 22 22 29 3a 0a 20 20 20  rest == ""):.   
5620: 20 20 20 20 20 70 72 69 6e 74 28 22 57 61 72 6e       print("Warn
5630: 69 6e 67 21 20 6f 70 74 69 6f 6e 20 65 6e 64 20  ing! option end 
5640: 73 74 61 74 65 6d 65 6e 74 20 61 74 20 6c 69 6e  statement at lin
5650: 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  e " + \.        
5660: 20 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f    str(self.line_
5670: 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22  ct_stack[0]) + "
5680: 20 65 6e 63 6f 75 6e 74 65 72 65 64 20 77 69 74   encountered wit
5690: 68 20 6e 6f 20 61 72 67 75 6d 65 6e 74 2e 22 29  h no argument.")
56a0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20  .        return 
56b0: 4e 6f 6e 65 0a 20 20 20 20 20 20 69 66 20 6c 65  None.      if le
56c0: 6e 28 73 65 6c 66 2e 6f 70 74 69 6f 6e 73 5f 73  n(self.options_s
56d0: 74 61 63 6b 29 20 3d 3d 20 30 3a 0a 20 20 20 20  tack) == 0:.    
56e0: 20 20 20 20 70 72 69 6e 74 28 22 57 61 72 6e 69      print("Warni
56f0: 6e 67 21 20 6f 70 74 69 6f 6e 20 65 6e 64 20 73  ng! option end s
5700: 74 61 74 65 6d 65 6e 74 20 61 74 20 6c 69 6e 65  tatement at line
5710: 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 20   " + \.         
5720: 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63   str(self.line_c
5730: 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 5c 0a  t_stack[0]) + \.
5740: 20 20 20 20 20 20 20 20 20 20 22 20 66 6f 75 6e            " foun
5750: 64 20 77 69 74 68 20 6e 6f 20 6d 61 74 63 68 69  d with no matchi
5760: 6e 67 20 62 65 67 69 6e 20 66 6f 72 20 6f 70 74  ng begin for opt
5770: 69 6f 6e 3a 20 22 20 2b 20 72 65 73 74 29 0a 20  ion: " + rest). 
5780: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 4e 6f         return No
5790: 6e 65 0a 20 20 20 20 20 20 69 66 20 72 65 73 74  ne.      if rest
57a0: 20 21 3d 20 73 65 6c 66 2e 6f 70 74 69 6f 6e 73   != self.options
57b0: 5f 73 74 61 63 6b 5b 30 5d 3a 0a 20 20 20 20 20  _stack[0]:.     
57c0: 20 20 20 70 72 69 6e 74 28 22 57 61 72 6e 69 6e     print("Warnin
57d0: 67 21 20 4d 69 73 6d 61 74 63 68 65 64 20 6f 70  g! Mismatched op
57e0: 74 69 6f 6e 20 62 65 67 69 6e 2f 65 6e 64 20 67  tion begin/end g
57f0: 72 6f 75 70 20 61 74 20 6c 69 6e 65 20 22 20 2b  roup at line " +
5800: 20 5c 0a 20 20 20 20 20 20 20 20 20 20 73 74 72   \.          str
5810: 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74  (self.line_ct_st
5820: 61 63 6b 5b 30 5d 29 20 2b 20 22 2e 20 43 75 72  ack[0]) + ". Cur
5830: 72 65 6e 74 6c 79 20 69 6e 73 69 64 65 20 6f 70  rently inside op
5840: 74 69 6f 6e 3a 20 22 20 2b 20 5c 0a 20 20 20 20  tion: " + \.    
5850: 20 20 20 20 20 20 73 65 6c 66 2e 6f 70 74 69 6f        self.optio
5860: 6e 73 5f 73 74 61 63 6b 5b 30 5d 20 2b 20 22 20  ns_stack[0] + " 
5870: 6e 6f 74 20 22 20 2b 20 72 65 73 74 29 0a 20 20  not " + rest).  
5880: 20 20 20 20 20 20 72 65 74 75 72 6e 20 4e 6f 6e        return Non
5890: 65 0a 20 20 20 20 20 20 65 6c 73 65 3a 0a 20 20  e.      else:.  
58a0: 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65        if self.de
58b0: 62 75 67 3a 20 70 72 69 6e 74 28 22 50 6f 70 70  bug: print("Popp
58c0: 69 6e 67 20 22 20 2b 20 73 65 6c 66 2e 6f 70 74  ing " + self.opt
58d0: 69 6f 6e 73 5f 73 74 61 63 6b 5b 30 5d 29 0a 20  ions_stack[0]). 
58e0: 20 20 20 20 20 20 20 73 65 6c 66 2e 6f 70 74 69         self.opti
58f0: 6f 6e 73 5f 73 74 61 63 6b 2e 70 6f 70 28 30 29  ons_stack.pop(0)
5900: 0a 20 20 20 20 20 20 20 20 69 66 20 73 65 6c 66  .        if self
5910: 2e 64 65 62 75 67 3a 0a 20 20 20 20 20 20 20 20  .debug:.        
5920: 20 20 70 72 69 6e 74 28 22 6e 65 77 20 6f 70 74    print("new opt
5930: 69 6f 6e 73 5f 73 74 61 63 6b 3a 20 22 20 2b 20  ions_stack: " + 
5940: 73 74 72 28 73 65 6c 66 2e 6f 70 74 69 6f 6e 73  str(self.options
5950: 5f 73 74 61 63 6b 29 29 0a 20 20 20 20 20 20 20  _stack)).       
5960: 20 72 65 74 75 72 6e 20 4e 6f 6e 65 0a 20 20 0a   return None.  .
5970: 20 20 20 20 72 65 74 75 72 6e 20 72 65 74 76 61      return retva
5980: 6c 0a 20 20 0a 20 20 0a 20 20 23 23 23 23 20 69  l.  .  .  #### i
5990: 67 6e 6f 72 65 5f 74 6f 5f 73 75 62 63 6f 6d 6d  gnore_to_subcomm
59a0: 5f 65 6e 64 20 23 23 23 23 23 23 23 23 23 23 23  _end ###########
59b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
59c0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
59d0: 0a 20 20 0a 20 20 64 65 66 20 69 67 6e 6f 72 65  .  .  def ignore
59e0: 5f 74 6f 5f 73 75 62 63 6f 6d 6d 5f 65 6e 64 20  _to_subcomm_end 
59f0: 28 73 65 6c 66 2c 20 6f 6c 64 5f 6c 69 6e 65 2c  (self, old_line,
5a00: 20 73 63 72 69 70 74 5f 66 69 6c 65 2c 20 65 6e   script_file, en
5a10: 64 5f 73 74 72 29 3a 0a 20 20 20 20 69 66 20 73  d_str):.    if s
5a20: 65 6c 66 2e 64 65 62 75 67 3a 20 70 72 69 6e 74  elf.debug: print
5a30: 28 22 69 67 6e 6f 72 65 20 74 6f 3a 20 22 20 2b  ("ignore to: " +
5a40: 20 65 6e 64 5f 73 74 72 29 0a 20 20 20 20 66 6f   end_str).    fo
5a50: 72 20 6c 69 6e 65 20 69 6e 20 73 63 72 69 70 74  r line in script
5a60: 5f 66 69 6c 65 3a 0a 20 20 20 20 20 20 73 65 6c  _file:.      sel
5a70: 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b  f.line_ct_stack[
5a80: 30 5d 20 2b 3d 20 31 0a 20 20 20 20 20 20 6c 69  0] += 1.      li
5a90: 6e 65 20 3d 20 6c 69 6e 65 2e 73 74 72 69 70 28  ne = line.strip(
5aa0: 29 0a 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e  ).      if self.
5ab0: 76 65 72 62 6f 73 65 3a 0a 20 20 20 20 20 20 20  verbose:.       
5ac0: 20 70 72 69 6e 74 28 22 49 67 6e 6f 72 65 20 6c   print("Ignore l
5ad0: 69 6e 65 20 22 20 2b 20 73 74 72 28 73 65 6c 66  ine " + str(self
5ae0: 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
5af0: 5d 29 20 2b 20 22 3a 20 22 20 2b 20 6c 69 6e 65  ]) + ": " + line
5b00: 29 0a 20 20 20 20 20 20 0a 20 20 20 20 20 20 6d  ).      .      m
5b10: 20 3d 20 72 65 2e 6d 61 74 63 68 28 5f 65 6e 64   = re.match(_end
5b20: 5f 63 6f 6d 6d 5f 72 65 2c 20 6c 69 6e 65 29 0a  _comm_re, line).
5b30: 20 20 20 20 20 20 69 66 20 6d 20 3d 3d 20 4e 6f        if m == No
5b40: 6e 65 3a 20 63 6f 6e 74 69 6e 75 65 0a 20 20 0a  ne: continue.  .
5b50: 20 20 20 20 20 20 72 65 73 74 20 3d 20 6d 2e 67        rest = m.g
5b60: 72 6f 75 70 28 31 29 0a 20 20 20 20 20 20 69 66  roup(1).      if
5b70: 20 72 65 73 74 20 3d 3d 20 4e 6f 6e 65 3a 20 72   rest == None: r
5b80: 65 73 74 20 3d 20 22 22 0a 20 20 20 20 20 20 0a  est = "".      .
5b90: 20 20 20 20 20 20 69 66 20 72 65 73 74 20 3d 3d        if rest ==
5ba0: 20 65 6e 64 5f 73 74 72 3a 20 72 65 74 75 72 6e   end_str: return
5bb0: 0a 20 20 0a 20 20 0a 20 20 23 23 23 23 20 69 6e  .  .  .  #### in
5bc0: 63 6c 75 64 65 5f 63 6f 6d 6d 61 6e 64 20 23 23  clude_command ##
5bd0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
5be0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
5bf0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  ###############.
5c00: 20 20 23 20 43 61 6c 6c 20 72 75 6e 5f 73 63 72    # Call run_scr
5c10: 69 70 74 5f 66 69 6c 65 20 72 65 63 75 72 73 69  ipt_file recursi
5c20: 76 65 6c 79 20 6f 6e 20 74 68 65 20 66 69 6c 65  vely on the file
5c30: 20 70 61 74 68 20 70 72 6f 76 69 64 65 64 2e 0a   path provided..
5c40: 20 20 0a 20 20 64 65 66 20 69 6e 63 6c 75 64 65    .  def include
5c50: 5f 63 6f 6d 6d 61 6e 64 20 28 73 65 6c 66 2c 20  _command (self, 
5c60: 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f 66 69 6c  line, script_fil
5c70: 65 29 3a 0a 20 20 20 20 70 61 74 68 20 3d 20 73  e):.    path = s
5c80: 65 6c 66 2e 70 61 74 68 5f 65 78 70 61 6e 64 28  elf.path_expand(
5c90: 6c 69 6e 65 29 0a 20 20 20 20 69 66 20 70 61 74  line).    if pat
5ca0: 68 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20  h == None:.     
5cb0: 20 70 72 69 6e 74 28 22 49 67 6e 6f 72 69 6e 67   print("Ignoring
5cc0: 3a 20 5c 6e 5c 74 69 6e 63 6c 75 64 65 20 22 20  : \n\tinclude " 
5cd0: 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20 20 72 65  + line).      re
5ce0: 74 75 72 6e 20 22 66 61 69 6c 22 0a 0a 20 20 20  turn "fail"..   
5cf0: 20 69 66 20 6e 6f 74 20 6f 73 2e 70 61 74 68 2e   if not os.path.
5d00: 69 73 66 69 6c 65 28 70 61 74 68 29 3a 0a 20 20  isfile(path):.  
5d10: 20 20 20 20 70 72 69 6e 74 28 22 4c 69 6e 65 20      print("Line 
5d20: 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e  " + str(self.lin
5d30: 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b  e_ct_stack[0]) +
5d40: 20 5c 0a 20 20 20 20 20 20 20 20 22 3a 20 43 6f   \.        ": Co
5d50: 75 6c 64 20 6e 6f 74 20 66 69 6e 64 20 69 6e 63  uld not find inc
5d60: 6c 75 64 65 20 66 69 6c 65 3a 20 22 20 2b 20 70  lude file: " + p
5d70: 61 74 68 29 0a 20 20 20 20 20 20 72 65 74 75 72  ath).      retur
5d80: 6e 20 22 66 61 69 6c 22 0a 20 20 20 20 69 66 20  n "fail".    if 
5d90: 73 65 6c 66 2e 76 65 72 62 6f 73 65 3a 0a 20 20  self.verbose:.  
5da0: 20 20 20 20 70 72 69 6e 74 28 22 6c 69 6e 65 3a      print("line:
5db0: 20 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69   " + str(self.li
5dc0: 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20  ne_ct_stack[0]) 
5dd0: 2b 20 22 3a 20 69 6e 63 6c 75 64 65 20 22 20 2b  + ": include " +
5de0: 20 70 61 74 68 29 0a 20 20 20 20 72 65 74 75 72   path).    retur
5df0: 6e 20 73 65 6c 66 2e 72 75 6e 5f 73 63 72 69 70  n self.run_scrip
5e00: 74 5f 66 69 6c 65 20 28 70 61 74 68 29 0a 20 20  t_file (path).  
5e10: 20 20 20 20 0a 20 20 0a 20 20 23 23 23 23 20 65      .  .  #### e
5e20: 6e 61 62 6c 65 5f 6f 70 74 69 6f 6e 5f 63 6f 6d  nable_option_com
5e30: 6d 61 6e 64 20 23 23 23 23 23 23 23 23 23 23 23  mand ###########
5e40: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
5e50: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
5e60: 0a 20 20 23 20 44 65 6c 65 74 65 73 20 61 6e 20  .  # Deletes an 
5e70: 6f 70 74 69 6f 6e 20 66 72 6f 6d 20 74 68 65 20  option from the 
5e80: 6c 69 73 74 20 6f 66 20 61 63 74 69 76 65 20 6f  list of active o
5e90: 70 74 69 6f 6e 73 2e 0a 20 20 23 20 50 61 72 73  ptions..  # Pars
5ea0: 65 73 20 74 68 65 20 66 69 72 73 74 20 61 72 67  es the first arg
5eb0: 75 6d 65 6e 74 20 61 66 74 65 72 20 22 65 6e 61  ument after "ena
5ec0: 62 6c 65 22 20 61 73 20 74 68 65 20 6b 65 79 20  ble" as the key 
5ed0: 74 6f 20 65 6e 61 62 6c 65 2e 0a 20 20 23 20 54  to enable..  # T
5ee0: 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 6b 65  he end of the ke
5ef0: 79 20 69 73 20 74 68 65 20 65 6e 64 20 6f 66 20  y is the end of 
5f00: 74 68 65 20 6c 69 6e 65 20 6f 72 20 74 68 65 20  the line or the 
5f10: 66 69 72 73 74 20 77 68 69 74 65 73 70 61 63 65  first whitespace
5f20: 0a 20 20 23 20 63 68 61 72 61 63 74 65 72 2e 0a  .  # character..
5f30: 20 20 0a 20 20 64 65 66 20 65 6e 61 62 6c 65 5f    .  def enable_
5f40: 6f 70 74 69 6f 6e 5f 63 6f 6d 6d 61 6e 64 20 28  option_command (
5f50: 73 65 6c 66 2c 20 6c 69 6e 65 2c 20 73 63 72 69  self, line, scri
5f60: 70 74 5f 66 69 6c 65 29 3a 0a 20 20 20 20 69 66  pt_file):.    if
5f70: 20 6c 69 6e 65 20 3d 3d 20 22 22 3a 0a 20 20 20   line == "":.   
5f80: 20 20 20 70 72 69 6e 74 28 22 45 6d 70 74 79 20     print("Empty 
5f90: 6f 70 74 69 6f 6e 20 74 6f 20 65 6e 61 62 6c 65  option to enable
5fa0: 20 61 74 20 6c 69 6e 65 3a 20 22 20 2b 20 5c 0a   at line: " + \.
5fb0: 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c 66          str(self
5fc0: 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
5fd0: 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20 20 20 20  ]) + ".").      
5fe0: 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a 20 20  return "fail".  
5ff0: 20 20 6d 20 3d 20 72 65 2e 6d 61 74 63 68 28 5f    m = re.match(_
6000: 63 6f 6d 6d 5f 72 65 2c 20 6c 69 6e 65 29 0a 20  comm_re, line). 
6010: 20 20 20 69 66 20 6d 20 3d 3d 20 4e 6f 6e 65 3a     if m == None:
6020: 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22 43 6f  .      print("Co
6030: 75 6c 64 20 6e 6f 74 20 70 61 72 73 65 20 65 6e  uld not parse en
6040: 61 62 6c 65 20 63 6f 6d 6d 61 6e 64 20 61 74 20  able command at 
6050: 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20 20  line " + \.     
6060: 20 20 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65     str(self.line
6070: 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20  _ct_stack[0]) + 
6080: 22 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72  ".").      retur
6090: 6e 20 22 66 61 69 6c 22 0a 20 20 20 20 6f 70 74  n "fail".    opt
60a0: 69 6f 6e 20 3d 20 6d 2e 67 72 6f 75 70 28 31 29  ion = m.group(1)
60b0: 0a 20 20 20 20 69 66 20 6f 70 74 69 6f 6e 20 3d  .    if option =
60c0: 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20 70 72  = None:.      pr
60d0: 69 6e 74 28 22 45 6d 70 74 79 20 6f 70 74 69 6f  int("Empty optio
60e0: 6e 20 74 6f 20 65 6e 61 62 6c 65 20 63 6f 6d 6d  n to enable comm
60f0: 61 6e 64 20 61 74 20 6c 69 6e 65 3a 20 22 20 2b  and at line: " +
6100: 20 5c 0a 20 20 20 20 20 20 20 20 73 74 72 28 73   \.        str(s
6110: 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63  elf.line_ct_stac
6120: 6b 5b 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20  k[0]) + ".").   
6130: 20 20 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22     return "fail"
6140: 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 76 65 72  .    if self.ver
6150: 62 6f 73 65 3a 0a 20 20 20 20 20 20 70 72 69 6e  bose:.      prin
6160: 74 28 22 4c 69 6e 65 20 22 20 2b 20 73 74 72 28  t("Line " + str(
6170: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
6180: 63 6b 5b 30 5d 29 20 2b 20 5c 0a 20 20 20 20 20  ck[0]) + \.     
6190: 20 20 20 20 22 3a 20 65 6e 61 62 6c 65 20 6f 70      ": enable op
61a0: 74 69 6f 6e 3a 20 22 20 2b 20 6f 70 74 69 6f 6e  tion: " + option
61b0: 29 0a 20 20 20 20 23 20 52 65 6d 6f 76 65 20 69  ).    # Remove i
61c0: 74 20 66 72 6f 6d 20 6f 74 68 65 72 20 73 65 74  t from other set
61d0: 20 69 66 20 70 72 65 73 65 6e 74 0a 20 20 20 20   if present.    
61e0: 69 66 20 6f 70 74 69 6f 6e 20 69 6e 20 73 65 6c  if option in sel
61f0: 66 2e 6f 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c  f.options_disabl
6200: 65 64 3a 0a 20 20 20 20 20 20 73 65 6c 66 2e 6f  ed:.      self.o
6210: 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c 65 64 2e  ptions_disabled.
6220: 72 65 6d 6f 76 65 28 6f 70 74 69 6f 6e 29 0a 20  remove(option). 
6230: 20 20 20 23 20 41 64 64 20 69 74 20 69 66 20 6e     # Add it if n
6240: 6f 74 20 61 6c 72 65 61 64 79 20 70 72 65 73 65  ot already prese
6250: 6e 74 2e 0a 20 20 20 20 69 66 20 6f 70 74 69 6f  nt..    if optio
6260: 6e 20 6e 6f 74 20 69 6e 20 73 65 6c 66 2e 6f 70  n not in self.op
6270: 74 69 6f 6e 73 5f 65 6e 61 62 6c 65 64 3a 0a 20  tions_enabled:. 
6280: 20 20 20 20 20 73 65 6c 66 2e 6f 70 74 69 6f 6e       self.option
6290: 73 5f 65 6e 61 62 6c 65 64 2e 61 70 70 65 6e 64  s_enabled.append
62a0: 28 6f 70 74 69 6f 6e 29 0a 20 20 20 20 72 65 74  (option).    ret
62b0: 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 0a 0a  urn "success"...
62c0: 20 20 23 23 23 23 20 64 69 73 61 62 6c 65 5f 6f    #### disable_o
62d0: 70 74 69 6f 6e 5f 63 6f 6d 6d 61 6e 64 20 23 23  ption_command ##
62e0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
62f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
6300: 23 23 23 23 23 23 23 23 23 0a 20 20 23 20 44 65  #########.  # De
6310: 6c 65 74 65 73 20 61 6e 20 6f 70 74 69 6f 6e 20  letes an option 
6320: 66 72 6f 6d 20 74 68 65 20 6c 69 73 74 20 6f 66  from the list of
6330: 20 61 63 74 69 76 65 20 6f 70 74 69 6f 6e 73 2e   active options.
6340: 0a 20 20 23 20 50 61 72 73 65 73 20 74 68 65 20  .  # Parses the 
6350: 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 61  first argument a
6360: 66 74 65 72 20 22 64 69 73 61 62 6c 65 22 20 61  fter "disable" a
6370: 73 20 74 68 65 20 6b 65 79 20 74 6f 20 65 6e 61  s the key to ena
6380: 62 6c 65 2e 0a 20 20 23 20 54 68 65 20 65 6e 64  ble..  # The end
6390: 20 6f 66 20 74 68 65 20 6b 65 79 20 69 73 20 74   of the key is t
63a0: 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 6c 69  he end of the li
63b0: 6e 65 20 6f 72 20 74 68 65 20 66 69 72 73 74 20  ne or the first 
63c0: 77 68 69 74 65 73 70 61 63 65 0a 20 20 23 20 63  whitespace.  # c
63d0: 68 61 72 61 63 74 65 72 2e 0a 20 0a 20 20 64 65  haracter.. .  de
63e0: 66 20 64 69 73 61 62 6c 65 5f 6f 70 74 69 6f 6e  f disable_option
63f0: 5f 63 6f 6d 6d 61 6e 64 20 28 73 65 6c 66 2c 20  _command (self, 
6400: 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f 66 69 6c  line, script_fil
6410: 65 29 3a 0a 20 20 20 20 69 66 20 6c 69 6e 65 20  e):.    if line 
6420: 3d 3d 20 22 22 3a 0a 20 20 20 20 20 20 70 72 69  == "":.      pri
6430: 6e 74 28 22 45 6d 70 74 79 20 6f 70 74 69 6f 6e  nt("Empty option
6440: 20 74 6f 20 64 69 73 61 62 6c 65 20 61 74 20 6c   to disable at l
6450: 69 6e 65 3a 20 22 20 2b 20 5c 0a 20 20 20 20 20  ine: " + \.     
6460: 20 20 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65     str(self.line
6470: 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20  _ct_stack[0]) + 
6480: 22 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72  ".").      retur
6490: 6e 20 22 66 61 69 6c 22 0a 20 20 20 20 6d 20 3d  n "fail".    m =
64a0: 20 72 65 2e 6d 61 74 63 68 28 5f 63 6f 6d 6d 5f   re.match(_comm_
64b0: 72 65 2c 20 6c 69 6e 65 29 0a 20 20 20 20 69 66  re, line).    if
64c0: 20 6d 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20   m == None:.    
64d0: 20 20 70 72 69 6e 74 28 22 43 6f 75 6c 64 20 6e    print("Could n
64e0: 6f 74 20 70 61 72 73 65 20 64 69 73 61 62 6c 65  ot parse disable
64f0: 20 6f 70 74 69 6f 6e 20 63 6f 6d 6d 61 6e 64 20   option command 
6500: 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20  at line " + \.  
6510: 20 20 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6c        str(self.l
6520: 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29  ine_ct_stack[0])
6530: 20 2b 20 22 2e 22 29 0a 20 20 20 20 20 20 72 65   + ".").      re
6540: 74 75 72 6e 20 22 66 61 69 6c 22 0a 20 20 20 20  turn "fail".    
6550: 6f 70 74 69 6f 6e 20 3d 20 6d 2e 67 72 6f 75 70  option = m.group
6560: 28 31 29 0a 20 20 20 20 69 66 20 6f 70 74 69 6f  (1).    if optio
6570: 6e 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20  n == None:.     
6580: 20 70 72 69 6e 74 28 22 45 6d 70 74 79 20 6f 70   print("Empty op
6590: 74 69 6f 6e 20 74 6f 20 64 69 73 61 62 6c 65 20  tion to disable 
65a0: 63 6f 6d 6d 61 6e 64 20 61 74 20 6c 69 6e 65 20  command at line 
65b0: 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 73 74  " + \.        st
65c0: 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73  r(self.line_ct_s
65d0: 74 61 63 6b 5b 30 5d 29 20 2b 20 22 2e 22 29 0a  tack[0]) + ".").
65e0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 66 61        return "fa
65f0: 69 6c 22 0a 20 20 20 20 69 66 20 73 65 6c 66 2e  il".    if self.
6600: 76 65 72 62 6f 73 65 3a 0a 20 20 20 20 20 20 70  verbose:.      p
6610: 72 69 6e 74 28 22 6c 69 6e 65 3a 20 22 20 2b 20  rint("line: " + 
6620: 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74  str(self.line_ct
6630: 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 5c 0a 20  _stack[0]) + \. 
6640: 20 20 20 20 20 20 20 20 20 22 3a 20 64 69 73 61           ": disa
6650: 62 6c 65 20 6f 70 74 69 6f 6e 3a 20 22 20 2b 20  ble option: " + 
6660: 6f 70 74 69 6f 6e 29 0a 20 20 20 20 23 20 52 65  option).    # Re
6670: 6d 6f 76 65 20 69 74 20 66 72 6f 6d 20 6f 74 68  move it from oth
6680: 65 72 20 73 65 74 20 69 66 20 70 72 65 73 65 6e  er set if presen
6690: 74 0a 20 20 20 20 69 66 20 6f 70 74 69 6f 6e 20  t.    if option 
66a0: 69 6e 20 73 65 6c 66 2e 6f 70 74 69 6f 6e 73 5f  in self.options_
66b0: 65 6e 61 62 6c 65 64 3a 0a 20 20 20 20 20 20 73  enabled:.      s
66c0: 65 6c 66 2e 6f 70 74 69 6f 6e 73 5f 65 6e 61 62  elf.options_enab
66d0: 6c 65 64 2e 72 65 6d 6f 76 65 28 6f 70 74 69 6f  led.remove(optio
66e0: 6e 29 0a 20 20 20 20 23 20 41 64 64 20 69 74 20  n).    # Add it 
66f0: 69 66 20 6e 6f 74 20 61 6c 72 65 61 64 79 20 70  if not already p
6700: 72 65 73 65 6e 74 2e 0a 20 20 20 20 69 66 20 6f  resent..    if o
6710: 70 74 69 6f 6e 20 6e 6f 74 20 69 6e 20 73 65 6c  ption not in sel
6720: 66 2e 6f 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c  f.options_disabl
6730: 65 64 3a 0a 20 20 20 20 20 20 73 65 6c 66 2e 6f  ed:.      self.o
6740: 70 74 69 6f 6e 73 5f 64 69 73 61 62 6c 65 64 2e  ptions_disabled.
6750: 61 70 70 65 6e 64 28 6f 70 74 69 6f 6e 29 0a 20  append(option). 
6760: 20 20 20 72 65 74 75 72 6e 20 22 73 75 63 63 65     return "succe
6770: 73 73 22 0a 0a 0a 20 20 23 23 23 23 20 63 6f 6e  ss"...  #### con
6780: 66 69 67 75 72 65 5f 63 6f 6d 6d 61 6e 64 20 23  figure_command #
6790: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
67a0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
67b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20  ##############. 
67c0: 20 23 20 46 69 72 73 74 20 61 72 67 20 69 73 20   # First arg is 
67d0: 74 68 65 20 69 74 65 6d 20 74 6f 20 63 6f 6e 66  the item to conf
67e0: 69 67 75 72 65 2e 0a 20 20 23 20 53 65 63 6f 6e  igure..  # Secon
67f0: 64 20 61 72 67 20 69 73 20 74 68 65 20 73 65 74  d arg is the set
6800: 74 69 6e 67 2e 0a 20 20 23 20 54 68 69 73 20 65  ting..  # This e
6810: 6e 61 62 6c 65 73 20 61 64 64 69 6e 67 20 6f 70  nables adding op
6820: 74 69 6f 6e 20 73 65 74 74 69 6e 67 20 69 6e 73  tion setting ins
6830: 69 64 65 20 61 20 73 63 72 69 70 74 20 66 69 6c  ide a script fil
6840: 65 2e 0a 20 20 0a 20 20 64 65 66 20 63 6f 6e 66  e..  .  def conf
6850: 69 67 75 72 65 5f 63 6f 6d 6d 61 6e 64 20 28 73  igure_command (s
6860: 65 6c 66 2c 20 6c 69 6e 65 2c 20 73 63 72 69 70  elf, line, scrip
6870: 74 5f 66 69 6c 65 29 3a 0a 20 20 20 20 6d 20 3d  t_file):.    m =
6880: 20 72 65 2e 6d 61 74 63 68 28 5f 74 77 6f 5f 61   re.match(_two_a
6890: 72 67 73 5f 72 65 2c 20 6c 69 6e 65 29 0a 20 20  rgs_re, line).  
68a0: 20 20 69 66 20 6d 20 3d 3d 20 4e 6f 6e 65 20 6f    if m == None o
68b0: 72 20 6d 2e 67 72 6f 75 70 28 31 29 20 3d 3d 20  r m.group(1) == 
68c0: 4e 6f 6e 65 20 6f 72 20 6d 2e 67 72 6f 75 70 28  None or m.group(
68d0: 32 29 20 3d 3d 20 4e 6f 6e 65 3a 20 0a 20 20 20  2) == None: .   
68e0: 20 20 20 70 72 69 6e 74 28 22 43 6f 75 6c 64 20     print("Could 
68f0: 6e 6f 74 20 70 61 72 73 65 20 63 6f 6e 66 69 67  not parse config
6900: 75 72 65 20 63 6f 6d 6d 61 6e 64 20 61 72 67 75  ure command argu
6910: 6d 65 6e 74 73 20 61 74 20 6c 69 6e 65 20 22 20  ments at line " 
6920: 2b 20 5c 0a 20 20 20 20 20 20 20 20 73 74 72 28  + \.        str(
6930: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
6940: 63 6b 5b 30 5d 29 20 2b 20 22 3a 20 7b 22 20 2b  ck[0]) + ": {" +
6950: 20 6c 69 6e 65 20 2b 20 22 7d 22 29 0a 20 20 20   line + "}").   
6960: 20 20 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22     return "fail"
6970: 0a 20 20 20 20 69 74 65 6d 20 3d 20 6d 2e 67 72  .    item = m.gr
6980: 6f 75 70 28 31 29 0a 20 20 20 20 73 65 74 74 69  oup(1).    setti
6990: 6e 67 20 3d 20 6d 2e 67 72 6f 75 70 28 32 29 0a  ng = m.group(2).
69a0: 20 20 20 20 69 66 20 69 74 65 6d 20 6e 6f 74 20      if item not 
69b0: 69 6e 20 5f 63 6f 6e 66 69 67 75 72 61 62 6c 65  in _configurable
69c0: 73 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22  s:.      print("
69d0: 49 67 6e 6f 72 69 6e 67 20 69 6e 76 61 6c 69 64  Ignoring invalid
69e0: 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 69   configuration i
69f0: 74 65 6d 20 61 74 20 6c 69 6e 65 20 22 20 2b 20  tem at line " + 
6a00: 5c 0a 20 20 20 20 20 20 20 20 73 74 72 28 73 65  \.        str(se
6a10: 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b  lf.line_ct_stack
6a20: 5b 30 5d 29 20 2b 20 22 3a 20 22 20 2b 20 69 74  [0]) + ": " + it
6a30: 65 6d 29 0a 20 20 20 20 20 20 72 65 74 75 72 6e  em).      return
6a40: 20 22 66 61 69 6c 22 0a 20 20 20 20 69 66 20 73   "fail".    if s
6a50: 65 74 74 69 6e 67 20 6e 6f 74 20 69 6e 20 5f 63  etting not in _c
6a60: 6f 6e 66 69 67 75 72 61 62 6c 65 73 5b 69 74 65  onfigurables[ite
6a70: 6d 5d 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28  m]:.      print(
6a80: 22 41 74 20 6c 69 6e 65 20 22 20 2b 20 73 74 72  "At line " + str
6a90: 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74  (self.line_ct_st
6aa0: 61 63 6b 5b 30 5d 29 20 2b 20 5c 0a 20 20 20 20  ack[0]) + \.    
6ab0: 20 20 20 20 22 3a 20 43 61 6e 6e 6f 74 20 73 65      ": Cannot se
6ac0: 74 20 22 20 2b 20 69 74 65 6d 20 2b 20 22 20 74  t " + item + " t
6ad0: 6f 20 22 20 2b 20 73 65 74 74 69 6e 67 20 2b 20  o " + setting + 
6ae0: 22 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72  ".").      retur
6af0: 6e 20 22 66 61 69 6c 22 0a 20 20 20 20 69 66 20  n "fail".    if 
6b00: 69 74 65 6d 20 3d 3d 20 22 74 61 70 65 22 3a 0a  item == "tape":.
6b10: 20 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e        self.simh.
6b20: 73 65 74 5f 74 61 70 65 5f 63 6f 6e 66 69 67 28  set_tape_config(
6b30: 73 65 74 74 69 6e 67 29 0a 20 20 20 20 65 6c 69  setting).    eli
6b40: 66 20 69 74 65 6d 20 3d 3d 20 22 72 78 22 3a 0a  f item == "rx":.
6b50: 20 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e        self.simh.
6b60: 73 65 74 5f 72 78 5f 63 6f 6e 66 69 67 20 28 73  set_rx_config (s
6b70: 65 74 74 69 6e 67 29 0a 20 20 20 20 65 6c 69 66  etting).    elif
6b80: 20 69 74 65 6d 20 3d 3d 20 22 74 74 69 22 3a 0a   item == "tti":.
6b90: 20 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e        self.simh.
6ba0: 73 65 74 5f 74 74 69 5f 63 6f 6e 66 69 67 20 28  set_tti_config (
6bb0: 73 65 74 74 69 6e 67 29 0a 20 20 20 20 72 65 74  setting).    ret
6bc0: 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 0a 0a  urn "success"...
6bd0: 20 20 23 23 23 23 20 63 70 74 6f 5f 63 6f 6d 6d    #### cpto_comm
6be0: 61 6e 64 20 23 23 23 23 23 23 23 23 23 23 23 23  and ############
6bf0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
6c00: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  ###############.
6c10: 20 20 23 20 43 61 6c 6c 73 20 6f 73 38 5f 70 69    # Calls os8_pi
6c20: 70 5f 74 6f 20 77 69 74 68 20 74 68 65 20 63 6f  p_to with the co
6c30: 6d 6d 61 6e 64 20 6c 69 6e 65 20 61 72 67 75 6d  mmand line argum
6c40: 65 6e 74 73 2e 0a 20 20 0a 20 20 64 65 66 20 63  ents..  .  def c
6c50: 70 74 6f 5f 63 6f 6d 6d 61 6e 64 20 28 73 65 6c  pto_command (sel
6c60: 66 2c 20 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f  f, line, script_
6c70: 66 69 6c 65 29 3a 0a 20 20 20 20 69 66 20 6e 6f  file):.    if no
6c80: 74 20 73 65 6c 66 2e 62 6f 6f 74 65 64 3a 0a 20  t self.booted:. 
6c90: 20 20 20 20 20 70 72 69 6e 74 28 22 43 61 6e 6e       print("Cann
6ca0: 6f 74 20 72 75 6e 20 63 70 74 6f 20 63 6f 6d 6d  ot run cpto comm
6cb0: 61 6e 64 20 61 74 20 6c 69 6e 65 20 22 20 2b 20  and at line " + 
6cc0: 5c 0a 20 20 20 20 20 20 20 20 73 74 72 28 73 65  \.        str(se
6cd0: 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b  lf.line_ct_stack
6ce0: 5b 30 5d 29 20 2b 20 22 2e 20 4f 53 2f 38 20 68  [0]) + ". OS/8 h
6cf0: 61 73 20 6e 6f 74 20 62 65 65 6e 20 62 6f 6f 74  as not been boot
6d00: 65 64 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75  ed.").      retu
6d10: 72 6e 20 22 64 69 65 22 0a 0a 20 20 20 20 23 20  rn "die"..    # 
6d20: 49 73 20 32 6e 64 20 61 6e 64 20 66 69 6e 61 6c  Is 2nd and final
6d30: 20 61 72 67 20 74 68 65 20 6f 70 74 69 6f 6e 3f   arg the option?
6d40: 0a 20 20 20 20 6d 20 3d 20 72 65 2e 6d 61 74 63  .    m = re.matc
6d50: 68 28 5f 66 72 6f 6d 5f 74 6f 5f 72 65 5f 31 2c  h(_from_to_re_1,
6d60: 20 6c 69 6e 65 29 0a 20 20 20 20 69 66 20 6d 20   line).    if m 
6d70: 21 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20 23  != None:.      #
6d80: 20 59 65 73 2e 20 20 45 78 70 61 6e 64 20 53 6f   Yes.  Expand So
6d90: 75 72 63 65 20 66 69 72 73 74 2e 0a 20 20 20 20  urce first..    
6da0: 20 20 70 61 74 68 20 3d 20 73 65 6c 66 2e 70 61    path = self.pa
6db0: 74 68 5f 65 78 70 61 6e 64 28 6d 2e 67 72 6f 75  th_expand(m.grou
6dc0: 70 28 31 29 29 0a 20 20 20 20 20 20 69 66 20 70  p(1)).      if p
6dd0: 61 74 68 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20  ath == None:.   
6de0: 20 20 20 20 20 70 72 69 6e 74 28 22 49 67 6e 6f       print("Igno
6df0: 72 69 6e 67 3a 20 5c 6e 5c 74 63 70 74 6f 20 22  ring: \n\tcpto "
6e00: 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20 20 20   + line).       
6e10: 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a 20   return "fail". 
6e20: 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 6f       self.simh.o
6e30: 73 38 5f 70 69 70 5f 74 6f 20 28 70 61 74 68 2c  s8_pip_to (path,
6e40: 20 22 44 53 4b 3a 22 2c 20 6d 2e 67 72 6f 75 70   "DSK:", m.group
6e50: 28 32 29 29 0a 20 20 20 20 65 6c 73 65 3a 0a 20  (2)).    else:. 
6e60: 20 20 20 20 20 23 20 49 73 20 74 68 69 73 20 6e       # Is this n
6e70: 6f 72 6d 61 6c 20 63 61 73 65 20 6f 66 20 73 6f  ormal case of so
6e80: 75 72 63 65 2c 20 64 65 73 74 2c 20 77 69 74 68  urce, dest, with
6e90: 20 70 6f 73 73 69 62 6c 79 20 65 6d 70 74 79 20   possibly empty 
6ea0: 6f 70 74 69 6f 6e 3f 0a 20 20 20 20 20 20 6d 20  option?.      m 
6eb0: 3d 20 72 65 2e 6d 61 74 63 68 28 5f 66 72 6f 6d  = re.match(_from
6ec0: 5f 74 6f 5f 72 65 5f 32 2c 20 6c 69 6e 65 29 0a  _to_re_2, line).
6ed0: 20 20 20 20 20 20 69 66 20 6d 20 3d 3d 20 4e 6f        if m == No
6ee0: 6e 65 3a 0a 20 20 20 20 20 20 20 20 70 72 69 6e  ne:.        prin
6ef0: 74 28 22 43 6f 75 6c 64 20 6e 6f 74 20 70 61 72  t("Could not par
6f00: 73 65 20 63 70 74 6f 20 63 6f 6d 6d 61 6e 64 20  se cpto command 
6f10: 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20  at line " + \.  
6f20: 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c 66          str(self
6f30: 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
6f40: 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20 20 20 20  ]) + ".").      
6f50: 20 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a    return "fail".
6f60: 20 20 20 20 20 20 70 61 74 68 20 3d 20 73 65 6c        path = sel
6f70: 66 2e 70 61 74 68 5f 65 78 70 61 6e 64 28 6d 2e  f.path_expand(m.
6f80: 67 72 6f 75 70 28 31 29 29 0a 20 20 20 20 20 20  group(1)).      
6f90: 69 66 20 70 61 74 68 20 3d 3d 20 4e 6f 6e 65 3a  if path == None:
6fa0: 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22  .        print("
6fb0: 49 67 6e 6f 72 69 6e 67 3a 20 5c 6e 5c 74 63 70  Ignoring: \n\tcp
6fc0: 74 6f 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20  to " + line).   
6fd0: 20 20 20 20 20 72 65 74 75 72 6e 20 22 66 61 69       return "fai
6fe0: 6c 22 0a 20 20 20 20 20 20 73 65 6c 66 2e 73 69  l".      self.si
6ff0: 6d 68 2e 6f 73 38 5f 70 69 70 5f 74 6f 20 28 70  mh.os8_pip_to (p
7000: 61 74 68 2c 20 6d 2e 67 72 6f 75 70 28 32 29 2c  ath, m.group(2),
7010: 20 6d 2e 67 72 6f 75 70 28 34 29 2c 20 73 65 6c   m.group(4), sel
7020: 66 2e 64 65 62 75 67 29 0a 20 20 20 20 72 65 74  f.debug).    ret
7030: 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 0a 0a  urn "success"...
7040: 20 20 23 23 23 23 20 63 70 66 72 6f 6d 5f 63 6f    #### cpfrom_co
7050: 6d 6d 61 6e 64 20 23 23 23 23 23 23 23 23 23 23  mmand ##########
7060: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7070: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  ###############.
7080: 20 20 23 20 43 61 6c 6c 73 20 6f 73 38 5f 70 69    # Calls os8_pi
7090: 70 5f 66 72 6f 6d 20 77 69 74 68 20 74 68 65 20  p_from with the 
70a0: 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 20 61 72 67  command line arg
70b0: 75 6d 65 6e 74 73 2e 0a 20 20 0a 20 20 64 65 66  uments..  .  def
70c0: 20 63 70 66 72 6f 6d 5f 63 6f 6d 6d 61 6e 64 20   cpfrom_command 
70d0: 28 73 65 6c 66 2c 20 6c 69 6e 65 2c 20 73 63 72  (self, line, scr
70e0: 69 70 74 5f 66 69 6c 65 29 3a 0a 20 20 20 20 69  ipt_file):.    i
70f0: 66 20 6e 6f 74 20 73 65 6c 66 2e 62 6f 6f 74 65  f not self.boote
7100: 64 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22  d:.      print("
7110: 43 61 6e 6e 6f 74 20 72 75 6e 20 63 70 66 72 6f  Cannot run cpfro
7120: 6d 20 63 6f 6d 6d 61 6e 64 20 61 74 20 6c 69 6e  m command at lin
7130: 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  e " + \.        
7140: 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74  str(self.line_ct
7150: 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 2e 20  _stack[0]) + ". 
7160: 4f 53 2f 38 20 68 61 73 20 6e 6f 74 20 62 65 65  OS/8 has not bee
7170: 6e 20 62 6f 6f 74 65 64 2e 22 29 0a 20 20 20 20  n booted.").    
7180: 20 20 72 65 74 75 72 6e 20 22 64 69 65 22 0a 20    return "die". 
7190: 20 20 20 6d 20 3d 20 72 65 2e 6d 61 74 63 68 28     m = re.match(
71a0: 5f 66 72 6f 6d 5f 74 6f 5f 72 65 5f 32 2c 20 6c  _from_to_re_2, l
71b0: 69 6e 65 29 0a 20 20 20 20 69 66 20 6d 20 3d 3d  ine).    if m ==
71c0: 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20 70 72 69   None:.      pri
71d0: 6e 74 28 22 43 6f 75 6c 64 20 6e 6f 74 20 70 61  nt("Could not pa
71e0: 72 73 65 20 63 70 66 72 6f 6d 20 63 6f 6d 6d 61  rse cpfrom comma
71f0: 6e 64 20 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c  nd at line " + \
7200: 0a 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c  .        str(sel
7210: 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b  f.line_ct_stack[
7220: 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20 20 20  0]) + ".").     
7230: 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a 20   return "fail". 
7240: 20 0a 20 20 20 20 70 61 74 68 20 3d 20 73 65 6c   .    path = sel
7250: 66 2e 70 61 74 68 5f 65 78 70 61 6e 64 28 6d 2e  f.path_expand(m.
7260: 67 72 6f 75 70 28 32 29 29 0a 20 20 20 20 69 66  group(2)).    if
7270: 20 70 61 74 68 20 3d 3d 20 4e 6f 6e 65 3a 0a 20   path == None:. 
7280: 20 20 20 20 20 70 72 69 6e 74 28 22 49 67 6e 6f       print("Igno
7290: 72 69 6e 67 3a 20 5c 6e 5c 74 63 70 66 72 6f 6d  ring: \n\tcpfrom
72a0: 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20   " + line).     
72b0: 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a 20   return "fail". 
72c0: 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38     self.simh.os8
72d0: 5f 70 69 70 5f 66 72 6f 6d 20 28 6d 2e 67 72 6f  _pip_from (m.gro
72e0: 75 70 28 31 29 2c 20 70 61 74 68 2c 20 6d 2e 67  up(1), path, m.g
72f0: 72 6f 75 70 28 34 29 29 0a 20 20 20 20 72 65 74  roup(4)).    ret
7300: 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 0a 0a  urn "success"...
7310: 20 20 23 23 23 23 20 63 6f 70 79 5f 63 6f 6d 6d    #### copy_comm
7320: 61 6e 64 20 23 23 23 23 23 23 23 23 23 23 23 23  and ############
7330: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7340: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7350: 23 23 23 0a 20 20 23 20 53 69 6d 70 6c 65 20 73  ###.  # Simple s
7360: 63 72 69 70 74 20 69 6e 74 65 72 66 61 63 65 20  cript interface 
7370: 74 6f 20 63 72 65 61 74 65 20 61 20 63 6f 70 79  to create a copy
7380: 20 6f 66 20 61 20 66 69 6c 65 2e 0a 0a 20 20 64   of a file...  d
7390: 65 66 20 63 6f 70 79 5f 63 6f 6d 6d 61 6e 64 20  ef copy_command 
73a0: 28 73 65 6c 66 2c 20 6c 69 6e 65 2c 20 73 63 72  (self, line, scr
73b0: 69 70 74 5f 66 69 6c 65 29 3a 0a 20 20 20 20 6d  ipt_file):.    m
73c0: 20 3d 20 72 65 2e 6d 61 74 63 68 28 5f 74 77 6f   = re.match(_two
73d0: 5f 61 72 67 73 5f 72 65 2c 20 6c 69 6e 65 29 0a  _args_re, line).
73e0: 20 20 20 20 69 66 20 6d 20 3d 3d 20 4e 6f 6e 65      if m == None
73f0: 20 6f 72 20 6d 2e 67 72 6f 75 70 28 31 29 20 3d   or m.group(1) =
7400: 3d 20 4e 6f 6e 65 20 6f 72 20 6d 2e 67 72 6f 75  = None or m.grou
7410: 70 28 32 29 20 3d 3d 20 4e 6f 6e 65 3a 20 0a 20  p(2) == None: . 
7420: 20 20 20 20 20 70 72 69 6e 74 28 22 43 6f 75 6c       print("Coul
7430: 64 20 6e 6f 74 20 63 6f 70 79 20 63 6f 6d 6d 61  d not copy comma
7440: 6e 64 3a 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20  nd: " + line).  
7450: 20 20 20 20 72 65 74 75 72 6e 20 22 66 61 69 6c      return "fail
7460: 22 0a 20 20 20 20 66 72 6f 6d 5f 70 61 74 68 20  ".    from_path 
7470: 3d 20 73 65 6c 66 2e 70 61 74 68 5f 65 78 70 61  = self.path_expa
7480: 6e 64 28 6d 2e 67 72 6f 75 70 28 31 29 29 20 20  nd(m.group(1))  
7490: 20 20 20 20 0a 20 20 20 20 74 6f 5f 70 61 74 68      .    to_path
74a0: 20 3d 20 73 65 6c 66 2e 70 61 74 68 5f 65 78 70   = self.path_exp
74b0: 61 6e 64 28 6d 2e 67 72 6f 75 70 28 32 29 29 0a  and(m.group(2)).
74c0: 0a 20 20 20 20 69 66 20 66 72 6f 6d 5f 70 61 74  .    if from_pat
74d0: 68 20 3d 3d 20 4e 6f 6e 65 20 6f 72 20 74 6f 5f  h == None or to_
74e0: 70 61 74 68 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20  path == None:.  
74f0: 20 20 20 20 70 72 69 6e 74 28 22 49 67 6e 6f 72      print("Ignor
7500: 69 6e 67 3a 20 5c 6e 5c 74 20 63 6f 70 79 20 22  ing: \n\t copy "
7510: 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20 20 72   + line).      r
7520: 65 74 75 72 6e 20 22 66 61 69 6c 22 0a 0a 20 20  eturn "fail"..  
7530: 20 20 70 72 69 6e 74 28 22 63 6f 70 79 20 63 6f    print("copy co
7540: 6d 6d 61 6e 64 3a 20 5c 6e 5c 74 66 72 6f 6d 3a  mmand: \n\tfrom:
7550: 20 22 20 2b 20 66 72 6f 6d 5f 70 61 74 68 20 2b   " + from_path +
7560: 20 22 2c 20 5c 6e 5c 74 74 6f 3a 20 22 20 2b 20   ", \n\tto: " + 
7570: 74 6f 5f 70 61 74 68 29 0a 20 20 20 20 0a 20 20  to_path).    .  
7580: 20 20 69 66 20 28 6e 6f 74 20 6f 73 2e 70 61 74    if (not os.pat
7590: 68 2e 69 73 66 69 6c 65 28 66 72 6f 6d 5f 70 61  h.isfile(from_pa
75a0: 74 68 29 29 3a 0a 20 20 20 20 20 20 20 20 70 72  th)):.        pr
75b0: 69 6e 74 28 22 41 74 20 6c 69 6e 65 20 22 20 2b  int("At line " +
75c0: 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63   str(self.line_c
75d0: 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 5c 0a  t_stack[0]) + \.
75e0: 20 20 20 20 20 20 20 20 20 20 22 3a 20 52 65 71            ": Req
75f0: 75 69 72 65 64 20 63 6f 70 79 20 69 6e 70 75 74  uired copy input
7600: 20 66 69 6c 65 3a 20 22 20 2b 20 66 72 6f 6d 5f   file: " + from_
7610: 70 61 74 68 20 2b 20 22 20 6e 6f 74 20 66 6f 75  path + " not fou
7620: 6e 64 2e 22 29 0a 20 20 20 20 20 20 20 20 72 65  nd.").        re
7630: 74 75 72 6e 20 22 66 61 69 6c 22 0a 0a 20 20 20  turn "fail"..   
7640: 20 73 61 76 65 5f 69 66 5f 6e 65 65 64 65 64 28   save_if_needed(
7650: 74 6f 5f 70 61 74 68 29 0a 20 20 20 20 0a 20 20  to_path).    .  
7660: 20 20 74 72 79 3a 0a 20 20 20 20 20 20 73 68 75    try:.      shu
7670: 74 69 6c 2e 63 6f 70 79 66 69 6c 65 28 66 72 6f  til.copyfile(fro
7680: 6d 5f 70 61 74 68 2c 20 74 6f 5f 70 61 74 68 29  m_path, to_path)
7690: 0a 20 20 20 20 65 78 63 65 70 74 20 73 68 75 74  .    except shut
76a0: 69 6c 2e 45 72 72 6f 72 20 61 73 20 65 3a 0a 20  il.Error as e:. 
76b0: 20 20 20 20 20 70 72 69 6e 74 28 22 63 6f 70 79       print("copy
76c0: 20 63 6f 6d 6d 61 6e 64 20 66 61 69 6c 65 64 20   command failed 
76d0: 77 69 74 68 20 65 72 72 6f 72 3a 20 22 20 2b 20  with error: " + 
76e0: 73 74 72 28 65 29 29 0a 20 20 20 20 20 20 72 65  str(e)).      re
76f0: 74 75 72 6e 20 22 66 61 69 6c 22 0a 20 20 20 20  turn "fail".    
7700: 65 78 63 65 70 74 20 49 4f 45 72 72 6f 72 20 61  except IOError a
7710: 73 20 65 3a 0a 20 20 20 20 20 20 70 72 69 6e 74  s e:.      print
7720: 28 22 63 6f 70 79 20 63 6f 6d 6d 61 6e 64 20 66  ("copy command f
7730: 61 69 6c 65 64 20 77 69 74 68 20 49 4f 45 72 72  ailed with IOErr
7740: 6f 72 3a 20 22 20 2b 20 73 74 72 28 65 29 29 0a  or: " + str(e)).
7750: 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 66 61        return "fa
7760: 69 6c 22 0a 20 20 20 20 72 65 74 75 72 6e 20 22  il".    return "
7770: 73 75 63 63 65 73 73 22 0a 0a 0a 20 20 23 23 23  success"...  ###
7780: 23 20 72 65 73 75 6d 65 5f 63 6f 6d 6d 61 6e 64  # resume_command
7790: 20 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23   ###############
77a0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
77b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20  ##############. 
77c0: 20 23 20 43 61 6c 6c 20 74 68 65 20 6f 73 38 5f   # Call the os8_
77d0: 72 65 73 75 6d 65 20 69 6e 20 73 69 6d 68 20 74  resume in simh t
77e0: 6f 20 72 65 73 75 6d 65 20 4f 53 2f 38 2e 0a 0a  o resume OS/8...
77f0: 20 20 64 65 66 20 72 65 73 75 6d 65 5f 63 6f 6d    def resume_com
7800: 6d 61 6e 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65  mand (self, line
7810: 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a  , script_file):.
7820: 20 20 20 20 69 66 20 6e 6f 74 20 73 65 6c 66 2e      if not self.
7830: 62 6f 6f 74 65 64 3a 0a 20 20 20 20 20 20 70 72  booted:.      pr
7840: 69 6e 74 28 22 43 61 6e 6e 6f 74 20 72 75 6e 20  int("Cannot run 
7850: 72 65 73 75 6d 65 20 63 6f 6d 6d 61 6e 64 20 61  resume command a
7860: 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20 20  t line " + \.   
7870: 20 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6c 69       str(self.li
7880: 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20  ne_ct_stack[0]) 
7890: 2b 20 22 2e 20 4f 53 2f 38 20 68 61 73 20 6e 6f  + ". OS/8 has no
78a0: 74 20 62 65 65 6e 20 62 6f 6f 74 65 64 2e 22 29  t been booted.")
78b0: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 64  .      return "d
78c0: 69 65 22 0a 0a 20 20 20 20 69 66 20 73 65 6c 66  ie"..    if self
78d0: 2e 76 65 72 62 6f 73 65 3a 0a 20 20 20 20 20 20  .verbose:.      
78e0: 70 72 69 6e 74 28 22 52 65 73 75 6d 69 6e 67 20  print("Resuming 
78f0: 4f 53 2f 38 20 61 74 20 6c 69 6e 65 20 22 20 2b  OS/8 at line " +
7900: 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63   str(self.line_c
7910: 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 2e  t_stack[0]) + ".
7920: 22 29 0a 0a 20 20 20 20 73 65 6c 66 2e 73 69 6d  ")..    self.sim
7930: 68 2e 73 69 6d 68 5f 72 65 73 75 6d 65 5f 6f 73  h.simh_resume_os
7940: 38 28 29 0a 20 20 20 20 72 65 74 75 72 6e 20 22  8().    return "
7950: 73 75 63 63 65 73 73 22 0a 0a 0a 20 20 23 23 23  success"...  ###
7960: 23 20 72 65 73 74 61 72 74 5f 63 6f 6d 6d 61 6e  # restart_comman
7970: 64 20 23 23 23 23 23 23 23 23 23 23 23 23 23 23  d ##############
7980: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7990: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  ###############.
79a0: 20 20 23 20 43 61 6c 6c 20 74 68 65 20 6f 73 38    # Call the os8
79b0: 5f 72 65 73 74 61 72 74 20 69 6e 20 73 69 6d 68  _restart in simh
79c0: 20 74 6f 20 72 65 73 75 6d 65 20 4f 53 2f 38 2e   to resume OS/8.
79d0: 0a 0a 20 20 64 65 66 20 72 65 73 74 61 72 74 5f  ..  def restart_
79e0: 63 6f 6d 6d 61 6e 64 20 28 73 65 6c 66 2c 20 6c  command (self, l
79f0: 69 6e 65 2c 20 73 63 72 69 70 74 5f 66 69 6c 65  ine, script_file
7a00: 29 3a 0a 20 20 20 20 69 66 20 6e 6f 74 20 73 65  ):.    if not se
7a10: 6c 66 2e 62 6f 6f 74 65 64 3a 0a 20 20 20 20 20  lf.booted:.     
7a20: 20 70 72 69 6e 74 28 22 43 61 6e 6e 6f 74 20 72   print("Cannot r
7a30: 75 6e 20 72 65 73 74 61 72 74 20 63 6f 6d 6d 61  un restart comma
7a40: 6e 64 20 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c  nd at line " + \
7a50: 0a 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c  .        str(sel
7a60: 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b  f.line_ct_stack[
7a70: 30 5d 29 20 2b 20 22 2e 20 4f 53 2f 38 20 68 61  0]) + ". OS/8 ha
7a80: 73 20 6e 6f 74 20 62 65 65 6e 20 62 6f 6f 74 65  s not been boote
7a90: 64 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72  d.").      retur
7aa0: 6e 20 22 64 69 65 22 0a 0a 20 20 20 20 69 66 20  n "die"..    if 
7ab0: 73 65 6c 66 2e 76 65 72 62 6f 73 65 3a 0a 20 20  self.verbose:.  
7ac0: 20 20 20 20 70 72 69 6e 74 28 22 52 65 73 74 61      print("Resta
7ad0: 72 74 69 6e 67 20 4f 53 2f 38 20 61 74 20 6c 69  rting OS/8 at li
7ae0: 6e 65 20 22 20 2b 20 73 74 72 28 73 65 6c 66 2e  ne " + str(self.
7af0: 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d  line_ct_stack[0]
7b00: 29 20 2b 20 22 2e 22 29 0a 0a 20 20 20 20 73 65  ) + ".")..    se
7b10: 6c 66 2e 73 69 6d 68 2e 73 69 6d 68 5f 72 65 73  lf.simh.simh_res
7b20: 74 61 72 74 5f 6f 73 38 28 29 0a 20 20 20 20 72  tart_os8().    r
7b30: 65 74 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a  eturn "success".
7b40: 0a 0a 20 20 23 23 23 23 20 70 61 74 63 68 5f 63  ..  #### patch_c
7b50: 6f 6d 6d 61 6e 64 20 23 23 23 23 23 23 23 23 23  ommand #########
7b60: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7b70: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7b80: 23 23 23 23 23 0a 20 20 23 20 52 65 61 64 20 74  #####.  # Read t
7b90: 68 65 20 6e 61 6d 65 64 20 70 61 74 63 68 20 66  he named patch f
7ba0: 69 6c 65 20 61 6e 64 20 70 65 72 66 6f 72 6d 20  ile and perform 
7bb0: 69 74 73 20 61 63 74 69 6f 6e 73 2e 0a 0a 20 20  its actions...  
7bc0: 64 65 66 20 70 61 74 63 68 5f 63 6f 6d 6d 61 6e  def patch_comman
7bd0: 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65 2c 20 73  d (self, line, s
7be0: 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a 20 20 20  cript_file):.   
7bf0: 20 69 66 20 6e 6f 74 20 73 65 6c 66 2e 62 6f 6f   if not self.boo
7c00: 74 65 64 3a 0a 20 20 20 20 20 20 70 72 69 6e 74  ted:.      print
7c10: 28 22 43 61 6e 6e 6f 74 20 72 75 6e 20 70 61 74  ("Cannot run pat
7c20: 63 68 20 63 6f 6d 6d 61 6e 64 20 61 74 20 6c 69  ch command at li
7c30: 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20  ne " + \.       
7c40: 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63   str(self.line_c
7c50: 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 2e  t_stack[0]) + ".
7c60: 20 4f 53 2f 38 20 68 61 73 20 6e 6f 74 20 62 65   OS/8 has not be
7c70: 65 6e 20 62 6f 6f 74 65 64 2e 22 29 0a 20 20 20  en booted.").   
7c80: 20 20 20 72 65 74 75 72 6e 20 22 64 69 65 22 0a     return "die".
7c90: 20 20 20 20 70 61 74 68 20 3d 20 73 65 6c 66 2e      path = self.
7ca0: 70 61 74 68 5f 65 78 70 61 6e 64 28 6c 69 6e 65  path_expand(line
7cb0: 29 0a 20 20 20 20 69 66 20 70 61 74 68 20 3d 3d  ).    if path ==
7cc0: 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20 70 72 69   None:.      pri
7cd0: 6e 74 28 22 49 67 6e 6f 72 69 6e 67 3a 20 5c 6e  nt("Ignoring: \n
7ce0: 5c 74 22 20 2b 20 22 70 61 74 63 68 20 22 20 2b  \t" + "patch " +
7cf0: 20 6c 69 6e 65 29 0a 20 20 20 20 20 20 72 65 74   line).      ret
7d00: 75 72 6e 20 22 66 61 69 6c 22 0a 20 20 20 20 69  urn "fail".    i
7d10: 66 20 6e 6f 74 20 6f 73 2e 70 61 74 68 2e 69 73  f not os.path.is
7d20: 66 69 6c 65 28 70 61 74 68 29 3a 0a 20 20 20 20  file(path):.    
7d30: 20 20 70 72 69 6e 74 28 22 41 74 20 6c 69 6e 65    print("At line
7d40: 20 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69   " + str(self.li
7d50: 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20  ne_ct_stack[0]) 
7d60: 2b 20 5c 0a 20 20 20 20 20 20 20 20 22 3a 20 50  + \.        ": P
7d70: 61 74 63 68 20 66 69 6c 65 3a 20 22 20 2b 20 70  atch file: " + p
7d80: 61 74 68 20 2b 20 22 20 6e 6f 74 20 66 6f 75 6e  ath + " not foun
7d90: 64 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72  d.").      retur
7da0: 6e 20 22 66 61 69 6c 22 0a 0a 20 20 20 20 73 65  n "fail"..    se
7db0: 6c 66 2e 72 75 6e 5f 70 61 74 63 68 5f 66 69 6c  lf.run_patch_fil
7dc0: 65 20 28 70 61 74 68 2c 20 6c 69 6e 65 2c 20 73  e (path, line, s
7dd0: 63 72 69 70 74 5f 66 69 6c 65 29 0a 20 20 20 20  cript_file).    
7de0: 72 65 74 75 72 6e 20 22 73 75 63 63 65 73 73 22  return "success"
7df0: 0a 0a 0a 20 20 23 23 23 23 20 65 78 69 74 5f 63  ...  #### exit_c
7e00: 6f 6d 6d 61 6e 64 20 23 23 23 23 23 23 23 23 23  ommand #########
7e10: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7e20: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
7e30: 23 23 23 23 23 23 0a 20 20 23 20 4d 61 6b 65 20  ######.  # Make 
7e40: 61 20 67 72 61 63 65 66 75 6c 20 65 78 69 74 3a  a graceful exit:
7e50: 0a 20 20 23 20 20 20 20 52 65 6d 6f 76 65 20 73  .  #    Remove s
7e60: 63 72 61 74 63 68 20 66 69 6c 65 73 2e 0a 20 20  cratch files..  
7e70: 23 20 20 20 20 44 65 74 61 63 68 20 61 6c 6c 20  #    Detach all 
7e80: 64 65 76 69 63 65 73 20 66 72 6f 6d 20 72 75 6e  devices from run
7e90: 6e 69 6e 67 20 69 6d 61 67 65 2e 0a 20 20 23 20  ning image..  # 
7ea0: 20 20 20 51 75 69 74 20 53 49 4d 48 2e 0a 20 20     Quit SIMH..  
7eb0: 23 20 20 20 20 50 61 72 73 65 20 61 6e 20 65 78  #    Parse an ex
7ec0: 69 74 20 73 74 61 74 75 73 20 76 61 6c 75 65 20  it status value 
7ed0: 66 72 6f 6d 20 6c 69 6e 65 2e 20 44 65 66 61 75  from line. Defau
7ee0: 6c 74 20 74 6f 20 30 2e 0a 20 20 23 20 20 20 20  lt to 0..  #    
7ef0: 43 61 6c 6c 20 50 4f 53 49 58 20 65 78 69 74 20  Call POSIX exit 
7f00: 74 6f 20 65 78 69 74 20 74 68 65 20 72 75 6e 6e  to exit the runn
7f10: 69 6e 67 20 70 72 6f 67 72 61 6d 2c 0a 20 20 0a  ing program,.  .
7f20: 20 20 64 65 66 20 65 78 69 74 5f 63 6f 6d 6d 61    def exit_comma
7f30: 6e 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65 2c 20  nd (self, line, 
7f40: 73 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a 20 20  script_file):.  
7f50: 20 20 6d 20 3d 20 72 65 2e 6d 61 74 63 68 20 28    m = re.match (
7f60: 5f 65 78 69 74 5f 61 72 67 5f 72 65 2c 20 6c 69  _exit_arg_re, li
7f70: 6e 65 29 0a 20 20 20 20 69 66 20 6d 20 21 3d 20  ne).    if m != 
7f80: 4e 6f 6e 65 3a 0a 20 20 20 20 20 20 69 66 20 6d  None:.      if m
7f90: 2e 67 72 6f 75 70 28 31 29 20 21 3d 20 4e 6f 6e  .group(1) != Non
7fa0: 65 3a 0a 20 20 20 20 20 20 20 20 20 73 74 61 74  e:.         stat
7fb0: 75 73 20 3d 20 69 6e 74 28 6d 2e 67 72 6f 75 70  us = int(m.group
7fc0: 28 31 29 29 0a 20 20 20 20 20 20 65 6c 69 66 20  (1)).      elif 
7fd0: 6d 2e 67 72 6f 75 70 28 32 29 20 21 3d 20 4e 6f  m.group(2) != No
7fe0: 6e 65 3a 0a 20 20 20 20 20 20 20 20 20 73 74 61  ne:.         sta
7ff0: 74 75 73 20 3d 20 69 6e 74 28 6d 2e 67 72 6f 75  tus = int(m.grou
8000: 70 28 32 29 29 0a 20 20 20 20 20 20 65 6c 73 65  p(2)).      else
8010: 3a 0a 20 20 20 20 20 20 20 20 73 74 61 74 75 73  :.        status
8020: 20 3d 20 30 0a 20 20 20 20 66 6f 72 20 66 69 6c   = 0.    for fil
8030: 65 6e 61 6d 65 20 69 6e 20 73 65 6c 66 2e 73 63  ename in self.sc
8040: 72 61 74 63 68 5f 6c 69 73 74 3a 0a 20 20 20 20  ratch_list:.    
8050: 20 20 69 66 20 73 65 6c 66 2e 76 65 72 62 6f 73    if self.verbos
8060: 65 3a 20 70 72 69 6e 74 28 22 44 65 6c 65 74 69  e: print("Deleti
8070: 6e 67 20 73 63 72 61 74 63 68 5f 63 6f 70 79 3a  ng scratch_copy:
8080: 20 22 20 2b 20 66 69 6c 65 6e 61 6d 65 29 0a 20   " + filename). 
8090: 20 20 20 20 20 6f 73 2e 72 65 6d 6f 76 65 28 66       os.remove(f
80a0: 69 6c 65 6e 61 6d 65 29 0a 0a 20 20 20 20 73 65  ilename)..    se
80b0: 6c 66 2e 73 69 6d 68 2e 73 69 6d 68 5f 63 6d 64  lf.simh.simh_cmd
80c0: 20 28 22 64 65 74 61 63 68 20 61 6c 6c 22 29 0a   ("detach all").
80d0: 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 5f 63      self.simh._c
80e0: 68 69 6c 64 2e 73 65 6e 64 6c 69 6e 65 28 22 71  hild.sendline("q
80f0: 75 69 74 22 29 0a 0a 20 20 20 20 69 66 20 73 65  uit")..    if se
8100: 6c 66 2e 76 65 72 62 6f 73 65 3a 0a 20 20 20 20  lf.verbose:.    
8110: 20 20 70 72 69 6e 74 28 22 43 61 6c 6c 69 6e 67    print("Calling
8120: 20 73 79 73 2e 65 78 69 74 20 28 22 20 2b 20 20   sys.exit (" +  
8130: 73 74 72 28 73 74 61 74 75 73 29 20 2b 20 22 29  str(status) + ")
8140: 20 61 74 20 6c 69 6e 65 3a 20 22 20 2b 20 5c 0a   at line: " + \.
8150: 20 20 20 20 20 20 20 20 20 20 20 20 73 74 72 28              str(
8160: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
8170: 63 6b 5b 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20  ck[0]) + ".").  
8180: 20 20 73 79 73 2e 65 78 69 74 28 73 74 61 74 75    sys.exit(statu
8190: 73 29 0a 0a 0a 20 20 23 23 23 23 20 70 72 69 6e  s)...  #### prin
81a0: 74 5f 63 6f 6d 6d 61 6e 64 20 23 23 23 23 23 23  t_command ######
81b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
81c0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
81d0: 23 23 23 23 23 23 23 23 23 0a 20 20 23 20 50 72  #########.  # Pr
81e0: 69 6e 74 20 74 65 78 74 20 66 72 6f 6d 20 74 68  int text from th
81f0: 65 20 72 75 6e 6e 69 6e 67 20 73 63 72 69 70 74  e running script
8200: 0a 20 20 23 20 49 66 20 76 65 72 62 6f 73 65 20  .  # If verbose 
8210: 69 73 20 73 65 74 2c 20 73 61 79 20 77 68 61 74  is set, say what
8220: 20 6c 69 6e 65 20 69 6e 20 74 68 65 20 73 63 72   line in the scr
8230: 69 70 74 20 63 6f 6e 74 61 69 6e 69 6e 67 0a 20  ipt containing. 
8240: 20 23 20 74 68 65 20 70 72 69 6e 74 20 63 6f 6d   # the print com
8250: 6d 61 6e 64 2e 0a 0a 20 20 64 65 66 20 70 72 69  mand...  def pri
8260: 6e 74 5f 63 6f 6d 6d 61 6e 64 20 28 73 65 6c 66  nt_command (self
8270: 2c 20 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f 66  , line, script_f
8280: 69 6c 65 29 3a 0a 20 20 20 20 69 66 20 73 65 6c  ile):.    if sel
8290: 66 2e 76 65 72 62 6f 73 65 3a 0a 20 20 20 20 20  f.verbose:.     
82a0: 20 70 72 69 6e 74 28 22 4c 69 6e 65 3a 20 22 20   print("Line: " 
82b0: 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f  + str(self.line_
82c0: 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22  ct_stack[0]) + "
82d0: 3a 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20  : " + line).    
82e0: 65 6c 73 65 3a 0a 20 20 20 20 20 20 70 72 69 6e  else:.      prin
82f0: 74 28 73 65 6c 66 2e 70 72 69 6e 74 5f 65 78 70  t(self.print_exp
8300: 61 6e 64 28 6c 69 6e 65 29 29 0a 20 20 20 20 72  and(line)).    r
8310: 65 74 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a  eturn "success".
8320: 0a 0a 20 20 23 23 23 23 20 5f 63 6f 6d 6d 61 6e  ..  #### _comman
8330: 64 20 23 23 23 23 23 23 23 23 23 23 23 23 23 23  d ##############
8340: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
8350: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20 20  #############.  
8360: 23 20 0a 0a 20 20 64 65 66 20 5f 63 6f 6d 6d 61  # ..  def _comma
8370: 6e 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65 2c 20  nd (self, line, 
8380: 73 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a 20 20  script_file):.  
8390: 20 20 72 65 74 75 72 6e 20 22 73 75 63 63 65 73    return "succes
83a0: 73 22 0a 0a 0a 20 20 23 23 23 23 20 72 75 6e 5f  s"...  #### run_
83b0: 73 63 72 69 70 74 5f 66 69 6c 65 20 23 23 23 23  script_file ####
83c0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
83d0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
83e0: 23 23 23 23 23 23 23 23 0a 20 20 23 20 52 75 6e  ########.  # Run
83f0: 20 6f 73 38 20 63 6f 6d 6d 61 6e 64 20 73 63 72   os8 command scr
8400: 69 70 74 20 66 69 6c 65 0a 20 20 23 20 43 61 6c  ipt file.  # Cal
8410: 6c 20 70 61 72 73 65 72 73 20 61 73 20 6e 65 65  l parsers as nee
8420: 64 65 64 20 66 6f 72 20 73 75 70 70 6f 72 74 65  ded for supporte
8430: 64 20 73 75 62 20 63 6f 6d 6d 61 6e 64 73 2e 0a  d sub commands..
8440: 20 20 23 0a 20 20 23 20 43 6f 6d 6d 61 6e 64 73    #.  # Commands
8450: 3a 0a 20 20 23 20 6d 6f 75 6e 74 20 3c 73 69 6d  :.  # mount <sim
8460: 68 2d 64 65 76 3e 20 3c 69 6d 61 67 65 2d 66 69  h-dev> <image-fi
8470: 6c 65 3e 20 5b 3c 6f 70 74 69 6f 6e 3e 20 2e 2e  le> [<option> ..
8480: 2e 5d 0a 20 20 23 20 20 20 20 20 20 20 6f 70 74  .].  #       opt
8490: 69 6f 6e 3a 20 72 65 71 75 69 72 65 64 20 7c 20  ion: required | 
84a0: 70 72 65 73 65 72 76 65 20 7c 20 72 65 61 64 6f  preserve | reado
84b0: 6e 6c 79 20 7c 20 72 6f 20 7c 20 73 63 72 61 74  nly | ro | scrat
84c0: 63 68 0a 20 20 23 20 75 6d 6f 75 6e 74 20 3c 73  ch.  # umount <s
84d0: 69 6d 68 2d 64 65 76 3e 0a 20 20 23 20 62 6f 6f  imh-dev>.  # boo
84e0: 74 20 3c 73 69 6d 68 2d 64 65 76 3e 0a 20 20 23  t <simh-dev>.  #
84f0: 20 6f 73 38 20 3c 63 6f 6d 6d 61 6e 64 2d 6c 69   os8 <command-li
8500: 6e 65 3e 0a 20 20 23 20 20 20 20 20 20 20 74 68  ne>.  #       th
8510: 65 20 72 65 73 74 20 6f 66 20 74 68 65 20 6c 69  e rest of the li
8520: 6e 65 20 69 73 20 70 61 73 73 65 64 20 76 65 72  ne is passed ver
8530: 62 61 74 69 6d 20 74 6f 20 4f 53 2f 38 0a 20 20  batim to OS/8.  
8540: 23 20 70 61 6c 38 20 3c 70 61 6c 2d 63 6f 6d 6d  # pal8 <pal-comm
8550: 61 6e 64 20 6c 69 6e 65 3e 0a 20 20 23 20 69 6e  and line>.  # in
8560: 63 6c 75 64 65 20 3c 73 63 72 69 70 74 2d 66 69  clude <script-fi
8570: 6c 65 3e 0a 20 20 23 20 63 6f 6e 66 69 67 75 72  le>.  # configur
8580: 65 20 3c 64 65 76 69 63 65 3e 20 3c 70 61 72 61  e <device> <para
8590: 6d 65 74 65 72 3e 0a 20 20 23 20 20 20 20 20 20  meter>.  #      
85a0: 20 64 65 76 69 63 65 3a 20 74 74 69 20 7c 20 74   device: tti | t
85b0: 61 70 65 20 7c 20 72 78 0a 20 20 23 20 20 20 20  ape | rx.  #    
85c0: 20 20 20 74 74 20 70 61 72 61 6d 65 74 65 72 3a     tt parameter:
85d0: 20 4b 53 52 20 7c 20 37 62 0a 20 20 23 20 20 20   KSR | 7b.  #   
85e0: 20 20 20 20 74 61 70 65 20 70 61 72 61 6d 65 74      tape paramet
85f0: 65 72 3a 20 74 64 20 7c 20 64 74 0a 20 20 23 20  er: td | dt.  # 
8600: 20 20 20 20 20 20 72 78 20 70 61 72 61 6d 65 74        rx paramet
8610: 65 72 3a 20 72 78 38 65 20 7c 20 72 78 32 38 20  er: rx8e | rx28 
8620: 7c 20 72 78 30 31 20 7c 20 72 78 30 32 0a 20 20  | rx01 | rx02.  
8630: 23 20 65 6e 61 62 6c 65 20 3c 70 61 72 61 6d 65  # enable <parame
8640: 74 65 72 3e 0a 20 20 23 20 64 69 73 61 62 6c 65  ter>.  # disable
8650: 20 3c 70 61 72 61 6d 65 74 65 72 3e 0a 20 20 23   <parameter>.  #
8660: 20 63 70 74 6f 20 3c 70 6f 73 69 78 2d 66 69 6c   cpto <posix-fil
8670: 65 3e 20 5b 3c 6f 73 38 2d 66 69 6c 65 3e 5d 20  e> [<os8-file>] 
8680: 5b 3c 66 6f 72 6d 61 74 3e 5d 0a 20 20 23 20 63  [<format>].  # c
8690: 70 66 72 6f 6d 20 3c 6f 73 38 2d 66 69 6c 65 3e  pfrom <os8-file>
86a0: 20 3c 70 6f 73 69 78 2d 66 69 6c 65 3e 20 5b 3c   <posix-file> [<
86b0: 66 6f 72 6d 61 74 3e 5d 0a 20 20 23 20 20 20 20  format>].  #    
86c0: 20 20 20 66 6f 72 6d 61 74 3a 20 2f 41 20 7c 20     format: /A | 
86d0: 2f 49 20 7c 20 2f 42 0a 20 20 23 20 63 6f 70 79  /I | /B.  # copy
86e0: 20 3c 66 72 6f 6d 2d 66 69 6c 65 3e 20 3c 74 6f   <from-file> <to
86f0: 2d 66 69 6c 65 3e 0a 20 20 23 20 70 61 74 63 68  -file>.  # patch
8700: 20 3c 70 61 74 63 68 2d 66 69 6c 65 3e 0a 20 20   <patch-file>.  
8710: 23 20 72 65 73 75 6d 65 0a 20 20 23 20 72 65 73  # resume.  # res
8720: 74 61 72 74 0a 20 20 23 20 62 65 67 69 6e 20 3c  tart.  # begin <
8730: 73 75 62 2d 63 6f 6d 6d 61 6e 64 3e 20 3c 6f 73  sub-command> <os
8740: 38 2d 70 61 74 68 3e 0a 20 20 23 20 65 6e 64 20  8-path>.  # end 
8750: 3c 73 75 62 2d 63 6f 6d 6d 61 6e 64 3e 0a 20 20  <sub-command>.  
8760: 23 20 70 72 69 6e 74 20 3c 6f 75 74 70 75 74 20  # print <output 
8770: 74 65 78 74 3e 0a 20 20 23 20 65 78 69 74 20 3c  text>.  # exit <
8780: 73 74 61 74 75 73 3e 0a 0a 20 20 23 20 53 75 62  status>..  # Sub
8790: 2d 63 6f 6d 6d 61 6e 64 73 3a 0a 20 20 23 20 62  -commands:.  # b
87a0: 75 69 6c 64 2c 20 66 6f 74 70 2c 20 61 62 73 6c  uild, fotp, absl
87b0: 64 72 0a 20 20 23 0a 20 20 23 20 43 6f 6d 6d 61  dr.  #.  # Comma
87c0: 6e 64 73 20 72 65 74 75 72 6e 2c 20 22 73 75 63  nds return, "suc
87d0: 63 65 73 73 22 2c 20 22 66 61 69 6c 22 2c 20 6f  cess", "fail", o
87e0: 72 20 22 64 69 65 22 2e 0a 0a 20 20 64 65 66 20  r "die"...  def 
87f0: 72 75 6e 5f 73 63 72 69 70 74 5f 66 69 6c 65 20  run_script_file 
8800: 28 73 65 6c 66 2c 20 73 63 72 69 70 74 5f 70 61  (self, script_pa
8810: 74 68 29 3a 0a 20 20 20 20 74 72 79 3a 0a 20 20  th):.    try:.  
8820: 20 20 20 20 73 63 72 69 70 74 5f 66 69 6c 65 20      script_file 
8830: 3d 20 6f 70 65 6e 28 73 63 72 69 70 74 5f 70 61  = open(script_pa
8840: 74 68 2c 20 22 72 22 29 0a 20 20 20 20 65 78 63  th, "r").    exc
8850: 65 70 74 20 49 4f 45 72 72 6f 72 3a 0a 20 20 20  ept IOError:.   
8860: 20 20 20 70 72 69 6e 74 28 73 63 72 69 70 74 5f     print(script_
8870: 70 61 74 68 20 2b 20 22 20 6e 6f 74 20 66 6f 75  path + " not fou
8880: 6e 64 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75  nd.").      retu
8890: 72 6e 20 22 66 61 69 6c 22 0a 20 20 20 20 72 65  rn "fail".    re
88a0: 74 75 72 6e 20 73 65 6c 66 2e 72 75 6e 5f 73 63  turn self.run_sc
88b0: 72 69 70 74 5f 68 61 6e 64 6c 65 28 73 63 72 69  ript_handle(scri
88c0: 70 74 5f 66 69 6c 65 2c 20 73 63 72 69 70 74 5f  pt_file, script_
88d0: 70 61 74 68 29 0a 20 20 20 20 0a 20 20 64 65 66  path).    .  def
88e0: 20 72 75 6e 5f 73 63 72 69 70 74 5f 68 61 6e 64   run_script_hand
88f0: 6c 65 20 28 73 65 6c 66 2c 20 73 63 72 69 70 74  le (self, script
8900: 5f 66 69 6c 65 2c 20 73 63 72 69 70 74 5f 70 61  _file, script_pa
8910: 74 68 29 3a 0a 20 20 23 20 53 74 72 69 6e 67 73  th):.  # Strings
8920: 2c 20 72 65 67 65 78 70 73 2c 20 61 6e 64 20 63  , regexps, and c
8930: 6f 6d 6d 61 6e 64 20 61 72 72 61 79 73 20 75 73  ommand arrays us
8940: 65 64 20 62 79 20 72 75 6e 5f 73 79 73 74 65 6d  ed by run_system
8950: 0a 20 20 20 20 63 6f 6d 6d 61 6e 64 73 20 3d 20  .    commands = 
8960: 7b 22 6d 6f 75 6e 74 22 3a 20 73 65 6c 66 2e 6d  {"mount": self.m
8970: 6f 75 6e 74 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20  ount_command,.  
8980: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 62                "b
8990: 6f 6f 74 22 3a 20 73 65 6c 66 2e 62 6f 6f 74 5f  oot": self.boot_
89a0: 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20 20 20  command,.       
89b0: 20 20 20 20 20 20 20 20 20 22 6f 73 38 22 3a 20           "os8": 
89c0: 73 65 6c 66 2e 6f 73 38 5f 63 6f 6d 6d 61 6e 64  self.os8_command
89d0: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
89e0: 20 20 22 6f 63 6f 6d 70 22 3a 20 73 65 6c 66 2e    "ocomp": self.
89f0: 6f 63 6f 6d 70 5f 63 6f 6d 6d 61 6e 64 2c 0a 20  ocomp_command,. 
8a00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22                 "
8a10: 70 61 6c 38 22 3a 20 73 65 6c 66 2e 70 61 6c 38  pal8": self.pal8
8a20: 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20 20  _command,.      
8a30: 20 20 20 20 20 20 20 20 20 20 22 69 6e 63 6c 75            "inclu
8a40: 64 65 22 3a 20 73 65 6c 66 2e 69 6e 63 6c 75 64  de": self.includ
8a50: 65 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20  e_command,.     
8a60: 20 20 20 20 20 20 20 20 20 20 20 22 62 65 67 69             "begi
8a70: 6e 22 3a 20 73 65 6c 66 2e 62 65 67 69 6e 5f 63  n": self.begin_c
8a80: 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20 20 20 20  ommand,.        
8a90: 20 20 20 20 20 20 20 20 22 65 6e 64 22 3a 20 73          "end": s
8aa0: 65 6c 66 2e 65 6e 64 5f 63 6f 6d 6d 61 6e 64 2c  elf.end_command,
8ab0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
8ac0: 20 22 65 78 69 74 22 3a 20 73 65 6c 66 2e 65 78   "exit": self.ex
8ad0: 69 74 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20  it_command,.    
8ae0: 20 20 20 20 20 20 20 20 20 20 20 20 22 70 72 69              "pri
8af0: 6e 74 22 3a 20 73 65 6c 66 2e 70 72 69 6e 74 5f  nt": self.print_
8b00: 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20 20 20  command,.       
8b10: 20 20 20 20 20 20 20 20 20 22 75 6d 6f 75 6e 74           "umount
8b20: 22 3a 20 73 65 6c 66 2e 75 6d 6f 75 6e 74 5f 63  ": self.umount_c
8b30: 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20 20 20 20  ommand,.        
8b40: 20 20 20 20 20 20 20 20 22 73 69 6d 68 22 3a 20          "simh": 
8b50: 73 65 6c 66 2e 73 69 6d 68 5f 63 6f 6d 6d 61 6e  self.simh_comman
8b60: 64 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  d,.             
8b70: 20 20 20 22 63 6f 6e 66 69 67 75 72 65 22 3a 20     "configure": 
8b80: 73 65 6c 66 2e 63 6f 6e 66 69 67 75 72 65 5f 63  self.configure_c
8b90: 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20 20 20 20  ommand,.        
8ba0: 20 20 20 20 20 20 20 20 22 65 6e 61 62 6c 65 22          "enable"
8bb0: 3a 20 73 65 6c 66 2e 65 6e 61 62 6c 65 5f 6f 70  : self.enable_op
8bc0: 74 69 6f 6e 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20  tion_command,.  
8bd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 64                "d
8be0: 69 73 61 62 6c 65 22 3a 20 73 65 6c 66 2e 64 69  isable": self.di
8bf0: 73 61 62 6c 65 5f 6f 70 74 69 6f 6e 5f 63 6f 6d  sable_option_com
8c00: 6d 61 6e 64 2c 0a 20 20 20 20 20 20 20 20 20 20  mand,.          
8c10: 20 20 20 20 20 20 22 63 70 74 6f 22 3a 20 73 65        "cpto": se
8c20: 6c 66 2e 63 70 74 6f 5f 63 6f 6d 6d 61 6e 64 2c  lf.cpto_command,
8c30: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
8c40: 20 22 63 70 66 72 6f 6d 22 3a 20 73 65 6c 66 2e   "cpfrom": self.
8c50: 63 70 66 72 6f 6d 5f 63 6f 6d 6d 61 6e 64 2c 0a  cpfrom_command,.
8c60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
8c70: 22 63 6f 70 79 22 3a 20 73 65 6c 66 2e 63 6f 70  "copy": self.cop
8c80: 79 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20  y_command,.     
8c90: 20 20 20 20 20 20 20 20 20 20 20 22 72 65 73 75             "resu
8ca0: 6d 65 22 3a 20 73 65 6c 66 2e 72 65 73 75 6d 65  me": self.resume
8cb0: 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20 20  _command,.      
8cc0: 20 20 20 20 20 20 20 20 20 20 22 72 65 73 74 61            "resta
8cd0: 72 74 22 3a 20 73 65 6c 66 2e 72 65 73 74 61 72  rt": self.restar
8ce0: 74 5f 63 6f 6d 6d 61 6e 64 2c 0a 20 20 20 20 20  t_command,.     
8cf0: 20 20 20 20 20 20 20 20 20 20 20 22 70 61 74 63             "patc
8d00: 68 22 3a 20 73 65 6c 66 2e 70 61 74 63 68 5f 63  h": self.patch_c
8d10: 6f 6d 6d 61 6e 64 7d 0a 20 20 0a 20 20 20 20 23  ommand}.  .    #
8d20: 20 45 76 65 72 79 20 74 69 6d 65 20 77 65 20 73   Every time we s
8d30: 74 61 72 74 20 61 20 6e 65 77 20 73 63 72 69 70  tart a new scrip
8d40: 74 0a 20 20 20 20 23 20 57 65 20 61 70 70 65 6e  t.    # We appen
8d50: 64 20 61 20 6e 65 77 20 6c 69 6e 65 20 6e 75 6d  d a new line num
8d60: 62 65 72 20 63 6f 75 6e 74 20 6f 66 20 30 0a 20  ber count of 0. 
8d70: 20 20 20 23 20 6f 6e 74 6f 20 6f 75 72 20 6c 69     # onto our li
8d80: 6e 65 5f 63 74 5f 73 74 61 63 6b 0a 20 20 20 20  ne_ct_stack.    
8d90: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
8da0: 63 6b 2e 69 6e 73 65 72 74 28 30 2c 20 30 29 0a  ck.insert(0, 0).
8db0: 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65 62 75      if self.debu
8dc0: 67 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22  g:.      print("
8dd0: 4e 65 77 20 6c 69 6e 65 5f 63 74 5f 73 74 61 63  New line_ct_stac
8de0: 6b 3a 20 22 20 2b 20 73 74 72 28 73 65 6c 66 2e  k: " + str(self.
8df0: 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 29 29 0a  line_ct_stack)).
8e00: 20 20 0a 20 20 20 20 66 6f 72 20 6c 69 6e 65 20    .    for line 
8e10: 69 6e 20 73 63 72 69 70 74 5f 66 69 6c 65 3a 0a  in script_file:.
8e20: 20 20 20 20 20 20 6c 69 6e 65 20 3d 20 73 65 6c        line = sel
8e30: 66 2e 62 61 73 69 63 5f 6c 69 6e 65 5f 70 61 72  f.basic_line_par
8e40: 73 65 20 28 6c 69 6e 65 2c 20 73 63 72 69 70 74  se (line, script
8e50: 5f 66 69 6c 65 29 0a 20 20 20 20 20 20 69 66 20  _file).      if 
8e60: 6c 69 6e 65 20 3d 3d 20 4e 6f 6e 65 3a 20 63 6f  line == None: co
8e70: 6e 74 69 6e 75 65 0a 20 20 20 20 20 20 0a 20 20  ntinue.      .  
8e80: 20 20 20 20 6d 20 3d 20 72 65 2e 6d 61 74 63 68      m = re.match
8e90: 28 5f 63 6f 6d 6d 5f 72 65 2c 20 6c 69 6e 65 29  (_comm_re, line)
8ea0: 0a 20 20 20 20 20 20 69 66 20 6d 20 3d 3d 20 4e  .      if m == N
8eb0: 6f 6e 65 3a 0a 20 20 20 20 20 20 20 20 70 72 69  one:.        pri
8ec0: 6e 74 28 22 49 67 6e 6f 72 69 6e 67 20 63 6f 6d  nt("Ignoring com
8ed0: 6d 61 6e 64 20 6c 69 6e 65 20 61 74 20 6c 69 6e  mand line at lin
8ee0: 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  e " + \.        
8ef0: 20 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f    str(self.line_
8f00: 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22  ct_stack[0]) + "
8f10: 3a 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20  : " + line).    
8f20: 20 20 20 20 63 6f 6e 74 69 6e 75 65 0a 20 20 0a      continue.  .
8f30: 20 20 20 20 20 20 69 66 20 6d 2e 67 72 6f 75 70        if m.group
8f40: 28 31 29 20 6e 6f 74 20 69 6e 20 63 6f 6d 6d 61  (1) not in comma
8f50: 6e 64 73 3a 0a 20 20 20 20 20 20 20 20 70 72 69  nds:.        pri
8f60: 6e 74 28 22 55 6e 72 65 63 6f 67 6e 69 7a 65 64  nt("Unrecognized
8f70: 20 73 63 72 69 70 74 20 63 6f 6d 6d 61 6e 64 20   script command 
8f80: 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20  at line " + \.  
8f90: 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c 66          str(self
8fa0: 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
8fb0: 5d 29 20 2b 20 22 3a 20 22 20 2b 20 6d 2e 67 72  ]) + ": " + m.gr
8fc0: 6f 75 70 28 31 29 29 0a 20 20 20 20 20 20 20 20  oup(1)).        
8fd0: 63 6f 6e 74 69 6e 75 65 0a 20 20 0a 20 20 20 20  continue.  .    
8fe0: 20 20 23 20 70 72 69 6e 74 28 22 61 72 67 3a 20    # print("arg: 
8ff0: 22 20 2b 20 6d 2e 67 72 6f 75 70 28 33 29 29 0a  " + m.group(3)).
9000: 20 20 20 20 20 20 69 66 20 6d 2e 67 72 6f 75 70        if m.group
9010: 28 33 29 20 3d 3d 20 4e 6f 6e 65 3a 20 72 65 73  (3) == None: res
9020: 74 20 3d 20 22 22 0a 20 20 20 20 20 20 65 6c 73  t = "".      els
9030: 65 3a 20 72 65 73 74 20 3d 20 6d 2e 67 72 6f 75  e: rest = m.grou
9040: 70 28 33 29 0a 20 20 20 20 20 20 72 65 74 76 61  p(3).      retva
9050: 6c 20 3d 20 63 6f 6d 6d 61 6e 64 73 5b 6d 2e 67  l = commands[m.g
9060: 72 6f 75 70 28 31 29 5d 28 72 65 73 74 2c 20 73  roup(1)](rest, s
9070: 63 72 69 70 74 5f 66 69 6c 65 29 0a 20 20 20 20  cript_file).    
9080: 20 20 69 66 20 72 65 74 76 61 6c 20 3d 3d 20 22    if retval == "
9090: 64 69 65 22 3a 0a 20 20 20 20 20 20 20 20 70 72  die":.        pr
90a0: 69 6e 74 28 22 5c 6e 46 61 74 61 6c 20 65 72 72  int("\nFatal err
90b0: 6f 72 20 65 6e 63 6f 75 6e 74 65 72 65 64 20 69  or encountered i
90c0: 6e 20 22 20 2b 20 73 63 72 69 70 74 5f 70 61 74  n " + script_pat
90d0: 68 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 20 20  h + \.          
90e0: 22 20 61 74 20 6c 69 6e 65 20 22 20 2b 20 20 73  " at line " +  s
90f0: 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f  tr(self.line_ct_
9100: 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 3a 22 29  stack[0]) + ":")
9110: 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22  .        print("
9120: 5c 74 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20  \t" + line).    
9130: 20 20 20 20 73 79 73 2e 65 78 69 74 28 2d 31 29      sys.exit(-1)
9140: 0a 20 20 20 20 20 20 65 6c 69 66 20 72 65 74 76  .      elif retv
9150: 61 6c 20 3d 3d 20 22 66 61 69 6c 22 3a 0a 20 20  al == "fail":.  
9160: 20 20 20 20 20 20 70 72 69 6e 74 28 22 4e 6f 6e        print("Non
9170: 2d 66 61 74 61 6c 20 65 72 72 6f 72 20 65 6e 63  -fatal error enc
9180: 6f 75 6e 74 65 72 65 64 20 69 6e 20 22 20 2b 20  ountered in " + 
9190: 73 63 72 69 70 74 5f 70 61 74 68 20 2b 20 5c 0a  script_path + \.
91a0: 20 20 20 20 20 20 20 20 20 20 22 20 61 74 20 6c            " at l
91b0: 69 6e 65 20 22 20 2b 20 20 73 74 72 28 73 65 6c  ine " +  str(sel
91c0: 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b  f.line_ct_stack[
91d0: 30 5d 29 20 2b 20 22 3a 22 29 0a 20 20 20 20 20  0]) + ":").     
91e0: 20 20 20 70 72 69 6e 74 28 22 5c 74 22 20 2b 20     print("\t" + 
91f0: 6c 69 6e 65 20 2b 20 22 5c 6e 22 29 0a 0a 20 20  line + "\n")..  
9200: 20 20 23 20 44 6f 6e 65 2e 20 20 50 6f 70 20 74    # Done.  Pop t
9210: 68 65 20 6c 69 6e 65 20 63 6f 75 6e 74 20 6f 66  he line count of
9220: 66 20 6f 75 72 20 6c 69 6e 65 5f 63 74 5f 73 74  f our line_ct_st
9230: 61 63 6b 0a 20 20 20 20 73 65 6c 66 2e 6c 69 6e  ack.    self.lin
9240: 65 5f 63 74 5f 73 74 61 63 6b 2e 70 6f 70 28 30  e_ct_stack.pop(0
9250: 29 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65  ).    if self.de
9260: 62 75 67 3a 0a 20 20 20 20 20 20 70 72 69 6e 74  bug:.      print
9270: 28 22 70 6f 70 70 65 64 20 6c 69 6e 65 5f 63 74  ("popped line_ct
9280: 5f 73 74 61 63 6b 3a 20 22 20 2b 20 73 74 72 28  _stack: " + str(
9290: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
92a0: 63 6b 29 29 0a 20 20 20 20 0a 20 20 20 20 72 65  ck)).    .    re
92b0: 74 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 0a  turn "success"..
92c0: 0a 20 20 23 23 23 23 20 65 6e 64 5f 63 6f 6d 6d  .  #### end_comm
92d0: 61 6e 64 20 23 23 23 23 23 23 23 23 23 23 23 23  and ############
92e0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
92f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9300: 23 23 23 23 23 23 23 23 23 0a 20 20 0a 20 20 64  #########.  .  d
9310: 65 66 20 65 6e 64 5f 63 6f 6d 6d 61 6e 64 20 28  ef end_command (
9320: 73 65 6c 66 2c 20 6c 69 6e 65 2c 20 73 63 72 69  self, line, scri
9330: 70 74 5f 66 69 6c 65 29 3a 0a 20 20 20 20 70 72  pt_file):.    pr
9340: 69 6e 74 28 22 55 6e 65 78 70 65 63 74 65 64 6c  int("Unexpectedl
9350: 79 20 65 6e 63 6f 75 6e 74 65 72 65 64 20 65 6e  y encountered en
9360: 64 20 63 6f 6d 6d 61 6e 64 20 61 74 20 6c 69 6e  d command at lin
9370: 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 73 74  e " + \.      st
9380: 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73  r(self.line_ct_s
9390: 74 61 63 6b 5b 30 5d 29 20 2b 20 22 3a 20 22 20  tack[0]) + ": " 
93a0: 2b 20 6c 69 6e 65 29 0a 20 20 20 20 72 65 74 75  + line).    retu
93b0: 72 6e 20 22 66 61 69 6c 22 0a 0a 20 20 0a 20 20  rn "fail"..  .  
93c0: 23 23 23 23 20 70 61 72 73 65 5f 6f 64 74 20 23  #### parse_odt #
93d0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
93e0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
93f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9400: 23 23 23 23 23 23 0a 20 20 0a 20 20 64 65 66 20  ######.  .  def 
9410: 70 61 72 73 65 5f 6f 64 74 20 28 73 65 6c 66 2c  parse_odt (self,
9420: 20 6c 69 6e 65 29 3a 0a 20 20 20 20 69 66 20 73   line):.    if s
9430: 65 6c 66 2e 64 65 62 75 67 3a 20 70 72 69 6e 74  elf.debug: print
9440: 28 6c 69 6e 65 29 0a 20 20 20 20 0a 20 20 20 20  (line).    .    
9450: 69 66 20 6c 69 6e 65 20 3d 3d 20 22 5c 5c 63 22  if line == "\\c"
9460: 3a 20 72 65 74 75 72 6e 20 22 62 72 65 61 6b 22  : return "break"
9470: 0a 20 20 20 20 6d 61 74 63 68 20 3d 20 5f 6f 64  .    match = _od
9480: 74 5f 70 61 72 73 65 2e 6d 61 74 63 68 28 6c 69  t_parse.match(li
9490: 6e 65 29 0a 20 20 20 20 69 66 20 6d 61 74 63 68  ne).    if match
94a0: 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20   == None:.      
94b0: 70 72 69 6e 74 28 22 41 62 6f 72 74 69 6e 67 20  print("Aborting 
94c0: 62 65 63 61 75 73 65 20 6f 66 20 62 61 64 20 4f  because of bad O
94d0: 44 54 20 6c 69 6e 65 3a 20 22 20 2b 20 6c 69 6e  DT line: " + lin
94e0: 65 29 0a 20 20 20 20 20 20 73 65 6c 66 2e 73 69  e).      self.si
94f0: 6d 68 2e 6f 73 38 5f 63 74 72 6c 5f 63 20 28 63  mh.os8_ctrl_c (c
9500: 61 6c 6c 65 72 3d 22 70 61 72 73 65 5f 6f 64 74  aller="parse_odt
9510: 22 29 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20  ").      return 
9520: 22 65 72 72 22 0a 20 20 20 20 6c 6f 63 20 3d 20  "err".    loc = 
9530: 6d 61 74 63 68 2e 67 72 6f 75 70 28 31 29 0a 20  match.group(1). 
9540: 20 20 20 6f 6c 64 5f 76 61 6c 20 3d 20 6d 61 74     old_val = mat
9550: 63 68 2e 67 72 6f 75 70 28 32 29 0a 20 20 20 20  ch.group(2).    
9560: 6e 65 77 5f 76 61 6c 20 3d 20 6d 61 74 63 68 2e  new_val = match.
9570: 67 72 6f 75 70 28 33 29 0a 20 20 20 20 65 78 70  group(3).    exp
9580: 65 63 74 5f 76 61 6c 5f 73 74 72 20 3d 20 72 22  ect_val_str = r"
9590: 5c 73 2a 5b 30 2d 37 5d 7b 34 7d 20 22 0a 20 20  \s*[0-7]{4} ".  
95a0: 20 20 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 64    .    if self.d
95b0: 65 62 75 67 3a 0a 20 20 20 20 20 20 70 72 69 6e  ebug:.      prin
95c0: 74 28 22 4c 6f 63 3a 20 22 20 2b 20 6c 6f 63 20  t("Loc: " + loc 
95d0: 2b 20 22 2c 20 6f 6c 64 5f 76 61 6c 3a 20 22 20  + ", old_val: " 
95e0: 2b 20 6f 6c 64 5f 76 61 6c 20 2b 20 22 2c 20 6e  + old_val + ", n
95f0: 65 77 5f 76 61 6c 3a 20 22 20 2b 20 5c 0a 20 20  ew_val: " + \.  
9600: 20 20 20 20 20 20 20 20 6e 65 77 5f 76 61 6c 29          new_val)
9610: 0a 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 6f  .    self.simh.o
9620: 73 38 5f 73 65 6e 64 5f 73 74 72 20 28 6c 6f 63  s8_send_str (loc
9630: 20 2b 20 22 2f 22 29 0a 20 20 20 20 73 65 6c 66   + "/").    self
9640: 2e 73 69 6d 68 2e 5f 63 68 69 6c 64 2e 65 78 70  .simh._child.exp
9650: 65 63 74 28 65 78 70 65 63 74 5f 76 61 6c 5f 73  ect(expect_val_s
9660: 74 72 29 0a 20 20 0a 20 20 20 20 69 66 20 6f 6c  tr).  .    if ol
9670: 64 5f 76 61 6c 2e 69 73 64 69 67 69 74 28 29 3a  d_val.isdigit():
9680: 20 20 20 20 20 20 20 20 20 20 23 20 57 65 20 6e            # We n
9690: 65 65 64 20 74 6f 20 63 68 65 63 6b 20 6f 6c 64  eed to check old
96a0: 20 76 61 6c 75 65 0a 20 20 20 20 20 20 66 6f 75   value.      fou
96b0: 6e 64 5f 76 61 6c 20 3d 20 73 65 6c 66 2e 73 69  nd_val = self.si
96c0: 6d 68 2e 63 68 69 6c 64 5f 61 66 74 65 72 28 29  mh.child_after()
96d0: 2e 73 74 72 69 70 28 29 0a 20 20 20 20 20 20 69  .strip().      i
96e0: 66 20 66 6f 75 6e 64 5f 76 61 6c 20 21 3d 20 6f  f found_val != o
96f0: 6c 64 5f 76 61 6c 3a 0a 20 20 20 20 20 20 20 20  ld_val:.        
9700: 70 72 69 6e 74 28 22 5c 74 4f 6c 64 20 76 61 6c  print("\tOld val
9710: 75 65 3a 20 22 20 2b 20 66 6f 75 6e 64 5f 76 61  ue: " + found_va
9720: 6c 20 2b 20 22 20 64 6f 65 73 20 6e 6f 74 20 6d  l + " does not m
9730: 61 74 63 68 20 22 20 2b 0a 20 20 20 20 20 20 20  atch " +.       
9740: 20 20 20 20 20 6f 6c 64 5f 76 61 6c 20 2b 20 22       old_val + "
9750: 2e 20 41 62 6f 72 74 69 6e 67 20 70 61 74 63 68  . Aborting patch
9760: 2e 22 29 0a 20 20 20 20 20 20 20 20 23 20 41 62  .").        # Ab
9770: 6f 72 74 20 6f 75 74 20 6f 66 20 4f 44 54 20 62  ort out of ODT b
9780: 61 63 6b 20 74 6f 20 74 68 65 20 4f 53 2f 38 20  ack to the OS/8 
9790: 4d 6f 6e 69 74 6f 72 0a 20 20 20 20 20 20 20 20  Monitor.        
97a0: 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 63 74  self.simh.os8_ct
97b0: 72 6c 5f 63 20 28 22 70 61 72 73 65 5f 6f 64 74  rl_c ("parse_odt
97c0: 20 32 22 29 0a 20 20 20 20 20 20 20 20 72 65 74   2").        ret
97d0: 75 72 6e 20 22 65 72 72 22 0a 20 20 0a 20 20 20  urn "err".  .   
97e0: 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 73   self.simh.os8_s
97f0: 65 6e 64 5f 6c 69 6e 65 20 28 6e 65 77 5f 76 61  end_line (new_va
9800: 6c 29 0a 20 20 20 20 72 65 74 75 72 6e 20 22 63  l).    return "c
9810: 6f 6e 74 22 0a 0a 0a 20 20 23 23 23 23 20 66 75  ont"...  #### fu
9820: 74 69 6c 5f 65 78 69 74 20 23 23 23 23 23 23 23  til_exit #######
9830: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9840: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9850: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9860: 23 0a 20 20 0a 20 20 64 65 66 20 66 75 74 69 6c  #.  .  def futil
9870: 5f 65 78 69 74 20 28 73 65 6c 66 2c 20 6c 69 6e  _exit (self, lin
9880: 65 29 3a 0a 20 20 20 20 73 65 6c 66 2e 73 69 6d  e):.    self.sim
9890: 68 2e 6f 73 38 5f 73 65 6e 64 5f 6c 69 6e 65 28  h.os8_send_line(
98a0: 6c 69 6e 65 29 0a 20 20 20 20 72 65 74 75 72 6e  line).    return
98b0: 20 22 62 72 65 61 6b 22 0a 0a 0a 20 20 23 23 23   "break"...  ###
98c0: 23 20 66 75 74 69 6c 5f 66 69 6c 65 20 23 23 23  # futil_file ###
98d0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
98e0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
98f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9900: 23 23 23 23 23 0a 20 20 0a 20 20 64 65 66 20 66  #####.  .  def f
9910: 75 74 69 6c 5f 66 69 6c 65 20 28 73 65 6c 66 2c  util_file (self,
9920: 20 6c 69 6e 65 29 3a 0a 20 20 20 20 23 20 52 65   line):.    # Re
9930: 64 75 6e 64 61 6e 74 20 72 65 2d 70 61 72 73 65  dundant re-parse
9940: 20 6f 66 20 6c 69 6e 65 20 62 75 74 20 6e 6f 62   of line but nob
9950: 6f 64 79 20 65 6c 73 65 20 77 61 6e 74 73 20 61  ody else wants a
9960: 72 67 73 20 72 69 67 68 74 20 6e 6f 77 2e 0a 20  rgs right now.. 
9970: 20 20 20 6d 61 74 63 68 20 3d 20 5f 63 6f 6d 5f     match = _com_
9980: 73 70 6c 69 74 5f 70 61 72 73 65 2e 6d 61 74 63  split_parse.matc
9990: 68 28 6c 69 6e 65 29 0a 20 20 20 20 69 66 20 6d  h(line).    if m
99a0: 61 74 63 68 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20  atch == None:.  
99b0: 20 20 20 20 70 72 69 6e 74 28 22 41 62 6f 72 74      print("Abort
99c0: 69 6e 67 20 62 65 63 61 75 73 65 20 6f 66 20 6d  ing because of m
99d0: 61 6c 2d 66 6f 72 6d 65 64 20 46 55 54 49 4c 20  al-formed FUTIL 
99e0: 46 49 4c 45 20 63 6f 6d 6d 61 6e 64 3a 20 22 20  FILE command: " 
99f0: 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20 20 73 65  + line).      se
9a00: 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 63 74 72 6c  lf.simh.os8_ctrl
9a10: 5f 63 20 28 63 61 6c 6c 65 72 3d 22 66 75 74 69  _c (caller="futi
9a20: 6c 5f 66 69 6c 65 22 29 0a 20 20 20 20 20 20 72  l_file").      r
9a30: 65 74 75 72 6e 20 22 65 72 72 22 0a 20 20 20 20  eturn "err".    
9a40: 66 6e 61 6d 65 20 3d 20 6d 61 74 63 68 2e 67 72  fname = match.gr
9a50: 6f 75 70 28 32 29 0a 20 20 20 20 65 78 70 65 63  oup(2).    expec
9a60: 74 5f 66 75 74 69 6c 5f 66 69 6c 65 5f 73 74 72  t_futil_file_str
9a70: 20 3d 20 22 5c 6e 22 20 2b 20 66 6e 61 6d 65 20   = "\n" + fname 
9a80: 2b 20 72 22 5c 73 2b 28 3f 21 22 20 2b 20 66 6e  + r"\s+(?!" + fn
9a90: 61 6d 65 20 20 2b 20 72 22 29 3f 28 5c 53 2b 29  ame  + r")?(\S+)
9aa0: 28 2e 2a 29 24 22 0a 20 20 20 20 73 65 6c 66 2e  (.*)$".    self.
9ab0: 73 69 6d 68 2e 6f 73 38 5f 73 65 6e 64 5f 6c 69  simh.os8_send_li
9ac0: 6e 65 20 28 6c 69 6e 65 29 0a 20 20 20 20 73 65  ne (line).    se
9ad0: 6c 66 2e 73 69 6d 68 2e 5f 63 68 69 6c 64 2e 65  lf.simh._child.e
9ae0: 78 70 65 63 74 28 65 78 70 65 63 74 5f 66 75 74  xpect(expect_fut
9af0: 69 6c 5f 66 69 6c 65 5f 73 74 72 29 0a 20 20 20  il_file_str).   
9b00: 20 72 65 73 75 6c 74 20 3d 20 73 65 6c 66 2e 73   result = self.s
9b10: 69 6d 68 2e 63 68 69 6c 64 5f 61 66 74 65 72 28  imh.child_after(
9b20: 29 2e 73 74 72 69 70 28 29 0a 20 20 20 20 6d 61  ).strip().    ma
9b30: 74 63 68 20 3d 20 5f 63 6f 6d 5f 73 70 6c 69 74  tch = _com_split
9b40: 5f 70 61 72 73 65 2e 6d 61 74 63 68 28 72 65 73  _parse.match(res
9b50: 75 6c 74 29 0a 20 20 20 20 69 66 20 6d 61 74 63  ult).    if matc
9b60: 68 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20  h == None:.     
9b70: 20 70 72 69 6e 74 28 22 41 62 6f 72 74 69 6e 67   print("Aborting
9b80: 20 62 65 63 61 75 73 65 20 75 6e 65 78 70 65 63   because unexpec
9b90: 74 65 64 20 72 65 74 75 72 6e 20 73 74 61 74 75  ted return statu
9ba0: 73 3a 20 22 20 2b 20 72 65 73 75 6c 74 20 2b 20  s: " + result + 
9bb0: 5c 0a 20 20 20 20 20 20 20 20 20 20 22 20 66 72  \.          " fr
9bc0: 6f 6d 3a 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20  om: " + line).  
9bd0: 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73      self.simh.os
9be0: 38 5f 63 74 72 6c 5f 63 20 28 63 61 6c 6c 65 72  8_ctrl_c (caller
9bf0: 3d 22 66 75 74 69 6c 5f 66 69 6c 65 20 32 22 29  ="futil_file 2")
9c00: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 65  .      return "e
9c10: 72 72 22 0a 20 20 20 20 69 66 20 6d 61 74 63 68  rr".    if match
9c20: 2e 67 72 6f 75 70 28 32 29 2e 73 74 72 69 70 28  .group(2).strip(
9c30: 29 20 3d 3d 20 22 4c 4f 4f 4b 55 50 20 46 41 49  ) == "LOOKUP FAI
9c40: 4c 45 44 22 3a 0a 20 20 20 20 20 20 70 72 69 6e  LED":.      prin
9c50: 74 28 22 41 62 6f 72 74 69 6e 67 20 62 65 63 61  t("Aborting beca
9c60: 75 73 65 20 6f 66 20 46 55 54 49 4c 20 6c 6f 6f  use of FUTIL loo
9c70: 6b 75 70 20 66 61 69 6c 75 72 65 20 6f 6e 3a 20  kup failure on: 
9c80: 22 20 2b 20 66 6e 61 6d 65 29 0a 20 20 20 20 20  " + fname).     
9c90: 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 63   self.simh.os8_c
9ca0: 74 72 6c 5f 63 20 28 63 61 6c 6c 65 72 3d 22 66  trl_c (caller="f
9cb0: 75 74 69 6c 5f 66 69 6c 65 20 33 22 29 0a 20 20  util_file 3").  
9cc0: 20 20 20 20 72 65 74 75 72 6e 20 22 65 72 72 22      return "err"
9cd0: 0a 20 20 20 20 65 6c 73 65 3a 0a 20 20 20 20 20  .    else:.     
9ce0: 20 72 65 74 75 72 6e 20 22 63 6f 6e 74 22 0a 20   return "cont". 
9cf0: 20 0a 20 20 0a 20 20 23 23 23 23 20 70 61 72 73   .  .  #### pars
9d00: 65 5f 66 75 74 69 6c 20 23 23 23 23 23 23 23 23  e_futil ########
9d10: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9d20: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
9d30: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20 20  #############.  
9d40: 23 0a 20 20 23 20 56 65 72 79 20 73 69 6d 70 6c  #.  # Very simpl
9d50: 65 20 6d 69 6e 64 65 64 3a 0a 20 20 23 20 49 66  e minded:.  # If
9d60: 20 66 69 72 73 74 20 63 68 61 72 20 6f 6e 20 6c   first char on l
9d70: 69 6e 65 20 69 73 20 61 6e 20 61 6c 70 68 61 2c  ine is an alpha,
9d80: 20 72 75 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64   run the command
9d90: 2e 0a 20 20 23 20 49 66 20 74 68 65 20 66 69 72  ..  # If the fir
9da0: 73 74 20 63 68 61 72 20 6f 6e 20 6c 69 6e 65 20  st char on line 
9db0: 69 73 20 6e 75 6d 62 65 72 2c 20 64 6f 20 74 68  is number, do th
9dc0: 65 20 73 75 62 73 74 69 74 75 74 65 20 63 6f 6d  e substitute com
9dd0: 6d 61 6e 64 2e 0a 20 20 23 0a 20 20 23 20 53 75  mand..  #.  # Su
9de0: 62 73 74 69 74 75 74 65 20 63 6f 6d 6d 61 6e 64  bstitute command
9df0: 20 61 63 74 73 20 6c 69 6b 65 20 4f 44 54 2e 0a   acts like ODT..
9e00: 20 20 23 20 46 75 74 75 72 65 20 76 65 72 73 69    # Future versi
9e10: 6f 6e 20 73 68 6f 75 6c 64 20 73 75 70 70 6f 72  on should suppor
9e20: 74 20 74 68 65 20 49 46 20 63 6f 6e 73 74 72 75  t the IF constru
9e30: 63 74 2e 0a 20 20 23 0a 20 20 23 20 57 68 65 6e  ct..  #.  # When
9e40: 20 77 65 20 65 6e 63 6f 75 6e 74 65 72 20 74 68   we encounter th
9e50: 65 20 45 58 49 54 20 63 6f 6d 6d 61 6e 64 2c 20  e EXIT command, 
9e60: 77 65 20 72 65 74 75 72 6e 20 73 75 63 63 65 73  we return succes
9e70: 73 2e 0a 20 20 0a 20 20 64 65 66 20 70 61 72 73  s..  .  def pars
9e80: 65 5f 66 75 74 69 6c 20 28 73 65 6c 66 2c 20 6c  e_futil (self, l
9e90: 69 6e 65 29 3a 0a 20 20 20 20 66 75 74 69 6c 5f  ine):.    futil_
9ea0: 73 70 65 63 69 61 6c 73 20 3d 20 7b 0a 20 20 20  specials = {.   
9eb0: 20 20 20 22 45 58 49 54 22 3a 20 73 65 6c 66 2e     "EXIT": self.
9ec0: 66 75 74 69 6c 5f 65 78 69 74 2c 0a 20 20 20 20  futil_exit,.    
9ed0: 20 20 22 46 49 4c 45 22 3a 20 73 65 6c 66 2e 66    "FILE": self.f
9ee0: 75 74 69 6c 5f 66 69 6c 65 0a 20 20 20 20 7d 0a  util_file.    }.
9ef0: 20 20 0a 20 20 20 20 69 66 20 6c 69 6e 65 5b 30    .    if line[0
9f00: 5d 2e 69 73 64 69 67 69 74 28 29 3a 0a 20 20 20  ].isdigit():.   
9f10: 20 20 20 23 20 54 72 65 61 74 20 74 68 65 20 6c     # Treat the l
9f20: 69 6e 65 20 61 73 20 4f 44 54 0a 20 20 20 20 20  ine as ODT.     
9f30: 20 72 65 74 75 72 6e 20 73 65 6c 66 2e 70 61 72   return self.par
9f40: 73 65 5f 6f 64 74 28 6c 69 6e 65 29 0a 20 20 20  se_odt(line).   
9f50: 20 65 6c 73 65 3a 0a 20 20 20 20 20 20 6d 61 74   else:.      mat
9f60: 63 68 20 3d 20 5f 63 6f 6d 5f 73 70 6c 69 74 5f  ch = _com_split_
9f70: 70 61 72 73 65 2e 6d 61 74 63 68 28 6c 69 6e 65  parse.match(line
9f80: 29 0a 20 20 20 20 20 20 69 66 20 6d 61 74 63 68  ).      if match
9f90: 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20 20   == None:.      
9fa0: 20 20 70 72 69 6e 74 28 22 49 67 6e 6f 72 69 6e    print("Ignorin
9fb0: 67 20 66 61 69 6c 65 64 20 46 55 54 49 4c 20 63  g failed FUTIL c
9fc0: 6f 6d 6d 61 6e 64 20 70 61 72 73 65 20 6f 66 3a  ommand parse of:
9fd0: 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20   " + line).     
9fe0: 20 20 20 72 65 74 75 72 6e 20 22 63 6f 6e 74 22     return "cont"
9ff0: 0a 20 20 20 20 20 20 66 63 6f 6d 20 3d 20 6d 61  .      fcom = ma
a000: 74 63 68 2e 67 72 6f 75 70 28 31 29 0a 20 20 20  tch.group(1).   
a010: 20 20 20 72 65 73 74 20 3d 20 6d 61 74 63 68 2e     rest = match.
a020: 67 72 6f 75 70 28 32 29 0a 20 20 0a 20 20 20 20  group(2).  .    
a030: 20 20 69 66 20 66 63 6f 6d 20 6e 6f 74 20 69 6e    if fcom not in
a040: 20 66 75 74 69 6c 5f 73 70 65 63 69 61 6c 73 3a   futil_specials:
a050: 0a 20 20 20 20 20 20 20 20 23 20 42 6c 69 6e 64  .        # Blind
a060: 20 66 61 69 74 68 20 61 6e 64 20 6e 6f 20 65 72   faith and no er
a070: 72 6f 72 20 63 68 65 63 6b 69 6e 67 2e 0a 20 20  ror checking..  
a080: 20 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e        self.simh.
a090: 6f 73 38 5f 73 65 6e 64 5f 6c 69 6e 65 28 6c 69  os8_send_line(li
a0a0: 6e 65 29 0a 20 20 20 20 20 20 20 20 72 65 74 75  ne).        retu
a0b0: 72 6e 20 22 63 6f 6e 74 22 0a 20 20 20 20 20 20  rn "cont".      
a0c0: 65 6c 73 65 3a 0a 20 20 20 20 20 20 20 20 72 65  else:.        re
a0d0: 74 75 72 6e 20 66 75 74 69 6c 5f 73 70 65 63 69  turn futil_speci
a0e0: 61 6c 73 5b 66 63 6f 6d 5d 28 6c 69 6e 65 29 0a  als[fcom](line).
a0f0: 0a 0a 20 20 23 23 23 23 20 72 75 6e 5f 70 61 74  ..  #### run_pat
a100: 63 68 5f 66 69 6c 65 20 23 23 23 23 23 23 23 23  ch_file ########
a110: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
a120: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
a130: 23 23 23 23 23 23 23 23 23 23 0a 20 20 0a 20 20  ##########.  .  
a140: 64 65 66 20 72 75 6e 5f 70 61 74 63 68 5f 66 69  def run_patch_fi
a150: 6c 65 20 28 73 65 6c 66 2c 20 70 61 74 68 6e 61  le (self, pathna
a160: 6d 65 2c 20 6c 69 6e 65 2c 20 73 63 72 69 70 74  me, line, script
a170: 5f 66 69 6c 65 29 3a 0a 20 20 20 20 73 79 73 2e  _file):.    sys.
a180: 73 74 64 6f 75 74 2e 77 72 69 74 65 20 28 22 41  stdout.write ("A
a190: 70 70 6c 79 69 6e 67 20 70 61 74 63 68 20 22 20  pplying patch " 
a1a0: 2b 20 6f 73 2e 70 61 74 68 2e 62 61 73 65 6e 61  + os.path.basena
a1b0: 6d 65 20 28 70 61 74 68 6e 61 6d 65 29 20 2b 20  me (pathname) + 
a1c0: 22 2e 2e 2e 22 29 0a 20 20 20 20 73 79 73 2e 73  "...").    sys.s
a1d0: 74 64 6f 75 74 2e 66 6c 75 73 68 20 28 29 0a 0a  tdout.flush ()..
a1e0: 20 20 20 20 74 72 79 3a 0a 20 20 20 20 20 20 70      try:.      p
a1f0: 61 74 63 68 5f 66 69 6c 65 20 3d 20 6f 70 65 6e  atch_file = open
a200: 28 70 61 74 68 6e 61 6d 65 2c 20 22 72 22 29 0a  (pathname, "r").
a210: 20 20 20 20 65 78 63 65 70 74 20 49 4f 45 72 72      except IOErr
a220: 6f 72 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28  or:.      print(
a230: 70 61 74 68 6e 61 6d 65 20 2b 20 22 20 6e 6f 74  pathname + " not
a240: 20 66 6f 75 6e 64 2e 20 53 6b 69 70 70 69 6e 67   found. Skipping
a250: 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72 6e  .").      return
a260: 20 22 66 61 69 6c 22 0a 20 20 20 20 0a 20 20 20   "fail".    .   
a270: 20 23 20 53 75 70 70 6f 72 74 65 64 20 70 61 72   # Supported par
a280: 73 65 72 73 2e 0a 20 20 20 20 23 20 4e 6f 74 65  sers..    # Note
a290: 20 74 68 74 20 46 55 54 49 4c 20 68 61 73 20 6e   tht FUTIL has n
a2a0: 6f 74 20 62 65 65 6e 20 74 65 73 74 65 64 20 73  ot been tested s
a2b0: 69 6e 63 65 20 77 65 20 66 6c 69 70 70 65 64 20  ince we flipped 
a2c0: 74 68 65 20 65 78 70 65 63 74 20 6f 72 64 65 72  the expect order
a2d0: 2e 0a 20 20 20 20 70 61 72 73 65 72 73 20 3d 20  ..    parsers = 
a2e0: 7b 0a 20 20 20 20 20 20 22 4f 44 54 22 3a 20 73  {.      "ODT": s
a2f0: 65 6c 66 2e 70 61 72 73 65 5f 6f 64 74 2c 0a 20  elf.parse_odt,. 
a300: 20 20 20 20 20 22 46 55 54 49 4c 22 3a 20 73 65       "FUTIL": se
a310: 6c 66 2e 70 61 72 73 65 5f 66 75 74 69 6c 0a 20  lf.parse_futil. 
a320: 20 20 20 7d 0a 0a 20 20 20 20 23 20 57 68 61 74     }..    # What
a330: 20 70 72 6f 6d 70 74 20 64 6f 20 77 65 20 77 61   prompt do we wa
a340: 6e 74 20 77 68 65 6e 20 77 65 20 72 75 6e 20 61  nt when we run a
a350: 6e 20 61 6c 6c 6f 77 65 64 20 63 6f 6d 6d 61 6e  n allowed comman
a360: 64 3f 0a 20 20 20 20 23 20 49 66 20 74 68 65 72  d?.    # If ther
a370: 65 20 69 73 20 6e 6f 6e 65 2c 20 77 65 20 64 6f  e is none, we do
a380: 6e 27 74 20 77 61 69 74 2e 20 20 42 75 74 20 69  n't wait.  But i
a390: 66 20 77 65 20 77 61 6e 74 20 6f 6e 65 2c 0a 20  f we want one,. 
a3a0: 20 20 20 23 20 57 65 20 42 45 54 54 45 52 20 77     # We BETTER w
a3b0: 61 69 74 20 66 6f 72 20 69 74 2e 20 20 41 20 72  ait for it.  A r
a3c0: 61 63 65 20 63 6f 6e 64 69 74 69 6f 6e 20 68 61  ace condition ha
a3d0: 73 20 62 65 65 6e 20 6f 62 73 65 72 76 65 64 0a  s been observed.
a3e0: 20 20 20 20 23 20 77 68 65 72 65 2c 20 69 66 20      # where, if 
a3f0: 77 65 20 64 6f 6e 27 74 20 77 61 69 74 20 66 6f  we don't wait fo
a400: 72 20 53 41 56 45 2c 20 69 74 20 6d 69 67 68 74  r SAVE, it might
a410: 20 6e 6f 74 20 68 61 70 70 65 6e 2e 0a 20 20 20   not happen..   
a420: 20 61 6c 6c 6f 77 65 64 5f 63 6f 6d 6d 61 6e 64   allowed_command
a430: 73 20 3d 20 5b 22 4f 44 54 22 2c 20 22 52 22 2c  s = ["ODT", "R",
a440: 20 22 47 45 54 22 2c 20 22 47 45 22 2c 20 20 22   "GET", "GE",  "
a450: 53 41 56 45 22 2c 20 22 53 41 22 5d 0a 20 20 20  SAVE", "SA"].   
a460: 20 0a 20 20 20 20 69 6e 73 69 64 65 5f 61 5f 63   .    inside_a_c
a470: 6f 6d 6d 61 6e 64 20 3d 20 46 61 6c 73 65 0a 20  ommand = False. 
a480: 20 20 20 74 68 65 5f 63 6f 6d 6d 61 6e 64 20 3d     the_command =
a490: 20 22 22 0a 20 20 20 20 74 68 65 5f 63 6f 6d 6d   "".    the_comm
a4a0: 61 6e 64 5f 70 61 72 73 65 72 20 3d 20 4e 6f 6e  and_parser = Non
a4b0: 65 0a 20 20 20 20 0a 20 20 20 20 23 20 41 6e 79  e.    .    # Any
a4c0: 20 6f 73 38 2d 72 75 6e 20 63 6f 6d 6d 61 6e 64   os8-run command
a4d0: 20 6d 61 79 20 62 65 20 63 61 6c 6c 65 64 20 61   may be called a
a4e0: 66 74 65 72 20 61 20 73 69 6d 68 20 63 6f 6d 6d  fter a simh comm
a4f0: 61 6e 64 20 74 68 61 74 20 6c 65 66 74 20 75 73  and that left us
a500: 0a 20 20 20 20 23 20 69 6e 20 73 69 6d 68 20 63  .    # in simh c
a510: 6f 6e 74 65 78 74 2e 20 43 68 65 63 6b 20 74 6f  ontext. Check to
a520: 20 73 65 65 20 69 66 20 77 65 20 6e 65 65 64 20   see if we need 
a530: 74 6f 20 72 65 73 74 61 72 74 20 4f 53 2f 38 2e  to restart OS/8.
a540: 0a 20 20 20 20 23 20 57 65 20 72 65 73 75 6d 65  .    # We resume
a550: 20 4f 53 2f 38 2e 20 49 74 20 73 68 6f 75 6c 64   OS/8. It should
a560: 20 62 65 20 6e 6f 6e 2d 64 69 73 72 75 70 74 69   be non-disrupti
a570: 76 65 20 61 6e 64 20 77 6f 72 6b 20 77 65 6c 6c  ve and work well
a580: 2e 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 73 69  ..    if self.si
a590: 6d 68 2e 5f 63 6f 6e 74 65 78 74 20 3d 3d 20 22  mh._context == "
a5a0: 73 69 6d 68 22 3a 0a 20 20 20 20 20 20 73 65 6c  simh":.      sel
a5b0: 66 2e 72 65 73 75 6d 65 5f 63 6f 6d 6d 61 6e 64  f.resume_command
a5c0: 28 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f 66 69  (line, script_fi
a5d0: 6c 65 29 0a 0a 20 20 20 20 66 6f 72 20 6c 69 6e  le)..    for lin
a5e0: 65 20 69 6e 20 70 61 74 63 68 5f 66 69 6c 65 3a  e in patch_file:
a5f0: 0a 20 20 20 20 20 20 6c 69 6e 65 20 3d 20 6c 69  .      line = li
a600: 6e 65 2e 72 73 74 72 69 70 28 29 0a 20 20 20 20  ne.rstrip().    
a610: 20 20 69 66 20 6c 69 6e 65 20 3d 3d 20 22 22 3a    if line == "":
a620: 20 63 6f 6e 74 69 6e 75 65 0a 20 20 20 20 20 20   continue.      
a630: 65 6c 69 66 20 6c 69 6e 65 5b 30 5d 20 3d 3d 20  elif line[0] == 
a640: 27 23 27 3a 20 63 6f 6e 74 69 6e 75 65 20 20 20  '#': continue   
a650: 20 20 23 20 49 67 6e 6f 72 65 20 43 6f 6d 6d 65    # Ignore Comme
a660: 6e 74 73 0a 20 20 20 20 20 20 65 6c 69 66 20 69  nts.      elif i
a670: 6e 73 69 64 65 5f 61 5f 63 6f 6d 6d 61 6e 64 3a  nside_a_command:
a680: 0a 20 20 20 20 20 20 20 20 72 65 74 76 61 6c 20  .        retval 
a690: 3d 20 74 68 65 5f 63 6f 6d 6d 61 6e 64 5f 70 61  = the_command_pa
a6a0: 72 73 65 72 20 28 6c 69 6e 65 29 0a 20 20 20 20  rser (line).    
a6b0: 20 20 20 20 69 66 20 72 65 74 76 61 6c 20 3d 3d      if retval ==
a6c0: 20 22 62 72 65 61 6b 22 3a 0a 20 20 20 20 20 20   "break":.      
a6d0: 20 20 20 20 69 6e 73 69 64 65 5f 61 5f 63 6f 6d      inside_a_com
a6e0: 6d 61 6e 64 20 3d 20 46 61 6c 73 65 0a 20 20 20  mand = False.   
a6f0: 20 20 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68         self.simh
a700: 2e 6f 73 38 5f 63 74 72 6c 5f 63 20 28 63 61 6c  .os8_ctrl_c (cal
a710: 6c 65 72 3d 22 72 75 6e 5f 70 61 74 63 68 5f 66  ler="run_patch_f
a720: 69 6c 65 22 29 0a 20 20 20 20 20 20 20 20 65 6c  ile").        el
a730: 69 66 20 72 65 74 76 61 6c 20 3d 3d 20 22 65 72  if retval == "er
a740: 72 22 3a 0a 20 20 20 20 20 20 20 20 20 20 70 61  r":.          pa
a750: 74 63 68 5f 66 69 6c 65 2e 63 6c 6f 73 65 28 29  tch_file.close()
a760: 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72  .          retur
a770: 6e 20 22 66 61 69 6c 22 0a 20 20 20 20 20 20 65  n "fail".      e
a780: 6c 69 66 20 6c 69 6e 65 5b 30 5d 20 3d 3d 20 27  lif line[0] == '
a790: 2e 27 3a 20 20 20 20 20 20 20 20 23 20 4e 65 77  .':        # New
a7a0: 20 4f 53 2f 38 20 43 6f 6d 6d 61 6e 64 0a 20 20   OS/8 Command.  
a7b0: 20 20 20 20 20 20 6d 61 74 63 68 20 3d 20 5f 63        match = _c
a7c0: 6f 6d 5f 6f 73 38 5f 70 61 72 73 65 2e 6d 61 74  om_os8_parse.mat
a7d0: 63 68 28 6c 69 6e 65 29 0a 20 20 20 20 20 20 20  ch(line).       
a7e0: 20 69 66 20 6d 61 74 63 68 20 3d 3d 20 4e 6f 6e   if match == Non
a7f0: 65 3a 0a 20 20 20 20 20 20 20 20 20 20 70 72 69  e:.          pri
a800: 6e 74 28 22 41 62 6f 72 74 69 6e 67 20 70 61 74  nt("Aborting pat
a810: 63 68 20 6f 6e 20 66 61 69 6c 65 64 20 4f 53 2f  ch on failed OS/
a820: 38 20 63 6f 6d 6d 61 6e 64 20 70 61 72 73 65 20  8 command parse 
a830: 6f 66 3a 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20  of: " + line).  
a840: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 22          return "
a850: 66 61 69 6c 22 0a 20 20 20 20 20 20 20 20 63 6f  fail".        co
a860: 6d 20 3d 20 6d 61 74 63 68 2e 67 72 6f 75 70 28  m = match.group(
a870: 31 29 0a 20 20 20 20 20 20 20 20 72 65 73 74 20  1).        rest 
a880: 3d 20 6d 61 74 63 68 2e 67 72 6f 75 70 28 32 29  = match.group(2)
a890: 0a 20 20 0a 20 20 20 20 20 20 20 20 69 66 20 63  .  .        if c
a8a0: 6f 6d 20 6e 6f 74 20 69 6e 20 61 6c 6c 6f 77 65  om not in allowe
a8b0: 64 5f 63 6f 6d 6d 61 6e 64 73 3a 0a 20 20 20 20  d_commands:.    
a8c0: 20 20 20 20 20 20 70 72 69 6e 74 20 28 22 43 6f        print ("Co
a8d0: 6d 6d 61 6e 64 20 22 20 2b 20 63 6f 6d 20 2b 20  mmand " + com + 
a8e0: 22 20 6e 6f 74 20 61 6c 6c 6f 77 65 64 20 69 6e  " not allowed in
a8f0: 20 70 61 74 63 68 2e 20 49 67 6e 6f 72 69 6e 67   patch. Ignoring
a900: 2e 22 29 0a 20 20 20 20 20 20 20 20 20 20 63 6f  .").          co
a910: 6e 74 69 6e 75 65 0a 20 20 20 20 20 20 20 20 23  ntinue.        #
a920: 20 46 61 6c 6c 20 74 68 72 6f 75 67 68 20 74 6f   Fall through to
a930: 20 73 74 61 72 74 20 75 70 20 6f 75 72 20 63 6f   start up our co
a940: 6d 6d 61 6e 64 2e 0a 20 20 20 20 20 20 20 20 23  mmand..        #
a950: 20 4d 61 79 62 65 20 63 6f 6d 6d 61 6e 64 20 69   Maybe command i
a960: 73 20 22 2e 4f 44 54 22 2c 20 6d 61 79 62 65 20  s ".ODT", maybe 
a970: 69 74 27 73 20 22 52 20 46 55 54 49 4c 22 0a 20  it's "R FUTIL". 
a980: 20 20 20 20 20 20 20 69 66 20 63 6f 6d 20 3d 3d         if com ==
a990: 20 22 52 22 3a 0a 20 20 20 20 20 20 20 20 20 20   "R":.          
a9a0: 23 20 43 68 65 63 6b 20 74 6f 20 73 65 65 20 69  # Check to see i
a9b0: 66 20 77 65 20 63 61 6e 20 72 75 6e 20 74 68 69  f we can run thi
a9c0: 73 2e 0a 20 20 20 20 20 20 20 20 20 20 69 66 20  s..          if 
a9d0: 72 65 73 74 20 6e 6f 74 20 69 6e 20 70 61 72 73  rest not in pars
a9e0: 65 72 73 3a 0a 20 20 20 20 20 20 20 20 20 20 20  ers:.           
a9f0: 20 70 72 69 6e 74 20 28 22 4e 6f 74 20 61 6c 6c   print ("Not all
aa00: 6f 77 65 64 20 74 6f 20 72 75 6e 20 22 20 2b 20  owed to run " + 
aa10: 72 65 73 74 20 2b 20 22 20 69 6e 20 61 20 70 61  rest + " in a pa
aa20: 74 63 68 20 66 69 6c 65 2e 20 20 41 62 6f 72 74  tch file.  Abort
aa30: 69 6e 67 2e 22 29 0a 20 20 20 20 20 20 20 20 20  ing.").         
aa40: 20 20 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22     return "fail"
aa50: 0a 20 20 20 20 20 20 20 20 20 20 63 6f 6d 20 3d  .          com =
aa60: 20 72 65 73 74 20 20 20 20 20 23 20 4e 6f 77 20   rest     # Now 
aa70: 66 61 6c 6c 20 74 68 72 6f 75 67 68 20 61 6e 20  fall through an 
aa80: 73 65 74 20 74 68 65 5f 63 6f 6d 6d 61 6e 64 0a  set the_command.
aa90: 20 20 20 20 20 20 20 20 74 68 65 5f 63 6f 6d 6d          the_comm
aaa0: 61 6e 64 20 3d 20 63 6f 6d 0a 20 20 20 20 20 20  and = com.      
aab0: 20 20 0a 20 20 20 20 20 20 20 20 23 20 4e 6f 69    .        # Noi
aac0: 73 79 20 64 65 62 75 67 20 6f 75 74 70 75 74 2e  sy debug output.
aad0: 20 4f 75 72 20 6c 69 6e 65 2e 0a 20 20 20 20 20   Our line..     
aae0: 20 20 20 69 66 20 73 65 6c 66 2e 76 65 72 62 6f     if self.verbo
aaf0: 73 65 20 61 6e 64 20 73 65 6c 66 2e 64 65 62 75  se and self.debu
ab00: 67 3a 20 70 72 69 6e 74 28 6c 69 6e 65 29 0a 0a  g: print(line)..
ab10: 20 20 20 20 20 20 20 20 23 20 41 72 65 20 77 65          # Are we
ab20: 20 67 6f 69 6e 67 20 74 6f 20 62 65 20 69 6e 73   going to be ins
ab30: 69 64 65 20 61 20 63 6f 6d 6d 61 6e 64 20 61 66  ide a command af
ab40: 74 65 72 20 77 65 20 64 6f 20 74 68 65 20 72 75  ter we do the ru
ab50: 6e 3f 0a 20 20 20 20 20 20 20 20 69 66 20 63 6f  n?.        if co
ab60: 6d 20 69 6e 20 70 61 72 73 65 72 73 3a 0a 20 20  m in parsers:.  
ab70: 20 20 20 20 20 20 20 20 74 68 65 5f 63 6f 6d 6d          the_comm
ab80: 61 6e 64 5f 70 61 72 73 65 72 20 3d 20 70 61 72  and_parser = par
ab90: 73 65 72 73 5b 63 6f 6d 5d 0a 20 20 20 20 20 20  sers[com].      
aba0: 20 20 20 20 69 6e 73 69 64 65 5f 61 5f 63 6f 6d      inside_a_com
abb0: 6d 61 6e 64 20 3d 20 54 72 75 65 0a 20 20 20 20  mand = True.    
abc0: 20 20 20 20 20 20 23 20 52 75 6e 20 74 68 65 20        # Run the 
abd0: 6c 69 6e 65 20 62 6c 69 6e 64 2c 20 73 6b 69 70  line blind, skip
abe0: 70 69 6e 67 20 6f 76 65 72 20 74 68 65 20 64 6f  ping over the do
abf0: 74 20 61 74 20 74 68 65 20 62 65 67 69 6e 6e 69  t at the beginni
ac00: 6e 67 2e 0a 20 20 20 20 20 20 20 20 20 20 23 20  ng..          # 
ac10: 57 65 20 77 6f 6e 27 74 20 67 65 74 20 61 20 70  We won't get a p
ac20: 72 6f 6d 70 74 2e 0a 20 20 20 20 20 20 20 20 20  rompt..         
ac30: 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 73   self.simh.os8_s
ac40: 65 6e 64 5f 6c 69 6e 65 20 28 6c 69 6e 65 5b 31  end_line (line[1
ac50: 3a 5d 29 0a 20 20 20 20 20 20 20 20 23 20 49 74  :]).        # It
ac60: 27 73 20 61 6e 20 4f 53 2f 38 20 63 6f 6d 6d 61  's an OS/8 comma
ac70: 6e 64 0a 20 20 20 20 20 20 20 20 65 6c 73 65 3a  nd.        else:
ac80: 0a 20 20 20 20 20 20 20 20 20 20 23 20 57 65 20  .          # We 
ac90: 6d 75 73 74 20 74 65 73 74 20 66 6f 72 20 6d 6f  must test for mo
aca0: 6e 69 74 6f 72 20 70 72 6f 6d 70 74 20 74 6f 20  nitor prompt to 
acb0: 73 69 67 6e 69 66 79 20 73 75 63 63 65 73 73 2e  signify success.
acc0: 0a 20 20 20 20 20 20 20 20 20 20 23 20 4f 74 68  .          # Oth
acd0: 65 72 77 69 73 65 20 61 20 72 61 63 65 20 63 6f  erwise a race co
ace0: 6e 64 69 74 69 6f 6e 20 68 61 73 20 62 65 65 6e  ndition has been
acf0: 20 73 68 6f 77 6e 20 74 6f 20 70 72 65 76 65 6e   shown to preven
ad00: 74 20 73 61 76 65 20 6f 66 0a 20 20 20 20 20 20  t save of.      
ad10: 20 20 20 20 23 20 70 61 74 63 68 65 64 20 62 69      # patched bi
ad20: 6e 61 72 79 20 62 65 63 61 75 73 65 20 6f 75 72  nary because our
ad30: 20 65 78 69 74 20 6f 66 20 53 49 4d 48 20 68 61   exit of SIMH ha
ad40: 70 70 65 6e 73 20 74 6f 6f 20 71 75 69 63 6b 6c  ppens too quickl
ad50: 79 21 0a 20 20 20 20 20 20 20 20 20 20 72 65 70  y!.          rep
ad60: 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 6f  ly = self.simh.o
ad70: 73 38 5f 63 6d 64 20 28 6c 69 6e 65 5b 31 3a 5d  s8_cmd (line[1:]
ad80: 29 20 20 23 20 53 6b 69 70 20 6f 76 65 72 20 50  )  # Skip over P
ad90: 72 6f 6d 70 74 20 69 6e 20 6c 69 6e 65 2e 0a 20  rompt in line.. 
ada0: 20 20 20 20 20 20 20 20 20 23 20 57 65 20 6e 65           # We ne
adb0: 65 64 20 74 6f 20 63 6f 6e 66 69 72 6d 20 77 65  ed to confirm we
adc0: 20 73 75 63 63 65 65 64 65 64 2e 0a 20 20 20 20   succeeded..    
add0: 20 20 20 20 20 20 23 20 49 66 20 77 65 20 66 61        # If we fa
ade0: 69 6c 2c 20 77 65 20 6a 75 73 74 20 63 6f 6d 70  il, we just comp
adf0: 6c 61 69 6e 20 61 6e 64 20 6b 65 65 70 20 67 6f  lain and keep go
ae00: 69 6e 67 2e 0a 20 20 20 20 20 20 20 20 20 20 73  ing..          s
ae10: 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 74 65 73  elf.simh.os8_tes
ae20: 74 5f 72 65 73 75 6c 74 20 28 72 65 70 6c 79 2c  t_result (reply,
ae30: 20 22 4d 6f 6e 69 74 6f 72 20 50 72 6f 6d 70 74   "Monitor Prompt
ae40: 22 2c 20 22 72 75 6e 5f 70 61 74 63 68 5f 66 69  ", "run_patch_fi
ae50: 6c 65 20 63 6f 6d 6d 61 6e 64 20 22 20 5c 0a 20  le command " \. 
ae60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
ae70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
ae80: 20 20 20 20 20 2b 20 6c 69 6e 65 5b 31 3a 5d 29       + line[1:])
ae90: 0a 20 20 20 20 23 20 44 6f 6e 65 20 77 69 74 68  .    # Done with
aea0: 20 61 6c 6c 20 70 61 74 63 68 20 66 69 6c 65 20   all patch file 
aeb0: 6c 69 6e 65 73 2e 0a 20 20 20 20 70 61 74 63 68  lines..    patch
aec0: 5f 66 69 6c 65 2e 63 6c 6f 73 65 28 29 0a 20 20  _file.close().  
aed0: 0a 20 20 20 20 70 72 69 6e 74 28 22 53 75 63 63  .    print("Succ
aee0: 65 73 73 2e 22 29 0a 20 20 20 20 72 65 74 75 72  ess.").    retur
aef0: 6e 20 22 73 75 63 63 65 73 73 22 0a 0a 0a 20 20  n "success"...  
af00: 23 23 23 23 20 73 6b 69 70 5f 70 61 74 63 68 20  #### skip_patch 
af10: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
af20: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
af30: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
af40: 23 23 23 23 23 23 0a 20 20 23 20 52 65 74 75 72  ######.  # Retur
af50: 6e 73 20 74 72 75 65 20 69 66 20 74 68 65 20 67  ns true if the g
af60: 69 76 65 6e 20 66 69 6c 65 6e 61 6d 65 20 6d 61  iven filename ma
af70: 74 63 68 65 73 20 6f 6e 65 20 6f 66 20 74 68 65  tches one of the
af80: 20 72 65 67 65 78 20 73 74 72 69 6e 67 0a 20 20   regex string.  
af90: 23 20 6b 65 79 73 20 6f 66 20 74 68 65 20 67 69  # keys of the gi
afa0: 76 65 6e 20 73 6b 69 70 73 20 64 69 63 74 20 61  ven skips dict a
afb0: 6e 64 20 74 68 65 20 66 6c 61 67 20 76 61 6c 75  nd the flag valu
afc0: 65 20 66 6f 72 20 74 68 61 74 20 6b 65 79 20 69  e for that key i
afd0: 73 20 73 65 74 2e 0a 20 20 23 20 53 65 65 20 73  s set..  # See s
afe0: 6b 69 70 73 20 64 65 66 69 6e 69 74 69 6f 6e 20  kips definition 
aff0: 69 6e 20 6d 61 6b 65 5f 70 61 74 63 68 2c 20 77  in make_patch, w
b000: 68 69 63 68 20 63 61 6c 6c 73 20 74 68 69 73 2e  hich calls this.
b010: 0a 20 20 0a 20 20 64 65 66 20 73 6b 69 70 5f 70  .  .  def skip_p
b020: 61 74 63 68 20 28 66 6e 2c 20 73 6b 69 70 73 29  atch (fn, skips)
b030: 3a 0a 20 20 20 20 20 20 66 6f 72 20 70 20 69 6e  :.      for p in
b040: 20 73 6b 69 70 73 3a 0a 20 20 20 20 20 20 20 20   skips:.        
b050: 20 20 69 66 20 72 65 2e 73 65 61 72 63 68 20 28    if re.search (
b060: 70 2c 20 66 6e 29 20 61 6e 64 20 73 6b 69 70 73  p, fn) and skips
b070: 5b 70 5d 3a 20 72 65 74 75 72 6e 20 54 72 75 65  [p]: return True
b080: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 46 61  .      return Fa
b090: 6c 73 65 0a 20 20 0a 0a 20 20 23 23 23 23 20 73  lse.  ..  #### s
b0a0: 69 6d 68 5f 63 6f 6d 6d 61 6e 64 20 23 23 23 23  imh_command ####
b0b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
b0c0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
b0d0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
b0e0: 0a 20 20 23 20 49 20 74 72 69 65 64 20 74 6f 20  .  # I tried to 
b0f0: 61 76 6f 69 64 20 69 6e 63 6c 75 64 69 6e 67 20  avoid including 
b100: 74 68 69 73 20 63 6f 6d 6d 61 6e 64 20 62 75 74  this command but
b110: 20 73 6f 6d 65 74 69 6d 65 73 20 79 6f 75 20 6a   sometimes you j
b120: 75 73 74 0a 20 20 23 20 68 61 76 65 20 74 6f 20  ust.  # have to 
b130: 72 65 63 6f 6e 66 69 67 75 72 65 20 73 75 62 74  reconfigure subt
b140: 6c 65 20 62 69 74 73 20 6f 66 20 64 65 76 69 63  le bits of devic
b150: 65 20 64 72 69 76 65 72 73 2e 0a 20 20 23 20 57  e drivers..  # W
b160: 65 20 61 73 73 75 6d 65 20 77 65 20 63 61 6e 20  e assume we can 
b170: 63 61 6c 6c 20 61 20 73 69 6d 68 20 63 6f 6d 6d  call a simh comm
b180: 61 6e 64 20 61 74 20 61 6e 79 20 74 69 6d 65 2c  and at any time,
b190: 20 62 75 74 0a 20 20 23 20 64 6f 69 6e 67 20 73   but.  # doing s
b1a0: 6f 20 70 75 74 73 20 75 73 20 69 6e 20 74 68 65  o puts us in the
b1b0: 20 73 69 6d 68 20 63 6f 6e 74 65 78 74 20 74 68   simh context th
b1c0: 61 74 20 70 65 72 73 69 73 74 73 20 75 6e 74 69  at persists unti
b1d0: 6c 20 77 65 0a 20 20 23 20 69 73 73 75 65 20 61  l we.  # issue a
b1e0: 20 62 6f 6f 74 20 6f 72 20 67 6f 20 63 6f 6d 6d   boot or go comm
b1f0: 61 6e 64 2e 0a 20 20 0a 20 20 64 65 66 20 73 69  and..  .  def si
b200: 6d 68 5f 63 6f 6d 6d 61 6e 64 20 28 73 65 6c 66  mh_command (self
b210: 2c 20 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f 66  , line, script_f
b220: 69 6c 65 29 3a 0a 20 20 20 20 70 72 69 6e 74 28  ile):.    print(
b230: 22 73 69 6d 68 20 63 6f 6d 6d 61 6e 64 20 69 73  "simh command is
b240: 20 64 69 73 61 62 6c 65 64 2e 20 4c 69 6e 65 20   disabled. Line 
b250: 22 20 2b 20 5c 0a 20 20 20 20 20 20 73 74 72 28  " + \.      str(
b260: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
b270: 63 6b 5b 30 5d 29 20 2b 20 22 20 69 67 6e 6f 72  ck[0]) + " ignor
b280: 65 64 2e 22 29 0a 20 20 20 20 72 65 74 75 72 6e  ed.").    return
b290: 20 22 66 61 69 6c 22 0a 20 20 20 20 69 66 20 73   "fail".    if s
b2a0: 65 6c 66 2e 76 65 72 62 6f 73 65 3a 20 70 72 69  elf.verbose: pri
b2b0: 6e 74 28 6c 69 6e 65 29 0a 20 20 20 20 72 65 70  nt(line).    rep
b2c0: 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 73  ly = self.simh.s
b2d0: 69 6d 68 5f 63 6d 64 28 6c 69 6e 65 29 0a 20 20  imh_cmd(line).  
b2e0: 20 20 73 65 6c 66 2e 73 69 6d 68 2e 73 69 6d 68    self.simh.simh
b2f0: 5f 74 65 73 74 5f 72 65 73 75 6c 74 28 72 65 70  _test_result(rep
b300: 6c 79 2c 20 22 50 72 6f 6d 70 74 22 2c 20 22 73  ly, "Prompt", "s
b310: 69 6d 68 5f 63 6f 6d 6d 61 6e 64 22 29 0a 20 20  imh_command").  
b320: 20 20 72 65 74 75 72 6e 20 22 73 75 63 63 65 73    return "succes
b330: 73 22 0a 0a 0a 20 20 23 23 23 23 20 75 6d 6f 75  s"...  #### umou
b340: 6e 74 5f 63 6f 6d 6d 61 6e 64 20 23 23 23 23 23  nt_command #####
b350: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
b360: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
b370: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20 20  #############.  
b380: 64 65 66 20 75 6d 6f 75 6e 74 5f 63 6f 6d 6d 61  def umount_comma
b390: 6e 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65 2c 20  nd (self, line, 
b3a0: 73 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a 20 20  script_file):.  
b3b0: 20 20 64 65 74 61 63 68 5f 63 6f 6d 6d 20 3d 20    detach_comm = 
b3c0: 22 64 65 74 20 22 20 2b 20 6c 69 6e 65 0a 20 20  "det " + line.  
b3d0: 20 20 69 66 20 73 65 6c 66 2e 76 65 72 62 6f 73    if self.verbos
b3e0: 65 3a 20 70 72 69 6e 74 28 22 6c 69 6e 65 3a 20  e: print("line: 
b3f0: 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 73 74  " + \.        st
b400: 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73  r(self.line_ct_s
b410: 74 61 63 6b 5b 30 5d 29 20 2b 20 22 3a 20 22 20  tack[0]) + ": " 
b420: 2b 20 64 65 74 61 63 68 5f 63 6f 6d 6d 29 0a 20  + detach_comm). 
b430: 20 20 20 72 65 70 6c 79 20 3d 20 73 65 6c 66 2e     reply = self.
b440: 73 69 6d 68 2e 73 69 6d 68 5f 63 6d 64 28 64 65  simh.simh_cmd(de
b450: 74 61 63 68 5f 63 6f 6d 6d 2c 20 64 65 62 75 67  tach_comm, debug
b460: 3d 73 65 6c 66 2e 64 65 62 75 67 29 0a 20 20 20  =self.debug).   
b470: 20 73 65 6c 66 2e 73 69 6d 68 2e 73 69 6d 68 5f   self.simh.simh_
b480: 74 65 73 74 5f 72 65 73 75 6c 74 28 72 65 70 6c  test_result(repl
b490: 79 2c 20 22 50 72 6f 6d 70 74 22 2c 20 22 75 6d  y, "Prompt", "um
b4a0: 6f 75 6e 74 5f 63 6f 6d 6d 61 6e 64 22 29 0a 20  ount_command"). 
b4b0: 20 20 20 72 65 74 75 72 6e 20 22 73 75 63 63 65     return "succe
b4c0: 73 73 22 0a 0a 0a 20 20 23 23 23 23 20 6d 61 6b  ss"...  #### mak
b4d0: 65 5f 73 63 72 61 74 63 68 20 23 23 23 23 23 23  e_scratch ######
b4e0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
b4f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
b500: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20  ##############. 
b510: 20 23 20 43 72 65 61 74 65 20 61 20 63 6f 70 79   # Create a copy
b520: 20 6f 66 20 74 68 65 20 63 6f 6e 74 65 6e 74 73   of the contents
b530: 20 6f 66 20 69 6d 61 67 65 20 66 69 6c 65 20 75   of image file u
b540: 73 69 6e 67 20 74 68 65 20 70 79 74 68 6f 6e 0a  sing the python.
b550: 20 20 23 20 6d 65 74 68 6f 64 20 74 6f 20 63 72    # method to cr
b560: 65 61 74 65 20 61 20 73 65 63 75 72 65 2c 20 6e  eate a secure, n
b570: 61 6d 65 64 20 74 65 6d 70 20 66 69 6c 65 6e 61  amed temp filena
b580: 6d 65 2e 0a 20 20 23 20 54 68 65 20 63 61 6c 6c  me..  # The call
b590: 65 72 20 68 61 73 20 73 70 6c 69 74 20 74 68 65  er has split the
b5a0: 20 69 6d 61 67 65 20 66 69 6c 65 20 6e 61 6d 65   image file name
b5b0: 20 69 6e 74 6f 20 61 20 62 61 73 65 20 70 61 74   into a base pat
b5c0: 68 2c 0a 20 20 23 20 61 6e 64 20 61 6e 20 65 78  h,.  # and an ex
b5d0: 74 65 6e 73 69 6f 6e 20 77 68 69 63 68 20 77 65  tension which we
b5e0: 20 75 73 65 2e 0a 20 20 23 20 41 66 74 65 72 20   use..  # After 
b5f0: 63 6f 70 79 69 6e 67 20 74 68 65 20 73 6f 75 72  copying the sour
b600: 63 65 20 69 6d 61 67 65 2c 20 74 68 65 20 66 69  ce image, the fi
b610: 6c 65 20 69 73 20 63 6c 6f 73 65 64 20 61 6e 64  le is closed and
b620: 20 74 68 65 20 6e 61 6d 65 0a 20 20 23 20 6f 66   the name.  # of
b630: 20 74 68 65 20 73 63 72 61 74 63 68 20 66 69 6c   the scratch fil
b640: 65 20 69 73 20 72 65 74 75 72 6e 65 64 2e 0a 20  e is returned.. 
b650: 20 64 65 66 20 6d 61 6b 65 5f 73 63 72 61 74 63   def make_scratc
b660: 68 20 28 73 65 6c 66 2c 20 62 61 73 65 5f 69 6d  h (self, base_im
b670: 61 67 65 6e 61 6d 65 2c 20 65 78 74 65 6e 73 69  agename, extensi
b680: 6f 6e 29 3a 0a 20 20 20 20 74 72 79 3a 0a 20 20  on):.    try:.  
b690: 20 20 20 20 73 72 63 5f 69 6d 61 67 65 20 3d 20      src_image = 
b6a0: 6f 70 65 6e 28 62 61 73 65 5f 69 6d 61 67 65 6e  open(base_imagen
b6b0: 61 6d 65 2b 65 78 74 65 6e 73 69 6f 6e 2c 20 22  ame+extension, "
b6c0: 72 62 22 29 0a 20 20 20 20 65 78 63 65 70 74 20  rb").    except 
b6d0: 49 4f 45 72 72 6f 72 3a 0a 20 20 20 20 20 20 70  IOError:.      p
b6e0: 72 69 6e 74 28 22 4f 70 65 6e 20 6f 66 20 69 6d  rint("Open of im
b6f0: 61 67 65 66 69 6c 65 20 22 20 2b 20 62 61 73 65  agefile " + base
b700: 5f 69 6d 61 67 65 6e 61 6d 65 20 2b 20 65 78 74  _imagename + ext
b710: 65 6e 73 69 6f 6e 20 2b 20 22 20 66 61 69 6c 65  ension + " faile
b720: 64 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72  d.").      retur
b730: 6e 20 4e 6f 6e 65 0a 20 20 20 20 20 20 0a 20 20  n None.      .  
b740: 20 20 64 65 73 74 5f 69 6d 61 67 65 20 3d 20 74    dest_image = t
b750: 65 6d 70 66 69 6c 65 2e 4e 61 6d 65 64 54 65 6d  empfile.NamedTem
b760: 70 6f 72 61 72 79 46 69 6c 65 28 6d 6f 64 65 3d  poraryFile(mode=
b770: 27 77 2b 62 27 2c 20 5c 0a 20 20 20 20 20 20 20  'w+b', \.       
b780: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
b790: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
b7a0: 20 20 20 20 20 20 70 72 65 66 69 78 3d 62 61 73        prefix=bas
b7b0: 65 5f 69 6d 61 67 65 6e 61 6d 65 2b 27 2d 74 65  e_imagename+'-te
b7c0: 6d 70 2d 27 2c 20 5c 0a 20 20 20 20 20 20 20 20  mp-', \.        
b7d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
b7e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
b7f0: 20 20 20 20 20 73 75 66 66 69 78 3d 65 78 74 65       suffix=exte
b800: 6e 73 69 6f 6e 2c 20 5c 0a 20 20 20 20 20 20 20  nsion, \.       
b810: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
b820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
b830: 20 20 20 20 20 20 64 65 6c 65 74 65 3d 46 61 6c        delete=Fal
b840: 73 65 29 0a 20 20 20 20 64 65 73 74 6e 61 6d 65  se).    destname
b850: 20 3d 20 64 65 73 74 5f 69 6d 61 67 65 2e 6e 61   = dest_image.na
b860: 6d 65 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 64  me.    if self.d
b870: 65 62 75 67 3a 20 70 72 69 6e 74 28 22 54 65 6d  ebug: print("Tem
b880: 70 20 66 69 6c 65 20 6e 61 6d 65 20 69 73 3a 20  p file name is: 
b890: 22 20 2b 20 64 65 73 74 6e 61 6d 65 29 0a 0a 20  " + destname).. 
b8a0: 20 20 20 74 72 79 3a 0a 20 20 20 20 20 20 73 68     try:.      sh
b8b0: 75 74 69 6c 2e 63 6f 70 79 66 69 6c 65 6f 62 6a  util.copyfileobj
b8c0: 28 73 72 63 5f 69 6d 61 67 65 2c 20 64 65 73 74  (src_image, dest
b8d0: 5f 69 6d 61 67 65 29 0a 20 20 20 20 65 78 63 65  _image).    exce
b8e0: 70 74 20 73 68 75 74 69 6c 2e 45 72 72 6f 72 20  pt shutil.Error 
b8f0: 61 73 20 65 3a 0a 20 20 20 20 20 20 70 72 69 6e  as e:.      prin
b900: 74 28 22 43 6f 70 79 20 6f 66 20 69 6d 61 67 65  t("Copy of image
b910: 66 69 6c 65 20 22 20 2b 20 62 61 73 65 5f 69 6d  file " + base_im
b920: 61 67 65 6e 61 6d 65 20 2b 20 65 78 74 65 6e 73  agename + extens
b930: 69 6f 6e 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  ion + \.        
b940: 22 20 74 6f 20 73 63 72 61 74 63 68 20 66 61 69  " to scratch fai
b950: 6c 65 64 20 77 69 74 68 20 65 72 72 6f 72 3a 20  led with error: 
b960: 22 20 2b 20 73 74 72 28 65 29 29 0a 20 20 20 20  " + str(e)).    
b970: 20 20 72 65 74 75 72 6e 20 4e 6f 6e 65 0a 20 20    return None.  
b980: 20 20 65 78 63 65 70 74 20 49 4f 45 72 72 6f 72    except IOError
b990: 20 61 73 20 65 3a 0a 20 20 20 20 20 20 70 72 69   as e:.      pri
b9a0: 6e 74 28 22 43 6f 70 79 20 6f 66 20 69 6d 61 67  nt("Copy of imag
b9b0: 65 66 69 6c 65 20 22 20 2b 20 62 61 73 65 5f 69  efile " + base_i
b9c0: 6d 61 67 65 6e 61 6d 65 20 2b 20 65 78 74 65 6e  magename + exten
b9d0: 73 69 6f 6e 20 2b 20 5c 0a 20 20 20 20 20 20 20  sion + \.       
b9e0: 20 20 20 22 2c 20 66 61 69 6c 65 64 20 77 69 74     ", failed wit
b9f0: 68 20 49 4f 45 72 72 6f 72 3a 20 22 20 2b 20 73  h IOError: " + s
ba00: 74 72 28 65 29 29 0a 20 20 20 20 20 20 72 65 74  tr(e)).      ret
ba10: 75 72 6e 20 4e 6f 6e 65 0a 20 20 20 20 73 72 63  urn None.    src
ba20: 5f 69 6d 61 67 65 2e 63 6c 6f 73 65 28 29 0a 20  _image.close(). 
ba30: 20 20 20 64 65 73 74 5f 69 6d 61 67 65 2e 63 6c     dest_image.cl
ba40: 6f 73 65 28 29 0a 20 20 20 20 73 65 6c 66 2e 73  ose().    self.s
ba50: 63 72 61 74 63 68 5f 6c 69 73 74 2e 61 70 70 65  cratch_list.appe
ba60: 6e 64 28 64 65 73 74 6e 61 6d 65 29 0a 20 20 20  nd(destname).   
ba70: 20 72 65 74 75 72 6e 20 64 65 73 74 6e 61 6d 65   return destname
ba80: 0a 20 20 20 20 0a 0a 20 20 23 23 23 23 20 6d 6f  .    ..  #### mo
ba90: 75 6e 74 5f 63 6f 6d 6d 61 6e 64 20 23 23 23 23  unt_command ####
baa0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
bab0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
bac0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 0a  ###############.
bad0: 20 20 23 20 6d 6f 75 6e 74 20 3c 73 69 6d 68 2d    # mount <simh-
bae0: 64 65 76 69 63 65 3e 20 3c 69 6d 61 67 65 2d 66  device> <image-f
baf0: 69 6c 65 3e 20 5b 6f 70 74 69 6f 6e 20 2e 2e 2e  ile> [option ...
bb00: 5d 0a 20 20 23 0a 20 20 23 20 49 6e 74 65 72 66  ].  #.  # Interf
bb10: 61 63 65 20 74 6f 20 53 49 4d 48 20 61 74 74 61  ace to SIMH atta
bb20: 63 68 20 63 6f 6d 6d 61 6e 64 20 77 69 74 68 20  ch command with 
bb30: 6f 70 74 69 6f 6e 73 20 74 68 61 74 20 64 6f 20  options that do 
bb40: 61 20 62 69 74 20 6d 6f 72 65 2e 0a 20 20 23 0a  a bit more..  #.
bb50: 20 20 23 20 4f 70 74 69 6f 6e 73 3a 0a 20 20 23    # Options:.  #
bb60: 20 72 65 71 75 69 72 65 64 3a 20 3c 69 6d 61 67   required: <imag
bb70: 65 2d 66 69 6c 65 3e 20 69 73 20 72 65 71 75 69  e-file> is requi
bb80: 72 65 64 20 74 6f 20 65 78 69 73 74 2c 20 6f 74  red to exist, ot
bb90: 68 65 72 77 69 73 65 20 61 62 6f 72 74 20 74 68  herwise abort th
bba0: 65 20 73 63 72 69 70 74 2e 0a 20 20 23 20 70 72  e script..  # pr
bbb0: 65 73 65 72 76 65 20 69 66 20 3c 69 6d 61 67 65  eserve if <image
bbc0: 2d 66 69 6c 65 3e 20 61 6c 72 65 61 64 79 20 65  -file> already e
bbd0: 78 69 73 74 73 2c 20 63 72 65 61 74 65 20 61 20  xists, create a 
bbe0: 63 6f 70 79 20 77 69 74 68 20 61 0a 20 20 23 20  copy with a.  # 
bbf0: 20 20 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65     version numbe
bc00: 72 20 73 75 66 66 69 78 2e 20 54 68 69 73 20 69  r suffix. This i
bc10: 73 20 75 73 65 66 75 6c 20 77 68 65 6e 20 79 6f  s useful when yo
bc20: 75 20 77 61 6e 74 20 74 6f 20 70 72 65 76 65 6e  u want to preven
bc30: 74 0a 20 20 23 20 20 20 20 6f 76 65 72 77 72 69  t.  #    overwri
bc40: 74 65 73 20 6f 66 20 61 20 67 6f 6f 64 20 69 6d  tes of a good im
bc50: 61 67 65 20 66 69 6c 65 20 77 69 74 68 20 63 68  age file with ch
bc60: 61 6e 67 65 73 20 74 68 61 74 20 6d 69 67 68 74  anges that might
bc70: 20 6e 6f 74 20 77 6f 72 6b 2e 0a 20 20 23 20 20   not work..  #  
bc80: 20 20 6f 73 38 2d 72 75 6e 20 70 72 65 73 65 72    os8-run preser
bc90: 76 65 73 20 61 6c 6c 20 76 65 72 73 69 6f 6e 73  ves all versions
bca0: 20 73 65 65 6e 20 61 6e 64 20 63 72 65 61 74 65   seen and create
bcb0: 73 20 61 20 6e 65 77 0a 20 20 23 20 20 20 20 76  s a new.  #    v
bcc0: 65 72 73 69 6f 6e 20 74 68 61 74 20 64 6f 65 73  ersion that does
bcd0: 6e 27 74 20 6f 76 65 72 77 72 69 74 65 20 61 6e  n't overwrite an
bce0: 79 20 6f 66 20 74 68 65 20 70 72 65 76 69 6f 75  y of the previou
bcf0: 73 20 6f 6e 65 73 2e 0a 20 20 23 20 72 65 61 64  s ones..  # read
bd00: 6f 6e 6c 79 3a 20 20 50 61 73 73 65 73 20 74 68  only:  Passes th
bd10: 65 20 60 2d 72 60 20 6f 70 74 69 6f 6e 20 74 6f  e `-r` option to
bd20: 20 53 49 4d 48 20 61 74 74 61 63 68 20 74 6f 20   SIMH attach to 
bd30: 6d 6f 75 6e 74 20 74 68 65 0a 20 20 23 20 20 20  mount the.  #   
bd40: 20 64 65 76 69 63 65 20 69 6e 20 72 65 61 64 20   device in read 
bd50: 6f 6e 6c 79 20 6d 6f 64 65 2e 0a 20 20 23 20 72  only mode..  # r
bd60: 6f 3a 20 61 62 62 72 65 76 69 61 74 69 6f 6e 20  o: abbreviation 
bd70: 66 6f 72 20 20 72 65 61 64 6f 6e 6c 79 2e 0a 20  for  readonly.. 
bd80: 20 23 20 73 63 72 61 74 63 68 3a 20 43 72 65 61   # scratch: Crea
bd90: 74 65 20 61 20 77 72 69 74 65 61 62 6c 65 20 73  te a writeable s
bda0: 63 72 61 74 63 68 20 63 6f 70 79 20 6f 66 20 74  cratch copy of t
bdb0: 68 65 20 6e 61 6d 65 64 20 69 6d 61 67 65 0a 20  he named image. 
bdc0: 20 23 20 20 20 20 66 69 6c 65 20 61 6e 64 20 6d   #    file and m
bdd0: 6f 75 6e 74 20 69 74 2e 20 20 54 68 69 73 20 69  ount it.  This i
bde0: 73 20 68 65 6c 70 66 75 6c 20 77 68 65 6e 20 79  s helpful when y
bdf0: 6f 75 20 61 72 65 20 62 6f 6f 74 69 6e 67 20 61  ou are booting a
be00: 0a 20 20 23 20 20 20 20 64 69 73 74 72 69 62 75  .  #    distribu
be10: 74 69 6f 6e 20 44 45 43 74 61 70 65 2e 20 20 42  tion DECtape.  B
be20: 6f 6f 74 65 64 20 44 45 43 74 61 70 65 20 69 6d  ooted DECtape im
be30: 61 67 65 73 20 6d 75 73 74 20 62 65 20 77 72 69  ages must be wri
be40: 74 65 61 62 6c 65 2e 0a 20 20 23 20 20 20 20 54  teable..  #    T
be50: 6f 20 70 72 6f 74 65 63 74 20 61 20 64 69 73 74  o protect a dist
be60: 72 69 62 75 74 69 6f 6e 20 44 45 43 74 61 70 65  ribution DECtape
be70: 2c 20 75 73 65 20 74 68 69 73 20 6f 70 74 69 6f  , use this optio
be80: 6e 2e 0a 20 20 23 20 20 20 20 57 68 65 6e 20 61  n..  #    When a
be90: 6c 6c 20 73 63 72 69 70 74 20 72 75 6e 73 20 61  ll script runs a
bea0: 72 65 20 64 6f 6e 65 2c 20 74 68 65 20 73 63 72  re done, the scr
beb0: 61 74 63 68 20 76 65 72 73 69 6f 6e 20 69 73 20  atch version is 
bec0: 64 65 6c 65 74 65 64 2e 0a 20 20 23 20 6e 65 77  deleted..  # new
bed0: 3a 20 49 66 20 74 68 65 72 65 20 69 73 20 61 6e  : If there is an
bee0: 20 65 78 69 73 74 69 6e 67 20 66 69 6c 65 2c 20   existing file, 
bef0: 6d 6f 76 65 20 69 74 20 61 73 69 64 65 20 61 73  move it aside as
bf00: 20 61 20 2e 73 61 76 65 20 62 65 63 61 75 73 65   a .save because
bf10: 0a 20 20 23 20 20 20 20 77 65 20 77 61 6e 74 20  .  #    we want 
bf20: 74 6f 20 63 72 65 61 74 65 20 61 20 6e 65 77 20  to create a new 
bf30: 65 6d 70 74 79 20 69 6d 61 67 65 20 66 69 6c 65  empty image file
bf40: 2e 0a 20 20 23 0a 20 20 23 20 49 66 20 74 68 65  ..  #.  # If the
bf50: 20 6d 6f 75 6e 74 20 63 6f 6d 6d 61 6e 64 20 66   mount command f
bf60: 61 69 6c 73 20 66 6f 72 20 61 6e 79 20 72 65 61  ails for any rea
bf70: 73 6f 6e 2c 20 77 65 20 70 72 65 73 75 6d 65 0a  son, we presume.
bf80: 20 20 23 20 69 74 20 69 73 20 61 20 66 61 74 61    # it is a fata
bf90: 6c 20 65 72 72 6f 72 20 61 6e 64 20 61 62 6f 72  l error and abor
bfa0: 74 20 74 68 65 20 73 63 72 69 70 74 2e 0a 20 20  t the script..  
bfb0: 0a 20 20 64 65 66 20 6d 6f 75 6e 74 5f 63 6f 6d  .  def mount_com
bfc0: 6d 61 6e 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65  mand (self, line
bfd0: 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a  , script_file):.
bfe0: 20 20 20 20 6d 20 3d 20 72 65 2e 6d 61 74 63 68      m = re.match
bff0: 28 5f 6d 6f 75 6e 74 5f 72 65 2c 20 6c 69 6e 65  (_mount_re, line
c000: 29 0a 20 20 20 20 69 66 20 6d 20 3d 3d 20 4e 6f  ).    if m == No
c010: 6e 65 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28  ne:.      print(
c020: 22 41 74 20 6c 69 6e 65 20 22 20 2b 20 73 74 72  "At line " + str
c030: 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74  (self.line_ct_st
c040: 61 63 6b 5b 30 5d 29 20 2b 20 5c 0a 20 20 20 20  ack[0]) + \.    
c050: 20 20 20 20 22 2c 20 63 6f 75 6c 64 20 6e 6f 74      ", could not
c060: 20 70 61 72 73 65 20 6d 6f 75 6e 74 2e 20 20 49   parse mount.  I
c070: 67 6e 6f 72 69 6e 67 3a 20 7b 22 20 2b 20 6c 69  gnoring: {" + li
c080: 6e 65 20 2b 20 22 7d 2e 22 29 0a 20 20 20 20 20  ne + "}.").     
c090: 20 72 65 74 75 72 6e 20 22 64 69 65 22 0a 20 20   return "die".  
c0a0: 20 20 73 69 6d 68 5f 64 65 76 20 3d 20 6d 2e 67    simh_dev = m.g
c0b0: 72 6f 75 70 28 31 29 0a 20 20 20 20 75 6e 69 74  roup(1).    unit
c0c0: 20 3d 20 6d 2e 67 72 6f 75 70 28 32 29 0a 20 20   = m.group(2).  
c0d0: 20 20 72 65 73 74 20 3d 20 6d 2e 67 72 6f 75 70    rest = m.group
c0e0: 28 33 29 0a 20 20 20 20 70 61 72 74 73 20 3d 20  (3).    parts = 
c0f0: 72 65 73 74 2e 73 70 6c 69 74 28 29 0a 20 20 20  rest.split().   
c100: 20 69 66 20 6c 65 6e 28 70 61 72 74 73 29 20 3d   if len(parts) =
c110: 3d 20 30 3a 0a 20 20 20 20 20 20 70 72 69 6e 74  = 0:.      print
c120: 28 22 41 74 20 6c 69 6e 65 20 22 20 2b 20 73 74  ("At line " + st
c130: 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73  r(self.line_ct_s
c140: 74 61 63 6b 5b 30 5d 29 20 2b 20 5c 0a 20 20 20  tack[0]) + \.   
c150: 20 20 20 20 20 22 3a 20 4e 6f 20 69 6d 61 67 65       ": No image
c160: 20 6e 61 6d 65 20 73 70 65 63 69 66 69 65 64 20   name specified 
c170: 69 6e 3a 20 7b 22 20 2b 20 6c 69 6e 65 20 2b 20  in: {" + line + 
c180: 22 7d 22 29 0a 20 20 20 20 20 20 72 65 74 75 72  "}").      retur
c190: 6e 20 22 64 69 65 22 0a 20 20 20 20 72 6f 5f 61  n "die".    ro_a
c1a0: 72 67 20 3d 20 22 22 0a 20 20 20 20 69 6d 61 67  rg = "".    imag
c1b0: 65 6e 61 6d 65 20 3d 20 73 65 6c 66 2e 70 61 74  ename = self.pat
c1c0: 68 5f 65 78 70 61 6e 64 28 70 61 72 74 73 5b 30  h_expand(parts[0
c1d0: 5d 29 0a 20 20 20 20 69 66 20 69 6d 61 67 65 6e  ]).    if imagen
c1e0: 61 6d 65 20 3d 3d 20 4e 6f 6e 65 3a 20 72 65 74  ame == None: ret
c1f0: 75 72 6e 20 22 64 69 65 22 0a 20 20 20 20 0a 20  urn "die".    . 
c200: 20 20 20 64 6f 74 20 3d 20 69 6d 61 67 65 6e 61     dot = imagena
c210: 6d 65 2e 72 69 6e 64 65 78 28 22 2e 22 29 0a 20  me.rindex("."). 
c220: 20 20 20 62 61 73 65 5f 69 6d 61 67 65 6e 61 6d     base_imagenam
c230: 65 20 3d 20 69 6d 61 67 65 6e 61 6d 65 5b 3a 64  e = imagename[:d
c240: 6f 74 5d 0a 20 20 20 20 65 78 74 65 6e 73 69 6f  ot].    extensio
c250: 6e 20 3d 20 69 6d 61 67 65 6e 61 6d 65 5b 64 6f  n = imagename[do
c260: 74 3a 5d 0a 20 20 20 20 63 6f 70 79 5f 69 6d 61  t:].    copy_ima
c270: 67 65 6e 61 6d 65 20 3d 20 22 22 0a 20 20 20 20  gename = "".    
c280: 23 20 43 61 73 65 20 6f 66 20 61 64 64 69 74 69  # Case of additi
c290: 6f 6e 61 6c 20 61 72 67 75 6d 65 6e 74 73 2e 0a  onal arguments..
c2a0: 20 20 20 20 69 66 20 6c 65 6e 20 28 70 61 72 74      if len (part
c2b0: 73 29 20 3e 20 31 3a 0a 20 20 20 20 20 20 23 20  s) > 1:.      # 
c2c0: 50 65 72 66 6f 72 6d 20 6d 75 73 74 5f 65 78 69  Perform must_exi
c2d0: 73 74 20 62 65 66 6f 72 65 20 73 63 72 61 74 63  st before scratc
c2e0: 68 0a 20 20 20 20 20 20 69 66 20 22 6e 65 77 22  h.      if "new"
c2f0: 20 69 6e 20 70 61 72 74 73 5b 31 3a 5d 3a 0a 20   in parts[1:]:. 
c300: 20 20 20 20 20 20 20 73 61 76 65 5f 69 66 5f 6e         save_if_n
c310: 65 65 64 65 64 28 69 6d 61 67 65 6e 61 6d 65 29  eeded(imagename)
c320: 0a 20 20 20 20 20 20 69 66 20 22 6d 75 73 74 5f  .      if "must_
c330: 65 78 69 73 74 22 20 69 6e 20 70 61 72 74 73 5b  exist" in parts[
c340: 31 3a 5d 20 6f 72 20 22 72 65 71 75 69 72 65 64  1:] or "required
c350: 22 20 69 6e 20 70 61 72 74 73 5b 31 3a 5d 3a 0a  " in parts[1:]:.
c360: 20 20 20 20 20 20 20 20 20 20 69 66 20 6e 6f 74            if not
c370: 20 6f 73 2e 70 61 74 68 2e 65 78 69 73 74 73 28   os.path.exists(
c380: 69 6d 61 67 65 6e 61 6d 65 29 3a 0a 20 20 20 20  imagename):.    
c390: 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22 41          print("A
c3a0: 74 20 6c 69 6e 65 20 22 20 2b 20 73 74 72 28 73  t line " + str(s
c3b0: 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63  elf.line_ct_stac
c3c0: 6b 5b 30 5d 29 20 2b 20 22 2c 20 22 20 2b 20 5c  k[0]) + ", " + \
c3d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
c3e0: 20 69 6d 61 67 65 6e 61 6d 65 20 2b 20 22 20 6d   imagename + " m
c3f0: 75 73 74 20 65 78 69 73 74 20 62 75 74 20 77 61  ust exist but wa
c400: 73 20 6e 6f 74 20 66 6f 75 6e 64 2e 20 4e 6f 74  s not found. Not
c410: 20 6d 6f 75 6e 74 69 6e 67 2e 22 29 0a 20 20 20   mounting.").   
c420: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20           return 
c430: 22 64 69 65 22 0a 20 20 20 20 20 20 69 66 20 22  "die".      if "
c440: 73 63 72 61 74 63 68 22 20 69 6e 20 70 61 72 74  scratch" in part
c450: 73 5b 31 3a 5d 3a 0a 20 20 20 20 20 20 20 20 63  s[1:]:.        c
c460: 6f 70 79 5f 69 6d 61 67 65 6e 61 6d 65 20 3d 20  opy_imagename = 
c470: 73 65 6c 66 2e 6d 61 6b 65 5f 73 63 72 61 74 63  self.make_scratc
c480: 68 28 62 61 73 65 5f 69 6d 61 67 65 6e 61 6d 65  h(base_imagename
c490: 2c 20 65 78 74 65 6e 73 69 6f 6e 29 0a 20 20 20  , extension).   
c4a0: 20 20 20 20 20 69 66 20 63 6f 70 79 5f 69 6d 61       if copy_ima
c4b0: 67 65 6e 61 6d 65 20 3d 3d 20 4e 6f 6e 65 3a 20  gename == None: 
c4c0: 72 65 74 75 72 6e 20 22 64 69 65 22 0a 20 20 20  return "die".   
c4d0: 20 20 20 20 20 69 6d 61 67 65 6e 61 6d 65 20 3d       imagename =
c4e0: 20 63 6f 70 79 5f 69 6d 61 67 65 6e 61 6d 65 0a   copy_imagename.
c4f0: 20 20 20 20 20 20 20 20 0a 20 20 20 20 20 20 69          .      i
c500: 66 20 22 72 65 61 64 6f 6e 6c 79 22 20 69 6e 20  f "readonly" in 
c510: 70 61 72 74 73 5b 31 3a 5d 20 6f 72 20 22 72 6f  parts[1:] or "ro
c520: 22 20 69 6e 20 70 61 72 74 73 5b 31 3a 5d 3a 0a  " in parts[1:]:.
c530: 20 20 20 20 20 20 20 20 69 66 20 63 6f 70 79 5f          if copy_
c540: 69 6d 61 67 65 6e 61 6d 65 20 21 3d 20 22 22 3a  imagename != "":
c550: 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74  .          print
c560: 28 22 41 74 20 6c 69 6e 65 20 22 20 2b 20 73 74  ("At line " + st
c570: 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73  r(self.line_ct_s
c580: 74 61 63 6b 5b 30 5d 29 20 2b 20 5c 0a 20 20 20  tack[0]) + \.   
c590: 20 20 20 20 20 20 20 20 20 22 3a 20 59 6f 75 20           ": You 
c5a0: 64 6f 6e 27 74 20 72 65 61 6c 6c 79 20 6e 65 65  don't really nee
c5b0: 64 20 74 6f 20 73 65 74 20 72 65 61 64 6f 6e 6c  d to set readonl
c5c0: 79 20 6f 6e 20 61 20 73 63 72 61 74 63 68 20 63  y on a scratch c
c5d0: 6f 70 79 2e 22 29 0a 20 20 20 20 20 20 20 20 72  opy.").        r
c5e0: 6f 5f 61 72 67 20 3d 20 22 2d 72 20 22 0a 20 20  o_arg = "-r ".  
c5f0: 20 20 20 20 69 66 20 22 6e 6f 5f 6f 76 65 72 77      if "no_overw
c600: 72 69 74 65 22 20 69 6e 20 70 61 72 74 73 5b 31  rite" in parts[1
c610: 3a 5d 20 6f 72 20 22 70 72 65 73 65 72 76 65 22  :] or "preserve"
c620: 20 69 6e 20 70 61 72 74 73 5b 31 3a 5d 3a 0a 20   in parts[1:]:. 
c630: 20 20 20 20 20 20 20 69 66 20 63 6f 70 79 5f 69         if copy_i
c640: 6d 61 67 65 6e 61 6d 65 20 21 3d 20 22 22 3a 0a  magename != "":.
c650: 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74 28            print(
c660: 22 49 67 6e 6f 72 69 6e 67 20 70 72 65 73 65 72  "Ignoring preser
c670: 76 65 20 6f 70 74 69 6f 6e 20 61 74 20 6c 69 6e  ve option at lin
c680: 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  e " + \.        
c690: 20 20 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6c        str(self.l
c6a0: 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29  ine_ct_stack[0])
c6b0: 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20   + \.           
c6c0: 20 20 20 22 20 62 65 63 61 75 73 65 20 73 63 72     " because scr
c6d0: 61 74 63 68 20 6f 70 74 69 6f 6e 20 69 73 20 70  atch option is p
c6e0: 72 65 73 65 6e 74 2e 22 29 0a 20 20 20 20 20 20  resent.").      
c6f0: 20 20 65 6c 73 65 3a 0a 20 20 20 20 20 20 20 20    else:.        
c700: 20 20 6e 65 78 74 5f 74 61 70 65 20 3d 20 30 0a    next_tape = 0.
c710: 20 20 20 20 20 20 20 20 20 20 77 68 69 6c 65 20            while 
c720: 6f 73 2e 70 61 74 68 2e 69 73 66 69 6c 65 28 69  os.path.isfile(i
c730: 6d 61 67 65 6e 61 6d 65 29 3a 0a 20 20 20 20 20  magename):.     
c740: 20 20 20 20 20 20 20 70 72 69 6e 74 28 22 46 6f         print("Fo
c750: 75 6e 64 3a 20 22 20 2b 20 69 6d 61 67 65 6e 61  und: " + imagena
c760: 6d 65 29 0a 20 20 20 20 20 20 20 20 20 20 20 20  me).            
c770: 6e 65 78 74 5f 74 61 70 65 20 2b 3d 20 31 0a 20  next_tape += 1. 
c780: 20 20 20 20 20 20 20 20 20 20 20 69 6d 61 67 65             image
c790: 6e 61 6d 65 20 3d 20 20 62 61 73 65 5f 69 6d 61  name =  base_ima
c7a0: 67 65 6e 61 6d 65 20 2b 20 22 2d 22 20 2b 20 73  gename + "-" + s
c7b0: 74 72 28 6e 65 78 74 5f 74 61 70 65 29 20 2b 20  tr(next_tape) + 
c7c0: 65 78 74 65 6e 73 69 6f 6e 0a 20 20 20 20 69 66  extension.    if
c7d0: 20 75 6e 69 74 20 3d 3d 20 4e 6f 6e 65 20 6f 72   unit == None or
c7e0: 20 75 6e 69 74 20 3d 3d 20 22 22 3a 0a 20 20 20   unit == "":.   
c7f0: 20 20 20 70 72 69 6e 74 28 22 4e 65 65 64 20 75     print("Need u
c800: 6e 69 74 20 6e 75 6d 62 65 72 20 66 6f 72 3a 20  nit number for: 
c810: 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20 20  " + line).      
c820: 72 65 74 75 72 6e 20 22 64 69 65 22 0a 20 20 0a  return "die".  .
c830: 20 20 20 20 69 66 20 73 69 6d 68 5f 64 65 76 20      if simh_dev 
c840: 6e 6f 74 20 69 6e 20 5f 6f 73 38 5f 66 72 6f 6d  not in _os8_from
c850: 5f 73 69 6d 68 5f 64 65 76 3a 0a 20 20 20 20 20  _simh_dev:.     
c860: 20 70 72 69 6e 74 28 22 41 74 20 6c 69 6e 65 20   print("At line 
c870: 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e  " + str(self.lin
c880: 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b  e_ct_stack[0]) +
c890: 20 5c 0a 20 20 20 20 20 20 20 20 20 20 22 3a 20   \.          ": 
c8a0: 55 6e 72 65 63 6f 67 6e 69 7a 65 64 20 73 69 6d  Unrecognized sim
c8b0: 68 20 64 65 76 3a 20 22 20 2b 20 73 69 6d 68 5f  h dev: " + simh_
c8c0: 64 65 76 29 0a 20 20 20 20 20 20 72 65 74 75 72  dev).      retur
c8d0: 6e 20 22 64 69 65 22 0a 20 20 20 20 6f 73 38 64  n "die".    os8d
c8e0: 65 76 20 3d 20 5f 6f 73 38 5f 66 72 6f 6d 5f 73  ev = _os8_from_s
c8f0: 69 6d 68 5f 64 65 76 5b 73 69 6d 68 5f 64 65 76  imh_dev[simh_dev
c900: 5d 0a 20 20 0a 20 20 20 20 61 74 74 61 63 68 5f  ].  .    attach_
c910: 63 6f 6d 6d 20 3d 20 22 61 74 74 20 22 20 2b 20  comm = "att " + 
c920: 72 6f 5f 61 72 67 20 2b 20 73 69 6d 68 5f 64 65  ro_arg + simh_de
c930: 76 20 2b 20 75 6e 69 74 20 2b 20 22 20 22 20 2b  v + unit + " " +
c940: 20 69 6d 61 67 65 6e 61 6d 65 0a 20 20 0a 20 20   imagename.  .  
c950: 20 20 69 66 20 73 65 6c 66 2e 76 65 72 62 6f 73    if self.verbos
c960: 65 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22  e:.      print("
c970: 4c 69 6e 65 20 22 20 2b 20 73 74 72 28 73 65 6c  Line " + str(sel
c980: 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b  f.line_ct_stack[
c990: 30 5d 29 20 2b 20 22 3a 20 6d 6f 75 6e 74 3a 20  0]) + ": mount: 
c9a0: 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 20 20  " + \.          
c9b0: 61 74 74 61 63 68 5f 63 6f 6d 6d 29 0a 20 20 20  attach_comm).   
c9c0: 20 72 65 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69   reply = self.si
c9d0: 6d 68 2e 73 69 6d 68 5f 63 6d 64 28 61 74 74 61  mh.simh_cmd(atta
c9e0: 63 68 5f 63 6f 6d 6d 29 0a 20 20 20 20 73 65 6c  ch_comm).    sel
c9f0: 66 2e 73 69 6d 68 2e 73 69 6d 68 5f 74 65 73 74  f.simh.simh_test
ca00: 5f 72 65 73 75 6c 74 28 72 65 70 6c 79 2c 20 22  _result(reply, "
ca10: 50 72 6f 6d 70 74 22 2c 20 22 6d 6f 75 6e 74 5f  Prompt", "mount_
ca20: 63 6f 6d 6d 61 6e 64 22 29 0a 20 20 20 20 72 65  command").    re
ca30: 74 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 0a  turn "success"..
ca40: 0a 20 20 23 23 23 23 20 62 6f 6f 74 5f 63 6f 6d  .  #### boot_com
ca50: 6d 61 6e 64 20 23 23 23 23 23 23 23 23 23 23 23  mand ###########
ca60: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
ca70: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
ca80: 23 23 23 23 23 23 23 23 23 0a 20 20 23 0a 20 20  #########.  #.  
ca90: 23 20 43 68 65 63 6b 20 74 6f 20 73 65 65 20 69  # Check to see i
caa0: 66 20 74 68 65 20 64 65 76 69 63 65 20 74 6f 20  f the device to 
cab0: 62 65 20 62 6f 6f 74 65 64 20 68 61 73 20 73 6f  be booted has so
cac0: 6d 65 74 68 69 6e 67 20 61 74 74 61 63 68 65 64  mething attached
cad0: 2e 0a 20 20 23 20 49 66 20 6e 6f 74 20 64 69 65  ..  # If not die
cae0: 2e 0a 20 20 23 20 49 66 20 73 6f 2c 20 62 6f 6f  ..  # If so, boo
caf0: 74 20 69 74 2c 20 61 6e 64 20 73 65 74 20 6f 75  t it, and set ou
cb00: 72 20 62 6f 6f 74 65 64 20 73 74 61 74 65 20 74  r booted state t
cb10: 6f 20 54 72 75 65 2e 0a 20 20 0a 20 20 64 65 66  o True..  .  def
cb20: 20 62 6f 6f 74 5f 63 6f 6d 6d 61 6e 64 20 28 73   boot_command (s
cb30: 65 6c 66 2c 20 6c 69 6e 65 2c 20 73 63 72 69 70  elf, line, scrip
cb40: 74 5f 66 69 6c 65 29 3a 0a 20 20 20 20 23 20 46  t_file):.    # F
cb50: 69 72 73 74 20 63 6f 6e 66 69 72 6d 20 73 6f 6d  irst confirm som
cb60: 65 74 68 69 6e 67 20 69 73 20 61 74 74 61 63 68  ething is attach
cb70: 65 64 20 74 6f 20 62 6f 6f 74 20 66 72 6f 6d 2e  ed to boot from.
cb80: 0a 20 20 20 20 75 63 6e 61 6d 65 20 3d 20 6c 69  .    ucname = li
cb90: 6e 65 2e 75 70 70 65 72 28 29 0a 20 20 20 20 62  ne.upper().    b
cba0: 6f 6f 74 5f 72 65 70 6c 69 65 73 20 3d 20 5b 75  oot_replies = [u
cbb0: 63 6e 61 6d 65 20 2b 20 72 22 5c 73 2b 28 2e 2b  cname + r"\s+(.+
cbc0: 29 5c 72 22 2c 20 22 4e 6f 6e 2d 65 78 69 73 74  )\r", "Non-exist
cbd0: 65 6e 74 20 64 65 76 69 63 65 22 5d 0a 20 20 20  ent device"].   
cbe0: 20 73 65 6c 66 2e 73 69 6d 68 2e 73 69 6d 68 5f   self.simh.simh_
cbf0: 73 65 6e 64 5f 6c 69 6e 65 28 22 73 68 6f 77 20  send_line("show 
cc00: 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 72 65  " + line).    re
cc10: 74 76 61 6c 20 3d 20 73 65 6c 66 2e 73 69 6d 68  tval = self.simh
cc20: 2e 5f 63 68 69 6c 64 2e 65 78 70 65 63 74 28 62  ._child.expect(b
cc30: 6f 6f 74 5f 72 65 70 6c 69 65 73 29 0a 20 20 20  oot_replies).   
cc40: 20 69 66 20 72 65 74 76 61 6c 20 3d 3d 20 31 3a   if retval == 1:
cc50: 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22 41 74  .      print("At
cc60: 74 65 6d 70 74 20 74 6f 20 62 6f 6f 74 20 6e 6f  tempt to boot no
cc70: 6e 2d 65 78 69 73 74 65 6e 74 20 64 65 76 69 63  n-existent devic
cc80: 65 3a 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20  e: " + line).   
cc90: 20 20 20 72 65 74 75 72 6e 20 22 64 69 65 22 0a     return "die".
cca0: 20 20 20 20 72 65 70 6c 79 5f 73 74 72 20 3d 20      reply_str = 
ccb0: 73 65 6c 66 2e 73 69 6d 68 2e 63 68 69 6c 64 5f  self.simh.child_
ccc0: 61 66 74 65 72 28 29 0a 20 20 20 20 6d 20 3d 20  after().    m = 
ccd0: 72 65 2e 6d 61 74 63 68 28 72 22 5e 28 5c 53 2b  re.match(r"^(\S+
cce0: 29 5c 73 2b 28 5c 53 2b 29 2c 5c 73 2b 28 61 74  )\s+(\S+),\s+(at
ccf0: 74 61 63 68 65 64 20 74 6f 20 7c 6e 6f 74 20 61  tached to |not a
cd00: 74 74 61 63 68 65 64 29 28 5c 53 2b 29 3f 2c 5c  ttached)(\S+)?,\
cd10: 73 2b 28 2e 2b 29 5c 72 22 2c 0a 20 20 20 20 20  s+(.+)\r",.     
cd20: 20 20 20 72 65 70 6c 79 5f 73 74 72 29 0a 20 20     reply_str).  
cd30: 20 20 69 66 20 6d 20 3d 3d 20 4e 6f 6e 65 3a 0a    if m == None:.
cd40: 20 20 20 20 20 20 70 72 69 6e 74 28 22 43 6f 75        print("Cou
cd50: 6c 64 20 6e 6f 74 20 64 65 74 65 72 6d 69 6e 65  ld not determine
cd60: 20 69 66 20 64 65 76 69 63 65 20 22 20 2b 20 6c   if device " + l
cd70: 69 6e 65 20 2b 20 22 20 69 73 20 61 74 74 61 63  ine + " is attac
cd80: 68 65 64 3b 20 22 20 2b 0a 20 20 20 20 20 20 20  hed; " +.       
cd90: 20 20 20 22 67 6f 74 20 27 22 20 2b 20 72 65 70     "got '" + rep
cda0: 6c 79 5f 73 74 72 20 2b 20 22 27 22 29 0a 20 20  ly_str + "'").  
cdb0: 20 20 20 20 72 65 74 75 72 6e 20 22 64 69 65 22      return "die"
cdc0: 0a 0a 20 20 20 20 23 20 43 61 75 74 69 6f 6e 20  ..    # Caution 
cdd0: 6d 61 74 63 68 20 67 72 6f 75 70 20 77 65 20 77  match group we w
cde0: 61 6e 74 20 65 6e 64 73 20 77 69 74 68 20 61 20  ant ends with a 
cdf0: 73 70 61 63 65 2e 0a 20 20 20 20 69 66 20 6d 2e  space..    if m.
ce00: 67 72 6f 75 70 28 33 29 20 21 3d 20 22 61 74 74  group(3) != "att
ce10: 61 63 68 65 64 20 74 6f 20 22 3a 0a 20 20 20 20  ached to ":.    
ce20: 20 20 70 72 69 6e 74 28 22 41 74 74 65 6d 70 74    print("Attempt
ce30: 20 74 6f 20 62 6f 6f 74 20 6f 6e 20 6e 6f 6e 2d   to boot on non-
ce40: 61 74 74 61 63 68 65 64 20 64 65 76 69 63 65 3a  attached device:
ce50: 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 20   " + line).     
ce60: 20 72 65 74 75 72 6e 20 22 64 69 65 22 0a 20 20   return "die".  
ce70: 20 20 0a 20 20 20 20 62 6f 6f 74 5f 63 6f 6d 6d    .    boot_comm
ce80: 20 3d 20 22 62 6f 6f 74 20 22 20 2b 20 6c 69 6e   = "boot " + lin
ce90: 65 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 76 65  e.    if self.ve
cea0: 72 62 6f 73 65 3a 0a 20 20 20 20 20 20 70 72 69  rbose:.      pri
ceb0: 6e 74 28 22 4c 69 6e 65 20 22 20 2b 20 73 74 72  nt("Line " + str
cec0: 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74  (self.line_ct_st
ced0: 61 63 6b 5b 30 5d 29 20 2b 20 22 3a 20 22 20 2b  ack[0]) + ": " +
cee0: 20 62 6f 6f 74 5f 63 6f 6d 6d 29 0a 20 20 20 20   boot_comm).    
cef0: 72 65 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d  reply = self.sim
cf00: 68 2e 73 69 6d 68 5f 63 6d 64 28 62 6f 6f 74 5f  h.simh_cmd(boot_
cf10: 63 6f 6d 6d 2c 20 73 65 6c 66 2e 73 69 6d 68 2e  comm, self.simh.
cf20: 5f 6f 73 38 5f 72 65 70 6c 69 65 73 5f 72 65 78  _os8_replies_rex
cf30: 29 0a 20 20 20 20 23 20 57 65 27 72 65 20 69 6e  ).    # We're in
cf40: 20 4f 53 2f 38 20 6e 6f 77 20 75 73 65 20 74 68   OS/8 now use th
cf50: 61 74 20 74 65 73 74 65 72 2e 0a 20 20 20 20 73  at tester..    s
cf60: 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 74 65 73  elf.simh.os8_tes
cf70: 74 5f 72 65 73 75 6c 74 20 28 72 65 70 6c 79 2c  t_result (reply,
cf80: 20 22 4d 6f 6e 69 74 6f 72 20 50 72 6f 6d 70 74   "Monitor Prompt
cf90: 22 2c 20 22 62 6f 6f 74 5f 63 6f 6d 6d 61 6e 64  ", "boot_command
cfa0: 22 29 0a 20 20 20 20 73 65 6c 66 2e 62 6f 6f 74  ").    self.boot
cfb0: 65 64 20 3d 20 54 72 75 65 0a 20 20 20 20 72 65  ed = True.    re
cfc0: 74 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 0a  turn "success"..
cfd0: 0a 20 20 23 23 23 23 20 63 68 65 63 6b 5f 61 6e  .  #### check_an
cfe0: 64 5f 72 75 6e 20 23 23 23 23 23 23 23 23 23 23  d_run ##########
cff0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
d000: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
d010: 23 23 23 23 23 23 23 23 0a 20 20 23 20 43 6f 6d  ########.  # Com
d020: 6d 6f 6e 20 72 6f 75 74 69 6e 65 20 74 6f 20 63  mon routine to c
d030: 68 65 63 6b 20 74 68 61 74 20 77 65 20 61 72 65  heck that we are
d040: 20 62 6f 6f 74 61 62 6c 65 2c 20 69 6e 20 74 68   bootable, in th
d050: 65 20 72 69 67 68 74 20 63 6f 6e 74 65 78 74 0a  e right context.
d060: 20 20 23 20 61 72 65 20 61 62 6c 65 20 74 6f 20    # are able to 
d070: 72 75 6e 20 61 20 63 6f 6d 6d 61 6e 64 20 75 6e  run a command un
d080: 64 65 72 20 4f 53 2f 38 2c 20 61 6e 64 20 74 68  der OS/8, and th
d090: 61 74 20 77 65 20 73 75 63 63 65 73 73 66 75 6c  at we successful
d0a0: 6c 79 20 72 75 6e 20 69 74 2e 0a 20 20 23 20 63  ly run it..  # c
d0b0: 61 6c 6c 65 72 20 69 73 20 74 68 65 20 6e 61 6d  aller is the nam
d0c0: 65 20 77 65 20 67 69 76 65 20 6f 75 74 20 61 73  e we give out as
d0d0: 20 6f 75 72 20 63 61 6c 6c 65 72 2e 0a 20 20 23   our caller..  #
d0e0: 20 52 65 74 75 72 6e 20 2d 31 20 69 66 20 77 65   Return -1 if we
d0f0: 20 61 72 65 20 6e 6f 74 20 62 6f 6f 74 65 64 20   are not booted 
d100: 61 6e 64 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20  and the command 
d110: 6e 65 65 64 73 20 74 6f 20 64 69 65 2e 0a 20 20  needs to die..  
d120: 23 20 6f 74 68 65 72 77 69 73 65 20 72 65 74 75  # otherwise retu
d130: 72 6e 20 74 68 65 20 72 65 70 6c 79 20 74 6f 20  rn the reply to 
d140: 74 68 65 20 63 6f 6d 6d 61 6e 64 2e 0a 20 20 23  the command..  #
d150: 20 57 65 20 67 65 6e 65 72 69 63 61 6c 6c 79 20   We generically 
d160: 73 75 70 70 6f 72 74 20 72 65 70 6f 72 74 69 6e  support reportin
d170: 67 20 6f 75 74 20 69 66 20 74 72 61 6e 73 63 72  g out if transcr
d180: 69 70 74 20 69 73 20 65 6e 61 62 6c 65 64 2e 0a  ipt is enabled..
d190: 0a 20 20 64 65 66 20 63 68 65 63 6b 5f 61 6e 64  .  def check_and
d1a0: 5f 72 75 6e 20 28 73 65 6c 66 2c 20 63 61 6c 6c  _run (self, call
d1b0: 65 72 2c 20 6f 73 38 5f 63 6f 6d 6d 2c 20 73 63  er, os8_comm, sc
d1c0: 72 69 70 74 5f 66 69 6c 65 2c 20 72 65 70 6c 69  ript_file, repli
d1d0: 65 73 3d 4e 6f 6e 65 29 3a 0a 20 20 20 20 69 66  es=None):.    if
d1e0: 20 6e 6f 74 20 73 65 6c 66 2e 62 6f 6f 74 65 64   not self.booted
d1f0: 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22 43  :.      print("C
d200: 61 6e 6e 6f 74 20 72 75 6e 20 22 20 2b 20 63 61  annot run " + ca
d210: 6c 6c 65 72 20 20 2b 20 22 20 63 6f 6d 6d 61 6e  ller  + " comman
d220: 64 20 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a  d at line " + \.
d230: 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c 66          str(self
d240: 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
d250: 5d 29 20 2b 20 22 2e 20 4f 53 2f 38 20 68 61 73  ]) + ". OS/8 has
d260: 20 6e 6f 74 20 62 65 65 6e 20 62 6f 6f 74 65 64   not been booted
d270: 2e 22 29 0a 20 20 20 20 20 20 72 65 74 75 72 6e  .").      return
d280: 20 2d 31 0a 0a 20 20 20 20 69 66 20 73 65 6c 66   -1..    if self
d290: 2e 76 65 72 62 6f 73 65 3a 20 70 72 69 6e 74 28  .verbose: print(
d2a0: 22 4c 69 6e 65 3a 20 22 20 2b 20 5c 0a 20 20 20  "Line: " + \.   
d2b0: 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e      str(self.lin
d2c0: 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b  e_ct_stack[0]) +
d2d0: 20 22 3a 20 22 20 2b 20 63 61 6c 6c 65 72 20 2b   ": " + caller +
d2e0: 20 22 5f 63 6f 6d 6d 61 6e 64 3a 20 22 20 2b 20   "_command: " + 
d2f0: 6f 73 38 5f 63 6f 6d 6d 29 0a 0a 20 20 20 20 23  os8_comm)..    #
d300: 20 41 6e 79 20 6f 73 38 2d 72 75 6e 20 63 6f 6d   Any os8-run com
d310: 6d 61 6e 64 20 6d 61 79 20 62 65 20 63 61 6c 6c  mand may be call
d320: 65 64 20 61 66 74 65 72 20 61 20 73 69 6d 68 20  ed after a simh 
d330: 63 6f 6d 6d 61 6e 64 20 74 68 61 74 20 6c 65 66  command that lef
d340: 74 20 75 73 0a 20 20 20 20 23 20 69 6e 20 73 69  t us.    # in si
d350: 6d 68 20 63 6f 6e 74 65 78 74 2e 20 43 68 65 63  mh context. Chec
d360: 6b 20 74 6f 20 73 65 65 20 69 66 20 77 65 20 6e  k to see if we n
d370: 65 65 64 20 74 6f 20 72 65 73 74 61 72 74 20 4f  eed to restart O
d380: 53 2f 38 2e 0a 20 20 20 20 23 20 57 65 20 63 6f  S/8..    # We co
d390: 75 6c 64 20 72 65 73 75 6d 65 2c 20 62 75 74 20  uld resume, but 
d3a0: 72 65 73 74 61 72 74 20 69 73 20 73 61 66 65 72  restart is safer
d3b0: 2e 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 73 69  ..    if self.si
d3c0: 6d 68 2e 5f 63 6f 6e 74 65 78 74 20 3d 3d 20 22  mh._context == "
d3d0: 73 69 6d 68 22 3a 0a 20 20 20 20 20 20 73 65 6c  simh":.      sel
d3e0: 66 2e 72 65 73 74 61 72 74 5f 63 6f 6d 6d 61 6e  f.restart_comman
d3f0: 64 28 6f 73 38 5f 63 6f 6d 6d 2c 20 73 63 72 69  d(os8_comm, scri
d400: 70 74 5f 66 69 6c 65 29 0a 0a 20 20 20 20 72 65  pt_file)..    re
d410: 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e  ply = self.simh.
d420: 6f 73 38 5f 63 6d 64 20 28 6f 73 38 5f 63 6f 6d  os8_cmd (os8_com
d430: 6d 2c 20 72 65 70 6c 69 65 73 2c 20 64 65 62 75  m, replies, debu
d440: 67 3d 73 65 6c 66 2e 64 65 62 75 67 29 0a 20 20  g=self.debug).  
d450: 20 20 69 66 20 22 74 72 61 6e 73 63 72 69 70 74    if "transcript
d460: 22 20 69 6e 20 73 65 6c 66 2e 6f 70 74 69 6f 6e  " in self.option
d470: 73 5f 65 6e 61 62 6c 65 64 3a 0a 20 20 20 20 20  s_enabled:.     
d480: 20 70 72 69 6e 74 20 28 73 65 6c 66 2e 73 69 6d   print (self.sim
d490: 68 2e 5f 63 68 69 6c 64 2e 62 65 66 6f 72 65 2e  h._child.before.
d4a0: 64 65 63 6f 64 65 28 29 2e 73 74 72 69 70 28 29  decode().strip()
d4b0: 29 0a 20 20 20 20 72 65 74 75 72 6e 20 72 65 70  ).    return rep
d4c0: 6c 79 0a 20 20 0a 20 20 0a 20 20 23 23 23 23 20  ly.  .  .  #### 
d4d0: 6f 73 38 5f 63 6f 6d 6d 61 6e 64 20 23 23 23 23  os8_command ####
d4e0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
d4f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
d500: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
d510: 23 0a 20 20 0a 20 20 64 65 66 20 6f 73 38 5f 63  #.  .  def os8_c
d520: 6f 6d 6d 61 6e 64 20 28 73 65 6c 66 2c 20 6c 69  ommand (self, li
d530: 6e 65 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 29  ne, script_file)
d540: 3a 0a 20 20 20 20 72 65 70 6c 79 20 3d 20 73 65  :.    reply = se
d550: 6c 66 2e 63 68 65 63 6b 5f 61 6e 64 5f 72 75 6e  lf.check_and_run
d560: 28 22 6f 73 38 22 2c 20 6c 69 6e 65 2c 20 73 63  ("os8", line, sc
d570: 72 69 70 74 5f 66 69 6c 65 29 0a 20 20 20 20 69  ript_file).    i
d580: 66 20 72 65 70 6c 79 20 3d 3d 20 2d 31 3a 20 72  f reply == -1: r
d590: 65 74 75 72 6e 20 22 64 69 65 22 0a 0a 20 20 20  eturn "die"..   
d5a0: 20 23 20 57 65 20 65 78 70 65 63 74 20 74 68 61   # We expect tha
d5b0: 74 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 77 69  t the command wi
d5c0: 6c 6c 20 65 78 69 74 20 74 6f 20 74 68 65 20 4f  ll exit to the O
d5d0: 53 2f 38 20 6d 6f 6e 69 74 6f 72 20 77 68 65 6e  S/8 monitor when
d5e0: 20 64 6f 6e 65 2e 0a 20 20 20 20 23 20 57 68 61   done..    # Wha
d5f0: 74 20 69 66 20 69 74 20 64 6f 65 73 6e 27 74 3f  t if it doesn't?
d600: 0a 20 20 20 20 23 20 57 65 20 77 61 6e 74 20 74  .    # We want t
d610: 6f 20 70 72 69 6e 74 20 65 72 72 6f 72 73 0a 20  o print errors. 
d620: 20 20 20 6d 6f 6e 20 3d 20 73 65 6c 66 2e 73 69     mon = self.si
d630: 6d 68 2e 6f 73 38 5f 74 65 73 74 5f 72 65 73 75  mh.os8_test_resu
d640: 6c 74 20 28 72 65 70 6c 79 2c 20 22 4d 6f 6e 69  lt (reply, "Moni
d650: 74 6f 72 20 50 72 6f 6d 70 74 22 2c 20 22 22 29  tor Prompt", "")
d660: 0a 20 20 20 20 69 66 20 6d 6f 6e 3a 20 72 65 74  .    if mon: ret
d670: 75 72 6e 20 22 73 75 63 63 65 73 73 22 0a 20 20  urn "success".  
d680: 20 20 63 64 20 20 3d 20 73 65 6c 66 2e 73 69 6d    cd  = self.sim
d690: 68 2e 6f 73 38 5f 74 65 73 74 5f 72 65 73 75 6c  h.os8_test_resul
d6a0: 74 20 28 72 65 70 6c 79 2c 20 22 43 6f 6d 6d 61  t (reply, "Comma
d6b0: 6e 64 20 44 65 63 6f 64 65 72 20 50 72 6f 6d 70  nd Decoder Promp
d6c0: 74 22 2c 20 22 22 29 0a 20 20 20 20 72 65 74 76  t", "").    retv
d6d0: 61 6c 20 3d 20 22 66 61 69 6c 22 0a 20 20 20 20  al = "fail".    
d6e0: 69 66 20 63 64 3a 0a 20 20 20 20 20 20 23 20 4f  if cd:.      # O
d6f0: 53 2f 38 20 63 6f 6d 6d 61 6e 64 20 72 65 74 75  S/8 command retu
d700: 72 6e 65 64 20 74 6f 20 63 6f 6d 6d 61 6e 64 20  rned to command 
d710: 64 65 63 6f 64 65 72 2e 20 20 57 65 20 65 73 63  decoder.  We esc
d720: 61 70 65 2e 0a 20 20 20 20 20 20 6d 6f 6e 20 3d  ape..      mon =
d730: 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 65   self.simh.os8_e
d740: 73 63 61 70 65 20 28 22 22 29 0a 20 20 20 20 20  scape ("").     
d750: 20 69 66 20 6d 6f 6e 20 3d 3d 20 46 61 6c 73 65   if mon == False
d760: 3a 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 20  :.        print 
d770: 28 22 6f 73 38 5f 63 6f 6d 6d 61 6e 64 3a 20 45  ("os8_command: E
d780: 73 63 61 70 65 20 66 72 6f 6d 20 63 6f 6d 6d 61  scape from comma
d790: 6e 64 20 64 65 63 6f 64 65 72 20 66 61 69 6c 65  nd decoder faile
d7a0: 64 2e 20 54 72 79 69 6e 67 20 5e 43 2e 22 29 0a  d. Trying ^C.").
d7b0: 20 20 20 20 20 20 20 20 6d 6f 6e 20 3d 20 73 65          mon = se
d7c0: 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 63 74 72 6c  lf.simh.os8_ctrl
d7d0: 5f 63 20 28 22 22 29 0a 20 20 20 20 20 20 20 20  _c ("").        
d7e0: 69 66 20 6d 6f 6e 20 3d 3d 20 46 61 6c 73 65 3a  if mon == False:
d7f0: 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74  .          print
d800: 20 28 22 5e 43 20 66 61 69 6c 65 64 20 74 6f 20   ("^C failed to 
d810: 72 65 74 75 72 6e 20 74 6f 20 6d 6f 6e 69 74 6f  return to monito
d820: 72 2e 20 4b 69 6c 6c 69 6e 67 20 73 63 72 69 70  r. Killing scrip
d830: 74 2e 22 29 0a 20 20 20 20 20 20 20 20 20 20 72  t.").          r
d840: 65 74 75 72 6e 20 22 64 69 65 22 0a 20 20 20 20  eturn "die".    
d850: 70 72 69 6e 74 20 28 22 6f 73 38 5f 63 6f 6d 6d  print ("os8_comm
d860: 61 6e 64 20 45 72 72 6f 72 3a 20 5c 6e 5c 74 22  and Error: \n\t"
d870: 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20 70 72 69   + line).    pri
d880: 6e 74 20 28 22 5c 74 22 20 2b 20 73 65 6c 66 2e  nt ("\t" + self.
d890: 73 69 6d 68 2e 63 68 69 6c 64 5f 61 66 74 65 72  simh.child_after
d8a0: 28 29 2e 73 74 72 69 70 28 29 29 0a 20 20 20 20  ().strip()).    
d8b0: 23 20 49 66 20 74 68 69 73 20 77 61 73 20 6e 6f  # If this was no
d8c0: 74 20 61 20 66 61 74 61 6c 20 65 72 72 6f 72 2c  t a fatal error,
d8d0: 20 77 65 20 6e 65 65 64 20 74 6f 20 5e 43 20 74   we need to ^C t
d8e0: 6f 20 67 65 74 20 62 61 63 6b 20 74 6f 20 4d 6f  o get back to Mo
d8f0: 6e 69 74 6f 72 2e 0a 20 20 20 20 23 20 42 75 74  nitor..    # But
d900: 20 73 6f 6d 65 74 69 6d 65 73 20 4f 53 2f 38 20   sometimes OS/8 
d910: 69 73 20 6e 6f 74 20 79 65 74 20 72 65 61 64 79  is not yet ready
d920: 20 66 6f 72 20 5e 43 2c 20 73 6f 20 77 65 20 77   for ^C, so we w
d930: 61 69 74 20 68 61 6c 66 20 61 20 73 65 63 6f 6e  ait half a secon
d940: 64 2e 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 73  d..    if self.s
d950: 69 6d 68 2e 5f 6f 73 38 5f 72 65 70 6c 69 65 73  imh._os8_replies
d960: 5b 72 65 70 6c 79 5d 5b 32 5d 20 3d 3d 20 46 61  [reply][2] == Fa
d970: 6c 73 65 3a 0a 20 20 20 20 20 20 74 69 6d 65 2e  lse:.      time.
d980: 73 6c 65 65 70 20 28 2e 35 29 0a 20 20 20 20 20  sleep (.5).     
d990: 20 70 72 69 6e 74 20 28 22 53 65 6e 64 69 6e 67   print ("Sending
d9a0: 20 5e 43 20 74 6f 20 72 65 74 75 72 6e 20 74 6f   ^C to return to
d9b0: 20 6d 6f 6e 69 74 6f 72 2e 22 29 0a 20 20 20 20   monitor.").    
d9c0: 20 20 65 73 63 61 70 65 20 3d 20 73 65 6c 66 2e    escape = self.
d9d0: 73 69 6d 68 2e 6f 73 38 5f 63 74 72 6c 5f 63 20  simh.os8_ctrl_c 
d9e0: 28 22 22 2c 20 64 65 62 75 67 3d 73 65 6c 66 2e  ("", debug=self.
d9f0: 64 65 62 75 67 29 0a 20 20 20 20 20 20 69 66 20  debug).      if 
da00: 65 73 63 61 70 65 3a 20 72 65 74 75 72 6e 20 22  escape: return "
da10: 66 61 69 6c 22 0a 20 20 20 20 20 20 65 6c 73 65  fail".      else
da20: 3a 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 20  :.        print 
da30: 28 22 5e 43 20 66 61 69 6c 65 64 20 74 6f 20 72  ("^C failed to r
da40: 65 74 75 72 6e 20 74 6f 20 6d 6f 6e 69 74 6f 72  eturn to monitor
da50: 2e 20 4b 69 6c 6c 69 6e 67 20 73 63 72 69 70 74  . Killing script
da60: 2e 22 29 0a 20 20 20 20 20 20 20 20 72 65 74 75  .").        retu
da70: 72 6e 20 22 64 69 65 22 0a 20 20 20 20 65 6c 73  rn "die".    els
da80: 65 3a 0a 20 20 20 20 20 20 23 20 47 6f 74 20 66  e:.      # Got f
da90: 61 74 61 6c 20 65 72 72 6f 72 2e 20 45 78 70 65  atal error. Expe
daa0: 63 74 20 6d 6f 6e 69 74 6f 72 20 70 72 6f 6d 70  ct monitor promp
dab0: 74 20 73 6f 20 73 74 61 74 65 20 6d 61 63 68 69  t so state machi
dac0: 6e 65 20 69 73 20 69 6e 20 74 68 65 20 72 69 67  ne is in the rig
dad0: 68 74 20 70 6c 61 63 65 2e 0a 20 20 20 20 20 20  ht place..      
dae0: 6d 6f 6e 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e  mon = self.simh.
daf0: 6f 73 38 5f 63 66 6d 5f 6d 6f 6e 69 74 6f 72 28  os8_cfm_monitor(
db00: 22 22 29 0a 20 20 20 20 20 20 69 66 20 6d 6f 6e  "").      if mon
db10: 3a 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a  : return "fail".
db20: 20 20 20 20 20 20 65 6c 73 65 3a 0a 20 20 20 20        else:.    
db30: 20 20 20 20 70 72 69 6e 74 20 28 22 6f 73 38 5f      print ("os8_
db40: 63 6f 6d 6d 61 6e 64 3a 20 46 61 69 6c 65 64 20  command: Failed 
db50: 74 6f 20 72 65 74 75 72 6e 20 74 6f 20 6d 6f 6e  to return to mon
db60: 69 74 6f 72 20 61 66 74 65 72 20 66 61 74 61 6c  itor after fatal
db70: 20 65 72 72 6f 72 2e 20 4b 69 6c 6c 69 6e 20 73   error. Killin s
db80: 63 72 69 70 74 2e 22 29 0a 20 20 20 20 20 20 20  cript.").       
db90: 20 72 65 74 75 72 6e 20 22 64 69 65 22 0a 0a 0a   return "die"...
dba0: 20 20 23 23 23 23 20 70 61 6c 38 5f 63 6f 6d 6d    #### pal8_comm
dbb0: 61 6e 64 20 23 23 23 23 23 23 23 23 23 23 23 23  and ############
dbc0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
dbd0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
dbe0: 23 23 23 23 23 23 23 23 0a 20 20 23 20 54 68 65  ########.  # The
dbf0: 20 22 70 61 6c 38 22 20 73 63 72 69 70 74 20 63   "pal8" script c
dc00: 6f 6d 6d 61 6e 64 20 63 6f 6d 65 73 20 69 6e 20  ommand comes in 
dc10: 74 77 6f 20 66 6f 72 6d 73 3a 0a 20 20 23 20 54  two forms:.  # T
dc20: 68 65 20 74 77 6f 20 61 72 67 75 6d 65 6e 74 20  he two argument 
dc30: 66 6f 72 6d 20 77 68 65 72 65 20 74 68 65 20 50  form where the P
dc40: 41 4c 38 20 73 74 61 74 75 73 20 69 73 20 70 72  AL8 status is pr
dc50: 69 6e 74 65 64 20 6f 6e 20 74 68 65 20 66 6c 79  inted on the fly
dc60: 0a 20 20 23 20 61 6e 64 20 74 68 65 20 33 20 61  .  # and the 3 a
dc70: 72 67 75 6d 65 6e 74 20 66 6f 72 6d 20 77 68 65  rgument form whe
dc80: 72 65 20 61 6c 6c 20 73 74 61 74 75 73 20 67 6f  re all status go
dc90: 65 73 20 69 6e 74 6f 20 74 68 65 20 6c 69 73 74  es into the list
dca0: 69 6e 67 20 66 69 6c 65 2e 0a 20 20 23 20 57 65  ing file..  # We
dcb0: 20 64 6f 20 74 68 65 20 33 20 61 72 67 75 6d 65   do the 3 argume
dcc0: 6e 74 20 66 6f 72 6d 20 77 69 74 68 20 61 20 73  nt form with a s
dcd0: 69 6d 70 6c 65 20 22 6f 73 38 22 20 73 63 72 69  imple "os8" scri
dce0: 70 74 20 63 6f 6d 6d 61 6e 64 2e 0a 20 20 0a 20  pt command..  . 
dcf0: 20 64 65 66 20 70 61 6c 38 5f 63 6f 6d 6d 61 6e   def pal8_comman
dd00: 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65 2c 20 73  d (self, line, s
dd10: 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a 20 20 20  cript_file):.   
dd20: 20 69 66 20 73 65 6c 66 2e 76 65 72 62 6f 73 65   if self.verbose
dd30: 3a 20 70 72 69 6e 74 28 22 52 75 6e 6e 69 6e 67  : print("Running
dd40: 20 50 41 4c 38 20 6f 6e 3a 20 22 20 2b 20 6c 69   PAL8 on: " + li
dd50: 6e 65 29 0a 20 20 20 20 72 65 70 6c 79 20 3d 20  ne).    reply = 
dd60: 73 65 6c 66 2e 63 68 65 63 6b 5f 61 6e 64 5f 72  self.check_and_r
dd70: 75 6e 28 22 70 61 6c 38 22 2c 20 22 52 20 50 41  un("pal8", "R PA
dd80: 4c 38 22 2c 20 73 63 72 69 70 74 5f 66 69 6c 65  L8", script_file
dd90: 29 0a 20 20 20 20 69 66 20 72 65 70 6c 79 20 3d  ).    if reply =
dda0: 3d 20 2d 31 3a 20 72 65 74 75 72 6e 20 22 64 69  = -1: return "di
ddb0: 65 22 0a 0a 20 20 20 20 69 66 20 73 65 6c 66 2e  e"..    if self.
ddc0: 73 69 6d 68 2e 6f 73 38 5f 74 65 73 74 5f 72 65  simh.os8_test_re
ddd0: 73 75 6c 74 20 28 72 65 70 6c 79 2c 20 22 43 6f  sult (reply, "Co
dde0: 6d 6d 61 6e 64 20 44 65 63 6f 64 65 72 20 50 72  mmand Decoder Pr
ddf0: 6f 6d 70 74 22 2c 20 22 63 61 6c 6c 5f 70 61 6c  ompt", "call_pal
de00: 38 22 29 20 3d 3d 20 46 61 6c 73 65 3a 0a 20 20  8") == False:.  
de10: 20 20 20 20 70 72 69 6e 74 28 22 50 41 4c 38 20      print("PAL8 
de20: 66 61 69 6c 65 64 20 74 6f 20 73 74 61 72 74 20  failed to start 
de30: 61 74 20 6c 69 6e 65 20 22 20 2b 20 73 74 72 28  at line " + str(
de40: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
de50: 63 6b 5b 30 5d 29 29 0a 20 20 20 20 20 20 72 65  ck[0])).      re
de60: 74 75 72 6e 20 22 66 61 69 6c 22 0a 0a 20 20 20  turn "fail"..   
de70: 20 69 66 20 73 65 6c 66 2e 76 65 72 62 6f 73 65   if self.verbose
de80: 3a 20 70 72 69 6e 74 28 22 4c 69 6e 65 3a 20 22  : print("Line: "
de90: 20 2b 20 5c 0a 20 20 20 20 20 20 20 73 74 72 28   + \.       str(
dea0: 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
deb0: 63 6b 5b 30 5d 29 20 2b 20 22 3a 20 70 61 6c 38  ck[0]) + ": pal8
dec0: 5f 63 6f 6d 6d 61 6e 64 3a 20 22 20 2b 20 6c 69  _command: " + li
ded0: 6e 65 29 0a 0a 20 20 20 20 23 20 53 65 6e 64 20  ne)..    # Send 
dee0: 6f 75 72 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65  our command line
def0: 20 61 72 67 73 20 61 6e 64 20 68 61 72 76 65 73   args and harves
df00: 74 20 72 65 73 75 6c 74 73 2e 0a 20 20 20 20 72  t results..    r
df10: 65 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68  eply = self.simh
df20: 2e 6f 73 38 5f 63 6d 64 20 28 6c 69 6e 65 2c 20  .os8_cmd (line, 
df30: 73 65 6c 66 2e 72 65 70 6c 69 65 73 5f 72 65 78  self.replies_rex
df40: 5b 22 70 61 6c 38 22 5d 29 0a 0a 20 20 20 20 65  ["pal8"])..    e
df50: 72 72 5f 63 6f 75 6e 74 20 3d 20 30 0a 20 20 20  rr_count = 0.   
df60: 20 65 78 65 63 75 74 65 64 5f 6c 69 6e 65 20 3d   executed_line =
df70: 20 73 65 6c 66 2e 73 69 6d 68 2e 5f 63 68 69 6c   self.simh._chil
df80: 64 2e 62 65 66 6f 72 65 2e 64 65 63 6f 64 65 28  d.before.decode(
df90: 29 2e 73 74 72 69 70 28 29 0a 20 20 20 20 6d 6f  ).strip().    mo
dfa0: 6e 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 74 65  n = self.simh.te
dfb0: 73 74 5f 72 65 73 75 6c 74 28 72 65 70 6c 79 2c  st_result(reply,
dfc0: 20 22 4d 6f 6e 69 74 6f 72 20 50 72 6f 6d 70 74   "Monitor Prompt
dfd0: 22 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73 5b  ", self.replies[
dfe0: 22 70 61 6c 38 22 5d 2c 20 22 22 29 0a 20 20 20  "pal8"], "").   
dff0: 20 65 72 72 5f 73 74 72 69 6e 67 20 3d 20 22 22   err_string = ""
e000: 0a 20 20 20 20 72 65 74 5f 76 61 6c 20 3d 20 22  .    ret_val = "
e010: 73 75 63 63 65 73 73 22 0a 20 20 20 20 65 78 70  success".    exp
e020: 65 63 74 5f 6c 6f 6f 70 20 3d 20 31 0a 0a 20 20  ect_loop = 1..  
e030: 20 20 23 20 57 65 27 72 65 20 67 6f 69 6e 67 20    # We're going 
e040: 74 6f 20 70 72 69 6e 74 20 61 6c 6c 20 74 68 65  to print all the
e050: 20 65 72 72 6f 72 73 20 77 65 20 73 65 65 0a 20   errors we see. 
e060: 20 20 20 23 20 61 6e 64 20 6b 65 65 70 20 6c 6f     # and keep lo
e070: 6f 6b 69 6e 67 20 74 69 6c 6c 20 77 65 20 67 65  oking till we ge
e080: 74 20 65 69 74 68 65 72 20 61 20 6d 6f 6e 69 74  t either a monit
e090: 6f 72 20 6f 72 20 63 6f 6d 6d 61 6e 64 20 64 65  or or command de
e0a0: 63 6f 64 65 72 20 70 72 6f 6d 70 74 2e 0a 20 20  coder prompt..  
e0b0: 20 20 77 68 69 6c 65 20 6e 6f 74 20 6d 6f 6e 3a    while not mon:
e0c0: 0a 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 64  .      if self.d
e0d0: 65 62 75 67 3a 20 70 72 69 6e 74 20 28 22 47 6f  ebug: print ("Go
e0e0: 74 20 72 65 70 6c 79 20 5b 22 20 2b 20 73 74 72  t reply [" + str
e0f0: 28 65 78 70 65 63 74 5f 6c 6f 6f 70 29 20 2b 22  (expect_loop) +"
e100: 5d 20 22 20 2b 20 73 74 72 28 72 65 70 6c 79 29  ] " + str(reply)
e110: 20 2b 20 22 20 2d 3e 20 22 20 2b 20 5c 0a 20 20   + " -> " + \.  
e120: 20 20 20 20 20 20 20 20 20 20 20 20 20 73 65 6c               sel
e130: 66 2e 72 65 70 6c 69 65 73 5b 22 70 61 6c 38 22  f.replies["pal8"
e140: 5d 20 5b 72 65 70 6c 79 5d 5b 30 5d 29 0a 0a 20  ] [reply][0]).. 
e150: 20 20 20 20 20 65 64 20 20 3d 20 73 65 6c 66 2e       ed  = self.
e160: 73 69 6d 68 2e 74 65 73 74 5f 72 65 73 75 6c 74  simh.test_result
e170: 28 72 65 70 6c 79 2c 20 22 45 52 52 4f 52 53 20  (reply, "ERRORS 
e180: 44 45 54 45 43 54 45 44 22 2c 20 73 65 6c 66 2e  DETECTED", self.
e190: 72 65 70 6c 69 65 73 5b 22 70 61 6c 38 22 5d 2c  replies["pal8"],
e1a0: 20 22 22 29 0a 20 20 20 20 20 20 63 64 20 20 3d   "").      cd  =
e1b0: 20 73 65 6c 66 2e 73 69 6d 68 2e 74 65 73 74 5f   self.simh.test_
e1c0: 72 65 73 75 6c 74 28 72 65 70 6c 79 2c 20 22 43  result(reply, "C
e1d0: 6f 6d 6d 61 6e 64 20 44 65 63 6f 64 65 72 20 50  ommand Decoder P
e1e0: 72 6f 6d 70 74 22 2c 20 73 65 6c 66 2e 72 65 70  rompt", self.rep
e1f0: 6c 69 65 73 5b 22 70 61 6c 38 22 5d 2c 20 22 22  lies["pal8"], ""
e200: 29 0a 20 20 20 20 20 20 6c 67 20 20 3d 20 73 65  ).      lg  = se
e210: 6c 66 2e 73 69 6d 68 2e 74 65 73 74 5f 72 65 73  lf.simh.test_res
e220: 75 6c 74 28 72 65 70 6c 79 2c 20 22 4c 49 4e 4b  ult(reply, "LINK
e230: 53 20 47 45 4e 45 52 41 54 45 44 22 2c 20 73 65  S GENERATED", se
e240: 6c 66 2e 72 65 70 6c 69 65 73 5b 22 70 61 6c 38  lf.replies["pal8
e250: 22 5d 2c 20 22 22 29 0a 20 0a 20 20 20 20 20 20  "], ""). .      
e260: 69 66 20 65 64 3a 20 20 20 23 20 47 6f 74 20 45  if ed:   # Got E
e270: 72 72 6f 72 73 20 44 65 74 65 63 74 65 64 2e 20  rrors Detected. 
e280: 43 6f 75 6e 74 20 74 68 65 6d 2e 0a 20 20 20 20  Count them..    
e290: 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 5f 63      self.simh._c
e2a0: 68 69 6c 64 2e 65 78 70 65 63 74 28 72 22 5c 64  hild.expect(r"\d
e2b0: 2b 22 29 0a 20 20 20 20 20 20 20 20 65 72 72 5f  +").        err_
e2c0: 63 6f 75 6e 74 20 3d 20 69 6e 74 28 73 65 6c 66  count = int(self
e2d0: 2e 73 69 6d 68 2e 63 68 69 6c 64 5f 61 66 74 65  .simh.child_afte
e2e0: 72 28 29 2e 73 74 72 69 70 28 29 29 0a 20 20 20  r().strip()).   
e2f0: 20 20 20 65 6c 69 66 20 6c 67 3a 20 0a 20 20 20     elif lg: .   
e300: 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 5f       self.simh._
e310: 63 68 69 6c 64 2e 65 78 70 65 63 74 28 72 22 5c  child.expect(r"\
e320: 64 2b 22 29 0a 20 20 20 20 20 20 20 20 6c 69 6e  d+").        lin
e330: 6b 5f 63 6f 75 6e 74 20 3d 20 69 6e 74 28 73 65  k_count = int(se
e340: 6c 66 2e 73 69 6d 68 2e 63 68 69 6c 64 5f 61 66  lf.simh.child_af
e350: 74 65 72 28 29 2e 73 74 72 69 70 28 29 29 0a 20  ter().strip()). 
e360: 20 20 20 20 20 65 6c 69 66 20 63 64 3a 20 23 20       elif cd: # 
e370: 47 6f 74 20 43 6f 6d 6d 61 6e 64 20 44 65 63 6f  Got Command Deco
e380: 64 65 72 2e 20 45 78 69 74 20 77 69 74 68 20 66  der. Exit with f
e390: 61 69 6c 75 72 65 2e 0a 20 20 20 20 20 20 20 20  ailure..        
e3a0: 69 66 20 73 65 6c 66 2e 64 65 62 75 67 3a 20 70  if self.debug: p
e3b0: 72 69 6e 74 20 28 22 63 61 6c 6c 5f 70 61 6c 38  rint ("call_pal8
e3c0: 3a 20 4e 6f 6e 2d 66 61 74 61 6c 20 65 72 72 6f  : Non-fatal erro
e3d0: 72 3a 20 53 65 6e 64 69 6e 67 20 5e 43 22 29 0a  r: Sending ^C").
e3e0: 20 20 20 20 20 20 20 20 23 20 45 78 69 74 20 70          # Exit p
e3f0: 61 6c 38 2e 20 57 65 27 6c 6c 20 63 6f 6e 66 69  al8. We'll confi
e400: 72 6d 20 77 65 20 67 6f 74 20 62 61 63 6b 20 74  rm we got back t
e410: 6f 20 4f 53 2f 38 20 6d 6f 6e 69 74 6f 72 20 62  o OS/8 monitor b
e420: 65 6c 6f 77 2e 0a 20 20 20 20 20 20 20 20 73 65  elow..        se
e430: 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 73 65 6e 64  lf.simh.os8_send
e440: 5f 63 74 72 6c 20 28 27 63 27 29 20 20 20 20 20  _ctrl ('c')     
e450: 20 0a 20 20 20 20 20 20 65 6c 73 65 3a 0a 20 20   .      else:.  
e460: 20 20 20 20 20 20 65 72 72 5f 73 74 72 69 6e 67        err_string
e470: 20 2b 3d 20 28 22 5c 74 22 20 2b 20 73 65 6c 66   += ("\t" + self
e480: 2e 73 69 6d 68 2e 63 68 69 6c 64 5f 61 66 74 65  .simh.child_afte
e490: 72 28 29 2e 73 74 72 69 70 28 29 20 2b 20 22 5c  r().strip() + "\
e4a0: 6e 22 29 0a 20 20 20 20 20 20 20 20 0a 20 20 20  n").        .   
e4b0: 20 20 20 65 78 70 65 63 74 5f 6c 6f 6f 70 20 2b     expect_loop +
e4c0: 3d 20 31 0a 20 20 20 20 20 20 72 65 70 6c 79 20  = 1.      reply 
e4d0: 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 5f 63 68 69  = self.simh._chi
e4e0: 6c 64 2e 65 78 70 65 63 74 28 73 65 6c 66 2e 72  ld.expect(self.r
e4f0: 65 70 6c 69 65 73 5f 72 65 78 5b 22 70 61 6c 38  eplies_rex["pal8
e500: 22 5d 29 0a 20 20 20 20 20 20 6d 6f 6e 20 3d 20  "]).      mon = 
e510: 73 65 6c 66 2e 73 69 6d 68 2e 74 65 73 74 5f 72  self.simh.test_r
e520: 65 73 75 6c 74 28 72 65 70 6c 79 2c 20 22 4d 6f  esult(reply, "Mo
e530: 6e 69 74 6f 72 20 50 72 6f 6d 70 74 22 2c 20 73  nitor Prompt", s
e540: 65 6c 66 2e 72 65 70 6c 69 65 73 5b 22 70 61 6c  elf.replies["pal
e550: 38 22 5d 2c 20 22 22 29 0a 20 20 20 20 69 66 20  8"], "").    if 
e560: 65 72 72 5f 63 6f 75 6e 74 20 3e 20 30 20 6f 72  err_count > 0 or
e570: 20 65 72 72 5f 73 74 72 69 6e 67 20 21 3d 20 22   err_string != "
e580: 22 3a 0a 20 20 20 20 20 20 70 72 69 6e 74 20 28  ":.      print (
e590: 22 50 41 4c 38 20 45 72 72 6f 72 3a 20 5c 6e 5c  "PAL8 Error: \n\
e5a0: 74 22 20 2b 20 65 78 65 63 75 74 65 64 5f 6c 69  t" + executed_li
e5b0: 6e 65 29 0a 20 20 20 20 20 20 70 72 69 6e 74 20  ne).      print 
e5c0: 28 65 72 72 5f 73 74 72 69 6e 67 29 0a 20 20 20  (err_string).   
e5d0: 20 20 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22     return "fail"
e5e0: 0a 20 20 20 20 72 65 74 75 72 6e 20 22 73 75 63  .    return "suc
e5f0: 63 65 73 73 22 0a 0a 0a 20 20 23 23 23 23 20 6f  cess"...  #### o
e600: 63 6f 6d 70 5f 63 6f 6d 6d 61 6e 64 20 23 23 23  comp_command ###
e610: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
e620: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
e630: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
e640: 0a 20 20 23 20 54 68 69 73 20 63 6f 6d 6d 61 6e  .  # This comman
e650: 64 20 77 69 6c 6c 20 62 65 20 75 73 65 64 20 74  d will be used t
e660: 6f 20 63 6f 6d 70 61 72 65 20 66 69 6c 65 73 20  o compare files 
e670: 69 6e 20 32 20 70 6c 61 63 65 73 20 61 6e 64 0a  in 2 places and.
e680: 20 20 23 20 52 65 74 75 72 6e 20 73 75 63 63 65    # Return succe
e690: 73 73 20 69 66 20 74 68 65 79 20 61 72 65 20 74  ss if they are t
e6a0: 68 65 20 73 61 6d 65 2c 20 61 6e 64 20 72 65 74  he same, and ret
e6b0: 75 72 6e 20 66 61 69 6c 75 72 65 20 69 66 0a 20  urn failure if. 
e6c0: 20 23 20 6f 6e 65 20 6f 72 20 74 68 65 20 6f 74   # one or the ot
e6d0: 68 65 72 20 69 73 20 6d 69 73 73 69 6e 67 2c 20  her is missing, 
e6e0: 6f 72 20 69 66 20 74 68 65 79 20 61 72 65 20 64  or if they are d
e6f0: 69 66 66 65 72 65 6e 74 2e 0a 20 20 23 20 54 68  ifferent..  # Th
e700: 69 73 20 72 65 71 75 69 72 65 73 20 6d 61 6b 69  is requires maki
e710: 6e 67 20 61 6e 20 69 6e 74 65 72 70 72 65 74 61  ng an interpreta
e720: 74 69 6f 6e 20 6f 66 20 74 68 65 20 6f 75 74 70  tion of the outp
e730: 75 74 20 74 68 61 74 20 69 73 0a 20 20 23 20 64  ut that is.  # d
e740: 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20 74 68  ifferent from th
e750: 65 20 65 78 70 65 63 74 65 64 20 22 6f 63 74 61  e expected "octa
e760: 6c 20 64 75 6d 70 20 6f 66 20 64 69 66 66 65 72  l dump of differ
e770: 65 6e 63 65 73 22 20 75 73 65 20 63 61 73 65 2e  ences" use case.
e780: 0a 20 20 23 20 22 4e 4f 54 48 49 4e 47 20 4f 55  .  # "NOTHING OU
e790: 54 50 55 54 22 20 6d 65 61 6e 73 20 73 75 63 63  TPUT" means succ
e7a0: 65 73 73 2e 0a 20 20 23 20 41 6e 79 20 22 55 53  ess..  # Any "US
e7b0: 45 52 20 45 52 52 4f 52 22 20 6f 75 74 70 75 74  ER ERROR" output
e7c0: 20 6d 65 61 6e 73 20 66 61 69 6c 75 72 65 2e 0a   means failure..
e7d0: 0a 20 20 64 65 66 20 6f 63 6f 6d 70 5f 63 6f 6d  .  def ocomp_com
e7e0: 6d 61 6e 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65  mand (self, line
e7f0: 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a  , script_file):.
e800: 20 20 20 20 69 66 20 73 65 6c 66 2e 76 65 72 62      if self.verb
e810: 6f 73 65 3a 20 70 72 69 6e 74 28 22 52 75 6e 6e  ose: print("Runn
e820: 69 6e 67 20 4f 43 4f 4d 50 20 6f 6e 3a 20 22 20  ing OCOMP on: " 
e830: 2b 20 6c 69 6e 65 29 0a 20 20 20 20 72 65 70 6c  + line).    repl
e840: 79 20 3d 20 73 65 6c 66 2e 63 68 65 63 6b 5f 61  y = self.check_a
e850: 6e 64 5f 72 75 6e 28 22 6f 63 6f 6d 70 22 2c 20  nd_run("ocomp", 
e860: 22 52 20 4f 43 4f 4d 50 22 2c 20 73 63 72 69 70  "R OCOMP", scrip
e870: 74 5f 66 69 6c 65 29 0a 20 20 20 20 69 66 20 72  t_file).    if r
e880: 65 70 6c 79 20 3d 3d 20 2d 31 3a 20 72 65 74 75  eply == -1: retu
e890: 72 6e 20 22 64 69 65 22 0a 0a 20 20 20 20 69 66  rn "die"..    if
e8a0: 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 74   self.simh.os8_t
e8b0: 65 73 74 5f 72 65 73 75 6c 74 20 28 72 65 70 6c  est_result (repl
e8c0: 79 2c 20 22 43 6f 6d 6d 61 6e 64 20 44 65 63 6f  y, "Command Deco
e8d0: 64 65 72 20 50 72 6f 6d 70 74 22 2c 20 22 63 61  der Prompt", "ca
e8e0: 6c 6c 5f 6f 63 6f 6d 70 22 29 20 3d 3d 20 46 61  ll_ocomp") == Fa
e8f0: 6c 73 65 3a 0a 20 20 20 20 20 20 70 72 69 6e 74  lse:.      print
e900: 28 22 4f 43 4f 4d 50 20 66 61 69 6c 65 64 20 74  ("OCOMP failed t
e910: 6f 20 73 74 61 72 74 20 61 74 20 6c 69 6e 65 20  o start at line 
e920: 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e  " + str(self.lin
e930: 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 29 0a  e_ct_stack[0])).
e940: 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 66 61        return "fa
e950: 69 6c 22 0a 0a 20 20 20 20 69 66 20 73 65 6c 66  il"..    if self
e960: 2e 76 65 72 62 6f 73 65 3a 20 70 72 69 6e 74 28  .verbose: print(
e970: 22 4c 69 6e 65 3a 20 22 20 2b 20 5c 0a 20 20 20  "Line: " + \.   
e980: 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e      str(self.lin
e990: 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b  e_ct_stack[0]) +
e9a0: 20 22 3a 20 6f 63 6f 6d 70 5f 63 6f 6d 6d 61 6e   ": ocomp_comman
e9b0: 64 3a 20 22 20 2b 20 6c 69 6e 65 29 0a 0a 20 20  d: " + line)..  
e9c0: 20 20 23 20 53 65 6e 64 20 6f 75 72 20 63 6f 6d    # Send our com
e9d0: 6d 61 6e 64 20 61 6e 64 20 68 61 72 76 65 73 74  mand and harvest
e9e0: 20 72 65 73 75 6c 74 73 2e 0a 20 20 20 20 72 65   results..    re
e9f0: 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e  ply = self.simh.
ea00: 6f 73 38 5f 63 6d 64 20 28 6c 69 6e 65 2c 20 73  os8_cmd (line, s
ea10: 65 6c 66 2e 72 65 70 6c 69 65 73 5f 72 65 78 5b  elf.replies_rex[
ea20: 22 6f 63 6f 6d 70 22 5d 29 0a 20 20 20 20 69 66  "ocomp"]).    if
ea30: 20 22 74 72 61 6e 73 63 72 69 70 74 22 20 69 6e   "transcript" in
ea40: 20 73 65 6c 66 2e 6f 70 74 69 6f 6e 73 5f 65 6e   self.options_en
ea50: 61 62 6c 65 64 3a 0a 20 20 20 20 20 20 70 72 69  abled:.      pri
ea60: 6e 74 20 28 73 65 6c 66 2e 73 69 6d 68 2e 5f 63  nt (self.simh._c
ea70: 68 69 6c 64 2e 62 65 66 6f 72 65 2e 64 65 63 6f  hild.before.deco
ea80: 64 65 28 29 2e 73 74 72 69 70 28 29 29 0a 0a 20  de().strip()).. 
ea90: 20 20 20 72 65 74 5f 76 61 6c 20 3d 20 22 66 61     ret_val = "fa
eaa0: 69 6c 22 0a 20 20 20 20 65 78 70 65 63 74 5f 6c  il".    expect_l
eab0: 6f 6f 70 20 3d 20 31 0a 0a 20 20 20 20 6d 6f 6e  oop = 1..    mon
eac0: 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 74 65 73   = self.simh.tes
ead0: 74 5f 72 65 73 75 6c 74 28 72 65 70 6c 79 2c 20  t_result(reply, 
eae0: 22 4d 6f 6e 69 74 6f 72 20 50 72 6f 6d 70 74 22  "Monitor Prompt"
eaf0: 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73 5b 22  , self.replies["
eb00: 6f 63 6f 6d 70 22 5d 2c 20 22 22 29 0a 20 20 20  ocomp"], "").   
eb10: 20 23 20 57 65 20 67 65 74 20 72 65 74 75 72 6e   # We get return
eb20: 20 73 74 61 74 75 73 20 61 6e 64 20 74 68 65 6e   status and then
eb30: 20 63 6c 65 61 6e 20 75 70 20 74 68 65 20 73 74   clean up the st
eb40: 61 74 65 20 6d 61 63 68 69 6e 65 2e 0a 20 20 20  ate machine..   
eb50: 20 77 68 69 6c 65 20 6e 6f 74 20 6d 6f 6e 3a 0a   while not mon:.
eb60: 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65        if self.de
eb70: 62 75 67 3a 0a 20 20 20 20 20 20 20 20 70 72 69  bug:.        pri
eb80: 6e 74 20 28 22 6f 63 6f 6d 70 20 67 61 76 65 20  nt ("ocomp gave 
eb90: 72 65 70 6c 79 3a 20 5b 22 20 2b 20 73 74 72 28  reply: [" + str(
eba0: 65 78 70 65 63 74 5f 6c 6f 6f 70 29 20 2b 22 5d  expect_loop) +"]
ebb0: 20 22 20 2b 20 73 74 72 28 72 65 70 6c 79 29 20   " + str(reply) 
ebc0: 2b 20 22 20 2d 3e 20 22 20 2b 20 5c 0a 20 20 20  + " -> " + \.   
ebd0: 20 20 20 20 20 20 20 20 20 20 73 65 6c 66 2e 72            self.r
ebe0: 65 70 6c 69 65 73 5b 22 6f 63 6f 6d 70 22 5d 5b  eplies["ocomp"][
ebf0: 72 65 70 6c 79 5d 5b 30 5d 29 0a 20 20 20 20 20  reply][0]).     
ec00: 20 6f 6b 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e   ok = self.simh.
ec10: 74 65 73 74 5f 72 65 73 75 6c 74 28 72 65 70 6c  test_result(repl
ec20: 79 2c 20 22 4e 4f 54 48 49 4e 47 20 4f 55 54 50  y, "NOTHING OUTP
ec30: 55 54 22 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65  UT", self.replie
ec40: 73 5b 22 6f 63 6f 6d 70 22 5d 2c 20 22 22 29 0a  s["ocomp"], "").
ec50: 20 20 20 20 20 20 63 64 20 20 3d 20 73 65 6c 66        cd  = self
ec60: 2e 73 69 6d 68 2e 74 65 73 74 5f 72 65 73 75 6c  .simh.test_resul
ec70: 74 28 72 65 70 6c 79 2c 20 22 43 6f 6d 6d 61 6e  t(reply, "Comman
ec80: 64 20 44 65 63 6f 64 65 72 20 50 72 6f 6d 70 74  d Decoder Prompt
ec90: 22 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73 5b  ", self.replies[
eca0: 22 6f 63 6f 6d 70 22 5d 2c 20 22 22 29 0a 20 20  "ocomp"], "").  
ecb0: 20 20 20 20 6e 66 20 3d 20 73 65 6c 66 2e 73 69      nf = self.si
ecc0: 6d 68 2e 74 65 73 74 5f 72 65 73 75 6c 74 28 72  mh.test_result(r
ecd0: 65 70 6c 79 2c 20 22 46 69 6c 65 20 6e 6f 74 20  eply, "File not 
ece0: 66 6f 75 6e 64 22 2c 20 73 65 6c 66 2e 72 65 70  found", self.rep
ecf0: 6c 69 65 73 5b 22 6f 63 6f 6d 70 22 5d 2c 20 22  lies["ocomp"], "
ed00: 22 29 0a 20 20 20 20 20 20 75 65 20 3d 20 73 65  ").      ue = se
ed10: 6c 66 2e 73 69 6d 68 2e 74 65 73 74 5f 72 65 73  lf.simh.test_res
ed20: 75 6c 74 28 72 65 70 6c 79 2c 20 22 55 53 45 52  ult(reply, "USER
ed30: 20 45 52 52 4f 52 22 2c 20 73 65 6c 66 2e 72 65   ERROR", self.re
ed40: 70 6c 69 65 73 5b 22 6f 63 6f 6d 70 22 5d 2c 20  plies["ocomp"], 
ed50: 22 22 29 0a 0a 20 20 20 20 20 20 69 66 20 6f 6b  "")..      if ok
ed60: 3a 0a 20 20 20 20 20 20 20 20 69 66 20 73 65 6c  :.        if sel
ed70: 66 2e 64 65 62 75 67 3a 20 70 72 69 6e 74 20 28  f.debug: print (
ed80: 22 53 75 63 63 65 73 73 22 29 0a 20 20 20 20 20  "Success").     
ed90: 20 20 20 72 65 74 5f 76 61 6c 20 3d 20 22 73 75     ret_val = "su
eda0: 63 63 65 73 73 22 0a 20 20 20 20 20 20 65 6c 69  ccess".      eli
edb0: 66 20 6e 66 20 6f 72 20 75 65 3a 0a 20 20 20 20  f nf or ue:.    
edc0: 20 20 20 20 70 72 69 6e 74 20 28 22 4f 43 4f 4d      print ("OCOM
edd0: 50 3a 22 20 2b 20 73 65 6c 66 2e 73 69 6d 68 2e  P:" + self.simh.
ede0: 63 68 69 6c 64 5f 61 66 74 65 72 28 29 2e 73 74  child_after().st
edf0: 72 69 70 28 29 20 2b 20 22 5c 6e 22 29 0a 20 20  rip() + "\n").  
ee00: 20 20 20 20 65 6c 69 66 20 63 64 3a 20 23 20 47      elif cd: # G
ee10: 6f 74 20 43 6f 6d 6d 61 6e 64 20 44 65 63 6f 64  ot Command Decod
ee20: 65 72 2e 20 45 78 69 74 20 77 69 74 68 20 66 61  er. Exit with fa
ee30: 69 6c 75 72 65 2e 0a 20 20 20 20 20 20 20 20 69  ilure..        i
ee40: 66 20 73 65 6c 66 2e 64 65 62 75 67 3a 20 70 72  f self.debug: pr
ee50: 69 6e 74 20 28 22 63 61 6c 6c 5f 6f 63 6f 6d 70  int ("call_ocomp
ee60: 3a 20 4e 6f 6e 2d 66 61 74 61 6c 20 65 72 72 6f  : Non-fatal erro
ee70: 72 3a 20 53 65 6e 64 69 6e 67 20 5e 43 22 29 0a  r: Sending ^C").
ee80: 20 20 20 20 20 20 20 20 23 20 45 78 69 74 20 4f          # Exit O
ee90: 43 4f 4d 50 2e 20 57 65 27 6c 6c 20 63 6f 6e 66  COMP. We'll conf
eea0: 69 72 6d 20 77 65 20 67 6f 74 20 62 61 63 6b 20  irm we got back 
eeb0: 74 6f 20 4f 53 2f 38 20 6d 6f 6e 69 74 6f 72 20  to OS/8 monitor 
eec0: 62 65 6c 6f 77 2e 0a 20 20 20 20 20 20 20 20 73  below..        s
eed0: 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 73 65 6e  elf.simh.os8_sen
eee0: 64 5f 63 74 72 6c 20 28 27 63 27 29 20 20 20 20  d_ctrl ('c')    
eef0: 20 20 0a 0a 20 20 20 20 20 20 72 65 70 6c 79 20    ..      reply 
ef00: 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 5f 63 68 69  = self.simh._chi
ef10: 6c 64 2e 65 78 70 65 63 74 28 73 65 6c 66 2e 72  ld.expect(self.r
ef20: 65 70 6c 69 65 73 5f 72 65 78 5b 22 6f 63 6f 6d  eplies_rex["ocom
ef30: 70 22 5d 29 0a 0a 20 20 20 20 20 20 69 66 20 22  p"])..      if "
ef40: 74 72 61 6e 73 63 72 69 70 74 22 20 69 6e 20 73  transcript" in s
ef50: 65 6c 66 2e 6f 70 74 69 6f 6e 73 5f 65 6e 61 62  elf.options_enab
ef60: 6c 65 64 3a 0a 20 20 20 20 20 20 20 20 70 72 69  led:.        pri
ef70: 6e 74 20 28 73 65 6c 66 2e 73 69 6d 68 2e 5f 63  nt (self.simh._c
ef80: 68 69 6c 64 2e 62 65 66 6f 72 65 2e 64 65 63 6f  hild.before.deco
ef90: 64 65 28 29 2e 73 74 72 69 70 28 29 29 0a 0a 20  de().strip()).. 
efa0: 20 20 20 20 20 65 78 70 65 63 74 5f 6c 6f 6f 70       expect_loop
efb0: 20 2b 3d 20 31 0a 0a 20 20 20 20 20 20 6d 6f 6e   += 1..      mon
efc0: 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 74 65 73   = self.simh.tes
efd0: 74 5f 72 65 73 75 6c 74 28 72 65 70 6c 79 2c 20  t_result(reply, 
efe0: 22 4d 6f 6e 69 74 6f 72 20 50 72 6f 6d 70 74 22  "Monitor Prompt"
eff0: 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73 5b 22  , self.replies["
f000: 6f 63 6f 6d 70 22 5d 2c 20 22 22 29 0a 0a 20 20  ocomp"], "")..  
f010: 20 20 72 65 74 75 72 6e 20 72 65 74 5f 76 61 6c    return ret_val
f020: 0a 0a 20 20 0a 20 20 23 23 23 23 20 62 65 67 69  ..  .  #### begi
f030: 6e 5f 63 6f 6d 6d 61 6e 64 20 23 23 23 23 23 23  n_command ######
f040: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
f050: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
f060: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 20 20  #############.  
f070: 0a 20 20 64 65 66 20 62 65 67 69 6e 5f 63 6f 6d  .  def begin_com
f080: 6d 61 6e 64 20 28 73 65 6c 66 2c 20 6c 69 6e 65  mand (self, line
f090: 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 29 3a 0a  , script_file):.
f0a0: 20 20 20 20 69 66 20 6e 6f 74 20 73 65 6c 66 2e      if not self.
f0b0: 62 6f 6f 74 65 64 3a 0a 20 20 20 20 20 20 70 72  booted:.      pr
f0c0: 69 6e 74 28 22 43 61 6e 6e 6f 74 20 65 78 65 63  int("Cannot exec
f0d0: 75 74 65 20 62 65 67 69 6e 20 73 75 62 63 6f 6d  ute begin subcom
f0e0: 6d 61 6e 64 20 62 6c 6f 63 6b 20 61 74 20 6c 69  mand block at li
f0f0: 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20  ne " + \.       
f100: 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63   str(self.line_c
f110: 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 2e  t_stack[0]) + ".
f120: 20 4f 53 2f 38 20 68 61 73 20 6e 6f 74 20 62 65   OS/8 has not be
f130: 65 6e 20 62 6f 6f 74 65 64 2e 22 29 0a 20 20 20  en booted.").   
f140: 20 20 20 72 65 74 75 72 6e 20 22 64 69 65 22 0a     return "die".
f150: 0a 20 20 20 20 73 75 62 5f 63 6f 6d 6d 61 6e 64  .    sub_command
f160: 73 20 3d 20 7b 22 62 75 69 6c 64 22 3a 20 73 65  s = {"build": se
f170: 6c 66 2e 62 75 69 6c 64 5f 73 75 62 63 6f 6d 6d  lf.build_subcomm
f180: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
f190: 20 20 20 20 20 20 22 63 64 70 72 6f 67 22 3a 20        "cdprog": 
f1a0: 73 65 6c 66 2e 63 64 70 72 6f 67 5f 73 75 62 63  self.cdprog_subc
f1b0: 6f 6d 6d 7d 0a 20 20 0a 20 20 20 20 6d 20 3d 20  omm}.  .    m = 
f1c0: 72 65 2e 6d 61 74 63 68 28 5f 63 6f 6d 6d 5f 72  re.match(_comm_r
f1d0: 65 2c 20 6c 69 6e 65 29 0a 20 20 20 20 69 66 20  e, line).    if 
f1e0: 6d 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20  m == None:.     
f1f0: 20 70 72 69 6e 74 28 22 43 6f 75 6c 64 20 6e 6f   print("Could no
f200: 74 20 70 61 72 73 65 20 73 75 62 2d 63 6f 6d 6d  t parse sub-comm
f210: 61 6e 64 20 61 74 20 6c 69 6e 65 20 22 20 2b 20  and at line " + 
f220: 5c 0a 20 20 20 20 20 20 20 20 73 74 72 28 73 65  \.        str(se
f230: 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b  lf.line_ct_stack
f240: 5b 30 5d 29 20 2b 20 22 3a 20 22 20 2b 20 6c 69  [0]) + ": " + li
f250: 6e 65 29 0a 20 20 20 20 69 66 20 6d 2e 67 72 6f  ne).    if m.gro
f260: 75 70 28 31 29 20 6e 6f 74 20 69 6e 20 73 75 62  up(1) not in sub
f270: 5f 63 6f 6d 6d 61 6e 64 73 3a 0a 20 20 20 20 20  _commands:.     
f280: 20 70 72 69 6e 74 28 22 49 67 6e 6f 72 69 6e 67   print("Ignoring
f290: 20 75 6e 72 65 63 6f 67 6e 69 7a 65 64 20 73 75   unrecognized su
f2a0: 62 2d 63 6f 6d 6d 61 6e 64 20 61 74 20 6c 69 6e  b-command at lin
f2b0: 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  e " + \.        
f2c0: 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74  str(self.line_ct
f2d0: 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 3a 20  _stack[0]) + ": 
f2e0: 22 20 2b 20 6d 2e 67 72 6f 75 70 28 31 29 29 0a  " + m.group(1)).
f2f0: 20 20 20 20 20 20 70 72 69 6e 74 28 22 49 67 6e        print("Ign
f300: 6f 72 69 6e 67 20 65 76 65 72 79 74 68 69 6e 67  oring everything
f310: 20 74 6f 20 6e 65 78 74 20 65 6e 64 2e 22 29 0a   to next end.").
f320: 20 20 20 20 20 20 73 65 6c 66 2e 69 67 6e 6f 72        self.ignor
f330: 65 5f 74 6f 5f 73 75 62 63 6f 6d 6d 5f 65 6e 64  e_to_subcomm_end
f340: 28 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f 66 69  (line, script_fi
f350: 6c 65 2c 20 22 22 29 0a 20 20 20 20 20 20 72 65  le, "").      re
f360: 74 75 72 6e 20 22 66 61 69 6c 22 0a 20 20 20 20  turn "fail".    
f370: 65 6c 73 65 3a 0a 20 20 20 20 20 20 23 20 41 6e  else:.      # An
f380: 79 20 6f 73 38 2d 72 75 6e 20 63 6f 6d 6d 61 6e  y os8-run comman
f390: 64 20 6d 61 79 20 62 65 20 63 61 6c 6c 65 64 20  d may be called 
f3a0: 61 66 74 65 72 20 61 20 73 69 6d 68 20 63 6f 6d  after a simh com
f3b0: 6d 61 6e 64 20 74 68 61 74 20 6c 65 66 74 20 75  mand that left u
f3c0: 73 0a 20 20 20 20 20 20 23 20 69 6e 20 73 69 6d  s.      # in sim
f3d0: 68 20 63 6f 6e 74 65 78 74 2e 20 43 68 65 63 6b  h context. Check
f3e0: 20 74 6f 20 73 65 65 20 69 66 20 77 65 20 6e 65   to see if we ne
f3f0: 65 64 20 74 6f 20 72 65 73 74 61 72 74 20 4f 53  ed to restart OS
f400: 2f 38 2e 0a 20 20 20 20 20 20 23 20 57 65 20 63  /8..      # We c
f410: 6f 75 6c 64 20 72 65 73 75 6d 65 2c 20 62 75 74  ould resume, but
f420: 20 72 65 73 74 61 72 74 20 69 73 20 73 61 66 65   restart is safe
f430: 72 2e 0a 20 20 20 20 20 20 69 66 20 73 65 6c 66  r..      if self
f440: 2e 73 69 6d 68 2e 5f 63 6f 6e 74 65 78 74 20 3d  .simh._context =
f450: 3d 20 22 73 69 6d 68 22 3a 0a 20 20 20 20 20 20  = "simh":.      
f460: 20 20 73 65 6c 66 2e 72 65 73 74 61 72 74 5f 63    self.restart_c
f470: 6f 6d 6d 61 6e 64 28 6c 69 6e 65 2c 20 73 63 72  ommand(line, scr
f480: 69 70 74 5f 66 69 6c 65 29 0a 0a 20 20 20 20 20  ipt_file)..     
f490: 20 72 65 74 75 72 6e 20 73 75 62 5f 63 6f 6d 6d   return sub_comm
f4a0: 61 6e 64 73 5b 6d 2e 67 72 6f 75 70 28 31 29 5d  ands[m.group(1)]
f4b0: 28 6d 2e 67 72 6f 75 70 28 33 29 2c 20 73 63 72  (m.group(3), scr
f4c0: 69 70 74 5f 66 69 6c 65 29 0a 20 20 0a 20 20 0a  ipt_file).  .  .
f4d0: 20 20 23 23 23 23 20 62 75 69 6c 64 5f 73 75 62    #### build_sub
f4e0: 63 6f 6d 6d 20 23 23 23 23 23 23 23 23 23 23 23  comm ###########
f4f0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
f500: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
f510: 23 23 23 23 23 23 23 23 0a 20 20 23 20 52 75 6e  ########.  # Run
f520: 20 73 79 73 74 65 6d 20 42 55 49 4c 44 20 63 6f   system BUILD co
f530: 6d 6d 61 6e 64 2e 0a 20 20 23 20 55 73 65 20 52  mmand..  # Use R
f540: 55 20 6e 6f 74 20 52 20 62 65 63 61 75 73 65 20  U not R because 
f550: 77 65 20 77 69 6c 6c 20 73 61 76 65 20 69 74 2e  we will save it.
f560: 0a 20 20 23 20 41 6c 6c 6f 77 20 73 70 65 63 69  .  # Allow speci
f570: 66 79 69 6e 67 20 57 48 49 43 48 20 76 65 72 73  fying WHICH vers
f580: 69 6f 6e 20 6f 66 20 62 75 69 6c 64 20 6f 6e 20  ion of build on 
f590: 74 68 65 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65  the command line
f5a0: 2e 0a 20 20 0a 20 20 64 65 66 20 62 75 69 6c 64  ..  .  def build
f5b0: 5f 73 75 62 63 6f 6d 6d 20 28 73 65 6c 66 2c 20  _subcomm (self, 
f5c0: 6f 6c 64 5f 6c 69 6e 65 2c 20 73 63 72 69 70 74  old_line, script
f5d0: 5f 66 69 6c 65 29 3a 0a 20 20 20 20 6f 73 38 5f  _file):.    os8_
f5e0: 63 6f 6d 6d 20 3d 20 22 52 55 20 22 20 2b 20 6f  comm = "RU " + o
f5f0: 6c 64 5f 6c 69 6e 65 0a 20 20 20 20 69 66 20 73  ld_line.    if s
f600: 65 6c 66 2e 76 65 72 62 6f 73 65 3a 0a 20 20 20  elf.verbose:.   
f610: 20 20 20 70 72 69 6e 74 28 22 4c 69 6e 65 20 22     print("Line "
f620: 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65   + str(self.line
f630: 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20  _ct_stack[0]) + 
f640: 22 3a 20 22 20 2b 20 6f 73 38 5f 63 6f 6d 6d 29  ": " + os8_comm)
f650: 0a 0a 20 20 20 20 23 20 52 75 6e 20 42 55 49 4c  ..    # Run BUIL
f660: 44 20 61 6e 64 20 63 6f 6e 66 69 72 6d 20 69 74  D and confirm it
f670: 20 68 61 73 20 73 74 61 72 74 65 64 20 73 75 63   has started suc
f680: 63 65 73 73 66 75 6c 6c 79 2e 0a 20 20 20 20 72  cessfully..    r
f690: 65 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68  eply = self.simh
f6a0: 2e 6f 73 38 5f 63 6d 64 20 28 6f 73 38 5f 63 6f  .os8_cmd (os8_co
f6b0: 6d 6d 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73  mm, self.replies
f6c0: 5f 72 65 78 5b 22 62 75 69 6c 64 22 5d 2c 20 64  _rex["build"], d
f6d0: 65 62 75 67 3d 73 65 6c 66 2e 64 65 62 75 67 29  ebug=self.debug)
f6e0: 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 73 69 6d  .    if self.sim
f6f0: 68 2e 74 65 73 74 5f 72 65 73 75 6c 74 20 28 72  h.test_result (r
f700: 65 70 6c 79 2c 20 22 42 55 49 4c 44 20 50 72 6f  eply, "BUILD Pro
f710: 6d 70 74 22 2c 20 73 65 6c 66 2e 72 65 70 6c 69  mpt", self.repli
f720: 65 73 5b 22 62 75 69 6c 64 22 5d 2c 20 5c 0a 20  es["build"], \. 
f730: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
f740: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 62 75               "bu
f750: 69 6c 64 5f 73 75 62 63 6f 6d 6d 20 73 74 61 72  ild_subcomm star
f760: 74 75 70 20 22 20 2b 20 6f 73 38 5f 63 6f 6d 6d  tup " + os8_comm
f770: 2c 20 64 65 62 75 67 3d 73 65 6c 66 2e 64 65 62  , debug=self.deb
f780: 75 67 29 20 3d 3d 20 46 61 6c 73 65 3a 0a 20 20  ug) == False:.  
f790: 20 20 20 20 70 72 69 6e 74 20 28 22 4c 69 6e 65      print ("Line
f7a0: 20 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69   " + str(self.li
f7b0: 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20  ne_ct_stack[0]) 
f7c0: 2b 20 22 3a 20 22 20 2b 20 6f 73 38 5f 63 6f 6d  + ": " + os8_com
f7d0: 6d 20 2b 20 22 20 66 61 69 6c 65 64 2e 22 29 0a  m + " failed.").
f7e0: 20 20 20 20 20 20 70 72 69 6e 74 20 28 22 49 67        print ("Ig
f7f0: 6e 6f 72 69 6e 67 20 74 68 65 20 72 65 73 74 20  noring the rest 
f800: 6f 66 20 74 68 69 73 20 62 6c 6f 63 6b 2e 22 29  of this block.")
f810: 0a 20 20 20 20 20 20 73 65 6c 66 2e 69 67 6e 6f  .      self.igno
f820: 72 65 5f 74 6f 5f 73 75 62 63 6f 6d 6d 5f 65 6e  re_to_subcomm_en
f830: 64 28 6f 73 38 5f 63 6f 6d 6d 2c 20 73 63 72 69  d(os8_comm, scri
f840: 70 74 5f 66 69 6c 65 2c 20 22 62 75 69 6c 64 22  pt_file, "build"
f850: 29 0a 20 20 20 20 20 20 23 20 43 6f 6e 66 69 72  ).      # Confir
f860: 6d 20 77 65 27 72 65 20 62 61 63 6b 20 74 6f 20  m we're back to 
f870: 6d 6f 6e 69 74 6f 72 20 63 6f 6d 6d 61 6e 64 20  monitor command 
f880: 6c 65 76 65 6c 2e 0a 20 20 20 20 20 20 73 65 6c  level..      sel
f890: 66 2e 73 69 6d 68 2e 6f 73 38 5f 63 66 6d 5f 6d  f.simh.os8_cfm_m
f8a0: 6f 6e 69 74 6f 72 20 28 22 62 75 69 6c 64 5f 73  onitor ("build_s
f8b0: 75 62 63 6f 6d 6d 20 31 22 29 0a 20 20 20 20 20  ubcomm 1").     
f8c0: 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a 0a   return "fail"..
f8d0: 20 20 20 20 23 20 53 75 62 6d 69 74 20 74 68 65      # Submit the
f8e0: 20 6c 69 6e 65 73 20 66 72 6f 6d 20 73 63 72 69   lines from scri
f8f0: 70 74 20 66 69 6c 65 20 74 6f 20 42 55 49 4c 44  pt file to BUILD
f900: 20 73 75 62 2d 63 6f 6d 6d 61 6e 64 2e 0a 20 20   sub-command..  
f910: 20 20 66 6f 72 20 6c 69 6e 65 20 69 6e 20 73 63    for line in sc
f920: 72 69 70 74 5f 66 69 6c 65 3a 0a 20 20 20 20 20  ript_file:.     
f930: 20 6c 69 6e 65 20 3d 20 73 65 6c 66 2e 62 61 73   line = self.bas
f940: 69 63 5f 6c 69 6e 65 5f 70 61 72 73 65 28 6c 69  ic_line_parse(li
f950: 6e 65 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 29  ne, script_file)
f960: 0a 20 20 20 20 20 20 69 66 20 6c 69 6e 65 20 3d  .      if line =
f970: 3d 20 4e 6f 6e 65 3a 20 63 6f 6e 74 69 6e 75 65  = None: continue
f980: 0a 20 20 0a 20 20 20 20 20 20 6d 20 3d 20 72 65  .  .      m = re
f990: 2e 6d 61 74 63 68 28 5f 63 6f 6d 6d 5f 72 65 2c  .match(_comm_re,
f9a0: 20 6c 69 6e 65 29 0a 20 20 20 20 20 20 69 66 20   line).      if 
f9b0: 6d 20 3d 3d 20 4e 6f 6e 65 3a 0a 20 20 20 20 20  m == None:.     
f9c0: 20 20 20 70 72 69 6e 74 28 22 49 67 6e 6f 72 69     print("Ignori
f9d0: 6e 67 20 6d 61 6c 2d 66 6f 72 6d 65 64 20 62 75  ng mal-formed bu
f9e0: 69 6c 64 20 73 75 62 2d 63 6f 6d 6d 61 6e 64 20  ild sub-command 
f9f0: 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20  at line " + \.  
fa00: 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c 66          str(self
fa10: 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
fa20: 5d 29 20 2b 20 22 3a 20 22 20 2b 20 6c 69 6e 65  ]) + ": " + line
fa30: 29 0a 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e  ).        contin
fa40: 75 65 0a 20 20 0a 20 20 20 20 20 20 62 75 69 6c  ue.  .      buil
fa50: 64 5f 73 75 62 20 3d 20 6d 2e 67 72 6f 75 70 28  d_sub = m.group(
fa60: 31 29 0a 20 20 20 20 20 20 72 65 73 74 20 3d 20  1).      rest = 
fa70: 6d 2e 67 72 6f 75 70 28 33 29 0a 20 20 20 20 20  m.group(3).     
fa80: 20 69 66 20 72 65 73 74 20 3d 3d 20 4e 6f 6e 65   if rest == None
fa90: 3a 20 72 65 73 74 20 3d 20 22 22 0a 20 20 20 20  : rest = "".    
faa0: 20 20 0a 20 20 20 20 20 20 69 66 20 73 65 6c 66    .      if self
fab0: 2e 64 65 62 75 67 3a 20 70 72 69 6e 74 20 28 22  .debug: print ("
fac0: 62 75 69 6c 64 5f 73 75 62 3a 20 22 20 2b 20 62  build_sub: " + b
fad0: 75 69 6c 64 5f 73 75 62 29 0a 20 20 20 20 20 20  uild_sub).      
fae0: 69 66 20 62 75 69 6c 64 5f 73 75 62 20 6e 6f 74  if build_sub not
faf0: 20 69 6e 20 5f 62 75 69 6c 64 5f 63 6f 6d 6d 5f   in _build_comm_
fb00: 72 65 67 73 3a 0a 20 20 20 20 20 20 20 20 70 72  regs:.        pr
fb10: 69 6e 74 28 22 55 6e 72 65 63 6f 67 6e 69 7a 65  int("Unrecognize
fb20: 64 20 42 55 49 4c 44 20 63 6f 6d 6d 61 6e 64 20  d BUILD command 
fb30: 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20  at line " + \.  
fb40: 20 20 20 20 20 20 20 20 20 20 73 74 72 28 73 65            str(se
fb50: 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b  lf.line_ct_stack
fb60: 5b 30 5d 29 20 2b 20 22 3a 20 22 20 2b 20 62 75  [0]) + ": " + bu
fb70: 69 6c 64 5f 73 75 62 29 0a 20 20 20 20 20 20 20  ild_sub).       
fb80: 20 63 6f 6e 74 69 6e 75 65 0a 0a 20 20 20 20 20   continue..     
fb90: 20 23 20 48 61 6e 64 6c 65 20 74 68 65 20 65 78   # Handle the ex
fba0: 69 74 20 66 72 6f 6d 20 42 55 49 4c 44 20 77 68  it from BUILD wh
fbb0: 65 6e 20 77 65 20 68 69 74 20 61 6e 20 22 65 6e  en we hit an "en
fbc0: 64 22 20 73 74 61 74 65 6d 65 6e 74 2e 0a 20 20  d" statement..  
fbd0: 20 20 20 20 69 66 20 62 75 69 6c 64 5f 73 75 62      if build_sub
fbe0: 20 3d 3d 20 22 65 6e 64 22 3a 0a 20 20 20 20 20   == "end":.     
fbf0: 20 20 20 69 66 20 72 65 73 74 20 3d 3d 20 22 22     if rest == ""
fc00: 3a 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e  :.          prin
fc10: 74 28 22 57 61 72 6e 69 6e 67 21 20 65 6e 64 20  t("Warning! end 
fc20: 73 74 61 74 65 6d 65 6e 74 20 65 6e 63 6f 75 6e  statement encoun
fc30: 74 65 72 65 64 20 69 6e 73 69 64 65 20 62 75 69  tered inside bui
fc40: 6c 64 20 77 69 74 68 20 6e 6f 20 61 72 67 75 6d  ld with no argum
fc50: 65 6e 74 20 61 74 20 6c 69 6e 65 20 22 20 2b 20  ent at line " + 
fc60: 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  \.              
fc70: 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74  str(self.line_ct
fc80: 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 2e 5c  _stack[0]) + ".\
fc90: 6e 45 78 69 74 69 6e 67 20 62 75 69 6c 64 2e 22  nExiting build."
fca0: 29 0a 20 20 20 20 20 20 20 20 20 20 23 20 45 78  ).          # Ex
fcb0: 69 74 20 42 55 49 4c 44 2e 20 4e 6f 74 65 21 20  it BUILD. Note! 
fcc0: 55 6e 6c 69 6b 65 20 6d 61 6e 79 20 63 6f 6d 6d  Unlike many comm
fcd0: 61 6e 64 73 20 62 75 69 6c 64 20 64 6f 65 73 20  ands build does 
fce0: 4e 4f 54 20 65 63 68 6f 20 22 5e 43 21 22 0a 20  NOT echo "^C!". 
fcf0: 20 20 20 20 20 20 20 20 20 73 65 6c 66 2e 73 69           self.si
fd00: 6d 68 2e 6f 73 38 5f 63 74 72 6c 5f 63 20 28 22  mh.os8_ctrl_c ("
fd10: 62 75 69 6c 64 5f 73 75 62 63 6f 6d 6d 20 65 6e  build_subcomm en
fd20: 64 20 77 69 74 68 20 6e 6f 20 61 72 67 75 6d 65  d with no argume
fd30: 6e 74 22 29 0a 20 20 20 20 20 20 20 20 20 20 72  nt").          r
fd40: 65 74 75 72 6e 20 22 66 61 69 6c 22 0a 20 20 20  eturn "fail".   
fd50: 20 20 20 20 20 65 6c 69 66 20 72 65 73 74 20 21       elif rest !
fd60: 3d 20 22 62 75 69 6c 64 22 3a 20 0a 20 20 20 20  = "build": .    
fd70: 20 20 20 20 20 20 70 72 69 6e 74 28 22 57 61 72        print("War
fd80: 6e 69 6e 67 21 20 4d 69 73 6d 61 74 63 68 65 64  ning! Mismatched
fd90: 20 62 65 67 69 6e 2f 65 6e 64 20 62 6c 6f 63 6b   begin/end block
fda0: 73 20 69 6e 20 42 55 49 4c 44 20 61 74 20 6c 69  s in BUILD at li
fdb0: 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20  ne " + \.       
fdc0: 20 20 20 20 20 20 20 73 74 72 28 73 65 6c 66 2e         str(self.
fdd0: 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d  line_ct_stack[0]
fde0: 29 20 2b 20 22 2e 5c 6e 45 6e 63 6f 75 6e 74 65  ) + ".\nEncounte
fdf0: 72 65 64 20 65 6e 64 3a 20 7b 22 20 2b 20 5c 0a  red end: {" + \.
fe00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65                re
fe10: 73 74 20 2b 20 22 7d 2e 20 45 78 69 74 69 6e 67  st + "}. Exiting
fe20: 20 42 55 49 4c 44 2e 22 29 0a 20 20 20 20 20 20   BUILD.").      
fe30: 20 20 20 20 23 20 45 78 69 74 20 42 55 49 4c 44      # Exit BUILD
fe40: 2e 20 4e 6f 74 65 21 20 55 6e 6c 69 6b 65 20 6d  . Note! Unlike m
fe50: 61 6e 79 20 63 6f 6d 6d 61 6e 64 73 20 62 75 69  any commands bui
fe60: 6c 64 20 64 6f 65 73 20 4e 4f 54 20 65 63 68 6f  ld does NOT echo
fe70: 20 22 5e 43 21 22 0a 20 20 20 20 20 20 20 20 20   "^C!".         
fe80: 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 63   self.simh.os8_c
fe90: 74 72 6c 5f 63 20 28 22 62 75 69 6c 64 5f 73 75  trl_c ("build_su
fea0: 62 63 6f 6d 6d 20 6d 69 73 6d 61 74 63 68 65 64  bcomm mismatched
feb0: 20 62 65 67 69 6e 2f 65 6e 64 22 29 0a 20 20 20   begin/end").   
fec0: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 66         return "f
fed0: 61 69 6c 22 0a 20 20 20 20 20 20 20 20 0a 20 20  ail".        .  
fee0: 20 20 20 20 20 20 23 20 57 65 27 72 65 20 64 6f        # We're do
fef0: 6e 65 2e 20 20 50 72 69 6e 74 20 61 6e 79 20 64  ne.  Print any d
ff00: 65 73 69 72 65 64 20 76 65 72 62 6f 73 65 20 6f  esired verbose o
ff10: 72 20 64 65 62 75 67 20 73 74 61 74 75 73 0a 20  r debug status. 
ff20: 20 20 20 20 20 20 20 23 20 74 68 65 6e 20 5e 43         # then ^C
ff30: 20 74 6f 20 65 78 69 74 20 61 6e 64 20 63 6f 6e   to exit and con
ff40: 66 69 72 6d 20 77 65 27 72 65 20 61 74 20 6d 6f  firm we're at mo
ff50: 6e 69 74 6f 72 20 6c 65 76 65 6c 2e 0a 20 20 20  nitor level..   
ff60: 20 20 20 20 20 69 66 20 73 65 6c 66 2e 76 65 72       if self.ver
ff70: 62 6f 73 65 3a 0a 20 20 20 20 20 20 20 20 20 20  bose:.          
ff80: 70 72 69 6e 74 28 22 4c 69 6e 65 20 22 20 2b 20  print("Line " + 
ff90: 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74  str(self.line_ct
ffa0: 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 3a 20  _stack[0]) + ": 
ffb0: 65 6e 64 20 42 55 49 4c 44 22 29 0a 20 20 20 20  end BUILD").    
ffc0: 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65 62 75      if self.debu
ffd0: 67 3a 0a 20 20 20 20 20 20 20 20 20 20 70 72 69  g:.          pri
ffe0: 6e 74 28 22 62 65 66 6f 72 65 3a 20 22 20 2b 20  nt("before: " + 
fff0: 73 65 6c 66 2e 73 69 6d 68 2e 5f 63 68 69 6c 64  self.simh._child
10000 2e 62 65 66 6f 72 65 2e 64 65 63 6f 64 65 28 29  .before.decode()
10010 2e 73 74 72 69 70 28 29 29 0a 20 20 20 20 20 20  .strip()).      
10020 20 20 20 20 70 72 69 6e 74 28 22 61 66 74 65 72      print("after
10030 3a 20 22 20 2b 20 73 65 6c 66 2e 73 69 6d 68 2e  : " + self.simh.
10040 63 68 69 6c 64 5f 61 66 74 65 72 28 29 2e 73 74  child_after().st
10050 72 69 70 28 29 29 0a 20 20 20 20 20 20 20 20 23  rip()).        #
10060 20 52 65 74 75 72 6e 20 74 6f 20 6d 6f 6e 69 74   Return to monit
10070 6f 72 2e 0a 20 20 20 20 20 20 20 20 23 20 4e 6f  or..        # No
10080 74 65 21 20 55 6e 6c 69 6b 65 20 6d 61 6e 79 20  te! Unlike many 
10090 63 6f 6d 6d 61 6e 64 73 20 62 75 69 6c 64 20 64  commands build d
100a0 6f 65 73 20 4e 4f 54 20 65 63 68 6f 20 22 5e 43  oes NOT echo "^C
100b0 21 22 0a 20 20 20 20 20 20 20 20 73 65 6c 66 2e  !".        self.
100c0 73 69 6d 68 2e 6f 73 38 5f 63 74 72 6c 5f 63 20  simh.os8_ctrl_c 
100d0 28 22 62 75 69 6c 64 5f 73 75 62 63 6f 6d 6d 20  ("build_subcomm 
100e0 65 6e 64 20 77 69 74 68 20 6e 6f 20 61 72 67 75  end with no argu
100f0 6d 65 6e 74 2e 22 29 0a 20 20 20 20 20 20 20 20  ment.").        
10100 72 65 74 75 72 6e 20 22 73 75 63 63 65 73 73 22  return "success"
10110 0a 20 20 20 20 20 20 20 20 0a 20 20 20 20 20 20  .        .      
10120 23 20 4e 6f 77 20 70 65 72 66 6f 72 6d 20 73 75  # Now perform su
10130 62 2d 63 6f 6d 6d 61 6e 64 73 20 77 69 74 68 69  b-commands withi
10140 6e 20 42 55 49 4c 44 2e 20 54 68 65 79 20 68 61  n BUILD. They ha
10150 76 65 20 61 20 64 69 73 63 65 72 6e 61 62 6c 65  ve a discernable
10160 20 66 6f 72 6d 61 74 2e 0a 20 20 20 20 20 20 62   format..      b
10170 75 69 6c 64 5f 72 65 20 3d 20 5f 62 75 69 6c 64  uild_re = _build
10180 5f 63 6f 6d 6d 5f 72 65 67 73 5b 62 75 69 6c 64  _comm_regs[build
10190 5f 73 75 62 5d 0a 20 20 0a 20 20 20 20 20 20 69  _sub].  .      i
101a0 66 20 62 75 69 6c 64 5f 72 65 20 21 3d 20 4e 6f  f build_re != No
101b0 6e 65 3a 0a 20 20 20 20 20 20 20 20 6d 32 20 3d  ne:.        m2 =
101c0 20 72 65 2e 6d 61 74 63 68 28 62 75 69 6c 64 5f   re.match(build_
101d0 72 65 2c 20 72 65 73 74 29 0a 20 20 20 20 20 20  re, rest).      
101e0 20 20 69 66 20 6d 32 20 3d 3d 20 4e 6f 6e 65 3a    if m2 == None:
101f0 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74  .          print
10200 28 22 49 67 6e 6f 72 69 6e 67 20 6d 61 6c 2d 66  ("Ignoring mal-f
10210 6f 72 6d 65 64 20 42 55 49 4c 44 20 61 74 20 6c  ormed BUILD at l
10220 69 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20  ine " + \.      
10230 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c 66          str(self
10240 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
10250 5d 29 20 2b 20 22 3a 20 22 20 2b 20 62 75 69 6c  ]) + ": " + buil
10260 64 5f 73 75 62 20 2b 20 5c 0a 20 20 20 20 20 20  d_sub + \.      
10270 20 20 20 20 20 20 20 20 22 20 63 6f 6d 6d 61 6e          " comman
10280 64 3a 20 22 20 2b 20 72 65 73 74 29 0a 20 20 20  d: " + rest).   
10290 20 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 0a         continue.
102a0 20 20 20 20 20 20 0a 20 20 20 20 20 20 20 20 69        .        i
102b0 66 20 62 75 69 6c 64 5f 73 75 62 20 3d 3d 20 22  f build_sub == "
102c0 42 55 49 4c 44 22 3a 0a 20 20 20 20 20 20 20 20  BUILD":.        
102d0 20 20 69 66 20 6d 32 2e 67 72 6f 75 70 28 31 29    if m2.group(1)
102e0 20 3d 3d 20 4e 6f 6e 65 20 6f 72 20 6d 32 2e 67   == None or m2.g
102f0 72 6f 75 70 28 31 29 20 3d 3d 20 22 22 3a 0a 20  roup(1) == "":. 
10300 20 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74             print
10310 28 22 4d 69 73 73 69 6e 67 20 73 6f 75 72 63 65  ("Missing source
10320 20 6f 66 20 4f 53 38 2e 42 4e 2e 20 49 67 6e 6f   of OS8.BN. Igno
10330 72 69 6e 67 20 42 55 49 4c 44 20 63 6f 6d 6d 61  ring BUILD comma
10340 6e 64 20 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c  nd at line " + \
10350 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
10360 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63   str(self.line_c
10370 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 2e  t_stack[0]) + ".
10380 22 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 63  ").            c
10390 6f 6e 74 69 6e 75 65 0a 20 20 20 20 20 20 20 20  ontinue.        
103a0 20 20 65 6c 73 65 3a 20 6b 62 6d 5f 61 72 67 20    else: kbm_arg 
103b0 3d 20 6d 32 2e 67 72 6f 75 70 28 31 29 0a 0a 20  = m2.group(1).. 
103c0 20 20 20 20 20 20 20 20 20 69 66 20 6d 32 2e 67           if m2.g
103d0 72 6f 75 70 28 33 29 20 3d 3d 20 4e 6f 6e 65 20  roup(3) == None 
103e0 6f 72 20 6d 32 2e 67 72 6f 75 70 28 33 29 20 3d  or m2.group(3) =
103f0 3d 20 22 22 3a 0a 20 20 20 20 20 20 20 20 20 20  = "":.          
10400 20 20 70 72 69 6e 74 28 22 4d 69 73 73 69 6e 67    print("Missing
10410 20 73 6f 72 63 65 20 6f 66 20 43 44 2e 42 4e 2e   sorce of CD.BN.
10420 20 49 67 6e 6f 72 69 6e 67 20 42 55 49 4c 44 20   Ignoring BUILD 
10430 63 6f 6d 6d 61 6e 64 20 61 74 20 6c 69 6e 65 20  command at line 
10440 22 20 2b 20 5c 0a 20 20 20 20 20 20 20 20 20 20  " + \.          
10450 20 20 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6c        str(self.l
10460 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29  ine_ct_stack[0])
10470 20 2b 20 22 2e 22 29 0a 20 20 20 20 20 20 20 20   + ".").        
10480 20 20 20 20 63 6f 6e 74 69 6e 75 65 0a 20 20 20      continue.   
10490 20 20 20 20 20 20 20 65 6c 73 65 3a 20 63 64 5f         else: cd_
104a0 61 72 67 20 3d 20 6d 32 2e 67 72 6f 75 70 28 33  arg = m2.group(3
104b0 29 0a 20 20 20 20 20 20 20 20 20 20 0a 20 20 20  ).          .   
104c0 20 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 76         if self.v
104d0 65 72 62 6f 73 65 3a 0a 20 20 20 20 20 20 20 20  erbose:.        
104e0 20 20 20 20 70 72 69 6e 74 28 22 4c 69 6e 65 20      print("Line 
104f0 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e  " + str(self.lin
10500 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b  e_ct_stack[0]) +
10510 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20   \.             
10520 20 20 20 20 22 3a 20 42 55 49 4c 44 20 4b 42 4d      ": BUILD KBM
10530 3a 20 22 20 2b 20 6b 62 6d 5f 61 72 67 20 2b 20  : " + kbm_arg + 
10540 22 2c 20 43 44 3a 20 22 20 2b 20 63 64 5f 61 72  ", CD: " + cd_ar
10550 67 29 0a 0a 20 20 20 20 20 20 20 20 20 20 23 20  g)..          # 
10560 43 6f 6e 66 69 72 6d 20 70 72 6f 6d 70 74 65 64  Confirm prompted
10570 20 66 6f 72 20 4f 53 38 20 62 69 6e 61 72 79 2e   for OS8 binary.
10580 0a 20 20 20 20 20 20 20 20 20 20 72 65 70 6c 79  .          reply
10590 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38   = self.simh.os8
105a0 5f 63 6d 64 20 28 22 42 55 49 4c 44 22 2c 20 73  _cmd ("BUILD", s
105b0 65 6c 66 2e 72 65 70 6c 69 65 73 5f 72 65 78 5b  elf.replies_rex[
105c0 22 62 75 69 6c 64 22 5d 2c 20 64 65 62 75 67 3d  "build"], debug=
105d0 73 65 6c 66 2e 64 65 62 75 67 29 0a 20 20 20 20  self.debug).    
105e0 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 73 69        if self.si
105f0 6d 68 2e 74 65 73 74 5f 72 65 73 75 6c 74 28 72  mh.test_result(r
10600 65 70 6c 79 2c 20 22 4c 4f 41 44 20 4f 53 38 22  eply, "LOAD OS8"
10610 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73 5b 22  , self.replies["
10620 62 75 69 6c 64 22 5d 2c 20 22 62 75 69 6c 64 5f  build"], "build_
10630 73 75 62 63 6f 6d 6d 20 35 22 29 20 3d 3d 20 46  subcomm 5") == F
10640 61 6c 73 65 3a 0a 20 20 20 20 20 20 20 20 20 20  alse:.          
10650 20 20 70 72 69 6e 74 28 22 4e 6f 20 70 72 6f 6d    print("No prom
10660 70 74 20 66 6f 72 20 4c 4f 41 44 20 4f 53 2f 38  pt for LOAD OS/8
10670 20 69 6e 20 42 55 49 4c 44 20 63 6f 6d 6d 61 6e   in BUILD comman
10680 64 20 77 69 74 68 69 6e 20 42 55 49 4c 44 20 61  d within BUILD a
10690 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20 20  t line " + \.   
106a0 20 20 20 20 20 20 20 20 20 20 20 73 74 72 28 73             str(s
106b0 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63  elf.line_ct_stac
106c0 6b 5b 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20  k[0]) + ".").   
106d0 20 20 20 20 20 20 20 20 20 70 72 69 6e 74 28 22           print("
106e0 46 61 74 61 6c 20 65 72 72 6f 72 2e 20 41 62 6f  Fatal error. Abo
106f0 72 74 69 6e 67 20 73 63 72 69 70 74 2e 22 29 0a  rting script.").
10700 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75              retu
10710 72 6e 20 22 64 69 65 22 0a 0a 20 20 20 20 20 20  rn "die"..      
10720 20 20 20 20 23 20 53 65 6e 64 20 69 74 20 61 6e      # Send it an
10730 64 20 63 6f 6e 66 69 72 6d 20 70 72 6f 6d 70 74  d confirm prompt
10740 65 64 20 66 6f 72 20 43 44 20 62 69 6e 61 72 79  ed for CD binary
10750 2e 0a 20 20 20 20 20 20 20 20 20 20 72 65 70 6c  ..          repl
10760 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73  y = self.simh.os
10770 38 5f 63 6d 64 20 28 6b 62 6d 5f 61 72 67 2c 20  8_cmd (kbm_arg, 
10780 73 65 6c 66 2e 72 65 70 6c 69 65 73 5f 72 65 78  self.replies_rex
10790 5b 22 62 75 69 6c 64 22 5d 2c 20 64 65 62 75 67  ["build"], debug
107a0 3d 73 65 6c 66 2e 64 65 62 75 67 29 0a 20 20 20  =self.debug).   
107b0 20 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 73         if self.s
107c0 69 6d 68 2e 74 65 73 74 5f 72 65 73 75 6c 74 28  imh.test_result(
107d0 72 65 70 6c 79 2c 20 22 4c 4f 41 44 20 43 44 22  reply, "LOAD CD"
107e0 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73 5b 22  , self.replies["
107f0 62 75 69 6c 64 22 5d 2c 20 22 62 75 69 6c 64 5f  build"], "build_
10800 73 75 62 63 6f 6d 6d 20 36 22 29 20 3d 3d 20 46  subcomm 6") == F
10810 61 6c 73 65 3a 0a 20 20 20 20 20 20 20 20 20 20  alse:.          
10820 20 20 70 72 69 6e 74 28 22 4e 6f 20 70 72 6f 6d    print("No prom
10830 70 74 20 66 6f 72 20 4c 4f 41 44 20 43 44 20 69  pt for LOAD CD i
10840 6e 20 42 55 49 4c 44 20 63 6f 6d 6d 61 6e 64 20  n BUILD command 
10850 77 69 74 68 69 6e 20 42 55 49 4c 44 20 61 74 20  within BUILD at 
10860 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20 20  line " + \.     
10870 20 20 20 20 20 20 20 20 20 73 74 72 28 73 65 6c           str(sel
10880 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b  f.line_ct_stack[
10890 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20 20 20  0]) + ".").     
108a0 20 20 20 20 20 20 20 70 72 69 6e 74 28 22 46 61         print("Fa
108b0 74 61 6c 20 65 72 72 6f 72 2e 20 41 62 6f 72 74  tal error. Abort
108c0 69 6e 67 20 73 63 72 69 70 74 2e 22 29 0a 20 20  ing script.").  
108d0 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e            return
108e0 20 22 64 69 65 22 0a 20 20 20 20 20 20 20 20 20   "die".         
108f0 20 23 20 53 65 6e 64 20 69 74 20 61 6e 64 20 63   # Send it and c
10900 6f 6e 66 69 72 6d 20 77 65 27 72 65 20 62 61 63  onfirm we're bac
10910 6b 20 69 6e 20 42 55 49 4c 44 20 63 6f 6d 6d 61  k in BUILD comma
10920 6e 64 20 6d 6f 64 65 2e 0a 20 20 20 20 20 20 20  nd mode..       
10930 20 20 20 72 65 70 6c 79 20 3d 20 73 65 6c 66 2e     reply = self.
10940 73 69 6d 68 2e 6f 73 38 5f 63 6d 64 20 28 63 64  simh.os8_cmd (cd
10950 5f 61 72 67 2c 20 73 65 6c 66 2e 72 65 70 6c 69  _arg, self.repli
10960 65 73 5f 72 65 78 5b 22 62 75 69 6c 64 22 5d 2c  es_rex["build"],
10970 20 64 65 62 75 67 3d 73 65 6c 66 2e 64 65 62 75   debug=self.debu
10980 67 29 0a 20 20 20 20 20 20 20 20 20 20 69 66 20  g).          if 
10990 73 65 6c 66 2e 73 69 6d 68 2e 74 65 73 74 5f 72  self.simh.test_r
109a0 65 73 75 6c 74 28 72 65 70 6c 79 2c 20 22 42 55  esult(reply, "BU
109b0 49 4c 44 20 50 72 6f 6d 70 74 22 2c 20 73 65 6c  ILD Prompt", sel
109c0 66 2e 72 65 70 6c 69 65 73 5b 22 62 75 69 6c 64  f.replies["build
109d0 22 5d 2c 20 22 62 75 69 6c 64 5f 73 75 62 63 6f  "], "build_subco
109e0 6d 6d 20 37 22 29 20 3d 3d 20 46 61 6c 73 65 3a  mm 7") == False:
109f0 0a 20 20 20 20 20 20 20 20 20 20 20 20 70 72 69  .            pri
10a00 6e 74 20 28 22 42 55 49 4c 44 20 63 6f 6d 6d 61  nt ("BUILD comma
10a10 6e 64 20 77 69 74 68 69 6e 20 62 75 69 6c 64 20  nd within build 
10a20 66 61 69 6c 65 64 2e 20 20 41 62 6f 72 74 69 6e  failed.  Abortin
10a30 67 20 73 63 72 69 70 74 2e 22 29 0a 20 20 20 20  g script.").    
10a40 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 22          return "
10a50 64 69 65 22 0a 20 20 20 20 20 20 20 20 20 20 69  die".          i
10a60 66 20 73 65 6c 66 2e 64 65 62 75 67 3a 0a 20 20  f self.debug:.  
10a70 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74 28            print(
10a80 22 52 65 73 75 6d 65 20 42 55 49 4c 44 2e 53 56  "Resume BUILD.SV
10a90 20 63 6f 6d 6d 61 6e 64 20 6c 6f 6f 70 2e 22 29   command loop.")
10aa0 0a 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69  .          conti
10ab0 6e 75 65 0a 0a 20 20 20 20 20 20 23 20 4e 6f 72  nue..      # Nor
10ac0 6d 61 6c 20 63 61 73 65 3a 20 63 6f 6d 6d 61 6e  mal case: comman
10ad0 64 73 20 77 69 74 68 69 6e 20 42 55 49 4c 44 2e  ds within BUILD.
10ae0 0a 20 20 20 20 20 20 63 6f 6d 6d 20 3d 20 62 75  .      comm = bu
10af0 69 6c 64 5f 73 75 62 20 2b 20 22 20 22 20 2b 20  ild_sub + " " + 
10b00 72 65 73 74 0a 20 20 20 20 20 20 69 66 20 73 65  rest.      if se
10b10 6c 66 2e 76 65 72 62 6f 73 65 3a 0a 20 20 20 20  lf.verbose:.    
10b20 20 20 20 20 70 72 69 6e 74 28 22 4c 69 6e 65 20      print("Line 
10b30 22 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e  " + str(self.lin
10b40 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b  e_ct_stack[0]) +
10b50 20 22 3a 20 42 55 49 4c 44 2d 3e 20 22 20 2b 20   ": BUILD-> " + 
10b60 63 6f 6d 6d 29 0a 20 20 20 20 20 20 72 65 70 6c  comm).      repl
10b70 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73  y = self.simh.os
10b80 38 5f 63 6d 64 20 28 63 6f 6d 6d 2c 20 73 65 6c  8_cmd (comm, sel
10b90 66 2e 72 65 70 6c 69 65 73 5f 72 65 78 5b 22 62  f.replies_rex["b
10ba0 75 69 6c 64 22 5d 2c 20 64 65 62 75 67 3d 73 65  uild"], debug=se
10bb0 6c 66 2e 64 65 62 75 67 29 0a 0a 20 20 20 20 20  lf.debug)..     
10bc0 20 23 20 53 70 65 63 69 61 6c 20 63 61 73 65 20   # Special case 
10bd0 22 42 4f 4f 54 22 20 73 75 62 2d 63 6f 6d 6d 61  "BOOT" sub-comma
10be0 6e 64 3a 20 4d 61 79 20 61 73 6b 2c 20 22 57 52  nd: May ask, "WR
10bf0 49 54 45 20 5a 45 52 4f 20 44 49 52 45 43 54 3f  ITE ZERO DIRECT?
10c00 22 0a 20 20 20 20 20 20 23 20 57 69 6c 6c 20 67  ".      # Will g
10c10 69 76 65 20 61 20 6d 6f 6e 69 74 6f 72 20 70 72  ive a monitor pr
10c20 6f 6d 70 74 20 77 68 65 6e 20 64 6f 6e 65 2e 0a  ompt when done..
10c30 20 20 20 20 20 20 69 66 20 62 75 69 6c 64 5f 73        if build_s
10c40 75 62 20 3d 3d 20 22 42 4f 4f 54 22 3a 0a 20 20  ub == "BOOT":.  
10c50 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 73 69        if self.si
10c60 6d 68 2e 74 65 73 74 5f 72 65 73 75 6c 74 28 72  mh.test_result(r
10c70 65 70 6c 79 2c 20 22 57 52 49 54 45 20 5a 45 52  eply, "WRITE ZER
10c80 4f 20 44 49 52 45 43 54 3f 22 2c 20 73 65 6c 66  O DIRECT?", self
10c90 2e 72 65 70 6c 69 65 73 5b 22 62 75 69 6c 64 22  .replies["build"
10ca0 5d 2c 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20  ], \.           
10cb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10cc0 20 20 20 20 20 20 22 22 2c 20 64 65 62 75 67 3d        "", debug=
10cd0 73 65 6c 66 2e 64 65 62 75 67 29 3a 0a 20 20 20  self.debug):.   
10ce0 20 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 64         if self.d
10cf0 65 62 75 67 3a 0a 20 20 20 20 20 20 20 20 20 20  ebug:.          
10d00 20 20 70 72 69 6e 74 28 22 47 6f 74 2c 20 5c 22    print("Got, \"
10d10 57 52 49 54 45 20 5a 45 52 4f 20 44 49 52 45 43  WRITE ZERO DIREC
10d20 54 3f 5c 22 2e 20 53 65 6e 64 69 6e 67 20 5c 22  T?\". Sending \"
10d30 59 5c 22 2e 22 29 0a 20 20 20 20 20 20 20 20 20  Y\".").         
10d40 20 72 65 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69   reply = self.si
10d50 6d 68 2e 6f 73 38 5f 63 6d 64 28 22 59 22 2c 20  mh.os8_cmd("Y", 
10d60 73 65 6c 66 2e 72 65 70 6c 69 65 73 5f 72 65 78  self.replies_rex
10d70 5b 22 62 75 69 6c 64 22 5d 2c 20 64 65 62 75 67  ["build"], debug
10d80 3d 73 65 6c 66 2e 64 65 62 75 67 29 0a 0a 20 20  =self.debug)..  
10d90 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 73 69        if self.si
10da0 6d 68 2e 74 65 73 74 5f 72 65 73 75 6c 74 28 72  mh.test_result(r
10db0 65 70 6c 79 2c 20 22 53 59 53 20 42 55 49 4c 54  eply, "SYS BUILT
10dc0 22 2c 20 73 65 6c 66 2e 72 65 70 6c 69 65 73 5b  ", self.replies[
10dd0 22 62 75 69 6c 64 22 5d 2c 20 22 22 2c 20 64 65  "build"], "", de
10de0 62 75 67 3d 73 65 6c 66 2e 64 65 62 75 67 29 3a  bug=self.debug):
10df0 0a 20 20 20 20 20 20 20 20 20 20 23 20 53 75 63  .          # Suc
10e00 63 65 73 73 66 75 6c 20 62 6f 6f 74 2e 20 20 57  cessful boot.  W
10e10 65 27 72 65 20 6e 6f 77 20 61 74 20 6d 6f 6e 69  e're now at moni
10e20 74 6f 72 20 6c 65 76 65 6c 2e 0a 20 20 20 20 20  tor level..     
10e30 20 20 20 20 20 23 20 53 69 6d 70 6c 65 73 74 20       # Simplest 
10e40 74 6f 20 69 67 6e 6f 72 65 20 61 6e 79 74 68 69  to ignore anythi
10e50 6e 67 20 65 6c 73 65 20 69 6e 20 74 68 65 20 73  ng else in the s
10e60 63 72 69 70 74 20 75 70 20 74 6f 20 22 65 6e 64  cript up to "end
10e70 20 62 75 69 6c 64 22 0a 20 20 20 20 20 20 20 20   build".        
10e80 20 20 23 20 52 65 74 75 72 6e 20 73 75 63 63 65    # Return succe
10e90 73 73 20 6f 72 20 66 61 69 6c 75 72 65 20 62 61  ss or failure ba
10ea0 73 65 64 20 6f 6e 20 66 69 6e 64 69 6e 67 20 74  sed on finding t
10eb0 68 61 74 20 6d 6f 6e 69 74 6f 72 20 70 72 6f 6d  hat monitor prom
10ec0 70 74 2e 0a 20 20 20 20 20 20 20 20 20 20 73 65  pt..          se
10ed0 6c 66 2e 69 67 6e 6f 72 65 5f 74 6f 5f 73 75 62  lf.ignore_to_sub
10ee0 63 6f 6d 6d 5f 65 6e 64 28 6f 73 38 5f 63 6f 6d  comm_end(os8_com
10ef0 6d 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 2c 20  m, script_file, 
10f00 22 62 75 69 6c 64 22 29 0a 20 20 20 20 20 20 20  "build").       
10f10 20 20 20 69 66 20 73 65 6c 66 2e 73 69 6d 68 2e     if self.simh.
10f20 6f 73 38 5f 63 66 6d 5f 6d 6f 6e 69 74 6f 72 20  os8_cfm_monitor 
10f30 28 22 62 75 69 6c 64 5f 73 75 62 63 6f 6d 6d 20  ("build_subcomm 
10f40 38 22 29 3a 0a 20 20 20 20 20 20 20 20 20 20 20  8"):.           
10f50 20 72 65 74 75 72 6e 20 22 73 75 63 63 65 73 73   return "success
10f60 22 0a 20 20 20 20 20 20 20 20 20 20 65 6c 73 65  ".          else
10f70 3a 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 65  :.            re
10f80 74 75 72 6e 20 22 66 61 69 6c 22 0a 0a 20 20 20  turn "fail"..   
10f90 20 20 20 23 20 41 74 20 74 68 69 73 20 70 6f 69     # At this poi
10fa0 6e 74 20 77 65 20 65 69 74 68 65 72 20 68 61 76  nt we either hav
10fb0 65 20 61 20 42 55 49 4c 44 20 70 72 6f 6d 70 74  e a BUILD prompt
10fc0 20 6f 72 20 61 6e 20 65 72 72 6f 72 20 6d 65 73   or an error mes
10fd0 73 61 67 65 2e 0a 20 20 20 20 20 20 23 20 49 66  sage..      # If
10fe0 20 69 74 27 73 20 6e 6f 74 20 74 68 65 20 42 55   it's not the BU
10ff0 49 4c 44 20 70 72 6f 6d 70 74 2c 20 77 65 20 70  ILD prompt, we p
11000 72 69 6e 74 20 61 6e 20 65 72 72 6f 72 2e 0a 20  rint an error.. 
11010 20 20 20 20 20 23 20 49 66 20 74 68 65 20 65 72       # If the er
11020 72 6f 72 20 69 73 20 66 61 74 61 6c 2c 20 69 67  ror is fatal, ig
11030 6e 6f 72 65 20 72 65 73 74 20 6f 66 20 62 75 69  nore rest of bui
11040 6c 64 20 62 6c 6f 63 6b 2c 0a 20 20 20 20 20 20  ld block,.      
11050 23 20 65 78 69 74 20 62 61 63 6b 20 74 6f 20 4f  # exit back to O
11060 53 2f 38 20 69 66 20 6e 65 63 65 73 73 61 72 79  S/8 if necessary
11070 20 61 6e 64 20 72 65 74 75 72 6e 20 66 61 69 6c   and return fail
11080 2e 0a 20 20 20 20 20 20 23 20 49 66 20 69 74 27  ..      # If it'
11090 73 20 6e 6f 74 20 66 61 74 61 6c 2c 20 63 6f 6e  s not fatal, con
110a0 74 69 6e 75 65 20 72 75 6e 6e 69 6e 67 20 42 55  tinue running BU
110b0 49 4c 44 2e 0a 20 20 20 20 20 20 69 66 20 73 65  ILD..      if se
110c0 6c 66 2e 73 69 6d 68 2e 74 65 73 74 5f 72 65 73  lf.simh.test_res
110d0 75 6c 74 28 72 65 70 6c 79 2c 20 22 42 55 49 4c  ult(reply, "BUIL
110e0 44 20 50 72 6f 6d 70 74 22 2c 20 73 65 6c 66 2e  D Prompt", self.
110f0 72 65 70 6c 69 65 73 5b 22 62 75 69 6c 64 22 5d  replies["build"]
11100 2c 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20  , \.            
11110 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
11120 20 20 20 22 62 75 69 6c 64 5f 73 75 62 63 6f 6d     "build_subcom
11130 6d 20 39 22 2c 20 64 65 62 75 67 3d 73 65 6c 66  m 9", debug=self
11140 2e 64 65 62 75 67 29 20 3d 3d 20 46 61 6c 73 65  .debug) == False
11150 3a 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 28  :.        print(
11160 22 42 55 49 4c 44 20 65 72 72 6f 72 20 61 74 20  "BUILD error at 
11170 6c 69 6e 65 20 22 20 2b 20 73 74 72 28 73 65 6c  line " + str(sel
11180 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b  f.line_ct_stack[
11190 30 5d 29 20 2b 20 5c 0a 20 20 20 20 20 20 20 20  0]) + \.        
111a0 20 20 22 20 77 69 74 68 20 63 6f 6d 6d 61 6e 64    " with command
111b0 20 22 20 2b 20 73 65 6c 66 2e 73 69 6d 68 2e 5f   " + self.simh._
111c0 63 68 69 6c 64 2e 62 65 66 6f 72 65 2e 64 65 63  child.before.dec
111d0 6f 64 65 28 29 2e 73 74 72 69 70 28 29 29 0a 20  ode().strip()). 
111e0 20 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 72         if self.r
111f0 65 70 6c 69 65 73 5b 22 62 75 69 6c 64 22 5d 5b  eplies["build"][
11200 72 65 70 6c 79 5d 5b 32 5d 20 3d 3d 20 54 72 75  reply][2] == Tru
11210 65 3a 0a 20 20 20 20 20 20 20 20 20 20 70 72 69  e:.          pri
11220 6e 74 20 28 22 46 61 74 61 6c 20 65 72 72 6f 72  nt ("Fatal error
11230 2e 20 20 49 67 6e 6f 72 69 6e 67 20 72 65 73 74  .  Ignoring rest
11240 20 6f 66 20 74 68 69 73 20 62 6c 6f 63 6b 2e 22   of this block."
11250 29 0a 20 20 20 20 20 20 20 20 20 20 73 65 6c 66  ).          self
11260 2e 69 67 6e 6f 72 65 5f 74 6f 5f 73 75 62 63 6f  .ignore_to_subco
11270 6d 6d 5f 65 6e 64 28 6f 73 38 5f 63 6f 6d 6d 2c  mm_end(os8_comm,
11280 20 73 63 72 69 70 74 5f 66 69 6c 65 2c 20 22 62   script_file, "b
11290 75 69 6c 64 22 29 0a 20 20 20 20 20 20 20 20 20  uild").         
112a0 20 23 20 43 6f 6e 66 69 72 6d 20 77 65 27 72 65   # Confirm we're
112b0 20 62 61 63 6b 20 61 74 20 74 68 65 20 6d 6f 6e   back at the mon
112c0 69 74 6f 72 20 61 73 20 65 78 70 65 63 74 65 64  itor as expected
112d0 2e 0a 20 20 20 20 20 20 20 20 20 20 73 65 6c 66  ..          self
112e0 2e 73 69 6d 68 2e 6f 73 38 5f 63 66 6d 5f 6d 6f  .simh.os8_cfm_mo
112f0 6e 69 74 6f 72 20 28 22 62 75 69 6c 64 5f 73 75  nitor ("build_su
11300 62 63 6f 6d 6d 20 31 30 22 29 0a 20 20 20 20 20  bcomm 10").     
11310 20 20 20 20 20 72 65 74 75 72 6e 20 22 66 61 69       return "fai
11320 6c 22 0a 20 20 20 20 20 20 20 20 23 20 54 6f 20  l".        # To 
11330 63 6f 6e 74 69 6e 75 65 2c 20 77 65 20 6e 65 65  continue, we nee
11340 64 20 74 6f 20 61 73 6b 20 70 65 78 70 65 63 74  d to ask pexpect
11350 20 74 6f 20 67 65 74 20 74 68 61 74 20 42 55 49   to get that BUI
11360 4c 44 20 70 72 6f 6d 70 74 20 62 65 66 6f 72 65  LD prompt before
11370 0a 20 20 20 20 20 20 20 20 23 20 72 65 73 75 6d  .        # resum
11380 69 6e 67 20 61 66 74 65 72 20 61 6e 20 65 72 72  ing after an err
11390 6f 72 2e 20 49 67 6e 6f 72 65 20 65 76 65 72 79  or. Ignore every
113a0 74 68 69 6e 67 20 75 6e 74 69 6c 20 77 65 20 67  thing until we g
113b0 65 74 20 69 74 2e 0a 20 20 20 20 20 20 20 20 73  et it..        s
113c0 65 6c 66 2e 73 69 6d 68 2e 5f 63 68 69 6c 64 2e  elf.simh._child.
113d0 65 78 70 65 63 74 28 22 5c 6e 5c 5c 24 24 22 29  expect("\n\\$$")
113e0 0a 20 20 20 20 20 20 20 20 0a 20 20 20 20 70 72  .        .    pr
113f0 69 6e 74 28 22 57 61 72 6e 69 6e 67 20 65 6e 64  int("Warning end
11400 20 6f 66 20 66 69 6c 65 20 65 6e 63 6f 75 6e 74   of file encount
11410 65 72 65 64 20 77 69 74 68 20 6e 6f 20 65 6e 64  ered with no end
11420 20 6f 66 20 42 55 49 4c 44 20 63 6f 6d 6d 61 6e   of BUILD comman
11430 64 20 62 6c 6f 63 6b 20 61 74 20 6c 69 6e 65 20  d block at line 
11440 22 20 2b 20 5c 0a 20 20 20 20 20 20 73 74 72 28  " + \.      str(
11450 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61  self.line_ct_sta
11460 63 6b 5b 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20  ck[0]) + ".").  
11470 20 20 72 65 74 75 72 6e 20 22 66 61 69 6c 22 0a    return "fail".
11480 0a 0a 20 20 23 23 23 23 20 63 64 70 72 6f 67 5f  ..  #### cdprog_
11490 73 75 62 63 6f 6d 6d 20 23 23 23 23 23 23 23 23  subcomm ########
114a0 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
114b0 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
114c0 23 23 23 23 23 23 23 23 23 23 0a 20 20 23 20 43  ##########.  # C
114d0 79 63 6c 65 20 74 68 72 6f 75 67 68 20 4f 53 2f  ycle through OS/
114e0 38 20 63 6f 6d 6d 61 6e 64 20 64 65 63 6f 64 65  8 command decode
114f0 72 20 77 69 74 68 20 74 68 65 20 63 6f 6d 6d 61  r with the comma
11500 6e 64 20 73 70 65 63 69 66 69 65 64 0a 20 20 23  nd specified.  #
11510 20 69 6e 20 74 68 65 20 61 72 67 75 6d 65 6e 74   in the argument
11520 2e 0a 20 20 0a 20 20 64 65 66 20 63 64 70 72 6f  ..  .  def cdpro
11530 67 5f 73 75 62 63 6f 6d 6d 20 28 73 65 6c 66 2c  g_subcomm (self,
11540 20 6f 6c 64 5f 6c 69 6e 65 2c 20 73 63 72 69 70   old_line, scrip
11550 74 5f 66 69 6c 65 29 3a 0a 20 20 20 20 6f 73 38  t_file):.    os8
11560 5f 63 6f 6d 6d 20 3d 20 22 52 55 20 22 20 2b 20  _comm = "RU " + 
11570 6f 6c 64 5f 6c 69 6e 65 0a 20 20 20 20 65 6e 64  old_line.    end
11580 5f 73 74 72 20 3d 20 22 63 64 70 72 6f 67 20 22  _str = "cdprog "
11590 20 2b 20 6f 6c 64 5f 6c 69 6e 65 0a 20 20 20 20   + old_line.    
115a0 69 66 20 73 65 6c 66 2e 76 65 72 62 6f 73 65 3a  if self.verbose:
115b0 0a 20 20 20 20 20 20 70 72 69 6e 74 28 22 4c 69  .      print("Li
115c0 6e 65 3a 20 22 20 2b 20 73 74 72 28 73 65 6c 66  ne: " + str(self
115d0 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30  .line_ct_stack[0
115e0 5d 29 20 2b 20 22 3a 20 22 20 2b 20 6f 73 38 5f  ]) + ": " + os8_
115f0 63 6f 6d 6d 29 0a 0a 20 20 20 20 72 65 70 6c 79  comm)..    reply
11600 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38   = self.simh.os8
11610 5f 63 6d 64 20 28 6f 73 38 5f 63 6f 6d 6d 2c 20  _cmd (os8_comm, 
11620 64 65 62 75 67 3d 73 65 6c 66 2e 64 65 62 75 67  debug=self.debug
11630 29 0a 20 20 20 20 69 66 20 73 65 6c 66 2e 73 69  ).    if self.si
11640 6d 68 2e 6f 73 38 5f 74 65 73 74 5f 72 65 73 75  mh.os8_test_resu
11650 6c 74 20 28 72 65 70 6c 79 2c 20 22 43 6f 6d 6d  lt (reply, "Comm
11660 61 6e 64 20 44 65 63 6f 64 65 72 20 50 72 6f 6d  and Decoder Prom
11670 70 74 22 2c 20 22 63 64 70 72 6f 67 3a 20 22 20  pt", "cdprog: " 
11680 2b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 20 20  + \.            
11690 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
116a0 20 20 20 20 20 20 6f 73 38 5f 63 6f 6d 6d 2c 20        os8_comm, 
116b0 64 65 62 75 67 3d 73 65 6c 66 2e 64 65 62 75 67  debug=self.debug
116c0 29 20 3d 3d 20 46 61 6c 73 65 3a 0a 20 20 20 20  ) == False:.    
116d0 20 20 70 72 69 6e 74 20 28 22 20 66 61 69 6c 65    print (" faile
116e0 64 20 61 74 20 4c 69 6e 65 20 22 20 2b 20 73 74  d at Line " + st
116f0 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73  r(self.line_ct_s
11700 74 61 63 6b 5b 30 5d 29 29 0a 20 20 20 20 20 20  tack[0])).      
11710 70 72 69 6e 74 20 28 22 49 67 6e 6f 72 69 6e 67  print ("Ignoring
11720 20 74 68 65 20 72 65 73 74 20 6f 66 20 74 68 69   the rest of thi
11730 73 20 62 6c 6f 63 6b 2e 22 29 0a 20 20 20 20 20  s block.").     
11740 20 73 65 6c 66 2e 69 67 6e 6f 72 65 5f 74 6f 5f   self.ignore_to_
11750 73 75 62 63 6f 6d 6d 5f 65 6e 64 28 6f 73 38 5f  subcomm_end(os8_
11760 63 6f 6d 6d 2c 20 73 63 72 69 70 74 5f 66 69 6c  comm, script_fil
11770 65 2c 20 65 6e 64 5f 73 74 72 29 0a 20 20 20 20  e, end_str).    
11780 20 20 23 20 43 6f 6e 66 69 72 6d 20 77 65 27 72    # Confirm we'r
11790 65 20 62 61 63 6b 20 74 6f 20 6d 6f 6e 69 74 6f  e back to monito
117a0 72 20 63 6f 6d 6d 61 6e 64 20 6c 65 76 65 6c 2e  r command level.
117b0 0a 20 20 20 20 20 20 73 65 6c 66 2e 73 69 6d 68  .      self.simh
117c0 2e 6f 73 38 5f 63 66 6d 5f 6d 6f 6e 69 74 6f 72  .os8_cfm_monitor
117d0 20 28 22 63 64 70 72 6f 67 20 4f 53 2f 38 20 72   ("cdprog OS/8 r
117e0 65 73 74 61 72 74 20 61 66 74 65 72 20 66 61 69  estart after fai
117f0 6c 65 64 20 52 55 20 63 6f 6d 6d 61 6e 64 22 29  led RU command")
11800 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 66  .      return "f
11810 61 69 6c 22 0a 0a 20 20 20 20 23 20 53 75 62 6d  ail"..    # Subm
11820 69 74 20 74 68 65 20 6c 69 6e 65 73 20 66 72 6f  it the lines fro
11830 6d 20 73 63 72 69 70 74 20 66 69 6c 65 20 74 6f  m script file to
11840 20 74 68 65 20 72 75 6e 6e 69 6e 67 20 63 6f 6d   the running com
11850 6d 61 6e 64 2e 0a 20 20 20 20 23 20 54 72 61 63  mand..    # Trac
11860 6b 20 77 68 65 74 68 65 72 20 77 65 20 72 65 74  k whether we ret
11870 75 72 6e 20 74 6f 20 74 68 65 20 43 6f 6d 6e 61  urn to the Comna
11880 6e 64 20 44 65 63 6f 64 65 72 20 66 6f 72 20 6d  nd Decoder for m
11890 6f 72 65 20 6f 72 20 65 78 69 74 2e 0a 20 20 20  ore or exit..   
118a0 20 23 20 54 72 61 63 6b 20 77 68 65 74 68 65 72   # Track whether
118b0 20 77 65 20 6e 65 65 64 20 74 6f 20 65 78 69 74   we need to exit
118c0 20 61 6e 64 20 69 67 6e 6f 72 65 20 74 68 65 20   and ignore the 
118d0 72 65 73 74 20 6f 66 20 74 68 65 20 62 6c 6f 63  rest of the bloc
118e0 6b 2e 0a 20 20 20 20 66 6f 72 20 6c 69 6e 65 20  k..    for line 
118f0 69 6e 20 73 63 72 69 70 74 5f 66 69 6c 65 3a 0a  in script_file:.
11900 20 20 20 20 20 20 6c 69 6e 65 20 3d 20 73 65 6c        line = sel
11910 66 2e 62 61 73 69 63 5f 6c 69 6e 65 5f 70 61 72  f.basic_line_par
11920 73 65 28 6c 69 6e 65 2c 20 73 63 72 69 70 74 5f  se(line, script_
11930 66 69 6c 65 29 0a 20 20 20 20 20 20 69 66 20 6c  file).      if l
11940 69 6e 65 20 3d 3d 20 4e 6f 6e 65 3a 20 63 6f 6e  ine == None: con
11950 74 69 6e 75 65 0a 20 20 0a 20 20 20 20 20 20 23  tinue.  .      #
11960 20 54 65 73 74 20 66 6f 72 20 73 70 65 63 69 61   Test for specia
11970 6c 20 63 61 73 65 2c 20 22 65 6e 64 22 20 61 6e  l case, "end" an
11980 64 20 61 63 74 20 6f 6e 20 69 74 20 69 66 20 70  d act on it if p
11990 72 65 73 65 6e 74 2e 0a 20 20 20 20 20 20 6d 20  resent..      m 
119a0 3d 20 72 65 2e 6d 61 74 63 68 28 5f 63 6f 6d 6d  = re.match(_comm
119b0 5f 72 65 2c 20 6c 69 6e 65 29 0a 20 20 20 20 20  _re, line).     
119c0 20 69 66 20 6d 20 21 3d 20 4e 6f 6e 65 20 61 6e   if m != None an
119d0 64 20 6d 2e 67 72 6f 75 70 28 31 29 20 21 3d 20  d m.group(1) != 
119e0 4e 6f 6e 65 20 61 6e 64 20 6d 2e 67 72 6f 75 70  None and m.group
119f0 28 31 29 20 21 3d 20 22 22 20 61 6e 64 20 6d 2e  (1) != "" and m.
11a00 67 72 6f 75 70 28 31 29 20 20 3d 3d 20 22 65 6e  group(1)  == "en
11a10 64 22 3a 0a 20 20 20 20 20 20 20 20 72 65 73 74  d":.        rest
11a20 20 3d 20 6d 2e 67 72 6f 75 70 28 33 29 0a 20 20   = m.group(3).  
11a30 20 20 20 20 20 20 72 65 74 76 61 6c 20 3d 20 22        retval = "
11a40 66 61 69 6c 22 20 20 23 20 52 65 74 75 72 6e 20  fail"  # Return 
11a50 66 61 69 6c 20 75 6e 6c 65 73 73 20 70 72 6f 76  fail unless prov
11a60 65 6e 20 73 75 63 63 65 73 73 66 75 6c 2e 0a 20  en successful.. 
11a70 20 20 20 20 20 20 20 69 66 20 72 65 73 74 20 3d         if rest =
11a80 3d 20 4e 6f 6e 65 20 6f 72 20 72 65 73 74 20 3d  = None or rest =
11a90 3d 20 22 22 3a 0a 20 20 20 20 20 20 20 20 20 20  = "":.          
11aa0 70 72 69 6e 74 28 22 57 61 72 6e 69 6e 67 21 20  print("Warning! 
11ab0 65 6e 64 20 73 74 61 74 65 6d 65 6e 74 20 65 6e  end statement en
11ac0 63 6f 75 6e 74 65 72 65 64 20 69 6e 73 69 64 65  countered inside
11ad0 20 63 64 70 72 6f 67 20 22 20 2b 20 5c 0a 20 20   cdprog " + \.  
11ae0 20 20 20 20 20 20 20 20 20 20 20 20 22 77 69 74              "wit
11af0 68 20 6e 6f 20 61 72 67 75 6d 65 6e 74 20 61 74  h no argument at
11b00 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20   line " + \.    
11b10 20 20 20 20 20 20 20 20 20 20 73 74 72 28 73 65            str(se
11b20 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63 6b  lf.line_ct_stack
11b30 5b 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20 20  [0]) + ".").    
11b40 20 20 20 20 20 20 70 72 69 6e 74 28 22 45 78 70        print("Exp
11b50 65 63 74 69 6e 67 3a 20 7b 22 20 2b 20 65 6e 64  ecting: {" + end
11b60 5f 73 74 72 20 2b 20 22 7d 2e 22 29 0a 20 20 20  _str + "}.").   
11b70 20 20 20 20 20 65 6c 69 66 20 72 65 73 74 20 21       elif rest !
11b80 3d 20 65 6e 64 5f 73 74 72 3a 0a 20 20 20 20 20  = end_str:.     
11b90 20 20 20 20 20 70 72 69 6e 74 28 22 57 61 72 6e       print("Warn
11ba0 69 6e 67 21 20 4d 69 73 6d 61 74 63 68 65 64 20  ing! Mismatched 
11bb0 62 65 67 69 6e 2f 65 6e 64 20 62 6c 6f 63 6b 73  begin/end blocks
11bc0 20 69 6e 20 63 64 70 72 6f 67 20 61 74 20 6c 69   in cdprog at li
11bd0 6e 65 20 22 20 2b 20 5c 0a 20 20 20 20 20 20 20  ne " + \.       
11be0 20 20 20 20 20 73 74 72 28 73 65 6c 66 2e 6c 69       str(self.li
11bf0 6e 65 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20  ne_ct_stack[0]) 
11c00 2b 20 22 2e 5c 6e 22 29 0a 20 20 20 20 20 20 20  + ".\n").       
11c10 20 20 20 70 72 69 6e 74 28 22 45 78 70 65 63 74     print("Expect
11c20 69 6e 67 3a 20 7b 22 20 2b 20 65 6e 64 5f 73 74  ing: {" + end_st
11c30 72 20 2b 20 22 7d 2e 20 47 6f 74 3a 20 7b 22 20  r + "}. Got: {" 
11c40 2b 20 72 65 73 74 20 2b 20 22 7d 2e 5c 6e 22 29  + rest + "}.\n")
11c50 0a 20 20 20 20 20 20 20 20 65 6c 73 65 3a 0a 20  .        else:. 
11c60 20 20 20 20 20 20 20 20 20 72 65 74 76 61 6c 20           retval 
11c70 3d 20 22 73 75 63 63 65 73 73 22 0a 20 20 20 20  = "success".    
11c80 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 76 65        if self.ve
11c90 72 62 6f 73 65 3a 0a 20 20 20 20 20 20 20 20 20  rbose:.         
11ca0 20 20 20 70 72 69 6e 74 28 22 4c 69 6e 65 20 22     print("Line "
11cb0 20 2b 20 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65   + str(self.line
11cc0 5f 63 74 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20  _ct_stack[0]) + 
11cd0 22 3a 20 65 6e 64 20 22 20 2b 20 65 6e 64 5f 73  ": end " + end_s
11ce0 74 72 29 0a 20 20 20 20 20 20 20 20 69 66 20 72  tr).        if r
11cf0 65 74 76 61 6c 20 3d 3d 20 22 66 61 69 6c 22 3a  etval == "fail":
11d00 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74  .          print
11d10 28 22 45 78 69 74 69 6e 67 20 63 64 70 72 6f 67  ("Exiting cdprog
11d20 2c 20 70 6f 73 73 69 62 6c 79 20 65 61 72 6c 69  , possibly earli
11d30 65 72 20 74 68 61 6e 20 65 78 70 65 63 74 65 64  er than expected
11d40 20 61 74 20 6c 69 6e 65 20 22 20 2b 20 5c 0a 20   at line " + \. 
11d50 20 20 20 20 20 20 20 20 20 20 20 73 74 72 28 73             str(s
11d60 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63  elf.line_ct_stac
11d70 6b 5b 30 5d 29 20 2b 20 22 2e 22 29 0a 20 20 20  k[0]) + ".").   
11d80 20 20 20 20 20 23 20 52 65 74 75 72 6e 20 74 6f       # Return to
11d90 20 4d 6f 6e 69 74 6f 72 0a 20 20 20 20 20 20 20   Monitor.       
11da0 20 72 65 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69   reply = self.si
11db0 6d 68 2e 6f 73 38 5f 65 73 63 61 70 65 20 28 63  mh.os8_escape (c
11dc0 61 6c 6c 65 72 3d 22 53 65 6e 64 69 6e 67 20 65  aller="Sending e
11dd0 73 63 61 70 65 20 66 61 69 6c 65 64 2e 20 54 72  scape failed. Tr
11de0 79 69 6e 67 20 5e 63 22 29 0a 20 20 20 20 20 20  ying ^c").      
11df0 20 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f    self.simh.os8_
11e00 63 74 72 6c 5f 63 20 28 22 63 64 70 72 6f 67 3a  ctrl_c ("cdprog:
11e10 20 5e 63 20 66 61 69 6c 65 64 2e 20 53 74 61 74   ^c failed. Stat
11e20 65 20 6d 61 63 68 69 6e 65 20 77 69 6c 6c 20 62  e machine will b
11e30 65 20 63 6f 6e 66 75 73 65 64 2e 22 29 0a 20 20  e confused.").  
11e40 20 20 20 20 20 20 72 65 74 75 72 6e 20 72 65 74        return ret
11e50 76 61 6c 0a 20 20 0a 20 20 20 20 20 20 23 20 57  val.  .      # W
11e60 65 20 63 6f 75 6c 64 20 64 6f 20 73 6f 6d 65 20  e could do some 
11e70 62 61 73 69 63 20 4f 53 2f 38 20 63 6f 6d 6d 61  basic OS/8 comma
11e80 6e 64 20 64 65 63 6f 64 65 72 20 73 79 6e 61 78  nd decoder synax
11e90 20 63 68 65 63 6b 69 6e 67 20 68 65 72 65 2e 0a   checking here..
11ea0 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e 76 65        if self.ve
11eb0 72 62 6f 73 65 3a 0a 20 20 20 20 20 20 20 20 70  rbose:.        p
11ec0 72 69 6e 74 28 22 4c 69 6e 65 3a 20 22 20 2b 20  rint("Line: " + 
11ed0 73 74 72 28 73 65 6c 66 2e 6c 69 6e 65 5f 63 74  str(self.line_ct
11ee0 5f 73 74 61 63 6b 5b 30 5d 29 20 2b 20 22 3a 20  _stack[0]) + ": 
11ef0 2a 20 22 20 2b 20 6c 69 6e 65 29 0a 20 20 20 20  * " + line).    
11f00 20 20 20 20 70 72 69 6e 74 28 22 53 65 6e 64 69      print("Sendi
11f10 6e 67 2e 2e 2e 22 29 0a 20 20 20 20 20 20 72 65  ng...").      re
11f20 70 6c 79 20 3d 20 73 65 6c 66 2e 73 69 6d 68 2e  ply = self.simh.
11f30 6f 73 38 5f 63 6d 64 20 28 6c 69 6e 65 29 0a 20  os8_cmd (line). 
11f40 20 20 20 20 20 69 66 20 73 65 6c 66 2e 64 65 62       if self.deb
11f50 75 67 3a 0a 20 20 20 20 20 20 20 20 70 72 69 6e  ug:.        prin
11f60 74 20 28 22 63 64 70 72 6f 67 20 73 65 6e 74 20  t ("cdprog sent 
11f70 6c 69 6e 65 2e 20 47 6f 74 20 72 65 70 6c 79 3a  line. Got reply:
11f80 20 22 20 2b 20 73 74 72 28 72 65 70 6c 79 29 20   " + str(reply) 
11f90 2b 20 22 20 2d 3e 20 22 20 2b 20 5c 0a 20 20 20  + " -> " + \.   
11fa0 20 20 20 20 20 20 20 20 20 20 20 20 73 65 6c 66              self
11fb0 2e 73 69 6d 68 2e 5f 6f 73 38 5f 72 65 70 6c 69  .simh._os8_repli
11fc0 65 73 20 5b 72 65 70 6c 79 5d 5b 30 5d 29 0a 0a  es [reply][0])..
11fd0 20 20 20 20 20 20 23 20 54 72 61 6e 73 63 72 69        # Transcri
11fe0 62 65 20 6f 75 72 20 6f 75 74 70 75 74 20 69 66  be our output if
11ff0 20 64 65 73 69 72 65 64 2e 0a 20 20 20 20 20 20   desired..      
12000 69 66 20 22 74 72 61 6e 73 63 72 69 70 74 22 20  if "transcript" 
12010 69 6e 20 73 65 6c 66 2e 6f 70 74 69 6f 6e 73 5f  in self.options_
12020 65 6e 61 62 6c 65 64 3a 0a 20 20 20 20 20 20 20  enabled:.       
12030 20 70 72 69 6e 74 20 28 73 65 6c 66 2e 73 69 6d   print (self.sim
12040 68 2e 5f 63 68 69 6c 64 2e 62 65 66 6f 72 65 2e  h._child.before.
12050 64 65 63 6f 64 65 28 29 2e 73 74 72 69 70 28 29  decode().strip()
12060 29 0a 0a 20 20 20 20 20 20 6d 6f 6e 20 3d 20 73  )..      mon = s
12070 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 74 65 73  elf.simh.os8_tes
12080 74 5f 72 65 73 75 6c 74 28 72 65 70 6c 79 2c 20  t_result(reply, 
12090 22 4d 6f 6e 69 74 6f 72 20 50 72 6f 6d 70 74 22  "Monitor Prompt"
120a0 2c 20 22 22 29 0a 20 20 20 20 20 20 63 64 20 20  , "").      cd  
120b0 3d 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f  = self.simh.os8_
120c0 74 65 73 74 5f 72 65 73 75 6c 74 28 72 65 70 6c  test_result(repl
120d0 79 2c 20 22 43 6f 6d 6d 61 6e 64 20 44 65 63 6f  y, "Command Deco
120e0 64 65 72 20 50 72 6f 6d 70 74 22 2c 20 22 22 29  der Prompt", "")
120f0 0a 20 20 20 20 20 20 69 66 20 6d 6f 6e 3a 0a 20  .      if mon:. 
12100 20 20 20 20 20 20 20 23 20 43 61 73 65 20 6f 66         # Case of
12110 20 63 6f 6d 6d 61 6e 64 20 72 75 6e 6e 69 6e 67   command running
12120 20 74 6f 20 63 6f 6d 70 6c 65 74 69 6f 6e 20 61   to completion a
12130 6e 64 20 72 65 74 75 72 6e 69 6e 67 20 74 6f 20  nd returning to 
12140 4f 53 2f 38 0a 20 20 20 20 20 20 20 20 23 20 43  OS/8.        # C
12150 6c 65 61 6e 20 75 70 20 74 68 65 20 70 61 72 73  lean up the pars
12160 65 20 74 6f 20 74 68 65 20 65 6e 64 20 6f 66 20  e to the end of 
12170 74 68 65 20 62 6c 6f 63 6b 20 61 6e 64 20 72 65  the block and re
12180 74 75 72 6e 20 73 75 63 63 65 73 73 2e 0a 20 20  turn success..  
12190 20 20 20 20 20 20 73 65 6c 66 2e 69 67 6e 6f 72        self.ignor
121a0 65 5f 74 6f 5f 73 75 62 63 6f 6d 6d 5f 65 6e 64  e_to_subcomm_end
121b0 28 6f 73 38 5f 63 6f 6d 6d 2c 20 73 63 72 69 70  (os8_comm, scrip
121c0 74 5f 66 69 6c 65 2c 20 65 6e 64 5f 73 74 72 29  t_file, end_str)
121d0 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20  .        return 
121e0 22 73 75 63 63 65 73 73 22 0a 20 20 20 20 20 20  "success".      
121f0 65 6c 69 66 20 6e 6f 74 20 63 64 3a 0a 20 20 20  elif not cd:.   
12200 20 20 20 20 20 23 20 57 65 20 64 69 64 6e 27 74       # We didn't
12210 20 72 65 74 75 72 6e 20 74 6f 20 63 6f 6d 6d 61   return to comma
12220 6e 64 20 64 65 63 6f 64 65 72 2e 20 20 54 68 61  nd decoder.  Tha
12230 74 20 6d 65 61 6e 73 20 77 65 20 68 61 76 65 20  t means we have 
12240 61 6e 20 65 72 72 6f 72 2e 0a 20 20 20 20 20 20  an error..      
12250 20 20 23 20 54 65 73 74 20 74 68 65 20 66 61 74    # Test the fat
12260 61 6c 20 62 69 74 20 69 6e 20 74 68 65 20 65 72  al bit in the er
12270 72 6f 72 20 73 74 72 75 63 74 75 72 65 2e 0a 20  ror structure.. 
12280 20 20 20 20 20 20 20 23 20 49 46 20 54 72 75 65         # IF True
12290 3a 20 77 65 20 72 65 74 75 72 6e 65 64 20 74 6f  : we returned to
122a0 20 4f 53 2f 38 2e 20 53 61 79 20 77 65 27 72 65   OS/8. Say we're
122b0 20 69 67 6e 6f 72 69 6e 67 20 74 68 65 20 62 6c   ignoring the bl
122c0 6f 63 6b 20 61 6e 64 20 72 65 74 75 72 6e 20 66  ock and return f
122d0 61 69 6c 75 72 65 2e 0a 20 20 20 20 20 20 20 20  ailure..        
122e0 23 20 4f 74 68 65 72 77 69 73 65 20 77 65 20 73  # Otherwise we s
122f0 68 6f 75 6c 64 20 63 6f 6e 74 69 6e 75 65 2e 0a  hould continue..
12300 20 20 20 20 20 20 20 20 69 66 20 73 65 6c 66 2e          if self.
12310 73 69 6d 68 2e 5f 6f 73 38 5f 72 65 70 6c 69 65  simh._os8_replie
12320 73 5b 72 65 70 6c 79 5d 5b 32 5d 20 3d 3d 20 54  s[reply][2] == T
12330 72 75 65 3a 0a 20 20 20 20 20 20 20 20 20 20 70  rue:.          p
12340 72 69 6e 74 20 28 22 46 61 74 61 6c 20 65 72 72  rint ("Fatal err
12350 6f 72 2e 20 49 67 6e 6f 72 69 6e 67 20 72 65 73  or. Ignoring res
12360 74 20 6f 66 20 74 68 69 73 20 62 6c 6f 63 6b 2e  t of this block.
12370 22 29 0a 20 20 20 20 20 20 20 20 20 20 73 65 6c  ").          sel
12380 66 2e 69 67 6e 6f 72 65 5f 74 6f 5f 73 75 62 63  f.ignore_to_subc
12390 6f 6d 6d 5f 65 6e 64 28 6f 73 38 5f 63 6f 6d 6d  omm_end(os8_comm
123a0 2c 20 73 63 72 69 70 74 5f 66 69 6c 65 2c 20 65  , script_file, e
123b0 6e 64 5f 73 74 72 29 0a 20 20 20 20 20 20 20 20  nd_str).        
123c0 20 20 23 20 50 72 69 6e 74 20 65 72 72 6f 72 20    # Print error 
123d0 6d 65 73 73 61 67 65 2e 0a 20 20 20 20 20 20 20  message..       
123e0 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73 38     self.simh.os8
123f0 5f 74 65 73 74 5f 72 65 73 75 6c 74 28 72 65 70  _test_result(rep
12400 6c 79 2c 20 22 43 6f 6d 6d 61 6e 64 20 44 65 63  ly, "Command Dec
12410 6f 64 65 72 20 50 72 6f 6d 70 74 22 2c 20 22 63  oder Prompt", "c
12420 64 70 72 6f 67 20 66 61 69 6c 75 72 65 22 29 0a  dprog failure").
12430 20 20 20 20 20 20 20 20 20 20 23 20 43 6f 6e 66            # Conf
12440 69 72 6d 20 77 65 27 72 65 20 62 61 63 6b 20 61  irm we're back a
12450 74 20 4d 6f 6e 69 74 6f 72 0a 20 20 20 20 20 20  t Monitor.      
12460 20 20 20 20 73 65 6c 66 2e 73 69 6d 68 2e 6f 73      self.simh.os
12470 38 5f 63 66 6d 5f 6d 6f 6e 69 74 6f 72 20 28 22  8_cfm_monitor ("
12480 63 64 70 72 6f 67 20 65 72 72 6f 72 20 68 61 6e  cdprog error han
12490 64 6c 65 72 20 72 65 74 75 72 6e 20 74 6f 20 6d  dler return to m
124a0 6f 6e 69 74 6f 72 20 66 61 69 6c 22 29 0a 20 20  onitor fail").  
124b0 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 22          return "
124c0 66 61 69 6c 22 0a 20 20 20 20 20 20 20 20 65 6c  fail".        el
124d0 73 65 3a 0a 20 20 20 20 20 20 20 20 20 20 70 72  se:.          pr
124e0 69 6e 74 20 28 22 4e 6f 6e 2d 66 61 74 61 6c 20  int ("Non-fatal 
124f0 65 72 72 6f 72 20 65 6e 63 6f 75 6e 74 65 72 65  error encountere
12500 64 20 77 69 74 68 3a 20 22 20 2b 20 6c 69 6e 65  d with: " + line
12510 29 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e  ).          prin
12520 74 20 28 22 5c 74 22 20 2b 20 73 65 6c 66 2e 73  t ("\t" + self.s
12530 69 6d 68 2e 5f 6f 73 38 5f 72 65 70 6c 69 65 73  imh._os8_replies
12540 5b 72 65 70 6c 79 5d 5b 30 5d 29 0a 20 20 20 20  [reply][0]).    
12550 20 20 20 20 20 20 23 20 54 6f 20 63 6f 6e 74 69        # To conti
12560 6e 75 65 2c 20 77 65 20 6e 65 65 64 20 74 6f 20  nue, we need to 
12570 61 73 6b 20 70 65 78 70 65 63 74 20 74 6f 20 67  ask pexpect to g
12580 65 74 20 74 68 61 74 20 43 6f 6d 6d 61 6e 64 20  et that Command 
12590 44 65 63 6f 64 65 72 0a 20 20 20 20 20 20 20 20  Decoder.        
125a0 20 20 23 20 70 72 6f 6d 70 74 20 62 65 66 6f 72    # prompt befor
125b0 65 20 72 65 73 75 6d 69 6e 67 20 61 66 74 65 72  e resuming after
125c0 20 61 6e 20 65 72 72 6f 72 2e 20 49 67 6e 6f 72   an error. Ignor
125d0 65 20 65 76 65 72 79 74 68 69 6e 67 20 75 6e 74  e everything unt
125e0 69 6c 20 77 65 20 67 65 74 20 69 74 2e 0a 20 20  il we get it..  
125f0 20 20 20 20 20 20 20 20 73 65 6c 66 2e 73 69 6d          self.sim
12600 68 2e 5f 63 68 69 6c 64 2e 65 78 70 65 63 74 28  h._child.expect(
12610 22 5c 6e 5c 5c 2a 24 22 29 0a 20 20 20 20 70 72  "\n\\*$").    pr
12620 69 6e 74 28 22 57 61 72 6e 69 6e 67 20 65 6e 64  int("Warning end
12630 20 6f 66 20 66 69 6c 65 20 65 6e 63 6f 75 6e 74   of file encount
12640 65 72 65 64 20 61 74 20 6c 69 6e 65 20 22 20 2b  ered at line " +
12650 20 5c 0a 20 20 20 20 20 20 20 20 73 74 72 28 73   \.        str(s
12660 65 6c 66 2e 6c 69 6e 65 5f 63 74 5f 73 74 61 63  elf.line_ct_stac
12670 6b 5b 30 5d 29 20 2b 20 5c 0a 20 20 20 20 20 20  k[0]) + \.      
12680 20 20 22 20 77 69 74 68 20 6e 6f 20 65 6e 64 20    " with no end 
12690 6f 66 20 63 64 70 72 6f 67 20 63 6f 6d 6d 61 6e  of cdprog comman
126a0 64 20 62 6c 6f 63 6b 2e 22 29 0a 20 20 20 20 23  d block.").    #
126b0 20 45 78 69 74 20 63 6f 6d 6d 61 6e 64 20 62 61   Exit command ba
126c0 63 6b 20 74 6f 20 4f 53 2f 38 20 6d 6f 6e 69 74  ck to OS/8 monit
126d0 6f 72 2e 0a 20 20 20 20 6d 6f 6e 20 3d 20 73 65  or..    mon = se
126e0 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 65 73 63 61  lf.simh.os8_esca
126f0 70 65 20 28 22 22 29 0a 20 20 20 20 69 66 20 6d  pe ("").    if m
12700 6f 6e 3a 20 72 65 74 75 72 6e 20 22 66 61 69 6c  on: return "fail
12710 22 0a 20 20 20 20 65 6c 73 65 3a 0a 20 20 20 20  ".    else:.    
12720 20 20 70 72 69 6e 74 20 28 22 63 64 70 72 6f 67    print ("cdprog
12730 3a 20 45 73 63 61 70 65 20 66 72 6f 6d 20 43 6f  : Escape from Co
12740 6d 6d 61 6e 64 20 44 65 63 6f 64 65 72 20 66 61  mmand Decoder fa
12750 69 6c 65 64 2e 20 53 65 6e 64 69 6e 67 20 5e 63  iled. Sending ^c
12760 22 29 0a 20 20 20 20 20 20 6d 6f 6e 20 3d 20 73  ").      mon = s
12770 65 6c 66 2e 73 69 6d 68 2e 6f 73 38 5f 63 74 72  elf.simh.os8_ctr
12780 6c 5f 63 20 28 22 22 29 0a 20 20 20 20 20 20 69  l_c ("").      i
12790 66 20 6d 6f 6e 3a 20 72 65 74 75 72 6e 20 22 66  f mon: return "f
127a0 61 69 6c 22 0a 20 20 20 20 20 20 65 6c 73 65 3a  ail".      else:
127b0 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 20 28  .        print (
127c0 22 46 61 69 6c 65 64 20 74 6f 20 67 65 74 20 74  "Failed to get t
127d0 6f 20 6d 6f 6e 69 74 6f 72 20 77 69 74 68 20 5e  o monitor with ^
127e0 63 2e 20 4b 69 6c 6c 69 6e 67 20 73 63 72 69 70  c. Killing scrip
127f0 74 2e 22 29 0a 20 20 20 20 20 20 20 20 72 65 74  t.").        ret
12800 75 72 6e 20 22 64 69 65 22 0a 0a 0a 20 20 23 23  urn "die"...  ##
12810 23 23 20 63 68 65 63 6b 5f 65 78 69 73 74 73 20  ## check_exists 
12820 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
12830 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
12840 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23  ################
12850 23 23 23 23 0a 20 20 23 20 43 68 65 63 6b 20 65  ####.  # Check e
12860 78 69 73 74 65 6e 63 65 20 6f 66 20 61 6c 6c 20  xistence of all 
12870 66 69 6c 65 73 20 6e 65 65 64 65 64 0a 20 20 0a  files needed.  .
12880 20 20 64 65 66 20 63 68 65 63 6b 5f 65 78 69 73    def check_exis
12890 74 73 20 28 73 2c 20 69 6d 61 67 65 5f 63 6f 70  ts (s, image_cop
128a0 79 69 6e 73 29 3a 0a 20 20 20 20 66 6f 72 20 63  yins):.    for c
128b0 6f 70 79 69 6e 20 69 6e 20 69 6d 61 67 65 5f 63  opyin in image_c
128c0 6f 70 79 69 6e 73 3a 0a 20 20 20 20 20 20 69 6d  opyins:.      im
128d0 61 67 65 20 3d 20 63 6f 70 79 69 6e 5b 31 5d 0a  age = copyin[1].
128e0 20 20 20 20 20 20 69 6d 61 67 65 5f 70 61 74 68        image_path
128f0 20 3d 20 64 69 72 73 2e 6f 73 38 6d 69 20 2b 20   = dirs.os8mi + 
12900 69 6d 61 67 65 0a 20 20 20 20 20 20 69 66 20 28  image.      if (
12910 6e 6f 74 20 6f 73 2e 70 61 74 68 2e 69 73 66 69  not os.path.isfi
12920 6c 65 28 69 6d 61 67 65 5f 70 61 74 68 29 29 3a  le(image_path)):
12930 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74  .          print
12940 28 22 52 65 71 75 69 72 65 64 20 66 69 6c 65 3a  ("Required file:
12950 20 22 20 2b 20 69 6d 61 67 65 5f 70 61 74 68 20   " + image_path 
12960 2b 20 22 20 6e 6f 74 20 66 6f 75 6e 64 2e 22 29  + " not found.")
12970 0a 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72  .          retur
12980 6e 20 22 64 69 65 22 0a 20 20 20 20 20 20 23 20  n "die".      # 
12990 65 6c 73 65 3a 20 70 72 69 6e 74 28 22 46 6f 75  else: print("Fou
129a0 6e 64 20 22 20 2b 20 69 6d 61 67 65 5f 70 61 74  nd " + image_pat
129b0 68 29 0a                                         h).