annotate src/os_msdos.c @ 8184:1f81c571d0e7 v7.4.1385

commit https://github.com/vim/vim/commit/5e83840756f6bb446d5cd8d026c1430b203645f1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 21 23:12:41 2016 +0100 patch 7.4.1385 Problem: Compiler warning for using array. Solution: Use the right member name. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Sun, 21 Feb 2016 23:15:05 +0100
parents 563c923b1584
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * os_msdos.c
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * MSDOS system-dependent routines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 * A cheap plastic imitation of the amiga dependent code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * A lot in this file was made by Juergen Weigert (jw).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 * DJGPP changes by Gert van Antwerpen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * Faster text screens by John Lange (jlange@zilker.net)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 * Windows clipboard functionality added by David Kotchan (dk)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 * Some functions are also used for Win16 (MS-Windows 3.1).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3927
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
26 /* cproto fails on missing include files */
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
27 #ifndef PROTO
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
28 # include <conio.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
29 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3927
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
31 #ifndef PROTO
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
32 # include <bios.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
33 # ifdef DJGPP
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
34 # include <dpmi.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
35 # include <signal.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
36 # include <sys/movedata.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
37 # include <crt0.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
38 # ifdef FEAT_CLIPBOARD
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
39 # include <sys/segments.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
40 # endif
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
41 # else
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
42 # include <alloc.h>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 #if defined(DJGPP) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 # define _cdecl /* DJGPP doesn't have this */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 static int cbrk_pressed = FALSE; /* set by ctrl-break interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 static int ctrlc_pressed = FALSE; /* set when ctrl-C or ctrl-break detected */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 static int delayed_redraw = FALSE; /* set when ctrl-C detected */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 static int bioskey_read = _NKEYBRD_READ; /* bioskey() argument: read key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 static int bioskey_ready = _NKEYBRD_READY; /* bioskey() argument: key ready? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 static int mouse_avail = FALSE; /* mouse present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 static int mouse_active; /* mouse enabled */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 static int mouse_hidden; /* mouse not shown */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 static int mouse_click = -1; /* mouse status */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 static int mouse_last_click = -1; /* previous status at click */
1210
302520c08584 updated for version 7.1b
vimboss
parents: 799
diff changeset
63 static int mouse_x = -1; /* mouse x coordinate */
302520c08584 updated for version 7.1b
vimboss
parents: 799
diff changeset
64 static int mouse_y = -1; /* mouse y coordinate */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 static long mouse_click_time = 0; /* biostime() of last click */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 static int mouse_click_count = 0; /* count for multi-clicks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 static int mouse_click_x = 0; /* x of previous mouse click */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 static int mouse_click_y = 0; /* y of previous mouse click */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 static linenr_T mouse_topline = 0; /* w_topline at previous mouse click */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 static int mouse_topfill = 0; /* w_topfill at previous mouse click */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 static int mouse_x_div = 8; /* column = x coord / mouse_x_div */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 static int mouse_y_div = 8; /* line = y coord / mouse_y_div */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 #define BIOSTICK 55 /* biostime() increases one tick about
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 every 55 msec */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 static int orig_attr = 0x0700; /* video attributes when starting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 static int S_iLeft = 0; /* Scroll window; these are 1 offset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 static int S_iTop = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 static int S_iRight = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 static int S_iBottom = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 * Need to remember the values, because we set horizontal and vertical
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 * edges separately.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 mywindow(int iLeft, int iTop, int iRight, int iBottom)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 S_iLeft = iLeft;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 S_iTop = iTop;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 S_iRight = iRight;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 S_iBottom = iBottom;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 window(iLeft, iTop, iRight, iBottom);
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 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 * For DJGPP, use our own functions for fast text screens. JML 1/18/98
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 unsigned long S_ulScreenBase = 0xb8000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 unsigned short S_uiAttribute = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 int S_iCurrentRow = 0; /* These are 0 offset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 int S_iCurrentColumn = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 short S_selVideo; /* Selector for DJGPP direct video transfers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 * Use burst writes to improve mch_write speed - VJN 01/10/99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 unsigned short S_linebuffer[8000]; /* <VN> enough for 160x50 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 unsigned short S_blankbuffer[256]; /* <VN> max length of console line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 unsigned short *S_linebufferpos = S_linebuffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 int S_iBufferRow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 int S_iBufferColumn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 myflush(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 if (S_linebufferpos != S_linebuffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 _dosmemputw(S_linebuffer, (S_linebufferpos - S_linebuffer),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 S_ulScreenBase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 + S_iBufferRow * (Columns << 1) + (S_iBufferColumn << 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 S_linebufferpos = S_linebuffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 mygotoxy(int x, int y)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 S_iCurrentRow = y - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 S_iCurrentColumn = x - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 * Set the system cursor to our cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 set_sys_cursor(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 if (term_console && full_screen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 gotoxy(S_iCurrentColumn + 1, S_iCurrentRow + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 setblankbuffer(unsigned short uiValue)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 static unsigned short olduiValue = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 if (olduiValue != uiValue)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 /* Load blank line buffer with spaces */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 for (i = 0; i < Columns; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 S_blankbuffer[i] = uiValue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 olduiValue = uiValue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 myclreol(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 /* Clear to end of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 setblankbuffer(S_uiAttribute | ' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 _dosmemputw(S_blankbuffer, S_iRight - S_iCurrentColumn, S_ulScreenBase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 + (S_iCurrentRow) * (Columns << 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 + (S_iCurrentColumn << 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 myclrscr(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 /* Clear whole screen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 short iColumn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 int endpoint = (Rows * Columns) << 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 setblankbuffer(S_uiAttribute | ' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 for (iColumn = 0; iColumn < endpoint; iColumn += (Columns << 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 _dosmemputw(S_blankbuffer, Columns, S_ulScreenBase + iColumn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 mydelline(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 short iRow, iColumn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 iColumn = (S_iLeft - 1) << 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 /* Copy the lines underneath */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 for (iRow = S_iCurrentRow; iRow < S_iBottom - 1; iRow++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 movedata(S_selVideo, (((iRow + 1) * Columns) << 1) + iColumn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 S_selVideo, ((iRow * Columns) << 1) + iColumn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 (S_iRight - S_iLeft + 1) << 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 /* Clear the new row */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 setblankbuffer(S_uiAttribute | ' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 _dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 + (S_iBottom - 1) * (Columns << 1) + iColumn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 myinsline(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 short iRow, iColumn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 iColumn = (S_iLeft - 1) << 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 /* Copy the lines underneath */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 for (iRow = S_iBottom - 1; iRow >= S_iTop; iRow--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 movedata(S_selVideo, (((iRow - 1) * Columns) << 1) + iColumn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 S_selVideo, ((iRow * Columns) << 1) + iColumn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 (S_iRight - S_iLeft + 1) << 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 /* Clear the new row */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 setblankbuffer(S_uiAttribute | ' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 _dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 + (S_iTop - 1) * (Columns << 1) + iColumn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 * Scroll the screen one line up, clear the last line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 myscroll(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 short iRow, iColumn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 iColumn = (S_iLeft - 1) << 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 /* Copy the screen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 for (iRow = S_iTop; iRow < S_iBottom; iRow++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 movedata(S_selVideo, ((iRow * Columns) << 1) + iColumn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 S_selVideo, (((iRow - 1) * Columns) << 1) + iColumn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 (S_iRight - S_iLeft + 1) << 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 /* Clear the bottom row */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 setblankbuffer(S_uiAttribute | ' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 _dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 + (S_iBottom - 1) * (Columns << 1) + iColumn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 myputch(int iChar)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 unsigned short uiValue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 if (iChar == '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 if (S_iCurrentRow >= S_iBottom - S_iTop)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 myscroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 S_iCurrentColumn = S_iLeft - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 S_iCurrentRow++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 else if (iChar == '\r')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 S_iCurrentColumn = S_iLeft - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 else if (iChar == '\b')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 if (S_iCurrentColumn >= S_iLeft)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 S_iCurrentColumn--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 else if (iChar == 7)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 sound(440); /* short beep */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 delay(200);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 nosound();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 uiValue = S_uiAttribute | (unsigned char)iChar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 * Normal char - are we starting to buffer?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 if (S_linebufferpos == S_linebuffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 S_iBufferColumn = S_iCurrentColumn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 S_iBufferRow = S_iCurrentRow;
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 *S_linebufferpos++ = uiValue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 S_iCurrentColumn++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 if (S_iCurrentColumn >= S_iRight && S_iCurrentRow >= S_iBottom - S_iTop)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 myscroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 S_iCurrentColumn = S_iLeft - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 S_iCurrentRow++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 mytextinit(struct text_info *pTextinfo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 S_selVideo = __dpmi_segment_to_descriptor(S_ulScreenBase >> 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 S_uiAttribute = pTextinfo->normattr << 8;
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 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 get_screenbase(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 static union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 /* old Hercules grafic card has different base address (Macewicz) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 regs.h.ah = 0x0f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 (void)int86(0x10, &regs, &regs); /* int 10 0f */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 if (regs.h.al == 0x07) /* video mode 7 -- hercules mono */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 S_ulScreenBase = 0xb0000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 S_ulScreenBase = 0xb8000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 mytextattr(int iAttribute)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 S_uiAttribute = (unsigned short)iAttribute << 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 mynormvideo(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 mytextattr(orig_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 mytextcolor(int iTextColor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 S_uiAttribute = (unsigned short)((S_uiAttribute & 0xf000)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 | (unsigned short)iTextColor << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 mytextbackground(int iBkgColor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 S_uiAttribute = (unsigned short)((S_uiAttribute & 0x0f00)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 | (unsigned short)(iBkgColor << 12));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 * Getdigits: Get a number from a string and skip over it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 * Note: the argument is a pointer to a char_u pointer!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 static long
7842
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
367 mygetdigits(char_u **pp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 long retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 p = *pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 if (*p == '-') /* skip negative sign */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 while (VIM_ISDIGIT(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 retval = (retval * 10) + (*p - '0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 if (**pp == '-') /* process negative sign */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 retval = -retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 *pp = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 # define mygotoxy gotoxy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 # define myputch putch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 # define myscroll scroll
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 # define mynormvideo normvideo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 # define mytextattr textattr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 # define mytextcolor textcolor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 # define mytextbackground textbackground
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 # define mygetdigits getdigits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 # define myclreol clreol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 # define myclrscr clrscr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 # define myinsline insline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 # define mydelline delline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 static const struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 char_u scancode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 char_u metakey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 } altkey_table[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 {0x1e, 0xe1}, /* a */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 {0x30, 0xe2}, /* b */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 {0x2e, 0xe3}, /* c */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 {0x20, 0xe4}, /* d */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 {0x12, 0xe5}, /* e */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 {0x21, 0xe6}, /* f */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 {0x22, 0xe7}, /* g */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 {0x23, 0xe8}, /* h */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 {0x17, 0xe9}, /* i */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 {0x24, 0xea}, /* j */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 {0x25, 0xeb}, /* k */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 {0x26, 0xec}, /* l */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 {0x32, 0xed}, /* m */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 {0x31, 0xee}, /* n */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 {0x18, 0xef}, /* o */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 {0x19, 0xf0}, /* p */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 {0x10, 0xf1}, /* q */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 {0x13, 0xf2}, /* r */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 {0x1f, 0xf3}, /* s */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 {0x14, 0xf4}, /* t */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 {0x16, 0xf5}, /* u */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 {0x2f, 0xf6}, /* v */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 {0x11, 0xf7}, /* w */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 {0x2d, 0xf8}, /* x */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 {0x15, 0xf9}, /* y */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 {0x2c, 0xfa}, /* z */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 {0x78, 0xb1}, /* 1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 {0x79, 0xb2}, /* 2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 {0x7a, 0xb3}, /* 3 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 {0x7b, 0xb4}, /* 4 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 {0x7c, 0xb5}, /* 5 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 {0x7d, 0xb6}, /* 6 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 {0x7e, 0xb7}, /* 7 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 {0x7f, 0xb8}, /* 8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 {0x80, 0xb9}, /* 9 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 {0x81, 0xb0}, /* 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 };
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 * Translate extended keycodes into meta-chars where applicable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 translate_altkeys(int rawkey)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 int i, c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 if ((rawkey & 0xff) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 c = (rawkey >> 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 for (i = sizeof(altkey_table) / sizeof(altkey_table[0]); --i >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 if (c == altkey_table[i].scancode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 return (int)altkey_table[i].metakey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 return rawkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 /*
1210
302520c08584 updated for version 7.1b
vimboss
parents: 799
diff changeset
466 * Set normal fg/bg color, based on T_ME. Called when t_me has been set.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 void
7842
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
469 mch_set_normal_colors(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 cterm_normal_fg_color = (orig_attr & 0xf) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 cterm_normal_bg_color = ((orig_attr >> 4) & 0xf) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 if (T_ME[0] == ESC && T_ME[1] == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 p = T_ME + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 n = getdigits(&p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 if (*p == 'm' && n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 cterm_normal_fg_color = (n & 0xf) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 cterm_normal_bg_color = ((n >> 4) & 0xf) + 1;
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 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 #if defined(MCH_CURSOR_SHAPE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 * Save/restore the shape of the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 * call with FALSE to save, TRUE to restore
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 mch_restore_cursor_shape(int restore)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 static union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 static int saved = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 if (restore)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 if (saved)
36
125e80798a85 updated for version 7.0021
vimboss
parents: 9
diff changeset
502 regs.h.ah = 0x01; /* Set Cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 {
36
125e80798a85 updated for version 7.0021
vimboss
parents: 9
diff changeset
508 regs.h.ah = 0x03; /* Get Cursor */
125e80798a85 updated for version 7.0021
vimboss
parents: 9
diff changeset
509 regs.h.bh = 0x00; /* Page */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 saved = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 (void)int86(0x10, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 * Set the shape of the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 * 'thickness' can be from 0 (thin) to 7 (block)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 mch_set_cursor_shape(int thickness)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524
36
125e80798a85 updated for version 7.0021
vimboss
parents: 9
diff changeset
525 regs.h.ch = 7 - thickness; /* Starting Line */
125e80798a85 updated for version 7.0021
vimboss
parents: 9
diff changeset
526 regs.h.cl = 7; /* Ending Line */
125e80798a85 updated for version 7.0021
vimboss
parents: 9
diff changeset
527 regs.h.ah = 0x01; /* Set Cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 (void)int86(0x10, &regs, &regs);
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 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 mch_update_cursor(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 int thickness;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 * How the cursor is drawn depends on the current mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 idx = get_shape_idx(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 if (shape_table[idx].shape == SHAPE_BLOCK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 thickness = 7;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 thickness = (7 * shape_table[idx].percentage + 90) / 100;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 mch_set_cursor_shape(thickness);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 /*
3634
286ba0251c0a updated for version 7.3.577
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
551 * Return amount of memory currently available in Kbyte.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 long_u
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 mch_avail_mem(int special)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 #ifdef DJGPP
3634
286ba0251c0a updated for version 7.3.577
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
557 return _go32_dpmi_remaining_virtual_memory() >> 10;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 #else
3634
286ba0251c0a updated for version 7.3.577
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
559 return coreleft() >> 10;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 * Set area where mouse can be moved to: The whole screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 * Rows and Columns must be valid when calling!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 mouse_area(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 if (mouse_avail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 regs.x.cx = 0; /* mouse visible between cx and dx */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 regs.x.dx = Columns * mouse_x_div - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 regs.x.ax = 7;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 (void)int86(0x33, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 regs.x.cx = 0; /* mouse visible between cx and dx */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 regs.x.dx = Rows * mouse_y_div - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 regs.x.ax = 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 (void)int86(0x33, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 show_mouse(int on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 static int was_on = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 if (mouse_avail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 if (!mouse_active || mouse_hidden)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 on = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 * Careful: Each switch on must be compensated by exactly one switch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 * off
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 if ((on && !was_on) || (!on && was_on))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 was_on = on;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 regs.x.ax = on ? 1 : 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 int86(0x33, &regs, &regs); /* show mouse */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 if (on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 mouse_area();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 }
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 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 * Version of kbhit() and getch() that use direct console I/O.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 * This avoids trouble with CTRL-P and the like, and should work over a telnet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 * connection (it works for Xvi).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 static int cons_key = -1;
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 * Try to get one character directly from the console.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 * If there is a key, it is stored in cons_key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 * Only call when cons_key is -1!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 cons_getkey(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 /* call DOS function 6: Direct console I/O */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 regs.h.ah = 0x06;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 regs.h.dl = 0xff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 (void)intdos(&regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 if ((regs.x.flags & 0x40) == 0) /* zero flag not set? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 cons_key = (regs.h.al & 0xff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 * Return TRUE if a character is available.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 cons_kbhit(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 if (cons_key < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 cons_getkey();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 return (cons_key >= 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 * Return a character from the console.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 * Should only be called when vim_kbhit() returns TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 cons_getch(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 int c = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 if (cons_key < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 cons_getkey();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 c = cons_key;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 cons_key = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 * DJGPP provides a kbhit() function that goes to the BIOS instead of DOS.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 * This doesn't work for terminals connected to a serial port.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 * Redefine kbhit() here to make it work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 vim_kbhit(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 regs.h.ah = 0x0b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 (void)intdos(&regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 return regs.h.al;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 #ifdef kbhit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 # undef kbhit /* might have been defined in conio.h */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 #define kbhit() vim_kbhit()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 * Simulate WaitForChar() by slowly polling with bioskey(1) or kbhit().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 * If Vim should work over the serial line after a 'ctty com1' we must use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 * kbhit() and getch(). (jw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 * Usually kbhit() is not used, because then CTRL-C and CTRL-P
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
698 * will be caught by DOS (mool).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 * return TRUE if a character is available, FALSE otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 #define FOREVER 1999999999L
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 WaitForChar(long msec)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 long starttime = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 if (msec != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 starttime = biostime(0, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 long clicktime;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 static int old_status = 0;
799
6beb2c667935 updated for version 7.0b
vimboss
parents: 716
diff changeset
718 union REGS regs;
6beb2c667935 updated for version 7.0b
vimboss
parents: 716
diff changeset
719 int x, y;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 if (mouse_avail && mouse_active && mouse_click < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 regs.x.ax = 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 int86(0x33, &regs, &regs); /* check mouse status */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 /* only recognize button-down and button-up event */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 x = regs.x.cx / mouse_x_div;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 y = regs.x.dx / mouse_y_div;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 if ((old_status == 0) != (regs.x.bx == 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 if (old_status) /* button up */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 mouse_click = MOUSE_RELEASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 else /* button down */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 * Translate MSDOS mouse events to Vim mouse events.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 * TODO: should handle middle mouse button, by pressing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 * left and right at the same time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 if (regs.x.bx & MSDOS_MOUSE_LEFT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 mouse_click = MOUSE_LEFT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 else if (regs.x.bx & MSDOS_MOUSE_RIGHT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 mouse_click = MOUSE_RIGHT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 else if (regs.x.bx & MSDOS_MOUSE_MIDDLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 mouse_click = MOUSE_MIDDLE;
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 * Find out if this is a multi-click
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 clicktime = biostime(0, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 if (mouse_click_x == x && mouse_click_y == y
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 && mouse_topline == curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 && mouse_topfill == curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 && mouse_click_count != 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 && mouse_click == mouse_last_click
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 && clicktime < mouse_click_time
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 + p_mouset / BIOSTICK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 ++mouse_click_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 mouse_click_count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 mouse_click_time = clicktime;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 mouse_last_click = mouse_click;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 mouse_click_x = x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 mouse_click_y = y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 mouse_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 mouse_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 SET_NUM_MOUSE_CLICKS(mouse_click, mouse_click_count);
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 else if (old_status && (x != mouse_x || y != mouse_y))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 mouse_click = MOUSE_DRAG;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 old_status = regs.x.bx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 if (mouse_hidden && mouse_x >= 0 && (mouse_x != x || mouse_y != y))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 mouse_hidden = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 show_mouse(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 mouse_x = x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 mouse_y = y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 if ((p_consk ? cons_kbhit()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 : p_biosk ? bioskey(bioskey_ready) : kbhit())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 || cbrk_pressed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 || mouse_click >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 * Use biostime() to wait until our time is done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 * We busy-wait here. Unfortunately, delay() and usleep() have been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 * reported to give problems with the original Windows 95. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 * fixed in service pack 1, but not everybody installed that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 * The DJGPP implementation of usleep() uses a busy-wait loop too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 if (msec == 0 || (msec != FOREVER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 && biostime(0, 0L) > starttime + msec / BIOSTICK))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 /* Yield the CPU to the next process. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 __dpmi_yield();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 * don't do anything for about "msec" msec
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 mch_delay(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 long msec,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 int ignoreinput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 long starttime;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 if (ignoreinput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 * We busy-wait here. Unfortunately, delay() and usleep() have been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 * reported to give problems with the original Windows 95. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 * fixed in service pack 1, but not everybody installed that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 starttime = biostime(0, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 while (biostime(0, 0L) < starttime + msec / BIOSTICK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 WaitForChar(msec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 }
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 * mch_write(): write the output buffer to the screen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 mch_write(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 char_u *s,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 int len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 int row, col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 if (term_console && full_screen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 while (len--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 /* translate ESC | sequences into bios calls */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 if (p_wd) /* testing: wait a bit for each char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 WaitForChar(p_wd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 if (s[0] == '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 S_iCurrentColumn = S_iLeft - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 myputch('\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 else if (s[0] == ESC && len > 1 && s[1] == '|')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 switch (s[2])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 case 'B': ScreenVisualBell();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 goto got3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 case 'J':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 myclrscr();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 goto got3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 case 'K':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 myclreol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 goto got3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 case 'L':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 myinsline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 goto got3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 case 'M':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 mydelline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 got3: s += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 len -= 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 case '0':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 case '1':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 case '2':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 case '3':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 case '4':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 case '5':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 case '6':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 case '7':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 case '8':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 case '9': p = s + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 row = mygetdigits(&p); /* no check for length! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 if (p > s + len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 if (*p == ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 col = mygetdigits(&p); /* no check for length! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 if (p > s + len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 if (*p == 'H' || *p == 'r' || *p == 'V')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 myflush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 if (*p == 'H') /* set cursor position */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 mygotoxy(col, row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 else if (*p == 'V')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 mywindow(row, S_iTop, col, S_iBottom);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 else /* set scroll region */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 mywindow(S_iLeft, row, S_iRight, col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 len -= p - s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 s = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 else if (*p == 'm' || *p == 'f' || *p == 'b')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 if (*p == 'm') /* set color */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 if (row == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 mynormvideo();/* reset color */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 mytextattr(row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 else if (*p == 'f') /* set foreground color */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 mytextcolor(row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 else /* set background color */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 mytextbackground(row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 len -= p - s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 s = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 }
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 myputch(*s++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 write(1, s, (unsigned)len);
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 /*
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
967 * mch_inchar(): low level input function.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 * Get a characters from the keyboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 * If time == 0 do not wait for characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 * If time == n wait a short time for characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 * If time == -1 wait forever for characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 * return the number of characters obtained
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 mch_inchar(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 char_u *buf,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 int maxlen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 long time,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 int tb_change_cnt)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 int len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 int tmp_c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 static int nextchar = 0; /* may keep character when maxlen == 1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 * if we got a ctrl-C when we were busy, there will be a "^C" somewhere
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
989 * on the screen, so we need to redisplay it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 if (delayed_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 delayed_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 update_screen(CLEAR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 /* return remaining character from last call */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 if (nextchar)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 *buf = nextchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 nextchar = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 if (time != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 show_mouse(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 set_sys_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 if (time >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 if (WaitForChar(time) == 0) /* no character available */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 show_mouse(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 return 0;
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 else /* time == -1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 * If there is no character available within 2 seconds (default)
212
e39657bbbb98 updated for version 7.0060
vimboss
parents: 39
diff changeset
1028 * write the autoscript file to disk. Or cause the CursorHold event
e39657bbbb98 updated for version 7.0060
vimboss
parents: 39
diff changeset
1029 * to be triggered.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 */
212
e39657bbbb98 updated for version 7.0060
vimboss
parents: 39
diff changeset
1031 if (WaitForChar(p_ut) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 #ifdef FEAT_AUTOCMD
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 418
diff changeset
1034 if (trigger_cursorhold() && maxlen >= 3)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 {
212
e39657bbbb98 updated for version 7.0060
vimboss
parents: 39
diff changeset
1036 buf[0] = K_SPECIAL;
e39657bbbb98 updated for version 7.0060
vimboss
parents: 39
diff changeset
1037 buf[1] = KS_EXTRA;
e39657bbbb98 updated for version 7.0060
vimboss
parents: 39
diff changeset
1038 buf[2] = (int)KE_CURSORHOLD;
e39657bbbb98 updated for version 7.0060
vimboss
parents: 39
diff changeset
1039 return 3;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 #endif
370
3a21825ad207 updated for version 7.0095
vimboss
parents: 212
diff changeset
1042 before_blocking();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 WaitForChar(FOREVER); /* wait for key or mouse click */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 * Try to read as many characters as there are, until the buffer is full.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 * we will get at least one key. Get more if they are available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 * After a ctrl-break we have to read a 0 (!) from the buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 * bioskey(1) will return 0 if no key is available and when a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 * ctrl-break was typed. When ctrl-break is hit, this does not always
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 * implies a key hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 cbrk_pressed = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 if (mouse_click >= 0 && maxlen >= 5)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 len = 5;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 *buf++ = ESC + 128;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 *buf++ = 'M';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 *buf++ = mouse_click;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 *buf++ = mouse_x + '!';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 *buf++ = mouse_y + '!';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 mouse_click = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 mouse_hidden = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 if (p_biosk && !p_consk)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 while ((len == 0 || bioskey(bioskey_ready)) && len < maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 c = translate_altkeys(bioskey(bioskey_read)); /* get the key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 * translate a few things for inchar():
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 * 0x0000 == CTRL-break -> 3 (CTRL-C)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 * 0x0300 == CTRL-@ -> NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 * 0xnn00 == extended key code -> K_NUL, nn
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 * 0xnne0 == enhanced keyboard -> K_NUL, nn
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 * K_NUL -> K_NUL, 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 if (c == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 c = 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 else if (c == 0x0300)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 c = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 else if ((c & 0xff) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 || c == K_NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 || c == 0x4e2b
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 || c == 0x4a2d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 || c == 0x372a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 || ((c & 0xff) == 0xe0 && c != 0xe0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 if (c == K_NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 c = 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 c >>= 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 *buf++ = K_NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 if (len < maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 *buf++ = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 len++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 /* Convert from 'termencoding' to 'encoding'. Only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 * translate normal characters, not key codes. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 if (input_conv.vc_type != CONV_NONE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 && (len == 1 || buf[-2] != K_NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 len += convert_input(buf - 1, 1, maxlen - len + 1) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 #endif
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 nextchar = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 while ((len == 0 || (p_consk ? cons_kbhit() : kbhit()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 && len < maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 switch (c = (p_consk ? cons_getch() : getch()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 case 0:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 /* NUL means that there is another character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 * Get it immediately, because kbhit() doesn't always
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 * return TRUE for the second character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 if (p_consk)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 c = cons_getch();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 c = getch();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 tmp_c = translate_altkeys(c << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 if (tmp_c == (c << 8))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 *buf++ = K_NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 c = tmp_c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 case K_NUL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 *buf++ = K_NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 c = 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 case 3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 cbrk_pressed = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 if (len < maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 *buf++ = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 ++len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 nextchar = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 show_mouse(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 beep_count = 0; /* may beep again now that we got some chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 * return non-zero if a character is available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 mch_char_avail(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 return WaitForChar(0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 # define INT_ARG int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 # define INT_ARG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 * function for ctrl-break interrupt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 static void interrupt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 catch_cbrk(int a)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 catch_cbrk(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 cbrk_pressed = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 ctrlc_pressed = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 #ifndef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 * ctrl-break handler for DOS. Never called when a ctrl-break is typed, because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 * we catch interrupt 1b. If you type ctrl-C while Vim is waiting for a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 * character this function is not called. When a ctrl-C is typed while Vim is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 * busy this function may be called. By that time a ^C has been displayed on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 * the screen, so we have to redisplay the screen. We can't do that here,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 * because we may be called by DOS. The redraw is in mch_inchar().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 static int _cdecl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 cbrk_handler(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 delayed_redraw = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 return 1; /* resume operation after ctrl-break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 * function for critical error interrupt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 * For DOS 1 and 2 return 0 (Ignore).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 * For DOS 3 and later return 3 (Fail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 static void interrupt
7842
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1228 catch_cint(
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1229 unsigned bp,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1230 unsigned di,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1231 unsigned si,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1232 unsigned ds,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1233 unsigned es,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1234 unsigned dx,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1235 unsigned cx,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1236 unsigned bx,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1237 unsigned ax)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 ax = (ax & 0xff00); /* set AL to 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 if (_osmajor >= 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 ax |= 3; /* set AL to 3 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 * Set the interrupt vectors for use with Vim on or off.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 * on == TRUE means as used within Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 set_interrupts(int on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 static int saved_cbrk;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 #ifndef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 static void interrupt (*old_cint)();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 static void interrupt (*old_cbrk)(INT_ARG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 if (on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 saved_cbrk = getcbrk(); /* save old ctrl-break setting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 setcbrk(0); /* do not check for ctrl-break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 old_cbrk = signal(SIGINT, catch_cbrk); /* critical error interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 old_cint = getvect(0x24); /* save old critical error interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 setvect(0x24, catch_cint); /* install our critical error interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 old_cbrk = getvect(0x1B); /* save old ctrl-break interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 setvect(0x1B, catch_cbrk); /* install our ctrl-break interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 ctrlbrk(cbrk_handler); /* vim's ctrl-break handler */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 if (term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 out_str(T_ME); /* set colors */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 setcbrk(saved_cbrk); /* restore ctrl-break setting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 signal(SIGINT,old_cbrk); /* critical error interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 setvect(0x24, old_cint); /* restore critical error interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 setvect(0x1B, old_cbrk); /* restore ctrl-break interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 /* restore ctrl-break handler, how ??? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 if (term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 mynormvideo(); /* restore screen colors */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 * We have no job control, fake it by starting a new shell.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 mch_suspend(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 suspend_shell();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 extern int _fmode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 * Prepare window for use by Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 mch_init(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 #if defined(DJGPP) && defined(FEAT_CLIPBOARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 __dpmi_regs dpmi_regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 * Get the video attributes at the cursor. These will be used as the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 * default attributes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 regs.h.ah = 0x08;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 regs.h.bh = 0x00; /* video page 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 int86(0x10, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 orig_attr = regs.h.ah;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 mynormvideo();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 if (cterm_normal_fg_color == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 cterm_normal_fg_color = (orig_attr & 0xf) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 if (cterm_normal_bg_color == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 cterm_normal_bg_color = ((orig_attr >> 4) & 0xf) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 term_console = TRUE; /* assume using the console for the things here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 _fmode = O_BINARY; /* we do our own CR-LF translation */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 set_interrupts(TRUE); /* catch interrupts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 * Use Long File Names by default, if $LFN not set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 if (getenv("LFN") == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 putenv("LFN=y");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 get_screenbase();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 /* find out if a MS compatible mouse is available */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 regs.x.ax = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 (void)int86(0x33, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 mouse_avail = regs.x.ax;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 /* best guess for mouse coordinate computations */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 mch_get_shellsize();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 if (Columns <= 40)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 mouse_x_div = 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 if (Rows == 30)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 mouse_y_div = 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 * Try switching to 16 colors for background, instead of 8 colors and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 * blinking. Does this always work? Can the old value be restored?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 regs.x.ax = 0x1003;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 regs.h.bl = 0x00;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 regs.h.bh = 0x00;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 int86(0x10, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 * Test if we have an enhanced AT keyboard. Write 0xFFFF to the keyboard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 * buffer and try to read it back. If we can't in 16 tries, it's an old
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 * type XT keyboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 regs.h.ah = 0x05;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 regs.x.cx = 0xffff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 int86(0x16, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 if (regs.h.al != 1) /* skip this when keyboard buffer is full */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 for (i = 0; i < 16; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 regs.h.ah = 0x10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 int86(0x16, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 if (regs.x.ax == 0xffff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 if (i == 16) /* 0xffff not read, must be old keyboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 bioskey_read = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 bioskey_ready = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 #ifdef MCH_CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 /* Save the old cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 mch_restore_cursor_shape(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 /* Initialise the cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 mch_update_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 #if defined(DJGPP) && defined(FEAT_CLIPBOARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 * Check to see if the Windows clipboard is available, ie. are we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 * running from a DOS session within Windows. Obviously, the Windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 * clipboard will not be available if we're running under pure DOS.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 * int 0x2f, AX = 0x1700 identifies the Windows version we're running
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 * under. Upon return from the interrupt, if AX is unchanged, we're
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 * running under pure DOS and no Windows clipboard is available.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 * Remark: could use int86() here but __dpmi_int() is recommended in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 * the DJGPP docs, since int86() doesn't cover all available interrupts.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 dpmi_regs.x.ax = 0x1700;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 if (__dpmi_int(0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 /* real-mode interrupt failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 dpmi_regs.x.ax = 0x1700; /* force failure */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 if (dpmi_regs.x.ax == 0x1700) /* no change in AX? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 clip_init(FALSE); /* no clipboard available, too bad */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 else /* else, running under Windows, OK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 clip_init(TRUE); /* clipboard is available */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 mch_check_win(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 int argc,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 char **argv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 /* store argv[0], may be used for $VIM */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 if (*argv[0] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 exe_name = FullName_save((char_u *)argv[0], FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 * Try the DOS search path. The executable may in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 * fact be called differently, so try this last.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 if (exe_name == NULL || *exe_name == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 exe_name = searchpath("vim.exe");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 if (isatty(1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 * Return TRUE if the input comes from a terminal, FALSE otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 mch_input_isatty(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 if (isatty(read_cmd_fd))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 #if defined(USE_FNAME_CASE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 * fname_case(): Set the case of the file name, if it already exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 * TODO: should expand short to long file names. Need to use DOS interrupts,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 * see DJGPP sources libc/dos/dir/findfirs.c.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 fname_case(char_u *name, int len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 char_u *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 struct ffblk fb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 slash_adjust(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 if (findfirst(name, &fb, 0) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 tail = gettail(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 if (len == 0 ? STRLEN(tail) == STRLEN(fb.ff_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 : (tail - name) + STRLEN(fb.ff_name) < len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 STRCPY(tail, fb.ff_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 * return process ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 mch_get_pid(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 return (long)0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 * Change default drive (just like _chdrive of Borland C 3.1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 change_drive(int drive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 regs.h.ah = 0x0e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 regs.h.dl = drive - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 intdos(&regs, &regs); /* set default drive */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 regs.h.ah = 0x19;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 intdos(&regs, &regs); /* get default drive */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 if (regs.h.al == drive - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 * Get absolute file name into buffer 'buf' of length 'len' bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 * All slashes are replaced with backslashes, to avoid trouble when comparing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 * file names. When 'shellslash' set do it the other way around.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 mch_FullName(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 char_u *fname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 char_u *buf,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 int len,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 int force)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 if (!force && mch_isFullName(fname)) /* already expanded */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 {
418
84825cc6f049 updated for version 7.0109
vimboss
parents: 370
diff changeset
1519 vim_strncpy(buf, fname, len - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 slash_adjust(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 #ifdef __BORLANDC__ /* Only Borland C++ has this */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 if (_fullpath((char *)buf, (char *)fname, len - 1) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 #else /* almost the same as mch_FullName() in os_unix.c */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 # if 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 char_u fullpath[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 if (!_truename(fname, fullpath))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 slash_adjust(fullpath); /* Only needed when 'shellslash' set */
418
84825cc6f049 updated for version 7.0109
vimboss
parents: 370
diff changeset
1536 vim_strncpy(buf, fullpath, len - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 # else /* Old code, to be deleted... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 char_u olddir[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 char_u *p, *q;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 int retval = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 *buf = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 * change to the directory for a moment,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 * and then do the getwd() (and get back to where we were).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 * This will get the correct path name with "../" things.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 p = vim_strrchr(fname, '/');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 q = vim_strrchr(fname, '\\');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 if (q != NULL && (p == NULL || q > p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 p = q;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 q = vim_strrchr(fname, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 if (q != NULL && (p == NULL || q > p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 p = q;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 if (getcwd(olddir, MAXPATHL) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 p = NULL; /* can't get current dir: don't chdir */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 if (p == fname) /* /fname */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 q = p + 1; /* -> / */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 else if (q + 1 == p) /* ... c:\foo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 q = p + 1; /* -> c:\ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 else /* but c:\foo\bar */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 q = p; /* -> c:\foo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 c = *q; /* truncate at start of fname */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 *q = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 # ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 STRCPY(buf, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 slash_adjust(buf); /* needed when fname starts with \ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 if (mch_chdir(buf)) /* change to the directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 if (mch_chdir(fname)) /* change to the directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 fname = q;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 if (c == psepc) /* if we cut the name at a */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 fname++; /* '\', don't add it again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 *q = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 if (getcwd(buf, len) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 *buf = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 # ifdef USE_FNAME_CASE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 char_u *head;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 char_u *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 struct ffblk fb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 int added;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 /* Apparently "longna~1" isn't expanded by getcwd(), at least not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 * for DJGPP. Expand it here. Have to do each dirname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 * separately. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 slash_adjust(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 head = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 if (isalpha(*head) && head[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 head += 2; /* skip "c:" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 while (*head != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 /* Advance "head" to the start of a dirname and "tail" to just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 * after it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 while (*head == '/' || *head == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 ++head;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 for (tail = head; *tail != NUL; ++tail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 if (*tail == '/' || *tail == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 c = *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 *tail = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 if (findfirst(buf, &fb, FA_DIREC) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 added = STRLEN(fb.ff_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 if ((head - buf) + added + STRLEN(tail + 1) + 2 < len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 added -= (tail - head);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 if (added != 0)
1621
82b5078be2dd updated for version 7.2a
vimboss
parents: 1210
diff changeset
1634 STRMOVE(tail + 1 + added, tail + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 STRCPY(head, fb.ff_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 tail += added;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 *tail = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 head = tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 mch_chdir(olddir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 * Concatenate the file name to the path.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 if (*fname != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 l = STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 if (l > 0 && buf[l - 1] != '/' && buf[l - 1] != '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 strcat(buf, pseps);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 strcat(buf, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 * Replace all slashes by backslashes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 * This used to be the other way around, but MS-DOS sometimes has problems
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 * with slashes (e.g. in a command name). We can't have mixed slashes and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 * backslashes, because comparing file names will not work correctly. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 * commands that use a file name should try to avoid the need to type a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 * backslash twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 * When 'shellslash' set do it the other way around.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 slash_adjust(char_u *p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 #ifdef OLD_DJGPP /* this seems to have been fixed in DJGPP 2.01 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 /* DJGPP can't handle a file name that starts with a backslash, and when it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 * starts with a slash there should be no backslashes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 if (*p == '\\' || *p == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 while (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 if (*p == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 *p = '/';
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
1682 mb_ptr_adv(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 while (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 if (*p == psepcN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 *p = psepc;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
1690 mb_ptr_adv(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 * Return TRUE if "fname" does not depend on the current directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 mch_isFullName(char_u *fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 /* A name like "d:/foo" and "//server/share" is absolute */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 return (fname[0] != NUL && fname[1] == ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 && (fname[2] == '/' || fname[2] == '\\'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 mch_early_init(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 * Careful: mch_exit() may be called before mch_init()!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 mch_exit(int r)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 settmode(TMODE_COOK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 stoptermcap();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 set_interrupts(FALSE); /* restore interrupts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 set_sys_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 /* Somehow outputting CR-NL causes the original colors to be restored */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 out_char('\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 out_char('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 ml_close_all(TRUE); /* remove all memfiles */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 #ifdef MCH_CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 mch_restore_cursor_shape(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 exit(r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 * set the tty in (raw) ? "raw" : "cooked" mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 * Does not change the tty, as bioskey() and kbhit() work raw all the time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 mch_settmode(int tmode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 mch_setmouse(int on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 mouse_active = on;
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
1749 mouse_hidden = TRUE; /* don't show it until moved */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 * set screen mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 mch_screenmode(char_u *arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 int mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 static char *(names[]) = {"BW40", "C40", "BW80", "C80", "MONO", "C4350"};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 static int modes[] = { BW40, C40, BW80, C80, MONO, C4350};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 mode = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 if (VIM_ISDIGIT(*arg)) /* mode number given */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 mode = atoi((char *)arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 for (i = 0; i < sizeof(names) / sizeof(char_u *); ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 if (stricmp(names[i], (char *)arg) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 mode = modes[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 if (mode == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 EMSG("E362: Unsupported screen mode");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 textmode(mode); /* use Borland function */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 /* base address may have changed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 get_screenbase();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 /* Screen colors may have changed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 out_str(T_ME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 if (mode <= 1 || mode == 4 || mode == 5 || mode == 13 || mode == 0x13)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 mouse_x_div = 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 mouse_x_div = 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 if (mode == 0x11 || mode == 0x12)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 mouse_y_div = 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 else if (mode == 0x10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 mouse_y_div = 14;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 mouse_y_div = 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 shell_resized();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 * Structure used by Turbo-C/Borland-C to store video parameters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 #ifndef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 extern struct text_info _video;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 * try to get the real window size
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 mch_get_shellsize(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 struct text_info textinfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 * The screenwidth is returned by the BIOS OK.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 * The screenheight is in a location in the bios RAM, if the display is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 * EGA or VGA.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 if (!term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 gettextinfo(&textinfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 Columns = textinfo.screenwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 Rows = textinfo.screenheight;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 #ifndef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 if (textinfo.currmode > 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 Rows = *(char far *)MK_FP(0x40, 0x84) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 if (Columns < MIN_COLUMNS || Rows < MIN_LINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 /* these values are overwritten by termcap size or default */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 Columns = 80;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 Rows = 25;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 mytextinit(&textinfo); /* Added by JML, 1/15/98 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 * Set the active window for delline/insline.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 set_window(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 if (term_console)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 #ifndef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 _video.screenheight = Rows;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 mywindow(1, 1, Columns, Rows);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 screen_start();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 mch_set_shellsize(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 /* Should try to set the window size to Rows and Columns.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 * May involve switching display mode....
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 * We assume the user knows the size and just use it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 * Rows and/or Columns has changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 void
7842
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1880 mch_new_shellsize(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 /* best guess for mouse coordinate computations */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 if (Columns <= 40)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 mouse_x_div = 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 if (Rows == 30)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 mouse_y_div = 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 set_window();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 mouse_area(); /* set area where mouse can go */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 #if defined(DJGPP) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 * Check the number of Columns with a BIOS call. This avoids a crash of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 * DOS console when 'columns' is set to a too large value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 void
7842
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
1901 mch_check_columns(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 static union REGS regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 regs.h.ah = 0x0f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 (void)int86(0x10, &regs, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 if ((unsigned)Columns > (unsigned)regs.h.ah)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 Columns = (unsigned)regs.h.ah;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 * call shell, return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 * options: SHELL_*, see vim.h.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 mch_call_shell(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 char_u *cmd,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 int options)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 int tmode = cur_tmode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 #ifndef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 char_u *newcmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 set_sys_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 if (options & SHELL_COOKED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 settmode(TMODE_COOK); /* set to normal mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 set_interrupts(FALSE); /* restore interrupts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 /* ignore signals while external command is running */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 signal(SIGINT, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 signal(SIGHUP, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 signal(SIGQUIT, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 signal(SIGTERM, SIG_IGN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 if (cmd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 x = system((char *)p_sh);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 * Use 'shell' for system().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 setenv("SHELL", (char *)p_sh, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 x = system(cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 /* we use "command" to start the shell, slow but easy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 newcmd = alloc(STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 if (newcmd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 x = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 sprintf((char *)newcmd, "%s %s %s", p_sh, p_shcf, cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 x = system((char *)newcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 vim_free(newcmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 signal(SIGINT, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 signal(SIGHUP, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 signal(SIGQUIT, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 signal(SIGTERM, SIG_DFL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 if (tmode == TMODE_RAW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 settmode(TMODE_RAW); /* set to raw mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 set_interrupts(TRUE); /* catch interrupts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 if (x && !(options & SHELL_SILENT) && !emsg_silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 MSG_PUTS("\nshell returned ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 msg_outnum((long)x);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 return x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 * check for an "interrupt signal": CTRL-break or CTRL-C
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 mch_breakcheck(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 if (ctrlc_pressed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 ctrlc_pressed = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 got_int = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 * Return TRUE if "p" contain a wildcard that can be expanded by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 * dos_expandpath().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 mch_has_exp_wildcard(char_u *p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2006 for ( ; *p; mb_ptr_adv(p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 if (vim_strchr((char_u *)"?*[", *p) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 || (*p == '~' && p[1] != NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 * Return TRUE if "p" contain a wildcard or a "~1" kind of thing (could be a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 * shortened file name).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 mch_has_wildcard(char_u *p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2022 for ( ; *p; mb_ptr_adv(p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 if (vim_strchr((char_u *)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 "?*$[`"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 "?*$["
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 , *p) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 || (*p == '~' && p[1] != NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 * Change directory to "path".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 * The normal chdir() does not change the default drive. This one does.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 * Return 0 for success, -1 for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 mch_chdir(char *path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 if (path[0] == NUL) /* just checking... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 return 0;
1936
85a99ba3eb5a updated for version 7.2-233
vimboss
parents: 1621
diff changeset
2047 if (p_verbose >= 5)
85a99ba3eb5a updated for version 7.2-233
vimboss
parents: 1621
diff changeset
2048 {
85a99ba3eb5a updated for version 7.2-233
vimboss
parents: 1621
diff changeset
2049 verbose_enter();
85a99ba3eb5a updated for version 7.2-233
vimboss
parents: 1621
diff changeset
2050 smsg((char_u *)"chdir(%s)", path);
85a99ba3eb5a updated for version 7.2-233
vimboss
parents: 1621
diff changeset
2051 verbose_leave();
85a99ba3eb5a updated for version 7.2-233
vimboss
parents: 1621
diff changeset
2052 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 if (path[1] == ':') /* has a drive name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 if (change_drive(TOLOWER_ASC(path[0]) - 'a' + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 return -1; /* invalid drive name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 path += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 if (*path == NUL) /* drive name only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 return chdir(path); /* let the normal chdir() do the rest */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 * mch_rename() works around a bug in rename (aka MoveFile) in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 * Windows 95: rename("foo.bar", "foo.bar~") will generate a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 * file whose short file name is "FOO.BAR" (its long file name will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 * be correct: "foo.bar~"). Because a file can be accessed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 * either its SFN or its LFN, "foo.bar" has effectively been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 * renamed to "foo.bar", which is not at all what was wanted. This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 * seems to happen only when renaming files with three-character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 * extensions by appending a suffix that does not include ".".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 * This works like mch_rename in os_win32.c, but is a bit simpler.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 * Like rename(), returns 0 upon success, non-zero upon failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 * Should probably set errno appropriately when errors occur.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 mch_rename(const char *OldFile, const char *NewFile)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 char_u *TempFile;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 int fd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 /* rename() works correctly without long file names, so use that */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 if (!_USE_LFN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 return rename(OldFile, NewFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 if ((TempFile = alloc((unsigned)(STRLEN(OldFile) + 13))) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 STRCPY(TempFile, OldFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 STRCPY(gettail(TempFile), "axlqwqhy.ba~");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 if (rename(OldFile, TempFile))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 retval = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 /* now create an empty file called OldFile; this prevents
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 * the operating system using OldFile as an alias (SFN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 * if we're renaming within the same directory. For example,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 * we're editing a file called filename.asc.txt by its SFN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 * filena~1.txt. If we rename filena~1.txt to filena~1.txt~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 * (i.e., we're making a backup while writing it), the SFN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 * for filena~1.txt~ will be filena~1.txt, by default, which
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2108 * will cause all sorts of problems later in buf_write(). So, we
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 * create an empty file called filena~1.txt and the system will have
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 * to find some other SFN for filena~1.txt~, such as filena~2.txt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 if ((fd = open(OldFile, O_RDWR|O_CREAT|O_EXCL, 0444)) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 retval = rename(TempFile, NewFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 close(fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 mch_remove((char_u *)OldFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 /* If renaming to NewFile failed, rename TempFile back to OldFile, so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 * that it looks like nothing happened. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 if (retval)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 rename(TempFile, OldFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 vim_free(TempFile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 return retval; /* success */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 #if defined(DJGPP) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131 * setlocale() for DJGPP with MS-DOS codepage support
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 * Author: Cyril Slobin <slobin@fe.msk.ru>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 * Scaled down a lot for use by Vim: Only support setlocale(LC_ALL, "").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 #undef setlocale
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138
3927
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
2139 #ifndef PROTO
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
2140 # include <go32.h>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
2141 # include <inlines/ctype.ha>
e6d8b44065bc updated for version 7.3.719
Bram Moolenaar <bram@vim.org>
parents: 3634
diff changeset
2142 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 #include <locale.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 #define UPCASE (__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 #define LOCASE (__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISLOWER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 djgpp_setlocale(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 __dpmi_regs regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 struct { char id; unsigned short off, seg; } __attribute__ ((packed)) info;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 unsigned char buffer[0x82], lower, upper;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 regs.x.ax = 0x6502;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 regs.x.bx = 0xffff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 regs.x.dx = 0xffff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 regs.x.cx = 5;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 regs.x.es = __tb >> 4;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 regs.x.di = __tb & 0xf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 __dpmi_int(0x21, &regs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 if (regs.x.flags & 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 dosmemget(__tb, 5, &info);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 dosmemget((info.seg << 4) + info.off, 0x82, buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 if (*(short *)buffer != 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 /* Fix problem of underscores being replaced with y-umlaut. (Levin) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 if (buffer[26] == 0x5f)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 buffer[26] = 0x98;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 for (i = 0; i < 0x80; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 lower = i + 0x80;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 upper = (buffer+2)[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 if (lower != upper)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 __dj_ctype_flags[lower+1] = LOCASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 __dj_ctype_toupper[lower+1] = upper;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 if (__dj_ctype_flags[upper+1] == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 __dj_ctype_flags[upper+1] = UPCASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 if (__dj_ctype_tolower[upper+1] == upper)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 __dj_ctype_tolower[upper+1] = lower;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 return "C";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 * Clipboard stuff, for cutting and pasting text to other windows.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 * Implementation of DOS/Windows clipboard data transfer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 * by David Kotchan (dkotchan@sympatico.ca)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 #define CF_TEXT 0x01 /* Windows clipboard format: Windows (ANSI) text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 #define CF_OEMTEXT 0x07 /* Windows clipboard format: OEM (DOS) text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 #define CF_VIMCLIP 0x04 /* trick: SYLK clipboard format for VimClipboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 static int Win16OpenClipboard(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 static int Win16CloseClipboard(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 static int Win16EmptyClipboard(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 static char_u *Win16GetClipboardData(int clip_data_format);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 static int Win16SetClipboardData(int clip_data_format, char_u *clip_data, int clip_data_size, int clip_data_type);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 * Make vim the owner of the current selection. Return OK upon success.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 clip_mch_own_selection(VimClipboard *cbd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 * Never actually own the clipboard. If another application sets the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 * clipboard, we don't want to think that we still own it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 * Make vim NOT the owner of the current selection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 clip_mch_lose_selection(VimClipboard *cbd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 /* Nothing needs to be done here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 * Read the Windows clipboard text and put it in Vim's clipboard register.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 clip_mch_request_selection(VimClipboard *cbd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 {
2896
fd4224d9ee09 updated for version 7.3.221
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
2243 int type = MAUTO;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 char_u *pAllocated = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 char_u *pClipText = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 int clip_data_format = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 if (Win16OpenClipboard())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 /* Check for Vim's own clipboard format first. The CF_VIMCLIP format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 * is just ordinary text (like CF_TEXT) except prepended by the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 * selection type (as a single character). Note that under DOS we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 * actually cannot define a custom CF_VIMCLIP clipboard format; we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 * use instead one of the existing Windows-defined formats, usually
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 * "DIF" or "SYLK". See Win16GetClipboardData() for details.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 * Note that Win16GetClipboardData() returns the address of the memory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 * block it allocated. This is not necessary the start of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 * clipboard text data: there may be other bytes ahead of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 * text (particularly for CF_VIMCLIP) which are used for data
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 * management. So pClipText is not necessarily == pAllocated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 if ((pAllocated = Win16GetClipboardData(CF_VIMCLIP)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 clip_data_format = CF_VIMCLIP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 pClipText = pAllocated;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 switch (*pClipText++) /* after ++, pClipText points to text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 case 'L': type = MLINE; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 case 'C': type = MCHAR; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 case 'B': type = MBLOCK; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 /* Otherwise, check for the normal Windows text formats. There are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 * two of these: CF_TEXT (common) and CF_OEMTEXT (used for DOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 * compatibility). Experiments show that, under the DOS/Windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 * clipboard interface, writing CF_TEXT data to the clipboard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 * automatically creates a CF_OEMTEXT format as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 else if ((pAllocated = Win16GetClipboardData(CF_TEXT)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 clip_data_format = CF_TEXT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 pClipText = pAllocated;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 else if ((pAllocated = Win16GetClipboardData(CF_OEMTEXT)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 clip_data_format = CF_OEMTEXT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 pClipText = pAllocated;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 /* Did we get anything? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 if (pClipText != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 char_u *pDest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 char_u *pStart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 char_u *pEnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 long_u clip_data_size = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 /* The Windows clipboard normally stores its text lines terminated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 * by <CR><NL>. But Vim uses only <NL>, so translate the <CR><NL>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 * into <NL>. Also, watch for possible null bytes at the end of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 * pClipText. These are padding added by "get_clipboard_data"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 * (int 0x2f, AX= 0x1705) in order to round the data size up to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 * next multiple of 32 bytes. See Win16GetClipboardData() for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 * details.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 pDest = strstr( pClipText, "\r\n" ); /* find first <CR><NL> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 if (pDest != NULL) /* found one? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 pStart = pDest + 1; /* points to <NL> after <CR> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 pEnd = strstr( pStart, "\r\n" );/* find next <CR><NL> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 while (pEnd != NULL) /* found one? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 memmove(pDest, pStart, (long)(pEnd - pStart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 /* exclude <CR> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 pDest += (long)(pEnd - pStart); /* new destination */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 pStart = pEnd + 1; /* new starting point */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 pEnd = strstr(pStart, "\r\n"); /* find next <CR><NL> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 /* Fell out of while() loop: no more <CR><NL> pairs. Just copy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 * the rest of the data, up to the first null byte. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 pEnd = strchr(pStart, '\0'); /* find first null */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 memmove(pDest, pStart, (long)(pEnd - pStart)); /* exclude nul */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 pDest += (long)(pEnd - pStart);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 *pDest = '\0'; /* terminate */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 /* Now that all <CR><NL> pairs have been "compressed" into just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 * <NL>'s, determine the true text length. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 clip_data_size = (long_u)(pDest - pClipText);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 /* no <CR><NL> pairs at all */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 /* Since the data may have been padded with trailing nulls,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 * determine the true string length. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 clip_data_size = STRLEN(pClipText); /* true data length */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 /* Copy the cleaned-up data over to Vim's clipboard "*" register. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 clip_yank_selection(type, pClipText, clip_data_size, cbd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 /* Free the memory that Win16GetClipboardData() allocated. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 vim_free(pAllocated);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 Win16CloseClipboard();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 } // end if (Win16OpenClipboard())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 * Send the currently selected Vim text to the Windows clipboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 clip_mch_set_selection( VimClipboard *cbd )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 char_u *pClipData = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 long_u clip_data_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 int clip_data_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 /* If the '*' register isn't already filled in, fill it in now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 cbd->owned = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 clip_get_selection(cbd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 cbd->owned = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 * clip_convert_selection() returns a pointer to a buffer containing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 * the text to send to the Windows clipboard, together with a count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 * of the number of characters (bytes) in the buffer. The function's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 * return value is the 'type' of selection: MLINE, MCHAR, or MBLOCK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 * or -1 for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386 clip_data_type = clip_convert_selection(&pClipData, &clip_data_size, cbd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 if (clip_data_type < 0) /* could not convert? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 return; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 if (Win16OpenClipboard())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 if (Win16EmptyClipboard())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 int sentOK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 sentOK = Win16SetClipboardData(CF_TEXT, pClipData,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 clip_data_size, clip_data_type);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 sentOK = Win16SetClipboardData(CF_VIMCLIP,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 pClipData, clip_data_size, clip_data_type) && sentOK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 if (!sentOK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 /* one or both of Win16SetClipboardData() failed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 /* Technically we don't know why Win16SetClipboardData()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 * failed, but almost always it will be because there wasn't
1210
302520c08584 updated for version 7.1b
vimboss
parents: 799
diff changeset
2407 * enough DOS memory to buffer the data, so report that as the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 * problem.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 * We report the error here (instead of in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 * Win16SetClipboardData()) because we don't want the error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 * reported twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 EMSG("E450: Selection too large, cannot allocate DOS buffer");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 Win16CloseClipboard();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 /* release memory allocated by clip_convert_selection() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422 vim_free(pClipData);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 * Win16OpenClipboard: open the Windows clipboard. The clipboard must be open
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 * before it can be communicated with at all. Return TRUE on success,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430 * FALSE on failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2431 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 Win16OpenClipboard(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 __dpmi_regs dpmi_regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 long start_time;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 int tick_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
2440 /* int 0x2f, AX = 0x1701 attempts to open the Windows clipboard. Upon
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 * return from the interrupt, if AX is non-zero, the clipboard was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 * successfully opened. If AX is zero, the clipboard could not be opened
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 * because it is currently in use by another process.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 * Remark: other DOS programs I (dk) have written that use the Windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 * clipboard sometimes encounter the problem that the clipboard cannot
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 * be opened even though it is demonstrably not in use by any other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 * process. In all cases, repeated attempts to open the clipboard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 * eventually succeed, but the initial attempt occasionally fails.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 * The problem is intermittent and appears to be related to DOS being
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 * "busy" at certain unpredictable times. DOS maintains two internal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 * flags that indicate whether it's busy: InDOS and CritErr. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2454 * location of InDOS can be found by calling int 0x21, AH = 0x34. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 * location of CritErr can be found by calling int 0x21, AX = 0x5d06.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 * If either of these flags is set, DOS is "busy" and cannot be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 * interrupted. See "Undocumented DOS" by Schulman et al for details.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 * However here I take the easier approach that if the first call to open
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 * the clipboard does not succeed, just try again. In fact, try once per
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 * biostime() clock tick, up to 18 times (about one second).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 tick_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 dpmi_regs.x.ax = 0x1701; /* open Windows clipboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 if (__dpmi_int(0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 /* real-mode interrupt failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 return FALSE; /* FALSE --> clipboard not open */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 /* wait up to one second */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 while (dpmi_regs.x.ax == 0 && tick_count++ < 18)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 /* Wait one clock tick (18.2 ticks/sec = 55 msec per tick).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 * We busy-wait here. Unfortunately, delay() and usleep() have been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 * reported to give problems with the original Windows 95. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 * fixed in service pack 1, but not everybody installed that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 start_time = biostime(0, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 while (biostime(0, 0L) == start_time)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 dpmi_regs.x.ax = 0x1701; /* open Windows clipboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 if (__dpmi_int(0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 /* real-mode interrupt failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 return FALSE; /* FALSE --> clipboard not open */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 /* Couldn't open the clipboard, even after 18 attempts? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 if (tick_count >= 18 && dpmi_regs.x.ax == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 return FALSE; /* FALSE --> clipboard not open */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 return TRUE; /* TRUE --> clipboard opened successfully, OK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 * Win16CloseClipboard: close the Windows clipboard. Return TRUE on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 * success, FALSE on failure. This function can always be called,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505 * whether the clipboard is open or not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 Win16CloseClipboard(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 __dpmi_regs dpmi_regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 /* Close the clipboard. This interrupt can always be called, even
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 * if the clipboard is already closed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 dpmi_regs.x.ax = 0x1708; /* close the clipboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 if (__dpmi_int(0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 /* real-mode interrupt failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 return FALSE; /* FALSE --> clipboard could not be closed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 return TRUE; /* TRUE --> clipboard closed successfully, OK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2527 * Win16EmptyClipboard: empty the (previously opened) Windows clipboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 * Return TRUE on success, FALSE on failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 Win16EmptyClipboard(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 __dpmi_regs dpmi_regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
2535 /* int 0x2f, AX = 0x1702 attempts to empty the Windows clipboard. Upon
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 * return from the interrupt, if AX == 0, the clipboard could not be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 * emptied (for some reason).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 dpmi_regs.x.ax = 0x1702; /* empty the Windows clipboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540 if (__dpmi_int(0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 /* real-mode interrupt failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 return FALSE; /* FALSE --> clipboard could not be emptied */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 /* Did we succeed in clearing the clipboard? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 if (dpmi_regs.x.ax == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 return FALSE; /* FALSE --> clipboard could not be emptied */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 return TRUE; /* TRUE --> clipboard was emptied, OK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 * FreeDOSMemory: a helper function to free memory previously
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 * allocated by a call to __dpmi_allocate_dos_memory().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 FreeDOSMemory(int protected_mode_selector)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 /* Free the DOS buffer and release the DPMI prot-mode selector.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 * It's important that DOS memory be properly released because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 * there's only a limited amount of it. Therefore, if the call
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 * to __dpmi_free_dos_memory() fails, emit an error message
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 * unconditionally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 if (__dpmi_free_dos_memory(protected_mode_selector) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 EMSG("E451: could not free DOS memory buffer (DJGPP)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 * Win16GetClipboardData: query the Windows clipboard as to whether data
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 * is available in a particular clipboard format. If data is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 * available, allocate a buffer for it and read the data from the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575 * clipboard into the buffer. Return a pointer to the buffer. If
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576 * no data is available in the requested format, return NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 * This routine allocates memory to hold the retrieved clipboard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 * data. It's the caller's responsibility to free this memory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580 * once it's finished using it. The memory should be freed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 * calling vim_free().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584 Win16GetClipboardData(int clip_data_format)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 __dpmi_regs dpmi_regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2588 int real_mode_segment_address;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2589 int protected_mode_selector;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591 char_u *clip_data_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 long_u clip_data_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594 /* We only handle clipboard formats we recognize, others are ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2595 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 * It's not possible to create a custom clipboard format for VimClipboard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2597 * data under DOS, so one of the predefined Windows formats had to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2598 * used for CF_VIMCLIP. Two obscure formats, popular when Windows 3.0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 * came out but no longer in much use today, are the DIF and SYLK formats.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 * DIF is the Data Interchange Format, SYLK is the Symbolic Link format.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2601 * They are both text formats and either one can be hijacked for use as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 * "the VimClipboard format". Of course, this conflicts with anyone who
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 * still *is* using DIF or SYLK data formats, but that will be very few
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 * people.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 * I (dk) chose SYLK as the more obscure format because it was used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 * mostly for Microsoft Multiplan (the pre-cursor to Excel) and it's not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 * likely Multiplan is used anywhere much anymore. Mind you, Excel can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 * still export to both DIF and SYLK formats.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 switch (clip_data_format)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2614 case CF_VIMCLIP: /* Vim's own special clipboard format */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 case CF_TEXT: /* Windows text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616 case CF_OEMTEXT: /* DOS (OEM) text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
2618 /* int 0x2f, AX = 0x1704 returns the number of bytes of data currently
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 * on the Windows clipboard, for the specified format. Upon return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 * from the interrupt, DX:AX = the number of bytes, rounded up to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621 * nearest multiple of 32.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 dpmi_regs.x.ax = 0x1704; /* get size of clipbd data */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 dpmi_regs.x.dx = clip_data_format;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 if (__dpmi_int(0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 /* real-mode interrupt failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 return NULL; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 /* Did we get anything? If not, this is not an error. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 if (dpmi_regs.x.dx == 0 && dpmi_regs.x.ax == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 /* no CF_VIMCLIP data? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 return NULL; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639 /* There is data available in the requested clipboard format.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 * Calculate data size. Remember this is rounded up to the nearest
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2642 * multiple of 32, so clip_data_size is actually an upper limit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2643 * The extra bytes, if any, are set to null (0x00) when the data is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 * read from the clipboard. (Later:) actually I'm no longer sure
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 * this is strictly true: the end-of-data is marked by a null, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 * the extra bytes appear to sometimes be null, sometimes not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647 * They may just be garbage.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 clip_data_size = dpmi_regs.x.ax + (dpmi_regs.x.dx << 16);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 /* Allocate memory to retrieve the data. The buffer has to lie in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 * DOS memory region (in the first 1 MByte of address space) because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653 * the Windows clipboard interface expects a 16-bit segment:offset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 * pointer to a buffer address within the DOS region. Must therefore
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 * use __dpmi_allocate_dos_memory() instead of lalloc() or alloc().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657 real_mode_segment_address = __dpmi_allocate_dos_memory(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2658 (clip_data_size + 15) >> 4, /* buffer size, in 16-byte paragraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659 &protected_mode_selector); /* prot-mode selector for the address */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2661 if (real_mode_segment_address == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 /* memory allocation failed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665 /* Technically we don't know why the allocation failed, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2666 * almost always it will be because there wasn't enough DOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2667 * memory to satisfy the request, so report that as the problem.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2668 * On my system, DJGPP is able to satisfy a DOS allocation request
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 * up to about 600K in size. This depends on your HIMEM.SYS and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670 * EMM386.EXE settings however.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672 EMSG("E452: Clipboard data too large, cannot allocate DOS buffer");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2673 return NULL; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2674 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 /* Copy data from the clipboard into the buffer. Experiments show that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 * the Windows clipboard is smart enough to handle data transfers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 * larger than 64K properly, even though the buffer address is a 16-bit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679 * segment:offset (which would normally limit the block size to 64K
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2680 * unless ES gets incremented).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2681 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2682 dpmi_regs.x.ax = 0x1705; /* get clipboard data */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2683 dpmi_regs.x.dx = clip_data_format; /* CF_VIMCLIP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2684 dpmi_regs.x.es = real_mode_segment_address; /* buffer ad: segment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685 dpmi_regs.x.bx = 0; /* buffer ad: offset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2686 if (__dpmi_int( 0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2687 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2688 /* real-mode interrupt failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2689 EMSG("E453: could not copy clipboard data to DOS buffer");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 FreeDOSMemory(protected_mode_selector); /* clean up DOS mem */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 return NULL; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2692 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2694 /* Clipboard data is now in DOS memory in the buffer pointed to by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2695 * ES:BX. Copy this into ordinary memory that Vim can access (ie.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2696 * prot-mode memory). Allocate one extra byte to ensure the text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 * is terminated properly (in case it was somehow corrupted).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 clip_data_buffer = (char_u *)lalloc(clip_data_size + 1, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 if (clip_data_buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703 /* allocation failed? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704 EMSG("E454: could not allocate clipboard memory buffer");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2705 FreeDOSMemory(protected_mode_selector); /* clean up DOS mem */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2706 return NULL; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 *(clip_data_buffer + clip_data_size) = '\0'; /* ensure terminated */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711 /* Copy the data from DOS memory to Vim-accessible memory. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712 movedata( /* DJGPP version of memcpy() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 protected_mode_selector, 0, /* source: DOS ad (via selector) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 _my_ds(), (unsigned)clip_data_buffer,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715 /* target: normal mem address */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 clip_data_size); /* how many bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718 /* Free the DOS buffer and release the DPMI prot-mode selector. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 FreeDOSMemory(protected_mode_selector); /* clean up DOS memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 return clip_data_buffer; /* return pointer to allocated buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 default: /* unknown clipboard format */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 * Win16SetClipboardData: send 'clip_data_size' bytes of data from the buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 * pointed to by 'clip_data', to the Windows clipboard. The data is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 * registered with the clipboard as being in the 'clip_data_format'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 * format.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 Win16SetClipboardData(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736 int clip_data_format,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 char_u *clip_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 int clip_data_size,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 int clip_data_type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 __dpmi_regs dpmi_regs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 int real_mode_segment_address;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 int protected_mode_selector;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745 long_u protected_mode_offset = 0L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 int total_size = clip_data_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 char_u *clip_sel_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 /* If we're using the CF_VIMCLIP custom format, allocate an extra
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 * byte for clip_sel_type, which is a character indicating the type
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 * of text selection: MLINE, MCHAR, or MBLOCK.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 if (clip_data_format == CF_VIMCLIP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 total_size++; /* extra byte for marker */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 /* Data cannot be sent directly from a Vim string (pClipData) to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 * the Windows clipboard, because the Windows clipboard interface
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 * expects a 16-bit (DOS) segment:offset address for the source
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 * buffer. Therefore we must create a "transfer buffer" in the DOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 * memory region (in the first 1 MByte of address space) and copy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 * the Vim string into that. From there, the data can then be sent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 * to the Windows clipboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 * To allocate DOS memory, we must use __dpmi_allocate_dos_memory()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 * instead of lalloc() or alloc(). If the allocation fails, it will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 * almost invariably be because there is not enough DOS memory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 * available to accommodate the size of clip_data. There is nothing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 * we can do about this, we simply have to fail.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 real_mode_segment_address = __dpmi_allocate_dos_memory(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 (total_size + 15) >> 4, /* buffer size, in 16-byte paragraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 &protected_mode_selector); /* prot-mode selector for the address */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 if (real_mode_segment_address == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 /* memory allocation failed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 /* Technically we don't know why the allocation failed, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 * almost always it will be because there wasn't enough DOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 * memory to satisfy the request. On my system, DJGPP is able
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 * to satisfy a DOS allocation request up to about 600K in size.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 * This depends however on HIMEM.SYS and EMM386.EXE settings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 return FALSE; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 /* Copy data from Vim's buffer (clip_data) into the DOS transfer buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 * This can be larger than 64K; movedata() takes care of crossing any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 * 16-bit segment boundaries.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 * If we're using Vim's custom clipboard format, we must copy one extra
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 * byte to indicate the type of selection: line, character, or block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 if (clip_data_format == CF_VIMCLIP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 switch (clip_data_type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 case MLINE: clip_sel_type = "L"; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 case MCHAR: clip_sel_type = "C"; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 case MBLOCK: clip_sel_type = "B"; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 movedata(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 _my_ds(), (unsigned)clip_sel_type,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 /* source: normal memory address */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 protected_mode_selector, 0, /* target: DOS ad (via selector) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 1); /* how many bytes to copy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 protected_mode_offset += STRLEN(clip_sel_type); /* allow for marker */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 movedata(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 _my_ds(), (unsigned)clip_data, /* source: normal memory address */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 protected_mode_selector, /* target: DOS address (via selector) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 protected_mode_offset, /* non-zero, if using clip_sel_type */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 clip_data_size); /* how many bytes to copy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 /* Send data from the DOS transfer buffer to the Windows clipboard.
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 3927
diff changeset
2820 * int 0x2f, AX = 0x1703 sends SI:CX bytes of data from the buffer
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 * at ES:BX, to the clipboard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823 dpmi_regs.x.ax = 0x1703; /* send clipboard data */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 dpmi_regs.x.dx = clip_data_format; /* flag: format of the data */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 dpmi_regs.x.si = ((total_size >> 16)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826 & 0x0000ffffL); /* hi word of data size */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 dpmi_regs.x.cx = (total_size & 0x0000ffffL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 /* lo word of data size */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 dpmi_regs.x.es = real_mode_segment_address; /* buffer address: segment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 dpmi_regs.x.bx = 0; /* buffer address: offset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 if (__dpmi_int(0x2f, &dpmi_regs) == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 /* real-mode interrupt failed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 FreeDOSMemory(protected_mode_selector); /* clean up DOS memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 return FALSE; /* early exit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2836 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 /* Free the DOS buffer and release the DPMI prot-mode selector. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 FreeDOSMemory(protected_mode_selector); /* clean up DOS memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 return TRUE; /* TRUE --> data successfully sent to clipboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 #endif /* FEAT_CLIPBOARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 #endif /* DJGPP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 /* common MS-DOS and Win16 code follows */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 vim_chmod(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 int f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 /* chmod() can't handle a file name with a trailing slash, remove it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 * But don't remove it for "/" or "c:/". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 p = name + STRLEN(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 if (p > name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 if (p > name && (*p == '\\' || *p == '/') && p[-1] != ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 c = *p; /* remove trailing (back)slash */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 #if defined(__BORLANDC__) && (__BORLANDC__ > 0x410)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 /* this also sets the archive bit, supported by Borland C 4.0 and later,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 * where __BORLANDC__ is 0x450 (3.1 is 0x410) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 f = _rtl_chmod((char *)name, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 f = _chmod((char *)name, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876 *p = c; /* put back (back)slash */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 return f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 * get file permissions for 'name'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 * Returns -1 for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 * Returns FA_attributes defined in dos.h
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 mch_getperm(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 return (long)vim_chmod(name); /* get file mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 * set file permission for 'name' to 'perm'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 mch_setperm(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898 char_u *name,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 long perm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2901 perm |= FA_ARCH; /* file has changed, set archive bit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2902 #if defined(__BORLANDC__) && (__BORLANDC__ > 0x410)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2903 return (_rtl_chmod((char *)name, 1, (int)perm) == -1 ? FAIL : OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2904 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2905 return (_chmod((char *)name, 1, (int)perm) == -1 ? FAIL : OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2906 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2909 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2910 * Set hidden flag for "name".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2911 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2912 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2913 mch_hide(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2914 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2915 /* DOS 6.2 share.exe causes "seek error on file write" errors when making
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 * the swap file hidden. Thus don't do it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 * return TRUE if "name" is a directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 * return FALSE if "name" is not a directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922 * return FALSE for error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924 * beware of a trailing (back)slash
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 mch_isdir(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 int f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 f = vim_chmod(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 if (f == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2933 return FALSE; /* file does not exist at all */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2934 if ((f & FA_DIREC) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 return FALSE; /* not a directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 * Return 1 if "name" can be executed, 0 if not.
6695
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2941 * If "use_path" is FALSE only check if "name" is executable.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 * Return -1 if unknown.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 int
7842
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
2945 mch_can_exe(
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
2946 char_u *name,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
2947 char_u **path,
cf744110897d commit https://github.com/vim/vim/commit/779a7759ad03e6a3fb616828793512644390655a
Christian Brabandt <cb@256bit.org>
parents: 6695
diff changeset
2948 int use_path)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 {
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
2950 char *p;
6695
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2951 int mode;
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
2952
6695
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2953 if (!use_path)
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2954 {
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2955 /* TODO: proper check if file is executable. */
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2956 mode = vim_chmod(name);
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2957 return mode != -1 && (mode & FA_DIREC) == 0;
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
2958 }
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
2959 p = searchpath(name);
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
2960 if (p == NULL || mch_isdir(p))
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
2961 return FALSE;
5782
5ab2946f7ce5 updated for version 7.4.235
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2962 if (path != NULL)
5ab2946f7ce5 updated for version 7.4.235
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2963 *path = vim_strsave(p);
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
2964 return TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 * Check what "name" is:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969 * NODE_NORMAL: file or directory (or doesn't exist)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 * NODE_WRITABLE: writable device, socket, fifo, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 * NODE_OTHER: non-writable things
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974 mch_nodetype(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 if (STRICMP(name, "AUX") == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 || STRICMP(name, "CON") == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 || STRICMP(name, "CLOCK$") == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 || STRICMP(name, "NUL") == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980 || STRICMP(name, "PRN") == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 || ((STRNICMP(name, "COM", 3) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 || STRNICMP(name, "LPT", 3) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 && VIM_ISDIGIT(name[3])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 && name[4] == NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985 return NODE_WRITABLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 /* TODO: NODE_OTHER? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 return NODE_NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 * Get name of current directory into buffer 'buf' of length 'len' bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 * Return OK for success, FAIL for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 mch_dirname(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 char_u *buf,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 int len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999 #ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000 if (getcwd((char *)buf, len) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002 /* turn the '/'s returned by DJGPP into '\'s */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 slash_adjust(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 return (getcwd((char *)buf, len) != NULL ? OK : FAIL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 * this version of remove is not scared by a readonly (backup) file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 * returns -1 on error, 0 otherwise (just like remove())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016 mch_remove(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 (void)mch_setperm(name, 0); /* default permissions */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019 return unlink((char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 * Special version of getenv(): Use uppercase name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 mch_getenv(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 #define MAXENVLEN 50
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 char_u var_copy[MAXENVLEN + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 char_u *res;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 * Take a copy of the argument, and force it to upper case before passing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 * to getenv(). On DOS systems, getenv() doesn't like lower-case argument
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 * (unlike Win32 et al.) If the name is too long to fit in var_copy[]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 * allocate memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 if ((i = STRLEN(name)) > MAXENVLEN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 p = alloc(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 p = var_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 p = name; /* out of memory, fall back to unmodified name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 for (i = 0; name[i] != NUL; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 p[i] = toupper(name[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 p[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 res = (char_u *)getenv((char *)p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 if (p != var_copy && p != name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 return res;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 * Insert user name in s[len].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 mch_get_user_name(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 char_u *s,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 int len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 *s = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 * Insert host name is s[len].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 mch_get_host_name(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078 char_u *s,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 int len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 #ifdef DJGPP
418
84825cc6f049 updated for version 7.0109
vimboss
parents: 370
diff changeset
3082 vim_strncpy(s, "PC (32 bits Vim)", len - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 #else
418
84825cc6f049 updated for version 7.0109
vimboss
parents: 370
diff changeset
3084 vim_strncpy(s, "PC (16 bits Vim)", len - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 }