summaryrefslogtreecommitdiff
path: root/ipl/gpacks/ged/ged.icn
blob: 0446d1e95236793dd0c0d41b21bc6220c7ea2ff9 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
############################################################################
#
#	Name:	ged.icn
#
#	Title:	Mouse-Oriented Text Editor for Windows
#
#	Author:	Robert J. Alexander
#
#	Date:	April 17, 1993
#
############################################################################
#
#  Usage: (see Usage() procedure, below)
#
#  See the file "textedit.icn" for a list of the editor's features.
#
############################################################################
#
#  Links: io, options, textedit
#
############################################################################

link io
link options
link textedit

procedure Usage(s)
   write(\s)
   write(
	 "Usage: ged <options> file..._
	 \n_
	 \nIf file is \"-\" then standard input is edited read-only._
	 \n_
	 \nOptions:_
	 \n_
	 \n        -g s    Geometry (<columns>x<lines>+x+y)_
	 \n        -f s    Font_
	 \n        -t n    Tab stop spacing_
	 \n        -b      Don't keep backup file if write successful_
	 \n        -i      Don't ignore case in find and replace_
	 \n        -c s    Save context in file \"s\"_
	 \n        -T s    Window title (if omitted, first file name is used)_
	 \n        -R      Read-only_
	 \n        -S      Standard input file prompts for save before close_
	 \n        -L n    Start at line number n_
	 \n        -N x    Buffer name for standard input file_
	 \n        -H      Print help window text to standard output_
	 \n        -E s    Repeated string to use as first line past EOF_
	 \n        -X      Use this if window manager crashes while scrolling_
	 \n_
	 \n  <<< Use control-? to get a \"help\" window. >>>_
	 \n")
   exit()
end


global Geometry,Font,WindowName,ReadOnly,LineNbr,Tabs,IgnoreCase,CopyAreaBug,
      UseCtx,CtxFile,StdInBufName,RmBackup,EOFStr,SaveStdIn

procedure Options(arg)
   local opt
   opt := options(arg,"Rg:f:t+T:L+hHiXc:N:bE:S",Usage)
   if \opt["h"] then Usage()
   if \opt["H"] then {
      write(EditHelpText())
      exit()
      }
   Geometry := \opt["g"] | "80x48"
   Font := \opt["f"] | "fixed"
   WindowName := opt["T"]
   StdInBufName := opt["N"]
   SaveStdIn := opt["S"]
   Tabs := (1 <= \opt["t"] | 8) + 1
   ReadOnly := opt["R"]
   LineNbr := \opt["L"] | 1
   IgnoreCase := (\opt["i"],&null) | 1
   CopyAreaBug := opt["X"]
   UseCtx := CtxFile := opt["c"]
   RmBackup := opt["b"]
   EOFStr := opt["E"]
   return opt
end




procedure main(arg)
   local fn,f,text,ctx
   Options(arg)
   InitControl()
   AddCtx(arg)
   ctx := Edit(arg,Geometry,Font,WindowName,1,,,ReadOnly,LineNbr,IgnoreCase,
	 UseCtx,LoadFile,SaveFile,RmBackup,EOFStr)
   WriteCtx(ctx)
end


procedure AddCtx(arg)
   local f,t,line,r,i
   if \UseCtx & f := open(CtxFile) then {
      if *arg = 0 then {
	 while put(arg,read(f))
	 }
      else {
	 t := table()
	 while line := read(f) do {
	    r := EditParseCtx(line)
	    t[r.fileName] := line
	    }
	 every i := 1 to *arg do {
	    arg[i] := \t[arg[i]]
	    }
	 }
      close(f)
      return
      }
end


procedure WriteCtx(ctx)
   local f,fn
   if \UseCtx & type(ctx) == "list" & f := open(CtxFile,"w") then {
      every fn := !ctx do {
	 if not match("*",fn) then write(f,fn)
	 }
      close(f)
      return
      }
end


procedure LoadFile(fn)
   local f,text,changed
   if fn == "-" then {
      f := &input
      fn := \StdInBufName | "*Standard Input*"
      ReadOnly := 1
      changed := SaveStdIn
      }
   else {
      f := open(fn) | fail
      }
   text := []
   every put(text,!f)
   close(&input ~=== f)
   return EditLoadRec(text,fn,changed)
end


procedure SaveFile(fn, text)
   stop() # this isn't called, yet (files are inappropriately saved in
	  # the edit proc)
end