Provide a framework for text filters
Prototype argc int filter(int argc, char *argv[], int (*process)(char *file))
Parameters argc how many argument strings
  argv array of pointers to argument strings
  process function that processes each argv string
Return Value: one (1) on success, any other integer value on failure
TO DO: change this to 0 on success.
filter() 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[1]; it ignores argv[0] 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.
  1. argv[1] is empty, i.e. the argv array only contains one entry
  2. the value of the argv entry is a single dash ("-")
  3. 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.
Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 26 of 485)
Comments, flames, broken links?
Please send email to