YaK:: NCL : a TCL shell for NitrOS9 [Changes]   [Calendar]   [Search]   [Index]   [PhotoTags]   
[mega_changes]
[photos]

NCL: a TCL shell for NitrOS9

Quick Doc: on this page: https://github.com/strickyak/doing_os9/tree/master/picol

Downloads: You need both of these:

  • ncl.bin
  • nclrc.tcl

    Put "ncl.bin" in your CMDS directory and name it "ncl". Give it execute attrs.

    Put "nclrc.tcl" in your SYS directory.

    quick demo

    My STARTUP contains "ncl </1" so it automatically runs the NCL shell. You will have to type NCL to your shell to run it.

    * Welcome to NitrOS-9 Level 2 *
    *   on the Color Computer 3   *
    December 25, 2019  12:18:59
     >NCL> mfree
    
     Blk Begin   End   Blks  Size
     --- ------ ------ ---- ------
      16  2C000  7BFFF   28   320k
                       ==== ======
                Total:   28   320k
     >NCL> mfree > z91
     ERROR: Failed to prep for command: 9create: ERROR 215; in eval; in catch; in then of if; in run; in eval; in unknown; in __repl__
     >NCL> mfree >z91
     >NCL> dump z91
    
    Address   0 1  2 3  4 5  6 7  8 9  A B  C D  E F  0 2 4 6 8 A C E
    -------- ---- ---- ---- ---- ---- ---- ---- ----  ----------------
    00000000 0D20 426C 6B20 4265 6769 6E20 2020 456E  . Blk Begin   En
    00000010 6420 2020 426C 6B73 2020 5369 7A65 0D20  d   Blks  Size.
    00000020 2D2D 2D20 2D2D 2D2D 2D2D 202D 2D2D 2D2D  --- ------ -----
    00000030 2D20 2D2D 2D2D 202D 2D2D 2D2D 2D0D 2020  - ---- ------.
    00000040 3136 2020 3243 3030 3020 2037 4246 4646  16  2C000  7BFFF
    00000050 2020 2032 3820 2020 3332 306B 0D20 2020     28   320k.
    00000060 2020 2020 2020 2020 2020 2020 2020 2020
    00000070 3D3D 3D3D 203D 3D3D 3D3D 3D0D 2020 2020  ==== ======.
    00000080 2020 2020 2020 2020 546F 7461 6C3A 2020          Total:
    00000090 2032 3820 2020 3332 306B 0D               28   320k.
     >NCL>
    

    This uses a command named "glob" defined in the nclrc.tcl file:

     >NCL> pwd
    /DD
     >NCL> glob *
    .. . OS9Boot CMDS SYS DEFS ccbkrn sysgo startup NITROS9 IOPAGE.BAS ZDIR COUNT100.BAS Z3 Z4 zsq Z93 Z9 Z91
     >NCL> glob *9*
    OS9Boot NITROS9 Z93 Z9 Z91
     >NCL> set i 0; foreach f [glob *9*] {puts "[incr i] : $f"}
    1 : OS9Boot
    2 : NITROS9
    3 : Z93
    4 : Z9
    5 : Z91
     >NCL>
    

    Digging deeper, glob calls readdir, and readdir calls 9read, but NCL doesn't handle NUL chars and binary data, so 9read returns lists of integers for the bytes. implode makes ASCII strings from ints.

    # For file globbing.
    proc implode_thru_hi_bit x {
            set z {}
            foreach i $x {if {bitand $i 128} {lappend z [bitand 127 $i]; break} else {lappend z $i}}
            implode $z
    }
    proc readdir d {
            set z {}
            set fd [9open $d 129]
            while * {
                    if {catch {set v [9read $fd 32]}} break
                    if {lindex $v 0} {lappend z [implode_thru_hi_bit $v]}
            }
            return $z
    }
    # Simple glob in current directory.
    proc glob pat {
            set z {}
            foreach f [readdir .] {if {smatch $pat $f} {lappend z $f}}
            set z
    }
    

  • ncl.bin
  • nclrc.tcl
  • (unless otherwise marked) Copyright 2002-2014 YakPeople. All rights reserved.
    (last modified 2020-01-13)       [Login]
    (No back references.)