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