[3ae31e9] | 1 |
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | Function: filter "Filter Command Line Files In Classic UNIX Style"
|
---|
| 5 |
|
---|
| 6 | Created: Sat Aug 10 21:57:12 EDT 1985
|
---|
| 7 | By: Gary Perlman (Wang Institute, Tyngsboro, MA 01879 USA)
|
---|
| 8 |
|
---|
| 9 | Compilation: nothing unusual
|
---|
| 10 |
|
---|
| 11 | Tester: $Compile: cc -DSTANDALONE -o filter %f
|
---|
| 12 |
|
---|
| 13 | Preconditions:
|
---|
| 14 | The index of the first file operand has been determined.
|
---|
| 15 |
|
---|
| 16 | Postconditions:
|
---|
| 17 | All files have been opened, processed, and closed.
|
---|
| 18 |
|
---|
| 19 | Returns:
|
---|
| 20 | The return status (non-zero is bad) depends on the accessibility
|
---|
| 21 | of files, the ability to open them, and the return statuses of
|
---|
| 22 | the called function.
|
---|
| 23 |
|
---|
| 24 | Exceptions:
|
---|
| 25 | If any file cannot be accessed, then none will be processed.
|
---|
| 26 | During processing, if something goes wrong (a file that could
|
---|
| 27 | be accessed cannot be opened, or the file processor returns a
|
---|
| 28 | non-zero status), processing continues.
|
---|
| 29 |
|
---|
| 30 | Notes:
|
---|
| 31 | "-" is the conventional name for the standard input.
|
---|
| 32 | It can only be read once.
|
---|
| 33 | Fputs and putc are used to print error messages to avoid
|
---|
| 34 | loading fat fprintf just because filter used it.
|
---|
| 35 |
|
---|
| 36 | Some modifications might be useful but unpopular:
|
---|
| 37 | If there is piped input (!isatty (fileno (stdin))),
|
---|
| 38 | and the standard input is not read,
|
---|
| 39 | then some information may be ignored,
|
---|
| 40 | so a warning should be printed.
|
---|
| 41 | Unfortunately, this would break things like vi filters.
|
---|
| 42 |
|
---|
| 43 | If there is not piped input,
|
---|
| 44 | and the standard input is being read from the keyboard,
|
---|
| 45 | then prompt the user for input with something like:
|
---|
| 46 | pgm: reading input from terminal
|
---|
| 47 | This would avoid the problem of people forgetting to supply
|
---|
| 48 | an input redirection.
|
---|