1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
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.
13 * Amiga system-dependent routines.
19 # undef Window /* Amiga has its own Window definition */
26 #undef TRUE /* will be redefined by exec/types.h */
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>
36 # include <proto/dos.h>
37 # include <libraries/dosextens.h>
38 # include <proto/intuition.h>
39 # include <proto/exec.h>
42 #include <exec/memory.h>
44 #include <dos/dostags.h> /* for 2.0 functions */
45 #include <dos/dosasl.h>
47 #if defined(LATTICE) && !defined(SASC) && defined(FEAT_ARP)
48 # include <libraries/arp_pragmas.h>
52 * At this point TRUE and FALSE are defined as 1L and 0L, but we want 1 and 0.
59 #if !defined(AZTEC_C) && !defined(__AROS__)
60 static long dos_packet
__ARGS((struct MsgPort
*, long, long));
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
));
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 */
71 struct IntuitionBase
*IntuitionBase
= NULL
;
73 struct ArpBase
*ArpBase
= NULL
;
76 static struct Window
*wb_window
;
77 static char_u
*oldwindowtitle
= NULL
;
80 int dos2
= FALSE
; /* Amiga DOS 2.0x or higher */
82 int size_set
= FALSE
; /* set to TRUE if window size was set */
87 OUT_STR_NF("\033[12{");
93 OUT_STR_NF("\033[12}");
101 Write(raw_out
, (char *)p
, (long)len
);
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.
111 * Return number of characters read.
114 mch_inchar(buf
, maxlen
, time
, tb_change_cnt
)
117 long time
; /* milli seconds */
126 utime
= 100L; /* time = 0 causes problems in DOS 1.2 */
128 utime
= time
* 1000L; /* convert from milli to micro secs */
129 if (WaitForChar(raw_in
, utime
) == 0) /* no character available */
132 else /* time == -1 */
135 * If there is no character available within 2 seconds (default)
136 * write the autoscript file to disk. Or cause the CursorHold event
139 if (WaitForChar(raw_in
, p_ut
* 1000L) == 0)
142 if (trigger_cursorhold() && maxlen
>= 3)
146 buf
[2] = (int)KE_CURSORHOLD
;
154 for (;;) /* repeat until we got a character */
157 len
= Read(raw_in
, (char *)buf
, (long)maxlen
/ input_conv
.vc_factor
);
159 len
= Read(raw_in
, (char *)buf
, (long)maxlen
);
164 /* Convert from 'termencoding' to 'encoding'. */
165 if (input_conv
.vc_type
!= CONV_NONE
)
166 len
= convert_input(buf
, len
, maxlen
);
174 * return non-zero if a character is available
179 return (WaitForChar(raw_in
, 100L) != 0);
183 * Return amount of memory still available.
186 mch_avail_mem(special
)
189 return (long_u
)AvailMem(special
? (long)MEMF_CHIP
: (long)MEMF_ANY
);
193 mch_delay(msec
, ignoreinput
)
197 #ifndef LATTICE /* SAS declares void Delay(UNLONG) */
198 void Delay
__ARGS((long));
204 Delay(msec
/ 20L); /* Delay works with 20 msec intervals */
206 WaitForChar(raw_in
, msec
* 1000L);
211 * We have no job control, fake it by starting a new shell.
220 # define DOS_LIBRARY ((UBYTE *)"dos.library")
226 static char intlibname
[] = "intuition.library";
229 Enable_Abort
= 0; /* disallow vim to be aborted */
235 * Set input and output channels, unless we have opened our own window
237 if (raw_in
== (BPTR
)NULL
)
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".
246 if (!IsInteractive(raw_in
))
248 else if (!IsInteractive(raw_out
))
255 if ((IntuitionBase
= (struct IntuitionBase
*)
256 OpenLibrary((UBYTE
*)intlibname
, 0L)) == NULL
)
258 mch_errmsg(_("cannot open "));
259 mch_errmsg(intlibname
);
265 #include <workbench/startup.h>
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
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.
278 #define BUF2SIZE 320 /* length of buffer for argument with complete path */
281 mch_check_win(argc
, argv
)
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");
296 char_u
*device
= NULL
;
298 struct Library
*DosBase
;
302 * check if we are running under DOS 2.0x or higher
304 DosBase
= OpenLibrary(DOS_LIBRARY
, 37L);
306 /* if (((struct Library *)DOSBase)->lib_Version >= 37) */
308 CloseLibrary(DosBase
);
313 else /* without arp functions we NEED 2.0 */
316 mch_errmsg(_("Need Amigados version 2.04 or later\n"));
319 /* need arp functions for dos 1.x */
320 if (!(ArpBase
= (struct ArpBase
*) OpenLibrary((UBYTE
*)ArpName
, ArpVersion
)))
322 fprintf(stderr
, _("Need %s version %ld\n"), ArpName
, ArpVersion
);
329 * scan argv[] for the "-f" and "-d" arguments
331 for (i
= 1; i
< argc
; ++i
)
332 if (argv
[i
][0] == '-')
343 /* require using "-dev", "-d" means diff mode */
344 && argv
[i
][2] == 'e' && argv
[i
][3] == 'v'
347 device
= (char_u
*)argv
[i
+ 1];
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
359 && (IsInteractive(Input()) || IsInteractive(Output())))
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.
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.
374 for (i
= -1; i
< 3; ++i
)
377 device
= constrings
[i
];
378 if (device
!= NULL
&& (raw_in
= Open((UBYTE
*)device
,
379 (long)MODE_NEWFILE
)) != (BPTR
)NULL
)
382 if (raw_in
== (BPTR
)NULL
) /* all three failed */
384 mch_errmsg(_(winerr
));
392 if ((nilfh
= Open((UBYTE
*)"NIL:", (long)MODE_NEWFILE
)) == (BPTR
)NULL
)
394 mch_errmsg(_("Cannot open NIL:\n"));
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).
402 sprintf((char *)buf1
, "t:nc%ld", (long)buf1
);
403 if ((fh
= Open((UBYTE
*)buf1
, (long)MODE_NEWFILE
)) == (BPTR
)NULL
)
405 mch_errmsg(_("Cannot create "));
406 mch_errmsg((char *)buf1
);
411 * Write the command into the file, put quotes around the arguments that
412 * have a space in them.
414 if (argc
== 0) /* run from workbench */
415 ac
= ((struct WBStartup
*)argv
)->sm_NumArgs
;
418 for (i
= 0; i
< ac
; ++i
)
423 argp
= &(((struct WBStartup
*)argv
)->sm_ArgList
[i
]);
425 (void)lock2name(argp
->wa_Lock
, buf2
, (long)(BUF2SIZE
- 1));
427 if (dos2
) /* use 2.0 function */
429 AddPart((UBYTE
*)buf2
, (UBYTE
*)argp
->wa_Name
, (long)(BUF2SIZE
- 1));
431 else /* use arp function */
432 TackOn((char *)buf2
, argp
->wa_Name
);
439 /* skip '-d' or "-dev" option */
440 if (av
[0] == '-' && av
[1] == 'd'
442 && av
[2] == 'e' && av
[3] == 'v'
449 if (vim_strchr((char_u
*)av
, ' '))
451 Write(fh
, av
, (long)strlen(av
));
452 if (vim_strchr((char_u
*)av
, ' '))
456 Write(fh
, "\nendcli\n", 8L);
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.
464 for (i
= -1; i
< 3; ++i
)
467 device
= constrings
[i
];
468 else if (device
== NULL
)
470 sprintf((char *)buf2
, "newcli <nil: >nil: %s from %s", (char *)device
, (char *)buf1
);
475 if (!SystemTags((UBYTE
*)buf2
, SYS_UserShell
, TRUE
, TAG_DONE
))
481 if (Execute((UBYTE
*)buf2
, nilfh
, nilfh
))
486 if (i
== 3) /* all three failed */
488 DeleteFile((UBYTE
*)buf1
);
489 mch_errmsg(_(winerr
));
492 exitval
= 0; /* The Execute succeeded: exit this program */
497 CloseLibrary((struct Library
*) ArpBase
);
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!
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.
520 fname_case(name
, len
)
522 int len
; /* buffer size, ignored here */
524 struct FileInfoBlock
*fib
;
531 if (flen
== strlen(fib
->fib_FileName
)) /* safety check */
532 mch_memmove(name
, fib
->fib_FileName
, flen
);
538 * Get the FileInfoBlock for file "fname"
539 * The returned structure has to be free()d.
540 * Returns NULL on error.
542 static struct FileInfoBlock
*
547 struct FileInfoBlock
*fib
;
549 if (fname
== NULL
) /* safety check */
551 fib
= (struct FileInfoBlock
*)malloc(sizeof(struct FileInfoBlock
));
554 flock
= Lock((UBYTE
*)fname
, (long)ACCESS_READ
);
555 if (flock
== (BPTR
)NULL
|| !Examine(flock
, fib
))
557 vim_free(fib
); /* in case of an error the memory is freed here */
568 * set the title of our window
569 * icon name is not set
572 mch_settitle(title
, icon
)
576 if (wb_window
!= NULL
&& title
!= NULL
)
577 SetWindowTitles(wb_window
, (UBYTE
*)title
, (UBYTE
*)-1L);
581 * Restore the window/icon title.
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)
588 mch_restore_title(which
)
592 mch_settitle(oldwindowtitle
, NULL
);
596 mch_can_restore_title()
598 return (wb_window
!= NULL
);
602 mch_can_restore_icon()
609 * Insert user name in s[len].
612 mch_get_user_name(s
, len
)
621 * Insert host name is s[len].
624 mch_get_host_name(s
, len
)
628 vim_strncpy(s
, "Amiga", len
- 1);
641 * Get name of current directory into buffer 'buf' of length 'len' bytes.
642 * Return OK for success, FAIL for failure.
645 mch_dirname(buf
, len
)
649 return mch_FullName((char_u
*)"", buf
, len
, FALSE
);
653 * get absolute file name into buffer 'buf' of length 'len' bytes
655 * return FAIL for failure, OK otherwise
658 mch_FullName(fname
, buf
, len
, force
)
667 /* Lock the file. If it exists, we can get the exact name. */
668 if ((l
= Lock((UBYTE
*)fname
, (long)ACCESS_READ
)) != (BPTR
)0)
670 retval
= lock2name(l
, buf
, (long)len
- 1);
673 else if (force
|| !mch_isFullName(fname
)) /* not a full path yet */
676 * If the file cannot be locked (doesn't exist), try to lock the
677 * current directory and concatenate the file name.
679 if ((l
= Lock((UBYTE
*)"", (long)ACCESS_READ
)) != (BPTR
)NULL
)
681 retval
= lock2name(l
, buf
, (long)len
);
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
)
690 if (i
< len
- 1 && (i
== 0 || buf
[i
- 1] != ':'))
692 vim_strncpy(buf
+ i
, fname
, len
- i
- 1);
697 if (*buf
== 0 || *buf
== ':')
698 retval
= FAIL
; /* something failed; use the file name */
703 * Return TRUE if "fname" does not depend on the current directory.
706 mch_isFullName(fname
)
709 return (vim_strchr(fname
, ':') != NULL
&& *fname
!= ':');
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.
716 * return FAIL for failure, OK otherwise
719 lock2name(lock
, buf
, len
)
725 if (dos2
) /* use 2.0 function */
727 return ((int)NameFromLock(lock
, (UBYTE
*)buf
, len
) ? OK
: FAIL
);
729 else /* use arp function */
730 return ((int)PathName(lock
, (char *)buf
, (long)(len
/32)) ? OK
: FAIL
);
735 * get file permissions for 'name'
736 * Returns -1 when it doesn't exist.
742 struct FileInfoBlock
*fib
;
748 retval
= fib
->fib_Protection
;
755 * set file permission for 'name' to 'perm'
757 * return FAIL for failure, OK otherwise
760 mch_setperm(name
, perm
)
764 perm
&= ~FIBF_ARCHIVE
; /* reset archived bit */
765 return (SetProtection((UBYTE
*)name
, (long)perm
) ? OK
: FAIL
);
769 * Set hidden flag for "name".
775 /* can't hide a file */
779 * return FALSE if "name" is not a directory
780 * return TRUE if "name" is a directory.
781 * return FALSE for error.
787 struct FileInfoBlock
*fib
;
793 retval
= ((fib
->fib_DirEntryType
>= 0) ? TRUE
: FALSE
);
800 * Create directory "name".
808 lock
= CreateDir(name
);
814 * Return 1 if "name" can be executed, 0 if not.
815 * Return -1 if unknown.
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
845 * Careful: mch_exit() may be called before mch_init()!
851 if (raw_in
) /* put terminal in 'normal' mode */
853 settmode(TMODE_COOK
);
861 win_resize_off(); /* window resize events de-activated */
863 OUT_STR("\233t\233u"); /* reset window size (CSI t CSI u) */
869 mch_restore_title(3); /* restore window title */
872 ml_close_all(TRUE
); /* remove all memfiles */
876 CloseLibrary((struct Library
*) ArpBase
);
881 printf(_("Vim exiting with %d\n"), r
); /* somehow this makes :cq work!? */
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.
890 * Written : 18-Jun-87 By Chuck McManis.
893 #define MP(xx) ((struct MsgPort *)((struct FileHandle *) (BADDR(xx)))->fh_Type)
896 * Function mch_settmode() - Convert the specified file pointer to 'raw' or
897 * 'cooked' mode. This only works on TTY's.
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.
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:
912 if (!SetMode(raw_in
, tmode
== TMODE_RAW
? 1 : 0))
914 if (dos_packet(MP(raw_in
), (long)ACTION_SCREEN_MODE
,
915 tmode
== TMODE_RAW
? -1L : 0L) == 0)
917 mch_errmsg(_("cannot change console mode ?!\n"));
921 * set screen mode, always fails.
927 EMSG(_(e_screenmode
));
932 * Code for this routine came from the following :
934 * ConPackets.c - C. Scheppner, A. Finkel, P. Lindsay CBM
938 * Found on Fish Disk 56.
940 * Heavely modified by mool.
943 #include <devices/conunit.h>
946 * try to get the real window size
947 * return FAIL for failure, OK otherwise
952 struct ConUnit
*conUnit
;
953 char id_a
[sizeof(struct InfoData
) + 3];
956 if (!term_console
) /* not an amiga window */
959 /* insure longword alignment */
960 id
= (struct InfoData
*)(((long)id_a
+ 3L) & ~3L);
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.
968 OUT_STR("\233t\233u"); /* CSI t CSI u */
972 if (!Info(raw_out
, id
)
973 || (wb_window
= (struct Window
*) id
->id_VolumeNode
) == NULL
)
975 if (dos_packet(MP(raw_out
), (long)ACTION_DISK_INFO
, ((ULONG
) id
) >> 2) == 0
976 || (wb_window
= (struct Window
*)id
->id_VolumeNode
) == NULL
)
979 /* it's not an amiga window, maybe aux device */
980 /* terminal type should be set */
981 term_console
= FALSE
;
984 if (oldwindowtitle
== NULL
)
985 oldwindowtitle
= (char_u
*)wb_window
->Title
;
986 if (id
->id_InUse
== (BPTR
)NULL
)
988 mch_errmsg(_("mch_get_shellsize: not a console??\n"));
991 conUnit
= (struct ConUnit
*) ((struct IOStdReq
*) id
->id_InUse
)->io_Unit
;
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 */
1000 term_console
= FALSE
;
1008 * Try to set the real window size to Rows and Columns.
1017 out_num((long)Rows
);
1020 out_num((long)Columns
);
1027 * Rows and/or Columns has changed.
1032 /* Nothing to do. */
1036 * out_num - output a (big) number fast
1042 OUT_STR_NF(tltoa((unsigned long)n
));
1045 #if !defined(AZTEC_C) && !defined(__AROS__)
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.
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'
1057 /* #include <proto/exec.h> */
1058 /* #include <proto/dos.h> */
1059 #include <exec/memory.h>
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
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 */
1074 struct MsgPort
*replyport
;
1075 struct StandardPacket
*packet
;
1080 return DoPkt(pid
, action
, arg
, 0L, 0L, 0L, 0L); /* use 2.0 function */
1083 replyport
= (struct MsgPort
*) CreatePort(NULL
, 0); /* use arp function */
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
);
1091 DeletePort(replyport
);
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
;
1100 PutMsg(pid
, (struct Message
*)packet
); /* send packet */
1102 WaitPort(replyport
);
1105 res1
= packet
->sp_Pkt
.dp_Res1
;
1107 FreeMem(packet
, (long) sizeof(struct StandardPacket
));
1108 DeletePort(replyport
);
1113 #endif /* !defined(AZTEC_C) && !defined(__AROS__) */
1117 * Return error number for failure, 0 otherwise
1120 mch_call_shell(cmd
, options
)
1122 int options
; /* SHELL_*, see vim.h */
1126 int tmode
= cur_tmode
;
1129 char_u
*shellcmd
= NULL
;
1136 /* if Vim opened a window: Executing a shell may cause crashes */
1137 EMSG(_("E360: Cannot execute shell with -f option"));
1142 win_resize_off(); /* window resize events de-activated */
1145 if (options
& SHELL_COOKED
)
1146 settmode(TMODE_COOK
); /* set to normal mode */
1147 mydir
= Lock((UBYTE
*)"", (long)ACCESS_READ
); /* remember current dir */
1149 #if !defined(AZTEC_C) /* not tested very much */
1155 x
= SystemTags(p_sh
, SYS_UserShell
, TRUE
, TAG_DONE
);
1158 x
= Execute(p_sh
, raw_in
, raw_out
);
1166 x
= SystemTags((char *)cmd
, SYS_UserShell
, TRUE
, TAG_DONE
);
1169 x
= Execute((char *)cmd
, 0L, raw_out
);
1173 if ((dos2
&& x
< 0) || (!dos2
&& !x
))
1178 MSG_PUTS(_("Cannot execute "));
1181 MSG_PUTS(_("shell "));
1190 else if (!dos2
|| x
)
1195 if ((x
= IoErr()) != 0)
1197 if (!(options
& SHELL_SILENT
))
1200 msg_outnum((long)x
);
1201 MSG_PUTS(_(" returned\n"));
1206 #else /* else part is for AZTEC_C */
1207 if (p_st
>= 4 || (p_st
>= 2 && !(options
& SHELL_FILTER
)))
1214 * separate shell name from argument
1216 shellcmd
= vim_strsave(p_sh
);
1217 if (shellcmd
== NULL
) /* out of memory, use Execute */
1221 shellarg
= skiptowhite(shellcmd
); /* find start of arguments */
1222 if (*shellarg
!= NUL
)
1225 shellarg
= skipwhite(shellarg
);
1236 x
= SystemTags((UBYTE
*)p_sh
, SYS_UserShell
, TRUE
, TAG_DONE
);
1239 x
= !Execute((UBYTE
*)p_sh
, raw_in
, raw_out
);
1243 x
= fexecl((char *)shellcmd
, (char *)shellcmd
, (char *)shellarg
, NULL
);
1245 else if (use_execute
)
1250 x
= SystemTags((UBYTE
*)cmd
, SYS_UserShell
, TRUE
, TAG_DONE
);
1253 x
= !Execute((UBYTE
*)cmd
, 0L, raw_out
);
1257 x
= fexecl((char *)shellcmd
, (char *)shellcmd
, (char *)shellarg
,
1260 x
= fexecl((char *)shellcmd
, (char *)shellcmd
, (char *)shellarg
,
1261 (char *)p_shcf
, (char *)cmd
, NULL
);
1263 if ((dos2
&& x
< 0) || (!dos2
&& x
))
1268 MSG_PUTS(_("Cannot execute "));
1278 MSG_PUTS(_("shell "));
1279 msg_outtrans(shellcmd
);
1299 if (!(options
& SHELL_SILENT
) && !emsg_silent
)
1302 msg_outnum((long)x
);
1303 MSG_PUTS(_(" returned\n"));
1309 #endif /* AZTEC_C */
1311 if ((mydir
= CurrentDir(mydir
)) != 0) /* make sure we stay in the same directory */
1313 if (tmode
== TMODE_RAW
)
1314 settmode(TMODE_RAW
); /* set to raw mode */
1319 win_resize_on(); /* window resize events activated */
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.
1331 if (SetSignal(0L, (long)(SIGBREAKF_CTRL_C
|SIGBREAKF_CTRL_D
|SIGBREAKF_CTRL_E
|SIGBREAKF_CTRL_F
)) & SIGBREAKF_CTRL_C
)
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 */
1340 #define Chk_Abort chkabort
1344 void __regargs
__chkabort(void);
1346 void __regargs
__chkabort(void)
1358 * mch_expandpath() - this code does wild-card pattern matching using the arp
1361 * "pat" has backslashes before chars that are not to be expanded.
1362 * Returns the number of matches found.
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.
1370 #define ANCHOR_BUF_SIZE (512)
1371 #define ANCHOR_SIZE (sizeof(struct AnchorPath) + ANCHOR_BUF_SIZE)
1374 mch_expandpath(gap
, pat
, flags
)
1377 int flags
; /* EW_* flags */
1379 struct AnchorPath
*Anchor
;
1381 char_u
*starbuf
, *sp
, *dp
;
1385 start_len
= gap
->ga_len
;
1387 /* Get our AnchorBase */
1388 Anchor
= (struct AnchorPath
*)alloc_clear((unsigned)ANCHOR_SIZE
);
1392 Anchor
->ap_Strlen
= ANCHOR_BUF_SIZE
; /* ap_Length not supported anymore */
1394 Anchor
->ap_Flags
= APF_DODOT
| APF_DOWILD
; /* allow '.' for current dir */
1396 Anchor
->ap_Flags
= APF_DoDot
| APF_DoWild
; /* allow '.' for current dir */
1403 /* hack to replace '*' by '#?' */
1404 starbuf
= alloc((unsigned)(2 * STRLEN(pat
) + 1));
1405 if (starbuf
== NULL
)
1407 for (sp
= pat
, dp
= starbuf
; *sp
; ++sp
)
1418 Result
= MatchFirst((UBYTE
*)starbuf
, Anchor
);
1423 Result
= FindFirst((char *)pat
, Anchor
);
1427 * Loop to get all matches.
1431 addfile(gap
, (char_u
*)Anchor
->ap_Buf
, flags
);
1435 Result
= MatchNext(Anchor
);
1438 Result
= FindNext(Anchor
);
1441 matches
= gap
->ga_len
- start_len
;
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"));
1451 * Sort the files for this pattern.
1454 qsort((void *)(((char_u
**)gap
->ga_data
) + start_len
),
1455 (size_t)matches
, sizeof(char_u
*), sortcmp
);
1457 /* Free the wildcard stuff */
1464 FreeAnchorChain(Anchor
);
1477 char *s
= *(char **)a
;
1478 char *t
= *(char **)b
;
1480 return pathcmp(s
, t
, -1);
1484 * Return TRUE if "p" has wildcards that can be expanded by mch_expandpath().
1487 mch_has_exp_wildcard(p
)
1490 for ( ; *p
; mb_ptr_adv(p
))
1492 if (*p
== '\\' && p
[1] != NUL
)
1494 else if (vim_strchr((char_u
*)"*?[(#", *p
) != NULL
)
1504 for ( ; *p
; mb_ptr_adv(p
))
1506 if (*p
== '\\' && p
[1] != NUL
)
1509 if (vim_strchr((char_u
*)
1510 # ifdef VIM_BACKTICK
1516 || (*p
== '~' && p
[1] != NUL
))
1523 * With AmigaDOS 2.0 support for reading local environment variables
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.
1534 UBYTE
*buf
; /* buffer to expand in */
1535 char_u
*retval
; /* return value */
1536 static char_u
*alloced
= NULL
; /* allocated memory */
1540 retval
= (char_u
*)getenv((char *)var
);
1548 buf
= alloc(IOSIZE
);
1552 len
= GetVar((UBYTE
*)var
, buf
, (long)(IOSIZE
- 1), (long)0);
1555 retval
= vim_strsave((char_u
*)buf
);
1562 /* if $VIM is not defined, use "vim:" instead */
1563 if (retval
== NULL
&& STRCMP(var
, "VIM") == 0)
1564 retval
= (char_u
*)"vim:";
1570 * Amiga version of setenv() with AmigaDOS 2.0 support.
1574 mch_setenv(var
, value
, x
)
1581 return setenv(var
, value
);
1584 if (SetVar((UBYTE
*)var
, (UBYTE
*)value
, (LONG
)-1, (ULONG
)GVF_LOCAL_ONLY
))
1585 return 0; /* success */
1586 return -1; /* failure */