annotate src/os_amiga.c @ 491:21c3634c2113 v7.0134

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