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