Mercurial > vim
annotate src/os_amiga.c @ 13905:7c7d949c4217
Added tag v8.0.1823 for changeset b94a9171ec7ce07692d159e1984f3551ea61602e
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 12 May 2018 21:15:07 +0200 |
parents | 69517d67421f |
children | 3375a8cbb442 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10025
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * os_amiga.c | |
12 * | |
13 * Amiga system-dependent routines. | |
14 */ | |
15 | |
16 #include "vim.h" | |
17 | |
18 #ifdef Window | |
19 # undef Window /* Amiga has its own Window definition */ | |
20 #endif | |
21 | |
22 #undef TRUE /* will be redefined by exec/types.h */ | |
23 #undef FALSE | |
24 | |
3927 | 25 /* cproto fails on missing include files, skip them */ |
26 #ifndef PROTO | |
27 | |
7 | 28 #ifndef LATTICE |
29 # include <exec/types.h> | |
30 # include <exec/exec.h> | |
31 # include <libraries/dos.h> | |
32 # include <intuition/intuition.h> | |
33 #endif | |
34 | |
1030 | 35 /* XXX These are included from os_amiga.h |
36 #include <proto/exec.h> | |
37 #include <proto/dos.h> | |
38 #include <proto/intuition.h> | |
39 */ | |
40 | |
7 | 41 #include <exec/memory.h> |
1030 | 42 #include <libraries/dosextens.h> |
7 | 43 |
44 #include <dos/dostags.h> /* for 2.0 functions */ | |
45 #include <dos/dosasl.h> | |
46 | |
1030 | 47 /* From version 4 of AmigaOS, several system structures must be allocated |
48 * and freed using system functions. "struct AnchorPath" is one. | |
49 */ | |
50 #ifdef __amigaos4__ | |
51 # include <dos/anchorpath.h> | |
52 # define free_fib(x) FreeDosObject(DOS_FIB, x) | |
53 #else | |
54 # define free_fib(x) vim_free(fib) | |
55 #endif | |
56 | |
7 | 57 #if defined(LATTICE) && !defined(SASC) && defined(FEAT_ARP) |
58 # include <libraries/arp_pragmas.h> | |
59 #endif | |
60 | |
3927 | 61 #endif /* PROTO */ |
62 | |
7 | 63 /* |
64 * At this point TRUE and FALSE are defined as 1L and 0L, but we want 1 and 0. | |
65 */ | |
66 #undef TRUE | |
67 #define TRUE (1) | |
68 #undef FALSE | |
69 #define FALSE (0) | |
70 | |
1030 | 71 #ifdef __amigaos4__ |
72 # define dos_packet(a, b, c) DoPkt(a, b, c, 0, 0, 0, 0) | |
73 #elif !defined(AZTEC_C) && !defined(__AROS__) | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6695
diff
changeset
|
74 static long dos_packet(struct MsgPort *, long, long); |
7 | 75 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6695
diff
changeset
|
76 static int lock2name(BPTR lock, char_u *buf, long len); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6695
diff
changeset
|
77 static void out_num(long n); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6695
diff
changeset
|
78 static struct FileInfoBlock *get_fib(char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6695
diff
changeset
|
79 static int sortcmp(const void *a, const void *b); |
7 | 80 |
81 static BPTR raw_in = (BPTR)NULL; | |
82 static BPTR raw_out = (BPTR)NULL; | |
83 static int close_win = FALSE; /* set if Vim opened the window */ | |
84 | |
1030 | 85 #ifndef __amigaos4__ /* Use autoopen for AmigaOS4 */ |
7 | 86 struct IntuitionBase *IntuitionBase = NULL; |
1030 | 87 #endif |
7 | 88 #ifdef FEAT_ARP |
89 struct ArpBase *ArpBase = NULL; | |
90 #endif | |
91 | |
92 static struct Window *wb_window; | |
93 static char_u *oldwindowtitle = NULL; | |
94 | |
95 #ifdef FEAT_ARP | |
96 int dos2 = FALSE; /* Amiga DOS 2.0x or higher */ | |
97 #endif | |
98 int size_set = FALSE; /* set to TRUE if window size was set */ | |
99 | |
100 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
101 win_resize_on(void) |
7 | 102 { |
103 OUT_STR_NF("\033[12{"); | |
104 } | |
105 | |
106 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
107 win_resize_off(void) |
7 | 108 { |
109 OUT_STR_NF("\033[12}"); | |
110 } | |
111 | |
112 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
113 mch_write(char_u *p, int len) |
7 | 114 { |
115 Write(raw_out, (char *)p, (long)len); | |
116 } | |
117 | |
118 /* | |
4352 | 119 * mch_inchar(): low level input function. |
7 | 120 * Get a characters from the keyboard. |
121 * If time == 0 do not wait for characters. | |
122 * If time == n wait a short time for characters. | |
123 * If time == -1 wait forever for characters. | |
124 * | |
125 * Return number of characters read. | |
126 */ | |
127 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
128 mch_inchar( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
129 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
130 int maxlen, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
131 long time, /* milli seconds */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
132 int tb_change_cnt) |
7 | 133 { |
134 int len; | |
135 long utime; | |
136 | |
137 if (time >= 0) | |
138 { | |
139 if (time == 0) | |
140 utime = 100L; /* time = 0 causes problems in DOS 1.2 */ | |
141 else | |
142 utime = time * 1000L; /* convert from milli to micro secs */ | |
143 if (WaitForChar(raw_in, utime) == 0) /* no character available */ | |
144 return 0; | |
145 } | |
146 else /* time == -1 */ | |
147 { | |
148 /* | |
149 * If there is no character available within 2 seconds (default) | |
208 | 150 * write the autoscript file to disk. Or cause the CursorHold event |
151 * to be triggered. | |
7 | 152 */ |
208 | 153 if (WaitForChar(raw_in, p_ut * 1000L) == 0) |
7 | 154 { |
610 | 155 if (trigger_cursorhold() && maxlen >= 3) |
7 | 156 { |
208 | 157 buf[0] = K_SPECIAL; |
158 buf[1] = KS_EXTRA; | |
159 buf[2] = (int)KE_CURSORHOLD; | |
160 return 3; | |
7 | 161 } |
371 | 162 before_blocking(); |
7 | 163 } |
164 } | |
165 | |
166 for (;;) /* repeat until we got a character */ | |
167 { | |
168 # ifdef FEAT_MBYTE | |
169 len = Read(raw_in, (char *)buf, (long)maxlen / input_conv.vc_factor); | |
170 # else | |
171 len = Read(raw_in, (char *)buf, (long)maxlen); | |
172 # endif | |
173 if (len > 0) | |
174 { | |
175 #ifdef FEAT_MBYTE | |
176 /* Convert from 'termencoding' to 'encoding'. */ | |
177 if (input_conv.vc_type != CONV_NONE) | |
178 len = convert_input(buf, len, maxlen); | |
179 #endif | |
180 return len; | |
181 } | |
182 } | |
183 } | |
184 | |
185 /* | |
186 * return non-zero if a character is available | |
187 */ | |
188 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
189 mch_char_avail(void) |
7 | 190 { |
191 return (WaitForChar(raw_in, 100L) != 0); | |
192 } | |
193 | |
194 /* | |
3634 | 195 * Return amount of memory still available in Kbyte. |
7 | 196 */ |
197 long_u | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
198 mch_avail_mem(int special) |
7 | 199 { |
1030 | 200 #ifdef __amigaos4__ |
3634 | 201 return (long_u)AvailMem(MEMF_ANY) >> 10; |
1030 | 202 #else |
3634 | 203 return (long_u)(AvailMem(special ? (long)MEMF_CHIP : (long)MEMF_ANY)) >> 10; |
1030 | 204 #endif |
7 | 205 } |
206 | |
1030 | 207 /* |
208 * Waits a specified amount of time, or until input arrives if | |
209 * ignoreinput is FALSE. | |
210 */ | |
7 | 211 void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
212 mch_delay(long msec, int ignoreinput) |
7 | 213 { |
1228 | 214 #ifndef LATTICE /* SAS declares void Delay(ULONG) */ |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
6695
diff
changeset
|
215 void Delay(long); |
7 | 216 #endif |
217 | |
218 if (msec > 0) | |
219 { | |
220 if (ignoreinput) | |
221 Delay(msec / 20L); /* Delay works with 20 msec intervals */ | |
222 else | |
223 WaitForChar(raw_in, msec * 1000L); | |
224 } | |
225 } | |
226 | |
227 /* | |
228 * We have no job control, fake it by starting a new shell. | |
229 */ | |
230 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
231 mch_suspend(void) |
7 | 232 { |
233 suspend_shell(); | |
234 } | |
235 | |
236 #ifndef DOS_LIBRARY | |
237 # define DOS_LIBRARY ((UBYTE *)"dos.library") | |
238 #endif | |
239 | |
240 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
241 mch_init(void) |
7 | 242 { |
243 static char intlibname[] = "intuition.library"; | |
244 | |
245 #ifdef AZTEC_C | |
246 Enable_Abort = 0; /* disallow vim to be aborted */ | |
247 #endif | |
248 Columns = 80; | |
249 Rows = 24; | |
250 | |
251 /* | |
252 * Set input and output channels, unless we have opened our own window | |
253 */ | |
254 if (raw_in == (BPTR)NULL) | |
255 { | |
256 raw_in = Input(); | |
257 raw_out = Output(); | |
258 /* | |
259 * If Input() is not interactive, then Output() will be (because of | |
260 * check in mch_check_win()). Used for "Vim -". | |
261 * Also check the other way around, for "Vim -h | more". | |
262 */ | |
263 if (!IsInteractive(raw_in)) | |
264 raw_in = raw_out; | |
265 else if (!IsInteractive(raw_out)) | |
266 raw_out = raw_in; | |
267 } | |
268 | |
269 out_flush(); | |
270 | |
271 wb_window = NULL; | |
1030 | 272 #ifndef __amigaos4__ |
7 | 273 if ((IntuitionBase = (struct IntuitionBase *) |
274 OpenLibrary((UBYTE *)intlibname, 0L)) == NULL) | |
275 { | |
276 mch_errmsg(_("cannot open ")); | |
277 mch_errmsg(intlibname); | |
278 mch_errmsg("!?\n"); | |
279 mch_exit(3); | |
280 } | |
1030 | 281 #endif |
7 | 282 } |
283 | |
3927 | 284 #ifndef PROTO |
285 # include <workbench/startup.h> | |
286 #endif | |
7 | 287 |
288 /* | |
289 * Check_win checks whether we have an interactive window. | |
290 * If not, a new window is opened with the newcli command. | |
291 * If we would open a window ourselves, the :sh and :! commands would not | |
292 * work properly (Why? probably because we are then running in a background | |
293 * CLI). This also is the best way to assure proper working in a next | |
294 * Workbench release. | |
295 * | |
296 * For the -f option (foreground mode) we open our own window and disable :sh. | |
297 * Otherwise the calling program would never know when editing is finished. | |
298 */ | |
299 #define BUF2SIZE 320 /* length of buffer for argument with complete path */ | |
300 | |
301 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
302 mch_check_win(int argc, char **argv) |
7 | 303 { |
304 int i; | |
305 BPTR nilfh, fh; | |
1030 | 306 char_u buf1[24]; |
7 | 307 char_u buf2[BUF2SIZE]; |
308 static char_u *(constrings[3]) = {(char_u *)"con:0/0/662/210/", | |
309 (char_u *)"con:0/0/640/200/", | |
310 (char_u *)"con:0/0/320/200/"}; | |
311 static char_u *winerr = (char_u *)N_("VIM: Can't open window!\n"); | |
312 struct WBArg *argp; | |
313 int ac; | |
314 char *av; | |
315 char_u *device = NULL; | |
316 int exitval = 4; | |
1030 | 317 #ifndef __amigaos4__ |
7 | 318 struct Library *DosBase; |
1030 | 319 #endif |
7 | 320 int usewin = FALSE; |
321 | |
322 /* | |
323 * check if we are running under DOS 2.0x or higher | |
324 */ | |
1030 | 325 #ifndef __amigaos4__ |
7 | 326 DosBase = OpenLibrary(DOS_LIBRARY, 37L); |
327 if (DosBase != NULL) | |
328 /* if (((struct Library *)DOSBase)->lib_Version >= 37) */ | |
329 { | |
330 CloseLibrary(DosBase); | |
1030 | 331 # ifdef FEAT_ARP |
7 | 332 dos2 = TRUE; |
1030 | 333 # endif |
7 | 334 } |
335 else /* without arp functions we NEED 2.0 */ | |
336 { | |
1030 | 337 # ifndef FEAT_ARP |
7 | 338 mch_errmsg(_("Need Amigados version 2.04 or later\n")); |
339 exit(3); | |
1030 | 340 # else |
7 | 341 /* need arp functions for dos 1.x */ |
342 if (!(ArpBase = (struct ArpBase *) OpenLibrary((UBYTE *)ArpName, ArpVersion))) | |
343 { | |
344 fprintf(stderr, _("Need %s version %ld\n"), ArpName, ArpVersion); | |
345 exit(3); | |
346 } | |
1030 | 347 # endif |
7 | 348 } |
1030 | 349 #endif /* __amigaos4__ */ |
7 | 350 |
351 /* | |
352 * scan argv[] for the "-f" and "-d" arguments | |
353 */ | |
354 for (i = 1; i < argc; ++i) | |
355 if (argv[i][0] == '-') | |
356 { | |
357 switch (argv[i][1]) | |
358 { | |
359 case 'f': | |
360 usewin = TRUE; | |
361 break; | |
362 | |
363 case 'd': | |
364 if (i < argc - 1 | |
365 #ifdef FEAT_DIFF | |
366 /* require using "-dev", "-d" means diff mode */ | |
367 && argv[i][2] == 'e' && argv[i][3] == 'v' | |
368 #endif | |
369 ) | |
370 device = (char_u *)argv[i + 1]; | |
371 break; | |
372 } | |
373 } | |
374 | |
375 /* | |
376 * If we were not started from workbench, do not have a "-d" or "-dev" | |
377 * argument and we have been started with an interactive window, use that | |
378 * window. | |
379 */ | |
380 if (argc != 0 | |
381 && device == NULL | |
382 && (IsInteractive(Input()) || IsInteractive(Output()))) | |
383 return OK; | |
384 | |
385 /* | |
386 * When given the "-f" argument, we open our own window. We can't use the | |
387 * newcli trick below, because the calling program (mail, rn, etc.) would not | |
388 * know when we are finished. | |
389 */ | |
390 if (usewin) | |
391 { | |
392 /* | |
393 * Try to open a window. First try the specified device. | |
394 * Then try a 24 line 80 column window. | |
395 * If that fails, try two smaller ones. | |
396 */ | |
397 for (i = -1; i < 3; ++i) | |
398 { | |
399 if (i >= 0) | |
400 device = constrings[i]; | |
401 if (device != NULL && (raw_in = Open((UBYTE *)device, | |
402 (long)MODE_NEWFILE)) != (BPTR)NULL) | |
403 break; | |
404 } | |
405 if (raw_in == (BPTR)NULL) /* all three failed */ | |
406 { | |
407 mch_errmsg(_(winerr)); | |
408 goto exit; | |
409 } | |
410 raw_out = raw_in; | |
411 close_win = TRUE; | |
412 return OK; | |
413 } | |
414 | |
415 if ((nilfh = Open((UBYTE *)"NIL:", (long)MODE_NEWFILE)) == (BPTR)NULL) | |
416 { | |
417 mch_errmsg(_("Cannot open NIL:\n")); | |
418 goto exit; | |
419 } | |
420 | |
421 /* | |
422 * Make a unique name for the temp file (which we will not delete!). | |
423 * Use a pointer on the stack (nobody else will be using it). | |
1030 | 424 * Under AmigaOS4, this assumption might change in the future, so |
425 * we use a pointer to the current task instead. This should be a | |
426 * shared structure and thus globally unique. | |
7 | 427 */ |
1030 | 428 #ifdef __amigaos4__ |
429 sprintf((char *)buf1, "t:nc%p", FindTask(0)); | |
430 #else | |
7 | 431 sprintf((char *)buf1, "t:nc%ld", (long)buf1); |
1030 | 432 #endif |
7 | 433 if ((fh = Open((UBYTE *)buf1, (long)MODE_NEWFILE)) == (BPTR)NULL) |
434 { | |
435 mch_errmsg(_("Cannot create ")); | |
436 mch_errmsg((char *)buf1); | |
437 mch_errmsg("\n"); | |
438 goto exit; | |
439 } | |
440 /* | |
441 * Write the command into the file, put quotes around the arguments that | |
442 * have a space in them. | |
443 */ | |
444 if (argc == 0) /* run from workbench */ | |
445 ac = ((struct WBStartup *)argv)->sm_NumArgs; | |
446 else | |
447 ac = argc; | |
448 for (i = 0; i < ac; ++i) | |
449 { | |
450 if (argc == 0) | |
451 { | |
452 *buf2 = NUL; | |
453 argp = &(((struct WBStartup *)argv)->sm_ArgList[i]); | |
454 if (argp->wa_Lock) | |
455 (void)lock2name(argp->wa_Lock, buf2, (long)(BUF2SIZE - 1)); | |
456 #ifdef FEAT_ARP | |
457 if (dos2) /* use 2.0 function */ | |
458 #endif | |
459 AddPart((UBYTE *)buf2, (UBYTE *)argp->wa_Name, (long)(BUF2SIZE - 1)); | |
460 #ifdef FEAT_ARP | |
461 else /* use arp function */ | |
462 TackOn((char *)buf2, argp->wa_Name); | |
463 #endif | |
464 av = (char *)buf2; | |
465 } | |
466 else | |
467 av = argv[i]; | |
468 | |
469 /* skip '-d' or "-dev" option */ | |
470 if (av[0] == '-' && av[1] == 'd' | |
471 #ifdef FEAT_DIFF | |
472 && av[2] == 'e' && av[3] == 'v' | |
473 #endif | |
474 ) | |
475 { | |
476 ++i; | |
477 continue; | |
478 } | |
479 if (vim_strchr((char_u *)av, ' ')) | |
480 Write(fh, "\"", 1L); | |
481 Write(fh, av, (long)strlen(av)); | |
482 if (vim_strchr((char_u *)av, ' ')) | |
483 Write(fh, "\"", 1L); | |
484 Write(fh, " ", 1L); | |
485 } | |
486 Write(fh, "\nendcli\n", 8L); | |
487 Close(fh); | |
488 | |
489 /* | |
490 * Try to open a new cli in a window. If "-d" or "-dev" argument was given try | |
491 * to open the specified device. Then try a 24 line 80 column window. If that | |
492 * fails, try two smaller ones. | |
493 */ | |
494 for (i = -1; i < 3; ++i) | |
495 { | |
496 if (i >= 0) | |
497 device = constrings[i]; | |
498 else if (device == NULL) | |
499 continue; | |
500 sprintf((char *)buf2, "newcli <nil: >nil: %s from %s", (char *)device, (char *)buf1); | |
501 #ifdef FEAT_ARP | |
502 if (dos2) | |
503 { | |
504 #endif | |
505 if (!SystemTags((UBYTE *)buf2, SYS_UserShell, TRUE, TAG_DONE)) | |
506 break; | |
507 #ifdef FEAT_ARP | |
508 } | |
509 else | |
510 { | |
511 if (Execute((UBYTE *)buf2, nilfh, nilfh)) | |
512 break; | |
513 } | |
514 #endif | |
515 } | |
516 if (i == 3) /* all three failed */ | |
517 { | |
518 DeleteFile((UBYTE *)buf1); | |
519 mch_errmsg(_(winerr)); | |
520 goto exit; | |
521 } | |
522 exitval = 0; /* The Execute succeeded: exit this program */ | |
523 | |
524 exit: | |
525 #ifdef FEAT_ARP | |
526 if (ArpBase) | |
527 CloseLibrary((struct Library *) ArpBase); | |
528 #endif | |
529 exit(exitval); | |
530 /* NOTREACHED */ | |
531 return FAIL; | |
532 } | |
533 | |
534 /* | |
535 * Return TRUE if the input comes from a terminal, FALSE otherwise. | |
536 * We fake there is a window, because we can always open one! | |
537 */ | |
538 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
539 mch_input_isatty(void) |
7 | 540 { |
541 return TRUE; | |
542 } | |
543 | |
544 /* | |
545 * fname_case(): Set the case of the file name, if it already exists. | |
1030 | 546 * This will cause the file name to remain exactly the same |
547 * if the file system ignores, but preserves case. | |
7 | 548 */ |
549 /*ARGSUSED*/ | |
550 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
551 fname_case( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
552 char_u *name, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
553 int len) /* buffer size, ignored here */ |
7 | 554 { |
555 struct FileInfoBlock *fib; | |
556 size_t flen; | |
557 | |
558 fib = get_fib(name); | |
559 if (fib != NULL) | |
560 { | |
561 flen = STRLEN(name); | |
1030 | 562 /* TODO: Check if this fix applies to AmigaOS < 4 too.*/ |
563 #ifdef __amigaos4__ | |
564 if (fib->fib_DirEntryType == ST_ROOT) | |
565 strcat(fib->fib_FileName, ":"); | |
566 #endif | |
7 | 567 if (flen == strlen(fib->fib_FileName)) /* safety check */ |
568 mch_memmove(name, fib->fib_FileName, flen); | |
1030 | 569 free_fib(fib); |
7 | 570 } |
571 } | |
572 | |
573 /* | |
574 * Get the FileInfoBlock for file "fname" | |
575 * The returned structure has to be free()d. | |
576 * Returns NULL on error. | |
577 */ | |
578 static struct FileInfoBlock * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
579 get_fib(char_u *fname) |
7 | 580 { |
581 BPTR flock; | |
582 struct FileInfoBlock *fib; | |
583 | |
584 if (fname == NULL) /* safety check */ | |
585 return NULL; | |
1030 | 586 #ifdef __amigaos4__ |
587 fib = AllocDosObject(DOS_FIB,0); | |
588 #else | |
589 fib = (struct FileInfoBlock *)alloc(sizeof(struct FileInfoBlock)); | |
590 #endif | |
7 | 591 if (fib != NULL) |
592 { | |
593 flock = Lock((UBYTE *)fname, (long)ACCESS_READ); | |
594 if (flock == (BPTR)NULL || !Examine(flock, fib)) | |
595 { | |
1030 | 596 free_fib(fib); /* in case of an error the memory is freed here */ |
7 | 597 fib = NULL; |
598 } | |
599 if (flock) | |
600 UnLock(flock); | |
601 } | |
602 return fib; | |
603 } | |
604 | |
605 #ifdef FEAT_TITLE | |
606 /* | |
607 * set the title of our window | |
608 * icon name is not set | |
609 */ | |
610 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
611 mch_settitle(char_u *title, char_u *icon) |
7 | 612 { |
613 if (wb_window != NULL && title != NULL) | |
614 SetWindowTitles(wb_window, (UBYTE *)title, (UBYTE *)-1L); | |
615 } | |
616 | |
617 /* | |
618 * Restore the window/icon title. | |
619 * which is one of: | |
620 * 1 Just restore title | |
621 * 2 Just restore icon (which we don't have) | |
622 * 3 Restore title and icon (which we don't have) | |
623 */ | |
624 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
625 mch_restore_title(int which) |
7 | 626 { |
627 if (which & 1) | |
628 mch_settitle(oldwindowtitle, NULL); | |
629 } | |
630 | |
631 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
632 mch_can_restore_title(void) |
7 | 633 { |
634 return (wb_window != NULL); | |
635 } | |
636 | |
637 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
638 mch_can_restore_icon(void) |
7 | 639 { |
640 return FALSE; | |
641 } | |
642 #endif | |
643 | |
644 /* | |
645 * Insert user name in s[len]. | |
646 */ | |
647 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
648 mch_get_user_name(char_u *s, int len) |
7 | 649 { |
1030 | 650 /* TODO: Implement this. */ |
7 | 651 *s = NUL; |
652 return FAIL; | |
653 } | |
654 | |
655 /* | |
656 * Insert host name is s[len]. | |
657 */ | |
658 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
659 mch_get_host_name(char_u *s, int len) |
7 | 660 { |
1030 | 661 #if defined(__amigaos4__) && defined(__CLIB2__) |
662 gethostname(s, len); | |
663 #else | |
419 | 664 vim_strncpy(s, "Amiga", len - 1); |
1030 | 665 #endif |
7 | 666 } |
667 | |
668 /* | |
669 * return process ID | |
670 */ | |
671 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
672 mch_get_pid(void) |
7 | 673 { |
1030 | 674 #ifdef __amigaos4__ |
675 /* This is as close to a pid as we can come. We could use CLI numbers also, | |
676 * but then we would have two different types of process identifiers. | |
677 */ | |
678 return((long)FindTask(0)); | |
679 #else | |
7 | 680 return (long)0; |
1030 | 681 #endif |
7 | 682 } |
683 | |
684 /* | |
685 * Get name of current directory into buffer 'buf' of length 'len' bytes. | |
686 * Return OK for success, FAIL for failure. | |
687 */ | |
688 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
689 mch_dirname(char_u *buf, int len) |
7 | 690 { |
691 return mch_FullName((char_u *)"", buf, len, FALSE); | |
692 } | |
693 | |
694 /* | |
695 * get absolute file name into buffer 'buf' of length 'len' bytes | |
696 * | |
697 * return FAIL for failure, OK otherwise | |
698 */ | |
699 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
700 mch_FullName( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
701 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
702 char_u *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
703 int len, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
704 int force) |
7 | 705 { |
706 BPTR l; | |
707 int retval = FAIL; | |
708 int i; | |
709 | |
710 /* Lock the file. If it exists, we can get the exact name. */ | |
711 if ((l = Lock((UBYTE *)fname, (long)ACCESS_READ)) != (BPTR)0) | |
712 { | |
713 retval = lock2name(l, buf, (long)len - 1); | |
714 UnLock(l); | |
715 } | |
716 else if (force || !mch_isFullName(fname)) /* not a full path yet */ | |
717 { | |
718 /* | |
719 * If the file cannot be locked (doesn't exist), try to lock the | |
720 * current directory and concatenate the file name. | |
721 */ | |
722 if ((l = Lock((UBYTE *)"", (long)ACCESS_READ)) != (BPTR)NULL) | |
723 { | |
724 retval = lock2name(l, buf, (long)len); | |
725 UnLock(l); | |
726 if (retval == OK) | |
727 { | |
728 i = STRLEN(buf); | |
729 /* Concatenate the fname to the directory. Don't add a slash | |
730 * if fname is empty, but do change "" to "/". */ | |
731 if (i == 0 || *fname != NUL) | |
732 { | |
733 if (i < len - 1 && (i == 0 || buf[i - 1] != ':')) | |
734 buf[i++] = '/'; | |
419 | 735 vim_strncpy(buf + i, fname, len - i - 1); |
7 | 736 } |
737 } | |
738 } | |
739 } | |
740 if (*buf == 0 || *buf == ':') | |
741 retval = FAIL; /* something failed; use the file name */ | |
742 return retval; | |
743 } | |
744 | |
745 /* | |
746 * Return TRUE if "fname" does not depend on the current directory. | |
747 */ | |
748 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
749 mch_isFullName(char_u *fname) |
7 | 750 { |
751 return (vim_strchr(fname, ':') != NULL && *fname != ':'); | |
752 } | |
753 | |
754 /* | |
755 * Get the full file name from a lock. Use 2.0 function if possible, because | |
756 * the arp function has more restrictions on the path length. | |
757 * | |
758 * return FAIL for failure, OK otherwise | |
759 */ | |
760 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
761 lock2name(BPTR lock, char_u *buf, long len) |
7 | 762 { |
763 #ifdef FEAT_ARP | |
764 if (dos2) /* use 2.0 function */ | |
765 #endif | |
766 return ((int)NameFromLock(lock, (UBYTE *)buf, len) ? OK : FAIL); | |
767 #ifdef FEAT_ARP | |
768 else /* use arp function */ | |
769 return ((int)PathName(lock, (char *)buf, (long)(len/32)) ? OK : FAIL); | |
770 #endif | |
771 } | |
772 | |
773 /* | |
774 * get file permissions for 'name' | |
775 * Returns -1 when it doesn't exist. | |
776 */ | |
777 long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
778 mch_getperm(char_u *name) |
7 | 779 { |
780 struct FileInfoBlock *fib; | |
781 long retval = -1; | |
782 | |
783 fib = get_fib(name); | |
784 if (fib != NULL) | |
785 { | |
786 retval = fib->fib_Protection; | |
1030 | 787 free_fib(fib); |
7 | 788 } |
789 return retval; | |
790 } | |
791 | |
792 /* | |
793 * set file permission for 'name' to 'perm' | |
794 * | |
795 * return FAIL for failure, OK otherwise | |
796 */ | |
797 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
798 mch_setperm(char_u *name, long perm) |
7 | 799 { |
800 perm &= ~FIBF_ARCHIVE; /* reset archived bit */ | |
801 return (SetProtection((UBYTE *)name, (long)perm) ? OK : FAIL); | |
802 } | |
803 | |
804 /* | |
805 * Set hidden flag for "name". | |
806 */ | |
807 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
808 mch_hide(char_u *name) |
7 | 809 { |
810 /* can't hide a file */ | |
811 } | |
812 | |
813 /* | |
814 * return FALSE if "name" is not a directory | |
815 * return TRUE if "name" is a directory. | |
816 * return FALSE for error. | |
817 */ | |
818 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
819 mch_isdir(char_u *name) |
7 | 820 { |
821 struct FileInfoBlock *fib; | |
822 int retval = FALSE; | |
823 | |
824 fib = get_fib(name); | |
825 if (fib != NULL) | |
826 { | |
1030 | 827 #ifdef __amigaos4__ |
828 retval = (FIB_IS_DRAWER(fib)) ? TRUE : FALSE; | |
829 #else | |
7 | 830 retval = ((fib->fib_DirEntryType >= 0) ? TRUE : FALSE); |
1030 | 831 #endif |
832 free_fib(fib); | |
7 | 833 } |
834 return retval; | |
835 } | |
836 | |
837 /* | |
838 * Create directory "name". | |
839 */ | |
982 | 840 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
841 mch_mkdir(char_u *name) |
7 | 842 { |
843 BPTR lock; | |
844 | |
845 lock = CreateDir(name); | |
846 if (lock != NULL) | |
982 | 847 { |
7 | 848 UnLock(lock); |
982 | 849 return 0; |
850 } | |
851 return -1; | |
7 | 852 } |
853 | |
854 /* | |
855 * Return 1 if "name" can be executed, 0 if not. | |
6695 | 856 * If "use_path" is FALSE only check if "name" is executable. |
7 | 857 * Return -1 if unknown. |
858 */ | |
859 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
860 mch_can_exe(char_u *name, char_u **path, int use_path) |
7 | 861 { |
862 /* TODO */ | |
863 return -1; | |
864 } | |
865 | |
866 /* | |
867 * Check what "name" is: | |
868 * NODE_NORMAL: file or directory (or doesn't exist) | |
869 * NODE_WRITABLE: writable device, socket, fifo, etc. | |
870 * NODE_OTHER: non-writable things | |
871 */ | |
872 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
873 mch_nodetype(char_u *name) |
7 | 874 { |
875 /* TODO */ | |
876 return NODE_NORMAL; | |
877 } | |
878 | |
879 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
880 mch_early_init(void) |
7 | 881 { |
882 } | |
883 | |
884 /* | |
885 * Careful: mch_exit() may be called before mch_init()! | |
886 */ | |
887 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
888 mch_exit(int r) |
7 | 889 { |
10835
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
890 exiting = TRUE; |
c9da7f9137af
patch 8.0.0307: asan detects a memory error when EXITFREE is defined
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
891 |
7 | 892 if (raw_in) /* put terminal in 'normal' mode */ |
893 { | |
894 settmode(TMODE_COOK); | |
895 stoptermcap(); | |
896 } | |
897 out_char('\n'); | |
898 if (raw_out) | |
899 { | |
900 if (term_console) | |
901 { | |
902 win_resize_off(); /* window resize events de-activated */ | |
903 if (size_set) | |
904 OUT_STR("\233t\233u"); /* reset window size (CSI t CSI u) */ | |
905 } | |
906 out_flush(); | |
907 } | |
908 | |
909 #ifdef FEAT_TITLE | |
910 mch_restore_title(3); /* restore window title */ | |
911 #endif | |
912 | |
913 ml_close_all(TRUE); /* remove all memfiles */ | |
914 | |
915 #ifdef FEAT_ARP | |
916 if (ArpBase) | |
917 CloseLibrary((struct Library *) ArpBase); | |
918 #endif | |
919 if (close_win) | |
920 Close(raw_in); | |
921 if (r) | |
922 printf(_("Vim exiting with %d\n"), r); /* somehow this makes :cq work!? */ | |
923 exit(r); | |
924 } | |
925 | |
926 /* | |
927 * This is a routine for setting a given stream to raw or cooked mode on the | |
928 * Amiga . This is useful when you are using Lattice C to produce programs | |
929 * that want to read single characters with the "getch()" or "fgetc" call. | |
930 * | |
931 * Written : 18-Jun-87 By Chuck McManis. | |
932 */ | |
933 | |
934 #define MP(xx) ((struct MsgPort *)((struct FileHandle *) (BADDR(xx)))->fh_Type) | |
935 | |
936 /* | |
937 * Function mch_settmode() - Convert the specified file pointer to 'raw' or | |
938 * 'cooked' mode. This only works on TTY's. | |
939 * | |
940 * Raw: keeps DOS from translating keys for you, also (BIG WIN) it means | |
941 * getch() will return immediately rather than wait for a return. You | |
942 * lose editing features though. | |
943 * | |
944 * Cooked: This function returns the designate file pointer to it's normal, | |
945 * wait for a <CR> mode. This is exactly like raw() except that | |
946 * it sends a 0 to the console to make it back into a CON: from a RAW: | |
947 */ | |
948 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
949 mch_settmode(int tmode) |
7 | 950 { |
1030 | 951 #if defined(__AROS__) || defined(__amigaos4__) |
7 | 952 if (!SetMode(raw_in, tmode == TMODE_RAW ? 1 : 0)) |
953 #else | |
954 if (dos_packet(MP(raw_in), (long)ACTION_SCREEN_MODE, | |
955 tmode == TMODE_RAW ? -1L : 0L) == 0) | |
956 #endif | |
957 mch_errmsg(_("cannot change console mode ?!\n")); | |
958 } | |
959 | |
960 /* | |
961 * set screen mode, always fails. | |
962 */ | |
963 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
964 mch_screenmode(char_u *arg) |
7 | 965 { |
966 EMSG(_(e_screenmode)); | |
967 return FAIL; | |
968 } | |
969 | |
970 /* | |
971 * Code for this routine came from the following : | |
972 * | |
973 * ConPackets.c - C. Scheppner, A. Finkel, P. Lindsay CBM | |
974 * DOS packet example | |
975 * Requires 1.2 | |
976 * | |
977 * Found on Fish Disk 56. | |
978 * | |
979 * Heavely modified by mool. | |
980 */ | |
981 | |
3927 | 982 #ifndef PROTO |
983 # include <devices/conunit.h> | |
984 #endif | |
7 | 985 |
986 /* | |
987 * try to get the real window size | |
988 * return FAIL for failure, OK otherwise | |
989 */ | |
990 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
991 mch_get_shellsize(void) |
7 | 992 { |
993 struct ConUnit *conUnit; | |
1030 | 994 #ifndef __amigaos4__ |
7 | 995 char id_a[sizeof(struct InfoData) + 3]; |
1030 | 996 #endif |
997 struct InfoData *id=0; | |
7 | 998 |
999 if (!term_console) /* not an amiga window */ | |
1030 | 1000 goto out; |
7 | 1001 |
1002 /* insure longword alignment */ | |
1030 | 1003 #ifdef __amigaos4__ |
3143 | 1004 if (!(id = AllocDosObject(DOS_INFODATA, 0))) |
1030 | 1005 goto out; |
1006 #else | |
7 | 1007 id = (struct InfoData *)(((long)id_a + 3L) & ~3L); |
1030 | 1008 #endif |
7 | 1009 |
1010 /* | |
1011 * Should make console aware of real window size, not the one we set. | |
1012 * Unfortunately, under DOS 2.0x this redraws the window and it | |
1013 * is rarely needed, so we skip it now, unless we changed the size. | |
1014 */ | |
1015 if (size_set) | |
1016 OUT_STR("\233t\233u"); /* CSI t CSI u */ | |
1017 out_flush(); | |
1018 | |
1019 #ifdef __AROS__ | |
1020 if (!Info(raw_out, id) | |
1021 || (wb_window = (struct Window *) id->id_VolumeNode) == NULL) | |
1022 #else | |
1023 if (dos_packet(MP(raw_out), (long)ACTION_DISK_INFO, ((ULONG) id) >> 2) == 0 | |
1024 || (wb_window = (struct Window *)id->id_VolumeNode) == NULL) | |
1025 #endif | |
1026 { | |
1027 /* it's not an amiga window, maybe aux device */ | |
1028 /* terminal type should be set */ | |
1029 term_console = FALSE; | |
1030 | 1030 goto out; |
7 | 1031 } |
1032 if (oldwindowtitle == NULL) | |
1033 oldwindowtitle = (char_u *)wb_window->Title; | |
1034 if (id->id_InUse == (BPTR)NULL) | |
1035 { | |
1036 mch_errmsg(_("mch_get_shellsize: not a console??\n")); | |
1037 return FAIL; | |
1038 } | |
1039 conUnit = (struct ConUnit *) ((struct IOStdReq *) id->id_InUse)->io_Unit; | |
1040 | |
1041 /* get window size */ | |
1042 Rows = conUnit->cu_YMax + 1; | |
1043 Columns = conUnit->cu_XMax + 1; | |
1044 if (Rows < 0 || Rows > 200) /* cannot be an amiga window */ | |
1045 { | |
1046 Columns = 80; | |
1047 Rows = 24; | |
1048 term_console = FALSE; | |
1049 return FAIL; | |
1050 } | |
1051 | |
1052 return OK; | |
1030 | 1053 out: |
1054 #ifdef __amigaos4__ | |
1055 FreeDosObject(DOS_INFODATA, id); /* Safe to pass NULL */ | |
1056 #endif | |
1057 | |
1058 return FAIL; | |
7 | 1059 } |
1060 | |
1061 /* | |
1062 * Try to set the real window size to Rows and Columns. | |
1063 */ | |
1064 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1065 mch_set_shellsize(void) |
7 | 1066 { |
1067 if (term_console) | |
1068 { | |
1069 size_set = TRUE; | |
1070 out_char(CSI); | |
1071 out_num((long)Rows); | |
1072 out_char('t'); | |
1073 out_char(CSI); | |
1074 out_num((long)Columns); | |
1075 out_char('u'); | |
1076 out_flush(); | |
1077 } | |
1078 } | |
1079 | |
1080 /* | |
1081 * Rows and/or Columns has changed. | |
1082 */ | |
1083 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1084 mch_new_shellsize(void) |
7 | 1085 { |
1086 /* Nothing to do. */ | |
1087 } | |
1088 | |
1089 /* | |
1090 * out_num - output a (big) number fast | |
1091 */ | |
1092 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1093 out_num(long n) |
7 | 1094 { |
1095 OUT_STR_NF(tltoa((unsigned long)n)); | |
1096 } | |
1097 | |
1030 | 1098 #if !defined(AZTEC_C) && !defined(__AROS__) && !defined(__amigaos4__) |
7 | 1099 /* |
1100 * Sendpacket.c | |
1101 * | |
1102 * An invaluable addition to your Amiga.lib file. This code sends a packet to | |
1103 * the given message port. This makes working around DOS lots easier. | |
1104 * | |
1105 * Note, I didn't write this, those wonderful folks at CBM did. I do suggest | |
1106 * however that you may wish to add it to Amiga.Lib, to do so, compile it and | |
1107 * say 'oml lib:amiga.lib -r sendpacket.o' | |
1108 */ | |
1109 | |
3927 | 1110 #ifndef PROTO |
7 | 1111 /* #include <proto/exec.h> */ |
1112 /* #include <proto/dos.h> */ | |
3927 | 1113 # include <exec/memory.h> |
1114 #endif | |
7 | 1115 |
1116 /* | |
1117 * Function - dos_packet written by Phil Lindsay, Carolyn Scheppner, and Andy | |
1118 * Finkel. This function will send a packet of the given type to the Message | |
1119 * Port supplied. | |
1120 */ | |
1121 | |
1122 static long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1123 dos_packet( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1124 struct MsgPort *pid, /* process identifier ... (handlers message port) */ |
7 | 1125 long action, /* packet type ... (what you want handler to do) */ |
10025
068f397d0da4
commit https://github.com/vim/vim/commit/d90b6c02e2900576fb37d95b5e4f4a32b2d7383f
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1126 long arg) /* single argument */ |
7 | 1127 { |
1128 # ifdef FEAT_ARP | |
1129 struct MsgPort *replyport; | |
1130 struct StandardPacket *packet; | |
1131 long res1; | |
1132 | |
1133 if (dos2) | |
1134 # endif | |
1135 return DoPkt(pid, action, arg, 0L, 0L, 0L, 0L); /* use 2.0 function */ | |
1136 # ifdef FEAT_ARP | |
1137 | |
1138 replyport = (struct MsgPort *) CreatePort(NULL, 0); /* use arp function */ | |
1139 if (!replyport) | |
1140 return (0); | |
1141 | |
1142 /* Allocate space for a packet, make it public and clear it */ | |
1143 packet = (struct StandardPacket *) | |
1144 AllocMem((long) sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR); | |
1145 if (!packet) { | |
1146 DeletePort(replyport); | |
1147 return (0); | |
1148 } | |
1149 packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt); | |
1150 packet->sp_Pkt.dp_Link = &(packet->sp_Msg); | |
1151 packet->sp_Pkt.dp_Port = replyport; | |
1152 packet->sp_Pkt.dp_Type = action; | |
1153 packet->sp_Pkt.dp_Arg1 = arg; | |
1154 | |
1155 PutMsg(pid, (struct Message *)packet); /* send packet */ | |
1156 | |
1157 WaitPort(replyport); | |
1158 GetMsg(replyport); | |
1159 | |
1160 res1 = packet->sp_Pkt.dp_Res1; | |
1161 | |
1162 FreeMem(packet, (long) sizeof(struct StandardPacket)); | |
1163 DeletePort(replyport); | |
1164 | |
1165 return (res1); | |
1166 # endif | |
1167 } | |
1168 #endif /* !defined(AZTEC_C) && !defined(__AROS__) */ | |
1169 | |
1170 /* | |
1171 * Call shell. | |
1172 * Return error number for failure, 0 otherwise | |
1173 */ | |
1174 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1175 mch_call_shell( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1176 char_u *cmd, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1177 int options) /* SHELL_*, see vim.h */ |
7 | 1178 { |
1179 BPTR mydir; | |
1180 int x; | |
1181 int tmode = cur_tmode; | |
1182 #ifdef AZTEC_C | |
1183 int use_execute; | |
1184 char_u *shellcmd = NULL; | |
1185 char_u *shellarg; | |
1186 #endif | |
1187 int retval = 0; | |
1188 | |
1189 if (close_win) | |
1190 { | |
1191 /* if Vim opened a window: Executing a shell may cause crashes */ | |
1192 EMSG(_("E360: Cannot execute shell with -f option")); | |
1193 return -1; | |
1194 } | |
1195 | |
1196 if (term_console) | |
1197 win_resize_off(); /* window resize events de-activated */ | |
1198 out_flush(); | |
1199 | |
1200 if (options & SHELL_COOKED) | |
1201 settmode(TMODE_COOK); /* set to normal mode */ | |
1202 mydir = Lock((UBYTE *)"", (long)ACCESS_READ); /* remember current dir */ | |
1203 | |
1204 #if !defined(AZTEC_C) /* not tested very much */ | |
1205 if (cmd == NULL) | |
1206 { | |
1207 # ifdef FEAT_ARP | |
1208 if (dos2) | |
1209 # endif | |
1210 x = SystemTags(p_sh, SYS_UserShell, TRUE, TAG_DONE); | |
1211 # ifdef FEAT_ARP | |
1212 else | |
1213 x = Execute(p_sh, raw_in, raw_out); | |
1214 # endif | |
1215 } | |
1216 else | |
1217 { | |
1218 # ifdef FEAT_ARP | |
1219 if (dos2) | |
1220 # endif | |
1221 x = SystemTags((char *)cmd, SYS_UserShell, TRUE, TAG_DONE); | |
1222 # ifdef FEAT_ARP | |
1223 else | |
1224 x = Execute((char *)cmd, 0L, raw_out); | |
1225 # endif | |
1226 } | |
1227 # ifdef FEAT_ARP | |
1228 if ((dos2 && x < 0) || (!dos2 && !x)) | |
1229 # else | |
1230 if (x < 0) | |
1231 # endif | |
1232 { | |
1233 MSG_PUTS(_("Cannot execute ")); | |
1234 if (cmd == NULL) | |
1235 { | |
1236 MSG_PUTS(_("shell ")); | |
1237 msg_outtrans(p_sh); | |
1238 } | |
1239 else | |
1240 msg_outtrans(cmd); | |
1241 msg_putchar('\n'); | |
1242 retval = -1; | |
1243 } | |
1244 # ifdef FEAT_ARP | |
1245 else if (!dos2 || x) | |
1246 # else | |
1247 else if (x) | |
1248 # endif | |
1249 { | |
1250 if ((x = IoErr()) != 0) | |
1251 { | |
1252 if (!(options & SHELL_SILENT)) | |
1253 { | |
1254 msg_putchar('\n'); | |
1255 msg_outnum((long)x); | |
1256 MSG_PUTS(_(" returned\n")); | |
1257 } | |
1258 retval = x; | |
1259 } | |
1260 } | |
1261 #else /* else part is for AZTEC_C */ | |
1262 if (p_st >= 4 || (p_st >= 2 && !(options & SHELL_FILTER))) | |
1263 use_execute = 1; | |
1264 else | |
1265 use_execute = 0; | |
1266 if (!use_execute) | |
1267 { | |
1268 /* | |
1269 * separate shell name from argument | |
1270 */ | |
1271 shellcmd = vim_strsave(p_sh); | |
1272 if (shellcmd == NULL) /* out of memory, use Execute */ | |
1273 use_execute = 1; | |
1274 else | |
1275 { | |
1276 shellarg = skiptowhite(shellcmd); /* find start of arguments */ | |
1277 if (*shellarg != NUL) | |
1278 { | |
1279 *shellarg++ = NUL; | |
1280 shellarg = skipwhite(shellarg); | |
1281 } | |
1282 } | |
1283 } | |
1284 if (cmd == NULL) | |
1285 { | |
1286 if (use_execute) | |
1287 { | |
1288 # ifdef FEAT_ARP | |
1289 if (dos2) | |
1290 # endif | |
1291 x = SystemTags((UBYTE *)p_sh, SYS_UserShell, TRUE, TAG_DONE); | |
1292 # ifdef FEAT_ARP | |
1293 else | |
1294 x = !Execute((UBYTE *)p_sh, raw_in, raw_out); | |
1295 # endif | |
1296 } | |
1297 else | |
1298 x = fexecl((char *)shellcmd, (char *)shellcmd, (char *)shellarg, NULL); | |
1299 } | |
1300 else if (use_execute) | |
1301 { | |
1302 # ifdef FEAT_ARP | |
1303 if (dos2) | |
1304 # endif | |
1305 x = SystemTags((UBYTE *)cmd, SYS_UserShell, TRUE, TAG_DONE); | |
1306 # ifdef FEAT_ARP | |
1307 else | |
1308 x = !Execute((UBYTE *)cmd, 0L, raw_out); | |
1309 # endif | |
1310 } | |
1311 else if (p_st & 1) | |
1312 x = fexecl((char *)shellcmd, (char *)shellcmd, (char *)shellarg, | |
1313 (char *)cmd, NULL); | |
1314 else | |
1315 x = fexecl((char *)shellcmd, (char *)shellcmd, (char *)shellarg, | |
1316 (char *)p_shcf, (char *)cmd, NULL); | |
1317 # ifdef FEAT_ARP | |
1318 if ((dos2 && x < 0) || (!dos2 && x)) | |
1319 # else | |
1320 if (x < 0) | |
1321 # endif | |
1322 { | |
1323 MSG_PUTS(_("Cannot execute ")); | |
1324 if (use_execute) | |
1325 { | |
1326 if (cmd == NULL) | |
1327 msg_outtrans(p_sh); | |
1328 else | |
1329 msg_outtrans(cmd); | |
1330 } | |
1331 else | |
1332 { | |
1333 MSG_PUTS(_("shell ")); | |
1334 msg_outtrans(shellcmd); | |
1335 } | |
1336 msg_putchar('\n'); | |
1337 retval = -1; | |
1338 } | |
1339 else | |
1340 { | |
1341 if (use_execute) | |
1342 { | |
1343 # ifdef FEAT_ARP | |
1344 if (!dos2 || x) | |
1345 # else | |
1346 if (x) | |
1347 # endif | |
1348 x = IoErr(); | |
1349 } | |
1350 else | |
1351 x = wait(); | |
1352 if (x) | |
1353 { | |
1354 if (!(options & SHELL_SILENT) && !emsg_silent) | |
1355 { | |
1356 msg_putchar('\n'); | |
1357 msg_outnum((long)x); | |
1358 MSG_PUTS(_(" returned\n")); | |
1359 } | |
1360 retval = x; | |
1361 } | |
1362 } | |
1363 vim_free(shellcmd); | |
1364 #endif /* AZTEC_C */ | |
1365 | |
1366 if ((mydir = CurrentDir(mydir)) != 0) /* make sure we stay in the same directory */ | |
1367 UnLock(mydir); | |
1368 if (tmode == TMODE_RAW) | |
1369 settmode(TMODE_RAW); /* set to raw mode */ | |
1370 #ifdef FEAT_TITLE | |
1371 resettitle(); | |
1372 #endif | |
1373 if (term_console) | |
1374 win_resize_on(); /* window resize events activated */ | |
1375 return retval; | |
1376 } | |
1377 | |
1378 /* | |
1379 * check for an "interrupt signal" | |
1380 * We only react to a CTRL-C, but also clear the other break signals to avoid | |
1381 * trouble with lattice-c programs. | |
1382 */ | |
1383 void | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1384 mch_breakcheck(int force) |
7 | 1385 { |
1386 if (SetSignal(0L, (long)(SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F)) & SIGBREAKF_CTRL_C) | |
1387 got_int = TRUE; | |
1388 } | |
1389 | |
1390 /* this routine causes manx to use this Chk_Abort() rather than it's own */ | |
1391 /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */ | |
1392 /* is zero). Since we want to check for our own ^C's */ | |
1393 | |
1394 #ifdef _DCC | |
1395 #define Chk_Abort chkabort | |
1396 #endif | |
1397 | |
1398 #ifdef LATTICE | |
1399 void __regargs __chkabort(void); | |
1400 | |
1401 void __regargs __chkabort(void) | |
1402 {} | |
1403 | |
1404 #else | |
1405 long | |
1406 Chk_Abort(void) | |
1407 { | |
1408 return(0L); | |
1409 } | |
1410 #endif | |
1411 | |
1412 /* | |
1413 * mch_expandpath() - this code does wild-card pattern matching using the arp | |
1414 * routines. | |
1415 * | |
1416 * "pat" has backslashes before chars that are not to be expanded. | |
1417 * Returns the number of matches found. | |
1418 * | |
1419 * This is based on WildDemo2.c (found in arp1.1 distribution). | |
1420 * That code's copyright follows: | |
1421 * Copyright (c) 1987, Scott Ballantyne | |
1422 * Use and abuse as you please. | |
1423 */ | |
1424 | |
1030 | 1425 #ifdef __amigaos4__ |
1426 # define ANCHOR_BUF_SIZE 1024 | |
1427 #else | |
1428 # define ANCHOR_BUF_SIZE (512) | |
1429 # define ANCHOR_SIZE (sizeof(struct AnchorPath) + ANCHOR_BUF_SIZE) | |
1430 #endif | |
7 | 1431 |
1432 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1433 mch_expandpath( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1434 garray_T *gap, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1435 char_u *pat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1436 int flags) /* EW_* flags */ |
7 | 1437 { |
1438 struct AnchorPath *Anchor; | |
1439 LONG Result; | |
1440 char_u *starbuf, *sp, *dp; | |
1441 int start_len; | |
1442 int matches; | |
1030 | 1443 #ifdef __amigaos4__ |
1444 struct TagItem AnchorTags[] = { | |
1445 {ADO_Strlen, ANCHOR_BUF_SIZE}, | |
1446 {ADO_Flags, APF_DODOT|APF_DOWILD|APF_MultiAssigns}, | |
1447 {TAG_DONE, 0L} | |
1448 }; | |
1449 #endif | |
7 | 1450 |
1451 start_len = gap->ga_len; | |
1452 | |
1453 /* Get our AnchorBase */ | |
1030 | 1454 #ifdef __amigaos4__ |
1455 Anchor = AllocDosObject(DOS_ANCHORPATH, AnchorTags); | |
1456 #else | |
7 | 1457 Anchor = (struct AnchorPath *)alloc_clear((unsigned)ANCHOR_SIZE); |
1030 | 1458 #endif |
7 | 1459 if (Anchor == NULL) |
1460 return 0; | |
1461 | |
1030 | 1462 #ifndef __amigaos4__ |
7 | 1463 Anchor->ap_Strlen = ANCHOR_BUF_SIZE; /* ap_Length not supported anymore */ |
1030 | 1464 # ifdef APF_DODOT |
7 | 1465 Anchor->ap_Flags = APF_DODOT | APF_DOWILD; /* allow '.' for current dir */ |
1030 | 1466 # else |
7 | 1467 Anchor->ap_Flags = APF_DoDot | APF_DoWild; /* allow '.' for current dir */ |
1030 | 1468 # endif |
7 | 1469 #endif |
1470 | |
1471 #ifdef FEAT_ARP | |
1472 if (dos2) | |
1473 { | |
1474 #endif | |
1475 /* hack to replace '*' by '#?' */ | |
1476 starbuf = alloc((unsigned)(2 * STRLEN(pat) + 1)); | |
1477 if (starbuf == NULL) | |
1478 goto Return; | |
1479 for (sp = pat, dp = starbuf; *sp; ++sp) | |
1480 { | |
1481 if (*sp == '*') | |
1482 { | |
1483 *dp++ = '#'; | |
1484 *dp++ = '?'; | |
1485 } | |
1486 else | |
1487 *dp++ = *sp; | |
1488 } | |
1489 *dp = NUL; | |
1490 Result = MatchFirst((UBYTE *)starbuf, Anchor); | |
1491 vim_free(starbuf); | |
1492 #ifdef FEAT_ARP | |
1493 } | |
1494 else | |
1495 Result = FindFirst((char *)pat, Anchor); | |
1496 #endif | |
1497 | |
1498 /* | |
1499 * Loop to get all matches. | |
1500 */ | |
1501 while (Result == 0) | |
1502 { | |
1030 | 1503 #ifdef __amigaos4__ |
1504 addfile(gap, (char_u *)Anchor->ap_Buffer, flags); | |
1505 #else | |
7 | 1506 addfile(gap, (char_u *)Anchor->ap_Buf, flags); |
1030 | 1507 #endif |
7 | 1508 #ifdef FEAT_ARP |
1509 if (dos2) | |
1510 #endif | |
1511 Result = MatchNext(Anchor); | |
1512 #ifdef FEAT_ARP | |
1513 else | |
1514 Result = FindNext(Anchor); | |
1515 #endif | |
1516 } | |
1517 matches = gap->ga_len - start_len; | |
1518 | |
1519 if (Result == ERROR_BUFFER_OVERFLOW) | |
1520 EMSG(_("ANCHOR_BUF_SIZE too small.")); | |
1521 else if (matches == 0 && Result != ERROR_OBJECT_NOT_FOUND | |
1522 && Result != ERROR_DEVICE_NOT_MOUNTED | |
1523 && Result != ERROR_NO_MORE_ENTRIES) | |
1524 EMSG(_("I/O ERROR")); | |
1525 | |
1526 /* | |
1527 * Sort the files for this pattern. | |
1528 */ | |
1529 if (matches) | |
1530 qsort((void *)(((char_u **)gap->ga_data) + start_len), | |
1531 (size_t)matches, sizeof(char_u *), sortcmp); | |
1532 | |
1533 /* Free the wildcard stuff */ | |
1534 #ifdef FEAT_ARP | |
1535 if (dos2) | |
1536 #endif | |
1537 MatchEnd(Anchor); | |
1538 #ifdef FEAT_ARP | |
1539 else | |
1540 FreeAnchorChain(Anchor); | |
1541 #endif | |
1542 | |
1543 Return: | |
1030 | 1544 #ifdef __amigaos4__ |
1545 FreeDosObject(DOS_ANCHORPATH, Anchor); | |
1546 #else | |
7 | 1547 vim_free(Anchor); |
1030 | 1548 #endif |
7 | 1549 |
1550 return matches; | |
1551 } | |
1552 | |
1553 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1554 sortcmp(const void *a, const void *b) |
7 | 1555 { |
1556 char *s = *(char **)a; | |
1557 char *t = *(char **)b; | |
1558 | |
39 | 1559 return pathcmp(s, t, -1); |
7 | 1560 } |
1561 | |
1562 /* | |
1563 * Return TRUE if "p" has wildcards that can be expanded by mch_expandpath(). | |
1564 */ | |
1565 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1566 mch_has_exp_wildcard(char_u *p) |
7 | 1567 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1568 for ( ; *p; MB_PTR_ADV(p)) |
7 | 1569 { |
1570 if (*p == '\\' && p[1] != NUL) | |
1571 ++p; | |
1572 else if (vim_strchr((char_u *)"*?[(#", *p) != NULL) | |
1573 return TRUE; | |
1574 } | |
1575 return FALSE; | |
1576 } | |
1577 | |
1578 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1579 mch_has_wildcard(char_u *p) |
7 | 1580 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10835
diff
changeset
|
1581 for ( ; *p; MB_PTR_ADV(p)) |
7 | 1582 { |
1583 if (*p == '\\' && p[1] != NUL) | |
1584 ++p; | |
1585 else | |
1586 if (vim_strchr((char_u *) | |
1587 # ifdef VIM_BACKTICK | |
1588 "*?[(#$`" | |
1589 # else | |
1590 "*?[(#$" | |
1591 # endif | |
1592 , *p) != NULL | |
1593 || (*p == '~' && p[1] != NUL)) | |
1594 return TRUE; | |
1595 } | |
1596 return FALSE; | |
1597 } | |
1598 | |
1599 /* | |
1600 * With AmigaDOS 2.0 support for reading local environment variables | |
1601 * | |
1602 * Two buffers are allocated: | |
1603 * - A big one to do the expansion into. It is freed before returning. | |
1604 * - A small one to hold the return value. It is kept until the next call. | |
1605 */ | |
1606 char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1607 mch_getenv(char_u *var) |
7 | 1608 { |
1609 int len; | |
1610 UBYTE *buf; /* buffer to expand in */ | |
1611 char_u *retval; /* return value */ | |
1612 static char_u *alloced = NULL; /* allocated memory */ | |
1613 | |
1614 #ifdef FEAT_ARP | |
1615 if (!dos2) | |
1616 retval = (char_u *)getenv((char *)var); | |
1617 else | |
1618 #endif | |
1619 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1620 VIM_CLEAR(alloced); |
7 | 1621 retval = NULL; |
1622 | |
1623 buf = alloc(IOSIZE); | |
1624 if (buf == NULL) | |
1625 return NULL; | |
1626 | |
1627 len = GetVar((UBYTE *)var, buf, (long)(IOSIZE - 1), (long)0); | |
1628 if (len >= 0) | |
1629 { | |
1630 retval = vim_strsave((char_u *)buf); | |
1631 alloced = retval; | |
1632 } | |
1633 | |
1634 vim_free(buf); | |
1635 } | |
1636 | |
1637 /* if $VIM is not defined, use "vim:" instead */ | |
1638 if (retval == NULL && STRCMP(var, "VIM") == 0) | |
1639 retval = (char_u *)"vim:"; | |
1640 | |
1641 return retval; | |
1642 } | |
1643 | |
1644 /* | |
1645 * Amiga version of setenv() with AmigaDOS 2.0 support. | |
1646 */ | |
1647 /* ARGSUSED */ | |
1648 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1649 mch_setenv(char *var, char *value, int x) |
7 | 1650 { |
1651 #ifdef FEAT_ARP | |
1652 if (!dos2) | |
1653 return setenv(var, value); | |
1654 #endif | |
1655 | |
1656 if (SetVar((UBYTE *)var, (UBYTE *)value, (LONG)-1, (ULONG)GVF_LOCAL_ONLY)) | |
1657 return 0; /* success */ | |
1658 return -1; /* failure */ | |
1659 } |