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

{ File mday

  March 2008

  This file is adapted from /usr/local/tops/usr/tiny to run an 
  interactive prompt when file mday.n is used to display daily 
  markets.
  
   Copyright (c) 2008   D. R. Williamson
}

{ GNU General Public License

Program Tops - a stack-based computing environment
Copyright (C) 1999-2005  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.

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

no catmsg
"key.v" "Keyboard words" msource keyboard
ok off \ no auto stack display; use .s to see stack

mpath dirnames "daily.lock" grepr rows 0>
IF " Daily is running.  Start another?  ([no], yes, rm) > "
\ rm removes old lock files and then starts another
   query push nl
   peek "yes" = 
   peek "y" = or
   peek "rm" = or not IF exit THEN

   peek "rm" =
   IF mpath dirnames mpath nose dup "daily.lock" grepr reach (hF)
      (hF) 1st over rows
      DO dup I quote delete LOOP drop \ remove lock files
   THEN
   pull drop
THEN

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

\ New words.

{" \ Function to display LATEST at every prompt (adapted from
   \ mday.Kfunc):
   "func" "MKT" localref exists?
   IF "func" "MKT" yank any?
      IF LATEST vol2str cprompt nose . THEN
   THEN
"}
"Kfunc" macro

\ Running word mday() just loaded from uboot.v, not this script 
\ named mday:
  mday 

inline: uclean_tiny ( --- ) \ uclean will run this on exit 
\ Remove this job's lock file
   mpath runid + '_daily.lock' + deleteif
end

clear

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

inline: cprompt ( --- qS) \ the console prompt
   "tinyc" "prompt" yank
end

inline: tinyc (qS --- f) \ prompter runs ptr to this word
   [ "% " into prompt, prompt chars into len ]
   [ "tout chars 0> IF nl THEN Kfunc nl" "NL" macro ] \ show LATEST

   "bye"  over = IF "exit" THEN    \ no Good-bye
   "sp"  over = IF drop "spx" THEN \ make sp work for spx, not space

   nl main \ run text S
   NL      \ run NL macro
   yes     \ keep running
end

mpath runid + "_daily.lock" + crush
"tinyc" ptr (nPTR) \ ptr to run
cprompt            \ prompt to show from tinyc lib
prompter 
