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

{ File mrtim

  March 2008

  This file is adapted from /usr/local/tops/usr/tiny to run an
  interactive prompt when file mobius.n is used to display real 
  time markets.

  Copyright (c) 2011-2014   D. R. Williamson
}

{ GNU General Public License

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

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

\ Defining word tinyc, tiny 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
   (qS) "sp" over = IF drop "spx" THEN (qS) 

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

pull (f) catmsg
fence

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

\ Defining new words (new words can be added here, or sourced later
\ from a file).

CATMSG (f) push no catmsg

\ Thu Jan 16 16:53:53 PST 2014.  If mobius.nv (a parsed version 
\ of mobius.n (word parse_save)) is newer than mobius.n, use it; 
\ otherwise, delete it and use mobius.n:
  usrpath "mobius.n" + filefound
  IF (qFile) filetime (s1)
     usrpath "mobius.nv" + filefound
     IF (qFile) filetime (s1 s2) < (NV) \ true if mobius.n is oldest
     ELSE (s1) drop no (NV)
     THEN "NV" book \ NV=true if ok to source mobius.nv
  ELSE " mrtim: file " usrpath "mobius.n" + " not found" + + . nl 
     5 idle exit
  THEN

  NV 
  IF usrpath "mobius.nv" + source
  ELSE 
   \ Silently delete mobius.nv if it is oldest:
     usrpath "mobius.nv" + deleteif 
     usrpath "mobius.n" + psource
  THEN

pull (f) catmsg

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

\ Running tinyc with prompter().

clear
"tinyc" ptr (ptrRun) \ ptr to tinyc

"Electronic Market Console" . nl
NV IF "Using mobius.nv" . nl THEN
"Enter ? for help, exit to quit" . nl 
"Enter a market symbol to connect to the real time data server: " . nl
tracklist1 lowercase vol2str 2 indent . nl

cprompt (qPrompt)    \ prompt to show
prompter 
exit




