Provide a framework for text filters
int filter(int argc, char *argv, int (*process)(char *file))
||how many argument strings
||array of pointers to argument strings
||function that processes each argv string
||one (1) on success, any other integer value on failure
TO DO: change this to 0 on success.
provides a framework to make the job of writing a text filter easier by abstracting the "boilerplate" code that is common to all text filters.
The routine loops through the its argv array reopening each as standard input and calling the routine pointed to by the process argument for each one.
filter starts with argv; it ignores argv so that the argv passed into the main() routine can be passed directly to filter().
Note that filter() treats all the argv entries as file names. If there are any options or qualifiers on the command line they should be removed before filter() is called.
Instead of a reopening a file a standard input, filter() processes the original standard input in three cases.
- argv is empty, i.e. the argv array only contains one entry
- the value of the argv entry is a single dash ("-")
- the value of the argv entry is NULL
If the routine pointed to by the process argument returns any value other than
one (1), filter() assumes an error has occurred. In this case, filter() terminates its loop through the argv array and returns the non-one value.