diff --git a/harbour/ChangeLog b/harbour/ChangeLog index dc1d94d6cc..5988924c93 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,71 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-06-25 16:48 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbver.h + * removed unnecessary EOL inside comment + + * harbour/contrib/hbodbc/odbc.c + ! use valid integer type instead of explicit casting in function call. + Such casting is vary dangerous and may cause unpredictible results + when integer value has different binary size + + * harbour/contrib/hbtpathy/Makefile + * harbour/contrib/hbtpathy/common.mak + * harbour/contrib/hbtpathy/telepath.ch + * harbour/contrib/hbtpathy/tplinux.c + * harbour/contrib/hbtpathy/tpwin32.c + * harbour/contrib/hbtpathy/tpos2.c + * harbour/contrib/hbtpathy/telepath.prg + * harbour/contrib/hbtpathy/readme.txt + * harbour/contrib/hbtpathy/tests/testtp.prg + * converted EOL style to native + * set valid SVN attributes + + * harbour/contrib/hbapollo/Makefile + * disabled non W32 builds, SDE exists only for MS-Windows + + * harbour/contrib/hbziparch/Makefile + ! fixed C flag setting for Linux builds + + * harbour/source/pp/ppcore.c + * formatting + + * harbour/source/rtl/valtoexp.prg + ! fixed empty date conversion + + * harbour/hbgtmk.sh + * harbour/make_xmingwce.sh + * harbour/make_deb.sh + * harbour/make_rpmw32.sh + * harbour/make_gcc.sh + * harbour/make_rpm.sh + * harbour/make_xmingw.sh + * harbour/make_tgz.sh + * harbour/make_rpmce.sh + * harbour/contrib/hbmzip/make_gcc.sh + * harbour/contrib/hbsqlit3/make_gcc.sh + * harbour/contrib/make_gcc_all.sh + * harbour/contrib/hbziparch/make_gcc.sh + * harbour/contrib/hbnf/make_gcc.sh + * harbour/contrib/hbhpdf/tests/files/cp932.txt + * harbour/contrib/hbhpdf/make_gcc.sh + * harbour/contrib/rddado/make_gcc.sh + * harbour/contrib/gtwvg/make_gcc.sh + * harbour/contrib/hbpgsql/make_gcc.sh + * harbour/contrib/rddads/make_gcc.sh + * harbour/contrib/hbclipsm/make_gcc.sh + * harbour/contrib/mtpl_gcc.sh + * harbour/contrib/hbfimage/make_gcc.sh + * harbour/contrib/hbgd/tests/bld.sh + * harbour/contrib/hbgd/make_gcc.sh + * harbour/contrib/hbmisc/make_gcc.sh + * harbour/contrib/hbtip/make_gcc.sh + * harbour/contrib/hbbmcdx/make_gcc.sh + * harbour/contrib/hbvpdf/make_gcc.sh + * harbour/contrib/hbbtree/make_gcc.sh + * set valid SVN EOL attribute + 2008-06-25 11:49 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * source/rtl/gtwvt/gtwvt.c * Slightly changed the way CLOSE button works. diff --git a/harbour/contrib/hbapollo/Makefile b/harbour/contrib/hbapollo/Makefile index dd8fc8e8fe..1cb3b5855c 100644 --- a/harbour/contrib/hbapollo/Makefile +++ b/harbour/contrib/hbapollo/Makefile @@ -2,6 +2,8 @@ # $Id$ # +ifeq ($(HB_ARCHITECTURE),w32) + ROOT = ../../ C_SOURCES=\ @@ -16,3 +18,5 @@ PRG_HEADERS=\ LIBNAME=hbapollo include $(TOP)$(ROOT)config/lib.cf + +endif diff --git a/harbour/contrib/hbhpdf/make_gcc.sh b/harbour/contrib/hbhpdf/make_gcc.sh index bab38b2e35..3372c53dbf 100644 --- a/harbour/contrib/hbhpdf/make_gcc.sh +++ b/harbour/contrib/hbhpdf/make_gcc.sh @@ -1,25 +1,25 @@ -#!/bin/sh - -# -# $Id$ -# - -if [ "${HB_INC_LIBHARU}" == "" ] -then - echo "---------------------------------------------------------------" - echo "IMPORTANT: You will need Haru Free PDF Library (libharu) DLL - echo " package installed and this envvar to be set to" - echo " successfully build this library:" - echo " export HB_INC_LIBHARU=C:/libharu/include" - echo " or" - echo " export HB_INC_LIBHARU=/usr/include/libharu" - echo "---------------------------------------------------------------" - exit 1 -fi - -export CFLAGS= -for I in ${HB_INC_LIBHARU}; do - CFLAGS="${CFLAGS} -I${I}" -done -../mtpl_gcc.sh $1 $2 $3 $4 $5 $6 $7 $8 $9 -unset CFLAGS +#!/bin/sh + +# +# $Id$ +# + +if [ "${HB_INC_LIBHARU}" == "" ] +then + echo "---------------------------------------------------------------" + echo "IMPORTANT: You will need Haru Free PDF Library (libharu) DLL + echo " package installed and this envvar to be set to" + echo " successfully build this library:" + echo " export HB_INC_LIBHARU=C:/libharu/include" + echo " or" + echo " export HB_INC_LIBHARU=/usr/include/libharu" + echo "---------------------------------------------------------------" + exit 1 +fi + +export CFLAGS= +for I in ${HB_INC_LIBHARU}; do + CFLAGS="${CFLAGS} -I${I}" +done +../mtpl_gcc.sh $1 $2 $3 $4 $5 $6 $7 $8 $9 +unset CFLAGS diff --git a/harbour/contrib/hbodbc/odbc.c b/harbour/contrib/hbodbc/odbc.c index 660eee364e..72d2e38c0b 100644 --- a/harbour/contrib/hbodbc/odbc.c +++ b/harbour/contrib/hbodbc/odbc.c @@ -366,14 +366,14 @@ HB_FUNC( SQLCOLATTRIBUTE ) SDWORD lLen = ( SDWORD ) hb_parnl( 5 ); PTR bBuffer = hb_xgrab( lLen ); SQLSMALLINT wBufLen = hb_parni( 6 ); - SQLSMALLINT wNumPtr = hb_parni( 7 ); +#if defined(__DMC__) + SQLINTEGER wNumPtr = hb_parni( 7 ); +#else + SQLLEN wNumPtr = hb_parni( 7 ); +#endif WORD wResult = SQLColAttribute( ( HSTMT ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 3 ), (unsigned char*) bBuffer, hb_parni( 5 ), &wBufLen, -#if defined(__DMC__) - (SQLINTEGER FAR*) &wNumPtr ); -#else - (SQLLEN *) &wNumPtr ); -#endif + &wNumPtr ); if( wResult == SQL_SUCCESS || wResult == SQL_SUCCESS_WITH_INFO ) { diff --git a/harbour/contrib/hbtpathy/ChangeLog b/harbour/contrib/hbtpathy/ChangeLog index a372d6b27d..5a39e5d098 100644 --- a/harbour/contrib/hbtpathy/ChangeLog +++ b/harbour/contrib/hbtpathy/ChangeLog @@ -1,5 +1,5 @@ /* - * $Id: ChangeLog,v 1.15 2005/10/24 14:39:26 mauriliolongo Exp $ + * $Id$ */ /* Use this format for the entry headers: diff --git a/harbour/contrib/hbtpathy/Makefile b/harbour/contrib/hbtpathy/Makefile index 0a1e7a419f..0694bcfdf0 100644 --- a/harbour/contrib/hbtpathy/Makefile +++ b/harbour/contrib/hbtpathy/Makefile @@ -1,38 +1,38 @@ -# -# $Id: Makefile,v 1.4 2005/10/13 10:45:46 mauriliolongo Exp $ -# - -ROOT = ../../ - -ifneq ($(HB_ARCHITECTURE),dos) - -ifeq ($(HB_ARCHITECTURE),linux) -C_SOURCES=\ - tplinux.c \ - tpcommon.c \ - -endif -ifeq ($(HB_ARCHITECTURE),win32) -C_SOURCES=\ - tpwin32.c \ - tpcommon.c \ - -endif -ifeq ($(HB_ARCHITECTURE),os2) -C_SOURCES=\ - tpos2.c \ - tpcommon.c \ - -endif - -PRG_SOURCES=\ - telepath.prg \ - -PRG_HEADERS=\ - telepath.ch \ - -LIBNAME=hbtpathy - -include $(TOP)$(ROOT)config/lib.cf - -endif +# +# $Id$ +# + +ROOT = ../../ + +ifneq ($(HB_ARCHITECTURE),dos) + +ifeq ($(HB_ARCHITECTURE),linux) +C_SOURCES=\ + tplinux.c \ + tpcommon.c \ + +endif +ifeq ($(HB_ARCHITECTURE),win32) +C_SOURCES=\ + tpwin32.c \ + tpcommon.c \ + +endif +ifeq ($(HB_ARCHITECTURE),os2) +C_SOURCES=\ + tpos2.c \ + tpcommon.c \ + +endif + +PRG_SOURCES=\ + telepath.prg \ + +PRG_HEADERS=\ + telepath.ch \ + +LIBNAME=hbtpathy + +include $(TOP)$(ROOT)config/lib.cf + +endif diff --git a/harbour/contrib/hbtpathy/common.mak b/harbour/contrib/hbtpathy/common.mak index 4c31c68af2..704ab1e06b 100644 --- a/harbour/contrib/hbtpathy/common.mak +++ b/harbour/contrib/hbtpathy/common.mak @@ -1,16 +1,16 @@ -# -# $Id: common.mak 7935 2007-11-10 11:31:17Z vszakats $ -# - -LIBNAME = $(LIBPREF)hbtpathy - -LIB_PATH = $(LIB_DIR)$(LIBNAME)$(LIBEXT) - -LIB_OBJS = \ - $(OBJ_DIR)tpwin32$(OBJEXT) \ - $(OBJ_DIR)tpcommon$(OBJEXT) \ - \ - $(OBJ_DIR)telepath$(OBJEXT) \ - -all: \ - $(LIB_PATH) \ +# +# $Id$ +# + +LIBNAME = $(LIBPREF)hbtpathy + +LIB_PATH = $(LIB_DIR)$(LIBNAME)$(LIBEXT) + +LIB_OBJS = \ + $(OBJ_DIR)tpwin32$(OBJEXT) \ + $(OBJ_DIR)tpcommon$(OBJEXT) \ + \ + $(OBJ_DIR)telepath$(OBJEXT) \ + +all: \ + $(LIB_PATH) \ diff --git a/harbour/contrib/hbtpathy/make_b32.bat b/harbour/contrib/hbtpathy/make_b32.bat index b61b6ac526..c484512c4c 100644 --- a/harbour/contrib/hbtpathy/make_b32.bat +++ b/harbour/contrib/hbtpathy/make_b32.bat @@ -1,6 +1,6 @@ @echo off rem -rem $Id: make_b32.bat 7974 2007-11-14 23:24:27Z vszakats $ +rem $Id$ rem call ..\mtpl_b32.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 diff --git a/harbour/contrib/hbtpathy/make_vc.bat b/harbour/contrib/hbtpathy/make_vc.bat index 54da3972e4..4ceb9b9261 100644 --- a/harbour/contrib/hbtpathy/make_vc.bat +++ b/harbour/contrib/hbtpathy/make_vc.bat @@ -1,6 +1,6 @@ @echo off rem -rem $Id: make_vc.bat 7974 2007-11-14 23:24:27Z vszakats $ +rem $Id$ rem call ..\mtpl_vc.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 diff --git a/harbour/contrib/hbtpathy/readme.txt b/harbour/contrib/hbtpathy/readme.txt index 5b54ae2c0c..4100182410 100644 --- a/harbour/contrib/hbtpathy/readme.txt +++ b/harbour/contrib/hbtpathy/readme.txt @@ -1,55 +1,55 @@ -/* - * $Id: README,v 1.2 2004/08/16 14:30:18 mauriliolongo Exp $ - */ - -Telepathy is the best serial communication library for Nantucket/CA Clipper. -I ported a significant amount of the functionality contained in Telepathy in -this Flagship port. - -The .prg (in the MyTelepathy.tar package) is meant to be compiled with -Flagship and provide some of the functionality of the Telepathy serial -library from Extrasensory Inc. I've talked to Ira Emus, the proprietor of -Extrasensory and he's ok with what I've done here. But Extrasensory has no -involvement or responsibility with this project. - -I wrote this originally on RedHat Linux 5.1 and I've tested it on RedHat -6.2. And now Neolinux 2.0.1 and 2.1. I've tested it on kernels 2.0.x - 2.4.x. -Your mileage may vary. - -I only ported the parts of Telepathy that I needed. If you need other parts -of the telepathy libarary, Use the Source... (and send me your new functions) - -I tried to keep parameter counts and orders as consistent as possible between -this Telepathy and the real Telepathy. The only difference I can think of is -the parameter list for tp_open (and tp_reopen). That's just because unix has -filename comports like /dev/ttyS0 and dos has com port numbers like 1. I kept -the com port number thing so that all the telepathy functions (and all your -code) that uses com port number won't need to be changed. But you do need to -change the calls to tp_open. - -Feel free to use, modify, distribute, hack, kludge, append, extend or whatever -you like to this source code. You can (at your own risk) compile it into any -program you wish and sell or freely distribute the resulting application. I -would prefer you make your application Free and distribute the source. But who -am I to say - the suite of applications that my company sells that I originally -wrote this for is closed source. - -Though I use this code in a production environment for a suite of programs that -my company actually sells, I make no promises (expressed or implied) about its -stability, functionality, effectiveness or anything else. I warn you now -that if you use my code, you're doing so at your own risk and it will probably -blow up your computer. But that's a risk you'll just have to take. - -There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE (thanks RMS). -This software is totally as is, you may use it at your own risk. - -This is freeware. But if you actually use this in your program, please send -me email at dan@boba-fett.net. I'd just be curious to see if anyone ever -uses it. - -If you find a bug or write some new code for this project, pretty please send -me email with it. - -- Dan Levitt - +/* + * $Id$ + */ + +Telepathy is the best serial communication library for Nantucket/CA Clipper. +I ported a significant amount of the functionality contained in Telepathy in +this Flagship port. + +The .prg (in the MyTelepathy.tar package) is meant to be compiled with +Flagship and provide some of the functionality of the Telepathy serial +library from Extrasensory Inc. I've talked to Ira Emus, the proprietor of +Extrasensory and he's ok with what I've done here. But Extrasensory has no +involvement or responsibility with this project. + +I wrote this originally on RedHat Linux 5.1 and I've tested it on RedHat +6.2. And now Neolinux 2.0.1 and 2.1. I've tested it on kernels 2.0.x - 2.4.x. +Your mileage may vary. + +I only ported the parts of Telepathy that I needed. If you need other parts +of the telepathy libarary, Use the Source... (and send me your new functions) + +I tried to keep parameter counts and orders as consistent as possible between +this Telepathy and the real Telepathy. The only difference I can think of is +the parameter list for tp_open (and tp_reopen). That's just because unix has +filename comports like /dev/ttyS0 and dos has com port numbers like 1. I kept +the com port number thing so that all the telepathy functions (and all your +code) that uses com port number won't need to be changed. But you do need to +change the calls to tp_open. + +Feel free to use, modify, distribute, hack, kludge, append, extend or whatever +you like to this source code. You can (at your own risk) compile it into any +program you wish and sell or freely distribute the resulting application. I +would prefer you make your application Free and distribute the source. But who +am I to say - the suite of applications that my company sells that I originally +wrote this for is closed source. + +Though I use this code in a production environment for a suite of programs that +my company actually sells, I make no promises (expressed or implied) about its +stability, functionality, effectiveness or anything else. I warn you now +that if you use my code, you're doing so at your own risk and it will probably +blow up your computer. But that's a risk you'll just have to take. + +There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE (thanks RMS). +This software is totally as is, you may use it at your own risk. + +This is freeware. But if you actually use this in your program, please send +me email at dan@boba-fett.net. I'd just be curious to see if anyone ever +uses it. + +If you find a bug or write some new code for this project, pretty please send +me email with it. + +- Dan Levitt + diff --git a/harbour/contrib/hbtpathy/telepath.ch b/harbour/contrib/hbtpathy/telepath.ch index 8065e5beec..cd1b27bfb0 100644 --- a/harbour/contrib/hbtpathy/telepath.ch +++ b/harbour/contrib/hbtpathy/telepath.ch @@ -1,126 +1,126 @@ -/* - * $Id: telepath.ch,v 1.1 2004/08/31 14:48:39 mauriliolongo Exp $ - */ - -/* - * Harbour Project source code: - * Telepathy emulation library - * - * Copyright 2000, 2001 Dan Levitt - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - - -#define TP_MAXPORTS 8 - -#define TPFP_NAME 1 // Structure of ports array -#define TPFP_HANDLE 2 -#define TPFP_BAUD 3 -#define TPFP_DBITS 4 -#define TPFP_PARITY 5 -#define TPFP_SBITS 6 -#define TPFP_OC 7 // Open/Close Flag -#define TPFP_INBUF 8 -#define TPFP_INBUF_SIZE 9 // Size of input buffer - - -// Error code definitions -#define TE_PARAM -1 // Bad parameter -#define TE_NOPORT -2 // No such port -#define TE_CLOSED -3 // Port not open -#define TE_CONFL -4 // IRQ conflict -#define TE_TMOUT -5 // Timeout -#define TE_NDCD -6 // Lost DCD -#define TE_ESCAPE -7 // User escape -#define TE_LENGTH -8 // Length limit -#define TE_CANCEL -9 // Input canceled -#define TE_NOHDL -10 // Out of handles - -#define TE_UCANCEL -50 // Canceled by user -#define TE_RCANCEL -51 // Canceled by remote -#define TE_STARTTM -52 // Timeout waiting to start -#define TE_BLOCKTM -53 // Timeout waiting for block -#define TE_ACKTM -54 // Timeout waiting for acknowledge -#define TE_SENDTM -55 // Timeout waiting to send -#define TE_CLEARTM -56 // Timeout waiting for sender to stop -#define TE_NAK -57 // Negative acknowledge -#define TE_BADACK -58 // Bad acknowledge character -#define TE_BADBLK -59 // Bad block format -#define TE_LONGBLK -60 // Long block received -#define TE_ERRMAX -61 // Too many errors -#define TE_DUPBLK -62 // Duplicate block -#define TE_PROTO -63 // Protocol failure -#define TE_CKSUM -64 // Checksum error -#define TE_HDRTM -65 // Timeout waiting for Zmodem header - -#define TE_DISKFULL -100 // Disk full -#define TE_NOFILE -102 // File not found -#define TE_NOPATH -103 // Path not found -#define TE_MFILE -104 // Too many open files -#define TE_ACCESS -105 // Access denied - -// File transfer status -#define TXS_START 1 // Start of transfer -#define TXS_SFILE 2 // Start of file -#define TXS_NEWNAME 3 // File renamed -#define TXS_SDATA 4 // Start of file data -#define TXS_BLOCK 5 // End of block -#define TXS_ERROR 6 // Error -#define TXS_ABFILE 7 // Aborting file -#define TXS_ABORT 8 // Aborting transfer -#define TXS_WEND 9 // Waiting for end of file -#define TXS_EFILE 10 // End of file -#define TXS_END 11 // End of transfer - -#define TP_32MAGIC 558161692 - -// Handshaking flags for tp_hshk() -#define THS_RDSR 1 // Require DSR -#define THS_RCTS 2 // Require CTS -#define THS_RXOFF 4 // Respect XON/XOFF -#define THS_RDCD 8 // Require DCD -#define THS_ADTR 16 // Assert DTR -#define THS_CDTR 32 // Flow control with DTR -#define THS_ARTS 64 // Assert RTS -#define THS_CRTS 128 // Flow control with RTS -#define THS_SXOFF 256 // Send XON/XOFF +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Telepathy emulation library + * + * Copyright 2000, 2001 Dan Levitt + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + + +#define TP_MAXPORTS 8 + +#define TPFP_NAME 1 // Structure of ports array +#define TPFP_HANDLE 2 +#define TPFP_BAUD 3 +#define TPFP_DBITS 4 +#define TPFP_PARITY 5 +#define TPFP_SBITS 6 +#define TPFP_OC 7 // Open/Close Flag +#define TPFP_INBUF 8 +#define TPFP_INBUF_SIZE 9 // Size of input buffer + + +// Error code definitions +#define TE_PARAM -1 // Bad parameter +#define TE_NOPORT -2 // No such port +#define TE_CLOSED -3 // Port not open +#define TE_CONFL -4 // IRQ conflict +#define TE_TMOUT -5 // Timeout +#define TE_NDCD -6 // Lost DCD +#define TE_ESCAPE -7 // User escape +#define TE_LENGTH -8 // Length limit +#define TE_CANCEL -9 // Input canceled +#define TE_NOHDL -10 // Out of handles + +#define TE_UCANCEL -50 // Canceled by user +#define TE_RCANCEL -51 // Canceled by remote +#define TE_STARTTM -52 // Timeout waiting to start +#define TE_BLOCKTM -53 // Timeout waiting for block +#define TE_ACKTM -54 // Timeout waiting for acknowledge +#define TE_SENDTM -55 // Timeout waiting to send +#define TE_CLEARTM -56 // Timeout waiting for sender to stop +#define TE_NAK -57 // Negative acknowledge +#define TE_BADACK -58 // Bad acknowledge character +#define TE_BADBLK -59 // Bad block format +#define TE_LONGBLK -60 // Long block received +#define TE_ERRMAX -61 // Too many errors +#define TE_DUPBLK -62 // Duplicate block +#define TE_PROTO -63 // Protocol failure +#define TE_CKSUM -64 // Checksum error +#define TE_HDRTM -65 // Timeout waiting for Zmodem header + +#define TE_DISKFULL -100 // Disk full +#define TE_NOFILE -102 // File not found +#define TE_NOPATH -103 // Path not found +#define TE_MFILE -104 // Too many open files +#define TE_ACCESS -105 // Access denied + +// File transfer status +#define TXS_START 1 // Start of transfer +#define TXS_SFILE 2 // Start of file +#define TXS_NEWNAME 3 // File renamed +#define TXS_SDATA 4 // Start of file data +#define TXS_BLOCK 5 // End of block +#define TXS_ERROR 6 // Error +#define TXS_ABFILE 7 // Aborting file +#define TXS_ABORT 8 // Aborting transfer +#define TXS_WEND 9 // Waiting for end of file +#define TXS_EFILE 10 // End of file +#define TXS_END 11 // End of transfer + +#define TP_32MAGIC 558161692 + +// Handshaking flags for tp_hshk() +#define THS_RDSR 1 // Require DSR +#define THS_RCTS 2 // Require CTS +#define THS_RXOFF 4 // Respect XON/XOFF +#define THS_RDCD 8 // Require DCD +#define THS_ADTR 16 // Assert DTR +#define THS_CDTR 32 // Flow control with DTR +#define THS_ARTS 64 // Assert RTS +#define THS_CRTS 128 // Flow control with RTS +#define THS_SXOFF 256 // Send XON/XOFF diff --git a/harbour/contrib/hbtpathy/telepath.prg b/harbour/contrib/hbtpathy/telepath.prg index d591fdac9f..6303505659 100644 --- a/harbour/contrib/hbtpathy/telepath.prg +++ b/harbour/contrib/hbtpathy/telepath.prg @@ -1,867 +1,867 @@ -/* - * $Id: telepath.prg,v 1.12 2005/10/24 14:39:26 mauriliolongo Exp $ - */ - -/* - * Harbour Project source code: - * Telepathy emulation library - * - * Copyright 2000, 2001 Dan Levitt - * Copyright 2004, 2005 Maurilio Longo - * www - http://www.xharbour.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -/* - This is based upon a library originally made by Dan Levitt - (see README and ChangeLog). The original files have been committed as v1.0, - so you can always retrieve them (see CVS docs on how to) -*/ - - -#include "common.ch" -#include "fileio.ch" -#include "telepath.ch" - - - -STATIC s_aPorts // Array with port info -STATIC s_nErrorCode := 0 // Error code from last operation, 0 if no error - - - - -function tp_baud( nPort, nNewBaud ) - - local nRes - - default nNewBaud to 0 - - if ! isport( nPort ) .OR. Empty( s_aPorts[ nPort, TPFP_NAME ] ) - return TE_NOPORT - endif - - if ! isopenport( nPort ) - return 0 - endif - - if nNewBaud > 0 - if ( nRes := p_InitPortSpeed( s_aPorts[ nPort, TPFP_HANDLE ] ,; - nNewBaud,; - s_aPorts[ nPort, TPFP_DBITS ] ,; - s_aPorts[ nPort, TPFP_PARITY ] ,; - s_aPorts[ nPort, TPFP_SBITS ] ) ) == 0 - - s_aPorts[ nPort, TPFP_BAUD ] := nNewBaud - - - else - // set error code - endif - endif - -return s_aPorts[ nPort, TPFP_BAUD ] - - - -function tp_inkey( nSecs ) - if valtype( nSecs ) == "U" - return inkey() - endif -return inkey( nSecs ) - - - -function tp_idle( lNewval ) - if lNewval == .t. - return .t. - endif -return .f. - - - -function tp_delay( nTime ) - - default nTime to 0 - - if nTime < 0 - return nil - - elseif nTime > 1800 - nTime := 1800 - - endif - - ThreadSleep( nTime * 1000 ) - -return nil - - - -function tp_close( nPort, nTimeout ) - - default nTimeout to 0 - - /* Clipper returns 0 even if a port is not open */ - if ! isopenport( nPort ) - return 0 - endif - - if nTimeout > 0 - tp_flush( nPort, nTimeout ) - endif - - if s_aPorts[ nPort, TPFP_HANDLE ] >= 0 - - fClose( s_aPorts[ nPort, TPFP_HANDLE ] ) - - /* Port parameters should stay the same for the case the port - gets reopened - */ - s_aPorts[ nPort, TPFP_OC ] := .F. - s_aPorts[ nPort, TPFP_INBUF ] := "" - s_aPorts[ nPort, TPFP_HANDLE ] := -1 - endif - -return 0 - - - -function tp_reopen( nPort, nInSize, nOutSize ) - - LOCAL nBaud, nData, cParity, nStop, cPortName - - default nInSize to 1536, nOutSize to 1536 - - if ! isport( nPort ) .OR. Empty( s_aPorts[ nPort, TPFP_NAME ] ) - return TE_NOPORT - endif - - cPortname := s_aPorts[ nPort, TPFP_NAME ] - nBaud := s_aPorts[ nPort, TPFP_BAUD ] - nData := s_aPorts[ nPort, TPFP_DBITS ] - cParity := s_aPorts[ nPort, TPFP_PARITY ] - nStop := s_aPorts[ nPort, TPFP_SBITS ] - -return tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortName ) - - - -function tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortname ) - - local nRes, lPortExist - - #ifdef __PLATFORM__Linux - local nFileCase, nDirCase - #endif - - default nInSize to 1536, nOutSize to 1536 - default nBaud to 1200, nData to 8, cParity to "N", nStop to 1 - - /* Serial ports name are made up of cPortName + nPort if nPort is not NIL */ - #ifdef __PLATFORM__Linux - default cPortName to "/dev/ttyS" - #else - default cPortName to "COM" // Ok for Win32 and OS/2 - #endif - - /* This way compatibility is retained for ports 1-4 on Win32 and Linux, but, - should necessity arise, it is possible to simply pass a NIL on nPort and - a full name on cPortName - */ - #ifdef __PLATFORM__Linux - cPortname := AllTrim( cPortname ) + iif( ValType( nPort ) == "N", AllTrim( Str( nPort - 1 ) ), "" ) - #else - cPortname := AllTrim( cPortname ) + iif( ValType( nPort ) == "N", AllTrim( Str( nPort ) ), "" ) - #endif - - #ifdef __PLATFORM__Linux - nFileCase := Set( _SET_FILECASE, 0 ) - nDirCase := Set( _SET_DIRCASE, 0 ) - #endif - lPortExist := File( cPortname ) - #ifdef __PLATFORM__Linux - Set( _SET_FILECASE, nFileCase ) - Set( _SET_DIRCASE, nDirCase ) - #endif - - if ! lPortExist - return TE_NOPORT - endif - - if ! isport( nPort ) - return TE_NOPORT - endif - - s_aPorts[ nPort, TPFP_NAME ] := cPortname - s_aPorts[ nPort, TPFP_BAUD ] := nBaud - s_aPorts[ nPort, TPFP_DBITS ] := nData - s_aPorts[ nPort, TPFP_PARITY ] := cParity - s_aPorts[ nPort, TPFP_SBITS ] := nStop - s_aPorts[ nPort, TPFP_OC ] := .F. - s_aPorts[ nPort, TPFP_INBUF ] := "" - s_aPorts[ nPort, TPFP_INBUF_SIZE ] := nInSize - - #ifdef __PLATFORM__Linux - // Maybe we should have a p_Open() on every platform - s_aPorts[ nPort, TPFP_HANDLE ] := p_Open( cPortname ) - #else - s_aPorts[ nPort, TPFP_HANDLE ] := fOpen( cPortname, FO_READWRITE ) - #endif - - if s_aPorts[ nPort, TPFP_HANDLE ] >= 0 - - /* low level C functions are prefixed p_ (don't ask me why :)) */ - if ( nRes := p_InitPortSpeed( s_aPorts[ nPort, TPFP_HANDLE ] ,; - s_aPorts[ nPort, TPFP_BAUD ] ,; - s_aPorts[ nPort, TPFP_DBITS ] ,; - s_aPorts[ nPort, TPFP_PARITY ] ,; - s_aPorts[ nPort, TPFP_SBITS ] ) ) == 0 - - s_aPorts[ nPort, TPFP_OC ] := .T. - return nRes - - else - - tp_Close( s_aPorts[ nPort, TPFP_HANDLE ] ) - return nRes - - endif - - endif - - // set error code to a static var to have tp_error() work as expected - //cnHandle := ferror() - - s_aPorts[ nPort, TPFP_NAME ] := "" - s_aPorts[ nPort, TPFP_HANDLE ] := -1 - s_aPorts[ nPort, TPFP_BAUD ] := 1200 - s_aPorts[ nPort, TPFP_DBITS ] := 8 - s_aPorts[ nPort, TPFP_PARITY ] := "N" - s_aPorts[ nPort, TPFP_SBITS ] := 1 - s_aPorts[ nPort, TPFP_OC ] := .F. - s_aPorts[ nPort, TPFP_INBUF ] := "" - s_aPorts[ nPort, TPFP_INBUF_SIZE ] := 0 - -return TE_CONFL // maybe should return something different? - - - -function tp_recv( nPort, nLength, nTimeout ) - - local nDone - local cRet := "" - - default nLength to s_aPorts[ nPort, TPFP_INBUF_SIZE ] - default nTimeout to 0 - - FetchChars( nPort ) - - nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) - - while Len( s_aPorts[ nPort, TPFP_INBUF ] ) < nLength .AND.; - ( nTimeout < 0 .OR. Seconds() < nDone ) - - if ! tp_idle() - FetchChars( nPort ) - else - exit - endif - - enddo - - if nLength > Len( s_aPorts[ nPort, TPFP_INBUF ] ) - cRet := s_aPorts[ nPort, TPFP_INBUF ] - s_aPorts[ nPort, TPFP_INBUF ] := "" - else - cRet := SubStr( s_aPorts[ nPort, TPFP_INBUF ], 1, nLength ) - s_aPorts[ nPort, TPFP_INBUF ] := SubStr( s_aPorts[ nPort, TPFP_INBUF ], nLength + 1 ) - endif - -return cRet - - - -function tp_send( nPort, cString, nTimeout ) - - local nWritten, nTotWritten, nDone - - default cString to "", nTimeout to 0 - - if ! isopenport( nPort ) - return 0 - endif - - if Empty( cString ) - return 0 - endif - - nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0) - nWritten := nTotWritten := 0 - - while nTotWritten < Len( cString ) .AND. ; - ( nTimeout < 0 .OR. Seconds() <= nDone ) - - nWritten := p_WritePort( s_aPorts[ nPort, TPFP_HANDLE ], SubStr( cString, nTotWritten + 1 ) ) - - if nWritten >= 0 - - nTotWritten += nWritten - - if nTotWritten < Len( cString ) - - if ! tp_idle() - ThreadSleep( 1000 ) - else - exit - endif - - endif - - else // nWritten < 0, error occurred - exit - - endif - - enddo - -return nTotWritten - - - -function tp_sendsub( nPort, cString, nStart, nLength, nTimeout ) - - default nStart to 1, nLength to Len( cString ) - -return tp_send( nPort, SubStr( cString, nStart, nLength ), nTimeout ) - - - -function tp_recvto( nPort, cDelim, nMaxlen, nTimeout ) - - local cChar - local nAt - local nStartPos := 1, nFirst := 0 - local nDone, cRet := "" - - - if ! isopenport( nPort ) - return "" - endif - - if !( ValType( cDelim ) == "C" ) .OR. Empty( cDelim ) - return "" - endif - - default nMaxlen to 64999 /* dos telepathy def. on xharbour could be higher */ - default nTimeout to 0 - - - FetchChars( nPort ) - - /* Telepathy ng: [...] If nTimeout is omitted or zero, reads until finding the - delimiter or the input buffer is empty. */ - if nTimeout == 0 .AND. Empty( s_aPorts[ nPort, TPFP_INBUF ] ) - return "" - endif - - nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) - - while ( nTimeout < 0 .OR. Seconds() < nDone ) - - if Len( cDelim ) == 1 - - nAt := hb_At( cDelim, s_aPorts[ nPort, TPFP_INBUF ], nStartPos ) - - if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) - nFirst := nAt - endif - - else - - FOR EACH cChar IN cDelim - - nAt := hb_At( cChar, s_aPorts[ nPort, TPFP_INBUF ], nStartPos ) - - if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) - nFirst := nAt - endif - - NEXT - - endif - - // I've found it - if nFirst > 0 - exit - - else - // Next loop I don't need to search that part of the input buffer that - // I've already just searched for - nStartPos := Max( Len( s_aPorts[ nPort, TPFP_INBUF ] ), 1 ) - - // I've read more characters than I'm allowed to, so I exit - if nStartPos >= nMaxLen - exit - endif - - if ! tp_idle() - FetchChars( nPort ) - else - exit - endif - endif - - enddo - - if nFirst > 0 - cRet := Left( s_aPorts[ nPort, TPFP_INBUF ], nFirst ) - s_aPorts[ nPort, TPFP_INBUF ] := SubStr( s_aPorts[ nPort, TPFP_INBUF ], nFirst + 1 ) - endif - -return cRet - - - -/* - here's an improvement over original TP... you can "lookfor" a string - here rather than just a char. yay me. - of course, if you're using clipper/tp code and you search for a single char it will work - the same. -*/ -function tp_lookfor( nPort, cLookfor ) - - if ! isopenport( nPort ) - return 0 - endif - - FetchChars( nPort ) - -return At( cLookfor, s_aPorts[ nPort, TPFP_INBUF ] ) - - - -function tp_inchrs( nPort ) - - if ! isopenport( nPort ) - return 0 - endif - - FetchChars( nPort ) - -return Len( s_aPorts[ nPort, TPFP_INBUF ] ) - - - -function tp_outfree( nPort ) - - if ! isopenport( nPort ) - return 0 - endif - -return p_OutFree( s_aPorts[ nPort, TPFP_HANDLE ] ) - - - -function tp_clearin( nPort ) - - if isopenport( nPort ) - FetchChars( nPort ) - s_aPorts[ nPort, TPFP_INBUF ] := "" - endif - -return nil - - - -function tp_clrkbd() - - clear typeahead - -return nil - - - -function tp_crc16( cString ) - -return p_CRC16( cString ) - - - -function tp_crc32( cString ) - -return p_CRC32( cString ) - - -/* nPort, nTimeout, acList|cString..., lIgnorecase */ -function tp_waitfor( ... ) - - local aParam := hb_AParams() - local nPort, nTimeout, lIgnorecase - - nPort := aParam[ 1 ] - nTimeout := aParam[ 2 ] - lIgnorecase := aParam[ Len( aParam ) ] - - if ! isopenport( nPort ) - return 0 - endif - - default nTimeout to -1 - default lIgnorecase to .f. - - /* - - if ntimeout < 0 - nDone := _clock() + 999999 - elseif ntimeout == 0 - nDone := 4 - else - nDone := _clock() + nTimeout - endif - - while ( nDone > _clock() .or. nFirst == 100000 ) .and. ! tp_idle() - - if nFirst == 100000 - nFirst := 99999 - endif - - FetchChars( nPort ) - - for x := 1 to len( acList ) - if lIgnorecase - nAt := at( upper( acList[ x ] ), upper( s_aPorts[ nPort, TPFP_INBUF ] )) - else - nAt := at( acList[ x ] , s_aPorts[ nPort, TPFP_INBUF ] ) - endif - if nAt > 0 .and. nAt < nFirst - nFirst := nAt - nRet := x - endif - next - - if nFirst < 64000 - exit - endif - -#if 0 - sched_yield() // C level function -#endif - - enddo - - if nFirst < 64000 - tp_recv( nPort, nAt + len( acList[ nRet ] )) - return nRet - endif - */ - -return 0 - - - -/* We cannot set, well, _I_ think we cannot, CTS without setting RTS flowcontrol, so this - function and tp_ctrlrts() do the same thing, that is set/reset CRTSCTS flowcontol */ -function tp_ctrlcts( nPort, nNewCtrl ) - - local nCurValue - - if ! isopenport( nPort ) - return 0 - endif - - if Valtype( nNewCtrl ) == "U" - nCurValue := p_ctrlcts( s_aPorts[ nPort, TPFP_HANDLE ] ) - - else - nCurValue := p_ctrlcts( s_aPorts[ nPort, TPFP_HANDLE ], nNewCtrl ) - - endif - -return nCurValue - - -// Simply calls tp_ctrlcts() -function tp_ctrlrts( nPort, nNewCtrl ) - -return tp_ctrlcts( nPort, nNewCtrl ) - - - -/* - -// telepathy says... -// returns old dtr value 0,1,2 -// sets to 0 = dtr off, 1 dtr on, 2 = dtr flow control autotoggle -// I don't support 2. who uses dtr for flow control anyway... -function tp_ctrldtr( nPort, nParamNewval ) - LOCAL nph, nnewval, noldval - - if ! isopenport( nPort ) - return -1 - endif - nph := s_aPorts[ nPort, TPFP_HANDLE ] - - _P_CTRLDTR(nph, @nnewval, @noldval) - -return noldval -*/ - - - -function tp_isdcd( nPort ) - - if ! isopenport( nPort ) - return .f. - endif - -return p_isdcd( s_aPorts[ nPort, TPFP_HANDLE ] ) - - - -function tp_isri( nPort ) - - if ! isopenport( nPort ) - return .f. - endif - -return p_isri( s_aPorts[ nPort, TPFP_HANDLE ] ) - - - -function tp_isdsr( nPort ) - - if ! isopenport( nPort ) - return .f. - endif - -return p_isdsr( s_aPorts[ nPort, TPFP_HANDLE ] ) - - - -function tp_iscts( nPort ) - - if ! isopenport( nPort ) - return .f. - endif - -return p_iscts( s_aPorts[ nPort, TPFP_HANDLE ] ) - - - -#ifdef __PLATFORM__Linux -// NB: On linux i don't know how to make a drain with a timeout, so here -// I'll wait as long as it takes to drain the port. -function tp_flush( nPort, nTimeout ) - - local nStart := Seconds() - local nRes - - default nTimeout to 0 - - if ! isopenport( nPort ) - return TE_CLOSED - endif - - nRes := p_Drain( s_aPorts[ nPort, TPFP_HANDLE ] ) - - // Sleep rest of timeout - /* - if nTimeout > 0 .AND. Seconds() - nStart < nTimeout - ThreadSleep( ( nTimeout - ( Seconds() - nStart ) ) * 1000 ) - endif - */ - - // NB: returns timeout on error trying to reach compatibility with other platforms - // to be tested -return iif( nRes == 0, 0, TE_TMOUT ) - -#else - -function tp_flush( nPort, nTimeout ) - - local nDone - - default nTimeout to -1 - - if ! isopenport( nPort ) - return TE_CLOSED - endif - - if nTimeout > 1800 - nTimeout := 1800 - endif - - nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) - - while tp_OutFree( nPort ) > 0 .AND. ; - ( nTimeout < 0 .OR. Seconds() < nDone ) - hb_IdleState() - enddo - -return iif( tp_OutFree( nPort ) > 0, TE_TMOUT, 0 ) -#endif - - - -/* - -/// sorry, but ctrldsr and ctrlcts will act like isdsr and iscts... if you want -/// flow control, talk to the system. -function tp_ctrldsr( nPort ) -return tp_isdsr( nPort ) - -/// you can't do these things. try rc.serial -function tp_shared -return 0 - -function tp_setport -return 0 - - - -*/ - -// internal (static) functions --------------------------------------------------- - -static function isopenport( nPort ) - - if ! isport( nPort ) - return .f. - endif - -return s_aPorts[ nPort, TPFP_OC ] - - - -static function isport( nPort ) - - if valtype( nPort ) != "N" .or. nPort < 1 .or. nPort > TP_MAXPORTS - return .f. - endif - -return .t. - - - -static function FetchChars( nPort ) - - local cStr := "" - - if ! isopenport( nPort ) - return 0 - endif - - cStr := p_ReadPort( s_aPorts[ nPort, TPFP_HANDLE ] ) - - if ! Empty( cStr ) - s_aPorts[ nPort, TPFP_INBUF ] += cStr - endif - -return Len( cStr ) - - - -INIT PROCEDURE _tpinit() - - local x - - if s_aPorts == nil - s_aPorts := array( TP_MAXPORTS ) - for x := 1 to len( s_aPorts ) - /// port name, file handle, baud, data bits, parity, stop bits, Open?, input buffer, input buff.size - s_aPorts[ x ] := { "", -1, 1200, 8, "N", 1, .F., "", 0 } - next - endif - -return - - - - -/* -/// you can uncomment the following section for compatability with TP code... I figured -/// you'd probably want them commented so it won't compile so that you would see where -/// you have potential incomplete port problems -///function tp_mstat -///return "" -/// -///function tp_szmodem -///return 0 -/// -///function tp_noteoff -///return 0 -/// -///function tp_ontime -///return 0 -/// -///function tp_rzmodem -///return 0 -/// -///function tp_error -///return 0 -/// -///function tp_errmsg -///return "" -/// -///function tp_fifo -///return 0 -/// -/// -///function tp_outchrs -///return 0 -/// -///function tp_keybd -///return 0 -/// - -/// tp_debug is not a real TP function. I included it so you can define your own debug -/// output function. -/// the point of the first parameter is a "debug level". I keep a system variable for how -/// much debuggning output is wanted and if the tp_debug parameter is a LOWER number than -/// the global debug level I print the message. Since I don't have your system globals, -/// I will ignore the first parameter and always print it. -/// I recommend you modify this function to suit your own debugging needs -function tp_debug( nDebugLevel, cString ) - ? cString -return nil -*/ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Telepathy emulation library + * + * Copyright 2000, 2001 Dan Levitt + * Copyright 2004, 2005 Maurilio Longo + * www - http://www.xharbour.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + This is based upon a library originally made by Dan Levitt + (see README and ChangeLog). The original files have been committed as v1.0, + so you can always retrieve them (see CVS docs on how to) +*/ + + +#include "common.ch" +#include "fileio.ch" +#include "telepath.ch" + + + +STATIC s_aPorts // Array with port info +STATIC s_nErrorCode := 0 // Error code from last operation, 0 if no error + + + + +function tp_baud( nPort, nNewBaud ) + + local nRes + + default nNewBaud to 0 + + if ! isport( nPort ) .OR. Empty( s_aPorts[ nPort, TPFP_NAME ] ) + return TE_NOPORT + endif + + if ! isopenport( nPort ) + return 0 + endif + + if nNewBaud > 0 + if ( nRes := p_InitPortSpeed( s_aPorts[ nPort, TPFP_HANDLE ] ,; + nNewBaud,; + s_aPorts[ nPort, TPFP_DBITS ] ,; + s_aPorts[ nPort, TPFP_PARITY ] ,; + s_aPorts[ nPort, TPFP_SBITS ] ) ) == 0 + + s_aPorts[ nPort, TPFP_BAUD ] := nNewBaud + + + else + // set error code + endif + endif + +return s_aPorts[ nPort, TPFP_BAUD ] + + + +function tp_inkey( nSecs ) + if valtype( nSecs ) == "U" + return inkey() + endif +return inkey( nSecs ) + + + +function tp_idle( lNewval ) + if lNewval == .t. + return .t. + endif +return .f. + + + +function tp_delay( nTime ) + + default nTime to 0 + + if nTime < 0 + return nil + + elseif nTime > 1800 + nTime := 1800 + + endif + + ThreadSleep( nTime * 1000 ) + +return nil + + + +function tp_close( nPort, nTimeout ) + + default nTimeout to 0 + + /* Clipper returns 0 even if a port is not open */ + if ! isopenport( nPort ) + return 0 + endif + + if nTimeout > 0 + tp_flush( nPort, nTimeout ) + endif + + if s_aPorts[ nPort, TPFP_HANDLE ] >= 0 + + fClose( s_aPorts[ nPort, TPFP_HANDLE ] ) + + /* Port parameters should stay the same for the case the port + gets reopened + */ + s_aPorts[ nPort, TPFP_OC ] := .F. + s_aPorts[ nPort, TPFP_INBUF ] := "" + s_aPorts[ nPort, TPFP_HANDLE ] := -1 + endif + +return 0 + + + +function tp_reopen( nPort, nInSize, nOutSize ) + + LOCAL nBaud, nData, cParity, nStop, cPortName + + default nInSize to 1536, nOutSize to 1536 + + if ! isport( nPort ) .OR. Empty( s_aPorts[ nPort, TPFP_NAME ] ) + return TE_NOPORT + endif + + cPortname := s_aPorts[ nPort, TPFP_NAME ] + nBaud := s_aPorts[ nPort, TPFP_BAUD ] + nData := s_aPorts[ nPort, TPFP_DBITS ] + cParity := s_aPorts[ nPort, TPFP_PARITY ] + nStop := s_aPorts[ nPort, TPFP_SBITS ] + +return tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortName ) + + + +function tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortname ) + + local nRes, lPortExist + + #ifdef __PLATFORM__Linux + local nFileCase, nDirCase + #endif + + default nInSize to 1536, nOutSize to 1536 + default nBaud to 1200, nData to 8, cParity to "N", nStop to 1 + + /* Serial ports name are made up of cPortName + nPort if nPort is not NIL */ + #ifdef __PLATFORM__Linux + default cPortName to "/dev/ttyS" + #else + default cPortName to "COM" // Ok for Win32 and OS/2 + #endif + + /* This way compatibility is retained for ports 1-4 on Win32 and Linux, but, + should necessity arise, it is possible to simply pass a NIL on nPort and + a full name on cPortName + */ + #ifdef __PLATFORM__Linux + cPortname := AllTrim( cPortname ) + iif( ValType( nPort ) == "N", AllTrim( Str( nPort - 1 ) ), "" ) + #else + cPortname := AllTrim( cPortname ) + iif( ValType( nPort ) == "N", AllTrim( Str( nPort ) ), "" ) + #endif + + #ifdef __PLATFORM__Linux + nFileCase := Set( _SET_FILECASE, 0 ) + nDirCase := Set( _SET_DIRCASE, 0 ) + #endif + lPortExist := File( cPortname ) + #ifdef __PLATFORM__Linux + Set( _SET_FILECASE, nFileCase ) + Set( _SET_DIRCASE, nDirCase ) + #endif + + if ! lPortExist + return TE_NOPORT + endif + + if ! isport( nPort ) + return TE_NOPORT + endif + + s_aPorts[ nPort, TPFP_NAME ] := cPortname + s_aPorts[ nPort, TPFP_BAUD ] := nBaud + s_aPorts[ nPort, TPFP_DBITS ] := nData + s_aPorts[ nPort, TPFP_PARITY ] := cParity + s_aPorts[ nPort, TPFP_SBITS ] := nStop + s_aPorts[ nPort, TPFP_OC ] := .F. + s_aPorts[ nPort, TPFP_INBUF ] := "" + s_aPorts[ nPort, TPFP_INBUF_SIZE ] := nInSize + + #ifdef __PLATFORM__Linux + // Maybe we should have a p_Open() on every platform + s_aPorts[ nPort, TPFP_HANDLE ] := p_Open( cPortname ) + #else + s_aPorts[ nPort, TPFP_HANDLE ] := fOpen( cPortname, FO_READWRITE ) + #endif + + if s_aPorts[ nPort, TPFP_HANDLE ] >= 0 + + /* low level C functions are prefixed p_ (don't ask me why :)) */ + if ( nRes := p_InitPortSpeed( s_aPorts[ nPort, TPFP_HANDLE ] ,; + s_aPorts[ nPort, TPFP_BAUD ] ,; + s_aPorts[ nPort, TPFP_DBITS ] ,; + s_aPorts[ nPort, TPFP_PARITY ] ,; + s_aPorts[ nPort, TPFP_SBITS ] ) ) == 0 + + s_aPorts[ nPort, TPFP_OC ] := .T. + return nRes + + else + + tp_Close( s_aPorts[ nPort, TPFP_HANDLE ] ) + return nRes + + endif + + endif + + // set error code to a static var to have tp_error() work as expected + //cnHandle := ferror() + + s_aPorts[ nPort, TPFP_NAME ] := "" + s_aPorts[ nPort, TPFP_HANDLE ] := -1 + s_aPorts[ nPort, TPFP_BAUD ] := 1200 + s_aPorts[ nPort, TPFP_DBITS ] := 8 + s_aPorts[ nPort, TPFP_PARITY ] := "N" + s_aPorts[ nPort, TPFP_SBITS ] := 1 + s_aPorts[ nPort, TPFP_OC ] := .F. + s_aPorts[ nPort, TPFP_INBUF ] := "" + s_aPorts[ nPort, TPFP_INBUF_SIZE ] := 0 + +return TE_CONFL // maybe should return something different? + + + +function tp_recv( nPort, nLength, nTimeout ) + + local nDone + local cRet := "" + + default nLength to s_aPorts[ nPort, TPFP_INBUF_SIZE ] + default nTimeout to 0 + + FetchChars( nPort ) + + nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) + + while Len( s_aPorts[ nPort, TPFP_INBUF ] ) < nLength .AND.; + ( nTimeout < 0 .OR. Seconds() < nDone ) + + if ! tp_idle() + FetchChars( nPort ) + else + exit + endif + + enddo + + if nLength > Len( s_aPorts[ nPort, TPFP_INBUF ] ) + cRet := s_aPorts[ nPort, TPFP_INBUF ] + s_aPorts[ nPort, TPFP_INBUF ] := "" + else + cRet := SubStr( s_aPorts[ nPort, TPFP_INBUF ], 1, nLength ) + s_aPorts[ nPort, TPFP_INBUF ] := SubStr( s_aPorts[ nPort, TPFP_INBUF ], nLength + 1 ) + endif + +return cRet + + + +function tp_send( nPort, cString, nTimeout ) + + local nWritten, nTotWritten, nDone + + default cString to "", nTimeout to 0 + + if ! isopenport( nPort ) + return 0 + endif + + if Empty( cString ) + return 0 + endif + + nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0) + nWritten := nTotWritten := 0 + + while nTotWritten < Len( cString ) .AND. ; + ( nTimeout < 0 .OR. Seconds() <= nDone ) + + nWritten := p_WritePort( s_aPorts[ nPort, TPFP_HANDLE ], SubStr( cString, nTotWritten + 1 ) ) + + if nWritten >= 0 + + nTotWritten += nWritten + + if nTotWritten < Len( cString ) + + if ! tp_idle() + ThreadSleep( 1000 ) + else + exit + endif + + endif + + else // nWritten < 0, error occurred + exit + + endif + + enddo + +return nTotWritten + + + +function tp_sendsub( nPort, cString, nStart, nLength, nTimeout ) + + default nStart to 1, nLength to Len( cString ) + +return tp_send( nPort, SubStr( cString, nStart, nLength ), nTimeout ) + + + +function tp_recvto( nPort, cDelim, nMaxlen, nTimeout ) + + local cChar + local nAt + local nStartPos := 1, nFirst := 0 + local nDone, cRet := "" + + + if ! isopenport( nPort ) + return "" + endif + + if !( ValType( cDelim ) == "C" ) .OR. Empty( cDelim ) + return "" + endif + + default nMaxlen to 64999 /* dos telepathy def. on xharbour could be higher */ + default nTimeout to 0 + + + FetchChars( nPort ) + + /* Telepathy ng: [...] If nTimeout is omitted or zero, reads until finding the + delimiter or the input buffer is empty. */ + if nTimeout == 0 .AND. Empty( s_aPorts[ nPort, TPFP_INBUF ] ) + return "" + endif + + nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) + + while ( nTimeout < 0 .OR. Seconds() < nDone ) + + if Len( cDelim ) == 1 + + nAt := hb_At( cDelim, s_aPorts[ nPort, TPFP_INBUF ], nStartPos ) + + if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) + nFirst := nAt + endif + + else + + FOR EACH cChar IN cDelim + + nAt := hb_At( cChar, s_aPorts[ nPort, TPFP_INBUF ], nStartPos ) + + if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) + nFirst := nAt + endif + + NEXT + + endif + + // I've found it + if nFirst > 0 + exit + + else + // Next loop I don't need to search that part of the input buffer that + // I've already just searched for + nStartPos := Max( Len( s_aPorts[ nPort, TPFP_INBUF ] ), 1 ) + + // I've read more characters than I'm allowed to, so I exit + if nStartPos >= nMaxLen + exit + endif + + if ! tp_idle() + FetchChars( nPort ) + else + exit + endif + endif + + enddo + + if nFirst > 0 + cRet := Left( s_aPorts[ nPort, TPFP_INBUF ], nFirst ) + s_aPorts[ nPort, TPFP_INBUF ] := SubStr( s_aPorts[ nPort, TPFP_INBUF ], nFirst + 1 ) + endif + +return cRet + + + +/* + here's an improvement over original TP... you can "lookfor" a string + here rather than just a char. yay me. + of course, if you're using clipper/tp code and you search for a single char it will work + the same. +*/ +function tp_lookfor( nPort, cLookfor ) + + if ! isopenport( nPort ) + return 0 + endif + + FetchChars( nPort ) + +return At( cLookfor, s_aPorts[ nPort, TPFP_INBUF ] ) + + + +function tp_inchrs( nPort ) + + if ! isopenport( nPort ) + return 0 + endif + + FetchChars( nPort ) + +return Len( s_aPorts[ nPort, TPFP_INBUF ] ) + + + +function tp_outfree( nPort ) + + if ! isopenport( nPort ) + return 0 + endif + +return p_OutFree( s_aPorts[ nPort, TPFP_HANDLE ] ) + + + +function tp_clearin( nPort ) + + if isopenport( nPort ) + FetchChars( nPort ) + s_aPorts[ nPort, TPFP_INBUF ] := "" + endif + +return nil + + + +function tp_clrkbd() + + clear typeahead + +return nil + + + +function tp_crc16( cString ) + +return p_CRC16( cString ) + + + +function tp_crc32( cString ) + +return p_CRC32( cString ) + + +/* nPort, nTimeout, acList|cString..., lIgnorecase */ +function tp_waitfor( ... ) + + local aParam := hb_AParams() + local nPort, nTimeout, lIgnorecase + + nPort := aParam[ 1 ] + nTimeout := aParam[ 2 ] + lIgnorecase := aParam[ Len( aParam ) ] + + if ! isopenport( nPort ) + return 0 + endif + + default nTimeout to -1 + default lIgnorecase to .f. + + /* + + if ntimeout < 0 + nDone := _clock() + 999999 + elseif ntimeout == 0 + nDone := 4 + else + nDone := _clock() + nTimeout + endif + + while ( nDone > _clock() .or. nFirst == 100000 ) .and. ! tp_idle() + + if nFirst == 100000 + nFirst := 99999 + endif + + FetchChars( nPort ) + + for x := 1 to len( acList ) + if lIgnorecase + nAt := at( upper( acList[ x ] ), upper( s_aPorts[ nPort, TPFP_INBUF ] )) + else + nAt := at( acList[ x ] , s_aPorts[ nPort, TPFP_INBUF ] ) + endif + if nAt > 0 .and. nAt < nFirst + nFirst := nAt + nRet := x + endif + next + + if nFirst < 64000 + exit + endif + +#if 0 + sched_yield() // C level function +#endif + + enddo + + if nFirst < 64000 + tp_recv( nPort, nAt + len( acList[ nRet ] )) + return nRet + endif + */ + +return 0 + + + +/* We cannot set, well, _I_ think we cannot, CTS without setting RTS flowcontrol, so this + function and tp_ctrlrts() do the same thing, that is set/reset CRTSCTS flowcontol */ +function tp_ctrlcts( nPort, nNewCtrl ) + + local nCurValue + + if ! isopenport( nPort ) + return 0 + endif + + if Valtype( nNewCtrl ) == "U" + nCurValue := p_ctrlcts( s_aPorts[ nPort, TPFP_HANDLE ] ) + + else + nCurValue := p_ctrlcts( s_aPorts[ nPort, TPFP_HANDLE ], nNewCtrl ) + + endif + +return nCurValue + + +// Simply calls tp_ctrlcts() +function tp_ctrlrts( nPort, nNewCtrl ) + +return tp_ctrlcts( nPort, nNewCtrl ) + + + +/* + +// telepathy says... +// returns old dtr value 0,1,2 +// sets to 0 = dtr off, 1 dtr on, 2 = dtr flow control autotoggle +// I don't support 2. who uses dtr for flow control anyway... +function tp_ctrldtr( nPort, nParamNewval ) + LOCAL nph, nnewval, noldval + + if ! isopenport( nPort ) + return -1 + endif + nph := s_aPorts[ nPort, TPFP_HANDLE ] + + _P_CTRLDTR(nph, @nnewval, @noldval) + +return noldval +*/ + + + +function tp_isdcd( nPort ) + + if ! isopenport( nPort ) + return .f. + endif + +return p_isdcd( s_aPorts[ nPort, TPFP_HANDLE ] ) + + + +function tp_isri( nPort ) + + if ! isopenport( nPort ) + return .f. + endif + +return p_isri( s_aPorts[ nPort, TPFP_HANDLE ] ) + + + +function tp_isdsr( nPort ) + + if ! isopenport( nPort ) + return .f. + endif + +return p_isdsr( s_aPorts[ nPort, TPFP_HANDLE ] ) + + + +function tp_iscts( nPort ) + + if ! isopenport( nPort ) + return .f. + endif + +return p_iscts( s_aPorts[ nPort, TPFP_HANDLE ] ) + + + +#ifdef __PLATFORM__Linux +// NB: On linux i don't know how to make a drain with a timeout, so here +// I'll wait as long as it takes to drain the port. +function tp_flush( nPort, nTimeout ) + + local nStart := Seconds() + local nRes + + default nTimeout to 0 + + if ! isopenport( nPort ) + return TE_CLOSED + endif + + nRes := p_Drain( s_aPorts[ nPort, TPFP_HANDLE ] ) + + // Sleep rest of timeout + /* + if nTimeout > 0 .AND. Seconds() - nStart < nTimeout + ThreadSleep( ( nTimeout - ( Seconds() - nStart ) ) * 1000 ) + endif + */ + + // NB: returns timeout on error trying to reach compatibility with other platforms + // to be tested +return iif( nRes == 0, 0, TE_TMOUT ) + +#else + +function tp_flush( nPort, nTimeout ) + + local nDone + + default nTimeout to -1 + + if ! isopenport( nPort ) + return TE_CLOSED + endif + + if nTimeout > 1800 + nTimeout := 1800 + endif + + nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) + + while tp_OutFree( nPort ) > 0 .AND. ; + ( nTimeout < 0 .OR. Seconds() < nDone ) + hb_IdleState() + enddo + +return iif( tp_OutFree( nPort ) > 0, TE_TMOUT, 0 ) +#endif + + + +/* + +/// sorry, but ctrldsr and ctrlcts will act like isdsr and iscts... if you want +/// flow control, talk to the system. +function tp_ctrldsr( nPort ) +return tp_isdsr( nPort ) + +/// you can't do these things. try rc.serial +function tp_shared +return 0 + +function tp_setport +return 0 + + + +*/ + +// internal (static) functions --------------------------------------------------- + +static function isopenport( nPort ) + + if ! isport( nPort ) + return .f. + endif + +return s_aPorts[ nPort, TPFP_OC ] + + + +static function isport( nPort ) + + if valtype( nPort ) != "N" .or. nPort < 1 .or. nPort > TP_MAXPORTS + return .f. + endif + +return .t. + + + +static function FetchChars( nPort ) + + local cStr := "" + + if ! isopenport( nPort ) + return 0 + endif + + cStr := p_ReadPort( s_aPorts[ nPort, TPFP_HANDLE ] ) + + if ! Empty( cStr ) + s_aPorts[ nPort, TPFP_INBUF ] += cStr + endif + +return Len( cStr ) + + + +INIT PROCEDURE _tpinit() + + local x + + if s_aPorts == nil + s_aPorts := array( TP_MAXPORTS ) + for x := 1 to len( s_aPorts ) + /// port name, file handle, baud, data bits, parity, stop bits, Open?, input buffer, input buff.size + s_aPorts[ x ] := { "", -1, 1200, 8, "N", 1, .F., "", 0 } + next + endif + +return + + + + +/* +/// you can uncomment the following section for compatability with TP code... I figured +/// you'd probably want them commented so it won't compile so that you would see where +/// you have potential incomplete port problems +///function tp_mstat +///return "" +/// +///function tp_szmodem +///return 0 +/// +///function tp_noteoff +///return 0 +/// +///function tp_ontime +///return 0 +/// +///function tp_rzmodem +///return 0 +/// +///function tp_error +///return 0 +/// +///function tp_errmsg +///return "" +/// +///function tp_fifo +///return 0 +/// +/// +///function tp_outchrs +///return 0 +/// +///function tp_keybd +///return 0 +/// + +/// tp_debug is not a real TP function. I included it so you can define your own debug +/// output function. +/// the point of the first parameter is a "debug level". I keep a system variable for how +/// much debuggning output is wanted and if the tp_debug parameter is a LOWER number than +/// the global debug level I print the message. Since I don't have your system globals, +/// I will ignore the first parameter and always print it. +/// I recommend you modify this function to suit your own debugging needs +function tp_debug( nDebugLevel, cString ) + ? cString +return nil +*/ diff --git a/harbour/contrib/hbtpathy/tests/testtp.prg b/harbour/contrib/hbtpathy/tests/testtp.prg index 43bf010915..4c33e95c4d 100644 --- a/harbour/contrib/hbtpathy/tests/testtp.prg +++ b/harbour/contrib/hbtpathy/tests/testtp.prg @@ -1,78 +1,78 @@ -/* - * $Id: testtp.prg,v 1.4 2004/08/25 08:49:06 mauriliolongo Exp $ - */ - -/* - * Harbour Project source code: - * Telepathy emulation library - * - * Copyright 2000, 2001 Dan Levitt - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -/* - This is based upon a library originally made by Dan Levitt - (see README and ChangeLog). The original files have been committed as v1.0, - so you can always retrieve them (see CVS docs on how to) - - First xHarbour Port by Luiz Rafael Culik Guimaraes (culikr@brturbo.com) -*/ - -/* - instructions - hook up a loopback device to "com1" of your computer - run this program. It should echo Hi there bob. - If it gives you a file i/o error, try running as root. - also make sure that other programs (minicom?) can successfully talk to your - com port. -*/ - -function main - ? - ? - ? tp_open( 1,, 9600, 8, "N", 1 ) - //tp_send( 1, "Hi there bob" ) - tp_inkey( .5 ) - //? tp_recv( 1 ) - ? - tp_Close( 1 ) -return nil +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Telepathy emulation library + * + * Copyright 2000, 2001 Dan Levitt + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + This is based upon a library originally made by Dan Levitt + (see README and ChangeLog). The original files have been committed as v1.0, + so you can always retrieve them (see CVS docs on how to) + + First xHarbour Port by Luiz Rafael Culik Guimaraes (culikr@brturbo.com) +*/ + +/* + instructions - hook up a loopback device to "com1" of your computer + run this program. It should echo Hi there bob. + If it gives you a file i/o error, try running as root. + also make sure that other programs (minicom?) can successfully talk to your + com port. +*/ + +function main + ? + ? + ? tp_open( 1,, 9600, 8, "N", 1 ) + //tp_send( 1, "Hi there bob" ) + tp_inkey( .5 ) + //? tp_recv( 1 ) + ? + tp_Close( 1 ) +return nil diff --git a/harbour/contrib/hbtpathy/tplinux.c b/harbour/contrib/hbtpathy/tplinux.c index fcda4f8a9b..9abbaf4e93 100644 --- a/harbour/contrib/hbtpathy/tplinux.c +++ b/harbour/contrib/hbtpathy/tplinux.c @@ -1,308 +1,308 @@ -/* - * $Id: linux.c,v 1.2 2005/10/24 14:39:26 mauriliolongo Exp $ - */ - -/* - * Harbour Project source code: - * Telepathy emulation library - * C low level module for linux serial communication - * - * Copyright 2005 - Maurilio Longo - * www - http://www.harbour-project.org - * - * Lots of code from http://www.easysw.com/~mike/serial/serial.html - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbapi.h" -#include "hbapiitm.h" -#include "hbapifs.h" - -#ifdef HB_OS_UNIX - -#include /* Standard input/output definitions */ -#include /* String function definitions */ -#include /* UNIX standard function definitions */ -#include /* File control definitions */ -#include /* Error number definitions */ -#include /* POSIX terminal control definitions */ -#include - -HB_FUNC( P_OPEN ) -{ - int fd = open( hb_parcx( 1 ), O_RDWR | O_NOCTTY | O_NDELAY ); /* File descriptor for the port */ - - if( fd != -1 ) - fcntl( fd, F_SETFL, 0 ); - - hb_retnl( fd ); -} - -/* -p_InitPortSpeed( aPorts[ nPort, TPFP_HANDLE ] ,; - aPorts[ nPort, TPFP_BAUD ] ,; - aPorts[ nPort, TPFP_DBITS ] ,; - aPorts[ nPort, TPFP_PARITY ] ,; - aPorts[ nPort, TPFP_SBITS ] ) -*/ -HB_FUNC( P_INITPORTSPEED ) -{ - struct termios options; - int port = hb_parnl( 1 ); - int baud = B300; - char * ptr = hb_parcx( 4 ); - int rc; - - tcgetattr( port, &options ); - - /* let's set baud rate */ - switch( hb_parnl( 2 ) ) - { - case 0: baud = B0; break; /* Drop line */ - case 50: baud = B50; break; - case 75: baud = B75; break; - case 110: baud = B110; break; - case 150: baud = B150; break; - case 200: baud = B200; break; - case 300: baud = B300; break; - case 600: baud = B600; break; - case 1200: baud = B1200; break; - case 1800: baud = B1800; break; - case 2400: baud = B2400; break; - case 4800: baud = B4800; break; - case 9600: baud = B9600; break; - case 19200: baud = B19200; break; - case 38400: baud = B38400; break; - case 57600: baud = B57600; break; - case 115200: baud = B115200; break; - case 230400: baud = B230400; break; - } - - cfsetispeed( &options, baud ); - cfsetospeed( &options, baud ); - - /* Enable the receiver and set local mode... */ - options.c_cflag |= ( CLOCAL | CREAD ); - - /* Raw input from device */ - cfmakeraw( &options ); - - /* Reset data bits ( cfmakeraw() puts it to CS8 ) */ - options.c_cflag &= ~CSIZE; - - /* Data bits */ - if( hb_parni( 3 ) == 8 ) - options.c_cflag |= CS8; - else - options.c_cflag |= CS7; - - /* Stop bits */ - if( hb_parni( 5 ) == 1 ) - options.c_cflag &= ~CSTOPB; - - /* Parity, only No, Even, Odd supported */ - switch ( *ptr ) - { - case 'N': - case 'n': - options.c_cflag &= ~PARENB; - - options.c_iflag &= ~(INPCK); /* disable input parity checking */ - break; - - case 'O': - case 'o': - options.c_cflag |= PARENB; - options.c_cflag |= PARODD; - - options.c_iflag |= INPCK; - break; - - case 'E': - case 'e': - options.c_cflag |= PARENB; - options.c_cflag &= ~PARODD; - - options.c_iflag |= INPCK; - break; - } - - /* Every read() call returns as soon as a char is available OR after 3 tenths of a second */ - options.c_cc[ VMIN ] = 0; - options.c_cc[ VTIME ] = 3; - - /* Set the new options for the port... */ - rc = tcsetattr( port, TCSAFLUSH, &options ); - - hb_retnl( rc ); -} - -HB_FUNC( P_READPORT ) -{ - char Buffer[ 512 ]; - int nRead = read( hb_parnl( 1 ), Buffer, sizeof( Buffer ) ); - - hb_retclen( nRead > 0 ? Buffer : NULL, nRead ); -} - -HB_FUNC( P_WRITEPORT ) -{ - long n = write( hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ) ); - - hb_retnl( n < 0 ? -1 : n ); -} - -HB_FUNC( P_DRAIN ) -{ - hb_retnl( tcdrain( hb_parnl( 1 ) ) ); -} - -HB_FUNC( P_OUTFREE ) -{ -#if 0 - APIRET rc; - RXQUEUE rxqueue = { 0 }; - - if ( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, - NULL, 0L, NULL, &rxqueue, sizeof( RXQUEUE ), NULL ) ) == NO_ERROR ) - hb_retnl( rxqueue.cb - rxqueue.cch ); - else - hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */ -#endif -} - -HB_FUNC( P_ISDCD ) -{ - int status; - - if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) - hb_retl( ( status & TIOCM_CD ) == TIOCM_CD ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_ISRI ) -{ - int status; - - if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) - hb_retl( ( status & TIOCM_RI ) == TIOCM_RI ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_ISDSR ) -{ - int status; - - if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) - hb_retl( ( status & TIOCM_DSR ) == TIOCM_DSR ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_ISCTS ) -{ - int status; - - if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) - hb_retl( ( status & TIOCM_CTS ) == TIOCM_CTS ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_CTRLCTS ) { - - struct termios options; - int port = hb_parnl( 1 ); - int newvalue = hb_pcount() == 2 ? hb_parnl( 2 ) : -1; - int curvalue; - int rc; - - tcgetattr( port, &options ); - curvalue = ( options.c_cflag & CRTSCTS ) == CRTSCTS; - - if( newvalue == 0 ) - options.c_cflag &= ~CRTSCTS; - else if( newvalue == 1 ) - options.c_cflag |= CRTSCTS; - - if( newvalue >= 0 ) - rc = tcsetattr( port, TCSAFLUSH, &options ); - - hb_retni( curvalue ? 1 : 0 ); -} - -#if 0 - -/* Inline function moved here from telepath.prg */ -HB_FUNC( _P_CTRLDTR ) -{ - double nph = hb_parnd( 1 ); - double nnewval, noldval; - unsigned int result = 0; - - ioctl( nph, TIOCMGET, &result ); - - if( result & TIOCM_DTR ) - noldval = 1; - else - noldval = 0; - - if( noldval != nnewval ) - { - if( nnewval == 0 ) - result &= ~TIOCM_DTR; - else - result |= TIOCM_DTR; - - ioctl( nph, TIOCMSET, &result ); - } - - hb_stornd( nnewval, 2 ); - hb_stornd( noldval, 3 ); -} - -#endif - -#endif /* HB_OS_UNIX */ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Telepathy emulation library + * C low level module for linux serial communication + * + * Copyright 2005 - Maurilio Longo + * www - http://www.harbour-project.org + * + * Lots of code from http://www.easysw.com/~mike/serial/serial.html + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbapifs.h" + +#ifdef HB_OS_UNIX + +#include /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ +#include /* File control definitions */ +#include /* Error number definitions */ +#include /* POSIX terminal control definitions */ +#include + +HB_FUNC( P_OPEN ) +{ + int fd = open( hb_parcx( 1 ), O_RDWR | O_NOCTTY | O_NDELAY ); /* File descriptor for the port */ + + if( fd != -1 ) + fcntl( fd, F_SETFL, 0 ); + + hb_retnl( fd ); +} + +/* +p_InitPortSpeed( aPorts[ nPort, TPFP_HANDLE ] ,; + aPorts[ nPort, TPFP_BAUD ] ,; + aPorts[ nPort, TPFP_DBITS ] ,; + aPorts[ nPort, TPFP_PARITY ] ,; + aPorts[ nPort, TPFP_SBITS ] ) +*/ +HB_FUNC( P_INITPORTSPEED ) +{ + struct termios options; + int port = hb_parnl( 1 ); + int baud = B300; + char * ptr = hb_parcx( 4 ); + int rc; + + tcgetattr( port, &options ); + + /* let's set baud rate */ + switch( hb_parnl( 2 ) ) + { + case 0: baud = B0; break; /* Drop line */ + case 50: baud = B50; break; + case 75: baud = B75; break; + case 110: baud = B110; break; + case 150: baud = B150; break; + case 200: baud = B200; break; + case 300: baud = B300; break; + case 600: baud = B600; break; + case 1200: baud = B1200; break; + case 1800: baud = B1800; break; + case 2400: baud = B2400; break; + case 4800: baud = B4800; break; + case 9600: baud = B9600; break; + case 19200: baud = B19200; break; + case 38400: baud = B38400; break; + case 57600: baud = B57600; break; + case 115200: baud = B115200; break; + case 230400: baud = B230400; break; + } + + cfsetispeed( &options, baud ); + cfsetospeed( &options, baud ); + + /* Enable the receiver and set local mode... */ + options.c_cflag |= ( CLOCAL | CREAD ); + + /* Raw input from device */ + cfmakeraw( &options ); + + /* Reset data bits ( cfmakeraw() puts it to CS8 ) */ + options.c_cflag &= ~CSIZE; + + /* Data bits */ + if( hb_parni( 3 ) == 8 ) + options.c_cflag |= CS8; + else + options.c_cflag |= CS7; + + /* Stop bits */ + if( hb_parni( 5 ) == 1 ) + options.c_cflag &= ~CSTOPB; + + /* Parity, only No, Even, Odd supported */ + switch ( *ptr ) + { + case 'N': + case 'n': + options.c_cflag &= ~PARENB; + + options.c_iflag &= ~(INPCK); /* disable input parity checking */ + break; + + case 'O': + case 'o': + options.c_cflag |= PARENB; + options.c_cflag |= PARODD; + + options.c_iflag |= INPCK; + break; + + case 'E': + case 'e': + options.c_cflag |= PARENB; + options.c_cflag &= ~PARODD; + + options.c_iflag |= INPCK; + break; + } + + /* Every read() call returns as soon as a char is available OR after 3 tenths of a second */ + options.c_cc[ VMIN ] = 0; + options.c_cc[ VTIME ] = 3; + + /* Set the new options for the port... */ + rc = tcsetattr( port, TCSAFLUSH, &options ); + + hb_retnl( rc ); +} + +HB_FUNC( P_READPORT ) +{ + char Buffer[ 512 ]; + int nRead = read( hb_parnl( 1 ), Buffer, sizeof( Buffer ) ); + + hb_retclen( nRead > 0 ? Buffer : NULL, nRead ); +} + +HB_FUNC( P_WRITEPORT ) +{ + long n = write( hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ) ); + + hb_retnl( n < 0 ? -1 : n ); +} + +HB_FUNC( P_DRAIN ) +{ + hb_retnl( tcdrain( hb_parnl( 1 ) ) ); +} + +HB_FUNC( P_OUTFREE ) +{ +#if 0 + APIRET rc; + RXQUEUE rxqueue = { 0 }; + + if ( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, + NULL, 0L, NULL, &rxqueue, sizeof( RXQUEUE ), NULL ) ) == NO_ERROR ) + hb_retnl( rxqueue.cb - rxqueue.cch ); + else + hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */ +#endif +} + +HB_FUNC( P_ISDCD ) +{ + int status; + + if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) + hb_retl( ( status & TIOCM_CD ) == TIOCM_CD ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_ISRI ) +{ + int status; + + if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) + hb_retl( ( status & TIOCM_RI ) == TIOCM_RI ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_ISDSR ) +{ + int status; + + if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) + hb_retl( ( status & TIOCM_DSR ) == TIOCM_DSR ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_ISCTS ) +{ + int status; + + if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 ) + hb_retl( ( status & TIOCM_CTS ) == TIOCM_CTS ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_CTRLCTS ) { + + struct termios options; + int port = hb_parnl( 1 ); + int newvalue = hb_pcount() == 2 ? hb_parnl( 2 ) : -1; + int curvalue; + int rc; + + tcgetattr( port, &options ); + curvalue = ( options.c_cflag & CRTSCTS ) == CRTSCTS; + + if( newvalue == 0 ) + options.c_cflag &= ~CRTSCTS; + else if( newvalue == 1 ) + options.c_cflag |= CRTSCTS; + + if( newvalue >= 0 ) + rc = tcsetattr( port, TCSAFLUSH, &options ); + + hb_retni( curvalue ? 1 : 0 ); +} + +#if 0 + +/* Inline function moved here from telepath.prg */ +HB_FUNC( _P_CTRLDTR ) +{ + double nph = hb_parnd( 1 ); + double nnewval, noldval; + unsigned int result = 0; + + ioctl( nph, TIOCMGET, &result ); + + if( result & TIOCM_DTR ) + noldval = 1; + else + noldval = 0; + + if( noldval != nnewval ) + { + if( nnewval == 0 ) + result &= ~TIOCM_DTR; + else + result |= TIOCM_DTR; + + ioctl( nph, TIOCMSET, &result ); + } + + hb_stornd( nnewval, 2 ); + hb_stornd( noldval, 3 ); +} + +#endif + +#endif /* HB_OS_UNIX */ diff --git a/harbour/contrib/hbtpathy/tpos2.c b/harbour/contrib/hbtpathy/tpos2.c index 62f302072b..954bb42506 100644 --- a/harbour/contrib/hbtpathy/tpos2.c +++ b/harbour/contrib/hbtpathy/tpos2.c @@ -1,220 +1,220 @@ -/* - * $Id: os2.c,v 1.5 2005/10/24 14:39:26 mauriliolongo Exp $ - */ - -/* - * Harbour Project source code: - * Telepathy emulation library - * C low level module for OS/2 serial communication - * - * Copyright 2004 - Maurilio Longo - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#include "hbapi.h" -#include "hbapiitm.h" -#include "hbapifs.h" - -#ifdef HB_OS_OS2 - -#define INCL_BASE -#define INCL_DOS -#define INCL_DOSERROR -#define INCL_DOSDEVIOCTL -#include - -#include - -HB_FUNC( P_INITPORTSPEED ) -{ - APIRET rc; - LINECONTROL lctl; - DCBINFO dcb; - USHORT Baud = ( USHORT ) hb_parnl( 2 ); - char * ptr = hb_parcx( 4 ); - - memset( &dcb, 0, sizeof( dcb ) ); - memset( &lctl, 0, sizeof( lctl ) ); - - /* OS/2 has Mark and Space parity options */ - switch( *ptr ) - { - case 'N': - case 'n': - lctl.bParity = 0; - break; - case 'O': - case 'o': - lctl.bParity = 1; - break; - case 'E': - case 'e': - lctl.bParity = 2; - break; - case 'M': - case 'm': - lctl.bParity = 3; - break; - case 'S': - case 's': - lctl.bParity = 4; - } - - lctl.bDataBits = hb_parnl( 3 ); - lctl.bStopBits = hb_parnl( 5 ) == 1 ? 0 : hb_parnl( 5 ); /* 1 == 1.5 stop bits only valid with 5 data bits */ - lctl.fTransBreak = 0; - - if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETBAUDRATE, &Baud, - sizeof( USHORT ), NULL, NULL, 0L, NULL ) == NO_ERROR ) - { - if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETLINECTRL, - &lctl, sizeof( LINECONTROL ), NULL, NULL, 0L, NULL ) == NO_ERROR ) - { - /* tp_ help says: on port open - DTR ON (value 1) - CTS OFF - DCD IGNORE - DSR OFF - RTS ON (value 1) - XON/XOFF OFF - */ - dcb.fbCtlHndShake = MODE_DTR_HANDSHAKE | MODE_RTS_HANDSHAKE; - - /* 0x20 == full duplex */ - dcb.fbFlowReplace = MODE_RTS_HANDSHAKE | 0x20; - - dcb.fbTimeout = MODE_NO_WRITE_TIMEOUT | MODE_NOWAIT_READ_TIMEOUT; - - if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETDCBINFO, &dcb, - sizeof(DCBINFO), 0L, NULL, 0L, NULL ) == NO_ERROR ) - hb_retnl( 0 ); - else - hb_retnl( -3 ); - } - else - hb_retnl( -2 ); - } - else - hb_retnl( -1 ); -} - -HB_FUNC( P_READPORT ) -{ - char Buffer[ 512 ]; - ULONG nRead = 0; - APIRET rc = DosRead( ( HFILE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead ); - - hb_retclen( rc == NO_ERROR ? Buffer : NULL, nRead ); -} - -HB_FUNC( P_WRITEPORT ) -{ - ULONG nWritten = 0; - APIRET rc = DosWrite( ( HFILE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten ); - - hb_retnl( rc == NO_ERROR ? nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */ -} - -HB_FUNC( P_OUTFREE ) -{ - APIRET rc; - RXQUEUE rxqueue = { 0 }; - - if( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, - NULL, 0L, NULL, &rxqueue, sizeof(RXQUEUE), NULL ) ) == NO_ERROR ) - hb_retnl( rxqueue.cb - rxqueue.cch ); - else - hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */ -} - -HB_FUNC( P_ISDCD ) -{ - BYTE instat; - - /* if DosDevIOCtl() returns an error, return no DCD */ - if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) - hb_retl( ( instat & DCD_ON ) == DCD_ON ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_ISRI ) -{ - BYTE instat; - - if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) - hb_retl( ( instat & RI_ON ) == RI_ON ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_ISDSR ) -{ - BYTE instat; - - if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) - hb_retl( ( instat & DSR_ON ) == DSR_ON ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_ISCTS ) -{ - BYTE instat; - - if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, - NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) - hb_retl( ( instat & CTS_ON ) == CTS_ON ); - else - hb_retl( FALSE ); -} - -HB_FUNC( P_CTRLCTS ) -{ - hb_retni( 0 ); -} - -#endif /* HB_OS_OS2 */ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Telepathy emulation library + * C low level module for OS/2 serial communication + * + * Copyright 2004 - Maurilio Longo + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbapifs.h" + +#ifdef HB_OS_OS2 + +#define INCL_BASE +#define INCL_DOS +#define INCL_DOSERROR +#define INCL_DOSDEVIOCTL +#include + +#include + +HB_FUNC( P_INITPORTSPEED ) +{ + APIRET rc; + LINECONTROL lctl; + DCBINFO dcb; + USHORT Baud = ( USHORT ) hb_parnl( 2 ); + char * ptr = hb_parcx( 4 ); + + memset( &dcb, 0, sizeof( dcb ) ); + memset( &lctl, 0, sizeof( lctl ) ); + + /* OS/2 has Mark and Space parity options */ + switch( *ptr ) + { + case 'N': + case 'n': + lctl.bParity = 0; + break; + case 'O': + case 'o': + lctl.bParity = 1; + break; + case 'E': + case 'e': + lctl.bParity = 2; + break; + case 'M': + case 'm': + lctl.bParity = 3; + break; + case 'S': + case 's': + lctl.bParity = 4; + } + + lctl.bDataBits = hb_parnl( 3 ); + lctl.bStopBits = hb_parnl( 5 ) == 1 ? 0 : hb_parnl( 5 ); /* 1 == 1.5 stop bits only valid with 5 data bits */ + lctl.fTransBreak = 0; + + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETBAUDRATE, &Baud, + sizeof( USHORT ), NULL, NULL, 0L, NULL ) == NO_ERROR ) + { + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETLINECTRL, + &lctl, sizeof( LINECONTROL ), NULL, NULL, 0L, NULL ) == NO_ERROR ) + { + /* tp_ help says: on port open + DTR ON (value 1) + CTS OFF + DCD IGNORE + DSR OFF + RTS ON (value 1) + XON/XOFF OFF + */ + dcb.fbCtlHndShake = MODE_DTR_HANDSHAKE | MODE_RTS_HANDSHAKE; + + /* 0x20 == full duplex */ + dcb.fbFlowReplace = MODE_RTS_HANDSHAKE | 0x20; + + dcb.fbTimeout = MODE_NO_WRITE_TIMEOUT | MODE_NOWAIT_READ_TIMEOUT; + + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETDCBINFO, &dcb, + sizeof(DCBINFO), 0L, NULL, 0L, NULL ) == NO_ERROR ) + hb_retnl( 0 ); + else + hb_retnl( -3 ); + } + else + hb_retnl( -2 ); + } + else + hb_retnl( -1 ); +} + +HB_FUNC( P_READPORT ) +{ + char Buffer[ 512 ]; + ULONG nRead = 0; + APIRET rc = DosRead( ( HFILE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead ); + + hb_retclen( rc == NO_ERROR ? Buffer : NULL, nRead ); +} + +HB_FUNC( P_WRITEPORT ) +{ + ULONG nWritten = 0; + APIRET rc = DosWrite( ( HFILE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten ); + + hb_retnl( rc == NO_ERROR ? nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */ +} + +HB_FUNC( P_OUTFREE ) +{ + APIRET rc; + RXQUEUE rxqueue = { 0 }; + + if( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT, + NULL, 0L, NULL, &rxqueue, sizeof(RXQUEUE), NULL ) ) == NO_ERROR ) + hb_retnl( rxqueue.cb - rxqueue.cch ); + else + hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */ +} + +HB_FUNC( P_ISDCD ) +{ + BYTE instat; + + /* if DosDevIOCtl() returns an error, return no DCD */ + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) + hb_retl( ( instat & DCD_ON ) == DCD_ON ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_ISRI ) +{ + BYTE instat; + + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) + hb_retl( ( instat & RI_ON ) == RI_ON ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_ISDSR ) +{ + BYTE instat; + + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) + hb_retl( ( instat & DSR_ON ) == DSR_ON ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_ISCTS ) +{ + BYTE instat; + + if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT, + NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR ) + hb_retl( ( instat & CTS_ON ) == CTS_ON ); + else + hb_retl( FALSE ); +} + +HB_FUNC( P_CTRLCTS ) +{ + hb_retni( 0 ); +} + +#endif /* HB_OS_OS2 */ diff --git a/harbour/contrib/hbtpathy/tpwin32.c b/harbour/contrib/hbtpathy/tpwin32.c index d3b32931e5..8c0d557c26 100644 --- a/harbour/contrib/hbtpathy/tpwin32.c +++ b/harbour/contrib/hbtpathy/tpwin32.c @@ -1,115 +1,115 @@ -/* - * $Id: win32.c,v 1.2 2004/08/25 13:43:53 mauriliolongo Exp $ - */ - -/* - * Harbour Project source code: - * Telepathy emulation library - * C low level module for Win32 serial communication - * - * Copyright 2004 - Maurilio Longo - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#define HB_OS_WIN_32_USED - -#include "hbapi.h" -#include "hbapiitm.h" -#include "hbapifs.h" - -#ifdef HB_OS_WIN_32 - -#include - -HB_FUNC( P_INITPORTSPEED ) { - - DCB dcb; - char values[ 20 ]; - - FillMemory( &dcb, sizeof( dcb ), 0 ); - dcb.DCBlength = sizeof( dcb ); - - snprintf( values, sizeof( values ), "%u,%1s,%1u,%1u", hb_parnl( 2 ), hb_parcx( 4 ), hb_parnl( 3 ), hb_parnl( 5 ) ); - - if( BuildCommDCB( values, &dcb ) ) - { - if( SetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb ) ) - { - COMMTIMEOUTS timeouts; - - /* read/write operations return immediatly */ - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = 0; - timeouts.ReadTotalTimeoutConstant = 0; - timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = 0; - - hb_retnl( SetCommTimeouts( ( HANDLE ) hb_parnl( 1 ), &timeouts ) ? 0 : -1 ); - } - else - hb_retnl( -1 ); - } - else - hb_retnl( -1 ); -} - -HB_FUNC( P_READPORT ) -{ - char Buffer[ 512 ]; - DWORD nRead = 0; - OVERLAPPED Overlapped = { 0 }; - BOOL bRet = ReadFile( ( HANDLE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead, &Overlapped ); - - hb_retclen( bRet ? Buffer : NULL, nRead ); -} - -HB_FUNC( P_WRITEPORT ) -{ - DWORD nWritten = 0; - OVERLAPPED Overlapped = { 0 }; - BOOL bRet = WriteFile( ( HANDLE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten, &Overlapped ); - - hb_retnl( bRet ? nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */ -} - -#endif /* HB_OS_WIN_32 */ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Telepathy emulation library + * C low level module for Win32 serial communication + * + * Copyright 2004 - Maurilio Longo + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#define HB_OS_WIN_32_USED + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbapifs.h" + +#ifdef HB_OS_WIN_32 + +#include + +HB_FUNC( P_INITPORTSPEED ) { + + DCB dcb; + char values[ 20 ]; + + FillMemory( &dcb, sizeof( dcb ), 0 ); + dcb.DCBlength = sizeof( dcb ); + + snprintf( values, sizeof( values ), "%u,%1s,%1u,%1u", hb_parnl( 2 ), hb_parcx( 4 ), hb_parnl( 3 ), hb_parnl( 5 ) ); + + if( BuildCommDCB( values, &dcb ) ) + { + if( SetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb ) ) + { + COMMTIMEOUTS timeouts; + + /* read/write operations return immediatly */ + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = 0; + timeouts.ReadTotalTimeoutConstant = 0; + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 0; + + hb_retnl( SetCommTimeouts( ( HANDLE ) hb_parnl( 1 ), &timeouts ) ? 0 : -1 ); + } + else + hb_retnl( -1 ); + } + else + hb_retnl( -1 ); +} + +HB_FUNC( P_READPORT ) +{ + char Buffer[ 512 ]; + DWORD nRead = 0; + OVERLAPPED Overlapped = { 0 }; + BOOL bRet = ReadFile( ( HANDLE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead, &Overlapped ); + + hb_retclen( bRet ? Buffer : NULL, nRead ); +} + +HB_FUNC( P_WRITEPORT ) +{ + DWORD nWritten = 0; + OVERLAPPED Overlapped = { 0 }; + BOOL bRet = WriteFile( ( HANDLE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten, &Overlapped ); + + hb_retnl( bRet ? nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */ +} + +#endif /* HB_OS_WIN_32 */ diff --git a/harbour/contrib/hbziparch/Makefile b/harbour/contrib/hbziparch/Makefile index 72aae450e5..8a9a8fce78 100644 --- a/harbour/contrib/hbziparch/Makefile +++ b/harbour/contrib/hbziparch/Makefile @@ -60,7 +60,7 @@ PRG_SOURCES= \ LIBNAME=hbziparch ifeq ($(HB_ARCHITECTURE),linux) -CFLAGS := $(CFLAGS) -DZIP_ARCHIVE_LNX +C_USR += -DZIP_ARCHIVE_LNX endif include $(TOP)$(ROOT)config/lib.cf diff --git a/harbour/include/hbver.h b/harbour/include/hbver.h index c4203e6957..e85ff551a0 100644 --- a/harbour/include/hbver.h +++ b/harbour/include/hbver.h @@ -59,8 +59,7 @@ #define HB_VER_MINOR 0 /* Minor version number */ #define HB_VER_REVISION 0 /* Revision number */ #define HB_VER_STATUS "RC1" /* Build status */ -#define HB_VERSION 0x010000 /* Three bytes: Major + Minor + -Revision */ +#define HB_VERSION 0x010000 /* Three bytes: Major + Minor + Revision */ /* #include "hb_verbld.h" */ diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index 70852df349..96db597899 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -587,7 +587,7 @@ static void hb_pp_tokenAddNext( PHB_PP_STATE pState, const char * value, ULONG u else if( pState->iBlockState == 2 && HB_PP_TOKEN_TYPE( type ) == HB_PP_TOKEN_COMMA ) pState->iBlockState = 1; - else + else pState->iBlockState = 0; } diff --git a/harbour/source/rtl/valtoexp.prg b/harbour/source/rtl/valtoexp.prg index b210ae1d21..f5fe2eec59 100644 --- a/harbour/source/rtl/valtoexp.prg +++ b/harbour/source/rtl/valtoexp.prg @@ -63,7 +63,7 @@ FUNCTION hb_VALTOEXP( xVal ) cVal := LTRIM( STR( xVal ) ) EXIT CASE "D" - cVal := "0d" + DTOS( xVal ) + cVal := IIF( EMPTY( xVal ), "0d00000000", "0d" + DTOS( xVal ) ) EXIT CASE "L" cVal := IIF( xVal, ".T.", ".F." ) @@ -117,7 +117,7 @@ FUNCTION hb_CSTR( xVal ) CASE "N" RETURN STR( xVal ) CASE "D" - RETURN "0d" + DTOS( xVal ) + RETURN IIF( EMPTY( xVal ), "0d00000000", "0d" + DTOS( xVal ) ) CASE "L" RETURN IIF( xVal, ".T.", ".F." ) CASE "S"