annotate src/os_riscos.c @ 1270:d9d524594fe5

updated for version 7.1
author vimboss
date Sat, 12 May 2007 14:57:31 +0000
parents b526e10493b1
children 85a99ba3eb5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * os_riscos.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * Thomas Leonard <tal197@ecs.soton.ac.uk>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 const char *__dynamic_da_name = "Vim heap"; /* Enable and name our dynamic area */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 int ro_line_mode = TRUE; /* For Ex mode we much echo chars to the screen ourselves */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 int windowed; /* Flag - are we running inside a text window? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 int WinLeft, WinTop; /* We might be started inside a text window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 int ScrollTop; /* Make cursor movements relative to ScrollTop. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 int old_escape_state = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 int old_cursor_state = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #define rgb(r,g,b) ((b<<24) + (g<<16) + (r<<8))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 #define NORMAL_FG 0x00000000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #define NORMAL_BG 0xffffffff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 /* Convert a DOS colour number to an RGB palette entry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * Mappings from X11 rgb/txt file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 map_colour(dos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 int dos; /* Standard DOS colour number. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 switch (dos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 case 0: return 0; /* Black */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 case 1: return rgb(0,0,139); /* DarkBlue */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 case 2: return rgb(0,100,0); /* DarkGreen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 case 3: return rgb(0,139,139); /* DarkCyan */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 case 4: return rgb(139,0,0); /* DarkRed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 case 5: return rgb(139,0,139); /* DarkMagenta */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 case 6: return rgb(165,42,42); /* Brown, DarkYellow */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 case 7: return rgb(211,211,211); /* LightGray, LightGrey, Gray, Grey */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 case 8: return rgb(169,169,169); /* DarkGray, DarkGrey */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 case 9: return rgb(173,216,230); /* Blue, LightBlue */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 case 10: return rgb(144,238,144); /* Green, LightGreen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 case 11: return rgb(224,255,255); /* Cyan, LightCyan */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 case 12: return rgb(255,0,0); /* Red, LightRed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 case 13: return rgb(255,0,255); /* Magenta, LightMagenta */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 case 14: return rgb(255,255,0); /* Yellow, LightYellow */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 case 15: return rgb(255,255,255); /* White */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 return rgb(100,100,100);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 text_fg(fg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 int fg; /* Foregound colour in the form &BBGGRR00 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 xswi(ColourTrans_SetTextColour, fg, 0, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 text_bg(bg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 int bg; /* Backgound colour in the form &BBGGRR00 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 xswi(ColourTrans_SetTextColour, bg, 0, 0, 1 << 7);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 #define OUT_NORMAL 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #define OUT_NUMBER 1 /* Reading in a number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 mch_write(s, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 static int mode = OUT_NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 static int x, y; /* For reading numbers in. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 if (!term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 /* Maybe we are running Vim remotely - don't interpret chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 while (len--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 char_u c = *s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 swi(OS_WriteC, c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 /* We might need to send a CR too. This shouldn't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 * hurt if we don't need it, should it?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 if (c == 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 swi(OS_WriteI + 13);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 while (len--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 char_u c = *s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 switch (mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 case OUT_NUMBER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 if (c < '0' || c > '9')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 mode = OUT_NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 x = (x * 10) + c - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 /* note: no break here! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 case OUT_NORMAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 case 1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 /* Number (in decimal) follows. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 mode = OUT_NUMBER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 y = x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 x = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 case 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 /* Position cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 swi(OS_WriteI + 31);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 swi(OS_WriteC, x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 swi(OS_WriteC, y - ScrollTop);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 case 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 /* Set scroll region. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 if (x == Rows -1 && y == 0 && !windowed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 /* Whole screen - remove text window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 * This is MUCH faster.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 swi(OS_WriteI + 26);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 /* Create a text window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 swi(OS_WriteI + 28);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 swi(OS_WriteC, WinLeft);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 swi(OS_WriteC, WinTop + x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 swi(OS_WriteC, WinLeft + Columns - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 swi(OS_WriteC, WinTop + y);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 ScrollTop = y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 case 4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 /* Normal mode. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 text_fg(NORMAL_FG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 text_bg(NORMAL_BG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 case 5:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 /* Reverse mode. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 text_fg(NORMAL_BG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 text_bg(NORMAL_FG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 case 10:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 swi(OS_NewLine);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 case 14:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 /* Cursor invisible. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 swi(OS_WriteN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 "\027\001\000\000\000\000\000\000\000\000",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 case 15:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 /* Cursor visible. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 swi(OS_WriteN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 "\027\001\002\000\000\000\000\000\000\000",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 case 16:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 /* Cursor very visible (flash) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 swi(OS_WriteN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 "\027\001\003\000\000\000\000\000\000\000",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 case 17:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 /* Set foreground colour. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 text_fg(map_colour(x));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 case 18:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 /* Set background colour. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 text_bg(map_colour(x));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 case 19:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 /* Scroll text down. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 swi(OS_WriteN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 "\027\007\000\002\000\000\000\000\000\000",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 swi(OS_WriteC, c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 printf("[output error]");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 mode = OUT_NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 * mch_inchar(): low level input funcion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 * Get a characters from the keyboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 * Return the number of characters that are available.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 * If wtime == 0 do not wait for characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 * If wtime == n wait n msecs for characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 * If wtime == -1 wait forever for characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 * TODO: call convert_input() for 'fileencoding' to 'encoding' conversion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 mch_inchar(buf, maxlen, wtime, tb_change_cnt)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 int maxlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 long wtime;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 int tb_change_cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 int got=0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 unsigned int start_time = clock();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 if (ro_line_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 /* We're probably in Ex mode - get whole lines at a time. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 static char_u line_buffer[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 static int remaining_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 static int buf_pos = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 /* Do we need to fetch another line? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 if (remaining_chars == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 int old_esc_state;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 swi(OS_Byte, 200, 1, 0xfe);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 old_esc_state = r1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 buf_pos = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 if (xswi(OS_ReadLine, line_buffer, 255, 0, 255) & (c_flag | v_flag))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 got_int = TRUE; /* ESC pressed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 r1 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 line_buffer[r1] = 13;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 remaining_chars = r1 + 1; /* Count CR as part of input */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 swi(OS_Byte, 200, old_esc_state, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 /* Can we send the rest of the buffer back in one go? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 if (remaining_chars <= maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 int got = remaining_chars;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 memcpy(buf, line_buffer + buf_pos, got);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 remaining_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 return got;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 /* Send as much as we can */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 memcpy(buf, line_buffer + buf_pos, maxlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 buf_pos += maxlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 remaining_chars -= maxlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 return maxlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 if (!term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 /* Use OS_ReadC for all input.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 * Avoids problems with remote access getting interference from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 * the keyboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 if (wtime == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 return 0; /* Ignore quick key checks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 if (xswi(OS_ReadC) & c_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 got_int = TRUE; /* ESC pressed - can this happen? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 swi(OS_Byte, 124); /* Clear Escape state */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 r0 = 0x1b; /* It *might* not have been Escape! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 buf[0] = r0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 * OK, here's the plan:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 * 1) Wait until wtime expires or we get a key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 * 2) Get keys until the keyboard buffer is empty or buf is full
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 while (xswi(OS_Byte,145,0) & c_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 /* Nothing at all in the keyboard buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 * Has our time expired yet?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 if ( (wtime != -1) && (clock() - start_time) >= wtime )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 return 0; /* Nothing read - giving up */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 /* We've got one char (in r2) - are there any more? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 while (got < maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 buf[got++] = r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 if (xswi(OS_Byte,145,0) & c_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 return got; /* Keyboard buffer empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 return got; /* buf is full */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 * return non-zero if a character is available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 mch_char_avail()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 if (!term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 return 0; /* Can't tell */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 if (xswi(OS_Byte, 152, 0) & c_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 /* Find out how much free memory we have.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 * I don't know how to work this out exactly but, since we can claim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 * more memory from the OS, let's just report the free pool size.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 * Dynamic area 6 doesn't exist pre 3.6 according to StrongHelp, so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 * we'll use Wimp_SlotSize. If that fails (outside the desktop?)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 * then just return a big number and hope.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 long_u
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 mch_avail_mem(special)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 int special;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 if (xswi(Wimp_SlotSize, -1, -1) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 return 0x7fffffff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 return r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 mch_delay(msec, ignoreinput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 long msec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 int ignoreinput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 int start_time, time_now;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 int csec = msec / 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 swi(OS_ReadMonotonicTime);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 start_time = r0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 swi(OS_ReadMonotonicTime);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 time_now = r0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 if (time_now - start_time > csec)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 /* In the GUI, allow other programs to run while waiting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 gui_mch_wait_for_chars(start_time + csec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 * If the machine has job control, use it to suspend the program,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 * otherwise fake it by starting a new shell.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 mch_suspend()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 suspend_shell();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 mch_init()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 * Read window size first. Calls to mch_get_shellsize() will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 * simply return these values in future so that setting the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 * text window (used for scrolling) won't give strange results.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 int buf[7] = {132, 135, 256, 257, 1, 2, -1};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 /* Command windows are no longer forced open, since if we are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 * in the desktop then we'll use the GUI version.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 * Opening a command window here messes up the GUI version startup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 #ifndef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 swi(OS_WriteI);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 swi(OS_ReadVduVariables, buf, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 WinLeft = buf[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 WinTop = buf[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 Columns = buf[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 Rows = buf[3] + 1; /* Seems to be one off (VduVars wrong?) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 ScrollTop = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 /* Are we running in a textwindow? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 if (Rows == buf[5] + 1 && Columns == buf[4] + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 windowed = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 windowed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 /* Choose a nice colour scheme. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 text_fg(NORMAL_FG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 text_bg(NORMAL_BG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 * Check_win checks whether we have an interactive stdout.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 mch_check_win(argc, argv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 int argc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 char **argv;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 * Return TRUE if the input comes from a terminal, FALSE otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 mch_input_isatty()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 if (xswi(OS_ChangeRedirection, -1, -1) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 return TRUE; /* Error - TRUE is probably correct though */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 if (r0 == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 #ifdef FEAT_TITLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 mch_can_restore_title()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 mch_can_restore_icon()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 * Set the window title and icon.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 mch_settitle(title, icon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 char_u *title;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 char_u *icon;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 if (title == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 title = (char_u *) "<untitled>";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 if (gui.in_use && strcmp(title, gui.window_title))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 int length;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 length = strlen(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 if (length >= gui.window_title_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 length = gui.window_title_size - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 strncpy(gui.window_title, title, length);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 gui.window_title[length] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 ro_redraw_title(gui.window_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 * Restore the window/icon title.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 * "which" is one of:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 * 1 only restore title
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 * 2 only restore icon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 * 3 restore title and icon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 mch_restore_title(which)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 int which;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 * Insert user name in s[len].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 * Return OK if a name found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 mch_get_user_name(s, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 /* RISC OS doesn't support user names. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 *s = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 * Insert host name in s[len].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 mch_get_host_name(s, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 if (xswi(OS_ReadVarVal, "Machine$Name", s, len, 0, 3) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 /* Variable does not exist (normal operation) */
416
3da34f87c760 updated for version 7.0109
vimboss
parents: 35
diff changeset
526 vim_strncpy(s, "(unknown)", len - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 * return process ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 mch_get_pid()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 if (xswi(Wimp_ReadSysInfo, 5) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 return r0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 * Get name of current directory into buffer 'buf' of length 'len' bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 * Return OK for success, FAIL for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 mch_dirname(buf, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 if (xswi(OS_FSControl, 37, "@", buf, 0, 0, len) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 * Get absolute file name into buffer 'buf' of length 'len' bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 * return FAIL for failure, OK for success
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 mch_FullName(fname, buf, len, force)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 char_u *fname, *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 int force; /* Also expand when already absolute path name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 * Not used under RISC OS.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 if (xswi(OS_FSControl, 37, fname, buf, 0, 0, len) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 * Return TRUE if "fname" does not depend on the current directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 mch_isFullName(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 if (strstr(fname, "::") && strstr(fname,".$."))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 * Get file permissions for 'name'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 * Returns -1 when it doesn't exist.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 mch_getperm(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 struct stat statb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 if (stat((char *)name, &statb))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 return statb.st_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 * set file permission for 'name' to 'perm'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 mch_setperm(name, perm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 long perm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 return (chmod((char *)name, (mode_t)perm) == 0 ? OK : FAIL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 * Set hidden flag for "name".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 mch_hide(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 /* can't hide a file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 * return TRUE if "name" is a directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 * return FALSE if "name" is not a directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 * return FALSE for error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 mch_isdir(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 if (xswi(OS_File, 17, name) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 if (r0 == 2 || r0 == 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 return TRUE; /* Count image files as directories. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 * Return 1 if "name" can be executed, 0 if not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 * Return -1 if unknown. Requires which to work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 mch_can_exe(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 buf = alloc((unsigned)STRLEN(name) + 7);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 sprintf((char *)buf, "which %s", name);
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 7
diff changeset
656 p = get_cmd_output(buf, NULL, SHELL_SILENT);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 /* result can be: "name: Command not found" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 retval = (*p != NUL && strstr((char *)p, "not found") == NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 * Check what "name" is:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 * NODE_NORMAL: file or directory (or doesn't exist)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 * NODE_WRITABLE: writable device, socket, fifo, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 * NODE_OTHER: non-writable things
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 mch_nodetype(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 /* TODO */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 return NODE_NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 mch_early_init()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 /* Turn off all the horrible filename munging in UnixLib. */
35
8f3a526c2fe1 updated for version 7.0021
vimboss
parents: 24
diff changeset
684 int __riscosify_control = __RISCOSIFY_NO_PROCESS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 mch_exit(r)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 int r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 settmode(TMODE_COOK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 exiting = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 ml_close_all(TRUE); /* remove all memfiles */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 gui_exit(r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 swi(OS_NewLine);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 if (old_escape_state != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 swi(OS_Byte, 229, old_escape_state, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 if (old_cursor_state != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 swi(OS_Byte, 4, old_cursor_state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 exit(r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 mch_settmode(tmode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 int tmode; /* TMODE_RAW or TMODE_COOK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 if (tmode == TMODE_COOK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 ro_line_mode = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 ro_line_mode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 if (term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 /* Block cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 swi(OS_WriteN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 "\027\000\012\000\000\000\000\000\000\000",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 /* Disable the standard cursor key actions. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 swi(OS_Byte, 4, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 if (old_cursor_state == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 old_cursor_state = r1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 /* Stop Escape from quitting Vim! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 swi(OS_Byte, 229, 1, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 if (old_escape_state == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 old_escape_state = r1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 * set mouse clicks on or off (only works for xterms)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 mch_setmouse(on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 int on;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 * set screen mode, always fails.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 mch_screenmode(arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 char_u *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 {
35
8f3a526c2fe1 updated for version 7.0021
vimboss
parents: 24
diff changeset
756 EMSG(_(e_screenmode));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 * Try to get the current window size.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 * Return OK when size could be determined, FAIL otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 * Simply return results stored by mch_init() if we are the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 * machine's console. If not, we don't know how big the screen is.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 mch_get_shellsize()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 /* if size changed: screenalloc will allocate new screen buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 return term_console ? OK : FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 * Can't change the size.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 * Assume the user knows what he's doing and use the new values.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 mch_set_shellsize()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 /* Assume the user knows what he's doing and use the new values. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 * Rows and/or Columns has changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 mch_new_shellsize()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 /* Nothing to do. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 mch_call_shell(cmd, options)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 char_u *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 int options; /* SHELL_*, see vim.h */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 int tmode = cur_tmode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 if (cmd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 cmd = (char_u *) "GOS";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 return gui_mch_call_shell(cmd, options);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 if (options & SHELL_COOKED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 settmode(TMODE_COOK); /* set to normal mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 MSG_PUTS("\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 /* I don't even want to think about what UnixLib must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 * be doing to allow this to work...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 retval = system(cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 if (retval && !(options & SHELL_SILENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 EMSG(strerror(EOPSYS)); /* Doesn't seem to set errno? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 swi(OS_Byte, 229, 1, 0); /* Re-disable escape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 if (tmode == TMODE_RAW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 settmode(TMODE_RAW); /* set to raw mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 return retval ? FAIL : OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 * Check for Escape being pressed right now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 * [ different if !term_console? ]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 mch_breakcheck()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 if (xswi(OS_Byte, 121, 0xf0) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 if (r1 == 0xff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 got_int = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 swi(OS_Byte, 15, 1); /* Flush input buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 * Recursively expand one path component into all matching files and/or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 * directories.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 * "path" has backslashes before chars that are not to be expanded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 * Return the number of matches found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 mch_expandpath(gap, path, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 garray_T *gap; /* Grow array for results. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 char_u *path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 int flags; /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 int got; /* Number of matches. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 char_u *pattern;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 /* Plan:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 * 1) Get first part of path - no wildcards
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 * 2) Get next path element (wildcarded)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 * 3) Get rest of path
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 * If (3) is nothing then only the leaf is wildcarded - add to gap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 * Otherwise call recursively for each path in (2), passing (3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 * This is just the header function.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 /* We must be able to modifiy path, so make a copy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 pattern = vim_strsave(path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 if (pattern == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 got = expand_section(gap, (char_u *)"", pattern, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 vim_free(pattern);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 return got;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 * expand_section(gap, "$.Dir1.Dir2", "ABBA*.myleaf##")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 * calls expand_section(gap, "$.Dir1.Dir2.ABBA_Gold", "myleaf##")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 * and expand_section(gap, "$.Dir1.Dir2.ABBA_Live", "myleaf##")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 * If rest is just a leaf then all matches are added to gap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 * Returns number of items added to gap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 expand_section(gap, root, rest, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 garray_T *gap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 char_u *root; /* Non-wildcarded path to search */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 char_u *rest; /* Wildcarded remainder of path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 int flags; /* Add dirs/files/missing objects. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 static char_u buf[MAXPATHL]; /* Temporary buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 char_u dir[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 int start_element = -1; /* Start of wildcarded element */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 char_u c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 int got, dir_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 int buflen; /* Chars used in buf[] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 int colon = 0; /* Dir ends in ':' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 buflen = strlen(root);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 STRNCPY(buf, root, buflen); /* Copy root into buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 * Find end of nonwildcarded section.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 * Count ':' as a path sep since Vim:Bug* is a valid pathname.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 for (i = 0; c = rest[i]; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 if (c == PATHSEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 start_element = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 colon = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 if (c == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 start_element = i + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 colon = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 if (c == '#' || c == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 if (c == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 start_element = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 * start_element +> terminator for non-wildcarded section.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 * Transfer this bit into buf.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 if (buflen + start_element + 4 >= MAXPATHL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 return 0; /* Buffer full */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 if (start_element >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 if (*root && !colon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 buf[buflen++] = PATHSEP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 strncpy(buf + buflen, rest, start_element);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 buflen += start_element;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 buf[buflen] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 * Did we reach the end of the string without hitting any wildcards?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 if (c == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 /* Yes - add combined path to grow array and return. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 addfile(gap, buf, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 if (start_element < 0 || !colon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 start_element++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 rest += start_element;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 * rest does contain wildcards if we get here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 * Now : have we reached the leaf names part yet?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 * If so, add all matches (files and dirs) to gap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 * If not, get next path element and scan all matching directories.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 start_element = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 for (i = 0; rest[i]; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 if (rest[i] == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 start_element = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 rest[i] = 0; /* Break string here. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 /* If start_element is -1 then we are matching leaf names */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 r3 = 0; /* Number of objs read. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 dir_pos = 0; /* Position through directory. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 got = 0; /* Files added so far. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 while (dir_pos != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 buf[buflen] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 if (xswi(OS_GBPB, 9,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 buf, /* Directory to scan. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 buf + buflen + (1 - colon), /* Buffer for result. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 1, /* Number of objects to read. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 dir_pos, /* Search position. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 MAXPATHL - 2 - buflen, /* Size of result buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 rest) /* Wildcarded leafname. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 EMSG(r0 + 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 r4 = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 dir_pos = r4; /* r4 corrupted by addfile() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 if (r3 > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 char_u *path = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 if (buflen == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 path++; /* Don't do '.File' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 else if (!colon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 buf[buflen] = '.'; /* Join path and leaf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 /* Path -> full path of object found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 if (start_element == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 addfile(gap, path, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 got++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 /* Scan into subdirectories and images; ignore files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 swi(OS_File, 17, path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 if (r0 == 2 || r0 == 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 got += expand_section(gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 rest + start_element + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 /* Restore the dot if we removed it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 if (start_element >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 rest[start_element] = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 return got;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 * mch_expand_wildcards() - this code does wild-card pattern matching using
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 * the shell. It isn't used under RISC OS.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 * return OK for success, FAIL for error (you may lose some memory) and put
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 * an error message in *file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 * num_pat is number of input patterns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 * pat is array of pointers to input patterns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 * num_file is pointer to number of matched file names
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 * file is pointer to array of pointers to matched file names
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 mch_expand_wildcards(num_pat, pat, num_file, file, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 int num_pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 char_u **pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 int *num_file;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 char_u ***file;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 int flags; /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 /* This doesn't get called unless SPECIAL_WILDCHAR is defined. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 * Return TRUE if "p" contains wildcards which can be expanded by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 * mch_expandpath().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 mch_has_exp_wildcard(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 if (vim_strpbrk((char_u *)"*#", p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 /* Return TRUE if "p" contains wildcards. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 mch_has_wildcard(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 if (vim_strpbrk((char_u *)"*#`", p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 int /* see Unix unlink(2) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 mch_remove(file)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 char_u *file; /* Name of file to delete. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 if (xswi(OS_FSControl, 27, file, 0, 0) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 return EXIT_FAILURE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 return EXIT_SUCCESS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 /* Try to make existing scripts work without modification.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 * Return a pointer to the new string (freed by caller), or NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 * Two main cases:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 * - Absolute : $VIM/syntax/help.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 * - Relative : Adfs::4.$.!Vim.Resources.Syntax/help.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 mch_munge_fname(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 char_u c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 retval = fname = vim_strsave(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 if (strncmp(fname, "$VIM/", 5) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 strncpy(fname, "Vim:", 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 for (fname += 5; c = *fname; fname++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 if (c == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 if (c == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 fname[-1] = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 fname[-1] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 fname[-1] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 /* Check to see if the file exists without modification. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 if (xswi(OS_File, 17, fname) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 r0 == 0; /* Invalid filename? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 if (r0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 len = strlen(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 if (strcmp(fname + len - 4, ".vim") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 fname[len - 4] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 for (; c = *fname; fname++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 if (c == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 *fname = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 /* QuickFix reads munged names from the error file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 * Correct them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 ro_buflist_add(old_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 char_u *old_name; /* Name of file found by quickfix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 char_u *leaf; /* Pointer to start of leaf in old_name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 char_u c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 if (old_name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 return buflist_add(NULL, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 /* Copy the name so we can mess around with it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 fname = vim_strsave(old_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 /* Out of memory - can't modify name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 return buflist_add(old_name, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 /* Change `dir/main.c' into `dir.c.main' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 leaf = fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 for (ptr = fname; c = *ptr; ptr++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 if (c == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 leaf = ptr + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 *ptr = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 else if (c == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 if (c == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 /* Change `main.c' into `c.main'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 * | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 * leaf ptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 ptr += old_name - fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 *ptr = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 sprintf(leaf,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 "%s.%s",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 ptr + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 leaf - fname + old_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 retval = buflist_add(fname, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 free(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 /* Change the current directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 * Strip trailing dots to make it easier to use with filename completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 * Return 0 for success, -1 for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 mch_chdir(dir)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 char_u *dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 int length;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 char_u *new_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 length = strlen(dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 if (dir[length - 1] != '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 return chdir(dir); /* No trailing dots - nothing to do. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 new_dir = vim_strsave(dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 if (new_dir == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 return chdir(dir); /* Can't allocate memory. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 while (new_dir[--length] == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 new_dir[length] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 retval = chdir(new_dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 vim_free(new_dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 /* Examine the named file, and set the 'osfiletype' option
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 * (in curbuf) to the file's type.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 mch_read_filetype(file)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 char_u *file;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 int type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 char_u type_string[9];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 if (xswi(OS_File, 23, file) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 type = 0xfff; /* Default to Text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 type = r6;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 /* Type is the numerical value - see if we have a textual equivalent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 swi(OS_FSControl, 18, 0, type);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 ((int *) type_string)[0] = r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 ((int *) type_string)[1] = r3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 type_string[8] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 for (i = 0; type_string[i] > ' '; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 type_string[i] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 416
diff changeset
1246 set_string_option_direct("osfiletype", -1, type_string, OPT_FREE, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 mch_set_filetype(file, type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 char_u *file;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 char_u *type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 if (xswi(OS_FSControl, 31, type) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 EMSG(_("E366: Invalid 'osfiletype' option - using Text"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 r2 = 0xfff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 swi(OS_File, 18, file, r2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 /* Return TRUE if the file's type matches 'type'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 * RISC OS types always start with '&'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 mch_check_filetype(fname, type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 char_u *type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 int value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 char *end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 if (*type != '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 value = strtol(type + 1, &end, 16);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 if (*end)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 return FALSE; /* Invalid type (report error?) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 if (xswi(OS_File, 23, fname) & v_flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 return FALSE; /* Invalid filename? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 return (r0 && r6 == value);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 }