Commit 46251197 authored by deuce's avatar deuce
Browse files

Use alloca() instead of malloc()/free() where possible.

parent 537015dc
......@@ -69,7 +69,6 @@ int ansi_cols=80;
int ansi_got_row=0;
int ansi_got_col=0;
int ansi_esc_delay=25;
int puttext_no_move=0;
const int ansi_tabs[10]={9,17,25,33,41,49,57,65,73,80};
const int ansi_colours[8]={0,4,2,6,1,5,3,7};
......@@ -223,6 +222,7 @@ int ansi_puttext(int sx, int sy, int ex, int ey, void* buf)
struct text_info ti;
int attrib;
unsigned char *fill = (unsigned char*)buf;
char str[16];
gettextinfo(&ti);
......@@ -243,11 +243,10 @@ int ansi_puttext(int sx, int sy, int ex, int ey, void* buf)
attrib=ti.attribute;
i=0; /* Did a nasty. */
/* Check if this is a nasty scroll */
/* Check if this is a nasty screen clear... */
j=0; /* We can clearscreen */
if(sx==1 && sy==1 && ex==ti.screenwidth && ey==ti.screenheight && (*out==' ' || *out==0)) {
if(!i && sx==1 && sy==1 && ex==ti.screenwidth && ey==ti.screenheight && (*out==' ' || *out==0)) {
j=1; /* We can clearscreen */
for(cy=sy-1;cy<ey;cy++) {
for(cx=sx-1;cx<ex;cx++) {
......@@ -269,6 +268,47 @@ int ansi_puttext(int sx, int sy, int ex, int ey, void* buf)
memcpy(ansivmem,out,ti.screenwidth*ti.screenheight*2);
i=1;
}
#if 0
/* Check if this is a scroll */
if(sx==1 && sy==1 && ex==ti.screenwidth && ey==ti.screenheight-1
&& memcmp(buf,ansivmem,ti.screenwidth*(ti.screenheight-1)*2)==0) {
/* We need to get to the bottom line... */
if(ansi_row < ti.screenheight-1) {
if(ansi_row > ti.screenheight-5) {
ansi_sendstr("\n\n\n\n\n",ti.screenheight-ansi_row-1);
}
else {
sprintf(str,"\033[%dB",ti.screenheight-ansi_row-1);
ansi_sendstr(str,-1);
}
}
ansi_sendstr("\n",1);
memcpy(ansivmem,buf,ti.screenwidth*(ti.screenheight-1)*2);
for(x=0;x<ti.screenwidth;x++)
ansivmem[(ti.screenheight-1)*ti.screenwidth+x]=(ti.attribute<<8)|' ';
i=1;
}
/* Check if this *includes* a scroll */
if(sx==1 && sy==1 && ex==ti.screenwidth && ey==ti.screenheight
&& memcmp(buf,ansivmem,ti.screenwidth*(ti.screenheight-1)*2)==0) {
/* We need to get to the bottom line... */
if(ansi_row < ti.screenheight-1) {
if(ansi_row > ti.screenheight-5) {
ansi_sendstr("\n\n\n\n\n",ti.screenheight-ansi_row-1);
}
else {
sprintf(str,"\033[%dB",ti.screenheight-ansi_row-1);
ansi_sendstr(str,-1);
}
}
ansi_sendstr("\n",1);
memcpy(ansivmem,buf,ti.screenwidth*(ti.screenheight-1)*2);
for(x=0;x<ti.screenwidth;x++)
ansivmem[(ti.screenheight-1)*ti.screenwidth+x]=(ti.attribute<<8)|' ';
out += ti.screenwidth*(ti.screenheight-1)*2;
sy=ti.screenheight;
}
#endif
if(!i) {
for(y=sy-1;y<ey;y++) {
for(x=sx-1;x<ex;x++) {
......@@ -341,7 +381,7 @@ int ansi_puttext(int sx, int sy, int ex, int ey, void* buf)
}
}
if(!puttext_no_move)
if(!puttext_can_move)
gotoxy(ti.curx,ti.cury);
if(attrib!=ti.attribute)
textattr(ti.attribute);
......@@ -619,7 +659,7 @@ int ansi_putch(int ch)
buf[1]=ansi_curr_attr>>8;
gettextinfo(&ti);
puttext_no_move=1;
puttext_can_move=1;
switch(ch) {
case '\r':
......@@ -675,7 +715,7 @@ int ansi_putch(int ch)
break;
}
puttext_no_move=0;
puttext_can_move=0;
return(ch);
}
......
......@@ -37,7 +37,7 @@
#endif
#include <stdarg.h>
#include <stdlib.h> /* malloc */
#include <stdlib.h> /* alloca */
#include <stdio.h>
#include <threadwrap.h>
......@@ -68,6 +68,7 @@ static int lastmode=3;
CIOLIBEXPORT int _wscroll=1;
CIOLIBEXPORT int directvideo=0;
CIOLIBEXPORT int hold_update=0;
CIOLIBEXPORT int puttext_can_move=0;
static int initialized=0;
CIOLIBEXPORT int CIOLIBCALL ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy);
......@@ -415,18 +416,13 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_movetext(int sx, int sy, int ex, int ey, int
width=ex-sx;
height=ey-sy;
buf=(unsigned char *)malloc((width+1)*(height+1)*2);
buf=(unsigned char *)alloca((width+1)*(height+1)*2);
if(buf==NULL)
return(0);
if(!ciolib_gettext(sx,sy,ex,ey,buf)) {
free(buf);
if(!ciolib_gettext(sx,sy,ex,ey,buf))
return(0);
}
if(!ciolib_puttext(dx,dy,dx+width,dy+height,buf)) {
free(buf);
if(!ciolib_puttext(dx,dy,dx+width,dy+height,buf))
return(0);
}
free(buf);
return(1);
}
......@@ -702,13 +698,12 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_clreol(void)
width=ti.winright-ti.curx+1;
height=1;
buf=(unsigned char *)malloc(width*height*2);
buf=(unsigned char *)alloca(width*height*2);
for(i=0;i<width*height*2;) {
buf[i++]=' ';
buf[i++]=ti.attribute;
}
ciolib_puttext(ti.curx+ti.winleft-1,ti.cury+ti.wintop-1,ti.winright,ti.cury+ti.wintop-1,buf);
free(buf);
}
CIOLIBEXPORT void CIOLIBCALL ciolib_clrscr(void)
......@@ -724,14 +719,13 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_clrscr(void)
width=ti.winright-ti.winleft+1;
height=ti.winbottom-ti.wintop+1;
buf=(unsigned char *)malloc(width*height*2);
buf=(unsigned char *)alloca(width*height*2);
for(i=0;i<width*height*2;) {
buf[i++]=' ';
buf[i++]=ti.attribute;
}
ciolib_puttext(ti.winleft,ti.wintop,ti.winright,ti.winbottom,buf);
ciolib_gotoxy(1,1);
free(buf);
}
CIOLIBEXPORT void CIOLIBCALL ciolib_delline(void)
......@@ -781,7 +775,7 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_cprintf(char *fmat, ...)
ret=vsnprintf(NULL,0,fmat,argptr);
if(ret<0)
return(EOF);
str=(char *)malloc(ret+1);
str=(char *)alloca(ret+1);
if(str==NULL)
return(EOF);
ret=vsprintf(str,fmat,argptr);
......@@ -791,9 +785,6 @@ CIOLIBEXPORT int CIOLIBCALL ciolib_cprintf(char *fmat, ...)
ciolib_cputs(str);
else
ret=EOF;
#ifndef _MSC_VER
free(str);
#endif
return(ret);
}
......
......@@ -251,6 +251,7 @@ CIOLIBEXPORTVAR cioapi_t cio_api;
CIOLIBEXPORTVAR int _wscroll;
CIOLIBEXPORTVAR int directvideo;
CIOLIBEXPORTVAR int hold_update;
CIOLIBEXPORTVAR int puttext_can_move;
#define _conio_kbhit() kbhit()
......
# Microsoft Developer Studio Project File - Name="conio" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=conio - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "conio.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "conio.mak" CFG="conio - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "conio - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "conio - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "conio - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "msvc.win32.release"
# PROP Intermediate_Dir "msvc.win32.release_mt"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "..\xpdev" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LINK_LIST_THREADSAFE" /YX /FD /Zm400 /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "conio - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "msvc.win32.debug"
# PROP Intermediate_Dir "msvc.win32.debug_mt"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "." /I "..\xpdev" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LINK_LIST_THREADSAFE" /YX /FD /GZ /Zm400 /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "conio - Win32 Release"
# Name "conio - Win32 Debug"
# Begin Source File
SOURCE=.\allfonts.c
# End Source File
# Begin Source File
SOURCE=.\ansi_cio.c
# End Source File
# Begin Source File
SOURCE=.\ciolib.c
# End Source File
# Begin Source File
SOURCE=.\cterm.c
# End Source File
# Begin Source File
SOURCE=.\mouse.c
# End Source File
# Begin Source File
SOURCE=.\vidmodes.c
# End Source File
# Begin Source File
SOURCE=.\win32cio.c
# End Source File
# End Target
# End Project
# Microsoft Developer Studio Project File - Name="conio" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=conio - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "conio.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "conio.mak" CFG="conio - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "conio - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "conio - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "conio - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "msvc.win32.release"
# PROP Intermediate_Dir "msvc.win32.release_mt"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "..\xpdev" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LINK_LIST_THREADSAFE" /YX /FD /Zm400 /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "conio - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "msvc.win32.debug"
# PROP Intermediate_Dir "msvc.win32.debug_mt"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "." /I "..\xpdev" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LINK_LIST_THREADSAFE" /YX /FD /GZ /Zm400 /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "conio - Win32 Release"
# Name "conio - Win32 Debug"
# Begin Source File
SOURCE=.\allfonts.c
# End Source File
# Begin Source File
SOURCE=.\ansi_cio.c
# End Source File
# Begin Source File
SOURCE=.\ciolib.c
# End Source File
# Begin Source File
SOURCE=.\cterm.c
# End Source File
# Begin Source File
SOURCE=.\mouse.c
# End Source File
# Begin Source File
SOURCE=.\vidmodes.c
# End Source File
# Begin Source File
SOURCE=.\win32cio.c
# End Source File
# End Target
# End Project
......@@ -460,7 +460,7 @@ video_update_text()
curscol=CursCol;
wakeup_poll(); /* Wake up anyone waiting on kbd poll */
vmemc = (WORD *)malloc(DpyCols*(DpyRows+1)*sizeof(WORD));
vmemc = (WORD *)alloca(DpyCols*(DpyRows+1)*sizeof(WORD));
pthread_mutex_lock(&lines_mutex);
memcpy(vmemc, vmem, DpyCols*(DpyRows+1)*sizeof(WORD));
for (r = 0; r < (DpyRows+1); ++r) {
......@@ -501,8 +501,6 @@ video_update_text()
flush=1;
}
free(vmemc);
or =cursrow;
oc =curscol;
os =show;
......
......@@ -366,7 +366,7 @@ void scrolldown(void)
char *buf;
int i,j;
buf=(char *)malloc(cterm.width*(cterm.height-1)*2);
buf=(char *)alloca(cterm.width*(cterm.height-1)*2);
gettext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y+cterm.height-2,buf);
puttext(cterm.x,cterm.y+1,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
j=0;
......@@ -375,7 +375,6 @@ void scrolldown(void)
buf[j++]=cterm.attr;
}
puttext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y,buf);
free(buf);
}
void scrollup(void)
......@@ -391,7 +390,7 @@ void scrollup(void)
}
gettext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y,cterm.scrollback+(cterm.backpos-1)*cterm.width*2);
}
buf=(char *)malloc(cterm.width*(cterm.height-1)*2);
buf=(char *)alloca(cterm.width*(cterm.height-1)*2);
gettext(cterm.x,cterm.y+1,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
puttext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y+cterm.height-2,buf);
j=0;
......@@ -400,7 +399,6 @@ void scrollup(void)
buf[j++]=cterm.attr;
}
puttext(cterm.x,cterm.y+cterm.height-1,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
free(buf);
}
void dellines(int lines)
......@@ -408,7 +406,7 @@ void dellines(int lines)
char *buf;
int i,j;
buf=(char *)malloc(cterm.width*(cterm.height-1)*2);
buf=(char *)alloca(cterm.width*(cterm.height-1)*2);
gettext(cterm.x,cterm.y+wherey()+lines-1,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
puttext(cterm.x,cterm.y+wherey()-1,cterm.x+cterm.width-1,cterm.y+cterm.height-1-lines,buf);
j=0;
......@@ -417,7 +415,6 @@ void dellines(int lines)
buf[j++]=cterm.attr;
}
puttext(cterm.x,cterm.y+cterm.height-lines,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
free(buf);
}
void clear2bol(void)
......@@ -425,14 +422,13 @@ void clear2bol(void)
char *buf;
int i,j;
buf=(char *)malloc((wherex()+1)*2);
buf=(char *)alloca((wherex()+1)*2);
j=0;
for(i=1;i<=wherex();i++) {
buf[j++]=' ';
buf[j++]=cterm.attr;
}
puttext(cterm.x+1,cterm.y+wherey(),cterm.x+wherex(),cterm.y+wherey(),buf);
free(buf);
}
void clear2eol(void)
......@@ -625,7 +621,7 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
switch(i) {
case 0:
clear2eol();
p2=(char *)malloc(cterm.width*2);
p2=(char *)alloca(cterm.width*2);
j=0;
for(i=0;i<cterm.width;i++) {
p2[j++]=' ';
......@@ -634,11 +630,10 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
for(i=wherey()+1;i<=cterm.height;i++) {
puttext(cterm.x+1,cterm.y+i,cterm.x+cterm.width,cterm.y+i,p2);
}
free(p2);
break;
case 1:
clear2bol();
p2=(char *)malloc(cterm.width*2);
p2=(char *)alloca(cterm.width*2);
j=0;
for(i=0;i<cterm.width;i++) {
p2[j++]=' ';
......@@ -647,7 +642,6 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
for(i=wherey()-1;i>=1;i--) {
puttext(cterm.x+1,cterm.y+i,cterm.x+cterm.width,cterm.y+i,p2);
}
free(p2);
break;
case 2:
clearscreen((char)cterm.attr);
......@@ -665,14 +659,13 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
clear2bol();
break;
case 2:
p2=(char *)malloc(cterm.width*2);
p2=(char *)alloca(cterm.width*2);
j=0;
for(i=0;i<cterm.width;i++) {
p2[j++]=' ';
p2[j++]=cterm.attr;
}
puttext(cterm.x+1,cterm.y+wherey(),cterm.x+cterm.width,cterm.y+wherey(),p2);
free(p2);
break;
}
break;
......@@ -683,12 +676,11 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
if(i>cterm.height-wherey())
i=cterm.height-wherey();
if(i<cterm.height-wherey()) {
p2=(char *)malloc((cterm.height-wherey()-i)*cterm.width*2);
p2=(char *)alloca((cterm.height-wherey()-i)*cterm.width*2);
gettext(cterm.x+1,cterm.y+wherey(),cterm.x+cterm.width,wherey()+(cterm.height-wherey()-i),p2);
puttext(cterm.x+1,cterm.y+wherey()+i,cterm.x+cterm.width,wherey()+(cterm.height-wherey()),p2);
free(p2);
}
p2=(char *)malloc(cterm.width*2);
p2=(char *)alloca(cterm.width*2);
j=0;
for(k=0;k<cterm.width;k++) {
p2[j++]=' ';
......@@ -697,7 +689,6 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
for(i=0;j<i;i++) {
puttext(cterm.x+1,cterm.y+i,cterm.x+cterm.width,cterm.y+i,p2);
}
free(p2);
break;
case 'M': /* ANSI music and also supposed to be delete line! */
if(cterm.music_enable==CTERM_MUSIC_ENABLED) {
......@@ -722,13 +713,12 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
i=1;
if(i>cterm.width-wherex())
i=cterm.width-wherex();
p2=(char *)malloc((cterm.width-wherex())*2);
p2=(char *)alloca((cterm.width-wherex())*2);
gettext(cterm.x+wherex(),cterm.y+wherey(),cterm.x+cterm.width,cterm.y+wherey(),p2);
memmove(p2,p2+(i*2),(cterm.width-wherex()-i)*2);
for(i=(cterm.width-wherex())*2-2;i>=wherex();i-=2)
p2[i]=' ';
puttext(cterm.x+wherex(),cterm.y+wherey(),cterm.x+cterm.width,cterm.y+wherey(),p2);
free(p2);
break;
case 'S':
i=atoi(cterm.escbuf+1);
......@@ -1182,7 +1172,10 @@ char *cterm_write(unsigned char *buf, int buflen, char *retbuf, size_t retsize,
int j,k;
struct text_info ti;
int olddmc;
int oldptnm;
oldptnm=puttext_can_move;
puttext_can_move=1;
olddmc=hold_update;
hold_update=1;
if(retbuf!=NULL)
......@@ -1397,6 +1390,7 @@ char *cterm_write(unsigned char *buf, int buflen, char *retbuf, size_t retsize,
#endif
hold_update=olddmc;
puttext_can_move=oldptnm;
gotoxy(wherex(),wherey());
return(retbuf);
}
......
......@@ -552,7 +552,7 @@ int win32_gettext(int left, int top, int right, int bottom, void* buf)
reg.Right=right-1;
reg.Top=top-1;
reg.Bottom=bottom-1;
ci=(CHAR_INFO *)malloc(sizeof(CHAR_INFO)*(bs.X*bs.Y));
ci=(CHAR_INFO *)alloca(sizeof(CHAR_INFO)*(bs.X*bs.Y));
if((h=GetStdHandle(STD_OUTPUT_HANDLE)) != INVALID_HANDLE_VALUE)
ReadConsoleOutput(h,ci,bs,bc,&reg);
for(y=0;y<=(bottom-top);y++) {
......@@ -561,7 +561,6 @@ int win32_gettext(int left, int top, int right, int bottom, void* buf)
bu[(((y*bs.X)+x)*2)+1]=WintoDOSAttr(ci[(y*bs.X)+x].Attributes);
}
}
free(ci);
return 1;
}
......@@ -625,7 +624,7 @@ int win32_puttext(int left, int top, int right, int bottom, void* buf)
reg.Right=right-1;
reg.Top=top-1;
reg.Bottom=bottom-1;
ci=(CHAR_INFO *)malloc(sizeof(CHAR_INFO)*(bs.X*bs.Y));