wine/misc/comm.c
Alexandre Julliard 5f721f81fd Release 0.5
Sun Jan  2 12:38:53 1994  David Metcalfe <david@prism.demon.co.uk>

	* [windows/class.c]
	Implemented GetClassName and GetClassInfo.

	* [windows/caret.c]
	Various improvements to text caret code.

Fri Dec 31 15:22:22 1993  John Brezak <brezak@apollo.hp.com>

	* [misc/comm.c]
	Patches to work with NetBSD.

Thu Dec 30 12:11:55 1993  John Richardson <jrichard@cs.uml.edu>

	* [objects/bitblt.c] Added StretchBlt().

Tue Jan  4 05:22:07 1994  julliard@di.epfl.ch (Alexandre Julliard)

	* [misc/user.c]
	Added creation of system message queue.

	* [objects/bitmap.c] [objects/dcvalues.c] [windows/dc.c]
	Added DC size fields into DC structure.		

	* [objects/clipping.c]
	Bug fix in CLIPPING_IntersectRect().

	* [windows/class.c]
	Allocate a DCE instead of a DC for CS_CLASSDC classes.

	* [windows/clipping.c]
	Fixed GetUpdateRect() and GetUpdateRgn() to clip to the client area.

	* [windows/dce.c]
	Implemented GetDCEx() and GetWindowDC().

	* [windows/defwnd.c]
	Implemented WM_WINDOWPOSCHANGED handling.

	* [windows/event.c]
	Preliminary support for Xlib event handling instead of Xt callbacks.
	Changed MSG_AddMsg() calls to hardware_event() or PostMessage().

	* [windows/message.c]
	Preliminary support for multiple message queues.
	Implemented hardware_event() to store messages into the system queue.
	Implemented Get/SetTaskQueue().
	Better WM_PAINT and WM_TIMER handling.
	Changes to use Xlib instead of Xt for events.

	* [windows/painting.c]
	Use GetDCEx() to retrieve the DC, to get a correct visible region.

	* [windows/timer.c]
	Moved the timer procedure callback into DispatchMessage().
	Changed implementation to get rid of Xt timeouts.  Timer checking
	is now done inside GetMessage().

	* [windows/win.c]
	Allocate a DCE instead of a DC for CS_OWNDC windows.
	Replaced Xt calls with Xlib calls.
	Moved window positioning functions into windows/winpos.c

	* [windows/winpos.c]  (New file)
	Rewritten most of the window positioning functions.
	Implemented SetWindowPos() and MapWindowPoints().

Jan 3, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [if1632/user.spec]
	Bad arguments description for function SetDlgItemText.

	* [objects/text.c]
	Function DrawText now handle DT_CALCRECT request.

	* [misc/message.c]
	Message boxes now use DrawText with DT_CALCRECT.

	* [windows/graphics.c]
	Bug fix in function FrameRect, (it was using PEN instead of BRUSH).

	* [windows/win.c]
	Bug fix for flags in function ShowWindow.
	More accurate WM_SIZE generated by function ShowWindow.

	* [controls/listbox.c]
	More code for LBS_MULTIPLESEL.
	More code for LBS_MULTICOLUMN.

	* [include/windows.h]
	Bad define for MF_SEPARATOR.

	* [controls/menu.c]
	New functions: PopMenuWndProc() with 'glues',
	CreatePopupMenu(), AppendMenu(), InsertMenu(), RemoveMenu(), 
	DeleteMenu(), ModifyMenu(), TrackPopupMenu().
	Code in stubs: CreateMenu(), DestroyMenu(). 

Sat Jan  1 10:22:43 1994  Bob Amstadt  (bob@pooh)

	* loader/wine.c: Added support for relocation types 5 and 6.

Mon Dec 27 11:06:03 1993  Erik Bos (erik@trashcan.hacktic.nl)

	* [misc/comm.c]
	new functions: BuildCommDCB(), OpenComm(), CloseComm(),
	SetCommBreak(), ClearCommBreak(), EscapeCommFunction(), FlushComm(),
	GetCommError(), SetCommEventMask(), GetCommEventMask(),
	SetCommState(), GetCommState(), TransmitCommChar(), ReadComm(), 
	WriteComm().

Wed Dec 22 13:00:15 1993  David Metcalfe <david@prism.demon.co.uk>

	* [windows/caret.c]
	Implemented text caret functions.

Tue Dec 21 06:13:58 1993  julliard@di.epfl.ch (Alexandre Julliard)

	* [loader/wine.c]
	Bug fix in LoadImage().

	* [objects/bitblt.c] [objects/clipping.c] [objects/text.c]
	  [windows/dc.c] [windows/dce.c] [windows/graphics.c]
	Modified graphics calls to take into account the DC origin.

	* [windows/defwnd.c]
	Added preliminary WM_NCCALCSIZE handling.

	* [windows/event.c]
	Send WM_NCCALCSIZE message on resize event.

	* [windows/win.c]
	Send WM_NCCALCSIZE message in CreateWindow().
	Realize widgets at creation time (should prevent problems with
	unrealized widgets).

Dec 19, 93 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [controls/static.c]
	Send mouse & keyboard message received to its parent.

	* [controls/scroll.c]
	Send keyboard message received to its parent.

	* [controls/listbox.c]
	Add Navigation keys .
	ListBox now use VSCROLL & HSCROLL instead of children.
	Alpha version of LBS_MULTIPLESEL.
	Alpha version of LBS_MULTICOLUMN.

	* [controls/combo.c]
	Add Navigation keys on closed ComboBox.
	Remove useless 'COMBOBOX_CreateComboBox' function.

Mon Dec 19 20:39:34 1993  Erik Bos (erik@trashcan.hacktic.nl)

	* [loader/wine.
	LoadImage() modified to use FindFile().

	* [misc/file.c]
	SetErrorMode added

	* [misc/dos_fs.c]
	bug fixes.

Dec 13, 93 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [memory/global.c]
	bug fix in GlobalGetFreeSegment : good ptr in 'g_prev'.

	* [sysres.dll]
	preliminary version of a 'glass of wine' bitmap

	* [windows/event.c]
	New function 'GetCapture'.

	* [controls/scroll.c]
	Remove useless 'SCROLLBAR_CreateScrollBar' function.

	* [controls/listbox.c]
	Remove useless 'LISTBOX_CreateListBox' function.

Mon Dec 13 13:51:00 1993  David Metcalfe <david@prism.demon.co.uk>

	* [objects/font.c]
	Corrected bugs in GetCharWidth().

	* [windows/event.c]
	Modified EVENT_key to send Windows virtual key codes for
	WM_KEYDOWN and WM_KEYUP messages, and a WM_CHAR message
	for printable characters.

Wed Dec 08 19:20:00 1993  Karl Guenter Wuensch (hn324wu@unidui.uni-duisburg.de)

	* [windows/graphics.c]
	Added Polyline and Polygon

Mon Dec 13 14:51:54 1993  Erik Bos (erik@trashcan.hacktic.nl)

	* [controls/listbox.c]
	ListBoxDirectory() modified to use dos_fs.c's functions to
	access files&|drives.

Sat Dec 04 17:04:23 1993  Erik Bos (erik@trashcan.hacktic.nl)

       	* [misc/dos_fs.c]
       	Added FindFile() to search a file in a dos/unix style path.
	
	* [misc/file.c]
	New Win31 functions: OpenFile, _lcreate, _llseek, GetTempDrive,
	GetTempFileName, GetWindowsDirectory, GetSystemDirectory,
	GetDriveType.			   

       	* [misc/int21.c]
       	Modified.

Wed Dec  1 16:20:45 1993  Miguel de Icaza  (miguel@roxanne.nuclecu.unam.mx)

        * [misc/profile.c]
        The Profile functions now return the correct values. They now
        implement all the features described in the SDK.

Tue Nov 30 13:55:27 1993  Bob Amstadt  (bob at amscons)

	* [loader/selector.c]
	Rewrote selector aliasing routines to use System V IPC
	routine to alias memory segments.

Nov 28, 93 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [controls/listbox.c]
	More consistency in functions using wIndexes

	* [controls/scroll.c]
	New function : ShowScrollBar().

	* [loader/cursor.c] ... New file
	Move cursor functions from [loader/resource.c].
	New function : ClipCursor().
	New function : GetClipCursor().
	New function : CreateCursor().
	SetCursor() now working using gloabal variable 'winHasCursor'.

	*[object/palette.c]
	New stub only : SelectPalette().
	New stub only : RealizePalette().

	*[win/event.c]
	New function : EVENT_enter_notify(),
		update 'winHasCursor' and send WM_SETCURSOR.

	*[win/defwnd.c]
	Add processing of WM_SETCURSOR message.

	*[win/win.c]
	New members in WND structure : hCursor, hWndVScroll & hWndHScroll. 
	CreateWindowEx() now create children for WM_HSCROLL & WM_VSCROLL.
	New function ClientToScreen().
	New function ScreenToClient().

Mon Nov 25 18:25:40 1993  Erik Bos (erik@trashcan.hacktic.nl)

       	* [files.h / regfunc.h / misc/dos.c]
       	Removed.

       	* [misc/dos_fs.c]
       	Added support for loading dosdrive cfg from wine.ini.

       	* [misc/int21.c]
       	Modified.


Wed Nov 24 11:37:33 1993  julliard@disuns2.epfl.ch (Alexandre Julliard)

	* [include/atom.h] [memory/atom.c]
	Implemented atoms.

	* [windows/class.c]
	Modified RegisterClass() to use atoms.
	Implemented CS_GLOBALCLASS style.

	* [windows/message.c]
	Implemented RegisterWindowMessage().

	* [loader/resource.c]
	Bug fix in LoadResource().

	* [windows/dialog.c]
	Modified CreateDialogParam() to use Find/LoadResource().
1994-01-04 20:14:34 +00:00

873 lines
16 KiB
C

/*
* DEC 93 Erik Bos (erik@trashcan.hacktic.nl)
*/
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#ifdef __NetBSD__
#include <errno.h>
#include <sys/ioctl.h>
#endif
#include "wine.h"
#include "windows.h"
#define DEBUG_COMM
#define MAX_PORTS 16
int commerror = 0, eventmask = 0;
struct DosDeviceStruct {
char *devicename; /* /dev/cua1 */
int fd;
int suspended;
};
struct DosDeviceStruct COM[MAX_PORTS];
struct DosDeviceStruct LPT[MAX_PORTS];
void Comm_DeInit(void);
void Comm_Init(void)
{
int x, serial = 0, parallel = 0;
char option[10], temp[256], *ptr;
struct stat st;
for (x=0; x!=MAX_PORTS; x++) {
strcpy(option,"COMx");
option[3] = '0' + x;
option[4] = '\0';
GetPrivateProfileString("serialports", option, "*", temp, sizeof(temp), WINE_INI);
if (!strcmp(temp, "*") || *temp == '\0')
COM[serial].devicename = NULL;
else {
stat(temp, &st);
if (!S_ISCHR(st.st_mode))
fprintf(stderr,"comm: can 't use `%s' as COM%d !\n", temp, x);
else
if ((ptr = malloc(strlen(temp)+1)) == NULL)
fprintf(stderr,"comm: can't malloc for device info!\n");
else {
COM[serial].fd = 0;
COM[serial].devicename = ptr;
strcpy(COM[serial++].devicename, temp);
}
}
strcpy(option, "LPTx");
option[3] = '0' + x;
option[4] = '\0';
GetPrivateProfileString("parallelports", option, "*", temp, sizeof(temp), WINE_INI);
if (!strcmp(temp, "*") || *temp == '\0')
LPT[parallel].devicename = NULL;
else {
stat(temp, &st);
if (!S_ISCHR(st.st_mode))
fprintf(stderr,"comm: can 't use `%s' as LPT%d !\n", temp, x);
else
if ((ptr = malloc(strlen(temp)+1)) == NULL)
fprintf(stderr,"comm: can't malloc for device info!\n");
else {
LPT[serial].fd = 0;
LPT[serial].devicename = ptr;
strcpy(LPT[serial++].devicename, temp);
}
}
}
atexit(Comm_DeInit);
#ifdef DEBUG_COMM
for (x=0; x!=MAX_PORTS; x++) {
if (COM[x].devicename)
fprintf(stderr, "comm: COM%d = %s\n", x, COM[x].devicename);
if (LPT[x].devicename)
fprintf(stderr, "comm: LPT%d = %s\n", x, LPT[x].devicename);
}
#endif
}
void Comm_DeInit(void)
{
int x;
for (x=0; x!=MAX_PORTS; x++) {
if (COM[x].devicename) {
if (COM[x].fd)
close(COM[x].fd);
fprintf(stderr, "comm: COM%d = %s\n",x,COM[x].devicename);
free(COM[x].devicename);
}
if (LPT[x].devicename) {
if (LPT[x].fd)
close(LPT[x].fd);
fprintf(stderr, "comm: LPT%d = %s\n",x,LPT[x].devicename);
free(LPT[x].devicename);
}
}
}
struct DosDeviceStruct *GetDeviceStruct(int fd)
{
int x;
for (x=0; x!=MAX_PORTS; x++) {
if (COM[x].fd == fd)
return &COM[x];
if (LPT[x].fd == fd)
return &LPT[x];
}
return NULL;
}
int ValidCOMPort(int x)
{
return(x < MAX_PORTS ? (int) COM[x].devicename : 0);
}
int ValidLPTPort(int x)
{
return(x < MAX_PORTS ? (int) LPT[x].devicename : 0);
}
int WinError(void)
{
perror("comm");
switch (errno) {
default:
return CE_IOE;
}
}
int BuildCommDCB(LPSTR device, DCB FAR *lpdcb)
{
/* "COM1:9600,n,8,1" */
/* 012345 */
int port;
char *ptr, *ptr2, temp[256],temp2[10];
#ifdef DEBUG_COMM
fprintf(stderr,"BuildCommDCB: (%s), ptr %d\n", device, lpdcb);
#endif
commerror = 0;
if (!strncmp(device,"COM",3)) {
port = device[3] - '0';
if (!ValidCOMPort(port)) {
commerror = IE_BADID;
return -1;
}
if (!COM[port].fd) {
commerror = IE_NOPEN;
return -1;
}
lpdcb->Id = COM[port].fd;
if (!*(device+4))
return 0;
if (*(device+4) != ':')
return -1;
strcpy(temp,device+5);
ptr = strtok(temp, ",");
fprintf(stderr,"BuildCommDCB: baudrate (%s)\n", ptr);
lpdcb->BaudRate = atoi(ptr);
ptr = strtok(NULL, ",");
if (islower(*ptr))
*ptr = toupper(*ptr);
fprintf(stderr,"BuildCommDCB: parity (%c)\n", *ptr);
switch (*ptr) {
case 'N':
lpdcb->Parity = NOPARITY;
lpdcb->fParity = 0;
break;
lpdcb->fParity = 1;
case 'E':
lpdcb->Parity = EVENPARITY;
break;
case 'M':
lpdcb->Parity = MARKPARITY;
break;
case 'O':
lpdcb->Parity = ODDPARITY;
break;
default:
fprintf(stderr,"comm: unknown parity `%c'!\n", *ptr);
return -1;
}
ptr = strtok(NULL, ",");
fprintf(stderr, "BuildCommDCB: charsize (%c)\n", *ptr);
lpdcb->ByteSize = *ptr - '0';
ptr = strtok(NULL, ",");
fprintf(stderr, "BuildCommDCB: stopbits (%c)\n", *ptr);
switch (*ptr) {
case '1':
lpdcb->StopBits = ONESTOPBIT;
break;
case '2':
lpdcb->StopBits = TWOSTOPBITS;
break;
default:
fprintf(stderr,"comm: unknown # of stopbits `%c'!\n", *ptr);
return -1;
}
}
return 0;
}
int OpenComm(LPSTR device, UINT cbInQueue, UINT cbOutQueue)
{
int port, fd;
#ifdef DEBUG_COMM
fprintf(stderr,"OpenComm: %s, %d, %d\n", device, cbInQueue, cbOutQueue);
#endif
commerror = 0;
if (!strncmp(device,"COM",3)) {
port = device[3] - '0';
if (!ValidCOMPort(port)) {
commerror = IE_BADID;
return -1;
}
if (COM[port].fd) {
commerror = IE_OPEN;
return -1;
}
fd = open(COM[port].devicename, O_RDWR | O_NONBLOCK, 0);
if (fd == -1) {
commerror = WinError();
return -1;
} else {
COM[port].fd = fd;
return fd;
}
}
else
if (!strncmp(device,"LPT",3)) {
port = device[3] - '0';
if (!ValidLPTPort(port)) {
commerror = IE_BADID;
return -1;
}
if (LPT[port].fd) {
commerror = IE_OPEN;
return -1;
}
fd = open(LPT[port].devicename, O_RDWR | O_NONBLOCK, 0);
if (fd == -1) {
commerror = WinError();
return -1;
} else {
LPT[port].fd = fd;
return fd;
}
}
return 0;
}
int CloseComm(int fd)
{
int status;
#ifdef DEBUG_COMM
fprintf(stderr,"CloseComm: fd %d\n", fd);
#endif
if (close(fd) == -1) {
commerror = WinError();
return -1;
} else {
commerror = 0;
return 0;
}
}
int SetCommBreak(int fd)
{
struct DosDeviceStruct *ptr;
#ifdef DEBUG_COMM
fprintf(stderr,"SetCommBreak: fd: %d\n", fd);
#endif
if ((ptr = GetDeviceStruct(fd)) == NULL) {
commerror = IE_BADID;
return -1;
}
ptr->suspended = 1;
commerror = 0;
return 0;
}
int ClearCommBreak(int fd)
{
struct DosDeviceStruct *ptr;
#ifdef DEBUG_COMM
fprintf(stderr,"ClearCommBreak: fd: %d\n", fd);
#endif
if ((ptr = GetDeviceStruct(fd)) == NULL) {
commerror = IE_BADID;
return -1;
}
ptr->suspended = 0;
commerror = 0;
return 0;
}
LONG EscapeCommFunction(int fd, int nFunction)
{
int max;
struct termios port;
#ifdef DEBUG_COMM
fprintf(stderr,"EscapeCommFunction fd: %d, function: %d\n", fd, nFunction);
#endif
if (tcgetattr(fd, &port) == -1) {
commerror = WinError();
return -1;
}
switch (nFunction) {
case RESETDEV:
break;
case GETMAXCOM:
for (max = 0;COM[max].devicename;max++)
;
return max;
break;
case GETMAXLPT:
for (max = 0;LPT[max].devicename;max++)
;
return 0x80 + max;
break;
case CLRDTR:
port.c_cflag &= TIOCM_DTR;
break;
case CLRRTS:
port.c_cflag &= TIOCM_RTS;
break;
case SETDTR:
port.c_cflag |= CRTSCTS;
break;
case SETRTS:
port.c_cflag |= CRTSCTS;
break;
case SETXOFF:
port.c_iflag |= IXOFF;
break;
case SETXON:
port.c_iflag |= IXON;
break;
default:
fprintf(stderr,"EscapeCommFunction fd: %d, unknown function: %d\n", fd, nFunction);
break;
}
if (tcsetattr(fd, TCSADRAIN, &port) == -1) {
commerror = WinError();
return -1;
} else {
commerror = 0;
return 0;
}
}
int FlushComm(int fd, int fnQueue)
{
int queue;
#ifdef DEBUG_COMM
fprintf(stderr,"FlushComm fd: %d, queue: %d\n", fd, fnQueue);
#endif
switch (fnQueue) {
case 0:
queue = TCOFLUSH;
break;
case 1:
queue = TCIFLUSH;
break;
default:
fprintf(stderr,"FlushComm fd: %d, UNKNOWN queue: %d\n", fd, fnQueue);
return -1;
}
if (tcflush(fd, fnQueue)) {
commerror = WinError();
return -1;
} else {
commerror = 0;
return 0;
}
}
int GetCommError(int fd, COMSTAT FAR *lpStat)
{
#ifdef DEBUG_COMM
fprintf(stderr,"GetCommError: fd %d (current error %d)\n", fd, commerror);
#endif
return(commerror);
}
UINT FAR* SetCommEventMask(int fd, UINT fuEvtMask)
{
#ifdef DEBUG_COMM
fprintf(stderr,"SetCommEventMask: fd %d, mask %d\n", fd, fuEvtMask);
#endif
eventmask |= fuEvtMask;
return (UINT *)&eventmask;
}
UINT GetCommEventMask(int fd, int fnEvtClear)
{
#ifdef DEBUG_COMM
fprintf(stderr,"GetCommEventMask: fd %d, mask %d\n", fd, fnEvtClear);
#endif
eventmask &= ~fnEvtClear;
return eventmask;
}
int SetCommState(DCB FAR *lpdcb)
{
struct termios port;
#ifdef DEBUG_COMM
fprintf(stderr,"SetCommState: fd %d, ptr %d\n", lpdcb->Id, lpdcb);
#endif
if (tcgetattr(lpdcb->Id, &port) == -1) {
commerror = WinError();
return -1;
}
cfmakeraw(&port);
port.c_cc[VMIN] = 0;
port.c_cc[VTIME] = 0;
fprintf(stderr,"SetCommState: baudrate %d\n",lpdcb->BaudRate);
#ifdef CBAUD
port.c_cflag &= ~CBAUD;
switch (lpdcb->BaudRate) {
case 110:
case CBR_110:
port.c_cflag |= B110;
break;
case 300:
case CBR_300:
port.c_cflag |= B300;
break;
case 600:
case CBR_600:
port.c_cflag |= B600;
break;
case 1200:
case CBR_1200:
port.c_cflag |= B1200;
break;
case 2400:
case CBR_2400:
port.c_cflag |= B2400;
break;
case 4800:
case CBR_4800:
port.c_cflag |= B4800;
break;
case 9600:
case CBR_9600:
port.c_cflag |= B9600;
break;
case 19200:
case CBR_19200:
port.c_cflag |= B19200;
break;
case 38400:
case CBR_38400:
port.c_cflag |= B38400;
break;
default:
commerror = IE_BAUDRATE;
return -1;
}
#else
switch (lpdcb->BaudRate) {
case 110:
case CBR_110:
port.c_ospeed = B110;
break;
case 300:
case CBR_300:
port.c_ospeed = B300;
break;
case 600:
case CBR_600:
port.c_ospeed = B600;
break;
case 1200:
case CBR_1200:
port.c_ospeed = B1200;
break;
case 2400:
case CBR_2400:
port.c_ospeed = B2400;
break;
case 4800:
case CBR_4800:
port.c_ospeed = B4800;
break;
case 9600:
case CBR_9600:
port.c_ospeed = B9600;
break;
case 19200:
case CBR_19200:
port.c_ospeed = B19200;
break;
case 38400:
case CBR_38400:
port.c_ospeed = B38400;
break;
default:
commerror = IE_BAUDRATE;
return -1;
}
port.c_ispeed = port.c_ospeed;
#endif
fprintf(stderr,"SetCommState: bytesize %d\n",lpdcb->ByteSize);
port.c_cflag &= ~CSIZE;
switch (lpdcb->ByteSize) {
case 5:
port.c_cflag |= CS5;
break;
case 6:
port.c_cflag |= CS6;
break;
case 7:
port.c_cflag |= CS7;
break;
case 8:
port.c_cflag |= CS8;
break;
default:
commerror = IE_BYTESIZE;
return -1;
}
fprintf(stderr,"SetCommState: parity %d\n",lpdcb->Parity);
port.c_cflag &= ~(PARENB | PARODD);
if (lpdcb->fParity)
switch (lpdcb->Parity) {
case NOPARITY:
port.c_iflag &= ~INPCK;
break;
case ODDPARITY:
port.c_cflag |= (PARENB | PARODD);
port.c_iflag |= INPCK;
break;
case EVENPARITY:
port.c_cflag |= PARENB;
port.c_iflag |= INPCK;
break;
default:
commerror = IE_BYTESIZE;
return -1;
}
fprintf(stderr,"SetCommState: stopbits %d\n",lpdcb->StopBits);
switch (lpdcb->StopBits) {
case ONESTOPBIT:
port.c_cflag &= ~CSTOPB;
break;
case TWOSTOPBITS:
port.c_cflag |= CSTOPB;
break;
default:
commerror = IE_BYTESIZE;
return -1;
}
if (lpdcb->fDtrflow || lpdcb->fRtsflow || lpdcb->fOutxCtsFlow)
port.c_cflag |= CRTSCTS;
if (lpdcb->fDtrDisable)
port.c_cflag &= ~CRTSCTS;
if (lpdcb->fInX)
port.c_iflag |= IXON;
if (lpdcb->fOutX)
port.c_iflag |= IXOFF;
if (tcsetattr(lpdcb->Id, TCSADRAIN, &port) == -1) {
commerror = WinError();
return -1;
} else {
commerror = 0;
return 0;
}
}
int GetCommState(int fd, DCB FAR *lpdcb)
{
struct termios port;
#ifdef DEBUG_COMM
fprintf(stderr,"GetCommState: fd %d, ptr %d\n", fd, lpdcb);
#endif
if (tcgetattr(fd, &port) == -1) {
commerror = WinError();
return -1;
}
lpdcb->Id = fd;
#ifdef CBAUD
switch (port.c_cflag & CBAUD) {
#else
switch (port.c_ospeed) {
#endif
case B110:
lpdcb->BaudRate = 110;
break;
case B300:
lpdcb->BaudRate = 300;
break;
case B600:
lpdcb->BaudRate = 600;
break;
case B1200:
lpdcb->BaudRate = 1200;
break;
case B2400:
lpdcb->BaudRate = 2400;
break;
case B4800:
lpdcb->BaudRate = 4800;
break;
case B9600:
lpdcb->BaudRate = 9600;
break;
case B19200:
lpdcb->BaudRate = 19200;
break;
case B38400:
lpdcb->BaudRate = 38400;
break;
}
switch (port.c_cflag & CSIZE) {
case CS5:
lpdcb->ByteSize = 5;
break;
case CS6:
lpdcb->ByteSize = 6;
break;
case CS7:
lpdcb->ByteSize = 7;
break;
case CS8:
lpdcb->ByteSize = 8;
break;
}
switch (port.c_cflag & ~(PARENB | PARODD)) {
case 0:
lpdcb->fParity = NOPARITY;
break;
case PARENB:
lpdcb->fParity = EVENPARITY;
break;
case (PARENB | PARODD):
lpdcb->fParity = ODDPARITY;
break;
}
if (port.c_cflag & CSTOPB)
lpdcb->StopBits = TWOSTOPBITS;
else
lpdcb->StopBits = ONESTOPBIT;
lpdcb->RlsTimeout = 50;
lpdcb->CtsTimeout = 50;
lpdcb->DsrTimeout = 50;
lpdcb->fNull = 0;
lpdcb->fChEvt = 0;
lpdcb->fBinary = 1;
lpdcb->fDtrDisable = 0;
if (port.c_cflag & CRTSCTS) {
lpdcb->fDtrflow = 1;
lpdcb->fRtsflow = 1;
lpdcb->fOutxCtsFlow = 1;
lpdcb->fOutxDsrFlow = 1;
} else
lpdcb->fDtrDisable = 1;
if (port.c_iflag & IXON)
lpdcb->fInX = 1;
else
lpdcb->fInX = 0;
if (port.c_iflag & IXOFF)
lpdcb->fOutX = 1;
else
lpdcb->fOutX = 0;
/*
lpdcb->XonChar =
lpdcb->XoffChar =
*/
lpdcb->XonLim = 10;
lpdcb->XoffLim = 10;
commerror = 0;
return 0;
}
int TransmitCommChar(int fd, char chTransmit)
{
struct DosDeviceStruct *ptr;
#ifdef DEBUG_COMM
fprintf(stderr,"TransmitCommChar: fd %d, data %d \n", fd, chTransmit);
#endif
if ((ptr = GetDeviceStruct(fd)) == NULL) {
commerror = IE_BADID;
return -1;
}
if (ptr->suspended) {
commerror = IE_HARDWARE;
return -1;
}
if (write(fd, (void *) &chTransmit, 1) == -1) {
commerror = WinError();
return -1;
} else {
commerror = 0;
return 0;
}
}
int UngetCommChar(int fd, char chUnget)
{
struct DosDeviceStruct *ptr;
#ifdef DEBUG_COMM
fprintf(stderr,"UngetCommChar: fd %d (char %d)\n", fd, chUnget);
#endif
fprintf(stderr,"NOT implemented!\n");
if ((ptr = GetDeviceStruct(fd)) == NULL) {
commerror = IE_BADID;
return -1;
}
if (ptr->suspended) {
commerror = IE_HARDWARE;
return -1;
}
commerror = 0;
return 0;
}
int ReadComm(int fd, LPSTR lpvBuf, int cbRead)
{
struct DosDeviceStruct *ptr;
#ifdef DEBUG_COMM
fprintf(stderr,"ReadComm: fd %d, ptr %d, length %d\n", fd, lpvBuf, cbRead);
#endif
if ((ptr = GetDeviceStruct(fd)) == NULL) {
commerror = IE_BADID;
return -1;
}
if (ptr->suspended) {
commerror = IE_HARDWARE;
return -1;
}
if (read(fd, (void *) lpvBuf, cbRead) == -1) {
commerror = WinError();
return -1;
} else {
commerror = 0;
return 0;
}
}
int WriteComm(int fd, LPSTR lpvBuf, int cbWrite)
{
int x;
struct DosDeviceStruct *ptr;
#ifdef DEBUG_COMM
fprintf(stderr,"WriteComm: fd %d, ptr %d, length %d\n", fd, lpvBuf, cbWrite);
#endif
if ((ptr = GetDeviceStruct(fd)) == NULL) {
commerror = IE_BADID;
return -1;
}
if (ptr->suspended) {
commerror = IE_HARDWARE;
return -1;
}
for (x=0; x != cbWrite ; x++)
fprintf(stderr,"%c", *(lpvBuf + x) );
if (write(fd, (void *) lpvBuf, cbWrite) == -1) {
commerror = WinError();
return -1;
} else {
commerror = 0;
return 0;
}
}