--- os2sdk/demos/apps/terminal/terminal.c 2018/08/09 12:25:13 1.1 +++ os2sdk/demos/apps/terminal/terminal.c 2018/08/09 12:26:00 1.1.1.2 @@ -3,8 +3,7 @@ * TITLE * * terminal.c - * Copyright (C) Microsoft Corporation 1987 - * March 1987 + * Created by Microsoft Corporation 1987 * * DESCRIPTION * @@ -27,9 +26,15 @@ * ***/ +#define INCL_DOSSIGNALS +#define INCL_SUB +#define INCL_DOSFILEMGR +#define INCL_DOSPROCESS +#define INCL_DOSDEVICES + +#include +#include #include -#include -#include #include #include #include @@ -45,41 +50,41 @@ extern void discon_modem(void); /* di void init_com_port(void); /* initialise com port */ void far read_com_port(void); /* routine addr for a thread */ void write_com_port(void); /* routine addr for another thread */ -void far pascal handle_signals(int, int); /* BREAK signals handler */ +void APIENTRY handle_signals(USHORT,USHORT); /* BREAK signals handler */ void close_conn(void); /*close modem connection & com port*/ -void far xit(void); /* exit routine for this program */ +void far xit(void); /* exit routine for this program */ char *ErrMsg[] = { - "VIOGETCONFIG", - "KBDSETSTATUS", + "VIOGETCONFIG", + "KBDSETSTATUS", "OUT OF MEMORY", - "DOSCREATETHREAD", - "DOSCLOSE COMPORT", - "DOSDEVIOCTL SETDCB", - "DOSREAD", - "VIOWRTTTY", - "DOSOPEN: check if COM driver is installed", - "DOSDEVIOCTL SETBAUD", - "DOSDEVIOCTL SETLINECHAR", - "DOSDEVIOCTL GETDCB", - "KBDCHARIN", - "DOSWRITE", - "VIOWRTCHARSTRATT", - "VIOWRTNCELL", - "DOSEXITLIST ADD_ADDR", - "VIOSETCURPOS", - "VIOGETMODE", - "DOSDEVIOCTL FLUSH_XMIT_RECV_QUEUE", - "DOSDEVIOCTL GETCOM", - "DOSSETSIGHANDLER", - "DOSDEVIOCTL SETBREAKON", - "DOSDEVIOCTL SETBREAKOFF", + "DOSCREATETHREAD", + "DOSCLOSE COMPORT", + "DOSDEVIOCTL SETDCB", + "DOSREAD", + "VIOWRTTTY", + "DOSOPEN: check if COM driver is installed", + "DOSDEVIOCTL SETBAUD", + "DOSDEVIOCTL SETLINECHAR", + "DOSDEVIOCTL GETDCB", + "KBDCHARIN", + "DOSWRITE", + "VIOWRTCHARSTRATT", + "VIOWRTNCELL", + "DOSEXITLIST ADD_ADDR", + "VIOSETCURPOS", + "VIOGETMODE", + "DOSDEVIOCTL FLUSH_XMIT_RECV_QUEUE", + "DOSDEVIOCTL GETCOM", + "DOSSETSIGHANDLER", + "DOSDEVIOCTL SETBREAKON", + "DOSDEVIOCTL SETBREAKOFF", "INVALID SIGNAL", "do_option: invalid option type", "mod_option: invalid option type", "show_option: invalid option type" }; -unsigned FileHndl = NULL; /* COM port file handle */ +HFILE FileHndl = NULL; /* COM port file handle */ static char ExitPgm = FALSE; /* indicate if program should terminate */ static int ErrorNumber = -1, /* used as index to ErrMsg array */ @@ -119,14 +124,14 @@ main(argc,argv) int argc; char *argv[]; { - unsigned char *Stack1; /* stack for a thread */ - unsigned ThreadID, - RetCode, /* return code */ - NumBytes, /* number of bytes to be written */ + UCHAR *Stack1; /* stack for a thread */ + TID ThreadID; + unsigned RetCode, /* return code */ Result = TRUE; - long PrevAddress; - unsigned PrevAction; - static struct KbdStatus OurKbdStatus = + USHORT NumBytes; /* number of bytes to be written */ + PFNSIGHANDLER PrevAddress; + USHORT PrevAction; + static KBDINFO OurKbdStatus = {sizeof(OurKbdStatus),KBD_BITMASK,}; /* get COM port and modem options */ @@ -136,7 +141,7 @@ char *argv[]; init_com_port(); /* establish xit() as the exit routine */ - if ((RetCode = DOSEXITLIST(ADD_ADDR, xit)) != 0) + if ((RetCode = DosExitList(EXLST_ADD, (void (far *)(USHORT))xit)) != 0) error(ERR_DOSEXITLIST, RetCode); /* make modem connection if requested */ @@ -150,17 +155,17 @@ char *argv[]; /* create a thread that will execute the read_com_port() */ Stack1 += STACKSIZE; - if ((RetCode = DOSCREATETHREAD(read_com_port, &ThreadID, + if ((RetCode = DosCreateThread(read_com_port, &ThreadID, Stack1)) != 0) error(ERR_DOSCREATETHREAD, RetCode); /* set the keyboard status */ - if ((RetCode = KBDSETSTATUS((struct KbdStatus *) (&OurKbdStatus), + if ((RetCode = KbdSetStatus(&OurKbdStatus, RESERVED)) != 0) error(ERR_KBDSETSTATUS, RetCode); /* set signal handler for BREAK signal */ - if ((RetCode = DOSSETSIGHANDLER(handle_signals, + if ((RetCode = DosSetSigHandler(handle_signals, &PrevAddress, &PrevAction, RECV_CTRL, BREAK)) != 0) @@ -177,7 +182,7 @@ char *argv[]; -/*** init_com_port - open the COM port and initialise line charecteristics +/*** init_com_port - open the COM port and initialise line characteristics * * This routine opens the com port. It sets the com port options * BaudRate, DataBits, Parity and the StopBits. It sets the read timeout. @@ -198,8 +203,8 @@ char *argv[]; void init_com_port() { - unsigned ActionTaken, /* action: file existed,created,replaced */ - RetCode; + USHORT ActionTaken; /* action: file existed,created,replaced */ + unsigned RetCode; structLineChar sLineChar; /* line characteristics */ structDCB sDCB; /* device control block information */ structComOptions sComOptions; @@ -207,12 +212,12 @@ void init_com_port() get_com_options(&sComOptions); /* open the com port */ - if ((RetCode = DOSOPEN(sComOptions.pPortName, &FileHndl, + if ((RetCode = DosOpen(sComOptions.pPortName, &FileHndl, &ActionTaken, 0L, 0, 0x0001, 0x0042, 0L)) != 0) error(ERR_DOSOPEN, RetCode); /* set the baud rate */ - if ((RetCode = DOSDEVIOCTL(0L, (char *) &(sComOptions.iBaudRate), + if ((RetCode = DosDevIOCtl(0L, &(sComOptions.iBaudRate), SETBAUD, SERIAL, FileHndl)) != 0) error(ERR_IOCTLSETBAUD, RetCode); @@ -220,12 +225,12 @@ void init_com_port() sLineChar.DataBits = sComOptions.chDataBits; sLineChar.Parity = sComOptions.chParity; sLineChar.StopBits = sComOptions.chStopBits; - if ((RetCode = DOSDEVIOCTL(0L, (char *) &sLineChar, SETLINECHAR, + if ((RetCode = DosDevIOCtl(0L, &sLineChar, SETLINECHAR, SERIAL, FileHndl)) != 0) error(ERR_IOCTLSETLINECHAR, RetCode); /* get device control block info */ - if ((RetCode = DOSDEVIOCTL((char *) &sDCB, 0L, GETDCB, SERIAL, + if ((RetCode = DosDevIOCtl(&sDCB, 0L, GETDCB, SERIAL, FileHndl)) != 0) error(ERR_IOCTLGETDCB, RetCode); @@ -235,7 +240,7 @@ void init_com_port() sDCB.ReadTimeOut = READTIMEOUT; /* set read timout value */ /* set device control block info */ - if ((RetCode = DOSDEVIOCTL(0L, (char *) &sDCB, SETDCB, SERIAL, + if ((RetCode = DosDevIOCtl(0L, &sDCB, SETDCB, SERIAL, FileHndl)) != 0) error(ERR_IOCTLSETDCB, RetCode); } @@ -263,20 +268,20 @@ void init_com_port() void write_com_port() { - unsigned NumBytes, /* number of bytes actually written */ - RetCode; + USHORT NumBytes; /* number of bytes actually written */ + unsigned RetCode; char OutBuffer; /* output buffer */ - struct KeyData OurKeyData; /* struc to read a char from kbd */ + KBDKEYINFO OurKeyData; /* struc to read a char from kbd */ while (!ExitPgm) { /* read input from the keyboard */ - if ((RetCode = KBDCHARIN((struct KeyData *) (&OurKeyData), + if ((RetCode = KbdCharIn(&OurKeyData, IOWAIT, RESERVED)) != 0) - error(ERR_KBDCHARIN, RetCode); - OutBuffer = OurKeyData.char_code; + error(ERR_KBDCHARIN, RetCode); + OutBuffer = OurKeyData.chChar; if ((OutBuffer == 0) || (OutBuffer == 0xE0)) { - OutBuffer = OurKeyData.scan_code; + OutBuffer = OurKeyData.chScan; switch (OutBuffer) { case DEL_SCAN : OutBuffer = DEL_ASCII; break; @@ -286,13 +291,13 @@ void write_com_port() }; if (OutBuffer != ALT_F1) /* write the input from the keyboard to the com port */ - if ((RetCode = DOSWRITE(FileHndl, &OutBuffer, 1, + if ((RetCode = DosWrite(FileHndl, &OutBuffer, 1, &NumBytes)) != 0) - error(ERR_DOSWRITE, RetCode); + error(ERR_DOSWRITE, RetCode); } else { /* write the input from the keyboard to the com port */ - if ((RetCode = DOSWRITE(FileHndl, &OutBuffer, 1, + if ((RetCode = DosWrite(FileHndl, &OutBuffer, 1, &NumBytes)) != 0) error(ERR_DOSWRITE, RetCode); }; @@ -323,8 +328,8 @@ void write_com_port() void far read_com_port() { - unsigned NumBytes, /* number of bytes actually read */ - RetCode; + USHORT NumBytes; /* number of bytes actually read */ + unsigned RetCode; struct CharsInQue { /*data ret'ned by get num chars in que IOCTL*/ unsigned NumCharsInQue; unsigned SizeQue; @@ -333,20 +338,20 @@ void far read_com_port() while (!ExitPgm) { /* get number of characters in receive queue */ - if ((RetCode = DOSDEVIOCTL((char *) &sCharsInQue, 0L, GETNUMCHARS, + if ((RetCode = DosDevIOCtl(&sCharsInQue, 0L, GETNUMCHARS, SERIAL, FileHndl)) != 0) setup_error_msg(ERR_IOCTLSETDCB, RetCode); if (sCharsInQue.NumCharsInQue == 0) sCharsInQue.NumCharsInQue++; - if ((RetCode = DOSREAD(FileHndl, InBuffer, sCharsInQue.NumCharsInQue, + if ((RetCode = DosRead(FileHndl, InBuffer, sCharsInQue.NumCharsInQue, &NumBytes)) != 0) setup_error_msg(ERR_DOSREAD, RetCode); if (NumBytes) { /* write to the tty display */ - if ((RetCode = VIOWRTTTY(InBuffer, NumBytes, RESERVED)) != 0) + if ((RetCode = VioWrtTTy(InBuffer, NumBytes, RESERVED)) != 0) setup_error_msg(ERR_VIOWRTTTY, RetCode); } } @@ -375,22 +380,21 @@ void far read_com_port() * ***/ -void far pascal handle_signals(SigArg, SigNumber) -int SigArg, +void APIENTRY handle_signals(SigArg, SigNumber) +USHORT SigArg, SigNumber; { - unsigned RetCode, - NumBytes, + unsigned RetCode, Status; char OutBuffer; switch (SigNumber) { case BREAK :/* send BREAK to the com port */ - if ((RetCode = DOSDEVIOCTL((char *) &Status, 0L, + if ((RetCode = DosDevIOCtl(&Status, 0L, SETBREAKON, SERIAL, FileHndl)) != 0) error(ERR_IOCTLSETBREAKON, RetCode); - DOSSLEEP((long) 1); - if ((RetCode = DOSDEVIOCTL((char *) &Status, 0L, + DosSleep(1L); + if ((RetCode = DosDevIOCtl(&Status, 0L, SETBREAKOFF, SERIAL, FileHndl)) != 0) error(ERR_IOCTLSETBREAKOFF, RetCode); break; @@ -426,7 +430,7 @@ void close_conn() static char CloseMsg[] = "exiting terminal..."; /* send closing message to the display */ - if ((RetCode = VIOWRTTTY(CloseMsg, sizeof(CloseMsg), RESERVED)) != 0) + if ((RetCode = VioWrtTTy(CloseMsg, sizeof(CloseMsg), RESERVED)) != 0) print_err_msg(ErrMsg[ERR_VIOWRTTTY], RetCode); /* if modem connection was made, close it */ @@ -434,7 +438,7 @@ void close_conn() discon_modem(); /* close the com port */ - if ((RetCode = DOSCLOSE(FileHndl)) != 0) + if ((RetCode = DosClose(FileHndl)) != 0) print_err_msg(ErrMsg[ERR_DOSCLOSECOMPORT], RetCode); } @@ -452,7 +456,7 @@ void close_conn() * the threads, there will be no race condition in error reporting. * * The following routines are also part of the error handling: - * - xit() is a DOSEXITLIST routine + * - xit() is a DosExitList routine * - print_err_msg() does the actual printing of the error message * * All the routines discussed above are defined below. @@ -464,7 +468,7 @@ void close_conn() /*** error * * This routine is invoked when there is an error. It prints an - * an error message and calls DOSEXIT. + * an error message and calls DosExit. * * error(ErrNum, RetCode) * @@ -474,8 +478,8 @@ void close_conn() * * EXIT * global variables ErrorNumber & ReturnCode still contain the - * initial value of -1. At program termination (via DOSEXIT call) - * the DOSEXITLIST routine xit() is invoked (described below). + * initial value of -1. At program termination (via DosExit call) + * the DosExitList routine xit() is invoked (described below). * On return from xit(), this program will terminate. * * WARNING @@ -489,7 +493,7 @@ int ErrNum; int RetCode; { print_err_msg(ErrMsg[ErrNum], RetCode); - DOSEXIT(1, 1); + DosExit(EXIT_PROCESS, 1); } @@ -497,7 +501,7 @@ int RetCode; /*** setup_error_msg - setup error message * - * Sets up the global ErrorNumber and ReturnCode. It then calls DOSEXIT. + * Sets up the global ErrorNumber and ReturnCode. It then calls DosExit. * * setup_error_msg(ErrNum, RetCode) * @@ -507,7 +511,7 @@ int RetCode; * * EXIT * global variables ErrorNumber & ReturnCode are setup. At - * program termination (via DOSEXIT call) the DOSEXITLIST + * program termination (via DosExit call) the DosExitList * routine xit() is invoked (described below). xit() will print * an error message. On return from xit(), this program will * terminate. @@ -524,7 +528,7 @@ int ErrNum, { ErrorNumber = ErrNum; ReturnCode = RetCode; - DOSEXIT(1, 1); + DosExit(EXIT_PROCESS, 1); } @@ -532,7 +536,7 @@ int ErrNum, /*** xit - exit function executed at program termination * - * This is a DOSEXITLIST routine. It prints an error message if + * This is a DosExitList routine. It prints an error message if * the global variable ErrorNumber is non-negative. * * xit() @@ -549,12 +553,12 @@ int ErrNum, * ***/ -void far xit() +void far xit(void) { if (ErrorNumber != -1) print_err_msg(ErrMsg[ErrorNumber], ReturnCode); close_conn(); /* close modem connection and the com port */ - DOSEXITLIST(XFER, 0L); + DosExitList(XFER, 0L); }