summaryrefslogtreecommitdiff
path: root/ipl/progs/newicon.icn
blob: 87404560f62c1ef6410dd6a561bc3fc26872924d (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
############################################################################
#
#	File:     newicon.icn
#
#	Subject:  Program to produce new Icon program file
#
#	Author:   Ralph E. Griswold
#
#	Date:     March 26, 2002
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program creates a new file with a standard Icon program
#  header and a skeleton mail procedure.
#
#  The first command-line argument is taken as the base
#  name of the file; default "foo".  The second command-line argument is
#  taken as the author; the default is "Ralph E. Griswold" -- with minor
#  apologies, I use this program a lot; personalize it for your own
#  use.  The same comment applies to the skeleton file mentioned below.
#
#  The new file is brought up in the vi editor.
#
#  The supported options are:
#
#	-f	overwrite and existing file
#	-p	produce a procedure file instead of a program
#	-o	provide program skeleton with options()
#
#  The files skeleton.icn, skelproc.icn, and skelopt.icn must be accessible
#  via dopen().
#
############################################################################
#
#  Requires:  system(), vi(1)
#
############################################################################
#
#  Links:  basename, datetime, io, options
#
############################################################################

link basename
link datetime
link io
link options

procedure main(args)
   local opts, overwrite, name, author, input, output, file

   opts := options(args, "fpo")
   if \opts["f"] then overwrite := 1

   name := (args[1] | "foo")
   if (*name < 4) | (name[-4:0] ~== ".icn") then name ||:= ".icn"

   author := args[2] | "Ralph E. Griswold"

   if /overwrite then {				# check to see if file exists
       if input := open(name) then {
          close(input)
          system("vi " || name)
          exit()
          }
      }

   output := open(name, "w") |
      stop("*** cannot open ", name, " for writing")

   input := dopen(
      if \opts["o"] then file := "skelopt.icn"
      else if \opts["p"] then "skelproc.icn"
      else "skeleton.icn"
      ) | stop("*** cannot open skeleton file")

   every 1 to 2 do write(output, read(input)) |
      stop("*** short skeleton file")
   write(output, read(input), name) |
      stop("*** short skeleton file")
   every 1 to 3 do write(output, read(input)) |
      stop("*** short skeleton file")
   write(output, read(input), author) |
      stop("*** short skeleton file")
   write(output, read(input)) |
      stop("*** short skeleton file")
   write(output, read(input), date()) |
      stop("*** short skeleton file")
   write(output, read(input)) |
      stop("*** short skeleton file")
   while write(output, read(input))

   if \opts["p"] then {
      write(output, "procedure ", basename(name, ".icn"), "()")
      write(output)
      write(output, "end")
      }

   close(output)

   system("vi " || name)

end