From fd10cf24fb61b829085e8b08e8341d1011e8e3ac Mon Sep 17 00:00:00 2001 From: Eddie Runia Date: Tue, 15 Jun 1999 22:03:11 +0000 Subject: [PATCH] see changelog --- harbour/ChangeLog | 5 + harbour/tests/working/hscript/bld32exe.bat | 27 +++ harbour/tests/working/hscript/dir.hs | 46 +++++ harbour/tests/working/hscript/hb32.bat | 10 ++ harbour/tests/working/hscript/hello.hs | 38 +++++ harbour/tests/working/hscript/hscript.prg | 187 +++++++++++++++++++++ harbour/tests/working/hscript/makehs.bat | 2 + harbour/tests/working/hscript/makehtm.bat | 32 ++++ harbour/tests/working/hscript/multiply.hs | 49 ++++++ harbour/tests/working/hscript/readme.txt | 96 +++++++++++ 10 files changed, 492 insertions(+) create mode 100644 harbour/tests/working/hscript/bld32exe.bat create mode 100644 harbour/tests/working/hscript/dir.hs create mode 100644 harbour/tests/working/hscript/hb32.bat create mode 100644 harbour/tests/working/hscript/hello.hs create mode 100644 harbour/tests/working/hscript/hscript.prg create mode 100644 harbour/tests/working/hscript/makehs.bat create mode 100644 harbour/tests/working/hscript/makehtm.bat create mode 100644 harbour/tests/working/hscript/multiply.hs create mode 100644 harbour/tests/working/hscript/readme.txt diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 14373bf932..480471e732 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +19990615-23:00 CET Felipe Coury + + tests/working/hscript/bld32exe.bat; dir.hs; hb32.bat; hello.hs; + hscript.prg; makehs.prg; makehtm.prg; multiply.hs readme.txt + First release of hScript added + 19990615-21:00 CET Jose Lalin / Eddie Runia + source/rtl/natmsg/msgbas.c * source/rtl/msgxxx.c diff --git a/harbour/tests/working/hscript/bld32exe.bat b/harbour/tests/working/hscript/bld32exe.bat new file mode 100644 index 0000000000..a67c99c25c --- /dev/null +++ b/harbour/tests/working/hscript/bld32exe.bat @@ -0,0 +1,27 @@ +@echo off + +IF A%1 == A GOTO :SINTAX +IF A%2 == A GOTO :NOOUTPUT + +echo -O2 -e%2.exe -I..\..\..\include ..\..\..\source\vm\hvm.c %1.c > b32.bc +echo ..\..\..\libs\b32\harbour.lib ..\..\..\libs\b32\terminal.lib >> b32.bc +echo ..\..\..\libs\b32\hbgt.lib >> b32.bc +bcc32 @b32.bc +del b32.bc +GOTO :END + +:NOOUTPUT +echo -O2 -e%1.exe -I..\..\..\include ..\..\..\source\vm\hvm.c %1.c > b32.bc +echo ..\..\..\libs\b32\harbour.lib ..\..\..\libs\b32\terminal.lib >> b32.bc +echo ..\..\..\libs\b32\hbgt.lib >> b32.bc +echo runner.obj >> b32.bc +bcc32 @b32.bc +del b32.bc +GOTO :END + +:SINTAX +ECHO syntax: BuildExe Harbour_Output_Filename [Exe_Output_Filename] +ECHO Use Harbour_Output_Filename and Exe_Output_Filename without extensions +ECHO\ + +:END diff --git a/harbour/tests/working/hscript/dir.hs b/harbour/tests/working/hscript/dir.hs new file mode 100644 index 0000000000..fc5e43bda3 --- /dev/null +++ b/harbour/tests/working/hscript/dir.hs @@ -0,0 +1,46 @@ +<% +FUNCTION Main() + + LOCAL aDir := directory( "c:\*.*" ) + LOCAL i + + IF !empty( GetEnv( "SERVER_NAME" ) ) + qqOut( "HTTP/1.0 200 OK" ) + qOut( "CONTENT-TYPE: TEXT/HTML" ) + qOut( "" ) + ENDIF + + aSort( aDir,,, { |x, y| x[1] < y[1] } ) +%> + +dir.hs - HarourScript demo of active context + + + + + + + + + + +<% + FOR i := 1 TO len( aDir ) +%> + + + + + + + +<% + NEXT +%> +
File NameSizeDateTimeAttributes
<% qOut( aDir[i,1] ) %><% qOut( aDir[i,2] ) %><% qOut( aDir[i,3] ) %><% qOut( aDir[i,4] ) %><% qOut( aDir[i,5] ) %>
+ + +<% + + RETURN( NIL ) +%> diff --git a/harbour/tests/working/hscript/hb32.bat b/harbour/tests/working/hscript/hb32.bat new file mode 100644 index 0000000000..865cd15c70 --- /dev/null +++ b/harbour/tests/working/hscript/hb32.bat @@ -0,0 +1,10 @@ +@echo off + +REM From .PRG to .C = Harbour +..\..\..\bin\harbour %1.prg /n /i..\..\..\include +if errorlevel 1 goto end + +REM From .C to .EXE = BuildExe +call BLD32EXE %1 %2 + +:end diff --git a/harbour/tests/working/hscript/hello.hs b/harbour/tests/working/hscript/hello.hs new file mode 100644 index 0000000000..8a0a384dd2 --- /dev/null +++ b/harbour/tests/working/hscript/hello.hs @@ -0,0 +1,38 @@ +<% +/* +* +* hello.hs +* Famous "Hello World"! +* +*/ + +FUNCTION Main() + + // Add content-type parameter if using active page on a Web Server + IF !empty( GetEnv( "SERVER_NAME" ) ) + qqOut( "HTTP/1.0 200 OK" ) + qOut( "CONTENT-TYPE: TEXT/HTML" ) + qOut( "" ) + ENDIF + +%> + + +Hello world! + + + +<% + // Now saying hello to the world in 3 different ways: + // 1. Pure harbour: + qOut( "

Hello world!

" ) + + // 2. Hybrid harbour-html: +%> +

<% qOut( "Hello world!" ) %>

+<% + // 3. Pure html: +%> +

Hello world!

+ + diff --git a/harbour/tests/working/hscript/hscript.prg b/harbour/tests/working/hscript/hscript.prg new file mode 100644 index 0000000000..9622c5d43f --- /dev/null +++ b/harbour/tests/working/hscript/hscript.prg @@ -0,0 +1,187 @@ +/* +* +* HScript.PRG +* HarbourScript translator +* +* 1999/06/13 First implementation. +* +**/ + +#include "CGI.ch" +#define IF_BUFFER 65535 +#define NewLine chr(13)+chr(10) + +FUNCTION Main( cScript ) + + LOCAL aHRSHandle := {} // Handle for script lines + LOCAL aResult := {} // Handle for transl'd lines + LOCAL cLocation := {} // Location of scripts + LOCAL cHarbourDir := GetEnv( "HARBOUR_DIR" ) // Harbour.exe dir with '\' + LOCAL cHost := strtran( alltrim( ; // Random (not et al) + str( seconds() ) ), '.' ) // file name + LOCAL cScriptName, cFile, cRes, cLine + LOCAL hFile, nStartPos, nPos, i, lScriptFlag + + WHILE .t. + + IF empty( GetEnv( "SERVER_NAME" ) ) + cScriptName := cScript + cLocation := GetEnv( "PATH_TRANSLATED" ) + ; + strtran( GetEnv( "SCRIPT_NAME" ), "/", "\" ) + cLocation := substr( cLocation, 1, rat( "\", cLocation ) ) + cHarbourDir := cLocation + + ELSE + cScriptName := GetEnv( "QUERY_STRING" ) + IF at( "=", cScriptName ) != 0 + cScriptName := ParseString( cScriptName, "=", 2 ) + ENDIF + + ENDIF + + IF empty( cScriptName ) + IF !empty( GetEnv( "SERVER_NAME" ) ) + qqOut( "content-type: text/html" ) + qOut( "" ) + qOut( "

Server Error

" ) + qOut( "Must specify scriptname using hscript.exe?script=" ) + qOut( "" ) + + ELSE + qOut( "Please give .hs name" ) + + ENDIF + + EXIT + ENDIF + + // Script not found + IF !file( cScriptName ) + IF !empty( GetEnv( "SERVER_NAME" ) ) + qqOut( "CONTENT-TYPE: text/html" ) + ENDIF + qOut( "

Server Error

Script not found: " + cScriptName ) + EXIT + ENDIF + + // Reads all lines from script -> aHRBHandle + hFile := fOpen( cScriptName, 0 ) + cFile := space( IF_BUFFER ) + + cRes := "" + DO WHILE (nPos := fRead( hFile, @cFile, IF_BUFFER )) > 0 + + cFile := left( cFile, nPos ) + cRes += cFile + cFile := space( IF_BUFFER ) + + ENDDO + + fClose( cFile ) + + // "Break" infile into lines + nStartPos := 1 + FOR i := 1 TO len( cRes ) + + IF substr( cRes, i, 1 ) == chr(13) + + IF i = (nStartPos + 1) + aAdd( aHRSHandle, "" ) + ELSE + aAdd( aHRSHandle, strtran( ; + substr( cRes, nStartPos, i - nStartPos ), chr(10), "" ) ) + ENDIF + + nStartPos := i + 1 + ENDIF + + NEXT + + // Translate script to pure HTML + /* TODO: Add support for lines like "<% something" and "something %>" */ + nStartPos := 1 + lScriptFlag := .f. + + FOR i := 1 TO len( aHRSHandle ) + cLine := aHRSHandle[i] + + IF !lScriptFlag + nPos := at( "<%", cLine ) // Are we in script? + + IF nPos == 0 // No, use qout to + aadd( aResult, "qOut( '" + cLine + "' )" ) // write HTML code + + ELSE // Yes. + IF at( "%>", cLine ) != 0 // Is it inline? + aadd( aResult, "qOut( '" + ; // Yes, translate + substr( cLine, 1, nPos-1 ) + ; // only HTML to + "' ) " + NewLine + ; // qOut( ) + substr( cLine, nPos + 2, ; + at( "%>", cLine ) - ; + (nPos + 2) ) + ; + NewLine + "qOut( '" + ; + substr( cLine, at( "%>", cLine ) + ; + 2 ) + "' )" ) + ELSE // No. + lScriptFlag := .t. // Change the flag + aadd( aResult, "" ) // Add blank line + ENDIF + ENDIF + ELSE + IF at( "%>", cLine ) == 0 // Is this line EOS? - End of Script + aadd( aResult, cLine ) // No, add + ELSE // Yes, + lScriptFlag := .f. // Change the flag + aadd( aResult, "" ) // Add blank line + ENDIF + ENDIF + NEXT + + // Creates the temporary PRG + cFile := cLocation + cHost + ".prg" // Output file name + hFile := fCreate( cFile ) + FOR i := 1 TO len( aResult ) + fWrite( hFile, aResult[i] + chr(13)+chr(10) ) + NEXT + fClose( hFile ) + + // Creates the temporary HRB, erases the PRG + __Run( cHarbourDir + "harbour.exe " + cFile + " /q /n /gHRB" ) + fErase( cFile ) + + // Runs using Tugboat + cFile := strtran( upper( cFile ), ".PRG", ".HRB" ) + HB_Run( cFile ) + // Erases the HRB + fErase( cFile ) + + // That's all, folks! + EXIT + + ENDDO + + RETURN( NIL ) + +FUNCTION ParseString( cString, cDelim, nRet ) + + LOCAL cBuf, aElem, nPosFim, nSize, i + + nSize := len( cString ) - len( StrTran( cString, cDelim, '' ) ) + 1 + aElem := array( nSize ) + + cBuf := cString + i := 1 + FOR i := 1 TO nSize + nPosFim := at( cDelim, cBuf ) + + IF nPosFim > 0 + aElem[i] := substr( cBuf, 1, nPosFim - 1 ) + ELSE + aElem[i] := cBuf + ENDIF + + cBuf := substr( cBuf, nPosFim + 1, len( cBuf ) ) + + NEXT i + + RETURN( aElem[ nRet ] ) diff --git a/harbour/tests/working/hscript/makehs.bat b/harbour/tests/working/hscript/makehs.bat new file mode 100644 index 0000000000..eaf43e6a7b --- /dev/null +++ b/harbour/tests/working/hscript/makehs.bat @@ -0,0 +1,2 @@ +@echo off +call hb32 hscript \ No newline at end of file diff --git a/harbour/tests/working/hscript/makehtm.bat b/harbour/tests/working/hscript/makehtm.bat new file mode 100644 index 0000000000..f0f37e41b0 --- /dev/null +++ b/harbour/tests/working/hscript/makehtm.bat @@ -0,0 +1,32 @@ +@echo off +IF NOT EXIST hscript.exe GOTO :missing + +:start +SET HARBOUR_DIR=\HARBOUR\BIN\ + +hscript hello.hs >hello.htm +hscript multiply.hs >multiply.htm +hscript dir.hs >dir.htm + +cls +echo Ready to go! +echo\ +echo If you're under W95/98 try: +echo\ +echo start hello.htm +echo -or- +echo start multiply.htm +echo -or- +echo start dir.htm + +goto end + +:missing +echo Missing hscript.exe +echo\ +echo Press any key to build it or Ctrl+C to quit... +pause>nul +call makehs +goto :start + +:end diff --git a/harbour/tests/working/hscript/multiply.hs b/harbour/tests/working/hscript/multiply.hs new file mode 100644 index 0000000000..9fb57aca91 --- /dev/null +++ b/harbour/tests/working/hscript/multiply.hs @@ -0,0 +1,49 @@ +<% +/* +* +* multiply.hs +* HarbourScript Test +* +*/ + +FUNCTION Main() + + LOCAL i, j + + IF !empty( GetEnv( "SERVER_NAME" ) ) + qqOut( "HTTP/1.0 200 OK" ) + qOut( "CONTENT-TYPE: TEXT/HTML" ) + qOut( "" ) + ENDIF +%> + + +Testing script + + +

<% qOut( "Teste de HarbourScript!" ) %>

+ + +<% + FOR i := 1 TO 10 +%> + + +<% + FOR j := 1 TO 10 +%> + + + + +<% + NEXT +%> +
<% qOut( str( i, 2 ) + " x " + str( j, 2 ) ) %><% qOut( i*j ) %>
+
+<% + NEXT +%> + + + diff --git a/harbour/tests/working/hscript/readme.txt b/harbour/tests/working/hscript/readme.txt new file mode 100644 index 0000000000..2b6940db2e --- /dev/null +++ b/harbour/tests/working/hscript/readme.txt @@ -0,0 +1,96 @@ +WARNING +------- + +This document has serious bugs related to English Language. +I take no responsabilities for any misinformation in any form. + + + +HarbourScript Alfa Edition +-------------------------- + +Inside this zip file you will find HarbourScript package. This +should be unzipped to TESTS\WORKING\HSCRIPT directory in order +to work w/o any changes. + +To make the HarbourScript Translator, hscript.exe, use MAKEHS.BAT. +If you are going to test offline, there's no need to make it, +it will be done automatically for you (Batch Power). To test it, +you'll have the following options: + + +Testing HarbourScript using MS-Personal Web Server +-------------------------------------------------- + +(and maybe IIS 3.0+ too!) + +1. Copy hscript.exe and harbour.exe to your cgi-bin directory +(or any other with Scripting allowed) + +2. Copy all the scripts that you want to the same directory + +3. You can now test Harbour Script using +http://localhost/cgi-bin/hscript?script=