summaryrefslogtreecommitdiff
path: root/ipl/progs/filtskel.icn
blob: 4b9976387f451e93d673481e7e6c0df7f51ed8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
############################################################################
#
#	File:     filtskel.icn
#
#	Subject:  Program skeleton for generic filter
#
#	Author:   Robert J. Alexander
#
#	Date:     July 16, 1994
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  Generic filter skeleton in Icon.
#
#  This program is not intended to be used as is -- it serves as a
#  starting point for creation of filter programs.  Command line
#  options, file names, and tabbing are handled by the skeleton.  You
#  need only provide the filtering code.
#
#  As it stands, filter.icn simply copies the input file(s) to
#  standard output.
#
#  Multiple files can be specified as arguments, and will be processed
#  in sequence.  A file name of "-" represents the standard input file.
#  If there are no arguments, standard input is processed.
#
############################################################################
#
#  Links: options
#
############################################################################

link options

procedure main(arg)
   local opt, tabs, Detab, fn, f, line
   #
   #  Process command line options and file names.
   #
   opt := options(arg,"t+")      # e.g. "fs:i+r." (flag, string, integer, real)
   if *arg = 0 then arg := ["-"] # if no arguments, standard input
   tabs := (\opt["t"] | 8) + 1   # tabs default to 8
   Detab := tabs = 1 | detab     # if -t 0, no detabbing
   #
   #  Loop to process files.
   #
   every fn := !arg do {
      f := if fn == "-" then &input else
	    open(fn) | stop("Can't open input file \"",fn,"\"")
      #
      #  Loop to process lines of file (in string scanning mode).
      #
      while line := Detab(read(f)) do line ? {
	 write(line)       # copy line to standard output
	 }
      #
      #  Close this file.
      #
      close(f)
      }
   #
   #  End of program.
   #
end