Tue Mar 1 11:30:21 1994 Bob Amstadt (bob@pooh) * [Configure] [*/Imakefile] Created configure script to handle different types of Wine builds. * [Configure] [tools/build.c] [if1632/Imakefile] [Wine.tmpl] Added ability to compile Wine on systems with 14-char filename limit. * [if1632/relay.c] [include/options.h] [misc/main.c] Added -relaydbg option to command line if DEBUG_RELAY is defined. * [loader/selector.c] Fixed bug in GetEntryDLLName() that caused Wine to seg fault. * [memory/heap.c] Fixed LocalInit() to work correctly. * [misc/user.c] Added code to call loaded DLLs' initialization routines. Tue Mar 1 01:01:17 MET 1994 julliard@di.epfl.ch (Alexandre Julliard) * [windows/dce.c] Added clipping of child windows by their parent's client area. * [windows/nonclient.c] Bug fix in NC_DoNCPaint(). * [windows/painting.c] Bug fix in RedrawWindow(). Feb 27, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte) * [mem/atom.c] Bug fix again in ATOM_DeleteAtom() : change LocalFree() by USER_HEAP_FREE(). (Previous patch done Feb 13th had been lost) * [controls/scroll.c] Move bitmaps loading in AllocScrollBar() instead of in WM_CREATE. * [windows/class.c] (sorry Alex ...) There was no bug there "in RegisterClass() : WNDCLASS->lpszClassName was reset to NULL." ^^^^^ * [misc/clipboard.c] --- New File --- New function EnumClipboardFormats(). New function OpenClipboard(). New function CloseClipboard(). New function EmptyClipboard(). New function GetClipboardOwner(). New function GetClipboardViewer(). New function CountClipboardFormats(). New function IsClipboardFormatAvailable(). New function OpenClipboard(). New function GetClipboardData(). New function SetClipboardViewer(). New function EnumClipboardFormats(). New function RegisterClipboardFormat(). New function ChangeClipboardChain(). New function SetClipboardData(). New function GetOpenClipboardWindow(). New function GetPriorityClipboardFormat(). New function GetClipboardFormatName(). Tue Mar 1 20:15:45 1994 Erik Bos <erik@trashcan.hacktic.nl> * [misc/comm.c] bugfix in OpenComm(). Tue Feb 22 18:04:02 1994 Jeffrey Hsu <hsu@freefall.cdrom.com> * [include/winsock.h] The sockproto struct is already defined in <sys/socket.h> * [misc/winsock.c] Need to include <netinet/in.h> for struct in-addr. Use sys_errlist[] instead of strerror[]. *[toolkit/heap.c] ANSI C specifies that the malloc functions are defined in stdlib.h, so we don't need to include malloc.h. *[loader/ldtlib.c] Print informative error message about probable cause of i386_set_ldt() failure and then exit. *[Imakefile] For systems that don't use gmake by default, set the MAKE variable to gmake and propagate it on recursive makes. Take out -li386 for FreeBSD systems and define __FreeBSD__ so Wine can be built with the FreeBSD 1.0.2 compiler. Tue Feb 22 02:52:19 EST 1994 jrichard@cs.uml.edu (John Richardson) * [objects/bitblt.c] Added in three functions to do stretching and compression for WHITEONBLACK, BLACKONWHITE, and color copies. Tue Feb 22 15:01:31 EST 1994 jrichard@cs.uml.edu (John Richardson) * [windows/graphics.c] Added FloodFill and FloodFill_rec. FloodFill_rec is pretty inefficent, but should suffice for now. * [include/windows.h] Changed the x,y paramaters for the FloodFill prototype from ints to shorts Tue Feb 22 00:58:28 MET 1994 julliard@di.epfl.ch (Alexandre Julliard) * [windows/widgets.c] Added desktop window class. * [windows/painting.c] Bug fix in RedrawWindow(). Implemented ExcludeUpdateRgn(). * [windows/win.c] [windows/winpos.c] Implemented desktop window. * [controls/desktop.c] Preliminary desktop window procedure. Feb 20, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte) * [controls/menu.c] New function LoadMenuIndirect(). New function GetMenuCheckMarkDimensions(). * [if1632/user.spec] Entry for DefDlgProc(). * [windows/class.c] Fix bug in RegisterClass() : WNDCLASS->lpszMenuName was reset to NULL. * [windows/win.c] In CreateWindowEx(), if hMenu == 0 then use wndclass->lpszMenuName to load Menu from resource; Mon Feb 21 22:38:28 1994 Erik Bos (erik@trashcan.hacktic.nl) * [loader/library.c] [loader/wine.c] Fixed runing DLL's as main executable problem. * [misc/dos_fs.c] Added wildcard support in DOS_readdir(). * [misc/winsocket.c] Added proper error handling of BSD winsocket functions. * [miscemu/int21.c] KERNEL_DOS3Call renamed to DOS3Call and modified to use do_int21(). * [main/main.c] Added functions for GetVersion, GetWinFlags and GetTimerResolution for libwine.a, SystemParametersInfo() partly implemented. Tue Feb 22 19:00:02 1994 Miguel de Icaza (miguel@xochitl.nuclecu.unam.mx) * [toolkit/winmain.c] Added _WinMain function. Setups the library (calls USER_InitApp). * [toolkit/sup.c] Added load_mz_header, load_ne_header, load_type_info and load_name_info functions. * [toolkit/heap.c] Code cleanup. * [misc/user.c] Moved from loader/misc.c. I hope to put back all the loader functions in the ~loader subdirectory in the future. CUrrently is needed since it has USER_InitApp. * [misc/resource.c] Since WineLib will probably need DLLs (currently it needs Sysres.dll). WineLib will be using much code of the loader again. So I removed some ifdefs that were used by WineLib. Added load_typeinfo and load_nameinfo (and the corresponding functions in [toolkit/sup.c] Added integer convertion functions in the needed places. Added very ugly patch (includes wine.c). In the next release I plan to move back all the loader routines to ~/loader. In the meantime I needed this patch. It doesn't affect any of the emulator code (its ifdefed for WineLib). * [misc/main.c] Cleaned up call to WinMain (now uses [toolkit/winmain.c] Ifdefed argument number checking when compiling the library. * [loader/wine.c] Modified to use load_(mz|ne)_header instead of doing a direct read. When compiling the emulator it still uses the direct read for performance. * [include/wine.h] Prototypes for loading routines. * [include/class.h] Added WINE_PACKED macro instead of __attribute__ ((packed)) * [include/arch.h] Macros for converting integers (Little endian to big-endian). Needed in the Sun to allow loading of DLL files. Mon Feb 14 23:48:09 MET 1994 julliard@di.epfl.ch (Alexandre Julliard) * [windows/clipping.c] Moved everything into windows/painting.c and removed this file. * [windows/message.c] Removed calls to memmove() in MSG_RemoveMsg(). * [windows/nonclient.c] Added WM_GETMINMAXINFO support for window resizing. * [windows/painting.c] Implemented RedrawWindow(). * [windows/scroll.c] Bug fix in ScrollWindowEx(). * [windows/win.c] Moved UpdateWindow() to windows/painting.c. Fri Feb 11 12:41:28 1994 Erik Bos (erik@trashcan.hacktic.nl) * [loader/wine.c] [misc/dos_fs.c] getenv() eq NULL bugfixes. * [misc/comm.c] cfmakeraw changed for SunOS. Feb 13, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte) * [mem/atom.c] Bug fix in ATOM_DeleteAtom() : change LocalFree() by USER_HEAP_FREE(). * [misc/message.c] New function FatalAppExit(). * [objects/font.c] New empty stub SetMapperFlags(). * [controls/menu.c] Better CheckMark & other bitmaps placement. * [windows/graphics.c] New function RoundRect() : calc.exe now working... Tue Feb 15 14:29:37 1994 John Richardson * [objects/bitblt.c] Fixed StretchBlt so it works quicker and faster. It still doesn't use the StretchMode bits for bitmap compression, but that will come soon. Mon Feb 14 13:21:04 1994 Miguel de Icaza (miguel@roxanne.nuclecu.unam.mx) * [include/windows.h,dialog.h,gdi.h] Changed __atribute__ ((packed)) for WINE_PACKED. When compiling the library this is defined as nothing. This gets rid with all the problems compiling under SunOS. Also * [windows/utility.c] Added DebugPrintString. * [toolkit/sup.c] Added hSysRes = 1 definition to resolve externals. Added CallLineDDAProc function (toolkit version). Added toy, and hi ineficient memmove until code in message.c get rewritten. * [objects/gdiobj.c] Ifdefed linux/emulator-dependent code to allow compilation of WineLib. * [misc/winsocket.c] Added ifdef to allow compilation under SunOS. * [misc/resource.c] When compiling the library, the resource file is expected to be in a file called $argv[0].Res. Also the information of the resource is expected to be at offset 0 of the .Res file. * [misc/main.c] Call WinMain with arguments if compiling WineLib. Call shutdown functions (Comm_DeInit, DOS_DeInitFS). Call sync_profiles to preserve changes to .INI files. * [misc/comm.c,dos_fs.c] removed call to atexit(Comm_DeInit) removed call to atexit(DOS_DeInitFS) Shutdown functions are now called from the return of WinMain * removed memorylib subdirectory * moved memory/atom.c to misc/atom.c moved memorylib/heap.c to toolkit/heap.c * [loader/wine.c] Moved DebugPrintString to windows/utility.c * [include/winsock.h] Define SO_DONTLINGER only if it has not been previously defined. * [include/windows.h] added definition for DLGPROC. added definition for LMEM_WINE_ALIGN and other LMEM_* constants. When compiling WineLib WNDPROC is defined with all the parameters to avoid compilation problems. * [include/user.h] When compiling WineLib USER_HEAP_(ALLOC|REALLOC|ADDR|FREE) the calls are translated to the library allocation routines. * [include/gdi.h,user.h] When compiling WineLib GDI_HEAP_(ALLOC|ADDR|FREE) the calls are translated to the library allocation routines. * [include/atom.h] Defined LocalAlign. When compiling the emulator it's translated as a call to LocalAlloc (the original code), when compiling WineLib as a call to LocalAlloc with a WINE-flag called LMEM_WINE_ALIGN (atom.c needs aligned data on a 4 byte boundary). * [misc/file.c] Renamed KERNEL_* functions and fixed prototypes. * [if1632/kernel.spec] Renamed KERNEL_* functions in order to be used by applications using Wine as a library (OpeFile, _lclose, _lread, _lcreate, _llseek, _lopen, _lwrite). * [Makefile] Create library instead of executable when building target libwine.a Tue Feb 8 13:52:11 1994 Miguel de Icaza (miguel@roxanne) * [Makefiles] Use $(CC) instead of cc. Added libwine target. * [include/prototypes] #ifdefed section for WineLib * moved loader/cursor.c to misc/cursor.c moved loader/resource.c to misc/resource.c moved misc/emulate.c to miscemu/emulate.c moved misc/int1a.c to miscemu/int1a.c moved misc/int21.c to miscemu/int21.c moved misc/kernel.c to miscemu/kernel.c moved misc/user.c to miscemu/user.c * [memorylib/heap.c] Heap management for WineLib * [misc/comm.c] Modified to allow compilation under SunOS (#include errno, SunOS doesn't have atexit ()). * [misc/dos_fs.c] Modified to allow compilation under SunOS (#include vfs.h) * [misc/file.c] Modified to allow compilation under SunOS (OPEN_MAX constant, #include unistd.h) * [objects/palette.c] Modified to allow compilation under SunOS (#include limits) * [toolkit/sup.c] WineLib version of CallWindowProc. * [windows/event.c] Typedef XPointer under X11R4 (OpenWindows). * [windows/win.c] When compiling WineLib, use direct callbacks instead of the windows supplied callbacks. Mon Feb 7 22:37:34 MET 1994 julliard@di.epfl.ch (Alexandre Julliard) * [loader/cursor.c] New function CURSOR_SetWinCursor(), for internal use, to set the cursor of a specific window more reliably than with SetCursor(). * [windows/nonclient.c] Better window management. Moving and resizing from the system menu should work now. Added scroll-bar mouse tracking. * [windows/win.c] Moved scroll-bar creation and destruction to defwnd.c. Feb 5, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte) * [windows/nonclient.c] Call to StdDrawMenuBar() during NC's drawing. New NC_TrackMouseMenuBar() function which call MenuButtonDown(), MenuButtonUp() & MenuMouseMove(). * [controls/menu.c] New ChangeMenu() function. Remove permanently old Xt menu code. Make common functions MenuButtonDown(), MenuButtonUp() & MenuMouseMove() for both popups & menubar. * [controls/combo.c] Paint OBM_COMBO directly in combo client. * [controls/listbox.c] Fix bug in multicolumns calculations. * [controls/Makefile] Remove rules for old file 'caption.c'. * [misc/kernel.c] Remove empty stub GetModuleFileName(). * [loader/library.c] New GetModuleHandle() function. New GetModuleUsage() function. New GetModuleFileName() function. * [loader/resource.c] Try to find the bug a missing menu loading ... Not found yet ! * [windows/win.c] Remove old menubar creation. Thu Feb 3 22:30:11 1994 Erik Bos (erik@trashcan.hacktic.nl) * [misc/winsocket.c] More functions added. * [if1632/winsock.spec] [misc/winsocket.c] Added John Brezak's winsock.dll stuff.
905 lines
16 KiB
C
905 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 <errno.h>
|
|
#include <sys/stat.h>
|
|
#if defined(__NetBSD__) || defined(__FreeBSD__)
|
|
#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;
|
|
int unget;
|
|
int unget_byte;
|
|
};
|
|
|
|
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 ((COM[serial].devicename = malloc(strlen(temp)+1)) == NULL)
|
|
fprintf(stderr,"comm: can't malloc for device info!\n");
|
|
else {
|
|
COM[serial].fd = 0;
|
|
strcpy(COM[serial].devicename, temp);
|
|
serial++;
|
|
}
|
|
}
|
|
|
|
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 ((LPT[parallel].devicename = malloc(strlen(temp)+1)) == NULL)
|
|
fprintf(stderr,"comm: can't malloc for device info!\n");
|
|
else {
|
|
LPT[parallel].fd = 0;
|
|
strcpy(LPT[parallel].devicename, temp);
|
|
parallel++;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
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);
|
|
free(COM[x].devicename);
|
|
}
|
|
if (LPT[x].devicename) {
|
|
if (LPT[x].fd)
|
|
close(LPT[x].fd);
|
|
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 (port-- == 0) {
|
|
fprintf(stderr, "comm: BUG ! COM0 can't exists!.\n");
|
|
commerror = IE_BADID;
|
|
}
|
|
|
|
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 (port-- == 0) {
|
|
fprintf(stderr, "comm: BUG ! COM0 doesn't exists!.\n");
|
|
commerror = IE_BADID;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
port.c_cc[VMIN] = 0;
|
|
port.c_cc[VTIME] = 1;
|
|
|
|
port.c_iflag &= ~(ISTRIP|BRKINT|IGNCR|ICRNL|INLCR|IMAXBEL);
|
|
port.c_iflag |= (IGNBRK);
|
|
|
|
port.c_oflag &= ~(OPOST);
|
|
|
|
port.c_cflag &= ~(HUPCL);
|
|
port.c_cflag |= CLOCAL | CREAD;
|
|
|
|
port.c_lflag &= ~(ICANON|ECHO|ISIG);
|
|
port.c_lflag |= NOFLSH;
|
|
|
|
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
|
|
|
|
if ((ptr = GetDeviceStruct(fd)) == NULL) {
|
|
commerror = IE_BADID;
|
|
return -1;
|
|
}
|
|
|
|
if (ptr->suspended) {
|
|
commerror = IE_HARDWARE;
|
|
return -1;
|
|
}
|
|
|
|
ptr->unget = 1;
|
|
ptr->unget_byte = chUnget;
|
|
|
|
commerror = 0;
|
|
return 0;
|
|
}
|
|
|
|
int ReadComm(int fd, LPSTR lpvBuf, int cbRead)
|
|
{
|
|
int status, length;
|
|
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 (ptr->unget) {
|
|
*lpvBuf = ptr->unget_byte;
|
|
lpvBuf++;
|
|
ptr->unget = 0;
|
|
|
|
length = 1;
|
|
} else
|
|
length = 0;
|
|
|
|
status = read(fd, (void *) lpvBuf, cbRead);
|
|
|
|
if (status == -1) {
|
|
commerror = WinError();
|
|
return -1 - length;
|
|
} else {
|
|
commerror = 0;
|
|
return length + status;
|
|
}
|
|
}
|
|
|
|
int WriteComm(int fd, LPSTR lpvBuf, int cbWrite)
|
|
{
|
|
int x, length;
|
|
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;
|
|
}
|
|
|
|
#ifdef DEBUG_COMM
|
|
for (x=0; x != cbWrite ; x++)
|
|
fprintf(stderr,"%c", *(lpvBuf + x) );
|
|
#endif
|
|
|
|
length = write(fd, (void *) lpvBuf, cbWrite);
|
|
|
|
if (length == -1) {
|
|
commerror = WinError();
|
|
return -1;
|
|
} else {
|
|
commerror = 0;
|
|
return length;
|
|
}
|
|
}
|