From 416ae665b41a950e7d8b334f8085a2512a630e98 Mon Sep 17 00:00:00 2001 From: Eddie Runia Date: Thu, 24 Jun 1999 18:24:35 +0000 Subject: [PATCH] see changelog --- harbour/ChangeLog | 7 ++ harbour/tests/working/hscript/hscript.prg | 144 +++++++++++----------- harbour/tests/working/hscript/readme.txt | 11 -- harbour/tests/working/hscript/ugly.hs | 11 ++ 4 files changed, 87 insertions(+), 86 deletions(-) create mode 100644 harbour/tests/working/hscript/ugly.hs diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 03ae4bd706..7d8fc9407d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,10 @@ +19990624-19:17 CET Felipe Coury + + tests/working/hscript/ugly.hs + additional test file + * tests/working/hscript/hscript.prg + * tests/working/hscript/readme.txt + new version + Thu Jun 24 12:25:30 1999 Gonzalo A. Diethelm * include/Makefile: diff --git a/harbour/tests/working/hscript/hscript.prg b/harbour/tests/working/hscript/hscript.prg index fe6a10f068..46a9364470 100644 --- a/harbour/tests/working/hscript/hscript.prg +++ b/harbour/tests/working/hscript/hscript.prg @@ -1,9 +1,10 @@ /* * * HScript.PRG -* HarbourScript translator +* HarbourScript translation engine * * 1999/06/13 First implementation. +* 1999/06/24 Enhanced tag matching routines. * **/ @@ -16,11 +17,11 @@ 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 cHarbourDir := GetEnv( "HARBOURDIR" ) // 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 + LOCAL cScriptName, cFile, cLine, cTrans, c + LOCAL hFile, i, lOpen, nLen WHILE .t. @@ -64,81 +65,74 @@ FUNCTION Main( cScript ) EXIT ENDIF - // Reads all lines from script -> aHRBHandle - hFile := fOpen( cScriptName, 0 ) - cFile := space( IF_BUFFER ) + lOpen := .f. + hb_fUse( cScriptName ) + WHILE !hb_fEof() - cRes := "" - DO WHILE (nPos := fRead( hFile, @cFile, IF_BUFFER )) > 0 + cLine := alltrim( hb_fReadLn() ) + cTrans := "" + nLen := len( cLine ) - cFile := left( cFile, nPos ) - cRes += cFile - cFile := space( IF_BUFFER ) + IF lOpen + cTrans += "qOut( '" + ENDIF + + FOR i := 1 TO nLen + + c := substr( cLine, i, 1 ) + + IF c = "%" .AND. substr( cLine, i + 1, 1 ) = ">" + IF lOpen + // Error - Already in htm mode + + ELSE + // Abre script + IF i > 1 + //cTrans += " ; " + cTrans += NewLine + ENDIF + IF i + 1 < nLen + cTrans += "qOut( '" + ENDIF + lOpen := .t. + + ENDIF + i++ + + ELSEIF c = "<" .AND. substr( cLine, i + 1, 1 ) = "%" + IF !lOpen + // Error - Not in htm mode + + ELSE + // Fecha script + cTrans += "' )" + lOpen := .f. + IF i < nLen + // cTrans += " ; " + cTrans += NewLine + ENDIF + + ENDIF + i++ + + ELSE + cTrans += c + + ENDIF + + NEXT + + IF lOpen .AND. substr( cLine, nLen - 1, 2 ) <> "%>" + cTrans += "' )" + ENDIF + + aadd( aResult, cTrans ) + + hb_fSkip() ENDDO + hb_fUse() - 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? - // Yes, translate only HTML to qOut - aadd( aResult, "qOut( '" + ; - substr( cLine, 1, nPos-1 ) + ; - "' ) " + NewLine + ; - 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 ) @@ -153,7 +147,7 @@ FUNCTION Main( cScript ) // Runs using Tugboat cFile := strtran( upper( cFile ), ".PRG", ".HRB" ) HB_Run( cFile ) - // Erases the HRB + // Erases the HRB file fErase( cFile ) // That's all, folks! diff --git a/harbour/tests/working/hscript/readme.txt b/harbour/tests/working/hscript/readme.txt index 2b6940db2e..d0e6ac18ab 100644 --- a/harbour/tests/working/hscript/readme.txt +++ b/harbour/tests/working/hscript/readme.txt @@ -66,17 +66,6 @@ Known bugs - Web Server hanging some times (see above); -- No support for <% and %> tags on the same line without its -corresponding tag, eg.: -<% FUNCTION Main() -%>

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

<% - RETURN( NIL )%> - -- No support for multiple <% %> tags in the same line, eg.: -... -<% qOut( aArr[1] ) %><% qOut( aArr[2] ) %> -... - Open questions -------------- diff --git a/harbour/tests/working/hscript/ugly.hs b/harbour/tests/working/hscript/ugly.hs new file mode 100644 index 0000000000..d1b4a00e50 --- /dev/null +++ b/harbour/tests/working/hscript/ugly.hs @@ -0,0 +1,11 @@ +<% FUNCTION Main() + + LOCAL a := "Hello Mom!" %><% + qOut( a ) %>

This is a very ugly script!!!<% + qOut( "Line 2" ) + %> +

+<% +qOut( a, a, a ) +%> +<%RETURN( NIL )%>