Check-in [9352a29c3d]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add some twv demos
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9352a29c3d8faeb8737bbcb3e9c376bdb98586d5
User & Date: chw 2019-06-12 03:17:41
Context
2019-06-12
03:19
add tcl upstream changes check-in: b1cdfa6875 user: chw tags: trunk
03:17
add some twv demos check-in: 9352a29c3d user: chw tags: trunk
2019-06-11
09:31
another update of twv readme (fighting with markdown) check-in: b3e75d7de9 user: chw tags: trunk
Changes

Changes to undroid/build-vanilla-generic.sh.

1738
1739
1740
1741
1742
1743
1744

1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
....
1790
1791
1792
1793
1794
1795
1796




1797
1798
1799
1800
1801
1802
1803
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  if test -d ${PFX_HERE}/lib/fuse* ; then
    cp -rp ${PFX_HERE}/lib/fuse* assets
  fi
  if test -d ${PFX_HERE}/lib/twv* ; then
    cp -rp ${PFX_HERE}/lib/twv* assets

  fi
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  if test "$(uname -o)" = "GNU/Linux" ; then
    cp -rp ${AWDIR}/undroid/mkappimg assets
  fi 
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
    echo > tksqlite \
      'source [file dirname [info script]]/'$(echo tksqlite*)'/tksqlite.tcl'
................................................................................
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    if test -d tcl-fuse ; then
      echo > fuse \
        'set argv0 [file dirname [info script]]/'$(echo fuse*/fusevfs.tcl)
      echo >> fuse 'source $argv0'
    fi




  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \







>





|







 







>
>
>
>







1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
....
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  if test -d ${PFX_HERE}/lib/fuse* ; then
    cp -rp ${PFX_HERE}/lib/fuse* assets
  fi
  if test -d ${PFX_HERE}/lib/twv* ; then
    cp -rp ${PFX_HERE}/lib/twv* assets
    cp -rp ${AWDIR}/undroid/tsb* assets
  fi
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  if test "$(uname -o)" = "GNU/Linux" ; then
    cp -rp ${AWDIR}/undroid/mkappimg assets
  fi
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
    echo > tksqlite \
      'source [file dirname [info script]]/'$(echo tksqlite*)'/tksqlite.tcl'
................................................................................
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    if test -d tcl-fuse ; then
      echo > fuse \
        'set argv0 [file dirname [info script]]/'$(echo fuse*/fusevfs.tcl)
      echo >> fuse 'source $argv0'
    fi
    if test -d ${PFX_HERE}/lib/twv* ; then
      echo > TSB \
        'source [file dirname [info script]]/'$(echo tsb*/tsb.tcl)
    fi
  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \

Changes to undroid/build-vanilla-linux32.sh.

1718
1719
1720
1721
1722
1723
1724

1725
1726
1727
1728
1729
1730
1731
....
1768
1769
1770
1771
1772
1773
1774




1775
1776
1777
1778
1779
1780
1781
  cp -rp ${PFX_HERE}/lib/parse_args* assets
  cp -rp ${PFX_HERE}/lib/tkvlc* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/fuse* assets
  if test -d ${PFX_HERE}/lib/twv* ; then
    cp -rp ${PFX_HERE}/lib/twv* assets

  fi
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  if test "$ACTION" != "ebuild" ; then
    cp -rp ${AWDIR}/undroid/mkappimg assets
  fi
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
................................................................................
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    echo > fuse \
      'set argv0 [file dirname [info script]]/'$(echo fuse*/fusevfs.tcl)
    echo >> fuse 'source $argv0'




  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \







>







 







>
>
>
>







1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
....
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
  cp -rp ${PFX_HERE}/lib/parse_args* assets
  cp -rp ${PFX_HERE}/lib/tkvlc* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/fuse* assets
  if test -d ${PFX_HERE}/lib/twv* ; then
    cp -rp ${PFX_HERE}/lib/twv* assets
    cp -rp ${AWDIR}/undroid/tsb* assets
  fi
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  if test "$ACTION" != "ebuild" ; then
    cp -rp ${AWDIR}/undroid/mkappimg assets
  fi
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
................................................................................
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    echo > fuse \
      'set argv0 [file dirname [info script]]/'$(echo fuse*/fusevfs.tcl)
    echo >> fuse 'source $argv0'
    if test -d ${PFX_HERE}/lib/twv* ; then
      echo > TSB \
        'source [file dirname [info script]]/'$(echo tsb*/tsb.tcl)
    fi
  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \

Changes to undroid/build-vanilla-linux64.sh.

1718
1719
1720
1721
1722
1723
1724

1725
1726
1727
1728
1729
1730
1731
....
1768
1769
1770
1771
1772
1773
1774




1775
1776
1777
1778
1779
1780
1781
  cp -rp ${PFX_HERE}/lib/parse_args* assets
  cp -rp ${PFX_HERE}/lib/tkvlc* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/fuse* assets
  if test -d ${PFX_HERE}/lib/twv* ; then
    cp -rp ${PFX_HERE}/lib/twv* assets

  fi
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  if test "$ACTION" != "ebuild" ; then
    cp -rp ${AWDIR}/undroid/mkappimg assets
  fi
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
................................................................................
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    echo > fuse \
      'set argv0 [file dirname [info script]]/'$(echo fuse*/fusevfs.tcl)
    echo >> fuse 'source $argv0'




  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \







>







 







>
>
>
>







1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
....
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
  cp -rp ${PFX_HERE}/lib/parse_args* assets
  cp -rp ${PFX_HERE}/lib/tkvlc* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/fuse* assets
  if test -d ${PFX_HERE}/lib/twv* ; then
    cp -rp ${PFX_HERE}/lib/twv* assets
    cp -rp ${AWDIR}/undroid/tsb* assets
  fi
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  if test "$ACTION" != "ebuild" ; then
    cp -rp ${AWDIR}/undroid/mkappimg assets
  fi
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
................................................................................
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    echo > fuse \
      'set argv0 [file dirname [info script]]/'$(echo fuse*/fusevfs.tcl)
    echo >> fuse 'source $argv0'
    if test -d ${PFX_HERE}/lib/twv* ; then
      echo > TSB \
        'source [file dirname [info script]]/'$(echo tsb*/tsb.tcl)
    fi
  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \

Changes to undroid/build-vanilla-macosx.sh.

1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
....
1449
1450
1451
1452
1453
1454
1455

1456
1457
1458
1459
1460
1461
1462
....
1490
1491
1492
1493
1494
1495
1496


1497
1498
1499
1500
1501
1502
1503
  if test -d assets/tcluvc* ; then
    cp -rp ${HERE}/tcluvc*/demos assets/tcluvc*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets
................................................................................
  cp -rp ${PFX_HERE}/lib/tserialport* assets
  cp -rp ${PFX_HERE}/lib/topcua* assets
  cp -rp ${PFX_HERE}/lib/parse_args* assets
  cp -rp ${PFX_HERE}/lib/tkvlc* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/twv* assets

  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
................................................................................
      'source [file dirname [info script]]/'$(echo VecTcLab*)'/vectclab.tcl'
    echo > tkmc \
      'source [file dirname [info script]]/'$(echo TkMC*)'/tkmc.tcl'
    echo > helpviewer \
      'source [file dirname [info script]]/'$(echo helpviewer*/main.tcl)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)


  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \







|







 







>







 







>
>







1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
....
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
....
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
  if test -d assets/tcluvc* ; then
    cp -rp ${HERE}/tcluvc*/demos assets/tcluvc*
  fi
  cp -rp ${PFX_HERE}/lib/vectcl0* assets
  cp -rp ${PFX_HERE}/lib/vectcltk0* assets
  cp -rp ${AWDIR}/assets/vectcl*/demo assets/vectcl0*
  cp -rp ${PFX_HERE}/lib/WavReader* assets
  cp -rp ${AWDIR}/assets/VecTcLab* assets/VecTcLab1
  cp -rp ${PFX_HERE}/lib/ral* assets
  cp -rp ${AWDIR}/assets/ralutil* assets
  cp -rp ${PFX_HERE}/lib/tclepeg* assets
  cp -rp ${PFX_HERE}/lib/xotcl* assets
  cp -rp ${PFX_HERE}/lib/nsf* assets
  cp -rp ${PFX_HERE}/lib/vu* assets
  cp -rp ${PFX_HERE}/lib/rl_json* assets
................................................................................
  cp -rp ${PFX_HERE}/lib/tserialport* assets
  cp -rp ${PFX_HERE}/lib/topcua* assets
  cp -rp ${PFX_HERE}/lib/parse_args* assets
  cp -rp ${PFX_HERE}/lib/tkvlc* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/twv* assets
  cp -rp ${AWDIR}/undroid/tsb assets/tsb1
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
................................................................................
      'source [file dirname [info script]]/'$(echo VecTcLab*)'/vectclab.tcl'
    echo > tkmc \
      'source [file dirname [info script]]/'$(echo TkMC*)'/tkmc.tcl'
    echo > helpviewer \
      'source [file dirname [info script]]/'$(echo helpviewer*/main.tcl)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    echo > TSB \
      'source [file dirname [info script]]/'$(echo tsb*/tsb.tcl)
  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \

Changes to undroid/build-vanilla-win32.sh.

1504
1505
1506
1507
1508
1509
1510

1511
1512
1513
1514
1515
1516
1517
....
1549
1550
1551
1552
1553
1554
1555


1556
1557
1558
1559
1560
1561
1562
....
1657
1658
1659
1660
1661
1662
1663

1664
1665
1666
1667
1668
1669
1670
  cp -rp ${PFX_HERE}/lib/DiffUtil* assets
  cp -rp ${PFX_HERE}/lib/parser* assets
  cp -rp ${PFX_HERE}/lib/tclcompiler* assets
  cp -rp ${PFX_HERE}/lib/win32* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/twv* assets

  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
................................................................................
      'source [file dirname [info script]]/'$(echo TkMC*)'/tkmc.tcl'
    echo > helpviewer \
      'source [file dirname [info script]]/'$(echo helpviewer*/main.tcl)
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)


  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \
................................................................................
  cp -rp ${PFX_HERE}/lib/tserialport* tassets
  cp -rp ${PFX_HERE}/lib/topcua* tassets
  cp -rp ${PFX_HERE}/lib/parse_args* tassets
  cp -rp ${PFX_HERE}/lib/tkvlc* tassets
  cp -rp ${PFX_HERE}/lib/tclJBlend* tassets
  cp -rp ${AWDIR}/assets/tdbcjdbc* tassets
  cp -rp ${PFX_HERE}/lib/twv* tassets

  # add sdx
  cp -rp ${HERE}/tclkit/sdx/lib/app-sdx tassets/app-sdx2.0
  cp -rp ${HERE}/tclkit/sdx/lib/sdx tassets/sdx1.0
  cp -rp ${HERE}/tclkit/sdx/lib/starsync tassets/starsync1.0
  cp -rp ${HERE}/tclkit/sdx/lib/stringfileinfo tassets/stringfileinfo0.2
  echo > tassets/sdx 'package require starkit ; package require app-sdx'
  if test "$ACTION" = "ebuild" ; then







>







 







>
>







 







>







1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
....
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
....
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
  cp -rp ${PFX_HERE}/lib/DiffUtil* assets
  cp -rp ${PFX_HERE}/lib/parser* assets
  cp -rp ${PFX_HERE}/lib/tclcompiler* assets
  cp -rp ${PFX_HERE}/lib/win32* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/twv* assets
  cp -rp ${AWDIR}/undroid/tsb* assets
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
................................................................................
      'source [file dirname [info script]]/'$(echo TkMC*)'/tkmc.tcl'
    echo > helpviewer \
      'source [file dirname [info script]]/'$(echo helpviewer*/main.tcl)
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    echo > TSB \
      'source [file dirname [info script]]/'$(echo tsb*/tsb.tcl)
  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \
................................................................................
  cp -rp ${PFX_HERE}/lib/tserialport* tassets
  cp -rp ${PFX_HERE}/lib/topcua* tassets
  cp -rp ${PFX_HERE}/lib/parse_args* tassets
  cp -rp ${PFX_HERE}/lib/tkvlc* tassets
  cp -rp ${PFX_HERE}/lib/tclJBlend* tassets
  cp -rp ${AWDIR}/assets/tdbcjdbc* tassets
  cp -rp ${PFX_HERE}/lib/twv* tassets
  cp -rp ${AWDIR}/undroid/tsb* tassets
  # add sdx
  cp -rp ${HERE}/tclkit/sdx/lib/app-sdx tassets/app-sdx2.0
  cp -rp ${HERE}/tclkit/sdx/lib/sdx tassets/sdx1.0
  cp -rp ${HERE}/tclkit/sdx/lib/starsync tassets/starsync1.0
  cp -rp ${HERE}/tclkit/sdx/lib/stringfileinfo tassets/stringfileinfo0.2
  echo > tassets/sdx 'package require starkit ; package require app-sdx'
  if test "$ACTION" = "ebuild" ; then

Changes to undroid/build-vanilla-win64.sh.

1484
1485
1486
1487
1488
1489
1490

1491
1492
1493
1494
1495
1496
1497
....
1529
1530
1531
1532
1533
1534
1535


1536
1537
1538
1539
1540
1541
1542
....
1637
1638
1639
1640
1641
1642
1643

1644
1645
1646
1647
1648
1649
1650
  cp -rp ${PFX_HERE}/lib/DiffUtil* assets
  cp -rp ${PFX_HERE}/lib/parser* assets
  cp -rp ${PFX_HERE}/lib/tclcompiler* assets
  cp -rp ${PFX_HERE}/lib/win32* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/twv* assets

  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
................................................................................
      'source [file dirname [info script]]/'$(echo TkMC*)'/tkmc.tcl'
    echo > helpviewer \
      'source [file dirname [info script]]/'$(echo helpviewer*/main.tcl)
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)


  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \
................................................................................
  cp -rp ${PFX_HERE}/lib/tserialport* tassets
  cp -rp ${PFX_HERE}/lib/topcua* tassets
  cp -rp ${PFX_HERE}/lib/parse_args* tassets
  cp -rp ${PFX_HERE}/lib/tkvlc* tassets
  cp -rp ${PFX_HERE}/lib/tclJBlend* tassets
  cp -rp ${AWDIR}/assets/tdbcjdbc* tassets
  cp -rp ${PFX_HERE}/lib/twv* tassets

  # add sdx
  cp -rp ${HERE}/tclkit/sdx/lib/app-sdx tassets/app-sdx2.0
  cp -rp ${HERE}/tclkit/sdx/lib/sdx tassets/sdx1.0
  cp -rp ${HERE}/tclkit/sdx/lib/starsync tassets/starsync1.0
  cp -rp ${HERE}/tclkit/sdx/lib/stringfileinfo tassets/stringfileinfo0.2
  echo > tassets/sdx 'package require starkit ; package require app-sdx'
  if test "$ACTION" = "ebuild" ; then







>







 







>
>







 







>







1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
....
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
....
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
  cp -rp ${PFX_HERE}/lib/DiffUtil* assets
  cp -rp ${PFX_HERE}/lib/parser* assets
  cp -rp ${PFX_HERE}/lib/tclcompiler* assets
  cp -rp ${PFX_HERE}/lib/win32* assets
  cp -rp ${PFX_HERE}/lib/tclJBlend* assets
  cp -rp ${AWDIR}/assets/tdbcjdbc* assets
  cp -rp ${PFX_HERE}/lib/twv* assets
  cp -rp ${AWDIR}/undroid/tsb* assets
  # add stripped down TDK
  cp -rp ${AWDIR}/undroid/TDK assets
  # add shortcuts providing builtin:widget, builtin:tksqlite, etc.
  (
    cd assets
    echo > widget \
      'source [file dirname [info script]]/'$(echo tk8*)'/demos/widget'
................................................................................
      'source [file dirname [info script]]/'$(echo TkMC*)'/tkmc.tcl'
    echo > helpviewer \
      'source [file dirname [info script]]/'$(echo helpviewer*/main.tcl)
    echo > zinc-widget \
      'source [file dirname [info script]]/'$(echo Tkzinc*/demos/zinc-widget)
    echo > stardom \
      'source [file dirname [info script]]/'$(echo stardom*/stardom.tcl)
    echo > TSB \
      'source [file dirname [info script]]/'$(echo tsb*/tsb.tcl)
  )
  # add tkchat
  if test -d ${AWDIR}/assets/tkchat* ; then
    cp -rp ${AWDIR}/assets/tkchat* assets
    (
      cd assets
      echo > tkchat \
................................................................................
  cp -rp ${PFX_HERE}/lib/tserialport* tassets
  cp -rp ${PFX_HERE}/lib/topcua* tassets
  cp -rp ${PFX_HERE}/lib/parse_args* tassets
  cp -rp ${PFX_HERE}/lib/tkvlc* tassets
  cp -rp ${PFX_HERE}/lib/tclJBlend* tassets
  cp -rp ${AWDIR}/assets/tdbcjdbc* tassets
  cp -rp ${PFX_HERE}/lib/twv* tassets
  cp -rp ${AWDIR}/undroid/tsb* tassets
  # add sdx
  cp -rp ${HERE}/tclkit/sdx/lib/app-sdx tassets/app-sdx2.0
  cp -rp ${HERE}/tclkit/sdx/lib/sdx tassets/sdx1.0
  cp -rp ${HERE}/tclkit/sdx/lib/starsync tassets/starsync1.0
  cp -rp ${HERE}/tclkit/sdx/lib/stringfileinfo tassets/stringfileinfo0.2
  echo > tassets/sdx 'package require starkit ; package require app-sdx'
  if test "$ACTION" = "ebuild" ; then

Added undroid/tsb/examples/cheatsheet.tsb.

















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
1 {h3 "Taygete Scrap Book Cheat Sheet"} 2 {h4 "Important (internal) global variables"} 3 {table 1 [info global {[A-Z]*}]} 4 {#HTML
<dl>
 <dt><b>ID</b></dt>
 <dd>The current input field during evaluation, an integer number.</dd>
 <dt><b>W</b></dt>
 <dd>The Webview for displaying the page.</dd>
 <dt><b>H</b></dt>
 <dd>The history array of input fields, keys are integer numbers starting from 1.</dd>
</dl>} 5 {# current state of history array
table 2 [array get H]} 6 {h4 "Useful procs in the global namespace"} 7 {info proc *} 8 {#HTML
<dl>
 <dt><code><b>parray</b> arrayname ?pattern?</code></dt>
 <dd>Pretty print an array using <code><b>puts</b></code> and thus outputs after the corresponding input field.</dd><br>
 <dt><code><b>htmlraw</b> html ?hidden?</code></dt>
 <dd>Output raw HTML after the corresponding input field, if <code>hidden</code> is true, auto-hide the input field.</dd><br>
 <dt><code><b>gets</b></code>, <code><b>read</b></code></dt>
 <dd>Overriden, reading from <code>stdin</code> channel yields empty string.</dd><br>
 <dt><code><b>puts</b></code></dt>
 <dd>Overriden, writing to <code>stdout</code>/<code>stderr</code> channels outputs after the corresponding input field.</dd><br>
 <dt><code><b>h1</b> string</code>, <code><b>h2..h5</b></code></dt>
 <dd>Format a HTML header after the correspondig input field, auto-hide the input field.</dd><br>
 <dt><code><b>img</b> ?filename import mime?</code></dt>
 <dd>Format a HTML IMG given <code>filename</code>, if file name omitted, present file selection. If <code>import</code> is true, the image is inlined. If the mime type of the image is unknown it can be specified with the <code>mime</code> parameter.</dd><br>
 <dt><code><b>img_from_binary</b> data mime ?hidden?</code></dt>
 <dd>Format a HTML IMG given the byte array <code>data</code> and mime type <code>mime</code>. If <code>hidden</code> is false, the corresponding input field is not auto-hidden.</dd><br>
 <dt><code><b>table</b> ncols data</code></dt>
 <dd>Format a HTML table, <code>ncols</code> gives the number of columns, if negative, use the first <code>-ncols</code> items as header columns.</dd>
</dl>} 9 {h4 "Useful procs in the tsb namespace"} 10 {info proc tsb::*} 11 {#HTML
<dl>
 <dt><code><b>tsb::load</b> ?filename?</code></dt>
 <dd>Load page from given <code>filename</code>, if file name omitted, present file selection.</dd><br>
 <dt><code><b>tsb::save</b> ?filename?</code></dt>
 <dd>Save page to given <code>filename</code>, if file name omitted, present file selection.</dd><br>
 <dt><code><b>tsb::canvas</b> ?-width w -height h?</code></dt>
 <dd>Creates a <code>canvas</code> emulation implementing enough methods for Plotchart, returns a widget command.</dd><br>
 <dt><code><b>tsb::canvascmd</b> cmd ...</code></dt>
 <dd>Implementation of the canvas widget command, supports <code>create</code>, <code>delete</code> and other methods plus method <code>svg</code> which renders the canvas as SVG after the corresponding input field.</dd><br>
 <dt><code><b>tsb::clear</b></code></dt>
 <dd>Clears the entire page.</dd><br>
 <dt><code><b>tsb::eval</b> id</code></dt>
 <dd>Re-evaluates field with number <code>id</code>.</dd><br>
 <dt><code><b>tsb::print</b></code></dt>
 <dd>Opens the print dialog to print the page.</dd>
</dl>} 12 {h4 "Input Fields"} 13 {#HTML
<p>Input fields have a label of the form <code>in(&lt;number&gt;)</code> where the
number is the index in the history array. Arbitraty text can be entered which
however should be valid Tcl code, except the very first line is <code>#HTML</code>
in which case the following lines should be valid HTML text. The input field
is evaluated when <code>&lt;Shift&gt;-&lt;Return&gt;</code> is pressed.</p>
<p>Depending on the command evaluation the input field is sometimes hidden.
A double click on the corresponding output field(s) makes the input field visible
and thus editable, again.</p>} 14 {h4 "Output Fields"} 15 {#HTML
<p>Each input field has two corresponding output fields which are visible/non-empty
depending on context. One output field receives preformatted text, either the result
or the error message of a command evaluation. The other output field receives HTML,
e.g. for displaying an image or for the <code>#HTML</code> form from the input field.</p>} 16 {tsb::save cheatsheet.tsb}

Added undroid/tsb/examples/plotchart.tsb.

































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
4 {# Plotchart example code

# Part 1: create and configure

set S [::Plotchart::createXYPlot $C {0.0 100.0 10.0} {0.0 100.0 20.0}]} 5 {# Part2: fill in (random) data

$S deletedata
$S dataconfig series1 -colour "red"
$S dataconfig series2 -colour "blue"
$S dataconfig series3 -colour "magenta"

set xd    5.0
set yd   20.0
set xold  0.0
set yold 50.0

for {set i 0} {$i < 20} {incr i} {
   set xnew [expr {$xold + $xd}]
   set ynew [expr {$yold + (rand() - 0.5) * $yd}]
   set ynew2 [expr {$yold + (rand() - 0.5) * 2.0 * $yd}]
   $S plot series1 $xnew $ynew
   $S plot series2 $xnew $ynew2
   $S trend series3 $xnew $ynew2
   set xold $xnew
   set yold $ynew
}

$S interval series2 50.0 40.0 60.0 52.0
$S interval series2 60.0 40.0 60.0

$S xtext "X-coordinate"
$S ytext "Y-data"
$S title "Aha!"

# and finally output SVG

$C svg} 1 {h3 "Plotchart Demo"} 6 {# Cleanup canvas, commented out in order to allow step 5 to be repeated

# $C destroy} 2 {# Need Tk for Plotchart and SVG rendering mainly for font measurement
package require Tk

# ... but Tk may stay inivisble behind the curtain
wm withdraw .

# ... and now Plotchart
package require Plotchart} 7 {tsb::save plotchart.tsb} 3 {# Make a canvas emulation object for SVG output

set C [tsb::canvas -width 600 -height 400]}

Added undroid/tsb/examples/topcua.tsb.

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
8 {tsb::save topcua.tsb} 4 {# get the namespace of the webcam demo
set ns [opcua namespace C LilWebCam]

# name of image variable in address space
set iname "ns=${ns};Image"} 5 {# read the image variable (we know that it's a PNG image)
img_from_binary [opcua read C $iname] image/png 0} 1 {h3 "topcua Demonstration"} 6 {# refresh the image every 5 seconds
catch {after cancel $timer}
set timer [after 5000 {tsb::eval 5 ; tsb::eval 6}]} 2 {# prereqs
package require topcua} 7 {after cancel $timer} 3 {# create client
if {![catch {opcua info C}]} {
    opcua destroy C
}
opcua new client C

# connect to server which should be the webcam demo
opcua connect C opc.tcp://localhost:4840}

Added undroid/tsb/tsb.tcl.



























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
# Load webview.

package require twv

# On MacOSX we need Tk early, otherwise crashes occur.

if {$tcl_platform(os) eq "Darwin"} {
    package require Tk
}

# If nothing is in top toplevel, withdraw it assuming
# we don't need it for now.

if {([info command winfo] eq "winfo") &&
    [winfo exists .] && ([winfo children .] eq "")} {
    wm withdraw .
}

namespace eval ::tsb {
    variable inload 0
    variable ready 0
}

# The history array of input fields.

array set H {1 ""}

# This is invoked from the JS window.external.invoke function.
# The first non-blank characters are assumed to be the integer id
# of the (input) field.

proc ::tsb::call_from_js {str} {
    set n [string first " " $str]
    if {$n < 0} {
	return
    }
    set id [string trim [string range $str 0 $n]]
    incr n
    set str [string trim [string range $str $n end]]
    if {$id == 0} {
	# Should be the ping, Vasily.
	# But can be the reload, too.
	catch {uplevel \#0 $str}
	return
    }
    set ::H($id) $str
    if {$str eq ""} {
	$::W call Wclear $id
	return
    }
    set newfield 0
    set ::ID $id
    if {[string first "#HTML" $str] == 0} {
	set n [string first "\n" $str]
	if {$n > 4} {
	    incr n
	    set str [string range $str $n end]
	}
	$::W call Wraw $id $str 1
	$::W call Inhide $id 1
	set newfield 1
    } elseif {[catch {uplevel \#0 $str} ret opts]} {
	if {[dict get $opts -code] == 4} {
	    # continue
	    $::W call Wclear $id
	} else {
	    $::W call Werror $id $::errorInfo
	}
    } else {
	if {$ret ne ""} {
	    $::W call Wresult $id $ret
	} else {
	    $::W call Wclear $id
	}
	set newfield 1
    }
    if {$newfield} {
	incr id
	if {![info exists ::H($id)]} {
	    set ::H($id) ""
	    $::W call Field $id
	}
    }
    unset -nocomplain ::ID
}

# Change current (input) field if it consisted only of
# single command "cmd". Useful for "img" and load/save
# when a file dialog is used to select the file name.

proc ::tsb::change_field {cmd str} {
    if {[info exists ::ID]} {
	set id $::ID
	if {[string trim $::H($id)] eq $cmd} {
	    $::W call Winput $id $str
	    set ::H($id) $str
	}
    }
}

# Write raw HTML to current output field.

proc htmlraw {str {hidden 0}} {
    if {[info exists ::ID]} {
	$::W call Wraw $::ID $str
	if {$hidden} {
	    $::W call Inhide $::ID 1
	}
    }
    return
}

# Quote angle brackets and double quotes for HTML output.

proc ::tsb::htmlquote {str} {
    regsub -all -- "&" $str "\\&amp;" str
    regsub -all -- "<" $str "\\&lt;" str
    regsub -all -- ">" $str "\\&gt;" str
    regsub -all -- "\"" $str "\\&quot;" str
    return $str
}

# Simple HTML table formatter. If number of columns is negative,
# make a header, otherwise all columns are uniform.

proc table {ncols data} {
    if {$ncols == 0} {
	return
    }
    set ret "<table style='border: 1px solid;"
    append ret " margin-left: 1em; border-collapse: collapse; width: 90%'>"
    if {$ncols < 0} {
	set ncols [expr {0 - $ncols}]
	append ret "<tr>"
	for {set i 0} {$i < $ncols} {incr i} {
	    append ret "<th style='border: 1px solid;'><pre>" \
		[::tsb::htmlquote [lindex $data $i]] "</pre></th>"
	}
	append ret "</tr>"
	set data [lrange $data $ncols end]
    }
    while {[llength $data]} {
	append ret "<tr>"
	for {set i 0} {$i < $ncols} {incr i} {
	    append ret "<td style='border: 1px solid;'><pre>" \
		[::tsb::htmlquote [lindex $data $i]] "</pre></td>"
	}
	append ret "</tr>"
	set data [lrange $data $ncols end]
    }
    append ret "</table><br>"
    htmlraw $ret
}

# Insert various headers (<h1>, <h2> ...) and rulers.

proc h1 {str} {
    htmlraw "<h1>[::tsb::htmlquote $str]</h1>" 1
}

proc h2 {str} {
    htmlraw "<h2>[::tsb::htmlquote $str]</h2>" 1
}

proc h3 {str} {
    htmlraw "<h3>[::tsb::htmlquote $str]</h3>" 1
}

proc h4 {str} {
    htmlraw "<h4>[::tsb::htmlquote $str]</h4>" 1
}

proc h5 {str} {
    htmlraw "<h5>[::tsb::htmlquote $str]</h5>" 1
}

proc hr {} {
    set hr "<hr style='margin-left: 1em; margin-right: 1em;"
    append hr " margin-top: 1em; margin-bottom: 1em;"
    append hr " background-color: #000; height: 2px;'>"
    htmlraw $hr 1
}

# Insert image from local file.

proc img {{name {}} {import 0} {mime {}}} {
    set selname 0
    if {$name eq ""} {
	set selname 1
	set name [$::W dialog open "Select Image"]
    }
    if {$name eq ""} {
	return
    }
    # This needs work.
    if {$mime ne ""} {
	set mime [::tsb::htmlquote $mime]
    } else {
	set mime image/[string tolower [file extension $name]]
    }
    if {![catch {open $name rb} f]} {
	set ret "<img style='margin-left:1em;' src='data:$mime;base64,\n"
	append ret [binary encode base64 -maxlen 78 [read $f]]
	append ret "'>\n<br><br>"
	close $f
	if {$selname || $import} {
	    set cmd [dict get [info frame -1] cmd]
	    if {$import} {
		set newcmd "#HTML\n$ret"
	    } else {
		set newcmd $cmd
		lappend newcmd $name
	    }
	    ::tsb::change_field $cmd $newcmd
	}
	htmlraw $ret 1
    }
    return
}

# Insert image from byte array.

proc img_from_binary {data mime {hidden 1}} {
    set mime [::tsb::htmlquote $mime]
    set ret "<img style='margin-left:1em;' src='data:$mime;base64,\n"
    append ret [binary encode base64 -maxlen 78 $data]
    append ret "'>\n<br><br>"
    htmlraw $ret $hidden
    return
}

# Load and save functions.

proc ::tsb::load {{name {}}} {
    variable inload
    if {$inload} {
	return
    }
    if {$name eq ""} {
	set name [$::W dialog open "Load From File"]
    }
    if {$name eq ""} {
	return
    }
    set f [open $name r]
    set data [read $f]
    close $f
    array set h $data
    after idle [list ::tsb::loadh $data]
    set ::tsb::file $name
    $::W title "$::$tsb::title - [file tail $name]"
    return -code 4 ;# continue
}

proc ::tsb::loadh {data} {
    variable inload
    set inload 1
    unset -nocomplain ::H
    $::W call ClearFields
    foreach {key value} $data {
	if {[string is integer $key]} {
	    set h($key) $value
	}
    }
    foreach key [lsort -integer [array names h]] {
        $::W call InitField $key $h($key)
    }
    foreach key [lsort -integer [array names h]] {
	set ::H($key) ""
	set next $key
	incr next
	set ::H($next) ""
	::tsb::call_from_js "$key $h($key)"
    }
    if {[info exists next]} {
	unset ::H($next)
    }
    set inload 0
}

proc ::tsb::save {{name {}}} {
    variable inload
    if {$inload} {
	return
    }
    set selname 0
    if {$name eq ""} {
	set selname 1
	set name [$::W dialog open "Save To File"]
    }
    if {$name eq ""} {
	return
    }
    set f [open $name w]
    puts $f [array get ::H]
    close $f
    if {$selname} {
	set cmd [dict get [info frame -1] cmd]
	set newcmd $cmd
	lappend newcmd $name
	::tsb::change_field $cmd $newcmd
    }
    set ::tsb::file $name
    $::W title "$::tsb::title - [file tail $name]"
    return -code 4 ;# continue
}

# The sin: the ping function, to keep events alive and kicking.

proc ::tsb::ping {args} {
    # Nothing to see here ...
}

# Reload document related functions; used for initial load, too.

proc ::tsb::reload0 {} {
    variable ready
    if {![info exists ::W]} {
	# Can happen during init of webview.
	return
    }
    set ready 1
    $::W call document.write $::tsb::D
    set title $::tsb::title
    if {$::tsb::file ne ""} {
	append title " - [file tail $::tsb::file]"
    }
    $::W title $title
    ::tsb::loadh [array get ::H]
}

proc ::tsb::reload {args} {
    after cancel ::tsb::reload0
    after idle ::tsb::reload0
}
 
# Clear page.

proc ::tsb::clear {} {
    variable inload
    if {$inload} {
	return
    }
    after idle ::tsb::clearh
    set ::tsb::file ""
    $::W title $::tsb::title
    return -code 4 ;# continue
}

proc ::tsb::clearh {} {
    unset -nocomplain ::H
    $::W call ClearFields
    set ::H(1) ""
    $::W call InitField 1 $::H(1)
}

# Evaluate field.

proc ::tsb::eval {id} {
    tailcall $::W call Feval $id
}

# Print page; on Windows seems not to work, but pressing
# <Control-p> opens the printer dialog.

proc ::tsb::print {} {
    tailcall $::W call window.print()
}

# A minimal canvas emulation for plotchart. The svg method
# produces SVG into the current (output) field.
#
#  set C [::tsb::canvas ...]
#  $C create line 10 10 20 20 -fill black ...
#  ...
#  $C svg
#  $C destroy

namespace eval ::tsb {

    variable C
    array set C {cid 0}

    proc tagfind {c tags} {
	variable C
	set all $C($c,dlist)
	foreach tt $tags {
	    if {$tt eq "&&"} {
		continue
	    }
	    set sub {}
	    if {[string is integer $tt] && [info exists C($c,$tt)]} {
		set sub $tt
	    } else {
		foreach item $all {
		    set t [dict get $C($c,$item) -tags]
		    if {$tt in $t} {
			lappend sub $item
		    }
		}
	    }
	    set all $sub
	}
	return $all
    }

    proc canvascmd {c cmd args} {
	variable C
	set ret ""
	switch -glob -- $cmd {
	    cr* {
		# create
		set args [lassign $args type]
		set id [incr C($c,id)]
		set coords {}
		set count 0
		foreach arg $args {
		    if {[string is double $arg]} {
			lappend coords $arg
		    } else {
			break
		    }
		    incr count
		}
		dict set C($c,$id) -type $type
		dict set C($c,$id) -coords $coords
		dict set C($c,$id) -tags {}
		foreach {opt val} [lrange $args $count end] {
		    if {[string match -ta* $opt]} {
			set opt -tags
		    }
		    dict set C($c,$id) $opt $val
		}
		lappend C($c,dlist) $id
		set ret $id
	    }
	    bb* {
		# bbox, assumes measuring text item with "M"
		set ret {0 0 12 16}
	    }
	    cg* {
		# cget
		switch -glob -- [lindex $args 0] {
		    -bd - -bo* {
			set ret 0
		    }
		    -wi* {
			set ret $C($c,width)
		    }
		    -he* {
			set ret $C($c,height)
		    }
		}
	    }
	    ra* {
		# raise
		lassign $args tags
		set all $C($c,dlist)
		foreach t [tagfind $c $tags] {
		    set n [lsearch -exact $all $t]
		    if {$n >= 0} {
			set all [lreplace $all $n $n]
			lappend all $t
		    }
		}
		set C($c,dlist) $all
	    }
	    lo* {
		# lower
		lassign $args tags
		set all $C($c,dlist)
		foreach t [tagfind $c $tags] {
		    set n [lsearch -exact $all $t]
		    if {$n >= 0} {
			set all [lreplace $all $n $n]
			set all [linsert $all 0 $t]
		    }
		}
		set C($c,dlist) $all
	    }
	    des* {
		# destroy
		set cmd $C($c,cmd)
		foreach name [array names C $c,*] {
		    unset C($name)
		}
		rename "::$cmd" {}
	    }
	    de* {
		# delete
		lassign $args tags
		set all $C($c,dlist)
		foreach t [tagfind $c $tags] {
		    set n [lsearch -exact $all $t]
		    if {$n >= 0} {
			set all [lreplace $all $n $n]
			unset C($c,$t)
		    }
		}
		set C($c,dlist) $all
	    }
	    coo* {
		# coords
		set coords [lassign $args id]
		if {![info exists C($c,$id)]} {
		    foreach item $C($c,dlist) {
			set t [dict get $C($c,$item) -tags]
			if {$id in $t} {
			    if {[llength $coords]} {
				dict set C($c,$item) -coords $coords
			    } else {
				set ret [dict get $C($c,$item) -coords]
			    }
			}
		    }
		} elseif {[llength $coords]} {
		    dict set C($c,$id) -coords $coords
		} else {
		    set ret [dict get $C($c,$id) -coords]
		}
	    }
	    sv* {
		# svg
		package require can2svg
		set xml "<?xml version='1.0'?>\n"
		append xml "<svg width='$C($c,width)' height='$C($c,height)'"
		append xml " version='1.1'"
		append xml " xmlns='http://www.w3.org/2000/svg'"
		append xml " xmlns:xlink='http://www.w3.org/1999/xlink'>\n"
		foreach item $C($c,dlist) {
		    set type [dict get $C($c,$item) -type]
		    switch -- $type {
			image - window {
			    continue
			}
		    }
		    set cmd [list create $type \
				 {*}[dict get $C($c,$item) -coords]]
		    foreach key [dict keys $C($c,$item)] {
			switch -- $key {
			    -tags - -type - -coords {
				# already done or ignored
			    }
			    default {
				lappend cmd $key [dict get $C($c,$item) $key]
			    }
			}
		    }
		    append xml "  " [can2svg::can2svg $cmd {*}$args] "\n"
		}
		append xml "</svg>\n"
		htmlraw $xml 0
	    }
	}
	return $ret
    }

    proc canvas {args} {
	variable C
	set cid $C(cid)
	set cmd tsb_canv_obj$cid
	proc ::$cmd {cmd args} [subst {
	    tailcall [namespace current]::canvascmd $cid \$cmd {*}\$args
	}]
	set C($cid,cmd) $cmd
	set C($cid,dlist) {}
	set C($cid,width) 640
	set C($cid,height) 480
	set C($cid,id) 0
	incr C(cid)
	foreach {key value} $args {
	    switch -glob -- $key {
		-wi* {
		    if {[scan $value %d value]} {
			set C($cid,width) $value
		    }
		}
		-he* {
		    if {[scan $value %d value]} {
			set C($cid,height) $value
		    }
		}
	    }
	}
	return $cmd
    }
}

# Replacements for puts, get, read: move originals to tsb namespace.

rename puts ::tsb::puts
rename gets ::tsb::gets
rename read ::tsb::read

proc puts {args} {
    set len [llength $args]
    lassign $args arg1 arg2 arg3
    if {[info exists ::ID]} {
	switch $len {
	    1 {
		$::W call Wresult $::ID "${arg1}\n"
		return
	    }
	    2 {
		switch -- $arg1 {
		    -nonewline {
			$::W call Wresult $::ID $arg2
			return
		    }
		    stdout {
			$::W call Wresult $::ID "${arg2}\n"
			return
		    }
		    stderr {
			$::W call Werror $::ID "${arg2}\n"
			return
		    }
		}
	    }
	    3 {
		if {($arg1 eq "-nonewline") && ($arg2 eq "stdout")} {
		    $::W call Wresult $::ID $arg3
		    return
		} elseif {($arg1 eq "-nonewline") && ($arg2 eq "stderr")} {
		    $::W call Werror $::ID $arg3
		    return
		}
	    }
	}
    }
    if {[catch [linsert $args 0 ::tsb::puts] msg]} {
	return -code error $msg
    }
    return $msg
}

proc gets {args} {
    set len [llength $args]
    lassign $args arg1 arg2
    if {[info exists ::ID]} {
	switch $len {
	    1 {
		if {$arg1 eq "stdin"} {
		    return ""
		}
	    }
	    2 {
		if {$arg1 eq "stdin"} {
		    upvar 1 $arg2 var
		    set var ""
		    return ""
		}
	    }
	}
    }
    if {[catch [linsert $args 0 ::tsb::gets] msg]} {
	return -code error $msg
    }
    return $msg
}

proc read {args} {
    set len [llength $args]
    lassign $args arg1 arg2
    if {[info exists ::ID]} {
	switch $len {
	    1 {
		if {$arg1 eq "stdin"} {
		    return ""
		}
	    }
	    2 {
		if {($arg1 eq "stdin") && [string is integer $arg2]} {
		    return ""
		}
		if {($arg1 eq "-nonewline") && ($arg2 eq "stdin")} {
		    return ""
		}
	    }
	}
    }
    if {[catch [linsert $args 0 ::tsb::read] msg]} {
	return -code error $msg
    }
    return $msg
}

namespace eval ::tsb {

    # JS core functions assembled from various pieces into a big string.

    variable D

    set D {<html><head>}
    
    if {$::tcl_platform(platform) eq "windows"} {
	append D {
	    <style>
	    body {
		font-family: Arial, Tahoma, sans-serif, Helvetica; font-size: 90%;
	    }
	    </style>
	}
    } else {
	append doc {
	    <style>
	    body {
		font-family: sans-serif, Helvetica; font-size: 90%;
	    }
	    </style>
	}
    }

    append D {
	<script type="text/javascript">

	var msLike = /MSIE|Trident|Edge/i.test(navigator.userAgent);

	if (!msLike && !window.external) {
	    /* See also webview.h */
	    window.external = {
		invoke: function(str) {
		    window.webkit.messageHandlers.external.postMessage(str);
		}
	    };
	}
	
	var needsClear = new Array();

	var RunTcl = function(str) { window.external.invoke(str); };

	var Gtimer = window.setInterval(function() {
	    window.external.invoke("0 ::tsb::ping\n");
	}, 20);

	var Wclear = function(id) {
	    if (!needsClear[id]) {
		return;
	    }
	    var output =
		document.getElementById('out' + id + '-pre').firstChild;
	    output.style.color = 'inherit';
	    output.innerHTML = '';
	    output = document.getElementById('out' + id + '-raw');
	    output.innerHTML = '';
	};

	var Wresult = function(id, str) {
	    var output =
		document.getElementById('out' + id + '-pre').firstChild;
	    str = str.replace(/&/g, '&amp;');
	    str = str.replace(/</g, '&lt;');
	    str = str.replace(/>/g, '&gt;');
	    str = str.replace(/\"/g, '&quot;');
	    output.style.color = 'inherit';
	    if (needsClear[id]) {
		output.innerHTML = str;
		output = document.getElementById('out' + id + '-raw');
		output.innerHTML = '';
	    } else {
		output.innerHTML += str;
	    }
	    needsClear[id] = null;
	};

	var Werror = function(id, str) {
	    var output =
		document.getElementById('out' + id + '-pre').firstChild;
	    str = str.replace(/&/g, '&amp;');
	    str = str.replace(/</g, '&lt;');
	    str = str.replace(/>/g, '&gt;');
	    str = str.replace(/\"/g, '&quot;');
	    output.style.color = 'red';
	    if (needsClear[id]) {
		output.innerHTML = str;
		output = document.getElementById('out' + id + '-raw');
		output.innerHTML = '';
	    } else {
		output.innerHTML += str;
	    }
	    needsClear[id] = null;
	};

	var Wraw = function(id, str) {
	    var output = document.getElementById('out' + id + '-raw');
	    if (needsClear[id]) {
		output.innerHTML = str;
	    } else {
		output.innerHTML += str;
	    }
	    if (needsClear[id]) {
		output =
		    document.getElementById('out' + id + '-pre').firstChild;
		output.style.color = 'inherit';
		output.innerHTML = '';
	    }
	    needsClear[id] = null;
	};

	var Inhide = function(id, hide) {
	    var input = document.getElementById('in' + id);
	    var output = document.getElementById('out' + id + '-raw');
	    if (hide) {
		input.style.display = 'none';
		output.addEventListener('dblclick', function(event) {
		    Inhide(id, 0);
		});
	    } else {
		output.removeEventListener('dblclick', null);
		input.style.display = 'inline';
	    }
	};

	var Winput = function(id, str) {
	    var input = document.getElementById('code' + id);
	    input.value = str;
	    var lines = str.split(/\r?\n|\r/);
	    var nlines = (lines.length < 43) ? lines.length : 43;
	    input.rows = nlines;
	};

	var Feval = function(id) {
	    var input = document.getElementById('code' + id);
	    needsClear[id] = true;
	    RunTcl("" + id + " " + input.value);
	};
    
	var Field = function(id) {
	    var div = document.createElement('div');
	    div.classname = 'field';
	    var html = '<div class="field" id="in' + id + '">';
	    html += '<label for="code' + id + '"';
	    if (!msLike) {
		html += ' style="vertical-align:10px; font-family:monospace;"'
	    }
	    html += '>  in(' + id + ')  </label>';
	    html += '<textarea id="code' + id + '" rows="1"';
	    html += ' style="width:90%; resize:none;';
	    html += ' font-family:monospace; overflow:hidden">';
	    html += '</textarea></div><div class="field"';
	    html += ' id="out' + id + '-pre"';
	    if (msLike) {
		html += ' style="word-break:break-all"'
	    } else {
		html += ' style="overflow-wrap:break-word"'
	    }
	    html += '><pre></pre></div>';
	    html += '<div class="field" id="out' + id + '-raw"></div>';
	    div.innerHTML = html;
	    document.body.appendChild(div);
	    needsClear[id] = null;
	    var input = document.getElementById('code' + id);
	    input.addEventListener('keydown', function(event) {
		var code;
		var shift = false;
		if (window.event) {
		    code = window.event.keyCode;
		    if (window.event.shiftKey) {
			shift = true;
		    }
		} else {
		    code = event.keyCode;
		    if (event.shiftKey) {
			shift = true;
		    }
		    if (shift && code == 13) {
			event.stopPropagation();
		    }
		}
		if (shift && code == 13) {
		    needsClear[id] = true;
		    RunTcl("" + id + " " + input.value);
		    event.preventDefault();
		    return false;
		}
	    });
	    input.addEventListener('input', function(event) {
		var lines = input.value.split(/\r?\n|\r/);
		var nlines = (lines.length < 43) ? lines.length : 43;
		input.rows = nlines;
	    });
	    input.focus();
	    return input;
	};

	var InitField = function(id, str) {
	    var input = Field(id);
	    input.value = str;
	    var lines = str.split(/\r?\n|\r/);
	    var nlines = (lines.length < 43) ? lines.length : 43;
	    input.rows = nlines;
	};

	var ClearFields = function() {
	    while (1) {
		var fields = document.getElementsByClassName('field');
		if (fields.length > 0) {
		    fields[0].parentNode.removeChild(fields[0]);
		    continue;
		}
		break;
	    }
	};

	/* Is this really needed? */
	window.addEventListener('unload', function(event) {
	    window.clearInterval(Gtimer);
	    Gtimer = null;
	});
				
	</script>
    }

    append D {</head><body></body></html>}

    # The URL to be displayed.
    # Windows:   data:text/html,<html><head><script>window.external.invoke("0 ::tsb::reload");</script></head></html>
    # MacOS:     data:text/html,<html><head><script>window.external.invoke("0 ::tsb::reload");</script></head></html>
    # WebkitGtk: data:text/html,<html><head><script>window.webkit.messageHandlers.extern.postMessage("0 ::tsb::reload");</script></head></html>

    variable U
    set U "data:text/html,%3Chtml%3E%3Chead%3E%3Cscript%3E"
    if {($tcl_platform(platform) eq "windows") ||
	($tcl_platform(os) eq "Darwin")} {
	append U "window.external.invoke(%220%20::tsb::reload%22)%3B"
    } else {
	append U "window.webkit.messageHandlers.external.postMessage(%220%20::tsb::reload%22)%3B"
    }
    append U "%3C%2Fscript%3E%3C%2Fhead%3E%3C%2Fhtml%3E"

    # The base title
    variable title "Taygete Scrap Book"

    # The current file
    variable file ""
}

# If file name given, load history array from it now.

set title $::tsb::title
if {[llength $argv] && [file readable [lindex $argv 0]]} {
    catch {
	apply {name {
	    set f [open $name r]
	    set data [read $f]
	    close $f
	    array set ::H $data
	    set ::tsb::file $name
	}} [lindex $argv 0]
    }
}

# Initialize webview; document is loaded indirectly via the URL
# which triggers ::tsb::reload which does the rest, but see
# the ::tsb::ready block below.

set W [::twv::new -width 800 -height 600 -title $::tsb::title \
	   -url $::tsb::U -resizable 1 -debug 0 \
	   -callback ::tsb::call_from_js]

# On Windows this seems needed.

if {!$::tsb::ready} {
    ::tsb::reload0
}

# Enter webview event loop.

$W run

# Done.

exit 0