2009-03-01 23:54 UTC+0100 Viktor Szakats (harbour.01 syenar hu)

- contrib/examples/uhttpd/hbmk.bat
  + contrib/examples/uhttpd/uhttpdgd.hbm
  * contrib/examples/uhttpd/uhttpd.prg
  * contrib/examples/uhttpd/readme.txt
    * Added separate GD enabled .hbm file.
    * Remaining hbmk.bat features moved to .prg code and into readme.txt.

  * utils/hbmk2/hbmk2.prg
    + Added support for @ and .hbm parameters inside .hbm files.
      Currently three levels deep nesting in allowed.

  * contrib/xhb/Makefile
  + contrib/xhb/dbf2txt.c
    + Added DBF2TXT() function from xhb.
    ; TODO: RPC support and HB_SERVICE*() API ?
This commit is contained in:
Viktor Szakats
2009-03-01 22:58:28 +00:00
parent 0313662357
commit 1961ff18c2
8 changed files with 356 additions and 88 deletions

View File

@@ -8,6 +8,23 @@
2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
*/
2009-03-01 23:54 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
- contrib/examples/uhttpd/hbmk.bat
+ contrib/examples/uhttpd/uhttpdgd.hbm
* contrib/examples/uhttpd/uhttpd.prg
* contrib/examples/uhttpd/readme.txt
* Added separate GD enabled .hbm file.
* Remaining hbmk.bat features moved to .prg code and into readme.txt.
* utils/hbmk2/hbmk2.prg
+ Added support for @ and .hbm parameters inside .hbm files.
Currently three levels deep nesting in allowed.
* contrib/xhb/Makefile
+ contrib/xhb/dbf2txt.c
+ Added DBF2TXT() function from xhb.
; TODO: RPC support and HB_SERVICE*() API ?
2009-03-01 18:39 UTC+0100 Viktor Szakats (harbour.01 syenar hu)
* contrib/examples/uhttpd/hbmk.bat
* contrib/examples/uhttpd/uhttpd.hbm

View File

@@ -1,75 +0,0 @@
@rem
@rem $Id$
@rem
@echo off
CLS
SET UHTTP_INET_SUPPORT=no
SET UHTTP_INET_DEF=
SET UHTTP_INET_SOCKET=
SET UHTTP_GD_SUPPORT=yes
SET UHTTP_GD_DEF=
SET UHTTP_GD_LIBS=
:PARAM_CHECK
if "%1". == "--without-gd". goto PARAM_GD
if "%1". == "--with-inet". goto PARAM_INET
GOTO GO_ON
:PARAM_GD
SET UHTTP_GD_SUPPORT=no
shift
goto PARAM_CHECK
:PARAM_INET
SET UHTTP_INET_SUPPORT=yes
shift
goto PARAM_CHECK
:GO_ON
echo.
echo.Building uHTTPD server
echo.
if %UHTTP_GD_SUPPORT%.==yes. echo.Lib GD support enabled
if %UHTTP_GD_SUPPORT%.==no. echo.Lib GD support disabled
echo.
if %UHTTP_INET_SUPPORT%.==yes. echo.Harbour socket
if %UHTTP_INET_SUPPORT%.==no. echo.Mindaugas socket
echo.
if %UHTTP_GD_SUPPORT%.==yes. SET UHTTP_GD_DEF=-DGD_SUPPORT
if %UHTTP_GD_SUPPORT%.==yes. SET UHTTP_GD_LIBS=-lhbgd -lbgd
if %UHTTP_INET_SUPPORT%.==yes. SET UHTTP_INET_DEF=-DUSE_HB_INET
if exist uhttpd.exe uhttpd -s
..\..\..\bin\hbmk uhttpd.hbm %1 %2 %3 %4 %UHTTP_GD_DEF% %UHTTP_INET_DEF% %UHTTP_INET_SOCKET% %UHTTP_GD_LIBS%
if errorlevel 1 goto DOERROR
if not exist uhttpd.exe goto :EXIT
if %UHTTP_GD_SUPPORT%.==no. goto BUILD_OK
if not exist bgd.dll goto NOBGD
:BUILD_OK
echo.Build complete.
goto EXIT
:DOERROR
echo.Build error
goto EXIT
:NOBGD
echo.ATTENTION! This program needs bgd.dll
echo.Please download it from:
echo.http://www.libgd.org/releases/gd-latest-win32.zip
:EXIT
SET UHTTP_INET_SUPPORT=
SET UHTTP_INET_DEF=
SET UHTTP_INET_SOCKET=
SET UHTTP_GD_SUPPORT=
SET UHTTP_GD_DEF=
SET UHTTP_GD_LIBS=

View File

@@ -1,8 +1,16 @@
/*
* $Id$
*/
uHTTPD micro web server
Build it using hbmk*.bat
Parameters accepted: --without-gd (disable Lib GD support)
Build it without GD: ..\..\..\bin\hbmk uhttpd.hbm
Build it with GD: ..\..\..\bin\hbmk uhttpdgd.hbm
[ This one needs bgd.dll. Please download it from:
http://www.libgd.org/releases/gd-latest-win32.zip ]
Add -DUSE_HB_INET to command line if you want to use Harbour's
built-in socket functions.
To see accepted parameters run: uhttpd -?
Parameters can also be defined using uhttpd.ini file.
@@ -14,5 +22,3 @@ http://localhost:8082
to see default index page.
Francesco

View File

@@ -92,14 +92,18 @@
// adding GD support
REQUEST GDIMAGE, GDIMAGECHAR, GDCHART
#define APP_GD_SUPPORT "_GD"
#stdout "Lib GD support enabled"
#else
#define APP_GD_SUPPORT ""
#stdout "Lib GD support disabled"
#endif
#ifdef USE_HB_INET
#define APP_INET_SUPPORT "_INET"
#stdout "Harbour socket"
#else
#define APP_INET_SUPPORT ""
#stdout "Mindaugas socket"
#endif
#define APP_NAME "uhttpd"
@@ -2166,4 +2170,3 @@ STATIC FUNCTION ErrorMessage( oError )
ENDCASE
RETURN cMessage

View File

@@ -0,0 +1,6 @@
#
# $Id$
#
@uhttpd.hbm
-DGD_SUPPORT -lhbgd -lbgd

View File

@@ -7,6 +7,7 @@ ROOT = ../../
LIBNAME=xhb
C_SOURCES=\
dbf2txt.c \
filestat.c \
freadlin.c \
hbcrypt.c \
@@ -40,6 +41,7 @@ PRG_SOURCES=\
xhbcomp.prg \
dbgfx.prg \
sprintf.prg \
regexrpl.prg \
PRG_HEADERS=\
hbcompat.ch \

View File

@@ -0,0 +1,293 @@
/*
* $Id$
*/
/*
* xHarbour Project source code:
* DBF2TXT() function
*
* Copyright 1999 Andi Jahja <andij@aonlippo.co.id>
* 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.
*
*/
#include "hbapi.h"
#include "hbapiitm.h"
#include "hbapirdd.h"
#include "hbapierr.h"
#include "hbapicdp.h"
#include "hbapifs.h"
#include "hbvm.h"
/* Escaping delimited strings. Need to be cleaned/optimized/improved */
static char * hb_strescape( char * szInput, int lLen, char * cDelim )
{
int lCnt = 0;
char * szChr;
char * szEscape;
char * szReturn;
szReturn = szEscape = ( char * ) hb_xgrab( lLen * 2 + 4 );
while( lLen && HB_ISSPACE( szInput[ lLen - 1 ] ) )
lLen--;
szChr = szInput;
while( *szChr && lCnt++ < lLen )
{
if( *szChr == *cDelim )
*szEscape++ = '\\';
*szEscape++ = *szChr++;
}
*szEscape = '\0';
return szReturn;
}
/* Export field values to text file */
#ifndef HB_CDP_SUPPORT_OFF
static BOOL hb_ExportVar( int handle, PHB_ITEM pValue, char * cDelim, PHB_CODEPAGE cdp )
#else
static BOOL hb_ExportVar( int handle, PHB_ITEM pValue, char * cDelim )
#endif
{
switch( hb_itemType( pValue ) )
{
/* a "C" field */
case HB_IT_STRING:
{
char * szStrEsc;
char * szString;
szStrEsc = hb_strescape( hb_itemGetCPtr( pValue ),
hb_itemGetCLen( pValue ), cDelim );
#ifndef HB_CDP_SUPPORT_OFF
if( cdp )
hb_cdpnTranslate( szStrEsc, hb_vmCDP(), cdp, hb_itemGetCLen( pValue ) );
#endif
szString = hb_xstrcpy( NULL, cDelim, szStrEsc, cDelim, NULL );
/* FWrite( handle, szString ) */
hb_fsWriteLarge( handle, ( BYTE * ) szString, strlen( szString ) );
/* Orphaned, get rif off it */
hb_xfree( szStrEsc );
hb_xfree( szString );
break;
}
/* a "D" field */
case HB_IT_DATE:
{
char * szDate = ( char * ) hb_xgrab( 9 );
hb_itemGetDS( pValue, szDate );
hb_fsWriteLarge( handle, (BYTE*) szDate, strlen( szDate ) );
hb_xfree( szDate );
break;
}
/* an "L" field */
case HB_IT_LOGICAL:
{
hb_fsWriteLarge( handle, (BYTE*) ( hb_itemGetL( pValue ) ? "T" : "F" ), 1 );
break;
}
/* an "N" field */
case HB_IT_INTEGER:
case HB_IT_LONG:
case HB_IT_DOUBLE:
{
char *szResult = hb_itemStr( pValue, NULL, NULL );
if( szResult )
{
ULONG ulLen = strlen( szResult );
char * szTrimmed = hb_strLTrim( szResult, &ulLen );
hb_fsWriteLarge( handle, ( BYTE * ) szTrimmed, strlen( szTrimmed ) );
hb_xfree( szResult );
}
break;
}
/* an "M" field or the other, might be a "V" in SixDriver */
default:
/* We do not want MEMO contents */
return FALSE;
}
return TRUE;
}
HB_FUNC( DBF2TEXT )
{
PHB_ITEM pWhile = hb_param( 1, HB_IT_BLOCK );
PHB_ITEM pFor = hb_param( 2, HB_IT_BLOCK );
PHB_ITEM pFields = hb_param( 3, HB_IT_ARRAY );
char * cDelim = hb_parc( 4 );
HB_FHANDLE handle = ( HB_FHANDLE ) hb_parnl( 5 );
BYTE * cSep = ( BYTE * ) hb_parc( 6 );
int nCount = ( int ) hb_parnl( 7 );
#ifndef HB_CDP_SUPPORT_OFF
PHB_CODEPAGE cdp = hb_cdpFind( ( char * ) hb_parc( 8 ) );
#endif
AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
/* Export DBF content to text file */
int iSepLen;
USHORT uiFields = 0;
USHORT ui;
PHB_ITEM pTmp;
BOOL bWriteSep = FALSE;
BOOL bEof = TRUE;
BOOL bBof = TRUE;
BOOL bNoFieldPassed = ( pFields == NULL || hb_arrayLen( pFields ) == 0 );
if( ! pArea )
{
hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, HB_ERR_FUNCNAME );
return;
}
if( ! handle )
{
hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, HB_ERR_FUNCNAME );
return;
}
if( cdp && cdp == hb_vmCDP() )
cdp = NULL;
pTmp = hb_itemNew( NULL );
if( ! cDelim )
cDelim = "\"";
if( cSep )
iSepLen = hb_parclen( 6 );
else
{
cSep = ( BYTE * ) ',';
iSepLen = 1;
}
SELF_FIELDCOUNT( pArea, &uiFields );
while( ( nCount == -1 || nCount > 0 ) &&
( ! pWhile || hb_itemGetL( hb_vmEvalBlock( pWhile ) ) ) )
{
/* While !BOF() .AND. !EOF() */
SELF_EOF( pArea, &bEof );
SELF_BOF( pArea, &bBof );
if( bEof || bBof )
break;
/* For condition is met */
/* if For is NULL, hb__Eval returns TRUE */
if( ! pFor || hb_itemGetL( hb_vmEvalBlock( pFor ) ) )
{
/* User does not request fields, copy all fields */
if( bNoFieldPassed )
{
for( ui = 1; ui <= uiFields; ui ++ )
{
if( bWriteSep )
hb_fsWriteLarge( handle, cSep, iSepLen );
SELF_GETVALUE( pArea, ui, pTmp );
#ifndef HB_CDP_SUPPORT_OFF
bWriteSep = hb_ExportVar( handle, pTmp, cDelim, cdp );
#else
bWriteSep = hb_ExportVar( handle, pTmp, cDelim );
#endif
hb_itemClear( pTmp );
}
}
/* Only requested fields are exported here */
else
{
USHORT uiFieldCopy = ( USHORT ) hb_arrayLen( pFields );
USHORT uiItter;
for( uiItter = 1; uiItter <= uiFieldCopy; uiItter++ )
{
char * szFieldName = hb_arrayGetCPtr( pFields, uiItter );
if( szFieldName )
{
int iPos = hb_rddFieldIndex( pArea, szFieldName );
if( iPos )
{
if( bWriteSep )
hb_fsWriteLarge( handle, cSep, iSepLen );
SELF_GETVALUE( pArea, ( USHORT ) iPos, pTmp );
#ifndef HB_CDP_SUPPORT_OFF
bWriteSep = hb_ExportVar( handle, pTmp, cDelim, cdp );
#else
bWriteSep = hb_ExportVar( handle, pTmp, cDelim );
#endif
hb_itemClear( pTmp );
}
}
}
}
hb_fsWriteLarge( handle, (BYTE*) "\r\n", 2 );
bWriteSep = FALSE;
}
if( nCount != -1 )
nCount-- ;
/* DBSKIP() */
SELF_SKIP( pArea, 1 );
}
/* Writing EOF */
hb_fsWriteLarge( handle, ( BYTE * ) "\x1A", 1 );
hb_itemRelease( pTmp );
}

View File

@@ -260,6 +260,7 @@ FUNCTION Main( ... )
LOCAL lSysLoc
LOCAL cPrefix
LOCAL cPostfix
LOCAL nEmbedLevel
LOCAL lStopAfterHarbour := .F.
LOCAL lStopAfterCComp := .F.
@@ -621,9 +622,11 @@ FUNCTION Main( ... )
FOR EACH cParam IN hb_AParams()
DO CASE
CASE ( Len( cParam ) >= 1 .AND. Left( cParam, 1 ) == "@" )
HBM_Load( aParams, SubStr( cParam, 2 ) ) /* Load parameters from script file */
nEmbedLevel := 1
HBM_Load( aParams, SubStr( cParam, 2 ), @nEmbedLevel ) /* Load parameters from script file */
CASE Lower( FN_ExtGet( cParam ) ) == ".hbm"
HBM_Load( aParams, cParam ) /* Load parameters from script file */
nEmbedLevel := 1
HBM_Load( aParams, cParam, @nEmbedLevel ) /* Load parameters from script file */
OTHERWISE
AAdd( aParams, { cParam, "", 0 } )
ENDCASE
@@ -2492,10 +2495,10 @@ STATIC FUNCTION ValueIsF( cString )
RETURN cString == "no" .OR. ;
cString == "0" /* Compatibility */
STATIC PROCEDURE HBM_Load( aParams, cFileName )
STATIC PROCEDURE HBM_Load( aParams, cFileName, /* @ */ nEmbedLevel )
LOCAL cFile := hb_MemoRead( cFileName )
LOCAL cLine
LOCAL cOption
LOCAL cParam
IF ! hb_osNewLine() == _EOL
cFile := StrTran( cFile, hb_osNewLine(), _EOL )
@@ -2506,10 +2509,23 @@ STATIC PROCEDURE HBM_Load( aParams, cFileName )
FOR EACH cLine IN hb_ATokens( cFile, _EOL )
IF !( Left( cLine, 1 ) == "#" )
FOR EACH cOption IN hb_ATokens( cLine,, .T. )
cOption := StrStripQuote( cOption )
IF ! Empty( cOption )
AAdd( aParams, { cOption, cFileName, cLine:__enumIndex() } )
FOR EACH cParam IN hb_ATokens( cLine,, .T. )
cParam := StrStripQuote( cParam )
IF ! Empty( cParam )
DO CASE
CASE ( Len( cParam ) >= 1 .AND. Left( cParam, 1 ) == "@" )
IF !( SubStr( cParam, 2 ) == cFileName ) .AND. nEmbedLevel < 3
nEmbedLevel++
HBM_Load( aParams, SubStr( cParam, 2 ), @nEmbedLevel ) /* Load parameters from script file */
ENDIF
CASE Lower( FN_ExtGet( cParam ) ) == ".hbm"
IF !( cParam == cFileName ) .AND. nEmbedLevel < 3
nEmbedLevel++
HBM_Load( aParams, cParam, @nEmbedLevel ) /* Load parameters from script file */
ENDIF
OTHERWISE
AAdd( aParams, { cParam, cFileName, cLine:__enumIndex() } )
ENDCASE
ENDIF
NEXT
ENDIF