: say ( s -- ) me @ swap notify ; : usage ( -- ) "Usage: grep -[cefhimop] pattern object" say " c <-- display number of matches found" say " e <-- do not search exits" say " f <-- do not search fields" say " h <-- show this grep help screen" say " i <-- case insensitive search" say " m <-- do not search miscellaneous properties" say " o <-- do not search contents" say " p <-- do not search properties" say ; : explode_clear ( z x1 .. xN N -- z ) begin dup while swap pop 1 - repeat pop ; : case ( -- i ) 3 pick "i" instr if tolower then ; : grep_fields ( s d s i -- s d s i ) 3 pick daemon? if exit then 3 pick desc case dup 6 pick instr if "@DESC----> " swap strcat say 1 + else pop then 3 pick succ case dup 6 pick instr if "@SUCC----> " swap strcat say 1 + else pop then 3 pick osucc case dup 6 pick instr if "@OSUCC---> " swap strcat say 1 + else pop then 3 pick fail case dup 6 pick instr if "@FAIL----> " swap strcat say 1 + else pop then 3 pick ofail case dup 6 pick instr if "@OFAIL---> " swap strcat say 1 + else pop then 3 pick drop case dup 6 pick instr if "@DROP----> " swap strcat say 1 + else pop then 3 pick odrop case dup 6 pick instr if "@ODROP---> " swap strcat say 1 + else pop then ; : grep_properties ( s d s i -- s d s i ) 3 pick daemon? if exit then 3 pick propfirst begin while over over getpropstr 5 pick "i" instr if tolower then over 6 pick "i" instr if tolower then 8 pick instr swap 8 pick instr or if dup ": " strcat 3 pick 3 pick getpropstr strcat "PROPERTY-> " swap strcat say rot 1 + rot rot then propnext loop ; : grep_misc ( s d s i -- s d s i ) 3 pick unparse_flags case dup 6 pick instr if "FLAGS----> " swap strcat say 1 + else pop then 3 pick unparse_lock case dup 6 pick instr if "LOCK-----> " swap strcat say 1 + else pop then 3 pick dup player? swap thing? or if 3 pick getlink name case dup 6 pick instr if "HOME-----> " swap strcat say 1 + else pop then then 3 pick dup #0 dbcmp not swap daemon? not and if 3 pick location name case dup 6 pick instr if "LOCATION-> " swap strcat say 1 + else pop then then ; : grep_objects ( s d s i -- s d s i ) 3 pick dup room? swap player? or not if exit then 3 pick contents begin dup while dup name 4 pick "i" instr if tolower then 6 pick instr if "CONTENTS-> " over name strcat say swap 1 + swap then next loop pop ; : grep_exits ( s d s i -- s d s i ) 3 pick dup dup dup room? 4 rotatei player? rot thing? or or not if exit then 3 pick exits begin dup while dup name 4 pick "i" instr if tolower then 6 pick instr if "ACTION---> " over name strcat say swap 1 + swap then next loop pop ; : grep ( s s s -- ) over "h" instr if pop pop pop pop usage exit then pop rot swap over match dup dup dup #-1 dbcmp rot #-2 dbcmp rot #-3 dbcmp or or if pop pop pop pop "grep: invalid object" say exit then dup owner me @ dbcmp not me @ "C" flag? not and if pop pop pop pop "grep: uncontrolled object" say exit then rot pop swap 0 over "i" instr if 4 rotate tolower -4 rotate then over "f" instr not if grep_fields then over "p" instr not if grep_properties then over "m" instr not if grep_misc then over "o" instr not if grep_objects then over "e" instr not if grep_exits then over "c" instr if dup 1 = if " occurrence." else " occurrences." then "Grep found " rot intostr strcat swap strcat say else pop "Grep complete." say then pop pop pop ; : main ( s -- ) .sstrip dup "" strcmp not if pop usage exit then dup " " instr not if pop usage exit then " " explode dup dup 3 > swap 2 < or if explode_clear usage exit then dup 3 = if swap tolower swap grep else "" swap grep then ;