Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/examples/timecalc.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH Demo application - (c) 1995,2003 HanSoft & Partners
\ Portions by Leo Brodie

[needs lib/enter.4th]

: sextal 6 base ! ;
: :00 # sextal # decimal 58 hold ;
: sec <# :00 :00 #S #> type space ;
: to_secs [char] : parse-word number * ;
: margin 25 spaces ;

: EnterTime
      cr ." Enter time as 'hh:mm:ss': " refill drop
      3600 to_secs
        60 to_secs
         1 to_secs + +
;

: Show sp@ 2 < if exit else swap dup cr margin rot execute cr then ;
: Seconds ." Seconds: " . ;
: Times ." Time: " sec ;
: EnterSecs cr ." Enter number of seconds: " enter ;
: AddEntries sp@ 2 < if exit else + then ;
: ShowSecs ' Seconds Show ;
: ShowTime ' Times Show ;

create jumptable
       ' EnterTime , ' EnterSecs ,
       ' AddEntries , ' ShowSecs ,
       ' ShowTime ,

: menu   ( -- n )
  margin 5 spaces ." ** MENU **" cr cr
  margin ." 1) Enter time" cr
  margin ." 2) Enter seconds" cr
  margin ." 3) Add previous two entries" cr
  margin ." 4) Show number of seconds" cr
  margin ." 5) Show time" cr
  margin ." 6) Exit" cr cr
  margin ." Your choice: "
  enter
  dup 0 > if
  dup 6 < if
    jumptable 1- + @c execute 0
  then
  then
  cr cr
;

: do_menu begin menu 6 = until ;

do_menu

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].