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