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 */
22 #undef TRUE /* will be redefined by exec/types.h */
26 # include <exec/types.h>
27 # include <exec/exec.h>
28 # include <libraries/dos.h>
29 # include <intuition/intuition.h>
32 /* XXX These are included from os_amiga.h
33 #include <proto/exec.h>
34 #include <proto/dos.h>
35 #include <proto/intuition.h>
38 #include <exec/memory.h>
39 #include <libraries/dosextens.h>
41 #include <dos/dostags.h> /* for 2.0 functions */
42 #include <dos/dosasl.h>
44 /* From version 4 of AmigaOS, several system structures must be allocated
45 * and freed using system functions. "struct AnchorPath" is one.
48 # include <dos/anchorpath.h>
49 # define free_fib(x) FreeDosObject(DOS_FIB, x)
51 # define free_fib(x) vim_free(fib)
54 #if defined(LATTICE) && !defined(SASC) && defined(FEAT_ARP)
55 # include <libraries/arp_pragmas.h>
59 * At this point TRUE and FALSE are defined as 1L and 0L, but we want 1 and 0.
67 # define dos_packet(a, b, c) DoPkt(a, b, c, 0, 0, 0, 0)
68 #elif !defined(AZTEC_C) && !defined(__AROS__)
69 static long dos_packet
__ARGS((struct MsgPort
*, long, long));
71 static int lock2name
__ARGS((BPTR lock
, char_u
*buf
, long len
));
72 static void out_num
__ARGS((long n
));
73 static struct FileInfoBlock
*get_fib
__ARGS((char_u
*));
74 static int sortcmp
__ARGS((const void *a
, const void *b
));
76 static BPTR raw_in
= (BPTR
)NULL
;
77 static BPTR raw_out
= (BPTR
)NULL
;
78 static int close_win
= FALSE
; /* set if Vim opened the window */
80 #ifndef __amigaos4__ /* Use autoopen for AmigaOS4 */
81 struct IntuitionBase
*IntuitionBase
= NULL
;
84 struct ArpBase
*ArpBase
= NULL
;
87 static struct Window
*wb_window
;
88 static char_u
*oldwindowtitle
= NULL
;
91 int dos2
= FALSE
; /* Amiga DOS 2.0x or higher */
93 int size_set
= FALSE
; /* set to TRUE if window size was set */
98 OUT_STR_NF("\033[12{");
104 OUT_STR_NF("\033[12}");
112 Write(raw_out
, (char *)p
, (long)len
);
116 * mch_inchar(): low level input funcion.
117 * Get a characters from the keyboard.
118 * If time == 0 do not wait for characters.
119 * If time == n wait a short time for characters.
120 * If time == -1 wait forever for characters.
122 * Return number of characters read.
125 mch_inchar(buf
, maxlen
, time
, tb_change_cnt
)
128 long time
; /* milli seconds */
137 utime
= 100L; /* time = 0 causes problems in DOS 1.2 */
139 utime
= time
* 1000L; /* convert from milli to micro secs */
140 if (WaitForChar(raw_in
, utime
) == 0) /* no character available */
143 else /* time == -1 */
146 * If there is no character available within 2 seconds (default)
147 * write the autoscript file to disk. Or cause the CursorHold event
150 if (WaitForChar(raw_in
, p_ut
* 1000L) == 0)
153 if (trigger_cursorhold() && maxlen
>= 3)
157 buf
[2] = (int)KE_CURSORHOLD
;
165 for (;;) /* repeat until we got a character */
168 len
= Read(raw_in
, (char *)buf
, (long)maxlen
/ input_conv
.vc_factor
);
170 len
= Read(raw_in
, (char *)buf
, (long)maxlen
);
175 /* Convert from 'termencoding' to 'encoding'. */
176 if (input_conv
.vc_type
!= CONV_NONE
)
177 len
= convert_input(buf
, len
, maxlen
);
185 * return non-zero if a character is available
190 return (WaitForChar(raw_in
, 100L) != 0);
194 * Return amount of memory still available.
197 mch_avail_mem(special
)
201 return (long_u
)AvailMem(MEMF_ANY
);
203 return (long_u
)AvailMem(special
? (long)MEMF_CHIP
: (long)MEMF_ANY
);
208 * Waits a specified amount of time, or until input arrives if
209 * ignoreinput is FALSE.
212 mch_delay(msec
, ignoreinput
)
216 #ifndef LATTICE /* SAS declares void Delay(ULONG) */
217 void Delay
__ARGS((long));
223 Delay(msec
/ 20L); /* Delay works with 20 msec intervals */
225 WaitForChar(raw_in
, msec
* 1000L);
230 * We have no job control, fake it by starting a new shell.
239 # define DOS_LIBRARY ((UBYTE *)"dos.library")
245 static char intlibname
[] = "intuition.library";
248 Enable_Abort
= 0; /* disallow vim to be aborted */
254 * Set input and output channels, unless we have opened our own window
256 if (raw_in
== (BPTR
)NULL
)
261 * If Input() is not interactive, then Output() will be (because of
262 * check in mch_check_win()). Used for "Vim -".
263 * Also check the other way around, for "Vim -h | more".
265 if (!IsInteractive(raw_in
))
267 else if (!IsInteractive(raw_out
))
275 if ((IntuitionBase
= (struct IntuitionBase
*)
276 OpenLibrary((UBYTE
*)intlibname
, 0L)) == NULL
)
278 mch_errmsg(_("cannot open "));
279 mch_errmsg(intlibname
);
286 #include <workbench/startup.h>
289 * Check_win checks whether we have an interactive window.
290 * If not, a new window is opened with the newcli command.
291 * If we would open a window ourselves, the :sh and :! commands would not
292 * work properly (Why? probably because we are then running in a background
293 * CLI). This also is the best way to assure proper working in a next
296 * For the -f option (foreground mode) we open our own window and disable :sh.
297 * Otherwise the calling program would never know when editing is finished.
299 #define BUF2SIZE 320 /* length of buffer for argument with complete path */
302 mch_check_win(argc
, argv
)
309 char_u buf2
[BUF2SIZE
];
310 static char_u
*(constrings
[3]) = {(char_u
*)"con:0/0/662/210/",
311 (char_u
*)"con:0/0/640/200/",
312 (char_u
*)"con:0/0/320/200/"};
313 static char_u
*winerr
= (char_u
*)N_("VIM: Can't open window!\n");
317 char_u
*device
= NULL
;
320 struct Library
*DosBase
;
325 * check if we are running under DOS 2.0x or higher
328 DosBase
= OpenLibrary(DOS_LIBRARY
, 37L);
330 /* if (((struct Library *)DOSBase)->lib_Version >= 37) */
332 CloseLibrary(DosBase
);
337 else /* without arp functions we NEED 2.0 */
340 mch_errmsg(_("Need Amigados version 2.04 or later\n"));
343 /* need arp functions for dos 1.x */
344 if (!(ArpBase
= (struct ArpBase
*) OpenLibrary((UBYTE
*)ArpName
, ArpVersion
)))
346 fprintf(stderr
, _("Need %s version %ld\n"), ArpName
, ArpVersion
);
351 #endif /* __amigaos4__ */
354 * scan argv[] for the "-f" and "-d" arguments
356 for (i
= 1; i
< argc
; ++i
)
357 if (argv
[i
][0] == '-')
368 /* require using "-dev", "-d" means diff mode */
369 && argv
[i
][2] == 'e' && argv
[i
][3] == 'v'
372 device
= (char_u
*)argv
[i
+ 1];
378 * If we were not started from workbench, do not have a "-d" or "-dev"
379 * argument and we have been started with an interactive window, use that
384 && (IsInteractive(Input()) || IsInteractive(Output())))
388 * When given the "-f" argument, we open our own window. We can't use the
389 * newcli trick below, because the calling program (mail, rn, etc.) would not
390 * know when we are finished.
395 * Try to open a window. First try the specified device.
396 * Then try a 24 line 80 column window.
397 * If that fails, try two smaller ones.
399 for (i
= -1; i
< 3; ++i
)
402 device
= constrings
[i
];
403 if (device
!= NULL
&& (raw_in
= Open((UBYTE
*)device
,
404 (long)MODE_NEWFILE
)) != (BPTR
)NULL
)
407 if (raw_in
== (BPTR
)NULL
) /* all three failed */
409 mch_errmsg(_(winerr
));
417 if ((nilfh
= Open((UBYTE
*)"NIL:", (long)MODE_NEWFILE
)) == (BPTR
)NULL
)
419 mch_errmsg(_("Cannot open NIL:\n"));
424 * Make a unique name for the temp file (which we will not delete!).
425 * Use a pointer on the stack (nobody else will be using it).
426 * Under AmigaOS4, this assumption might change in the future, so
427 * we use a pointer to the current task instead. This should be a
428 * shared structure and thus globally unique.
431 sprintf((char *)buf1
, "t:nc%p", FindTask(0));
433 sprintf((char *)buf1
, "t:nc%ld", (long)buf1
);
435 if ((fh
= Open((UBYTE
*)buf1
, (long)MODE_NEWFILE
)) == (BPTR
)NULL
)
437 mch_errmsg(_("Cannot create "));
438 mch_errmsg((char *)buf1
);
443 * Write the command into the file, put quotes around the arguments that
444 * have a space in them.
446 if (argc
== 0) /* run from workbench */
447 ac
= ((struct WBStartup
*)argv
)->sm_NumArgs
;
450 for (i
= 0; i
< ac
; ++i
)
455 argp
= &(((struct WBStartup
*)argv
)->sm_ArgList
[i
]);
457 (void)lock2name(argp
->wa_Lock
, buf2
, (long)(BUF2SIZE
- 1));
459 if (dos2
) /* use 2.0 function */
461 AddPart((UBYTE
*)buf2
, (UBYTE
*)argp
->wa_Name
, (long)(BUF2SIZE
- 1));
463 else /* use arp function */
464 TackOn((char *)buf2
, argp
->wa_Name
);
471 /* skip '-d' or "-dev" option */
472 if (av
[0] == '-' && av
[1] == 'd'
474 && av
[2] == 'e' && av
[3] == 'v'
481 if (vim_strchr((char_u
*)av
, ' '))
483 Write(fh
, av
, (long)strlen(av
));
484 if (vim_strchr((char_u
*)av
, ' '))
488 Write(fh
, "\nendcli\n", 8L);
492 * Try to open a new cli in a window. If "-d" or "-dev" argument was given try
493 * to open the specified device. Then try a 24 line 80 column window. If that
494 * fails, try two smaller ones.
496 for (i
= -1; i
< 3; ++i
)
499 device
= constrings
[i
];
500 else if (device
== NULL
)
502 sprintf((char *)buf2
, "newcli <nil: >nil: %s from %s", (char *)device
, (char *)buf1
);
507 if (!SystemTags((UBYTE
*)buf2
, SYS_UserShell
, TRUE
, TAG_DONE
))
513 if (Execute((UBYTE
*)buf2
, nilfh
, nilfh
))
518 if (i
== 3) /* all three failed */
520 DeleteFile((UBYTE
*)buf1
);
521 mch_errmsg(_(winerr
));
524 exitval
= 0; /* The Execute succeeded: exit this program */
529 CloseLibrary((struct Library
*) ArpBase
);
537 * Return TRUE if the input comes from a terminal, FALSE otherwise.
538 * We fake there is a window, because we can always open one!
547 * fname_case(): Set the case of the file name, if it already exists.
548 * This will cause the file name to remain exactly the same
549 * if the file system ignores, but preserves case.
553 fname_case(name
, len
)
555 int len
; /* buffer size, ignored here */
557 struct FileInfoBlock
*fib
;
564 /* TODO: Check if this fix applies to AmigaOS < 4 too.*/
566 if (fib
->fib_DirEntryType
== ST_ROOT
)
567 strcat(fib
->fib_FileName
, ":");
569 if (flen
== strlen(fib
->fib_FileName
)) /* safety check */
570 mch_memmove(name
, fib
->fib_FileName
, flen
);
576 * Get the FileInfoBlock for file "fname"
577 * The returned structure has to be free()d.
578 * Returns NULL on error.
580 static struct FileInfoBlock
*
585 struct FileInfoBlock
*fib
;
587 if (fname
== NULL
) /* safety check */
590 fib
= AllocDosObject(DOS_FIB
,0);
592 fib
= (struct FileInfoBlock
*)alloc(sizeof(struct FileInfoBlock
));
596 flock
= Lock((UBYTE
*)fname
, (long)ACCESS_READ
);
597 if (flock
== (BPTR
)NULL
|| !Examine(flock
, fib
))
599 free_fib(fib
); /* in case of an error the memory is freed here */
610 * set the title of our window
611 * icon name is not set
614 mch_settitle(title
, icon
)
618 if (wb_window
!= NULL
&& title
!= NULL
)
619 SetWindowTitles(wb_window
, (UBYTE
*)title
, (UBYTE
*)-1L);
623 * Restore the window/icon title.
625 * 1 Just restore title
626 * 2 Just restore icon (which we don't have)
627 * 3 Restore title and icon (which we don't have)
630 mch_restore_title(which
)
634 mch_settitle(oldwindowtitle
, NULL
);
638 mch_can_restore_title()
640 return (wb_window
!= NULL
);
644 mch_can_restore_icon()
651 * Insert user name in s[len].
654 mch_get_user_name(s
, len
)
658 /* TODO: Implement this. */
664 * Insert host name is s[len].
667 mch_get_host_name(s
, len
)
671 #if defined(__amigaos4__) && defined(__CLIB2__)
674 vim_strncpy(s
, "Amiga", len
- 1);
685 /* This is as close to a pid as we can come. We could use CLI numbers also,
686 * but then we would have two different types of process identifiers.
688 return((long)FindTask(0));
695 * Get name of current directory into buffer 'buf' of length 'len' bytes.
696 * Return OK for success, FAIL for failure.
699 mch_dirname(buf
, len
)
703 return mch_FullName((char_u
*)"", buf
, len
, FALSE
);
707 * get absolute file name into buffer 'buf' of length 'len' bytes
709 * return FAIL for failure, OK otherwise
712 mch_FullName(fname
, buf
, len
, force
)
721 /* Lock the file. If it exists, we can get the exact name. */
722 if ((l
= Lock((UBYTE
*)fname
, (long)ACCESS_READ
)) != (BPTR
)0)
724 retval
= lock2name(l
, buf
, (long)len
- 1);
727 else if (force
|| !mch_isFullName(fname
)) /* not a full path yet */
730 * If the file cannot be locked (doesn't exist), try to lock the
731 * current directory and concatenate the file name.
733 if ((l
= Lock((UBYTE
*)"", (long)ACCESS_READ
)) != (BPTR
)NULL
)
735 retval
= lock2name(l
, buf
, (long)len
);
740 /* Concatenate the fname to the directory. Don't add a slash
741 * if fname is empty, but do change "" to "/". */
742 if (i
== 0 || *fname
!= NUL
)
744 if (i
< len
- 1 && (i
== 0 || buf
[i
- 1] != ':'))
746 vim_strncpy(buf
+ i
, fname
, len
- i
- 1);
751 if (*buf
== 0 || *buf
== ':')
752 retval
= FAIL
; /* something failed; use the file name */
757 * Return TRUE if "fname" does not depend on the current directory.
760 mch_isFullName(fname
)
763 return (vim_strchr(fname
, ':') != NULL
&& *fname
!= ':');
767 * Get the full file name from a lock. Use 2.0 function if possible, because
768 * the arp function has more restrictions on the path length.
770 * return FAIL for failure, OK otherwise
773 lock2name(lock
, buf
, len
)
779 if (dos2
) /* use 2.0 function */
781 return ((int)NameFromLock(lock
, (UBYTE
*)buf
, len
) ? OK
: FAIL
);
783 else /* use arp function */
784 return ((int)PathName(lock
, (char *)buf
, (long)(len
/32)) ? OK
: FAIL
);
789 * get file permissions for 'name'
790 * Returns -1 when it doesn't exist.
796 struct FileInfoBlock
*fib
;
802 retval
= fib
->fib_Protection
;
809 * set file permission for 'name' to 'perm'
811 * return FAIL for failure, OK otherwise
814 mch_setperm(name
, perm
)
818 perm
&= ~FIBF_ARCHIVE
; /* reset archived bit */
819 return (SetProtection((UBYTE
*)name
, (long)perm
) ? OK
: FAIL
);
823 * Set hidden flag for "name".
829 /* can't hide a file */
833 * return FALSE if "name" is not a directory
834 * return TRUE if "name" is a directory.
835 * return FALSE for error.
841 struct FileInfoBlock
*fib
;
848 retval
= (FIB_IS_DRAWER(fib
)) ? TRUE
: FALSE
;
850 retval
= ((fib
->fib_DirEntryType
>= 0) ? TRUE
: FALSE
);
858 * Create directory "name".
866 lock
= CreateDir(name
);
876 * Return 1 if "name" can be executed, 0 if not.
877 * Return -1 if unknown.
888 * Check what "name" is:
889 * NODE_NORMAL: file or directory (or doesn't exist)
890 * NODE_WRITABLE: writable device, socket, fifo, etc.
891 * NODE_OTHER: non-writable things
907 * Careful: mch_exit() may be called before mch_init()!
913 if (raw_in
) /* put terminal in 'normal' mode */
915 settmode(TMODE_COOK
);
923 win_resize_off(); /* window resize events de-activated */
925 OUT_STR("\233t\233u"); /* reset window size (CSI t CSI u) */
931 mch_restore_title(3); /* restore window title */
934 ml_close_all(TRUE
); /* remove all memfiles */
938 CloseLibrary((struct Library
*) ArpBase
);
943 printf(_("Vim exiting with %d\n"), r
); /* somehow this makes :cq work!? */
948 * This is a routine for setting a given stream to raw or cooked mode on the
949 * Amiga . This is useful when you are using Lattice C to produce programs
950 * that want to read single characters with the "getch()" or "fgetc" call.
952 * Written : 18-Jun-87 By Chuck McManis.
955 #define MP(xx) ((struct MsgPort *)((struct FileHandle *) (BADDR(xx)))->fh_Type)
958 * Function mch_settmode() - Convert the specified file pointer to 'raw' or
959 * 'cooked' mode. This only works on TTY's.
961 * Raw: keeps DOS from translating keys for you, also (BIG WIN) it means
962 * getch() will return immediately rather than wait for a return. You
963 * lose editing features though.
965 * Cooked: This function returns the designate file pointer to it's normal,
966 * wait for a <CR> mode. This is exactly like raw() except that
967 * it sends a 0 to the console to make it back into a CON: from a RAW:
973 #if defined(__AROS__) || defined(__amigaos4__)
974 if (!SetMode(raw_in
, tmode
== TMODE_RAW
? 1 : 0))
976 if (dos_packet(MP(raw_in
), (long)ACTION_SCREEN_MODE
,
977 tmode
== TMODE_RAW
? -1L : 0L) == 0)
979 mch_errmsg(_("cannot change console mode ?!\n"));
983 * set screen mode, always fails.
989 EMSG(_(e_screenmode
));
994 * Code for this routine came from the following :
996 * ConPackets.c - C. Scheppner, A. Finkel, P. Lindsay CBM
1000 * Found on Fish Disk 56.
1002 * Heavely modified by mool.
1005 #include <devices/conunit.h>
1008 * try to get the real window size
1009 * return FAIL for failure, OK otherwise
1014 struct ConUnit
*conUnit
;
1015 #ifndef __amigaos4__
1016 char id_a
[sizeof(struct InfoData
) + 3];
1018 struct InfoData
*id
=0;
1020 if (!term_console
) /* not an amiga window */
1023 /* insure longword alignment */
1025 if(!(id
= AllocDosObject(DOS_INFODATA
, 0)))
1028 id
= (struct InfoData
*)(((long)id_a
+ 3L) & ~3L);
1032 * Should make console aware of real window size, not the one we set.
1033 * Unfortunately, under DOS 2.0x this redraws the window and it
1034 * is rarely needed, so we skip it now, unless we changed the size.
1037 OUT_STR("\233t\233u"); /* CSI t CSI u */
1041 if (!Info(raw_out
, id
)
1042 || (wb_window
= (struct Window
*) id
->id_VolumeNode
) == NULL
)
1044 if (dos_packet(MP(raw_out
), (long)ACTION_DISK_INFO
, ((ULONG
) id
) >> 2) == 0
1045 || (wb_window
= (struct Window
*)id
->id_VolumeNode
) == NULL
)
1048 /* it's not an amiga window, maybe aux device */
1049 /* terminal type should be set */
1050 term_console
= FALSE
;
1053 if (oldwindowtitle
== NULL
)
1054 oldwindowtitle
= (char_u
*)wb_window
->Title
;
1055 if (id
->id_InUse
== (BPTR
)NULL
)
1057 mch_errmsg(_("mch_get_shellsize: not a console??\n"));
1060 conUnit
= (struct ConUnit
*) ((struct IOStdReq
*) id
->id_InUse
)->io_Unit
;
1062 /* get window size */
1063 Rows
= conUnit
->cu_YMax
+ 1;
1064 Columns
= conUnit
->cu_XMax
+ 1;
1065 if (Rows
< 0 || Rows
> 200) /* cannot be an amiga window */
1069 term_console
= FALSE
;
1076 FreeDosObject(DOS_INFODATA
, id
); /* Safe to pass NULL */
1083 * Try to set the real window size to Rows and Columns.
1092 out_num((long)Rows
);
1095 out_num((long)Columns
);
1102 * Rows and/or Columns has changed.
1107 /* Nothing to do. */
1111 * out_num - output a (big) number fast
1117 OUT_STR_NF(tltoa((unsigned long)n
));
1120 #if !defined(AZTEC_C) && !defined(__AROS__) && !defined(__amigaos4__)
1124 * An invaluable addition to your Amiga.lib file. This code sends a packet to
1125 * the given message port. This makes working around DOS lots easier.
1127 * Note, I didn't write this, those wonderful folks at CBM did. I do suggest
1128 * however that you may wish to add it to Amiga.Lib, to do so, compile it and
1129 * say 'oml lib:amiga.lib -r sendpacket.o'
1132 /* #include <proto/exec.h> */
1133 /* #include <proto/dos.h> */
1134 #include <exec/memory.h>
1137 * Function - dos_packet written by Phil Lindsay, Carolyn Scheppner, and Andy
1138 * Finkel. This function will send a packet of the given type to the Message
1143 dos_packet(pid
, action
, arg
)
1144 struct MsgPort
*pid
; /* process identifier ... (handlers message port) */
1145 long action
, /* packet type ... (what you want handler to do) */
1146 arg
; /* single argument */
1149 struct MsgPort
*replyport
;
1150 struct StandardPacket
*packet
;
1155 return DoPkt(pid
, action
, arg
, 0L, 0L, 0L, 0L); /* use 2.0 function */
1158 replyport
= (struct MsgPort
*) CreatePort(NULL
, 0); /* use arp function */
1162 /* Allocate space for a packet, make it public and clear it */
1163 packet
= (struct StandardPacket
*)
1164 AllocMem((long) sizeof(struct StandardPacket
), MEMF_PUBLIC
| MEMF_CLEAR
);
1166 DeletePort(replyport
);
1169 packet
->sp_Msg
.mn_Node
.ln_Name
= (char *) &(packet
->sp_Pkt
);
1170 packet
->sp_Pkt
.dp_Link
= &(packet
->sp_Msg
);
1171 packet
->sp_Pkt
.dp_Port
= replyport
;
1172 packet
->sp_Pkt
.dp_Type
= action
;
1173 packet
->sp_Pkt
.dp_Arg1
= arg
;
1175 PutMsg(pid
, (struct Message
*)packet
); /* send packet */
1177 WaitPort(replyport
);
1180 res1
= packet
->sp_Pkt
.dp_Res1
;
1182 FreeMem(packet
, (long) sizeof(struct StandardPacket
));
1183 DeletePort(replyport
);
1188 #endif /* !defined(AZTEC_C) && !defined(__AROS__) */
1192 * Return error number for failure, 0 otherwise
1195 mch_call_shell(cmd
, options
)
1197 int options
; /* SHELL_*, see vim.h */
1201 int tmode
= cur_tmode
;
1204 char_u
*shellcmd
= NULL
;
1211 /* if Vim opened a window: Executing a shell may cause crashes */
1212 EMSG(_("E360: Cannot execute shell with -f option"));
1217 win_resize_off(); /* window resize events de-activated */
1220 if (options
& SHELL_COOKED
)
1221 settmode(TMODE_COOK
); /* set to normal mode */
1222 mydir
= Lock((UBYTE
*)"", (long)ACCESS_READ
); /* remember current dir */
1224 #if !defined(AZTEC_C) /* not tested very much */
1230 x
= SystemTags(p_sh
, SYS_UserShell
, TRUE
, TAG_DONE
);
1233 x
= Execute(p_sh
, raw_in
, raw_out
);
1241 x
= SystemTags((char *)cmd
, SYS_UserShell
, TRUE
, TAG_DONE
);
1244 x
= Execute((char *)cmd
, 0L, raw_out
);
1248 if ((dos2
&& x
< 0) || (!dos2
&& !x
))
1253 MSG_PUTS(_("Cannot execute "));
1256 MSG_PUTS(_("shell "));
1265 else if (!dos2
|| x
)
1270 if ((x
= IoErr()) != 0)
1272 if (!(options
& SHELL_SILENT
))
1275 msg_outnum((long)x
);
1276 MSG_PUTS(_(" returned\n"));
1281 #else /* else part is for AZTEC_C */
1282 if (p_st
>= 4 || (p_st
>= 2 && !(options
& SHELL_FILTER
)))
1289 * separate shell name from argument
1291 shellcmd
= vim_strsave(p_sh
);
1292 if (shellcmd
== NULL
) /* out of memory, use Execute */
1296 shellarg
= skiptowhite(shellcmd
); /* find start of arguments */
1297 if (*shellarg
!= NUL
)
1300 shellarg
= skipwhite(shellarg
);
1311 x
= SystemTags((UBYTE
*)p_sh
, SYS_UserShell
, TRUE
, TAG_DONE
);
1314 x
= !Execute((UBYTE
*)p_sh
, raw_in
, raw_out
);
1318 x
= fexecl((char *)shellcmd
, (char *)shellcmd
, (char *)shellarg
, NULL
);
1320 else if (use_execute
)
1325 x
= SystemTags((UBYTE
*)cmd
, SYS_UserShell
, TRUE
, TAG_DONE
);
1328 x
= !Execute((UBYTE
*)cmd
, 0L, raw_out
);
1332 x
= fexecl((char *)shellcmd
, (char *)shellcmd
, (char *)shellarg
,
1335 x
= fexecl((char *)shellcmd
, (char *)shellcmd
, (char *)shellarg
,
1336 (char *)p_shcf
, (char *)cmd
, NULL
);
1338 if ((dos2
&& x
< 0) || (!dos2
&& x
))
1343 MSG_PUTS(_("Cannot execute "));
1353 MSG_PUTS(_("shell "));
1354 msg_outtrans(shellcmd
);
1374 if (!(options
& SHELL_SILENT
) && !emsg_silent
)
1377 msg_outnum((long)x
);
1378 MSG_PUTS(_(" returned\n"));
1384 #endif /* AZTEC_C */
1386 if ((mydir
= CurrentDir(mydir
)) != 0) /* make sure we stay in the same directory */
1388 if (tmode
== TMODE_RAW
)
1389 settmode(TMODE_RAW
); /* set to raw mode */
1394 win_resize_on(); /* window resize events activated */
1399 * check for an "interrupt signal"
1400 * We only react to a CTRL-C, but also clear the other break signals to avoid
1401 * trouble with lattice-c programs.
1406 if (SetSignal(0L, (long)(SIGBREAKF_CTRL_C
|SIGBREAKF_CTRL_D
|SIGBREAKF_CTRL_E
|SIGBREAKF_CTRL_F
)) & SIGBREAKF_CTRL_C
)
1410 /* this routine causes manx to use this Chk_Abort() rather than it's own */
1411 /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
1412 /* is zero). Since we want to check for our own ^C's */
1415 #define Chk_Abort chkabort
1419 void __regargs
__chkabort(void);
1421 void __regargs
__chkabort(void)
1433 * mch_expandpath() - this code does wild-card pattern matching using the arp
1436 * "pat" has backslashes before chars that are not to be expanded.
1437 * Returns the number of matches found.
1439 * This is based on WildDemo2.c (found in arp1.1 distribution).
1440 * That code's copyright follows:
1441 * Copyright (c) 1987, Scott Ballantyne
1442 * Use and abuse as you please.
1446 # define ANCHOR_BUF_SIZE 1024
1448 # define ANCHOR_BUF_SIZE (512)
1449 # define ANCHOR_SIZE (sizeof(struct AnchorPath) + ANCHOR_BUF_SIZE)
1453 mch_expandpath(gap
, pat
, flags
)
1456 int flags
; /* EW_* flags */
1458 struct AnchorPath
*Anchor
;
1460 char_u
*starbuf
, *sp
, *dp
;
1464 struct TagItem AnchorTags
[] = {
1465 {ADO_Strlen
, ANCHOR_BUF_SIZE
},
1466 {ADO_Flags
, APF_DODOT
|APF_DOWILD
|APF_MultiAssigns
},
1471 start_len
= gap
->ga_len
;
1473 /* Get our AnchorBase */
1475 Anchor
= AllocDosObject(DOS_ANCHORPATH
, AnchorTags
);
1477 Anchor
= (struct AnchorPath
*)alloc_clear((unsigned)ANCHOR_SIZE
);
1482 #ifndef __amigaos4__
1483 Anchor
->ap_Strlen
= ANCHOR_BUF_SIZE
; /* ap_Length not supported anymore */
1485 Anchor
->ap_Flags
= APF_DODOT
| APF_DOWILD
; /* allow '.' for current dir */
1487 Anchor
->ap_Flags
= APF_DoDot
| APF_DoWild
; /* allow '.' for current dir */
1495 /* hack to replace '*' by '#?' */
1496 starbuf
= alloc((unsigned)(2 * STRLEN(pat
) + 1));
1497 if (starbuf
== NULL
)
1499 for (sp
= pat
, dp
= starbuf
; *sp
; ++sp
)
1510 Result
= MatchFirst((UBYTE
*)starbuf
, Anchor
);
1515 Result
= FindFirst((char *)pat
, Anchor
);
1519 * Loop to get all matches.
1524 addfile(gap
, (char_u
*)Anchor
->ap_Buffer
, flags
);
1526 addfile(gap
, (char_u
*)Anchor
->ap_Buf
, flags
);
1531 Result
= MatchNext(Anchor
);
1534 Result
= FindNext(Anchor
);
1537 matches
= gap
->ga_len
- start_len
;
1539 if (Result
== ERROR_BUFFER_OVERFLOW
)
1540 EMSG(_("ANCHOR_BUF_SIZE too small."));
1541 else if (matches
== 0 && Result
!= ERROR_OBJECT_NOT_FOUND
1542 && Result
!= ERROR_DEVICE_NOT_MOUNTED
1543 && Result
!= ERROR_NO_MORE_ENTRIES
)
1544 EMSG(_("I/O ERROR"));
1547 * Sort the files for this pattern.
1550 qsort((void *)(((char_u
**)gap
->ga_data
) + start_len
),
1551 (size_t)matches
, sizeof(char_u
*), sortcmp
);
1553 /* Free the wildcard stuff */
1560 FreeAnchorChain(Anchor
);
1565 FreeDosObject(DOS_ANCHORPATH
, Anchor
);
1577 char *s
= *(char **)a
;
1578 char *t
= *(char **)b
;
1580 return pathcmp(s
, t
, -1);
1584 * Return TRUE if "p" has wildcards that can be expanded by mch_expandpath().
1587 mch_has_exp_wildcard(p
)
1590 for ( ; *p
; mb_ptr_adv(p
))
1592 if (*p
== '\\' && p
[1] != NUL
)
1594 else if (vim_strchr((char_u
*)"*?[(#", *p
) != NULL
)
1604 for ( ; *p
; mb_ptr_adv(p
))
1606 if (*p
== '\\' && p
[1] != NUL
)
1609 if (vim_strchr((char_u
*)
1610 # ifdef VIM_BACKTICK
1616 || (*p
== '~' && p
[1] != NUL
))
1623 * With AmigaDOS 2.0 support for reading local environment variables
1625 * Two buffers are allocated:
1626 * - A big one to do the expansion into. It is freed before returning.
1627 * - A small one to hold the return value. It is kept until the next call.
1634 UBYTE
*buf
; /* buffer to expand in */
1635 char_u
*retval
; /* return value */
1636 static char_u
*alloced
= NULL
; /* allocated memory */
1640 retval
= (char_u
*)getenv((char *)var
);
1648 buf
= alloc(IOSIZE
);
1652 len
= GetVar((UBYTE
*)var
, buf
, (long)(IOSIZE
- 1), (long)0);
1655 retval
= vim_strsave((char_u
*)buf
);
1662 /* if $VIM is not defined, use "vim:" instead */
1663 if (retval
== NULL
&& STRCMP(var
, "VIM") == 0)
1664 retval
= (char_u
*)"vim:";
1670 * Amiga version of setenv() with AmigaDOS 2.0 support.
1674 mch_setenv(var
, value
, x
)
1681 return setenv(var
, value
);
1684 if (SetVar((UBYTE
*)var
, (UBYTE
*)value
, (LONG
)-1, (ULONG
)GVF_LOCAL_ONLY
))
1685 return 0; /* success */
1686 return -1; /* failure */