160 constant max-line-chars
variable byte
create line-buf max-line-chars chars allot
variable lbcnt
variable fd
variable linecnt
\ Base logfile
\
: logfile s" log.000" ;
\ Create a new logfile with new 3 digit numeric extension
\ (e.g. log.001)
\
: gen-logfile ( nnn -- caddr u) 0 <# # # # #> logfile + 3 - swap drop 3 cmove logfile ;
\ Does this log file exist or is it available (free)?
\
: logfile-free? ( caddr u -- f) r/o open-file ?dup if drop 1 exit then close-file drop 0 ;
\ Iterate through to a free logfile.
\ We support up to 1000 log files before we fail.
\ (Need a failure handler!)
\
: next-logfile ( -- ) 999 0 do i gen-logfile logfile-free? if unloop exit then loop ;
: wiki-logger ( -- )
0 lbcnt !
lcd-cls
next-logfile
logfile w/o create-file ?dup if
cr lcd-." Can't create log: " lcd-. drop exit
then
fd !
lcd-cr
logfile lcd-type lcd-cr
lcd-." Ready. Press any button to exit." lcd-cr lcd-cr
begin
\ sleep only between lines
key? 0= lbcnt @ 0= and if wait-for-event then
key? if
key dup line-buf lbcnt @ + c! 1 lbcnt +! ( -- c)
10 = if
line-buf lbcnt @ 2dup fd @ write-line drop
lcd-type lcd-cr
0 lbcnt !
then
then
button? if
\ A button was pressed so clean up
\ and exit.
\
button-flush
fd @ close-file
exit
then
ctp-flush \ not interested
again ;
wiki-logger
You know how to decompress wikireader data?
ReplyDeleteNope. Not off the top of my head. But the decompressing code should be in the Wikireader open sources.
ReplyDelete