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