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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
#include <HTUtils.h>
#include <HTParse.h>
#include <HTAlert.h>
#include <LYCurses.h>
#include <LYUtils.h>
#include <LYGlobalDefs.h>
#include <LYEdit.h>
#ifdef VMS
#include <unixio.h>
#endif /* VMS */
#include <LYLeaks.h>
PUBLIC BOOLEAN editor_can_position NOARGS
{
static CONST char *table[] = {
#ifdef VMS
"sedt",
"SEDT"
#else
"emacs",
"jed",
"jmacs",
"joe",
"jove",
"jpico",
"jstar",
"pico",
"rjoe",
"vi"
#endif
};
unsigned n;
for (n = 0; n < TABLESIZE(table); n++) {
if (strstr(editor, table[n]) != 0) {
return TRUE;
}
}
return FALSE;
}
/*
* In edit mode invoke the given (or default) editor to display and edit the
* current file. For editors listed in 'editor_can_position()', Lynx
* will open the file to the same line that the screen cursor is on (or
* close...) when editing is invoked.
*
* Returns FALSE if file is uneditable.
*/
PUBLIC int edit_current_file ARGS3(
char *, newfile,
int, cur,
int, lineno)
{
int result = FALSE;
int params = 1;
char *format = "%s %s";
char *command = NULL;
char *filename = NULL;
#if !(defined(VMS) || defined(DOSPATH) || defined(__EMX__))
char *colon;
#endif
char *number_sign;
char position[80];
#if defined(VMS) || defined(CANT_EDIT_UNWRITABLE_FILES)
FILE *fp;
#endif
#if defined(__CYGWIN__) && defined(DOSPATH)
unsigned char temp_buff[LY_MAXPATH];
#endif
/*
* If its a remote file then we can't edit it.
*/
if (!LYisLocalFile(newfile)) {
HTUserMsg(CANNOT_EDIT_REMOTE_FILES);
return FALSE;
}
/*
* If there's a fragment, trim it. - FM
*/
number_sign = strchr(newfile, '#');
if (number_sign)
*number_sign = '\0';
/*
* On Unix, first try to open it as a completely referenced file,
* then via the path alone.
*
* On VMS, only try the path.
*/
#if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
filename = HTParse(newfile, "", PARSE_PATH+PARSE_PUNCTUATION);
HTUnEscape(filename);
StrAllocCopy(filename, HTSYS_name(filename));
if (!LYCanReadFile(filename)) {
#ifdef SH_EX
HTUserMsg2(COULD_NOT_EDIT_FILE, filename);
#else
HTAlert(COULD_NOT_ACCESS_FILE);
#endif
CTRACE((tfp, "filename: '%s'\n", filename));
goto done;
}
#else /* !(VMS || !DOSPATH || !__EMX__) == UNIX */
#ifdef SH_EX /* Speed Up! */
if (strncmp(newfile, "file://localhost/", 16) == 0)
colon = newfile + 16;
else
colon = strchr(newfile, ':');
#else
colon = strchr(newfile, ':');
#endif
StrAllocCopy(filename, (colon + 1));
HTUnEscape(filename);
if (!LYCanReadFile(filename)) {
FREE(filename);
filename = HTParse(newfile, "", PARSE_PATH+PARSE_PUNCTUATION);
HTUnEscape(filename);
if (!LYCanReadFile(HTSYS_name(filename))) {
HTAlert(COULD_NOT_ACCESS_FILE);
goto done;
}
}
#endif /* !(VMS || !DOSPATH || !__EMX__) */
#if defined(VMS) || defined(CANT_EDIT_UNWRITABLE_FILES)
/*
* Don't allow editing if user lacks append access.
*/
if ((fp = fopen(filename, "a")) == NULL)
{
HTUserMsg(NOAUTH_TO_EDIT_FILE);
goto done;
}
fclose(fp);
#endif /* VMS || CANT_EDIT_UNWRITABLE_FILES */
/*
* Make sure cur is at least zero. - FM
*/
if (cur < 0) {
cur = 0;
}
/*
* Set up the command for the editor. - FM
*/
*position = 0;
#ifdef VMS
lineno--;
#endif
lineno += (nlinks ? links[cur].ly : 0);
if (lineno > 0)
sprintf(position, "%d", lineno);
if (editor_can_position() && *position) {
#ifdef VMS
format = "%s %s -%s";
HTAddXpand(&command, format, params++, editor);
HTAddParam(&command, format, params++, filename);
HTAddParam(&command, format, params++, position);
HTEndParam(&command, format, params);
#else
format = "%s +%s %s";
HTAddXpand(&command, format, params++, editor);
HTAddParam(&command, format, params++, position);
HTAddParam(&command, format, params++, filename);
HTEndParam(&command, format, params);
#endif
}
#ifdef DOSPATH
else if (strncmp(editor, "VZ", 2)==0) {
/* for Vz editor */
format = "%s %s -%s";
HTAddXpand(&command, format, params++, editor);
HTAddParam(&command, format, params++, HTDOS_short_name(filename));
HTAddParam(&command, format, params++, position);
HTEndParam(&command, format, params);
} else if (strncmp(editor, "edit", 4)==0) {
/* for standard editor */
HTAddXpand(&command, format, params++, editor);
HTAddParam(&command, format, params++, HTDOS_short_name(filename));
HTEndParam(&command, format, params);
}
#endif
else {
#ifdef _WINDOWS
if (strchr(editor, ' '))
HTAddXpand(&command, format, params++, HTDOS_short_name(editor));
else
HTAddXpand(&command, format, params++, editor);
#else
#if defined(__CYGWIN__) && defined(DOSPATH)
if (strchr(editor, ' ')) {
cygwin_conv_to_full_posix_path(HTDOS_short_name(editor), temp_buff);
HTAddXpand(&command, format, params++, temp_buff);
} else {
HTAddXpand(&command, format, params++, editor);
}
#else
HTAddXpand(&command, format, params++, editor);
#endif /* __CYGWIN__ */
#endif
HTAddParam(&command, format, params++, filename);
HTEndParam(&command, format, params);
}
CTRACE((tfp, "LYEdit: %s\n", command));
CTRACE_SLEEP(MessageSecs);
/*
* Invoke the editor. - FM
*/
stop_curses();
LYSystem(command);
start_curses();
result = TRUE;
done:
/*
* Restore the fragment if there was one. - FM
*/
if (number_sign)
*number_sign = '#';
FREE(command);
FREE(filename);
return (result);
}
|