: book ( -- d ) trigger @ location dup "*copyof" prop-exists? if "*copyof" getpropstr atoi dbref then ; : say ( s -- ) me @ swap notify ; : sls ( s -- s ) dup " " 1 strncmp not if 1 strcut swap pop sls then ; : reading ( -- ) loc @ me @ dup name " opens a book and reads a passage within it silently." strcat notify_except ; : perusing ( -- ) loc @ me @ dup name " opens a book and scans the table of contents." strcat notify_except ; : do_inscribe book owner me @ dbcmp not me @ wizard? not and if "## You can't do that to his book!" say exit then 1 begin "_" over intostr strcat "_1" strcat book swap prop-exists? while 1 + loop "Writing to page " over intostr strcat "." strcat say "Title:" say read dup not if pop "" then me @ "_lnswitch" "on" 0 addprop over intostr "_" swap strcat "_1" strcat book swap rot 0 addprop "Title stored." say "Please enter body of text below. ##? for editor help." say 2 begin me @ "_lnswitch" prop-exists? if dup 1 - intostr ">" strcat say then read dup "." stringcmp while dup "##" 2 strncmp if 3 pick intostr "_" swap strcat "_" strcat 3 pick intostr strcat book swap rot 0 addprop else 2 strcut swap pop sls dup tolower "off" 2 strncmp not if me @ "_lnswitch" remove_prop then dup tolower "on" 2 strncmp not if me @ "_lnswitch" "on" 0 addprop then dup "-" 1 strncmp not if over 2 <= if "## No line to delete" say swap pop 2 swap else "## Backing up 1 line" say swap 1 - swap then then dup "?" 1 strncmp not if "-> ##on = turn line numbers on" say "-> ##off = turn line numbers off" say "-> ##- = back up one line" say "-> ##^x^y = sub y for x in last line" say "-> ##? = this help information" say then dup "^" 1 strncmp not if over 2 <= if "## No line in buffer" say swap pop 2 swap else dup 1 strcut swap pop dup "^" instr 1 - strcut 1 strcut swap pop swap "_" 6 pick intostr strcat "_" strcat 5 pick 1 - intostr strcat book over getpropstr 3 pick instr not if pop pop pop "## Text not found" say else book over getpropstr 4 rotate 4 rotate subst book rot rot 0 addprop "## Text substitued" say then then then pop 1 - then 1 + loop pop 2 - intostr " line(s) entered." strcat say pop me @ "_lnswitch" remove_prop ; : do_delete book owner me @ dbcmp not me @ wizard? not and if "## You can't do that to this book!" pop say exit then book "_1_1" prop-exists? not if "## The book is empty" say pop exit then dup not if "## You have to specify what you want to delete!" say pop exit then dup number? not if 0 swap 1 begin "_" over intostr strcat "_1" strcat book over prop-exists? while book swap getpropstr tolower 3 pick tolower instr if rot pop dup rot rot then 1 + loop pop pop pop else atoi then dup not over "_" swap intostr strcat "_1" strcat book swap prop-exists? not or if pop pop pop "## Couldn't find page or title." say exit then "## Deleting page " over intostr strcat "." strcat say book over "_" swap intostr strcat "_1" strcat getpropstr "## Title: " swap strcat say begin dup 1 + intostr "_" swap strcat "_1" strcat book swap prop-exists? while 1 begin over "_" swap intostr strcat "_" strcat over intostr strcat book over prop-exists? while book swap remove_prop 1 + loop pop pop 1 begin over 1 + "_" swap intostr strcat "_" strcat over intostr strcat book over prop-exists? while book swap getpropstr 3 pick intostr "_" swap strcat "_" strcat 3 pick intostr strcat book swap rot 0 addprop 1 + loop pop pop 1 + loop 1 begin over "_" swap intostr strcat "_" strcat over intostr strcat book over prop-exists? while book swap remove_prop 1 + loop pop pop "## Deleted." say ; : do_help "## ------------------------------------------" say "## Welcome to Sjade's Magic Tomes 1.01 " say "## ------------------------------------------" say trigger @ location "*copyof" prop-exists? not if "## inscribe | enter an entry into a book" say "## delete <#> | remove an entry from a book" say then "## view <#> | view entry from a book" say "## contents | show a table of contents" say "## book help | this help screen" say "## ------------------------------------------" say "## is delay (in seconds) between lines" say "## ------------------------------------------" say ; : do_view book "_1_1" prop-exists? not if "## The book is empty" say pop exit then dup not if "## You have to specify what you want to view!" say pop exit then dup " " instr dup if 1 - strcut 1 strcut swap pop dup number? not if pop "0" then else pop "0" then atoi swap dup number? not if 0 swap 1 begin "_" over intostr strcat "_1" strcat book over prop-exists? while book swap getpropstr tolower 3 pick tolower instr if rot pop dup rot rot then 1 + loop pop pop pop else atoi then dup not over "_" swap intostr strcat "_1" strcat book swap prop-exists? not or if pop "## Couldn't find page or title." say exit then "Reading from page " over intostr strcat "." strcat say dup "_" swap intostr strcat "_1" strcat book swap getpropstr "Title: " swap strcat say " " say reading 2 begin "_" 3 pick intostr strcat "_" strcat over intostr strcat book swap prop-exists? while "_" 3 pick intostr strcat "_" strcat over intostr strcat book swap getpropstr "# " swap strcat say 3 pick dup if sleep else pop then 1 + loop swap pop " " say 2 - intostr " line(s) displayed." strcat say pop ; : do_contents book "_1_1" getpropstr not if "## The book is empty" say exit then perusing "## Page | Title" say "## ----------------------------------------------" say 1 begin "_" over intostr strcat "_1" strcat book swap prop-exists? while dup intostr dup strlen " " swap strcut swap pop swap strcat "## " swap strcat " | " strcat over intostr "_" swap strcat "_1" strcat book swap getpropstr strcat say 1 + loop pop ; : main trigger @ name dup "inscribe" stringcmp not if pop pop do_inscribe exit then dup "view" stringcmp not if pop do_view exit then dup "contents" stringcmp not if pop pop do_contents exit then dup "book help" stringcmp not if pop pop do_help exit then dup "delete" stringcmp not if pop do_delete exit then pop "## Book action error." me @ swap notify ;