2
* Copyright 1989 Massachusetts Institute of Technology
4
* Permission to use, copy, modify, and distribute this software and its
5
* documentation for any purpose and without fee is hereby granted, provided
6
* that the above copyright notice appear in all copies and that both that
7
* copyright notice and this permission notice appear in supporting
8
* documentation, and that the name of M.I.T. not be used in advertising
9
* or publicity pertaining to distribution of the software without specific,
10
* written prior permission. M.I.T. makes no representations about the
11
* suitability of this software for any purpose. It is provided "as is"
12
* without express or implied warranty.
14
* M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
16
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
* carlo@athena.mit.edu
25
* $Header: /usr/sww/share/src/X11R5/local/clients/xless-1.4/RCS/callbacks.c,v 1.22 1993/03/02 01:57:10 dglo Exp dglo $
30
/* buffers for all dialog boxes */
31
static char search_buffer[MAX_INPUT];
32
static char newwin_buffer[MAX_INPUT];
33
static char chgfile_buffer[MAX_INPUT];
36
* Button callback functions.
40
Quit(widget, closure, callData)
49
Cancel(widget, closure, callData)
54
XtPopdown((Widget)closure);
58
CallEditor(widget, closure, callData)
63
WindowInfo *wi = (WindowInfo *)closure;
68
/* figure out which editor they want */
69
if ((editor = getenv(EDITORVAR)) == NULL)
72
/* get a buffer long enough for the entire command */
73
if (!resources.editorDoesWindows)
74
cmdlen = 9; /* "xterm -e " */
75
cmdlen += strlen(editor) + 1 + strlen(wi->file) + 2;
76
if (cmd = (char *)malloc(cmdlen)) {
78
/* don't start from an xterm if the editor has its own window */
79
if (resources.editorDoesWindows)
82
strcpy(cmd, "xterm -e ");
86
strcat(cmd, wi->file);
94
Reload(widget, closure, callData)
99
WindowInfo *wi = (WindowInfo *)closure;
103
if ((file = fopen(wi->file, "r")) == NULL)
104
CouldntOpen(wi->base, wi->file);
106
new_data = (char *)InitData(file);
107
free((void *)wi->memory);
108
SetReadText(wi->text, new_data);
109
wi->memory = new_data;
114
SearchNext(widget, closure, callData)
119
WindowInfo *wi = (WindowInfo *)closure;
121
DoSearch(wi->text, wi->memory, search_buffer, wi->base);
125
popdownAndSearch(widget, closure, callData)
130
WindowInfo *wi = (WindowInfo *)closure;
132
XtPopdown((Widget)wi->search_popup);
133
DoSearch(wi->text, wi->memory, search_buffer, wi->base);
137
Search(widget, closure, callData)
142
WindowInfo *wi = (WindowInfo *)closure;
144
/* build dialog box if it doesn't exist */
145
if (!wi->search_popup)
146
wi->search_popup = DialogBox(wi->base, popdownAndSearch, (XtPointer )wi,
147
"Search for:", "Search", search_buffer);
149
/* popup search dialog box */
150
SetPopup(wi->base, wi->search_popup);
154
popdownAndChange(widget, closure, callData)
159
WindowInfo *wi = (WindowInfo *)closure;
162
const char *filename;
163
XLessFlag flag = XLessClearFlag;
166
XtPopdown((Widget)wi->chgfile_popup);
168
/* make sure there's a filename there */
169
filename = chgfile_buffer;
173
#ifdef TILDE_EXPANSION
174
/* see if we need to do tilde expansion */
175
if (filename && *filename == '~') {
176
filename = TildeExpand(filename);
177
if (*filename != '~')
178
flag |= XLessFreeFilename;
180
#endif /* TILDE_EXPANSION */
182
if ((file = fopen(filename, "r")) == NULL)
183
CouldntOpen(wi->base, filename);
186
/* read in new file */
187
new_data = (char *)InitData(file);
188
free((void *)wi->memory);
189
if (wi->flag & XLessFreeFilename) {
190
free((void *)wi->file);
191
wi->flag &= ~XLessFreeFilename;
193
SetReadText(wi->text, new_data);
194
wi->memory = new_data;
198
/* sensitize buttons if previous file was STDIN */
199
XtSetArg(args[0], XtNsensitive, True);
200
if (wi->editor_button) {
201
XtSetValues(wi->editor_button, args, 1);
202
wi->editor_button = 0;
204
if (wi->reload_button) {
205
XtSetValues(wi->reload_button, args, 1);
206
wi->editor_button = 0;
209
/* set title & icon name */
210
SetXNames(wi->base, filename);
215
ChangeFile(widget, closure, callData)
220
WindowInfo *wi = (WindowInfo *)closure;
222
if (!wi->chgfile_popup)
223
wi->chgfile_popup = DialogBox(wi->base, popdownAndChange, (XtPointer)wi,
224
"Enter filename:", "Ok", chgfile_buffer);
226
SetPopup(wi->base, wi->chgfile_popup); /* Change file dialog box */
230
popdownAndCreate(widget, closure, callData)
235
WindowInfo *wi = (WindowInfo *)closure;
237
XtPopdown((Widget)wi->newwin_popup);
238
CreateWindow(wi->base, newwin_buffer);
242
NewWindow(widget, closure, callData)
247
WindowInfo *wi = (WindowInfo *)closure;
249
if (!wi->newwin_popup)
250
wi->newwin_popup = DialogBox(wi->base, popdownAndCreate, (XtPointer)wi,
251
"Enter filename:", "Ok", newwin_buffer);
252
SetPopup(wi->base, wi->newwin_popup); /* New window dialog box */
256
CloseWindow(widget, closure, callData)
261
WindowInfo *sd = (WindowInfo *)closure;
263
DestroyWindowInfo(sd);
267
Print(widget, closure, callData)
272
WindowInfo *wi = (WindowInfo *)closure;
274
const char *printfile;
280
if (wi->file == NULL||strcmp(wi->file,"stdin")==0) {
282
/* create a temporary file */
283
printfile = tmpnam(0);
284
file = fopen(printfile, "w");
287
/* write stdin (line by line) to temporary file */
288
line = l = wi->memory;
289
while (line && *line) {
290
if (l = strchr(line, '\n'))
292
fprintf(file, "%s\n", line);
297
#else /* !WIMPY_STDIO */
298
/* write stdin (in one manly hunk) to temp file */
299
fputs(wi->memory, file);
300
#endif /* WIMPY_STDIO */
303
printfile = wi->file;
305
/* create the print command string */
306
if (cmd = (char *)malloc(strlen(resources.printCmd) + 1 +
307
strlen(printfile) + 1)) {
308
strcpy(cmd, resources.printCmd);
310
strcat(cmd, printfile);
315
/* unlink the file if we created it */
316
if (wi->file == NULL)