#!/usr/local/bin/tops -p -s /usr/local/tops/sys -u /opt/mytops/usr/
#!../src/tops -s ../sys -u ../usr

{ File tcon

  May 2010

  This file is adapted from /usr/local/tops/usr/tiny to run an
  interactive prompt when tops is being run as the basic start up
  server (by running STARTUP in file usr/uboot.v) to start watch
  dogs, start the sound file server, send local IP address to sites 
  on the web, and continually monitor sites on the web.

   Copyright (c) 2010   D. R. Williamson
}

{ GNU General Public License

Program Tops - a stack-based computing environment
Copyright (C) 1999-2013  Dale R. Williamson

Author: Dale R. Williamson <dale.williamson@prodigy.net>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

------------------------------------------------------------------------

  File: tiny  December 2003
  Copyright (C) 2003  D. R. Williamson

  This script runs the program interactively in a minimal style, 
  like Forth.

  Use .s to display the stack.

---------------------------------------------------------------------- }

\ Starting a keyboard.

no catmsg
"key.v" "Keyboard words" msource
keyboard
keyboard_finish
ok off \ no auto stack display; .s shows the stack

\-----------------------------------------------------------------------

\ Tinyc console.

CATMSG (f) push no catmsg

inline: cprompt ( --- qS) \ the console prompt
   [ "% " "prompt" book ] prompt ;

inline: tinyc (qS --- f) \ prompter runs this word
   [ "tout chars 0> IF nl THEN" "NL" macro ]

   (qS) "bye" over = IF drop "exit" THEN (qS) \ no Good-bye

   nl (qS) main \ run text S
   NL           \ run NL macro
   yes (f)      \ keep prompter running
end

pull (f) catmsg
fence

\-----------------------------------------------------------------------

\ Words.

CATMSG (f) push no catmsg

\ First version of uclean_tiny:
inline: uclean_tiny ( --- ) \ uclean will run this on exit
   [ mpath "tcon.lock" + "LOCKFILE" book ]
end

\ Before making the full version of uclean_tiny (on redefinition below),
\ check that LOCKFILE does not exist and exit if it does:
mpath dirnames "uclean_tiny" "LOCKFILE" yank -path grepr rows 0>
IF " Lock file found: start up server is running." . nl
   " [Enter] to close this window, r to remove lock file and continue: "
   query nl lowercase "r" =
   IF "uclean_tiny" "LOCKFILE" yank deleteif 
   ELSE
      exit \ runs first version of uclean_tiny, does not delete LOCKFILE
   THEN
THEN

\ Full version of uclean_tiny (includes LOCKFILE booked in version 1):
inline: uclean_tiny ( --- ) \ uclean will run this on exit
\  Delete this job's lock file:
   LOCKFILE deleteif

\  Cleanup to do:

   "STARTUP" exists? 
   IF "STARTUP" "WPORT" yank -1 >
      IF "STARTUP" "KILL_SNDSERVER" yank shell \ kill SNDSERVER
      THEN
   THEN

 \ Remove host IP reference from msgcomm:
   host msgGet drop

   serverclose \ Wed May  8 18:19:14 PDT 2013
end

\fence

"uclean_tiny" "LOCKFILE" yank crush \ make a 1-byte lockfile

pull (f) catmsg

\-----------------------------------------------------------------------

\ Running tinyc with prompter().

"HOME" env chdir
clear
\ Start the start up server
  WWW 
"tinyc" ptr (ptrRun) \ ptr to tinyc
cprompt (qPrompt)    \ prompt to show
prompter 
exit
