View/Edit #3152:file_grep

Switch to edit mode.

Name(s): file_grep
1:  "Syntax: file_grep(object, file, text, case-sensitive)"
2:  "Returns 0 if text is not found, and a line number if the text is found."
3:  {?object = #-1, ?file = "", ?text = " ", ?case = 0} = args
4:  valid(object) && typeof(file) == $STR || raise(E_INVARG, "Object must be valid and file must be a string.")
5:  f = 0
6:  if (!object:fileexists(file) || $file_utils:is_binary(object, file) || !object:fileaccess(file))
7:    return f
8:  else
9:    for x in (object:fileread(file))
10:     f = f + 1
11:     if (index(x, text, case))
12:       return f
13:     endif
14:     ticks_left() > 100 || $cmd_utils:suspend_if_needed(1)
15:   endfor
16: endif
17: "Last modified by Dax (#789) on Tue May  3 14:03:28 2005 MDT."

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Anon (#3152)

You are not logged in.

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