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