View/Edit #13:@grep*! @egrep*!

Switch to edit mode.

Name(s): @grep*! @egrep*!
1:   "@[e]grep*! <expression> on [objects|player]<.:!>"
2:   "Searches properties, verbs and files on the object(s) for the expression."
3:   "Expression is literal, unless @egrep is used in which case it is a regex."
4:   "Only lists the first match in each prop/verb/file, unless grep! is used."
5:   "Objects can be a range in the format of #123..#234 or #123-#234."
6:   "If just a player is specified, then their audit is included in the grep."
7:   "If no objects are specified, then the entire Moo is grepped."
8:   ""
9:   if (player != this)
10:    return $msg:mtell("huh")
11:  endif
12:  this:isa($guardian) || set_task_perms(player)
13:  all_matches = verb[$] == "!"
14:  is_regex = verb[2] == "e"
15:  m = match(iobjstr, "[.:!]*$")
16:  mode = m[$][3]
17:  objectstr = $su:trim(iobjstr[1..m[$][1] - 1])
18:  if (!objectstr)
19:    "If no objects are specified, then the entire Moo is grepped."
20:    objects = $set_utils:union($root:descendants_suspended(), {$trash, $root, $new_root})
21:  elseif (m = match(objectstr, "^(#?[0-9]+)(-|%.%.)(#?[0-9]+)$"))
22:    "Objects can be a range in the format of #123..#234 or #123-#234."
23:    objects = {}
24:    for x in [toobj(m[1][3])..toobj(m[3][3])]
25:      $recycler:valid(x) && (objects = {@objects, x})
26:    endfor
27:  else
28:    objects = {player:my_match_object(objectstr)}
29:    if ($command_utils:object_match_failed(objects[1], objectstr))
30:      return
31:    elseif (objects[1]:isa($accountable))
32:      "If just a player is specified, then their audit is included"
33:      objects = setadd(objects[1].owned_objects, objects[1])
34:    endif
35:  endif
36:  syntax = "Syntax: @[e]grep*! &lt;expression&gt; on [objects|player]&lt;.:!&gt;"
37:  "Undo the damage caused by the XML munging system..."
38:  dobjstr = player:input_get_raw(dobjstr)
39:  if (!dobjstr)
40:    player:tell("No expression given.")
41:    player:tell(syntax)
42:    return
43:  elseif (!objects)
44:    player:tell("Zero objects specified.")
45:    player:tell(syntax)
46:    return
47:  elseif (is_regex && `match("test", dobjstr) ! E_INVARG' == E_INVARG)
48:    player:tell("'", $html_utils:literal_text(dobjstr), "' is not a legal regular expression.")
49:    player:tell(syntax)
50:    return
51:  elseif (!mode)
52:    player:tell("Grep what?  Properties (.) Verbs (:) and/or Files (!)")
53:    player:tell(syntax)
54:    return
55:  endif
56:  $code_utils:semaphore_enter("grep")
57:  if (index(mode, "."))
58:    this:tell("<B>=== ", verb, " of properties on ", length(objects) == 1 ? $su:nn(objects[1]) | tostr(length(objects), " objects"), " for '", $html_utils:literal_text(dobjstr), "' ===</B>")
59:    count = 0
60:    for x in (objects)
61:      $cmd_utils:suspend_if_needed()
62:      for y in ($code_utils:grep_props(x, dobjstr, is_regex, all_matches))
63:        this:tell($html_utils:literal_text(tostr(x, ".", y[1], " (Line ", y[2], ") -> ", y[3])))
64:        count = count + 1
65:        if (count == 100 && player:isa($guardian))
66:          if (!$command_utils:yes_or_no("100 property matches printed.  Continue with the spam?", 2))
67:            break x
68:          endif
69:        elseif (count == 100 && !player:isa($guardian))
70:          player:tell("100 property matches printed.  Too much spam.  Terminating grep.")
71:          break x
72:        endif
73:      endfor
74:    endfor
75:  endif
76:  if (index(mode, ":"))
77:    this:tell("<B>=== ", verb, " of verbs on ", length(objects) == 1 ? $su:nn(objects[1]) | tostr(length(objects), " objects"), " for '", $html_utils:literal_text(dobjstr), "' ===</B>")
78:    count = 0
79:    for x in (objects)
80:      $cmd_utils:suspend_if_needed()
81:      for y in ($code_utils:grep_verbs(x, dobjstr, is_regex, all_matches))
82:        this:tell($html_utils:literal_text(tostr(x, ":", verbs(x)[y[1]], " (Line ", y[2], ") -> ", y[3])))
83:        count = count + 1
84:        if (count == 100 && player:isa($guardian))
85:          if (!$command_utils:yes_or_no("100 verb matches printed.  Continue with the spam?", 2))
86:            break x
87:          endif
88:        elseif (count == 100 && !player:isa($guardian))
89:          player:tell("100 verb matches printed.  Too much spam.  Terminating grep.")
90:          break x
91:        endif
92:      endfor
93:    endfor
94:  endif
95:  if (index(mode, "!"))
96:    this:tell("<B>=== ", verb, " of files on ", length(objects) == 1 ? $su:nn(objects[1]) | tostr(length(objects), " objects"), " for '", $html_utils:literal_text(dobjstr), "' ===</B>")
97:    if (!player:tell("[Sorry, file grepping hasn't been implemented yet.]"))
98:      count = 0
99:      for x in (objects)
100:       $cmd_utils:suspend_if_needed()
101:       for y in ($code_utils:grep_files(x, dobjstr, is_regex, all_matches))
102:         this:tell($html_utils:literal_text(tostr(x, "!", y[1], " (Line ", y[2], ") -> ", y[3])))
103:         count = count + 1
104:         if (count == 100 && player:isa($guardian))
105:           if (!$command_utils:yes_or_no("100 file matches printed.  Continue with the spam?", 2))
106:             break x
107:           endif
108:         elseif (count == 100 && !player:isa($guardian))
109:           player:tell("100 file matches printed.  Too much spam.  Terminating grep.")
110:           break x
111:         endif
112:       endfor
113:     endfor
114:   endif
115: endif
116: this:tell("<B>=== End of ", verb, " ===</B>")
117: $code_utils:semaphore_exit("grep")
118: "Last modified by whiz (#3135) on Mon Feb 11 00:13:48 2008 EST."

Verb arguments: any on top of/on/onto/upon any
Verb perms: Readable NOT-Debug
Verb owned by: Dax (#789)

You are not logged in.

[home | help | who | search | setup | code]