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