From 4ab21df05cd4ad58f03b78f07ffd34873a77bd53 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 27 Jan 2011 13:30:44 +0000 Subject: [PATCH] 2011-01-27 14:30 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbnetio/utils/hbnetio/hbnetio.hbp * contrib/hbnetio/utils/hbnetio/hbnetioc.hbp * contrib/hbnetio/utils/hbnetio/netiosrv.prg + contrib/hbnetio/utils/hbnetio/netiocon.prg - contrib/hbnetio/utils/hbnetio/netiocui.prg + contrib/hbnetio/utils/hbnetio/netiocmd.prg + Split netiocui.prg into cmdline tool and console logic. The latter is now used by both the daemon tool and cmdline tool. --- harbour/ChangeLog | 11 + .../contrib/hbnetio/utils/hbnetio/hbnetio.hbp | 4 +- .../hbnetio/utils/hbnetio/hbnetioc.hbp | 3 +- .../hbnetio/utils/hbnetio/netiocmd.prg | 95 ++++++++ .../hbnetio/{netiocui.prg => netiocon.prg} | 220 ++++++------------ .../hbnetio/utils/hbnetio/netiosrv.prg | 2 +- 6 files changed, 185 insertions(+), 150 deletions(-) create mode 100644 harbour/contrib/hbnetio/utils/hbnetio/netiocmd.prg rename harbour/contrib/hbnetio/utils/hbnetio/{netiocui.prg => netiocon.prg} (81%) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 274f4ed4cc..f1f526293d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,17 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-27 14:30 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbnetio/utils/hbnetio/hbnetio.hbp + * contrib/hbnetio/utils/hbnetio/hbnetioc.hbp + * contrib/hbnetio/utils/hbnetio/netiosrv.prg + + contrib/hbnetio/utils/hbnetio/netiocon.prg + - contrib/hbnetio/utils/hbnetio/netiocui.prg + + contrib/hbnetio/utils/hbnetio/netiocmd.prg + + Split netiocui.prg into cmdline tool and + console logic. The latter is now used by both + the daemon tool and cmdline tool. + 2011-01-27 13:55 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbplist - contrib/hbnetio/utils/netiosrq diff --git a/harbour/contrib/hbnetio/utils/hbnetio/hbnetio.hbp b/harbour/contrib/hbnetio/utils/hbnetio/hbnetio.hbp index 5e5e3d5f11..6d787640ec 100644 --- a/harbour/contrib/hbnetio/utils/hbnetio/hbnetio.hbp +++ b/harbour/contrib/hbnetio/utils/hbnetio/hbnetio.hbp @@ -9,10 +9,8 @@ -o${hb_name} --D_CONSOLEUI_EMBEDDED - netiosrv.prg -netiocui.prg +netiocon.prg -ldflag={allmsvc}-nxcompat -ldflag={allmsvc}-dynamicbase diff --git a/harbour/contrib/hbnetio/utils/hbnetio/hbnetioc.hbp b/harbour/contrib/hbnetio/utils/hbnetio/hbnetioc.hbp index fcf01c3b05..6e3c43e635 100644 --- a/harbour/contrib/hbnetio/utils/hbnetio/hbnetioc.hbp +++ b/harbour/contrib/hbnetio/utils/hbnetio/hbnetioc.hbp @@ -8,4 +8,5 @@ -o${hb_name} -netiocui.prg +netiocmd.prg +netiocon.prg diff --git a/harbour/contrib/hbnetio/utils/hbnetio/netiocmd.prg b/harbour/contrib/hbnetio/utils/hbnetio/netiocmd.prg new file mode 100644 index 0000000000..d7c7295468 --- /dev/null +++ b/harbour/contrib/hbnetio/utils/hbnetio/netiocmd.prg @@ -0,0 +1,95 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Harbour NETIO server management cmdline tool + * + * Copyright 2009-2011 Viktor Szakats (harbour.01 syenar.hu) + * www - http://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 of the License, 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#define _NETIOMGM_IPV4_DEF "127.0.0.1" +#define _NETIOMGM_PORT_DEF 2940 + +PROCEDURE Main( ... ) + LOCAL cParam + + LOCAL cIP := _NETIOMGM_IPV4_DEF + LOCAL nPort := _NETIOMGM_PORT_DEF + LOCAL cPassword := "" + + SET DATE ANSI + SET CENTURY ON + SET CONFIRM ON + SET SCOREBOARD OFF + + HB_Logo() + + FOR EACH cParam IN { ... } + DO CASE + CASE Lower( Left( cParam, 6 ) ) == "-addr=" + hbnetiocon_IPPortSplit( SubStr( cParam, 7 ), @cIP, @nPort ) + IF Empty( nPort ) + nPort := _NETIOMGM_PORT_DEF + ENDIF + CASE Lower( Left( cParam, 6 ) ) == "-pass=" + cPassword := SubStr( cParam, 7 ) + hb_StrClear( @cParam ) + CASE Lower( cParam ) == "--version" + RETURN + CASE Lower( cParam ) == "-help" .OR. ; + Lower( cParam ) == "--help" + HB_Usage() + RETURN + OTHERWISE + OutStd( "Warning: Unkown parameter ignored: " + cParam + hb_eol() ) + ENDCASE + NEXT + + hbnetiocon_cmdUI( cIP, nPort, cPassword ) + + RETURN + +STATIC PROCEDURE HB_Logo() + + OutStd( "Harbour NETIO Server Management Console " + StrTran( Version(), "Harbour " ) + hb_eol() +; + "Copyright (c) 2009-2011, Viktor Szakats" + hb_eol() + ; + "http://harbour-project.org/" + hb_eol() +; + hb_eol() ) + + RETURN + +STATIC PROCEDURE HB_Usage() + + OutStd( "Syntax:" , hb_eol() ) + OutStd( hb_eol() ) + OutStd( " netiocui [options]" , hb_eol() ) + OutStd( hb_eol() ) + OutStd( "Options:" , hb_eol() ) + OutStd( hb_eol() ) + OutStd( " -addr= connect to netio server on IPv4 address " , hb_eol() ) + OutStd( hb_StrFormat( " Default: %1$s:%2$d", _NETIOMGM_IPV4_DEF, _NETIOMGM_PORT_DEF ) , hb_eol() ) + OutStd( " -pass= connect to netio server with password" , hb_eol() ) + OutStd( hb_eol() ) + OutStd( " --version display version header only" , hb_eol() ) + OutStd( " -help|--help this help" , hb_eol() ) + + RETURN diff --git a/harbour/contrib/hbnetio/utils/hbnetio/netiocui.prg b/harbour/contrib/hbnetio/utils/hbnetio/netiocon.prg similarity index 81% rename from harbour/contrib/hbnetio/utils/hbnetio/netiocui.prg rename to harbour/contrib/hbnetio/utils/hbnetio/netiocon.prg index 7da90f9d5c..0f50447085 100644 --- a/harbour/contrib/hbnetio/utils/hbnetio/netiocui.prg +++ b/harbour/contrib/hbnetio/utils/hbnetio/netiocon.prg @@ -18,133 +18,7 @@ #include "hbgtinfo.ch" -#define _NETIOMGM_IPV4_DEF "127.0.0.1" -#define _NETIOMGM_PORT_DEF 2940 - -#if ! defined( _CONSOLEUI_EMBEDDED ) - -PROCEDURE Main( ... ) - LOCAL cParam - - LOCAL cIP := _NETIOMGM_IPV4_DEF - LOCAL nPort := _NETIOMGM_PORT_DEF - LOCAL cPassword := "" - - SET DATE ANSI - SET CENTURY ON - SET CONFIRM ON - SET SCOREBOARD OFF - - HB_Logo() - - FOR EACH cParam IN { ... } - DO CASE - CASE Lower( Left( cParam, 6 ) ) == "-addr=" - IPPortSplit( SubStr( cParam, 7 ), @cIP, @nPort ) - IF Empty( nPort ) - nPort := _NETIOMGM_PORT_DEF - ENDIF - CASE Lower( Left( cParam, 6 ) ) == "-pass=" - cPassword := SubStr( cParam, 7 ) - hb_StrClear( @cParam ) - CASE Lower( cParam ) == "--version" - RETURN - CASE Lower( cParam ) == "-help" .OR. ; - Lower( cParam ) == "--help" - HB_Usage() - RETURN - OTHERWISE - OutStd( "Warning: Unkown parameter ignored: " + cParam + hb_eol() ) - ENDCASE - NEXT - - netiosrv_cmdUI( cIP, nPort, cPassword ) - - RETURN - -STATIC PROCEDURE HB_Logo() - - OutStd( "Harbour NETIO Server Management Console " + StrTran( Version(), "Harbour " ) + hb_eol() +; - "Copyright (c) 2009-2011, Viktor Szakats" + hb_eol() + ; - "http://harbour-project.org/" + hb_eol() +; - hb_eol() ) - - RETURN - -STATIC PROCEDURE HB_Usage() - - OutStd( "Syntax:" , hb_eol() ) - OutStd( hb_eol() ) - OutStd( " netiocui [options]" , hb_eol() ) - OutStd( hb_eol() ) - OutStd( "Options:" , hb_eol() ) - OutStd( hb_eol() ) - OutStd( " -addr= connect to netio server on IPv4 address " , hb_eol() ) - OutStd( hb_StrFormat( " Default: %1$s:%2$d", _NETIOMGM_IPV4_DEF, _NETIOMGM_PORT_DEF ) , hb_eol() ) - OutStd( " -pass= connect to netio server with password" , hb_eol() ) - OutStd( hb_eol() ) - OutStd( " --version display version header only" , hb_eol() ) - OutStd( " -help|--help this help" , hb_eol() ) - - RETURN - -#endif - -STATIC PROCEDURE cmdHelp( hCommands ) - LOCAL aTexts := {} - LOCAL n, c, m - - m := 0 - hb_HEval( hCommands, {| k, l | m := Max( m, Len( k + iif( Empty( l[ 1 ] ), "", " " + l[ 1 ] ) ) ) } ) - - AAdd( aTexts, "Commands:" ) - - /* Processing commands */ - FOR EACH n IN hCommands - AAdd( aTexts, " " + PadR( n:__enumKey() + iif( Empty( n[ 1 ] ), "", " " + n[ 1 ] ), m ) + " - " + n[ 2 ] ) - NEXT - - ASort( aTexts, 2 ) - - AAdd( aTexts, "" ) - AAdd( aTexts, "Keyboard shortcuts:" ) - AAdd( aTexts, PadR( " ", m ) + " - Move up on historic list." ) - AAdd( aTexts, PadR( " ", m ) + " - Move down on historic list." ) - AAdd( aTexts, PadR( " ", m ) + " - Complete command." ) - AAdd( aTexts, PadR( " ", m ) + " - Paste from clipboard." ) - - c := 0 - m := MaxRow() - - FOR EACH n IN aTexts - QQOut( n, hb_eol() ) - - IF ++c == m - c := 0 - QQOut( "Press any key to continue..." ) - Inkey( 0 ) - - Scroll( Row(), 0, Row(), MaxCol(), 0 ) - SetPos( Row(), 0 ) - ENDIF - NEXT - - RETURN - -STATIC FUNCTION netiosrv_clientinfo() - LOCAL hInfo := { => } - - hb_hKeepOrder( hInfo, .T. ) - - hInfo[ "OS()" ] := OS() - hInfo[ "Version()" ] := Version() - hInfo[ "hb_Compiler()" ] := hb_Compiler() - hInfo[ "NetName()" ] := NetName() - hInfo[ "hb_UserName()" ] := hb_UserName() - - RETURN hInfo - -PROCEDURE netiosrv_cmdUI( cIP, nPort, cPassword ) +PROCEDURE hbnetiocon_cmdUI( cIP, nPort, cPassword ) LOCAL GetList := {} LOCAL hCommands LOCAL nSavedRow @@ -283,6 +157,21 @@ PROCEDURE netiosrv_cmdUI( cIP, nPort, cPassword ) RETURN +PROCEDURE hbnetiocon_IPPortSplit( cAddr, /* @ */ cIP, /* @ */ nPort ) + LOCAL tmp + + IF ! Empty( cAddr ) + cIP := cAddr + IF ( tmp := At( ":", cIP ) ) > 0 + nPort := Val( SubStr( cIP, tmp + Len( ":" ) ) ) + cIP := Left( cIP, tmp - 1 ) + ELSE + nPort := NIL + ENDIF + ENDIF + + RETURN + /* connect to the server */ STATIC FUNCTION ConnectLow( cIP, nPort, cPassword ) LOCAL pConnection @@ -294,7 +183,7 @@ STATIC FUNCTION ConnectLow( cIP, nPort, cPassword ) IF ! Empty( pConnection ) - netio_funcexec( pConnection, "hbnetiomgm_setclientinfo", netiosrv_clientinfo() ) + netio_funcexec( pConnection, "hbnetiomgm_setclientinfo", MyClientInfo() ) netio_OpenItemStream( pConnection, "hbnetiomgm_cargo", "netiocui" ) QQOut( "Connected.", hb_eol() ) @@ -304,6 +193,19 @@ STATIC FUNCTION ConnectLow( cIP, nPort, cPassword ) RETURN pConnection +STATIC FUNCTION MyClientInfo() + LOCAL hInfo := { => } + + hb_hKeepOrder( hInfo, .T. ) + + hInfo[ "OS()" ] := OS() + hInfo[ "Version()" ] := Version() + hInfo[ "hb_Compiler()" ] := hb_Compiler() + hInfo[ "NetName()" ] := NetName() + hInfo[ "hb_UserName()" ] := hb_UserName() + + RETURN hInfo + STATIC FUNCTION GetPassword() LOCAL GetList := {} LOCAL cPassword := Space( 128 ) @@ -355,21 +257,6 @@ STATIC PROCEDURE CompleteCmd( cCommand, hCommands ) RETURN -STATIC PROCEDURE IPPortSplit( cAddr, /* @ */ cIP, /* @ */ nPort ) - LOCAL tmp - - IF ! Empty( cAddr ) - cIP := cAddr - IF ( tmp := At( ":", cIP ) ) > 0 - nPort := Val( SubStr( cIP, tmp + Len( ":" ) ) ) - cIP := Left( cIP, tmp - 1 ) - ELSE - nPort := NIL - ENDIF - ENDIF - - RETURN - STATIC FUNCTION XToStrX( xValue ) LOCAL cType := ValType( xValue ) @@ -427,18 +314,61 @@ STATIC FUNCTION XToStrX( xValue ) /* Commands */ +STATIC PROCEDURE cmdHelp( hCommands ) + LOCAL aTexts := {} + LOCAL n, c, m + + m := 0 + hb_HEval( hCommands, {| k, l | m := Max( m, Len( k + iif( Empty( l[ 1 ] ), "", " " + l[ 1 ] ) ) ) } ) + + AAdd( aTexts, "Commands:" ) + + /* Processing commands */ + FOR EACH n IN hCommands + AAdd( aTexts, " " + PadR( n:__enumKey() + iif( Empty( n[ 1 ] ), "", " " + n[ 1 ] ), m ) + " - " + n[ 2 ] ) + NEXT + + ASort( aTexts, 2 ) + + AAdd( aTexts, "" ) + AAdd( aTexts, "Keyboard shortcuts:" ) + AAdd( aTexts, PadR( " ", m ) + " - Move up on historic list." ) + AAdd( aTexts, PadR( " ", m ) + " - Move down on historic list." ) + AAdd( aTexts, PadR( " ", m ) + " - Complete command." ) + AAdd( aTexts, PadR( " ", m ) + " - Paste from clipboard." ) + + c := 0 + m := MaxRow() + + FOR EACH n IN aTexts + QQOut( n, hb_eol() ) + + IF ++c == m + c := 0 + QQOut( "Press any key to continue..." ) + Inkey( 0 ) + + Scroll( Row(), 0, Row(), MaxCol(), 0 ) + SetPos( Row(), 0 ) + ENDIF + NEXT + + RETURN + STATIC PROCEDURE cmdConnect( cCommand, /* @ */ pConnection, /* @ */ cIP, /* @ */ nPort ) LOCAL aToken LOCAL cPassword + LOCAL nPortOld IF Empty( pConnection ) aToken := hb_ATokens( cCommand, " " ) IF Len( aToken ) >= 2 - IPPortSplit( aToken[ 2 ], @cIP, @nPort ) + nPortOld := nPort + hbnetiocon_IPPortSplit( aToken[ 2 ], @cIP, @nPort ) IF Empty( nPort ) - nPort := _NETIOMGM_PORT_DEF + nPort := nPortOld ENDIF ENDIF IF Len( aToken ) >= 3 diff --git a/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg b/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg index c8ddbbf749..cc8ae21dbc 100644 --- a/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg +++ b/harbour/contrib/hbnetio/utils/hbnetio/netiosrv.prg @@ -216,7 +216,7 @@ PROCEDURE Main( ... ) OutStd( "Warning: Cannot start server management." + hb_eol() ) ELSE IF lUI - hb_threadDetach( hb_threadStart( {|| netiosrv_cmdUI( netiomgm[ _NETIOSRV_cIFAddr ], netiomgm[ _NETIOSRV_nPort ], cPasswordManagement ) } ) ) + hb_threadDetach( hb_threadStart( {|| hbnetiocon_cmdUI( netiomgm[ _NETIOSRV_cIFAddr ], netiomgm[ _NETIOSRV_nPort ], cPasswordManagement ) } ) ) ENDIF ENDIF ENDIF