1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
13 * MSDOS system-dependent routines.
14 * A cheap plastic imitation of the amiga dependent code.
15 * A lot in this file was made by Juergen Weigert (jw).
17 * DJGPP changes by Gert van Antwerpen
18 * Faster text screens by John Lange (jlange@zilker.net)
19 * Windows clipboard functionality added by David Kotchan (dk)
21 * Some functions are also used for Win16 (MS-Windows 3.1).
33 * MS-DOS only code, not used for Win16.
42 # include <sys/movedata.h>
44 # ifdef FEAT_CLIPBOARD
45 # include <sys/segments.h>
51 #if defined(DJGPP) || defined(PROTO)
52 # define _cdecl /* DJGPP doesn't have this */
55 static int cbrk_pressed
= FALSE
; /* set by ctrl-break interrupt */
56 static int ctrlc_pressed
= FALSE
; /* set when ctrl-C or ctrl-break detected */
57 static int delayed_redraw
= FALSE
; /* set when ctrl-C detected */
59 static int bioskey_read
= _NKEYBRD_READ
; /* bioskey() argument: read key */
60 static int bioskey_ready
= _NKEYBRD_READY
; /* bioskey() argument: key ready? */
63 static int mouse_avail
= FALSE
; /* mouse present */
64 static int mouse_active
; /* mouse enabled */
65 static int mouse_hidden
; /* mouse not shown */
66 static int mouse_click
= -1; /* mouse status */
67 static int mouse_last_click
= -1; /* previous status at click */
68 static int mouse_x
= -1; /* mouse x coordinate */
69 static int mouse_y
= -1; /* mouse y coordinate */
70 static long mouse_click_time
= 0; /* biostime() of last click */
71 static int mouse_click_count
= 0; /* count for multi-clicks */
72 static int mouse_click_x
= 0; /* x of previous mouse click */
73 static int mouse_click_y
= 0; /* y of previous mouse click */
74 static linenr_T mouse_topline
= 0; /* w_topline at previous mouse click */
76 static int mouse_topfill
= 0; /* w_topfill at previous mouse click */
78 static int mouse_x_div
= 8; /* column = x coord / mouse_x_div */
79 static int mouse_y_div
= 8; /* line = y coord / mouse_y_div */
82 #define BIOSTICK 55 /* biostime() increases one tick about
85 static int orig_attr
= 0x0700; /* video attributes when starting */
87 static int S_iLeft
= 0; /* Scroll window; these are 1 offset */
88 static int S_iTop
= 0;
89 static int S_iRight
= 0;
90 static int S_iBottom
= 0;
93 * Need to remember the values, because we set horizontal and vertical
97 mywindow(int iLeft
, int iTop
, int iRight
, int iBottom
)
103 window(iLeft
, iTop
, iRight
, iBottom
);
108 * For DJGPP, use our own functions for fast text screens. JML 1/18/98
111 unsigned long S_ulScreenBase
= 0xb8000;
112 unsigned short S_uiAttribute
= 0;
113 int S_iCurrentRow
= 0; /* These are 0 offset */
114 int S_iCurrentColumn
= 0;
115 short S_selVideo
; /* Selector for DJGPP direct video transfers */
118 * Use burst writes to improve mch_write speed - VJN 01/10/99
120 unsigned short S_linebuffer
[8000]; /* <VN> enough for 160x50 */
121 unsigned short S_blankbuffer
[256]; /* <VN> max length of console line */
122 unsigned short *S_linebufferpos
= S_linebuffer
;
129 if (S_linebufferpos
!= S_linebuffer
)
131 _dosmemputw(S_linebuffer
, (S_linebufferpos
- S_linebuffer
),
133 + S_iBufferRow
* (Columns
<< 1) + (S_iBufferColumn
<< 1));
134 S_linebufferpos
= S_linebuffer
;
139 mygotoxy(int x
, int y
)
141 S_iCurrentRow
= y
- 1;
142 S_iCurrentColumn
= x
- 1;
146 * Set the system cursor to our cursor position.
151 if (term_console
&& full_screen
)
154 gotoxy(S_iCurrentColumn
+ 1, S_iCurrentRow
+ 1);
159 setblankbuffer(unsigned short uiValue
)
162 static unsigned short olduiValue
= 0;
164 if (olduiValue
!= uiValue
)
166 /* Load blank line buffer with spaces */
167 for (i
= 0; i
< Columns
; ++i
)
168 S_blankbuffer
[i
] = uiValue
;
169 olduiValue
= uiValue
;
176 /* Clear to end of line */
177 setblankbuffer(S_uiAttribute
| ' ');
178 _dosmemputw(S_blankbuffer
, S_iRight
- S_iCurrentColumn
, S_ulScreenBase
179 + (S_iCurrentRow
) * (Columns
<< 1)
180 + (S_iCurrentColumn
<< 1));
186 /* Clear whole screen */
188 int endpoint
= (Rows
* Columns
) << 1;
190 setblankbuffer(S_uiAttribute
| ' ');
192 for (iColumn
= 0; iColumn
< endpoint
; iColumn
+= (Columns
<< 1))
193 _dosmemputw(S_blankbuffer
, Columns
, S_ulScreenBase
+ iColumn
);
201 iColumn
= (S_iLeft
- 1) << 1;
203 /* Copy the lines underneath */
204 for (iRow
= S_iCurrentRow
; iRow
< S_iBottom
- 1; iRow
++)
205 movedata(S_selVideo
, (((iRow
+ 1) * Columns
) << 1) + iColumn
,
206 S_selVideo
, ((iRow
* Columns
) << 1) + iColumn
,
207 (S_iRight
- S_iLeft
+ 1) << 1);
209 /* Clear the new row */
210 setblankbuffer(S_uiAttribute
| ' ');
212 _dosmemputw(S_blankbuffer
, (S_iRight
- S_iLeft
) + 1, S_ulScreenBase
213 + (S_iBottom
- 1) * (Columns
<< 1) + iColumn
);
221 iColumn
= (S_iLeft
- 1) << 1;
223 /* Copy the lines underneath */
224 for (iRow
= S_iBottom
- 1; iRow
>= S_iTop
; iRow
--)
225 movedata(S_selVideo
, (((iRow
- 1) * Columns
) << 1) + iColumn
,
226 S_selVideo
, ((iRow
* Columns
) << 1) + iColumn
,
227 (S_iRight
- S_iLeft
+ 1) << 1);
229 /* Clear the new row */
230 setblankbuffer(S_uiAttribute
| ' ');
232 _dosmemputw(S_blankbuffer
, (S_iRight
- S_iLeft
) + 1, S_ulScreenBase
233 + (S_iTop
- 1) * (Columns
<< 1) + iColumn
);
237 * Scroll the screen one line up, clear the last line.
244 iColumn
= (S_iLeft
- 1) << 1;
246 /* Copy the screen */
247 for (iRow
= S_iTop
; iRow
< S_iBottom
; iRow
++)
248 movedata(S_selVideo
, ((iRow
* Columns
) << 1) + iColumn
,
249 S_selVideo
, (((iRow
- 1) * Columns
) << 1) + iColumn
,
250 (S_iRight
- S_iLeft
+ 1) << 1);
252 /* Clear the bottom row */
253 setblankbuffer(S_uiAttribute
| ' ');
255 _dosmemputw(S_blankbuffer
, (S_iRight
- S_iLeft
) + 1, S_ulScreenBase
256 + (S_iBottom
- 1) * (Columns
<< 1) + iColumn
);
262 unsigned short uiValue
;
267 if (S_iCurrentRow
>= S_iBottom
- S_iTop
)
271 S_iCurrentColumn
= S_iLeft
- 1;
275 else if (iChar
== '\r')
278 S_iCurrentColumn
= S_iLeft
- 1;
280 else if (iChar
== '\b')
283 if (S_iCurrentColumn
>= S_iLeft
)
288 sound(440); /* short beep */
294 uiValue
= S_uiAttribute
| (unsigned char)iChar
;
297 * Normal char - are we starting to buffer?
299 if (S_linebufferpos
== S_linebuffer
)
301 S_iBufferColumn
= S_iCurrentColumn
;
302 S_iBufferRow
= S_iCurrentRow
;
305 *S_linebufferpos
++ = uiValue
;
308 if (S_iCurrentColumn
>= S_iRight
&& S_iCurrentRow
>= S_iBottom
- S_iTop
)
312 S_iCurrentColumn
= S_iLeft
- 1;
321 mytextinit(struct text_info
*pTextinfo
)
323 S_selVideo
= __dpmi_segment_to_descriptor(S_ulScreenBase
>> 4);
324 S_uiAttribute
= pTextinfo
->normattr
<< 8;
330 static union REGS regs
;
332 /* old Hercules grafic card has different base address (Macewicz) */
334 (void)int86(0x10, ®s
, ®s
); /* int 10 0f */
335 if (regs
.h
.al
== 0x07) /* video mode 7 -- hercules mono */
336 S_ulScreenBase
= 0xb0000;
338 S_ulScreenBase
= 0xb8000;
342 mytextattr(int iAttribute
)
344 S_uiAttribute
= (unsigned short)iAttribute
<< 8;
350 mytextattr(orig_attr
);
354 mytextcolor(int iTextColor
)
356 S_uiAttribute
= (unsigned short)((S_uiAttribute
& 0xf000)
357 | (unsigned short)iTextColor
<< 8);
361 mytextbackground(int iBkgColor
)
363 S_uiAttribute
= (unsigned short)((S_uiAttribute
& 0x0f00)
364 | (unsigned short)(iBkgColor
<< 12));
367 * Getdigits: Get a number from a string and skip over it.
368 * Note: the argument is a pointer to a char_u pointer!
379 if (*p
== '-') /* skip negative sign */
381 while (VIM_ISDIGIT(*p
))
383 retval
= (retval
* 10) + (*p
- '0');
386 if (**pp
== '-') /* process negative sign */
393 # define mygotoxy gotoxy
394 # define myputch putch
395 # define myscroll scroll
396 # define mynormvideo normvideo
397 # define mytextattr textattr
398 # define mytextcolor textcolor
399 # define mytextbackground textbackground
400 # define mygetdigits getdigits
401 # define myclreol clreol
402 # define myclrscr clrscr
403 # define myinsline insline
404 # define mydelline delline
413 {0x1e, 0xe1}, /* a */
414 {0x30, 0xe2}, /* b */
415 {0x2e, 0xe3}, /* c */
416 {0x20, 0xe4}, /* d */
417 {0x12, 0xe5}, /* e */
418 {0x21, 0xe6}, /* f */
419 {0x22, 0xe7}, /* g */
420 {0x23, 0xe8}, /* h */
421 {0x17, 0xe9}, /* i */
422 {0x24, 0xea}, /* j */
423 {0x25, 0xeb}, /* k */
424 {0x26, 0xec}, /* l */
425 {0x32, 0xed}, /* m */
426 {0x31, 0xee}, /* n */
427 {0x18, 0xef}, /* o */
428 {0x19, 0xf0}, /* p */
429 {0x10, 0xf1}, /* q */
430 {0x13, 0xf2}, /* r */
431 {0x1f, 0xf3}, /* s */
432 {0x14, 0xf4}, /* t */
433 {0x16, 0xf5}, /* u */
434 {0x2f, 0xf6}, /* v */
435 {0x11, 0xf7}, /* w */
436 {0x2d, 0xf8}, /* x */
437 {0x15, 0xf9}, /* y */
438 {0x2c, 0xfa}, /* z */
439 {0x78, 0xb1}, /* 1 */
440 {0x79, 0xb2}, /* 2 */
441 {0x7a, 0xb3}, /* 3 */
442 {0x7b, 0xb4}, /* 4 */
443 {0x7c, 0xb5}, /* 5 */
444 {0x7d, 0xb6}, /* 6 */
445 {0x7e, 0xb7}, /* 7 */
446 {0x7f, 0xb8}, /* 8 */
447 {0x80, 0xb9}, /* 9 */
448 {0x81, 0xb0}, /* 0 */
452 * Translate extended keycodes into meta-chars where applicable
455 translate_altkeys(int rawkey
)
459 if ((rawkey
& 0xff) == 0)
462 for (i
= sizeof(altkey_table
) / sizeof(altkey_table
[0]); --i
>= 0; )
464 if (c
== altkey_table
[i
].scancode
)
465 return (int)altkey_table
[i
].metakey
;
472 * Set normal fg/bg color, based on T_ME. Called when t_me has been set.
475 mch_set_normal_colors()
480 cterm_normal_fg_color
= (orig_attr
& 0xf) + 1;
481 cterm_normal_bg_color
= ((orig_attr
>> 4) & 0xf) + 1;
482 if (T_ME
[0] == ESC
&& T_ME
[1] == '|')
486 if (*p
== 'm' && n
> 0)
488 cterm_normal_fg_color
= (n
& 0xf) + 1;
489 cterm_normal_bg_color
= ((n
>> 4) & 0xf) + 1;
494 #if defined(MCH_CURSOR_SHAPE) || defined(PROTO)
496 * Save/restore the shape of the cursor.
497 * call with FALSE to save, TRUE to restore
500 mch_restore_cursor_shape(int restore
)
502 static union REGS regs
;
503 static int saved
= FALSE
;
508 regs
.h
.ah
= 0x01; /* Set Cursor */
514 regs
.h
.ah
= 0x03; /* Get Cursor */
515 regs
.h
.bh
= 0x00; /* Page */
519 (void)int86(0x10, ®s
, ®s
);
523 * Set the shape of the cursor.
524 * 'thickness' can be from 0 (thin) to 7 (block)
527 mch_set_cursor_shape(int thickness
)
531 regs
.h
.ch
= 7 - thickness
; /* Starting Line */
532 regs
.h
.cl
= 7; /* Ending Line */
533 regs
.h
.ah
= 0x01; /* Set Cursor */
534 (void)int86(0x10, ®s
, ®s
);
538 mch_update_cursor(void)
544 * How the cursor is drawn depends on the current mode.
546 idx
= get_shape_idx(FALSE
);
548 if (shape_table
[idx
].shape
== SHAPE_BLOCK
)
551 thickness
= (7 * shape_table
[idx
].percentage
+ 90) / 100;
552 mch_set_cursor_shape(thickness
);
557 * Return amount of memory currently available.
560 mch_avail_mem(int special
)
563 return _go32_dpmi_remaining_virtual_memory();
572 * Set area where mouse can be moved to: The whole screen.
573 * Rows and Columns must be valid when calling!
582 regs
.x
.cx
= 0; /* mouse visible between cx and dx */
583 regs
.x
.dx
= Columns
* mouse_x_div
- 1;
585 (void)int86(0x33, ®s
, ®s
);
587 regs
.x
.cx
= 0; /* mouse visible between cx and dx */
588 regs
.x
.dx
= Rows
* mouse_y_div
- 1;
590 (void)int86(0x33, ®s
, ®s
);
597 static int was_on
= FALSE
;
602 if (!mouse_active
|| mouse_hidden
)
605 * Careful: Each switch on must be compensated by exactly one switch
608 if ((on
&& !was_on
) || (!on
&& was_on
))
611 regs
.x
.ax
= on
? 1 : 2;
612 int86(0x33, ®s
, ®s
); /* show mouse */
622 * Version of kbhit() and getch() that use direct console I/O.
623 * This avoids trouble with CTRL-P and the like, and should work over a telnet
624 * connection (it works for Xvi).
627 static int cons_key
= -1;
630 * Try to get one character directly from the console.
631 * If there is a key, it is stored in cons_key.
632 * Only call when cons_key is -1!
639 /* call DOS function 6: Direct console I/O */
642 (void)intdos(®s
, ®s
);
643 if ((regs
.x
.flags
& 0x40) == 0) /* zero flag not set? */
644 cons_key
= (regs
.h
.al
& 0xff);
648 * Return TRUE if a character is available.
655 return (cons_key
>= 0);
659 * Return a character from the console.
660 * Should only be called when vim_kbhit() returns TRUE.
677 * DJGPP provides a kbhit() function that goes to the BIOS instead of DOS.
678 * This doesn't work for terminals connected to a serial port.
679 * Redefine kbhit() here to make it work.
687 (void)intdos(®s
, ®s
);
692 # undef kbhit /* might have been defined in conio.h */
694 #define kbhit() vim_kbhit()
699 * Simulate WaitForChar() by slowly polling with bioskey(1) or kbhit().
701 * If Vim should work over the serial line after a 'ctty com1' we must use
702 * kbhit() and getch(). (jw)
703 * Usually kbhit() is not used, because then CTRL-C and CTRL-P
704 * will be catched by DOS (mool).
706 * return TRUE if a character is available, FALSE otherwise
709 #define FOREVER 1999999999L
712 WaitForChar(long msec
)
717 starttime
= biostime(0, 0L);
723 static int old_status
= 0;
727 if (mouse_avail
&& mouse_active
&& mouse_click
< 0)
730 int86(0x33, ®s
, ®s
); /* check mouse status */
731 /* only recognize button-down and button-up event */
732 x
= regs
.x
.cx
/ mouse_x_div
;
733 y
= regs
.x
.dx
/ mouse_y_div
;
734 if ((old_status
== 0) != (regs
.x
.bx
== 0))
736 if (old_status
) /* button up */
737 mouse_click
= MOUSE_RELEASE
;
738 else /* button down */
741 * Translate MSDOS mouse events to Vim mouse events.
742 * TODO: should handle middle mouse button, by pressing
743 * left and right at the same time.
745 if (regs
.x
.bx
& MSDOS_MOUSE_LEFT
)
746 mouse_click
= MOUSE_LEFT
;
747 else if (regs
.x
.bx
& MSDOS_MOUSE_RIGHT
)
748 mouse_click
= MOUSE_RIGHT
;
749 else if (regs
.x
.bx
& MSDOS_MOUSE_MIDDLE
)
750 mouse_click
= MOUSE_MIDDLE
;
753 * Find out if this is a multi-click
755 clicktime
= biostime(0, 0L);
756 if (mouse_click_x
== x
&& mouse_click_y
== y
757 && mouse_topline
== curwin
->w_topline
759 && mouse_topfill
== curwin
->w_topfill
761 && mouse_click_count
!= 4
762 && mouse_click
== mouse_last_click
763 && clicktime
< mouse_click_time
764 + p_mouset
/ BIOSTICK
)
767 mouse_click_count
= 1;
768 mouse_click_time
= clicktime
;
769 mouse_last_click
= mouse_click
;
772 mouse_topline
= curwin
->w_topline
;
774 mouse_topfill
= curwin
->w_topfill
;
776 SET_NUM_MOUSE_CLICKS(mouse_click
, mouse_click_count
);
779 else if (old_status
&& (x
!= mouse_x
|| y
!= mouse_y
))
780 mouse_click
= MOUSE_DRAG
;
781 old_status
= regs
.x
.bx
;
782 if (mouse_hidden
&& mouse_x
>= 0 && (mouse_x
!= x
|| mouse_y
!= y
))
784 mouse_hidden
= FALSE
;
792 if ((p_consk
? cons_kbhit()
793 : p_biosk
? bioskey(bioskey_ready
) : kbhit())
801 * Use biostime() to wait until our time is done.
802 * We busy-wait here. Unfortunately, delay() and usleep() have been
803 * reported to give problems with the original Windows 95. This is
804 * fixed in service pack 1, but not everybody installed that.
805 * The DJGPP implementation of usleep() uses a busy-wait loop too.
807 if (msec
== 0 || (msec
!= FOREVER
808 && biostime(0, 0L) > starttime
+ msec
/ BIOSTICK
))
812 /* Yield the CPU to the next process. */
820 * don't do anything for about "msec" msec
832 * We busy-wait here. Unfortunately, delay() and usleep() have been
833 * reported to give problems with the original Windows 95. This is
834 * fixed in service pack 1, but not everybody installed that.
836 starttime
= biostime(0, 0L);
837 while (biostime(0, 0L) < starttime
+ msec
/ BIOSTICK
)
845 * mch_write(): write the output buffer to the screen
855 if (term_console
&& full_screen
)
858 /* translate ESC | sequences into bios calls */
859 if (p_wd
) /* testing: wait a bit for each char */
866 S_iCurrentColumn
= S_iLeft
- 1;
871 else if (s
[0] == ESC
&& len
> 1 && s
[1] == '|')
876 case 'B': ScreenVisualBell();
919 row
= mygetdigits(&p
); /* no check for length! */
925 col
= mygetdigits(&p
); /* no check for length! */
928 if (*p
== 'H' || *p
== 'r' || *p
== 'V')
933 if (*p
== 'H') /* set cursor position */
936 mywindow(row
, S_iTop
, col
, S_iBottom
);
937 else /* set scroll region */
938 mywindow(S_iLeft
, row
, S_iRight
, col
);
944 else if (*p
== 'm' || *p
== 'f' || *p
== 'b')
946 if (*p
== 'm') /* set color */
949 mynormvideo();/* reset color */
953 else if (*p
== 'f') /* set foreground color */
955 else /* set background color */
956 mytextbackground(row
);
968 write(1, s
, (unsigned)len
);
973 * mch_inchar(): low level input funcion.
974 * Get a characters from the keyboard.
975 * If time == 0 do not wait for characters.
976 * If time == n wait a short time for characters.
977 * If time == -1 wait forever for characters.
979 * return the number of characters obtained
991 static int nextchar
= 0; /* may keep character when maxlen == 1 */
994 * if we got a ctrl-C when we were busy, there will be a "^C" somewhere
995 * on the sceen, so we need to redisplay it.
999 delayed_redraw
= FALSE
;
1000 update_screen(CLEAR
);
1005 /* return remaining character from last call */
1022 if (WaitForChar(time
) == 0) /* no character available */
1030 else /* time == -1 */
1033 * If there is no character available within 2 seconds (default)
1034 * write the autoscript file to disk. Or cause the CursorHold event
1037 if (WaitForChar(p_ut
) == 0)
1040 if (trigger_cursorhold() && maxlen
>= 3)
1044 buf
[2] = (int)KE_CURSORHOLD
;
1051 WaitForChar(FOREVER
); /* wait for key or mouse click */
1054 * Try to read as many characters as there are, until the buffer is full.
1057 * we will get at least one key. Get more if they are available
1058 * After a ctrl-break we have to read a 0 (!) from the buffer.
1059 * bioskey(1) will return 0 if no key is available and when a
1060 * ctrl-break was typed. When ctrl-break is hit, this does not always
1061 * implies a key hit.
1063 cbrk_pressed
= FALSE
;
1065 if (mouse_click
>= 0 && maxlen
>= 5)
1070 *buf
++ = mouse_click
;
1071 *buf
++ = mouse_x
+ '!';
1072 *buf
++ = mouse_y
+ '!';
1079 mouse_hidden
= TRUE
;
1081 if (p_biosk
&& !p_consk
)
1083 while ((len
== 0 || bioskey(bioskey_ready
)) && len
< maxlen
)
1085 c
= translate_altkeys(bioskey(bioskey_read
)); /* get the key */
1087 * translate a few things for inchar():
1088 * 0x0000 == CTRL-break -> 3 (CTRL-C)
1089 * 0x0300 == CTRL-@ -> NUL
1090 * 0xnn00 == extended key code -> K_NUL, nn
1091 * 0xnne0 == enhanced keyboard -> K_NUL, nn
1096 else if (c
== 0x0300)
1098 else if ((c
& 0xff) == 0
1103 || ((c
& 0xff) == 0xe0 && c
!= 0xe0))
1118 /* Convert from 'termencoding' to 'encoding'. Only
1119 * translate normal characters, not key codes. */
1120 if (input_conv
.vc_type
!= CONV_NONE
1121 && (len
== 1 || buf
[-2] != K_NUL
))
1122 len
+= convert_input(buf
- 1, 1, maxlen
- len
+ 1) - 1;
1131 while ((len
== 0 || (p_consk
? cons_kbhit() : kbhit()))
1134 switch (c
= (p_consk
? cons_getch() : getch()))
1137 /* NUL means that there is another character.
1138 * Get it immediately, because kbhit() doesn't always
1139 * return TRUE for the second character.
1145 tmp_c
= translate_altkeys(c
<< 8);
1146 if (tmp_c
== (c
<< 8))
1160 cbrk_pressed
= TRUE
;
1179 beep_count
= 0; /* may beep again now that we got some chars */
1184 * return non-zero if a character is available
1187 mch_char_avail(void)
1189 return WaitForChar(0L);
1193 # define INT_ARG int
1199 * function for ctrl-break interrupt
1201 static void interrupt
1208 cbrk_pressed
= TRUE
;
1209 ctrlc_pressed
= TRUE
;
1214 * ctrl-break handler for DOS. Never called when a ctrl-break is typed, because
1215 * we catch interrupt 1b. If you type ctrl-C while Vim is waiting for a
1216 * character this function is not called. When a ctrl-C is typed while Vim is
1217 * busy this function may be called. By that time a ^C has been displayed on
1218 * the screen, so we have to redisplay the screen. We can't do that here,
1219 * because we may be called by DOS. The redraw is in mch_inchar().
1224 delayed_redraw
= TRUE
;
1225 return 1; /* resume operation after ctrl-break */
1229 * function for critical error interrupt
1230 * For DOS 1 and 2 return 0 (Ignore).
1231 * For DOS 3 and later return 3 (Fail)
1233 static void interrupt
1234 catch_cint(bp
, di
, si
, ds
, es
, dx
, cx
, bx
, ax
)
1235 unsigned bp
, di
, si
, ds
, es
, dx
, cx
, bx
, ax
;
1237 ax
= (ax
& 0xff00); /* set AL to 0 */
1239 ax
|= 3; /* set AL to 3 */
1244 * Set the interrupt vectors for use with Vim on or off.
1245 * on == TRUE means as used within Vim
1248 set_interrupts(int on
)
1250 static int saved_cbrk
;
1252 static void interrupt (*old_cint
)();
1254 static void interrupt (*old_cbrk
)(INT_ARG
);
1258 saved_cbrk
= getcbrk(); /* save old ctrl-break setting */
1259 setcbrk(0); /* do not check for ctrl-break */
1261 old_cbrk
= signal(SIGINT
, catch_cbrk
); /* critical error interrupt */
1263 old_cint
= getvect(0x24); /* save old critical error interrupt */
1264 setvect(0x24, catch_cint
); /* install our critical error interrupt */
1265 old_cbrk
= getvect(0x1B); /* save old ctrl-break interrupt */
1266 setvect(0x1B, catch_cbrk
); /* install our ctrl-break interrupt */
1267 ctrlbrk(cbrk_handler
); /* vim's ctrl-break handler */
1270 out_str(T_ME
); /* set colors */
1274 setcbrk(saved_cbrk
); /* restore ctrl-break setting */
1276 signal(SIGINT
,old_cbrk
); /* critical error interrupt */
1278 setvect(0x24, old_cint
); /* restore critical error interrupt */
1279 setvect(0x1B, old_cbrk
); /* restore ctrl-break interrupt */
1281 /* restore ctrl-break handler, how ??? */
1283 mynormvideo(); /* restore screen colors */
1288 * We have no job control, fake it by starting a new shell.
1299 * Prepare window for use by Vim.
1306 #if defined(DJGPP) && defined(FEAT_CLIPBOARD)
1307 __dpmi_regs dpmi_regs
;
1311 * Get the video attributes at the cursor. These will be used as the
1312 * default attributes.
1315 regs
.h
.bh
= 0x00; /* video page 0 */
1316 int86(0x10, ®s
, ®s
);
1317 orig_attr
= regs
.h
.ah
;
1319 if (cterm_normal_fg_color
== 0)
1320 cterm_normal_fg_color
= (orig_attr
& 0xf) + 1;
1321 if (cterm_normal_bg_color
== 0)
1322 cterm_normal_bg_color
= ((orig_attr
>> 4) & 0xf) + 1;
1324 term_console
= TRUE
; /* assume using the console for the things here */
1325 _fmode
= O_BINARY
; /* we do our own CR-LF translation */
1327 set_interrupts(TRUE
); /* catch interrupts */
1331 * Use Long File Names by default, if $LFN not set.
1333 if (getenv("LFN") == NULL
)
1340 /* find out if a MS compatible mouse is available */
1342 (void)int86(0x33, ®s
, ®s
);
1343 mouse_avail
= regs
.x
.ax
;
1344 /* best guess for mouse coordinate computations */
1345 mch_get_shellsize();
1353 * Try switching to 16 colors for background, instead of 8 colors and
1354 * blinking. Does this always work? Can the old value be restored?
1359 int86(0x10, ®s
, ®s
);
1362 * Test if we have an enhanced AT keyboard. Write 0xFFFF to the keyboard
1363 * buffer and try to read it back. If we can't in 16 tries, it's an old
1368 int86(0x16, ®s
, ®s
);
1369 if (regs
.h
.al
!= 1) /* skip this when keyboard buffer is full */
1373 for (i
= 0; i
< 16; ++i
)
1376 int86(0x16, ®s
, ®s
);
1377 if (regs
.x
.ax
== 0xffff)
1380 if (i
== 16) /* 0xffff not read, must be old keyboard */
1387 #ifdef MCH_CURSOR_SHAPE
1388 /* Save the old cursor shape */
1389 mch_restore_cursor_shape(FALSE
);
1390 /* Initialise the cursor shape */
1391 mch_update_cursor();
1394 #if defined(DJGPP) && defined(FEAT_CLIPBOARD)
1396 * Check to see if the Windows clipboard is available, ie. are we
1397 * running from a DOS session within Windows. Obviously, the Windows
1398 * clipboard will not be available if we're running under pure DOS.
1400 * int 0x2f, AX = 0x1700 identifies the Windows version we're running
1401 * under. Upon return from the interrupt, if AX is unchanged, we're
1402 * running under pure DOS and no Windows clipboard is available.
1404 * Remark: could use int86() here but __dpmi_int() is recommended in
1405 * the DJGPP docs, since int86() doesn't cover all available interrupts.
1407 dpmi_regs
.x
.ax
= 0x1700;
1408 if (__dpmi_int(0x2f, &dpmi_regs
) == -1)
1409 /* real-mode interrupt failed? */
1410 dpmi_regs
.x
.ax
= 0x1700; /* force failure */
1412 if (dpmi_regs
.x
.ax
== 0x1700) /* no change in AX? */
1413 clip_init(FALSE
); /* no clipboard available, too bad */
1414 else /* else, running under Windows, OK */
1415 clip_init(TRUE
); /* clipboard is available */
1424 /* store argv[0], may be used for $VIM */
1425 if (*argv
[0] != NUL
)
1426 exe_name
= FullName_save((char_u
*)argv
[0], FALSE
);
1429 * Try the DOS search path. The executable may in
1430 * fact be called differently, so try this last.
1432 if (exe_name
== NULL
|| *exe_name
== NUL
)
1433 exe_name
= searchpath("vim.exe");
1441 * Return TRUE if the input comes from a terminal, FALSE otherwise.
1444 mch_input_isatty(void)
1446 if (isatty(read_cmd_fd
))
1451 #if defined(USE_FNAME_CASE) || defined(PROTO)
1453 * fname_case(): Set the case of the file name, if it already exists.
1454 * TODO: should expand short to long file names. Need to use DOS interrupts,
1455 * see DJGPP sources libc/dos/dir/findfirs.c.
1458 fname_case(char_u
*name
, int len
)
1464 if (findfirst(name
, &fb
, 0) == 0)
1466 tail
= gettail(name
);
1467 if (len
== 0 ? STRLEN(tail
) == STRLEN(fb
.ff_name
)
1468 : (tail
- name
) + STRLEN(fb
.ff_name
) < len
)
1469 STRCPY(tail
, fb
.ff_name
);
1484 * Change default drive (just like _chdrive of Borland C 3.1)
1487 change_drive(int drive
)
1492 regs
.h
.dl
= drive
- 1;
1493 intdos(®s
, ®s
); /* set default drive */
1495 intdos(®s
, ®s
); /* get default drive */
1496 if (regs
.h
.al
== drive
- 1)
1502 * Get absolute file name into buffer 'buf' of length 'len' bytes.
1503 * All slashes are replaced with backslashes, to avoid trouble when comparing
1504 * file names. When 'shellslash' set do it the other way around.
1506 * return FAIL for failure, OK otherwise
1515 if (!force
&& mch_isFullName(fname
)) /* already expanded */
1517 vim_strncpy(buf
, fname
, len
- 1);
1522 #ifdef __BORLANDC__ /* Only Borland C++ has this */
1523 if (_fullpath((char *)buf
, (char *)fname
, len
- 1) == NULL
)
1526 #else /* almost the same as mch_FullName() in os_unix.c */
1529 char_u fullpath
[MAXPATHL
];
1531 if (!_truename(fname
, fullpath
))
1533 slash_adjust(fullpath
); /* Only needed when 'shellslash' set */
1534 vim_strncpy(buf
, fullpath
, len
- 1);
1537 # else /* Old code, to be deleted... */
1539 char_u olddir
[MAXPATHL
];
1546 * change to the directory for a moment,
1547 * and then do the getwd() (and get back to where we were).
1548 * This will get the correct path name with "../" things.
1550 p
= vim_strrchr(fname
, '/');
1551 q
= vim_strrchr(fname
, '\\');
1552 if (q
!= NULL
&& (p
== NULL
|| q
> p
))
1554 q
= vim_strrchr(fname
, ':');
1555 if (q
!= NULL
&& (p
== NULL
|| q
> p
))
1559 if (getcwd(olddir
, MAXPATHL
) == NULL
)
1561 p
= NULL
; /* can't get current dir: don't chdir */
1566 if (p
== fname
) /* /fname */
1567 q
= p
+ 1; /* -> / */
1568 else if (q
+ 1 == p
) /* ... c:\foo */
1569 q
= p
+ 1; /* -> c:\ */
1570 else /* but c:\foo\bar */
1571 q
= p
; /* -> c:\foo */
1573 c
= *q
; /* truncate at start of fname */
1577 slash_adjust(buf
); /* needed when fname starts with \ */
1578 if (mch_chdir(buf
)) /* change to the directory */
1580 if (mch_chdir(fname
)) /* change to the directory */
1586 if (c
== psepc
) /* if we cut the name at a */
1587 fname
++; /* '\', don't add it again */
1592 if (getcwd(buf
, len
) == NULL
)
1597 # ifdef USE_FNAME_CASE
1606 /* Apparently "longna~1" isn't expanded by getcwd(), at least not
1607 * for DJGPP. Expand it here. Have to do each dirname
1611 if (isalpha(*head
) && head
[1] == ':')
1612 head
+= 2; /* skip "c:" */
1613 while (*head
!= NUL
)
1615 /* Advance "head" to the start of a dirname and "tail" to just
1617 while (*head
== '/' || *head
== '\\')
1619 for (tail
= head
; *tail
!= NUL
; ++tail
)
1620 if (*tail
== '/' || *tail
== '\\')
1625 if (findfirst(buf
, &fb
, FA_DIREC
) == 0)
1627 added
= STRLEN(fb
.ff_name
);
1628 if ((head
- buf
) + added
+ STRLEN(tail
+ 1) + 2 < len
)
1630 added
-= (tail
- head
);
1632 mch_memmove(tail
+ 1 + added
, tail
+ 1,
1633 STRLEN(tail
+ 1) + 1);
1634 STRCPY(head
, fb
.ff_name
);
1646 * Concatenate the file name to the path.
1651 if (l
> 0 && buf
[l
- 1] != '/' && buf
[l
- 1] != '\\')
1662 * Replace all slashes by backslashes.
1663 * This used to be the other way around, but MS-DOS sometimes has problems
1664 * with slashes (e.g. in a command name). We can't have mixed slashes and
1665 * backslashes, because comparing file names will not work correctly. The
1666 * commands that use a file name should try to avoid the need to type a
1668 * When 'shellslash' set do it the other way around.
1671 slash_adjust(char_u
*p
)
1673 #ifdef OLD_DJGPP /* this seems to have been fixed in DJGPP 2.01 */
1674 /* DJGPP can't handle a file name that starts with a backslash, and when it
1675 * starts with a slash there should be no backslashes */
1676 if (*p
== '\\' || *p
== '/')
1694 * Return TRUE if "fname" does not depend on the current directory.
1697 mch_isFullName(char_u
*fname
)
1699 /* A name like "d:/foo" and "//server/share" is absolute */
1700 return (fname
[0] != NUL
&& fname
[1] == ':'
1701 && (fname
[2] == '/' || fname
[2] == '\\'))
1702 || (fname
[0] == fname
[1] && (fname
[0] == '/' || fname
[0] == '\\'));
1707 mch_early_init(void)
1712 * Careful: mch_exit() may be called before mch_init()!
1717 settmode(TMODE_COOK
);
1719 set_interrupts(FALSE
); /* restore interrupts */
1723 /* Somehow outputting CR-NL causes the original colors to be restored */
1727 ml_close_all(TRUE
); /* remove all memfiles */
1728 #ifdef MCH_CURSOR_SHAPE
1729 mch_restore_cursor_shape(TRUE
);
1735 * set the tty in (raw) ? "raw" : "cooked" mode
1736 * Does not change the tty, as bioskey() and kbhit() work raw all the time.
1739 mch_settmode(int tmode
)
1745 mch_setmouse(int on
)
1748 mouse_hidden
= TRUE
; /* dont show it until moved */
1754 * return FAIL for failure, OK otherwise
1757 mch_screenmode(char_u
*arg
)
1761 static char *(names
[]) = {"BW40", "C40", "BW80", "C80", "MONO", "C4350"};
1762 static int modes
[] = { BW40
, C40
, BW80
, C80
, MONO
, C4350
};
1765 if (VIM_ISDIGIT(*arg
)) /* mode number given */
1766 mode
= atoi((char *)arg
);
1769 for (i
= 0; i
< sizeof(names
) / sizeof(char_u
*); ++i
)
1770 if (stricmp(names
[i
], (char *)arg
) == 0)
1778 EMSG("E362: Unsupported screen mode");
1781 textmode(mode
); /* use Borland function */
1783 /* base address may have changed */
1787 /* Screen colors may have changed. */
1791 if (mode
<= 1 || mode
== 4 || mode
== 5 || mode
== 13 || mode
== 0x13)
1795 if (mode
== 0x11 || mode
== 0x12)
1797 else if (mode
== 0x10)
1807 * Structure used by Turbo-C/Borland-C to store video parameters.
1810 extern struct text_info _video
;
1814 * try to get the real window size
1815 * return FAIL for failure, OK otherwise
1818 mch_get_shellsize(void)
1820 struct text_info textinfo
;
1823 * The screenwidth is returned by the BIOS OK.
1824 * The screenheight is in a location in the bios RAM, if the display is
1829 gettextinfo(&textinfo
);
1830 Columns
= textinfo
.screenwidth
;
1831 Rows
= textinfo
.screenheight
;
1833 if (textinfo
.currmode
> 10)
1834 Rows
= *(char far
*)MK_FP(0x40, 0x84) + 1;
1837 if (Columns
< MIN_COLUMNS
|| Rows
< MIN_LINES
)
1839 /* these values are overwritten by termcap size or default */
1845 mytextinit(&textinfo
); /* Added by JML, 1/15/98 */
1852 * Set the active window for delline/insline.
1860 _video
.screenheight
= Rows
;
1862 mywindow(1, 1, Columns
, Rows
);
1868 mch_set_shellsize(void)
1870 /* Should try to set the window size to Rows and Columns.
1871 * May involve switching display mode....
1872 * We assume the user knows the size and just use it. */
1876 * Rows and/or Columns has changed.
1882 /* best guess for mouse coordinate computations */
1890 mouse_area(); /* set area where mouse can go */
1894 #if defined(DJGPP) || defined(PROTO)
1896 * Check the number of Columns with a BIOS call. This avoids a crash of the
1897 * DOS console when 'columns' is set to a too large value.
1902 static union REGS regs
;
1905 (void)int86(0x10, ®s
, ®s
);
1906 if ((unsigned)Columns
> (unsigned)regs
.h
.ah
)
1907 Columns
= (unsigned)regs
.h
.ah
;
1912 * call shell, return FAIL for failure, OK otherwise
1913 * options: SHELL_*, see vim.h.
1921 int tmode
= cur_tmode
;
1931 if (options
& SHELL_COOKED
)
1932 settmode(TMODE_COOK
); /* set to normal mode */
1933 set_interrupts(FALSE
); /* restore interrupts */
1936 /* ignore signals while external command is running */
1937 signal(SIGINT
, SIG_IGN
);
1938 signal(SIGHUP
, SIG_IGN
);
1939 signal(SIGQUIT
, SIG_IGN
);
1940 signal(SIGTERM
, SIG_IGN
);
1943 x
= system((char *)p_sh
);
1948 * Use 'shell' for system().
1950 setenv("SHELL", (char *)p_sh
, 1);
1953 /* we use "command" to start the shell, slow but easy */
1954 newcmd
= alloc(STRLEN(p_sh
) + STRLEN(p_shcf
) + STRLEN(cmd
) + 3);
1959 sprintf((char *)newcmd
, "%s %s %s", p_sh
, p_shcf
, cmd
);
1960 x
= system((char *)newcmd
);
1966 signal(SIGINT
, SIG_DFL
);
1967 signal(SIGHUP
, SIG_DFL
);
1968 signal(SIGQUIT
, SIG_DFL
);
1969 signal(SIGTERM
, SIG_DFL
);
1971 if (tmode
== TMODE_RAW
)
1972 settmode(TMODE_RAW
); /* set to raw mode */
1973 set_interrupts(TRUE
); /* catch interrupts */
1975 if (x
&& !(options
& SHELL_SILENT
) && !emsg_silent
)
1977 MSG_PUTS("\nshell returned ");
1978 msg_outnum((long)x
);
1986 * check for an "interrupt signal": CTRL-break or CTRL-C
1989 mch_breakcheck(void)
1993 ctrlc_pressed
= FALSE
;
1999 * Return TRUE if "p" contain a wildcard that can be expanded by
2003 mch_has_exp_wildcard(char_u
*p
)
2005 for ( ; *p
; mb_ptr_adv(p
))
2007 if (vim_strchr((char_u
*)"?*[", *p
) != NULL
2008 || (*p
== '~' && p
[1] != NUL
))
2015 * Return TRUE if "p" contain a wildcard or a "~1" kind of thing (could be a
2016 * shortened file name).
2019 mch_has_wildcard(char_u
*p
)
2021 for ( ; *p
; mb_ptr_adv(p
))
2023 if (vim_strchr((char_u
*)
2024 # ifdef VIM_BACKTICK
2030 || (*p
== '~' && p
[1] != NUL
))
2037 * Change directory to "path".
2038 * The normal chdir() does not change the default drive. This one does.
2039 * Return 0 for success, -1 for failure.
2042 mch_chdir(char *path
)
2044 if (path
[0] == NUL
) /* just checking... */
2046 if (path
[1] == ':') /* has a drive name */
2048 if (change_drive(TOLOWER_ASC(path
[0]) - 'a' + 1))
2049 return -1; /* invalid drive name */
2052 if (*path
== NUL
) /* drive name only */
2054 return chdir(path
); /* let the normal chdir() do the rest */
2059 * mch_rename() works around a bug in rename (aka MoveFile) in
2060 * Windows 95: rename("foo.bar", "foo.bar~") will generate a
2061 * file whose short file name is "FOO.BAR" (its long file name will
2062 * be correct: "foo.bar~"). Because a file can be accessed by
2063 * either its SFN or its LFN, "foo.bar" has effectively been
2064 * renamed to "foo.bar", which is not at all what was wanted. This
2065 * seems to happen only when renaming files with three-character
2066 * extensions by appending a suffix that does not include ".".
2067 * Windows NT gets it right, however, with an SFN of "FOO~1.BAR".
2068 * This works like mch_rename in os_win32.c, but is a bit simpler.
2070 * Like rename(), returns 0 upon success, non-zero upon failure.
2071 * Should probably set errno appropriately when errors occur.
2075 mch_rename(const char *OldFile
, const char *NewFile
)
2081 /* rename() works correctly without long file names, so use that */
2083 return rename(OldFile
, NewFile
);
2085 if ((TempFile
= alloc((unsigned)(STRLEN(OldFile
) + 13))) == NULL
)
2088 STRCPY(TempFile
, OldFile
);
2089 STRCPY(gettail(TempFile
), "axlqwqhy.ba~");
2090 if (rename(OldFile
, TempFile
))
2094 /* now create an empty file called OldFile; this prevents
2095 * the operating system using OldFile as an alias (SFN)
2096 * if we're renaming within the same directory. For example,
2097 * we're editing a file called filename.asc.txt by its SFN,
2098 * filena~1.txt. If we rename filena~1.txt to filena~1.txt~
2099 * (i.e., we're making a backup while writing it), the SFN
2100 * for filena~1.txt~ will be filena~1.txt, by default, which
2101 * will cause all sorts of problems later in buf_write(). So, we
2102 * create an empty file called filena~1.txt and the system will have
2103 * to find some other SFN for filena~1.txt~, such as filena~2.txt
2105 if ((fd
= open(OldFile
, O_RDWR
|O_CREAT
|O_EXCL
, 0444)) < 0)
2107 retval
= rename(TempFile
, NewFile
);
2109 mch_remove((char_u
*)OldFile
);
2111 /* If renaming to NewFile failed, rename TempFile back to OldFile, so
2112 * that it looks like nothing happened. */
2114 rename(TempFile
, OldFile
);
2118 return retval
; /* success */
2122 #if defined(DJGPP) || defined(PROTO)
2124 * setlocale() for DJGPP with MS-DOS codepage support
2125 * Author: Cyril Slobin <slobin@fe.msk.ru>
2127 * Scaled down a lot for use by Vim: Only support setlocale(LC_ALL, "").
2133 #include <inlines/ctype.ha>
2136 #define UPCASE (__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER)
2137 #define LOCASE (__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISLOWER)
2140 djgpp_setlocale(void)
2143 struct { char id
; unsigned short off
, seg
; } __attribute__ ((packed
)) info
;
2144 unsigned char buffer
[0x82], lower
, upper
;
2151 regs
.x
.es
= __tb
>> 4;
2152 regs
.x
.di
= __tb
& 0xf;
2154 __dpmi_int(0x21, ®s
);
2156 if (regs
.x
.flags
& 1)
2159 dosmemget(__tb
, 5, &info
);
2160 dosmemget((info
.seg
<< 4) + info
.off
, 0x82, buffer
);
2162 if (*(short *)buffer
!= 0x80)
2165 /* Fix problem of underscores being replaced with y-umlaut. (Levin) */
2166 if (buffer
[26] == 0x5f)
2169 for (i
= 0; i
< 0x80; i
++)
2172 upper
= (buffer
+2)[i
];
2175 __dj_ctype_flags
[lower
+1] = LOCASE
;
2176 __dj_ctype_toupper
[lower
+1] = upper
;
2177 if (__dj_ctype_flags
[upper
+1] == 0)
2178 __dj_ctype_flags
[upper
+1] = UPCASE
;
2179 if (__dj_ctype_tolower
[upper
+1] == upper
)
2180 __dj_ctype_tolower
[upper
+1] = lower
;
2187 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
2190 * Clipboard stuff, for cutting and pasting text to other windows.
2192 * Implementation of DOS/Windows clipboard data transfer
2193 * by David Kotchan (dkotchan@sympatico.ca)
2196 #define CF_TEXT 0x01 /* Windows clipboard format: Windows (ANSI) text */
2197 #define CF_OEMTEXT 0x07 /* Windows clipboard format: OEM (DOS) text */
2198 #define CF_VIMCLIP 0x04 /* trick: SYLK clipboard format for VimClipboard */
2200 static int Win16OpenClipboard(void);
2201 static int Win16CloseClipboard(void);
2202 static int Win16EmptyClipboard(void);
2203 static char_u
*Win16GetClipboardData(int clip_data_format
);
2204 static int Win16SetClipboardData(int clip_data_format
, char_u
*clip_data
, int clip_data_size
, int clip_data_type
);
2207 * Make vim the owner of the current selection. Return OK upon success.
2210 clip_mch_own_selection(VimClipboard
*cbd
)
2213 * Never actually own the clipboard. If another application sets the
2214 * clipboard, we don't want to think that we still own it.
2220 * Make vim NOT the owner of the current selection.
2223 clip_mch_lose_selection(VimClipboard
*cbd
)
2225 /* Nothing needs to be done here */
2229 * Read the Windows clipboard text and put it in Vim's clipboard register.
2232 clip_mch_request_selection(VimClipboard
*cbd
)
2235 char_u
*pAllocated
= NULL
;
2236 char_u
*pClipText
= NULL
;
2237 int clip_data_format
= 0;
2239 if (Win16OpenClipboard())
2241 /* Check for Vim's own clipboard format first. The CF_VIMCLIP format
2242 * is just ordinary text (like CF_TEXT) except prepended by the
2243 * selection type (as a single character). Note that under DOS we
2244 * actually cannot define a custom CF_VIMCLIP clipboard format; we
2245 * use instead one of the existing Windows-defined formats, usually
2246 * "DIF" or "SYLK". See Win16GetClipboardData() for details.
2248 * Note that Win16GetClipboardData() returns the address of the memory
2249 * block it allocated. This is not necessary the start of the
2250 * clipboard text data: there may be other bytes ahead of the
2251 * text (particularly for CF_VIMCLIP) which are used for data
2252 * management. So pClipText is not necessarily == pAllocated.
2255 if ((pAllocated
= Win16GetClipboardData(CF_VIMCLIP
)) != NULL
)
2257 clip_data_format
= CF_VIMCLIP
;
2258 pClipText
= pAllocated
;
2260 switch (*pClipText
++) /* after ++, pClipText points to text */
2263 case 'L': type
= MLINE
; break;
2264 case 'C': type
= MCHAR
; break;
2266 case 'B': type
= MBLOCK
; break;
2271 /* Otherwise, check for the normal Windows text formats. There are
2272 * two of these: CF_TEXT (common) and CF_OEMTEXT (used for DOS
2273 * compatibility). Experiments show that, under the DOS/Windows
2274 * clipboard interface, writing CF_TEXT data to the clipboard
2275 * automatically creates a CF_OEMTEXT format as well.
2278 else if ((pAllocated
= Win16GetClipboardData(CF_TEXT
)) != NULL
)
2280 clip_data_format
= CF_TEXT
;
2281 pClipText
= pAllocated
;
2282 type
= (vim_strchr((char*)pClipText
, '\r') != NULL
) ? MLINE
: MCHAR
;
2285 else if ((pAllocated
= Win16GetClipboardData(CF_OEMTEXT
)) != NULL
)
2287 clip_data_format
= CF_OEMTEXT
;
2288 pClipText
= pAllocated
;
2289 type
= (vim_strchr((char*)pClipText
, '\r') != NULL
) ? MLINE
: MCHAR
;
2292 /* Did we get anything? */
2294 if (pClipText
!= NULL
)
2300 long_u clip_data_size
= 0;
2302 /* The Windows clipboard normally stores its text lines terminated
2303 * by <CR><NL>. But Vim uses only <NL>, so translate the <CR><NL>
2304 * into <NL>. Also, watch for possible null bytes at the end of
2305 * pClipText. These are padding added by "get_clipboard_data"
2306 * (int 0x2f, AX= 0x1705) in order to round the data size up to the
2307 * next multiple of 32 bytes. See Win16GetClipboardData() for
2311 pDest
= strstr( pClipText
, "\r\n" ); /* find first <CR><NL> */
2313 if (pDest
!= NULL
) /* found one? */
2315 pStart
= pDest
+ 1; /* points to <NL> after <CR> */
2316 pEnd
= strstr( pStart
, "\r\n" );/* find next <CR><NL> */
2318 while (pEnd
!= NULL
) /* found one? */
2320 memmove(pDest
, pStart
, (long)(pEnd
- pStart
));
2322 pDest
+= (long)(pEnd
- pStart
); /* new destination */
2323 pStart
= pEnd
+ 1; /* new starting point */
2324 pEnd
= strstr(pStart
, "\r\n"); /* find next <CR><NL> */
2327 /* Fell out of while() loop: no more <CR><NL> pairs. Just copy
2328 * the rest of the data, up to the first null byte. */
2329 pEnd
= strchr(pStart
, '\0'); /* find first null */
2331 memmove(pDest
, pStart
, (long)(pEnd
- pStart
)); /* exclude nul */
2332 pDest
+= (long)(pEnd
- pStart
);
2333 *pDest
= '\0'; /* terminate */
2335 /* Now that all <CR><NL> pairs have been "compressed" into just
2336 * <NL>'s, determine the true text length. */
2337 clip_data_size
= (long_u
)(pDest
- pClipText
);
2341 /* no <CR><NL> pairs at all */
2342 /* Since the data may have been padded with trailing nulls,
2343 * determine the true string length. */
2344 clip_data_size
= STRLEN(pClipText
); /* true data length */
2347 /* Copy the cleaned-up data over to Vim's clipboard "*" register. */
2348 clip_yank_selection(type
, pClipText
, clip_data_size
, cbd
);
2350 /* Free the memory that Win16GetClipboardData() allocated. */
2351 vim_free(pAllocated
);
2354 Win16CloseClipboard();
2356 } // end if (Win16OpenClipboard())
2360 * Send the currently selected Vim text to the Windows clipboard.
2363 clip_mch_set_selection( VimClipboard
*cbd
)
2365 char_u
*pClipData
= NULL
;
2366 long_u clip_data_size
;
2369 /* If the '*' register isn't already filled in, fill it in now. */
2371 clip_get_selection(cbd
);
2375 * clip_convert_selection() returns a pointer to a buffer containing
2376 * the text to send to the Windows clipboard, together with a count
2377 * of the number of characters (bytes) in the buffer. The function's
2378 * return value is the 'type' of selection: MLINE, MCHAR, or MBLOCK;
2379 * or -1 for failure.
2381 clip_data_type
= clip_convert_selection(&pClipData
, &clip_data_size
, cbd
);
2383 if (clip_data_type
< 0) /* could not convert? */
2384 return; /* early exit */
2386 if (Win16OpenClipboard())
2388 if (Win16EmptyClipboard())
2392 sentOK
= Win16SetClipboardData(CF_TEXT
, pClipData
,
2393 clip_data_size
, clip_data_type
);
2394 sentOK
= Win16SetClipboardData(CF_VIMCLIP
,
2395 pClipData
, clip_data_size
, clip_data_type
) && sentOK
;
2399 /* one or both of Win16SetClipboardData() failed. */
2400 /* Technically we don't know why Win16SetClipboardData()
2401 * failed, but almost always it will be because there wasn't
2402 * enough DOS memory to buffer the data, so report that as the
2405 * We report the error here (instead of in
2406 * Win16SetClipboardData()) because we don't want the error
2409 EMSG("E450: Selection too large, cannot allocate DOS buffer");
2413 Win16CloseClipboard();
2416 /* release memory allocated by clip_convert_selection() */
2417 vim_free(pClipData
);
2423 * Win16OpenClipboard: open the Windows clipboard. The clipboard must be open
2424 * before it can be communicated with at all. Return TRUE on success,
2428 Win16OpenClipboard(void)
2430 __dpmi_regs dpmi_regs
;
2435 /* int 02xf, AX = 0x1701 attempts to open the Windows clipboard. Upon
2436 * return from the interrupt, if AX is non-zero, the clipboard was
2437 * successfully opened. If AX is zero, the clipboard could not be opened
2438 * because it is currently in use by another process.
2440 * Remark: other DOS programs I (dk) have written that use the Windows
2441 * clipboard sometimes encounter the problem that the clipboard cannot
2442 * be opened even though it is demonstrably not in use by any other
2443 * process. In all cases, repeated attempts to open the clipboard
2444 * eventually succeed, but the initial attempt occasionally fails.
2446 * The problem is intermittent and appears to be related to DOS being
2447 * "busy" at certain unpredictable times. DOS maintains two internal
2448 * flags that indicate whether it's busy: InDOS and CritErr. The
2449 * location of InDOS can be found by calling int 0x21, AH = 0x34. The
2450 * location of CritErr can be found by calling int 0x21, AX = 0x5d06.
2451 * If either of these flags is set, DOS is "busy" and cannot be
2452 * interrupted. See "Undocumented DOS" by Schulman et al for details.
2454 * However here I take the easier approach that if the first call to open
2455 * the clipboard does not succeed, just try again. In fact, try once per
2456 * biostime() clock tick, up to 18 times (about one second).
2461 dpmi_regs
.x
.ax
= 0x1701; /* open Windows clipboard */
2462 if (__dpmi_int(0x2f, &dpmi_regs
) == -1)
2464 /* real-mode interrupt failed? */
2465 return FALSE
; /* FALSE --> clipboard not open */
2468 /* wait up to one second */
2469 while (dpmi_regs
.x
.ax
== 0 && tick_count
++ < 18)
2471 /* Wait one clock tick (18.2 ticks/sec = 55 msec per tick).
2473 * We busy-wait here. Unfortunately, delay() and usleep() have been
2474 * reported to give problems with the original Windows 95. This is
2475 * fixed in service pack 1, but not everybody installed that.
2477 start_time
= biostime(0, 0L);
2478 while (biostime(0, 0L) == start_time
)
2481 dpmi_regs
.x
.ax
= 0x1701; /* open Windows clipboard */
2482 if (__dpmi_int(0x2f, &dpmi_regs
) == -1)
2484 /* real-mode interrupt failed? */
2485 return FALSE
; /* FALSE --> clipboard not open */
2489 /* Couldn't open the clipboard, even after 18 attempts? */
2491 if (tick_count
>= 18 && dpmi_regs
.x
.ax
== 0)
2492 return FALSE
; /* FALSE --> clipboard not open */
2494 return TRUE
; /* TRUE --> clipboard opened successfully, OK */
2498 * Win16CloseClipboard: close the Windows clipboard. Return TRUE on
2499 * success, FALSE on failure. This function can always be called,
2500 * whether the clipboard is open or not.
2503 Win16CloseClipboard(void)
2505 __dpmi_regs dpmi_regs
;
2507 /* Close the clipboard. This interrupt can always be called, even
2508 * if the clipboard is already closed.
2511 dpmi_regs
.x
.ax
= 0x1708; /* close the clipboard */
2512 if (__dpmi_int(0x2f, &dpmi_regs
) == -1)
2514 /* real-mode interrupt failed? */
2515 return FALSE
; /* FALSE --> clipboard could not be closed */
2518 return TRUE
; /* TRUE --> clipboard closed successfully, OK */
2522 * Win16EmptyClipboard: empty the (previously opened) Windows clipboard.
2523 * Return TRUE on success, FALSE on failure.
2526 Win16EmptyClipboard(void)
2528 __dpmi_regs dpmi_regs
;
2530 /* int 02xf, AX = 0x1702 attempts to empty the Windows clipboard. Upon
2531 * return from the interrupt, if AX == 0, the clipboard could not be
2532 * emptied (for some reason).
2534 dpmi_regs
.x
.ax
= 0x1702; /* empty the Windows clipboard */
2535 if (__dpmi_int(0x2f, &dpmi_regs
) == -1)
2537 /* real-mode interrupt failed? */
2538 return FALSE
; /* FALSE --> clipboard could not be emptied */
2541 /* Did we succeed in clearing the clipboard? */
2542 if (dpmi_regs
.x
.ax
== 0)
2543 return FALSE
; /* FALSE --> clipboard could not be emptied */
2545 return TRUE
; /* TRUE --> clipboard was emptied, OK */
2549 * FreeDOSMemory: a helper function to free memory previously
2550 * allocated by a call to __dpmi_allocate_dos_memory().
2553 FreeDOSMemory(int protected_mode_selector
)
2555 /* Free the DOS buffer and release the DPMI prot-mode selector.
2557 * It's important that DOS memory be properly released because
2558 * there's only a limited amount of it. Therefore, if the call
2559 * to __dpmi_free_dos_memory() fails, emit an error message
2562 if (__dpmi_free_dos_memory(protected_mode_selector
) == -1)
2563 EMSG("E451: could not free DOS memory buffer (DJGPP)");
2567 * Win16GetClipboardData: query the Windows clipboard as to whether data
2568 * is available in a particular clipboard format. If data is
2569 * available, allocate a buffer for it and read the data from the
2570 * clipboard into the buffer. Return a pointer to the buffer. If
2571 * no data is available in the requested format, return NULL.
2573 * This routine allocates memory to hold the retrieved clipboard
2574 * data. It's the caller's responsibility to free this memory
2575 * once it's finished using it. The memory should be freed by
2576 * calling vim_free().
2579 Win16GetClipboardData(int clip_data_format
)
2581 __dpmi_regs dpmi_regs
;
2583 int real_mode_segment_address
;
2584 int protected_mode_selector
;
2586 char_u
*clip_data_buffer
;
2587 long_u clip_data_size
;
2589 /* We only handle clipboard formats we recognize, others are ignored.
2591 * It's not possible to create a custom clipboard format for VimClipboard
2592 * data under DOS, so one of the predefined Windows formats had to be
2593 * used for CF_VIMCLIP. Two obscure formats, popular when Windows 3.0
2594 * came out but no longer in much use today, are the DIF and SYLK formats.
2595 * DIF is the Data Interchange Format, SYLK is the Symbolic Link format.
2596 * They are both text formats and either one can be hijacked for use as
2597 * "the VimClipboard format". Of course, this conflicts with anyone who
2598 * still *is* using DIF or SYLK data formats, but that will be very few
2601 * I (dk) chose SYLK as the more obscure format because it was used
2602 * mostly for Microsoft Multiplan (the pre-cursor to Excel) and it's not
2603 * likely Multiplan is used anywhere much anymore. Mind you, Excel can
2604 * still export to both DIF and SYLK formats.
2607 switch (clip_data_format
)
2609 case CF_VIMCLIP
: /* Vim's own special clipboard format */
2610 case CF_TEXT
: /* Windows text */
2611 case CF_OEMTEXT
: /* DOS (OEM) text */
2613 /* int 02xf, AX = 0x1704 returns the number of bytes of data currently
2614 * on the Windows clipboard, for the specified format. Upon return
2615 * from the interrupt, DX:AX = the number of bytes, rounded up to the
2616 * nearest multiple of 32.
2619 dpmi_regs
.x
.ax
= 0x1704; /* get size of clipbd data */
2620 dpmi_regs
.x
.dx
= clip_data_format
;
2621 if (__dpmi_int(0x2f, &dpmi_regs
) == -1)
2623 /* real-mode interrupt failed? */
2624 return NULL
; /* early exit */
2627 /* Did we get anything? If not, this is not an error. */
2628 if (dpmi_regs
.x
.dx
== 0 && dpmi_regs
.x
.ax
== 0)
2630 /* no CF_VIMCLIP data? */
2631 return NULL
; /* early exit */
2634 /* There is data available in the requested clipboard format.
2636 * Calculate data size. Remember this is rounded up to the nearest
2637 * multiple of 32, so clip_data_size is actually an upper limit.
2638 * The extra bytes, if any, are set to null (0x00) when the data is
2639 * read from the clipboard. (Later:) actually I'm no longer sure
2640 * this is strictly true: the end-of-data is marked by a null, but
2641 * the extra bytes appear to sometimes be null, sometimes not.
2642 * They may just be garbage.
2644 clip_data_size
= dpmi_regs
.x
.ax
+ (dpmi_regs
.x
.dx
<< 16);
2646 /* Allocate memory to retrieve the data. The buffer has to lie in the
2647 * DOS memory region (in the first 1 MByte of address space) because
2648 * the Windows clipboard interface expects a 16-bit segment:offset
2649 * pointer to a buffer address within the DOS region. Must therefore
2650 * use __dpmi_allocate_dos_memory() instead of lalloc() or alloc().
2652 real_mode_segment_address
= __dpmi_allocate_dos_memory(
2653 (clip_data_size
+ 15) >> 4, /* buffer size, in 16-byte paragraphs */
2654 &protected_mode_selector
); /* prot-mode selector for the address */
2656 if (real_mode_segment_address
== -1)
2658 /* memory allocation failed. */
2660 /* Technically we don't know why the allocation failed, but
2661 * almost always it will be because there wasn't enough DOS
2662 * memory to satisfy the request, so report that as the problem.
2663 * On my system, DJGPP is able to satisfy a DOS allocation request
2664 * up to about 600K in size. This depends on your HIMEM.SYS and
2665 * EMM386.EXE settings however.
2667 EMSG("E452: Clipboard data too large, cannot allocate DOS buffer");
2668 return NULL
; /* early exit */
2671 /* Copy data from the clipboard into the buffer. Experiments show that
2672 * the Windows clipboard is smart enough to handle data transfers
2673 * larger than 64K properly, even though the buffer address is a 16-bit
2674 * segment:offset (which would normally limit the block size to 64K
2675 * unless ES gets incremented).
2677 dpmi_regs
.x
.ax
= 0x1705; /* get clipboard data */
2678 dpmi_regs
.x
.dx
= clip_data_format
; /* CF_VIMCLIP */
2679 dpmi_regs
.x
.es
= real_mode_segment_address
; /* buffer ad: segment */
2680 dpmi_regs
.x
.bx
= 0; /* buffer ad: offset */
2681 if (__dpmi_int( 0x2f, &dpmi_regs
) == -1)
2683 /* real-mode interrupt failed? */
2684 EMSG("E453: could not copy clipboard data to DOS buffer");
2685 FreeDOSMemory(protected_mode_selector
); /* clean up DOS mem */
2686 return NULL
; /* early exit */
2689 /* Clipboard data is now in DOS memory in the buffer pointed to by
2690 * ES:BX. Copy this into ordinary memory that Vim can access (ie.
2691 * prot-mode memory). Allocate one extra byte to ensure the text
2692 * is terminated properly (in case it was somehow corrupted).
2694 clip_data_buffer
= (char_u
*)lalloc(clip_data_size
+ 1, TRUE
);
2696 if (clip_data_buffer
== NULL
)
2698 /* allocation failed? */
2699 EMSG("E454: could not allocate clipboard memory buffer");
2700 FreeDOSMemory(protected_mode_selector
); /* clean up DOS mem */
2701 return NULL
; /* early exit */
2704 *(clip_data_buffer
+ clip_data_size
) = '\0'; /* ensure terminated */
2706 /* Copy the data from DOS memory to Vim-accessible memory. */
2707 movedata( /* DJGPP version of memcpy() */
2708 protected_mode_selector
, 0, /* source: DOS ad (via selector) */
2709 _my_ds(), (unsigned)clip_data_buffer
,
2710 /* target: normal mem address */
2711 clip_data_size
); /* how many bytes */
2713 /* Free the DOS buffer and release the DPMI prot-mode selector. */
2714 FreeDOSMemory(protected_mode_selector
); /* clean up DOS memory */
2716 return clip_data_buffer
; /* return pointer to allocated buffer */
2718 default: /* unknown clipboard format */
2724 * Win16SetClipboardData: send 'clip_data_size' bytes of data from the buffer
2725 * pointed to by 'clip_data', to the Windows clipboard. The data is
2726 * registered with the clipboard as being in the 'clip_data_format'
2730 Win16SetClipboardData(
2731 int clip_data_format
,
2736 __dpmi_regs dpmi_regs
;
2738 int real_mode_segment_address
;
2739 int protected_mode_selector
;
2740 long_u protected_mode_offset
= 0L;
2741 int total_size
= clip_data_size
;
2743 char_u
*clip_sel_type
;
2745 /* If we're using the CF_VIMCLIP custom format, allocate an extra
2746 * byte for clip_sel_type, which is a character indicating the type
2747 * of text selection: MLINE, MCHAR, or MBLOCK.
2749 if (clip_data_format
== CF_VIMCLIP
)
2750 total_size
++; /* extra byte for marker */
2752 /* Data cannot be sent directly from a Vim string (pClipData) to
2753 * the Windows clipboard, because the Windows clipboard interface
2754 * expects a 16-bit (DOS) segment:offset address for the source
2755 * buffer. Therefore we must create a "transfer buffer" in the DOS
2756 * memory region (in the first 1 MByte of address space) and copy
2757 * the Vim string into that. From there, the data can then be sent
2758 * to the Windows clipboard.
2760 * To allocate DOS memory, we must use __dpmi_allocate_dos_memory()
2761 * instead of lalloc() or alloc(). If the allocation fails, it will
2762 * almost invariably be because there is not enough DOS memory
2763 * available to accommodate the size of clip_data. There is nothing
2764 * we can do about this, we simply have to fail.
2766 real_mode_segment_address
= __dpmi_allocate_dos_memory(
2767 (total_size
+ 15) >> 4, /* buffer size, in 16-byte paragraphs */
2768 &protected_mode_selector
); /* prot-mode selector for the address */
2770 if (real_mode_segment_address
== -1)
2772 /* memory allocation failed. */
2773 /* Technically we don't know why the allocation failed, but
2774 * almost always it will be because there wasn't enough DOS
2775 * memory to satisfy the request. On my system, DJGPP is able
2776 * to satisfy a DOS allocation request up to about 600K in size.
2777 * This depends however on HIMEM.SYS and EMM386.EXE settings.
2779 return FALSE
; /* early exit */
2782 /* Copy data from Vim's buffer (clip_data) into the DOS transfer buffer.
2783 * This can be larger than 64K; movedata() takes care of crossing any
2784 * 16-bit segment boundaries.
2786 * If we're using Vim's custom clipboard format, we must copy one extra
2787 * byte to indicate the type of selection: line, character, or block.
2789 if (clip_data_format
== CF_VIMCLIP
)
2791 switch (clip_data_type
)
2794 case MLINE
: clip_sel_type
= "L"; break;
2795 case MCHAR
: clip_sel_type
= "C"; break;
2797 case MBLOCK
: clip_sel_type
= "B"; break;
2802 _my_ds(), (unsigned)clip_sel_type
,
2803 /* source: normal memory address */
2804 protected_mode_selector
, 0, /* target: DOS ad (via selector) */
2805 1); /* how many bytes to copy */
2807 protected_mode_offset
+= STRLEN(clip_sel_type
); /* allow for marker */
2811 _my_ds(), (unsigned)clip_data
, /* source: normal memory address */
2812 protected_mode_selector
, /* target: DOS address (via selector) */
2813 protected_mode_offset
, /* non-zero, if using clip_sel_type */
2814 clip_data_size
); /* how many bytes to copy */
2816 /* Send data from the DOS transfer buffer to the Windows clipboard.
2817 * int 02xf, AX = 0x1703 sends SI:CX bytes of data from the buffer
2818 * at ES:BX, to the clipboard.
2820 dpmi_regs
.x
.ax
= 0x1703; /* send clipboard data */
2821 dpmi_regs
.x
.dx
= clip_data_format
; /* flag: format of the data */
2822 dpmi_regs
.x
.si
= ((total_size
>> 16)
2823 & 0x0000ffffL
); /* hi word of data size */
2824 dpmi_regs
.x
.cx
= (total_size
& 0x0000ffffL
);
2825 /* lo word of data size */
2826 dpmi_regs
.x
.es
= real_mode_segment_address
; /* buffer address: segment */
2827 dpmi_regs
.x
.bx
= 0; /* buffer address: offset */
2828 if (__dpmi_int(0x2f, &dpmi_regs
) == -1)
2830 /* real-mode interrupt failed. */
2831 FreeDOSMemory(protected_mode_selector
); /* clean up DOS memory */
2832 return FALSE
; /* early exit */
2835 /* Free the DOS buffer and release the DPMI prot-mode selector. */
2836 FreeDOSMemory(protected_mode_selector
); /* clean up DOS memory */
2838 return TRUE
; /* TRUE --> data successfully sent to clipboard */
2841 #endif /* FEAT_CLIPBOARD */
2845 * End of MS-DOS only code
2849 /* common MS-DOS and Win16 code follows */
2852 vim_chmod(char_u
*name
)
2858 /* chmod() can't handle a file name with a trailing slash, remove it.
2859 * But don't remove it for "/" or "c:/". */
2860 p
= name
+ STRLEN(name
);
2863 if (p
> name
&& (*p
== '\\' || *p
== '/') && p
[-1] != ':')
2865 c
= *p
; /* remove trailing (back)slash */
2870 #if defined(__BORLANDC__) && (__BORLANDC__ > 0x410)
2871 /* this also sets the archive bit, supported by Borland C 4.0 and later,
2872 * where __BORLANDC__ is 0x450 (3.1 is 0x410) */
2873 f
= _rtl_chmod((char *)name
, 0, 0);
2875 f
= _chmod((char *)name
, 0, 0);
2878 *p
= c
; /* put back (back)slash */
2883 * get file permissions for 'name'
2884 * Returns -1 for error.
2885 * Returns FA_attributes defined in dos.h
2888 mch_getperm(char_u
*name
)
2890 return (long)vim_chmod(name
); /* get file mode */
2894 * set file permission for 'name' to 'perm'
2896 * return FAIL for failure, OK otherwise
2903 perm
|= FA_ARCH
; /* file has changed, set archive bit */
2904 #if defined(__BORLANDC__) && (__BORLANDC__ > 0x410)
2905 return (_rtl_chmod((char *)name
, 1, (int)perm
) == -1 ? FAIL
: OK
);
2907 return (_chmod((char *)name
, 1, (int)perm
) == -1 ? FAIL
: OK
);
2912 * Set hidden flag for "name".
2915 mch_hide(char_u
*name
)
2917 /* DOS 6.2 share.exe causes "seek error on file write" errors when making
2918 * the swap file hidden. Thus don't do it. */
2922 * return TRUE if "name" is a directory
2923 * return FALSE if "name" is not a directory
2924 * return FALSE for error
2926 * beware of a trailing (back)slash
2929 mch_isdir(char_u
*name
)
2933 f
= vim_chmod(name
);
2935 return FALSE
; /* file does not exist at all */
2936 if ((f
& FA_DIREC
) == 0)
2937 return FALSE
; /* not a directory */
2942 * Return 1 if "name" can be executed, 0 if not.
2943 * Return -1 if unknown.
2951 p
= searchpath(name
);
2952 if (p
== NULL
|| mch_isdir(p
))
2958 * Check what "name" is:
2959 * NODE_NORMAL: file or directory (or doesn't exist)
2960 * NODE_WRITABLE: writable device, socket, fifo, etc.
2961 * NODE_OTHER: non-writable things
2964 mch_nodetype(char_u
*name
)
2966 if (STRICMP(name
, "AUX") == 0
2967 || STRICMP(name
, "CON") == 0
2968 || STRICMP(name
, "CLOCK$") == 0
2969 || STRICMP(name
, "NUL") == 0
2970 || STRICMP(name
, "PRN") == 0
2971 || ((STRNICMP(name
, "COM", 3) == 0
2972 || STRNICMP(name
, "LPT", 3) == 0)
2973 && VIM_ISDIGIT(name
[3])
2975 return NODE_WRITABLE
;
2976 /* TODO: NODE_OTHER? */
2981 * Get name of current directory into buffer 'buf' of length 'len' bytes.
2982 * Return OK for success, FAIL for failure.
2990 if (getcwd((char *)buf
, len
) == NULL
)
2992 /* turn the '/'s returned by DJGPP into '\'s */
2996 return (getcwd((char *)buf
, len
) != NULL
? OK
: FAIL
);
3001 * this version of remove is not scared by a readonly (backup) file
3003 * returns -1 on error, 0 otherwise (just like remove())
3006 mch_remove(char_u
*name
)
3008 (void)mch_setperm(name
, 0); /* default permissions */
3009 return unlink((char *)name
);
3013 * Special version of getenv(): Use uppercase name.
3016 mch_getenv(char_u
*name
)
3019 #define MAXENVLEN 50
3020 char_u var_copy
[MAXENVLEN
+ 1];
3025 * Take a copy of the argument, and force it to upper case before passing
3026 * to getenv(). On DOS systems, getenv() doesn't like lower-case argument
3027 * (unlike Win32 et al.) If the name is too long to fit in var_copy[]
3030 if ((i
= STRLEN(name
)) > MAXENVLEN
)
3035 p
= name
; /* out of memory, fall back to unmodified name */
3038 for (i
= 0; name
[i
] != NUL
; ++i
)
3039 p
[i
] = toupper(name
[i
]);
3043 res
= (char_u
*)getenv((char *)p
);
3045 if (p
!= var_copy
&& p
!= name
)
3052 * Insert user name in s[len].
3064 * Insert host name is s[len].
3072 vim_strncpy(s
, "PC (32 bits Vim)", len
- 1);
3074 vim_strncpy(s
, "PC (16 bits Vim)", len
- 1);