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