#include "vimio.h"
#include "vim.h"
#include <conio.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#ifndef WIN16
#include <bios.h>
#ifdef DJGPP
# include <dpmi.h>
# include <signal.h>
# include <sys/movedata.h>
# include <crt0.h>
# ifdef FEAT_CLIPBOARD
# include <sys/segments.h>
# endif
#else
# include <alloc.h>
#endif
#if defined(DJGPP) || defined(PROTO)
# define _cdecl
#endif
static int cbrk_pressed = FALSE;
static int ctrlc_pressed = FALSE;
static int delayed_redraw = FALSE;
static int bioskey_read = _NKEYBRD_READ;
static int bioskey_ready = _NKEYBRD_READY;
#ifdef FEAT_MOUSE
static int mouse_avail = FALSE;
static int mouse_active;
static int mouse_hidden;
static int mouse_click = -1;
static int mouse_last_click = -1;
static int mouse_x = -1;
static int mouse_y = -1;
static long mouse_click_time = 0;
static int mouse_click_count = 0;
static int mouse_click_x = 0;
static int mouse_click_y = 0;
static linenr_T mouse_topline = 0;
#ifdef FEAT_DIFF
static int mouse_topfill = 0;
#endif
static int mouse_x_div = 8;
static int mouse_y_div = 8;
#endif
#define BIOSTICK 55
static int orig_attr = 0x0700;
static int S_iLeft = 0;
static int S_iTop = 0;
static int S_iRight = 0;
static int S_iBottom = 0;
static void
mywindow(int iLeft, int iTop, int iRight, int iBottom)
{
S_iLeft = iLeft;
S_iTop = iTop;
S_iRight = iRight;
S_iBottom = iBottom;
window(iLeft, iTop, iRight, iBottom);
}
#ifdef DJGPP
unsigned long S_ulScreenBase = 0xb8000;
unsigned short S_uiAttribute = 0;
int S_iCurrentRow = 0;
int S_iCurrentColumn = 0;
short S_selVideo;
unsigned short S_linebuffer[8000];
unsigned short S_blankbuffer[256];
unsigned short *S_linebufferpos = S_linebuffer;
int S_iBufferRow;
int S_iBufferColumn;
static void
myflush(void)
{
if (S_linebufferpos != S_linebuffer)
{
_dosmemputw(S_linebuffer, (S_linebufferpos - S_linebuffer),
S_ulScreenBase
+ S_iBufferRow * (Columns << 1) + (S_iBufferColumn << 1));
S_linebufferpos = S_linebuffer;
}
}
static void
mygotoxy(int x, int y)
{
S_iCurrentRow = y - 1;
S_iCurrentColumn = x - 1;
}
static void
set_sys_cursor(void)
{
if (term_console && full_screen)
{
myflush();
gotoxy(S_iCurrentColumn + 1, S_iCurrentRow + 1);
}
}
static void
setblankbuffer(unsigned short uiValue)
{
int i;
static unsigned short olduiValue = 0;
if (olduiValue != uiValue)
{
for (i = 0; i < Columns; ++i)
S_blankbuffer[i] = uiValue;
olduiValue = uiValue;
}
}
static void
myclreol(void)
{
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, S_iRight - S_iCurrentColumn, S_ulScreenBase
+ (S_iCurrentRow) * (Columns << 1)
+ (S_iCurrentColumn << 1));
}
static void
myclrscr(void)
{
short iColumn;
int endpoint = (Rows * Columns) << 1;
setblankbuffer(S_uiAttribute | ' ');
for (iColumn = 0; iColumn < endpoint; iColumn += (Columns << 1))
_dosmemputw(S_blankbuffer, Columns, S_ulScreenBase + iColumn);
}
static void
mydelline(void)
{
short iRow, iColumn;
iColumn = (S_iLeft - 1) << 1;
for (iRow = S_iCurrentRow; iRow < S_iBottom - 1; iRow++)
movedata(S_selVideo, (((iRow + 1) * Columns) << 1) + iColumn,
S_selVideo, ((iRow * Columns) << 1) + iColumn,
(S_iRight - S_iLeft + 1) << 1);
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
+ (S_iBottom - 1) * (Columns << 1) + iColumn);
}
static void
myinsline(void)
{
short iRow, iColumn;
iColumn = (S_iLeft - 1) << 1;
for (iRow = S_iBottom - 1; iRow >= S_iTop; iRow--)
movedata(S_selVideo, (((iRow - 1) * Columns) << 1) + iColumn,
S_selVideo, ((iRow * Columns) << 1) + iColumn,
(S_iRight - S_iLeft + 1) << 1);
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
+ (S_iTop - 1) * (Columns << 1) + iColumn);
}
static void
myscroll(void)
{
short iRow, iColumn;
iColumn = (S_iLeft - 1) << 1;
for (iRow = S_iTop; iRow < S_iBottom; iRow++)
movedata(S_selVideo, ((iRow * Columns) << 1) + iColumn,
S_selVideo, (((iRow - 1) * Columns) << 1) + iColumn,
(S_iRight - S_iLeft + 1) << 1);
setblankbuffer(S_uiAttribute | ' ');
_dosmemputw(S_blankbuffer, (S_iRight - S_iLeft) + 1, S_ulScreenBase
+ (S_iBottom - 1) * (Columns << 1) + iColumn);
}
static int
myputch(int iChar)
{
unsigned short uiValue;
if (iChar == '\n')
{
myflush();
if (S_iCurrentRow >= S_iBottom - S_iTop)
myscroll();
else
{
S_iCurrentColumn = S_iLeft - 1;
S_iCurrentRow++;
}
}
else if (iChar == '\r')
{
myflush();
S_iCurrentColumn = S_iLeft - 1;
}
else if (iChar == '\b')
{
myflush();
if (S_iCurrentColumn >= S_iLeft)
S_iCurrentColumn--;
}
else if (iChar == 7)
{
sound(440);
delay(200);
nosound();
}
else
{
uiValue = S_uiAttribute | (unsigned char)iChar;
if (S_linebufferpos == S_linebuffer)
{
S_iBufferColumn = S_iCurrentColumn;
S_iBufferRow = S_iCurrentRow;
}
*S_linebufferpos++ = uiValue;
S_iCurrentColumn++;
if (S_iCurrentColumn >= S_iRight && S_iCurrentRow >= S_iBottom - S_iTop)
{
myflush();
myscroll();
S_iCurrentColumn = S_iLeft - 1;
S_iCurrentRow++;
}
}
return 0;
}
static void
mytextinit(struct text_info *pTextinfo)
{
S_selVideo = __dpmi_segment_to_descriptor(S_ulScreenBase >> 4);
S_uiAttribute = pTextinfo->normattr << 8;
}
static void
get_screenbase(void)
{
static union REGS regs;
regs.h.ah = 0x0f;
(void)int86(0x10, ®s, ®s);
if (regs.h.al == 0x07)
S_ulScreenBase = 0xb0000;
else
S_ulScreenBase = 0xb8000;
}
static void
mytextattr(int iAttribute)
{
S_uiAttribute = (unsigned short)iAttribute << 8;
}
static void
mynormvideo(void)
{
mytextattr(orig_attr);
}
static void
mytextcolor(int iTextColor)
{
S_uiAttribute = (unsigned short)((S_uiAttribute & 0xf000)
| (unsigned short)iTextColor << 8);
}
static void
mytextbackground(int iBkgColor)
{
S_uiAttribute = (unsigned short)((S_uiAttribute & 0x0f00)
| (unsigned short)(iBkgColor << 12));
}
static long
mygetdigits(pp)
char_u **pp;
{
char_u *p;
long retval = 0;
p = *pp;
if (*p == '-')
++p;
while (VIM_ISDIGIT(*p))
{
retval = (retval * 10) + (*p - '0');
++p;
}
if (**pp == '-')
retval = -retval;
*pp = p;
return retval;
}
#else
# define mygotoxy gotoxy
# define myputch putch
# define myscroll scroll
# define mynormvideo normvideo
# define mytextattr textattr
# define mytextcolor textcolor
# define mytextbackground textbackground
# define mygetdigits getdigits
# define myclreol clreol
# define myclrscr clrscr
# define myinsline insline
# define mydelline delline
#endif
static const struct
{
char_u scancode;
char_u metakey;
} altkey_table[] =
{
{0x1e, 0xe1},
{0x30, 0xe2},
{0x2e, 0xe3},
{0x20, 0xe4},
{0x12, 0xe5},
{0x21, 0xe6},
{0x22, 0xe7},
{0x23, 0xe8},
{0x17, 0xe9},
{0x24, 0xea},
{0x25, 0xeb},
{0x26, 0xec},
{0x32, 0xed},
{0x31, 0xee},
{0x18, 0xef},
{0x19, 0xf0},
{0x10, 0xf1},
{0x13, 0xf2},
{0x1f, 0xf3},
{0x14, 0xf4},
{0x16, 0xf5},
{0x2f, 0xf6},
{0x11, 0xf7},
{0x2d, 0xf8},
{0x15, 0xf9},
{0x2c, 0xfa},
{0x78, 0xb1},
{0x79, 0xb2},
{0x7a, 0xb3},
{0x7b, 0xb4},
{0x7c, 0xb5},
{0x7d, 0xb6},
{0x7e, 0xb7},
{0x7f, 0xb8},
{0x80, 0xb9},
{0x81, 0xb0},
};
static int
translate_altkeys(int rawkey)
{
int i, c;
if ((rawkey & 0xff) == 0)
{
c = (rawkey >> 8);
for (i = sizeof(altkey_table) / sizeof(altkey_table[0]); --i >= 0; )
{
if (c == altkey_table[i].scancode)
return (int)altkey_table[i].metakey;
}
}
return rawkey;
}
void
mch_set_normal_colors()
{
char_u *p;
int n;
cterm_normal_fg_color = (orig_attr & 0xf) + 1;
cterm_normal_bg_color = ((orig_attr >> 4) & 0xf) + 1;
if (T_ME[0] == ESC && T_ME[1] == '|')
{
p = T_ME + 2;
n = getdigits(&p);
if (*p == 'm' && n > 0)
{
cterm_normal_fg_color = (n & 0xf) + 1;
cterm_normal_bg_color = ((n >> 4) & 0xf) + 1;
}
}
}
#if defined(MCH_CURSOR_SHAPE) || defined(PROTO)
static void
mch_restore_cursor_shape(int restore)
{
static union REGS regs;
static int saved = FALSE;
if (restore)
{
if (saved)
regs.h.ah = 0x01;
else
return;
}
else
{
regs.h.ah = 0x03;
regs.h.bh = 0x00;
saved = TRUE;
}
(void)int86(0x10, ®s, ®s);
}
static void
mch_set_cursor_shape(int thickness)
{
union REGS regs;
regs.h.ch = 7 - thickness;
regs.h.cl = 7;
regs.h.ah = 0x01;
(void)int86(0x10, ®s, ®s);
}
void
mch_update_cursor(void)
{
int idx;
int thickness;
idx = get_shape_idx(FALSE);
if (shape_table[idx].shape == SHAPE_BLOCK)
thickness = 7;
else
thickness = (7 * shape_table[idx].percentage + 90) / 100;
mch_set_cursor_shape(thickness);
}
#endif
long_u
mch_avail_mem(int special)
{
#ifdef DJGPP
return _go32_dpmi_remaining_virtual_memory();
#else
return coreleft();
#endif
}
#ifdef FEAT_MOUSE
static void
mouse_area(void)
{
union REGS regs;
if (mouse_avail)
{
regs.x.cx = 0;
regs.x.dx = Columns * mouse_x_div - 1;
regs.x.ax = 7;
(void)int86(0x33, ®s, ®s);
regs.x.cx = 0;
regs.x.dx = Rows * mouse_y_div - 1;
regs.x.ax = 8;
(void)int86(0x33, ®s, ®s);
}
}
static void
show_mouse(int on)
{
static int was_on = FALSE;
union REGS regs;
if (mouse_avail)
{
if (!mouse_active || mouse_hidden)
on = FALSE;
if ((on && !was_on) || (!on && was_on))
{
was_on = on;
regs.x.ax = on ? 1 : 2;
int86(0x33, ®s, ®s);
if (on)
mouse_area();
}
}
}
#endif
static int cons_key = -1;
static void
cons_getkey(void)
{
union REGS regs;
regs.h.ah = 0x06;
regs.h.dl = 0xff;
(void)intdos(®s, ®s);
if ((regs.x.flags & 0x40) == 0)
cons_key = (regs.h.al & 0xff);
}
static int
cons_kbhit(void)
{
if (cons_key < 0)
cons_getkey();
return (cons_key >= 0);
}
static int
cons_getch(void)
{
int c = -1;
if (cons_key < 0)
cons_getkey();
c = cons_key;
cons_key = -1;
return c;
}
#ifdef DJGPP
static int
vim_kbhit(void)
{
union REGS regs;
regs.h.ah = 0x0b;
(void)intdos(®s, ®s);
return regs.h.al;
}
#ifdef kbhit
# undef kbhit
#endif
#define kbhit() vim_kbhit()
#endif
#define FOREVER 1999999999L
static int
WaitForChar(long msec)
{
long starttime = 0;
if (msec != 0)
starttime = biostime(0, 0L);
for (;;)
{
#ifdef FEAT_MOUSE
long clicktime;
static int old_status = 0;
union REGS regs;
int x, y;
if (mouse_avail && mouse_active && mouse_click < 0)
{
regs.x.ax = 3;
int86(0x33, ®s, ®s);
x = regs.x.cx / mouse_x_div;
y = regs.x.dx / mouse_y_div;
if ((old_status == 0) != (regs.x.bx == 0))
{
if (old_status)
mouse_click = MOUSE_RELEASE;
else
{
if (regs.x.bx & MSDOS_MOUSE_LEFT)
mouse_click = MOUSE_LEFT;
else if (regs.x.bx & MSDOS_MOUSE_RIGHT)
mouse_click = MOUSE_RIGHT;
else if (regs.x.bx & MSDOS_MOUSE_MIDDLE)
mouse_click = MOUSE_MIDDLE;
clicktime = biostime(0, 0L);
if (mouse_click_x == x && mouse_click_y == y
&& mouse_topline == curwin->w_topline
#ifdef FEAT_DIFF
&& mouse_topfill == curwin->w_topfill
#endif
&& mouse_click_count != 4
&& mouse_click == mouse_last_click
&& clicktime < mouse_click_time
+ p_mouset / BIOSTICK)
++mouse_click_count;
else
mouse_click_count = 1;
mouse_click_time = clicktime;
mouse_last_click = mouse_click;
mouse_click_x = x;
mouse_click_y = y;
mouse_topline = curwin->w_topline;
#ifdef FEAT_DIFF
mouse_topfill = curwin->w_topfill;
#endif
SET_NUM_MOUSE_CLICKS(mouse_click, mouse_click_count);
}
}
else if (old_status && (x != mouse_x || y != mouse_y))
mouse_click = MOUSE_DRAG;
old_status = regs.x.bx;
if (mouse_hidden && mouse_x >= 0 && (mouse_x != x || mouse_y != y))
{
mouse_hidden = FALSE;
show_mouse(TRUE);
}
mouse_x = x;
mouse_y = y;
}
#endif
if ((p_consk ? cons_kbhit()
: p_biosk ? bioskey(bioskey_ready) : kbhit())
|| cbrk_pressed
#ifdef FEAT_MOUSE
|| mouse_click >= 0
#endif
)
return TRUE;
if (msec == 0 || (msec != FOREVER
&& biostime(0, 0L) > starttime + msec / BIOSTICK))
break;
#ifdef DJGPP
__dpmi_yield();
#endif
}
return FALSE;
}
void
mch_delay(
long msec,
int ignoreinput)
{
long starttime;
if (ignoreinput)
{
starttime = biostime(0, 0L);
while (biostime(0, 0L) < starttime + msec / BIOSTICK)
;
}
else
WaitForChar(msec);
}
void
mch_write(
char_u *s,
int len)
{
char_u *p;
int row, col;
if (term_console && full_screen)
while (len--)
{
if (p_wd)
WaitForChar(p_wd);
if (s[0] == '\n')
#ifdef DJGPP
{
myflush();
S_iCurrentColumn = S_iLeft - 1;
}
#else
myputch('\r');
#endif
else if (s[0] == ESC && len > 1 && s[1] == '|')
{
switch (s[2])
{
#ifdef DJGPP
case 'B': ScreenVisualBell();
goto got3;
#endif
case 'J':
#ifdef DJGPP
myflush();
#endif
myclrscr();
goto got3;
case 'K':
#ifdef DJGPP
myflush();
#endif
myclreol();
goto got3;
case 'L':
#ifdef DJGPP
myflush();
#endif
myinsline();
goto got3;
case 'M':
#ifdef DJGPP
myflush();
#endif
mydelline();
got3: s += 3;
len -= 2;
continue;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': p = s + 2;
row = mygetdigits(&p);
if (p > s + len)
break;
if (*p == ';')
{
++p;
col = mygetdigits(&p);
if (p > s + len)
break;
if (*p == 'H' || *p == 'r' || *p == 'V')
{
#ifdef DJGPP
myflush();
#endif
if (*p == 'H')
mygotoxy(col, row);
else if (*p == 'V')
mywindow(row, S_iTop, col, S_iBottom);
else
mywindow(S_iLeft, row, S_iRight, col);
len -= p - s;
s = p + 1;
continue;
}
}
else if (*p == 'm' || *p == 'f' || *p == 'b')
{
if (*p == 'm')
{
if (row == 0)
mynormvideo();
else
mytextattr(row);
}
else if (*p == 'f')
mytextcolor(row);
else
mytextbackground(row);
len -= p - s;
s = p + 1;
continue;
}
}
}
myputch(*s++);
}
else
{
write(1, s, (unsigned)len);
}
}
int
mch_inchar(
char_u *buf,
int maxlen,
long time,
int tb_change_cnt)
{
int len = 0;
int c;
int tmp_c;
static int nextchar = 0;
if (delayed_redraw)
{
delayed_redraw = FALSE;
update_screen(CLEAR);
setcursor();
out_flush();
}
if (nextchar)
{
*buf = nextchar;
nextchar = 0;
return 1;
}
#ifdef FEAT_MOUSE
if (time != 0)
show_mouse(TRUE);
#endif
#ifdef DJGPP
set_sys_cursor();
#endif
if (time >= 0)
{
if (WaitForChar(time) == 0)
{
#ifdef FEAT_MOUSE
show_mouse(FALSE);
#endif
return 0;
}
}
else
{
if (WaitForChar(p_ut) == 0)
{
#ifdef FEAT_AUTOCMD
if (trigger_cursorhold() && maxlen >= 3)
{
buf[0] = K_SPECIAL;
buf[1] = KS_EXTRA;
buf[2] = (int)KE_CURSORHOLD;
return 3;
}
#endif
before_blocking();
}
}
WaitForChar(FOREVER);
cbrk_pressed = FALSE;
#ifdef FEAT_MOUSE
if (mouse_click >= 0 && maxlen >= 5)
{
len = 5;
*buf++ = ESC + 128;
*buf++ = 'M';
*buf++ = mouse_click;
*buf++ = mouse_x + '!';
*buf++ = mouse_y + '!';
mouse_click = -1;
}
else
#endif
{
#ifdef FEAT_MOUSE
mouse_hidden = TRUE;
#endif
if (p_biosk && !p_consk)
{
while ((len == 0 || bioskey(bioskey_ready)) && len < maxlen)
{
c = translate_altkeys(bioskey(bioskey_read));
if (c == 0)
c = 3;
else if (c == 0x0300)
c = NUL;
else if ((c & 0xff) == 0
|| c == K_NUL
|| c == 0x4e2b
|| c == 0x4a2d
|| c == 0x372a
|| ((c & 0xff) == 0xe0 && c != 0xe0))
{
if (c == K_NUL)
c = 3;
else
c >>= 8;
*buf++ = K_NUL;
++len;
}
if (len < maxlen)
{
*buf++ = c;
len++;
#ifdef FEAT_MBYTE
if (input_conv.vc_type != CONV_NONE
&& (len == 1 || buf[-2] != K_NUL))
len += convert_input(buf - 1, 1, maxlen - len + 1) - 1;
#endif
}
else
nextchar = c;
}
}
else
{
while ((len == 0 || (p_consk ? cons_kbhit() : kbhit()))
&& len < maxlen)
{
switch (c = (p_consk ? cons_getch() : getch()))
{
case 0:
if (p_consk)
c = cons_getch();
else
c = getch();
tmp_c = translate_altkeys(c << 8);
if (tmp_c == (c << 8))
{
*buf++ = K_NUL;
++len;
}
else
c = tmp_c;
break;
case K_NUL:
*buf++ = K_NUL;
++len;
c = 3;
break;
case 3:
cbrk_pressed = TRUE;
default:
break;
}
if (len < maxlen)
{
*buf++ = c;
++len;
}
else
nextchar = c;
}
}
}
#ifdef FEAT_MOUSE
show_mouse(FALSE);
#endif
beep_count = 0;
return len;
}
int
mch_char_avail(void)
{
return WaitForChar(0L);
}
#ifdef DJGPP
# define INT_ARG int
#else
# define INT_ARG
#endif
static void interrupt
#ifdef DJGPP
catch_cbrk(int a)
#else
catch_cbrk(void)
#endif
{
cbrk_pressed = TRUE;
ctrlc_pressed = TRUE;
}
#ifndef DJGPP
static int _cdecl
cbrk_handler(void)
{
delayed_redraw = TRUE;
return 1;
}
static void interrupt
catch_cint(bp, di, si, ds, es, dx, cx, bx, ax)
unsigned bp, di, si, ds, es, dx, cx, bx, ax;
{
ax = (ax & 0xff00);
if (_osmajor >= 3)
ax |= 3;
}
#endif
static void
set_interrupts(int on)
{
static int saved_cbrk;
#ifndef DJGPP
static void interrupt (*old_cint)();
#endif
static void interrupt (*old_cbrk)(INT_ARG);
if (on)
{
saved_cbrk = getcbrk();
setcbrk(0);
#ifdef DJGPP
old_cbrk = signal(SIGINT, catch_cbrk);
#else
old_cint = getvect(0x24);
setvect(0x24, catch_cint);
old_cbrk = getvect(0x1B);
setvect(0x1B, catch_cbrk);
ctrlbrk(cbrk_handler);
#endif
if (term_console)
out_str(T_ME);
}
else
{
setcbrk(saved_cbrk);
#ifdef DJGPP
signal(SIGINT,old_cbrk);
#else
setvect(0x24, old_cint);
setvect(0x1B, old_cbrk);
#endif
if (term_console)
mynormvideo();
}
}
void
mch_suspend(void)
{
suspend_shell();
}
extern int _fmode;
void
mch_init(void)
{
union REGS regs;
#if defined(DJGPP) && defined(FEAT_CLIPBOARD)
__dpmi_regs dpmi_regs;
#endif
regs.h.ah = 0x08;
regs.h.bh = 0x00;
int86(0x10, ®s, ®s);
orig_attr = regs.h.ah;
mynormvideo();
if (cterm_normal_fg_color == 0)
cterm_normal_fg_color = (orig_attr & 0xf) + 1;
if (cterm_normal_bg_color == 0)
cterm_normal_bg_color = ((orig_attr >> 4) & 0xf) + 1;
term_console = TRUE;
_fmode = O_BINARY;
out_flush();
set_interrupts(TRUE);
#ifdef DJGPP
if (getenv("LFN") == NULL)
putenv("LFN=y");
get_screenbase();
#endif
#ifdef FEAT_MOUSE
regs.x.ax = 0;
(void)int86(0x33, ®s, ®s);
mouse_avail = regs.x.ax;
mch_get_shellsize();
if (Columns <= 40)
mouse_x_div = 16;
if (Rows == 30)
mouse_y_div = 16;
#endif
regs.x.ax = 0x1003;
regs.h.bl = 0x00;
regs.h.bh = 0x00;
int86(0x10, ®s, ®s);
regs.h.ah = 0x05;
regs.x.cx = 0xffff;
int86(0x16, ®s, ®s);
if (regs.h.al != 1)
{
int i;
for (i = 0; i < 16; ++i)
{
regs.h.ah = 0x10;
int86(0x16, ®s, ®s);
if (regs.x.ax == 0xffff)
break;
}
if (i == 16)
{
bioskey_read = 0;
bioskey_ready = 1;
}
}
#ifdef MCH_CURSOR_SHAPE
mch_restore_cursor_shape(FALSE);
mch_update_cursor();
#endif
#if defined(DJGPP) && defined(FEAT_CLIPBOARD)
dpmi_regs.x.ax = 0x1700;
if (__dpmi_int(0x2f, &dpmi_regs) == -1)
dpmi_regs.x.ax = 0x1700;
if (dpmi_regs.x.ax == 0x1700)
clip_init(FALSE);
else
clip_init(TRUE);
#endif
}
int
mch_check_win(
int argc,
char **argv)
{
if (*argv[0] != NUL)
exe_name = FullName_save((char_u *)argv[0], FALSE);
if (exe_name == NULL || *exe_name == NUL)
exe_name = searchpath("vim.exe");
if (isatty(1))
return OK;
return FAIL;
}
int
mch_input_isatty(void)
{
if (isatty(read_cmd_fd))
return TRUE;
return FALSE;
}
#if defined(USE_FNAME_CASE) || defined(PROTO)
void
fname_case(char_u *name, int len)
{
char_u *tail;
struct ffblk fb;
slash_adjust(name);
if (findfirst(name, &fb, 0) == 0)
{
tail = gettail(name);
if (len == 0 ? STRLEN(tail) == STRLEN(fb.ff_name)
: (tail - name) + STRLEN(fb.ff_name) < len)
STRCPY(tail, fb.ff_name);
}
}
#endif
long
mch_get_pid(void)
{
return (long)0;
}
static int
change_drive(int drive)
{
union REGS regs;
regs.h.ah = 0x0e;
regs.h.dl = drive - 1;
intdos(®s, ®s);
regs.h.ah = 0x19;
intdos(®s, ®s);
if (regs.h.al == drive - 1)
return 0;
return -1;
}
int
mch_FullName(
char_u *fname,
char_u *buf,
int len,
int force)
{
if (!force && mch_isFullName(fname))
{
vim_strncpy(buf, fname, len - 1);
slash_adjust(buf);
return OK;
}
#ifdef __BORLANDC__
if (_fullpath((char *)buf, (char *)fname, len - 1) == NULL)
return FAIL;
return OK;
#else
{
# if 1
char_u fullpath[MAXPATHL];
if (!_truename(fname, fullpath))
return FAIL;
slash_adjust(fullpath);
vim_strncpy(buf, fullpath, len - 1);
return OK;
# else
int l;
char_u olddir[MAXPATHL];
char_u *p, *q;
int c;
int retval = OK;
*buf = 0;
p = vim_strrchr(fname, '/');
q = vim_strrchr(fname, '\\');
if (q != NULL && (p == NULL || q > p))
p = q;
q = vim_strrchr(fname, ':');
if (q != NULL && (p == NULL || q > p))
p = q;
if (p != NULL)
{
if (getcwd(olddir, MAXPATHL) == NULL)
{
p = NULL;
retval = FAIL;
}
else
{
if (p == fname)
q = p + 1;
else if (q + 1 == p)
q = p + 1;
else
q = p;
c = *q;
*q = NUL;
# ifdef DJGPP
STRCPY(buf, fname);
slash_adjust(buf);
if (mch_chdir(buf))
# else
if (mch_chdir(fname))
# endif
retval = FAIL;
else
{
fname = q;
if (c == psepc)
fname++;
}
*q = c;
}
}
if (getcwd(buf, len) == NULL)
{
retval = FAIL;
*buf = NUL;
}
# ifdef USE_FNAME_CASE
else
{
char_u *head;
char_u *tail;
struct ffblk fb;
int c;
int added;
slash_adjust(buf);
head = buf;
if (isalpha(*head) && head[1] == ':')
head += 2;
while (*head != NUL)
{
while (*head == '/' || *head == '\\')
++head;
for (tail = head; *tail != NUL; ++tail)
if (*tail == '/' || *tail == '\\')
break;
c = *tail;
*tail = NUL;
if (findfirst(buf, &fb, FA_DIREC) == 0)
{
added = STRLEN(fb.ff_name);
if ((head - buf) + added + STRLEN(tail + 1) + 2 < len)
{
added -= (tail - head);
if (added != 0)
mch_memmove(tail + 1 + added, tail + 1,
STRLEN(tail + 1) + 1);
STRCPY(head, fb.ff_name);
tail += added;
}
}
*tail = c;
head = tail;
}
}
# endif
if (p != NULL)
mch_chdir(olddir);
if (*fname != NUL)
{
l = STRLEN(buf);
if (l > 0 && buf[l - 1] != '/' && buf[l - 1] != '\\')
strcat(buf, pseps);
strcat(buf, fname);
}
return retval;
# endif
}
#endif
}
void
slash_adjust(char_u *p)
{
#ifdef OLD_DJGPP
if (*p == '\\' || *p == '/')
while (*p)
{
if (*p == '\\')
*p = '/';
mb_ptr_adv(p);
}
else
#endif
while (*p)
{
if (*p == psepcN)
*p = psepc;
mb_ptr_adv(p);
}
}
int
mch_isFullName(char_u *fname)
{
return (fname[0] != NUL && fname[1] == ':'
&& (fname[2] == '/' || fname[2] == '\\'))
|| (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'));
}
void
mch_early_init(void)
{
}
void
mch_exit(int r)
{
settmode(TMODE_COOK);
stoptermcap();
set_interrupts(FALSE);
#ifdef DJGPP
set_sys_cursor();
#endif
out_char('\r');
out_char('\n');
out_flush();
ml_close_all(TRUE);
#ifdef MCH_CURSOR_SHAPE
mch_restore_cursor_shape(TRUE);
#endif
exit(r);
}
void
mch_settmode(int tmode)
{
}
#ifdef FEAT_MOUSE
void
mch_setmouse(int on)
{
mouse_active = on;
mouse_hidden = TRUE;
}
#endif
int
mch_screenmode(char_u *arg)
{
int mode;
int i;
static char *(names[]) = {"BW40", "C40", "BW80", "C80", "MONO", "C4350"};
static int modes[] = { BW40, C40, BW80, C80, MONO, C4350};
mode = -1;
if (VIM_ISDIGIT(*arg))
mode = atoi((char *)arg);
else
{
for (i = 0; i < sizeof(names) / sizeof(char_u *); ++i)
if (stricmp(names[i], (char *)arg) == 0)
{
mode = modes[i];
break;
}
}
if (mode == -1)
{
EMSG("E362: Unsupported screen mode");
return FAIL;
}
textmode(mode);
#ifdef DJGPP
get_screenbase();
#endif
out_str(T_ME);
#ifdef FEAT_MOUSE
if (mode <= 1 || mode == 4 || mode == 5 || mode == 13 || mode == 0x13)
mouse_x_div = 16;
else
mouse_x_div = 8;
if (mode == 0x11 || mode == 0x12)
mouse_y_div = 16;
else if (mode == 0x10)
mouse_y_div = 14;
else
mouse_y_div = 8;
shell_resized();
#endif
return OK;
}
#ifndef DJGPP
extern struct text_info _video;
#endif
int
mch_get_shellsize(void)
{
struct text_info textinfo;
if (!term_console)
return FAIL;
gettextinfo(&textinfo);
Columns = textinfo.screenwidth;
Rows = textinfo.screenheight;
#ifndef DJGPP
if (textinfo.currmode > 10)
Rows = *(char far *)MK_FP(0x40, 0x84) + 1;
#endif
if (Columns < MIN_COLUMNS || Rows < MIN_LINES)
{
Columns = 80;
Rows = 25;
return FAIL;
}
#ifdef DJGPP
mytextinit(&textinfo);
#endif
return OK;
}
static void
set_window(void)
{
if (term_console)
{
#ifndef DJGPP
_video.screenheight = Rows;
#endif
mywindow(1, 1, Columns, Rows);
}
screen_start();
}
void
mch_set_shellsize(void)
{
}
void
mch_new_shellsize()
{
#ifdef FEAT_MOUSE
if (Columns <= 40)
mouse_x_div = 16;
if (Rows == 30)
mouse_y_div = 16;
#endif
set_window();
#ifdef FEAT_MOUSE
mouse_area();
#endif
}
#if defined(DJGPP) || defined(PROTO)
void
mch_check_columns()
{
static union REGS regs;
regs.h.ah = 0x0f;
(void)int86(0x10, ®s, ®s);
if ((unsigned)Columns > (unsigned)regs.h.ah)
Columns = (unsigned)regs.h.ah;
}
#endif
int
mch_call_shell(
char_u *cmd,
int options)
{
int x;
int tmode = cur_tmode;
#ifndef DJGPP
char_u *newcmd;
#endif
out_flush();
#ifdef DJGPP
set_sys_cursor();
#endif
if (options & SHELL_COOKED)
settmode(TMODE_COOK);
set_interrupts(FALSE);
#ifdef DJGPP
signal(SIGINT, SIG_IGN);
signal(SIGHUP, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
#endif
if (cmd == NULL)
x = system((char *)p_sh);
else
{
#ifdef DJGPP
setenv("SHELL", (char *)p_sh, 1);
x = system(cmd);
#else
newcmd = alloc(STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 3);
if (newcmd == NULL)
x = -1;
else
{
sprintf((char *)newcmd, "%s %s %s", p_sh, p_shcf, cmd);
x = system((char *)newcmd);
vim_free(newcmd);
}
#endif
}
#ifdef DJGPP
signal(SIGINT, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
#endif
if (tmode == TMODE_RAW)
settmode(TMODE_RAW);
set_interrupts(TRUE);
if (x && !(options & SHELL_SILENT) && !emsg_silent)
{
MSG_PUTS("\nshell returned ");
msg_outnum((long)x);
msg_putchar('\n');
}
return x;
}
void
mch_breakcheck(void)
{
if (ctrlc_pressed)
{
ctrlc_pressed = FALSE;
got_int = TRUE;
}
}
int
mch_has_exp_wildcard(char_u *p)
{
for ( ; *p; mb_ptr_adv(p))
{
if (vim_strchr((char_u *)"?*[", *p) != NULL
|| (*p == '~' && p[1] != NUL))
return TRUE;
}
return FALSE;
}
int
mch_has_wildcard(char_u *p)
{
for ( ; *p; mb_ptr_adv(p))
{
if (vim_strchr((char_u *)
# ifdef VIM_BACKTICK
"?*$[`"
# else
"?*$["
# endif
, *p) != NULL
|| (*p == '~' && p[1] != NUL))
return TRUE;
}
return FALSE;
}
int
mch_chdir(char *path)
{
if (path[0] == NUL)
return 0;
if (path[1] == ':')
{
if (change_drive(TOLOWER_ASC(path[0]) - 'a' + 1))
return -1;
path += 2;
}
if (*path == NUL)
return 0;
return chdir(path);
}
#ifdef DJGPP
int
mch_rename(const char *OldFile, const char *NewFile)
{
char_u *TempFile;
int retval;
int fd;
if (!_USE_LFN)
return rename(OldFile, NewFile);
if ((TempFile = alloc((unsigned)(STRLEN(OldFile) + 13))) == NULL)
return -1;
STRCPY(TempFile, OldFile);
STRCPY(gettail(TempFile), "axlqwqhy.ba~");
if (rename(OldFile, TempFile))
retval = -1;
else
{
if ((fd = open(OldFile, O_RDWR|O_CREAT|O_EXCL, 0444)) < 0)
return -1;
retval = rename(TempFile, NewFile);
close(fd);
mch_remove((char_u *)OldFile);
if (retval)
rename(TempFile, OldFile);
}
vim_free(TempFile);
return retval;
}
#endif
#if defined(DJGPP) || defined(PROTO)
#undef setlocale
#include <go32.h>
#include <inlines/ctype.ha>
#include <locale.h>
#define UPCASE (__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISUPPER)
#define LOCASE (__dj_ISALNUM | __dj_ISALPHA | __dj_ISGRAPH | __dj_ISPRINT | __dj_ISLOWER)
char *
djgpp_setlocale(void)
{
__dpmi_regs regs;
struct { char id; unsigned short off, seg; } __attribute__ ((packed)) info;
unsigned char buffer[0x82], lower, upper;
int i;
regs.x.ax = 0x6502;
regs.x.bx = 0xffff;
regs.x.dx = 0xffff;
regs.x.cx = 5;
regs.x.es = __tb >> 4;
regs.x.di = __tb & 0xf;
__dpmi_int(0x21, ®s);
if (regs.x.flags & 1)
return NULL;
dosmemget(__tb, 5, &info);
dosmemget((info.seg << 4) + info.off, 0x82, buffer);
if (*(short *)buffer != 0x80)
return NULL;
if (buffer[26] == 0x5f)
buffer[26] = 0x98;
for (i = 0; i < 0x80; i++)
{
lower = i + 0x80;
upper = (buffer+2)[i];
if (lower != upper)
{
__dj_ctype_flags[lower+1] = LOCASE;
__dj_ctype_toupper[lower+1] = upper;
if (__dj_ctype_flags[upper+1] == 0)
__dj_ctype_flags[upper+1] = UPCASE;
if (__dj_ctype_tolower[upper+1] == upper)
__dj_ctype_tolower[upper+1] = lower;
}
}
return "C";
}
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
#define CF_TEXT 0x01
#define CF_OEMTEXT 0x07
#define CF_VIMCLIP 0x04
static int Win16OpenClipboard(void);
static int Win16CloseClipboard(void);
static int Win16EmptyClipboard(void);
static char_u *Win16GetClipboardData(int clip_data_format);
static int Win16SetClipboardData(int clip_data_format, char_u *clip_data, int clip_data_size, int clip_data_type);
int
clip_mch_own_selection(VimClipboard *cbd)
{
return FAIL;
}
void
clip_mch_lose_selection(VimClipboard *cbd)
{
}
void
clip_mch_request_selection(VimClipboard *cbd)
{
int type = MCHAR;
char_u *pAllocated = NULL;
char_u *pClipText = NULL;
int clip_data_format = 0;
if (Win16OpenClipboard())
{
if ((pAllocated = Win16GetClipboardData(CF_VIMCLIP)) != NULL)
{
clip_data_format = CF_VIMCLIP;
pClipText = pAllocated;
switch (*pClipText++)
{
default:
case 'L': type = MLINE; break;
case 'C': type = MCHAR; break;
#ifdef FEAT_VISUAL
case 'B': type = MBLOCK; break;
#endif
}
}
else if ((pAllocated = Win16GetClipboardData(CF_TEXT)) != NULL)
{
clip_data_format = CF_TEXT;
pClipText = pAllocated;
type = (vim_strchr((char*)pClipText, '\r') != NULL) ? MLINE : MCHAR;
}
else if ((pAllocated = Win16GetClipboardData(CF_OEMTEXT)) != NULL)
{
clip_data_format = CF_OEMTEXT;
pClipText = pAllocated;
type = (vim_strchr((char*)pClipText, '\r') != NULL) ? MLINE : MCHAR;
}
if (pClipText != NULL)
{
char_u *pDest;
char_u *pStart;
char_u *pEnd;
long_u clip_data_size = 0;
pDest = strstr( pClipText, "\r\n" );
if (pDest != NULL)
{
pStart = pDest + 1;
pEnd = strstr( pStart, "\r\n" );
while (pEnd != NULL)
{
memmove(pDest, pStart, (long)(pEnd - pStart));
pDest += (long)(pEnd - pStart);
pStart = pEnd + 1;
pEnd = strstr(pStart, "\r\n");
}
pEnd = strchr(pStart, '\0');
memmove(pDest, pStart, (long)(pEnd - pStart));
pDest += (long)(pEnd - pStart);
*pDest = '\0';
clip_data_size = (long_u)(pDest - pClipText);
}
else
{
clip_data_size = STRLEN(pClipText);
}
clip_yank_selection(type, pClipText, clip_data_size, cbd);
vim_free(pAllocated);
}
Win16CloseClipboard();
} }
void
clip_mch_set_selection( VimClipboard *cbd )
{
char_u *pClipData = NULL;
long_u clip_data_size;
int clip_data_type;
cbd->owned = TRUE;
clip_get_selection(cbd);
cbd->owned = FALSE;
clip_data_type = clip_convert_selection(&pClipData, &clip_data_size, cbd);
if (clip_data_type < 0)
return;
if (Win16OpenClipboard())
{
if (Win16EmptyClipboard())
{
int sentOK;
sentOK = Win16SetClipboardData(CF_TEXT, pClipData,
clip_data_size, clip_data_type);
sentOK = Win16SetClipboardData(CF_VIMCLIP,
pClipData, clip_data_size, clip_data_type) && sentOK;
if (!sentOK)
{
EMSG("E450: Selection too large, cannot allocate DOS buffer");
}
}
Win16CloseClipboard();
}
vim_free(pClipData);
return;
}
static int
Win16OpenClipboard(void)
{
__dpmi_regs dpmi_regs;
long start_time;
int tick_count;
tick_count = 0;
dpmi_regs.x.ax = 0x1701;
if (__dpmi_int(0x2f, &dpmi_regs) == -1)
{
return FALSE;
}
while (dpmi_regs.x.ax == 0 && tick_count++ < 18)
{
start_time = biostime(0, 0L);
while (biostime(0, 0L) == start_time)
;
dpmi_regs.x.ax = 0x1701;
if (__dpmi_int(0x2f, &dpmi_regs) == -1)
{
return FALSE;
}
}
if (tick_count >= 18 && dpmi_regs.x.ax == 0)
return FALSE;
return TRUE;
}
static int
Win16CloseClipboard(void)
{
__dpmi_regs dpmi_regs;
dpmi_regs.x.ax = 0x1708;
if (__dpmi_int(0x2f, &dpmi_regs) == -1)
{
return FALSE;
}
return TRUE;
}
static int
Win16EmptyClipboard(void)
{
__dpmi_regs dpmi_regs;
dpmi_regs.x.ax = 0x1702;
if (__dpmi_int(0x2f, &dpmi_regs) == -1)
{
return FALSE;
}
if (dpmi_regs.x.ax == 0)
return FALSE;
return TRUE;
}
static void
FreeDOSMemory(int protected_mode_selector)
{
if (__dpmi_free_dos_memory(protected_mode_selector) == -1)
EMSG("E451: could not free DOS memory buffer (DJGPP)");
}
static char_u *
Win16GetClipboardData(int clip_data_format)
{
__dpmi_regs dpmi_regs;
int real_mode_segment_address;
int protected_mode_selector;
char_u *clip_data_buffer;
long_u clip_data_size;
switch (clip_data_format)
{
case CF_VIMCLIP:
case CF_TEXT:
case CF_OEMTEXT:
dpmi_regs.x.ax = 0x1704;
dpmi_regs.x.dx = clip_data_format;
if (__dpmi_int(0x2f, &dpmi_regs) == -1)
{
return NULL;
}
if (dpmi_regs.x.dx == 0 && dpmi_regs.x.ax == 0)
{
return NULL;
}
clip_data_size = dpmi_regs.x.ax + (dpmi_regs.x.dx << 16);
real_mode_segment_address = __dpmi_allocate_dos_memory(
(clip_data_size + 15) >> 4,
&protected_mode_selector);
if (real_mode_segment_address == -1)
{
EMSG("E452: Clipboard data too large, cannot allocate DOS buffer");
return NULL;
}
dpmi_regs.x.ax = 0x1705;
dpmi_regs.x.dx = clip_data_format;
dpmi_regs.x.es = real_mode_segment_address;
dpmi_regs.x.bx = 0;
if (__dpmi_int( 0x2f, &dpmi_regs) == -1)
{
EMSG("E453: could not copy clipboard data to DOS buffer");
FreeDOSMemory(protected_mode_selector);
return NULL;
}
clip_data_buffer = (char_u *)lalloc(clip_data_size + 1, TRUE);
if (clip_data_buffer == NULL)
{
EMSG("E454: could not allocate clipboard memory buffer");
FreeDOSMemory(protected_mode_selector);
return NULL;
}
*(clip_data_buffer + clip_data_size) = '\0';
movedata(
protected_mode_selector, 0,
_my_ds(), (unsigned)clip_data_buffer,
clip_data_size);
FreeDOSMemory(protected_mode_selector);
return clip_data_buffer;
default:
return NULL;
}
}
static int
Win16SetClipboardData(
int clip_data_format,
char_u *clip_data,
int clip_data_size,
int clip_data_type)
{
__dpmi_regs dpmi_regs;
int real_mode_segment_address;
int protected_mode_selector;
long_u protected_mode_offset = 0L;
int total_size = clip_data_size;
char_u *clip_sel_type;
if (clip_data_format == CF_VIMCLIP)
total_size++;
real_mode_segment_address = __dpmi_allocate_dos_memory(
(total_size + 15) >> 4,
&protected_mode_selector);
if (real_mode_segment_address == -1)
{
return FALSE;
}
if (clip_data_format == CF_VIMCLIP)
{
switch (clip_data_type)
{
default:
case MLINE: clip_sel_type = "L"; break;
case MCHAR: clip_sel_type = "C"; break;
#ifdef FEAT_VISUAL
case MBLOCK: clip_sel_type = "B"; break;
#endif
}
movedata(
_my_ds(), (unsigned)clip_sel_type,
protected_mode_selector, 0,
1);
protected_mode_offset += STRLEN(clip_sel_type);
}
movedata(
_my_ds(), (unsigned)clip_data,
protected_mode_selector,
protected_mode_offset,
clip_data_size);
dpmi_regs.x.ax = 0x1703;
dpmi_regs.x.dx = clip_data_format;
dpmi_regs.x.si = ((total_size >> 16)
& 0x0000ffffL);
dpmi_regs.x.cx = (total_size & 0x0000ffffL);
dpmi_regs.x.es = real_mode_segment_address;
dpmi_regs.x.bx = 0;
if (__dpmi_int(0x2f, &dpmi_regs) == -1)
{
FreeDOSMemory(protected_mode_selector);
return FALSE;
}
FreeDOSMemory(protected_mode_selector);
return TRUE;
}
#endif
#endif
#endif
static int
vim_chmod(char_u *name)
{
char_u *p;
int f;
int c = 0;
p = name + STRLEN(name);
if (p > name)
--p;
if (p > name && (*p == '\\' || *p == '/') && p[-1] != ':')
{
c = *p;
*p = NUL;
}
else
p = NULL;
#if defined(__BORLANDC__) && (__BORLANDC__ > 0x410)
f = _rtl_chmod((char *)name, 0, 0);
#else
f = _chmod((char *)name, 0, 0);
#endif
if (p != NULL)
*p = c;
return f;
}
long
mch_getperm(char_u *name)
{
return (long)vim_chmod(name);
}
int
mch_setperm(
char_u *name,
long perm)
{
perm |= FA_ARCH;
#if defined(__BORLANDC__) && (__BORLANDC__ > 0x410)
return (_rtl_chmod((char *)name, 1, (int)perm) == -1 ? FAIL : OK);
#else
return (_chmod((char *)name, 1, (int)perm) == -1 ? FAIL : OK);
#endif
}
void
mch_hide(char_u *name)
{
}
int
mch_isdir(char_u *name)
{
int f;
f = vim_chmod(name);
if (f == -1)
return FALSE;
if ((f & FA_DIREC) == 0)
return FALSE;
return TRUE;
}
int
mch_can_exe(name)
char_u *name;
{
char *p;
p = searchpath(name);
if (p == NULL || mch_isdir(p))
return FALSE;
return TRUE;
}
int
mch_nodetype(char_u *name)
{
if (STRICMP(name, "AUX") == 0
|| STRICMP(name, "CON") == 0
|| STRICMP(name, "CLOCK$") == 0
|| STRICMP(name, "NUL") == 0
|| STRICMP(name, "PRN") == 0
|| ((STRNICMP(name, "COM", 3) == 0
|| STRNICMP(name, "LPT", 3) == 0)
&& VIM_ISDIGIT(name[3])
&& name[4] == NUL))
return NODE_WRITABLE;
return NODE_NORMAL;
}
int
mch_dirname(
char_u *buf,
int len)
{
#ifdef DJGPP
if (getcwd((char *)buf, len) == NULL)
return FAIL;
slash_adjust(buf);
return OK;
#else
return (getcwd((char *)buf, len) != NULL ? OK : FAIL);
#endif
}
int
mch_remove(char_u *name)
{
(void)mch_setperm(name, 0);
return unlink((char *)name);
}
char_u *
mch_getenv(char_u *name)
{
int i;
#define MAXENVLEN 50
char_u var_copy[MAXENVLEN + 1];
char_u *p;
char_u *res;
if ((i = STRLEN(name)) > MAXENVLEN)
p = alloc(i + 1);
else
p = var_copy;
if (p == NULL)
p = name;
else
{
for (i = 0; name[i] != NUL; ++i)
p[i] = toupper(name[i]);
p[i] = NUL;
}
res = (char_u *)getenv((char *)p);
if (p != var_copy && p != name)
vim_free(p);
return res;
}
int
mch_get_user_name(
char_u *s,
int len)
{
*s = NUL;
return FAIL;
}
void
mch_get_host_name(
char_u *s,
int len)
{
#ifdef DJGPP
vim_strncpy(s, "PC (32 bits Vim)", len - 1);
#else
vim_strncpy(s, "PC (16 bits Vim)", len - 1);
#endif
}