Skip to content

Commit fdd95ca

Browse files
committed
VT port in DOS with Digital Mars compiler : workaround for duplicate getch()es
Both the curses library _and_ the Digital Mars runtime library have a function called int getch( void). This patch (which applies _only_ to the VT port compiled with DMC for DOS) works around that problem.
1 parent 4e23068 commit fdd95ca

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

vt/Makefile.dmc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ CC = dmc
2424

2525
CHTYPE = -DCHTYPE_32
2626

27-
CFLAGS = -c -o+space -Nc -mld -DDOS
28-
# CFLAGS = -c -o+space -Nc -mld -DDOS
27+
CFLAGS = -c -o+space -Nc
2928

30-
CPPFLAGS = -I$(PDCURSES_SRCDIR) -msd $(CHTYPE)
29+
CPPFLAGS = -I$(PDCURSES_SRCDIR) -DDOS -mld $(CHTYPE)
3130

3231
LINK = dmc
3332
LIBEXE = lib
@@ -60,7 +59,7 @@ scanw.obj scr_dump.obj scroll.obj slk.obj termattr.obj terminfo.obj \
6059
touch.obj util.obj window.obj debug.obj
6160

6261
PDCOBJS = pdcclip.obj pdcdisp.obj pdcgetsc.obj pdckbd.obj pdcscrn.obj \
63-
pdcsetsc.obj pdcutil.obj
62+
pdcsetsc.obj pdcutil.obj getch2.obj
6463

6564
DEMOOBS = calendar.obj firework.obj init_col.obj mbrot.obj \
6665
newtest.obj ozdemo.obj picsview.obj ptest.obj rain.obj speed.obj \
@@ -225,6 +224,9 @@ pdcsetsc.obj: $(osdir)\pdcsetsc.c
225224
pdcutil.obj: $(osdir)\pdcutil.c
226225
$(OSBUILD)
227226

227+
getch2.obj: getch2.c
228+
$(OSBUILD)
229+
228230
calendar.exe: $(demodir)\calendar.c
229231
$(DEMOBUILD)
230232

vt/getch2.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <conio.h>
2+
3+
/* Both the curses library and the Digital Mars runtime library have
4+
functions called int getch( void). With the following, code in pdckbd.c
5+
can call dmc_getch() and get the DMC library version. It is used _only_
6+
with Digital Mars; other compilers don't have the name collision. */
7+
8+
int dmc_getch( )
9+
{
10+
return( _getch( ));
11+
}

vt/pdckbd.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include <stdio.h>
32
#include <string.h>
43
#include <stdlib.h>
@@ -15,12 +14,16 @@
1514
#include "pdcvt.h"
1615
#include "../common/mouse.c"
1716

18-
#if defined( __BORLANDC__) || defined( DOS)
17+
#if defined( __BORLANDC__)
1918
#define WINDOWS_VERSION_OF_KBHIT kbhit
2019
#else
2120
#define WINDOWS_VERSION_OF_KBHIT _kbhit
2221
#endif
2322

23+
#ifdef __DMC__
24+
int dmc_getch( void); /* see 'getch2.c' */
25+
#endif
26+
2427
/* Modified from the accepted answer at
2528
2629
https://stackoverflow.com/questions/33025599/move-the-cursor-in-a-c-program
@@ -81,7 +84,11 @@ static bool check_key( int *c)
8184
{
8285
rval = TRUE;
8386
if( c)
87+
#ifdef __DMC__
88+
*c = dmc_getch( ); /* see 'getch2.c' */
89+
#else
8490
*c = _getch( );
91+
#endif
8592
}
8693
else
8794
rval = FALSE;

0 commit comments

Comments
 (0)