skyPorter
 
- skyPorter ports various timeLines Server Page formats to one another, e.g., ASP to Perl, ASP to PHP.

- We may make it a web service, paste in or upload a VB/ASP file, we convert?
- first pass = what language is this?  Looks like, etc....?

General porting code:
Open a file, get a line ready for substitution rules.
Documentation needed:
How to call 
How to batch run a folder of hundreds of page files.  
Unix filter program?

Case-Specific Substitution Rules
Note: Rules need intimate familiarity with source and target languages.

Begin with ASP/VBScript to Perl (PSP - Perl Server Pages)

Then do ASP/VBScript to PHP, ASP/VBScript to JSP
Next we should do ASP/VBScript to ASP/JavaScript.

Then perhaps PHP to Perl?

If Perl programs were written in a very simple direct style (C-like), and following a Server Page template standard, we might even be able to port back from Perl to PHP, ASP, and JSP. If dense "obfuscated Perl," this is impractical.
_________________________________________________
Phase 0

Convert several pages by hand to develop key transformation and substitution rules.  Do ASP to PHP, ASP to Perl.  Convert the very complex major (core) pages of timeLines. Provide these as side-by-side to show when and how code can be converted on a line-by-line basis.

Determine when some variables and structures will need to be held in temporary memory until their full use is visible (e.g., Case variables)

Completed 2/10/2000 
_________________________________________________
Phase 1  Client-side code (server variable interpolation)

- Pipe the lines to a new file without changing server-side code

Identify all client-side lines and pipe them to the new file, 
    except identify VBScript in-line Response.Write elements (<%= myVar %>) 
    replace with Perl variable interpolation ($myVar)
	
	surround blocks of client-side lines with a HERE String structure:
	
print header(); # once only, at first client-side code.

print < # commentary...
	
Declarations:
Identify 	Dim myVar, myVar2 
        	=> my ($myVar, $myVar2);
		Note: myVar(50) -> @myVar, and myVar(50, 20) needs special handling.
		Note: collect all Dims in section near top of page.

Replace dimmed VB arrays with my @arrays, var interpolate var1(num) as $var1[$num]. myArray(num, num2) => $myArray[$num][$num2]

Completed 2/13/2000
_________________________________________________
Phase 2b - Request

Identify  	myVar = Request.QueryString("myVar")
			and myVar = Request.Form("myVar")
         	=> $myVar = param("myVar");
		Note: We must handle If Form = "" get QueryString redundancy in ASP.
		
			myVar = Request.ServerVariables("myVar")
         	=> $myVar = $ENV("myVar");
			myVar = Request.Cookies("myVar")
         	=> $myVar = cookie("myVar");

Completed 02/14/2000							
_________________________________________________
Phase 2c - Database calls - SQLQuery:

Identify  	SQLQuery = "..........."
        	=> $SQLQuery = "..........";
		Note: BE CAREFUL NOT TO ALTER THE TEXT OF THE SQL: 
			SQLQuery = "....."& myVar1 &"......"		
			=> $SQLQuery = ".....".$myVar1.".....";

Identify 	Set RSXXXX = ObjdbConnection.Execute(SQLQuery)
        	=> $sthXXXX = $dbh->prepare($SQLQuery);
               $sthXXXX ->execute;
               $XXXX = $sthXXXX ->fetchrow_hashref;

Identify structures that move a database recordset into server variables

ScheduleColor = RSGlobals("ScheduleColor")
HomePageURL = RSGlobals("HomePageURL")
OrgName = reQuote(RSGlobals("OrgName"))

Replace with

$ScheduleColor = $$Globals{"ScheduleColor"};
$HomePageURL = $$Globals{"HomePageURL"};
$OrgName = reQuote($$Globals{"OrgName"});
	Note dereference of Globals hash ($$).

Identify structures that iterate database recordsets into server-side arrays

numStrings = 0
Do While Not RSStrings.EOF

numStrings = numStrings + 1
StringsName(numStrings) = RSStrings("LanguageCustom")
StringsID(numStrings) = RSStrings("ID")

RSStrings.moveNext
Loop

Replace with

$numStrings = 0;
while ($Strings = $sthStrings->fetchrow_hashref) {
		$numStrings = $numStrings + 1;	
		$StringsName[$numStrings] = $$Strings{"LanguageCustom"};
		$StringsName[$numStrings] = $$Strings{"ID"};
} 

and of course

If Not RSStrings.EOF Then

End If

=>
if (!EOF) {

$OrgName = reQuote($$Globals{"OrgName"});

}

Completed 02/18/2000
_________________________________________________
Phase 3a Server Header

Create a Header template that initializes target code, calls include files (Perl Modules), etc.

Replace the "header" material of original code as a block.

Completed 02/19/2000
_________________________________________________
Phase 3b Server Code

Convert VBScript code to Perl (also to PHP, Java, and JavaScript)

Control Structures (If Then, Do While, For Next, Foreach, Select Case)
	Note: Select Case => if {} elsif {} elsif {} else {}

VB Functions - InStr(), InStrRev(), Left(), Right(), Mid()

Include files... (Done by hand, insert standard header)
	QuoteSQL.inc > QuoteSQL.pm
	DBConnect.inc > DBConnect.pm

Completed 02/24/2000

Custom Subs and Functions 

Completed 02/25/2000

Replace CInt(myVar) with $myVar

SQL UPDATE, INSERT, DELETE may be special??

File handling (open, write, close, etc.)

Still in process at 02/25

_________________________________________________
Phase 4  Response

Response.Write
Response.Clear
Response.Redirect
Response.Buffer
________________________________________________________
Things we may need to do by hand.  Do not attempt to convert?
Just flag them in the Notesfile and do by hand?
We may only need to do some once, if page unlikely to change.

Various Date functions, DateDiff(), DateAdd(), DateSerial()

Remove redundancy in ASP
If Form = "", get QueryString.

_________________________________________________
We should impose certain style conventions on our ASP versions of timeLines Server Pages (to facilitate translation to other languages)

Preparation of pages for conversion 
- check that source (ASP) page does the following:

Gather Dims at the top, subroutines next, etc.

Run with OPTION EXPLICIT to insure that all vars are Dimmed.

Include description block, credits block

Perhaps add some structures that simplify conversion,
e.g., If (var = var1) Then  ' put parens around condition. 

_____________________________________________________
_____________________________________________________

Specific examples for ASP/Javascript, ASP/VBScript, JSP, Perl, PHP
(later other scripting languages - 4D, etc.?)
_____________________________________________________
Cross-program glossary, property/method names, core techniques
Needed to convert/port our timeLines Server Pages
_______________________________________________
Major Parts of a timeLines Server Page

Directives/Header

ASP/JS		<%@ Language = JavaScript %>
ASP/VB		<%@ Language = VBScript %>

JSP			<%@ Language = Java? %>

Perl		#!D:\Perl\bin\perl5.00503.exe -w

PHP			<?  ?>
_______________________________________________

Declaratives

ASP/JS		<% Response.Buffer = True %>
ASP/VB		<% Response.Buffer = True %>

JSP			<% %>

Perl		;

PHP			<?  ?>

_______________________________________________

Include files

ASP/JS		%>
			<!-- #include filename.inc -->
			<%
ASP/VB		%>
			<!-- #include filename.inc -->
			<%
			
JSP			%>
			<!-- #include filename.inc -->
			<%

Perl		use filename.pm;

PHP			%>
			<!-- #include filename.inc -->
			<%

_______________________________________________

Declarations and Initialization

ASP/JS		var myVar
			var myArray = new Array;
ASP/VB		Dim myVar, myArray(50)

JSP			?

Perl		my ($myVar, @myArray, %myHash);

PHP			? variables come into existence as you use them
_______________________________________________

Request Variables (round trip client-side variables)

ASP			myVar = Request.QueryString("myVar") 
			myVar = Request.Form("myVar")

JSP			

Perl		$myVar = param("myVar");

PHP			$myVar=$HTTP_GET_VARS["myVar"];


_______________________________________________

Database connections 

ASP/JS		OBJdbConnection = Server.CreateObject("ADODB.Connection"); 
			OBJdbConnection.Open "DTVGroup"; 
ASP/VB		Set OBJdbConnection = Server.CreateObject("ADODB.Connection")  
			OBJdbConnection.Open "DTVGroup" (assuming DSN name)
			or
			OBJdbConnection.Open("Driver={Microsoft Access Driver (*.mdb)};DBQ="D:\InetPub\DTVGroup.mdb")

JSP			

Perl		$DSN = "Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\InetPub\\DTVGroup.mdb";
			$dbh = DBI->connect("dbi:ODBC:$DSN", '','', {PrintError => 1, RaiseError => 1} ) or die 'Ouch!';

PHP			$OBJdbConnection=odbc_connect("DTVGroup","","");


_______________________________________________

SQL Queries (database recordset to server variables)

ASP/JS		SQLQuery = "SELECT ScheduleColor FROM Globals;" 
			Set RSGlobals = OBJdbConnection.Execute(SQLQuery)
			if (!(RSGlobals.EOF)) {
			ScheduleColor = RSGlobals("ScheduleColor")
			}

ASP/VB		SQLQuery = "SELECT ScheduleColor FROM Globals;" 
			RSGlobals = OBJdbConnection.Execute(SQLQuery)
			If Not RSGlobals.EOF Then
				ScheduleColor = RSGlobals("ScheduleColor")
			End If

JSP			

Perl		$SQLQuery = "SELECT ScheduleColor FROM Globals;";
			$sthGlobals = $dbh->prepare($SQLQuery);
			$sthGlobals->execute;
			# $Globals = $sthGlobals->fetchrow_hashref;
			
			while ($Globals = $sthGlobals->fetchrow_hashref) {
			$ScheduleColor = $$Globals{"ScheduleColor"};
			};

PHP			$SQLQuery="SELECT ScheduleColor, SmallIconURL, BGImageURL, OrgName, LogoColor, TimeLinesDarkColor, Debug, balloonsOn FROM Globals;";
			$RSGlobals_query=odbc_exec($OBJdbConnection,($SQLQuery));
			$RSGlobals_ptr=1;
			$RSGlobals=odbc_fetch_row($RSGlobals_query,$RSGlobals_ptr++);
			
			$ScheduleColor=odbc_result($RSGlobals_query,"ScheduleColor");


_______________________________________________

Iterate database recordsets into server-side arrays. DO the database query as above, then...

ASP/JS
			numStrings = 0
			while (! RSStrings.EOF) {
				numStrings = numStrings + 1
				StringsID(numStrings) = RSStrings("ID")
				RSStrings.moveNext
			}
ASP/VB
			numStrings = 0
			Do While Not RSStrings.EOF
			numStrings = numStrings + 1
			StringsID(numStrings) = RSStrings("ID")
			RSStrings.moveNext
			Loop

JSP

Perl
			$numStrings = 0;
			while ($Strings = $sthStrings->fetchrow_hashref) {
					$StringsID[$numStrings] = $$Dates{"ID"};
					$numStrings += 1;	
			} 
PHP	
_______________________________________________

Pass server-side variables, arrays, etc. to client in embedded HTML and client-side script.  Use variable interpolation (server variable substitution)

ASP/JS		%>
			<HTML>




			<TITLE>The Title = <%= sJSserverTitle %></TITLE>
			<SCRIPT LANGUAGE="JavaScript">
				var myJSvar = <%= myJSservervar %>;
			</SCRIPT>
			</HEAD>
			<BODY BGCOLOR="<%= sScheduleColor %>">
			</BODY>
			</HTML>
			<% 'End ASP %>

ASP/VB		%>
			<HTML><HEAD>
			<TITLE>The Title = <%= VBserverTitle %>
			<SCRIPT LANGUAGE="JavaScript">
				var myJSvar = <%= myVBservervar %>;
			</SCRIPT>
			</HEAD>
			<BODY BGCOLOR="<%= sScheduleColor %>">
			</BODY>
			</HTML>
			<% 'End ASP %>
			
JSP			

Perl		print header();

			print <<END_HTML; # herestring
			<HTML><HEAD>
			<TITLE>The Title = $PerlServerTitle</TITLE>
			<SCRIPT LANGUAGE="JavaScript">
				var myJSvar = $myPERLvar
			</SCRIPT>
			</HEAD>
			<BODY BGCOLOR="$ScheduleColor">
			</BODY>
			</HTML>
			END_HTML	# at start of line
						# needs empty line
			
N.B. herestrings are treated like double-quoted strings (variable interpolated), so all \ chars must be carefully escaped -> \\

PHP			
			<HTML><HEAD>
			<TITLE>The Title = <? echo $PHPServerTitle; ?></TITLE>
			<SCRIPT LANGUAGE="JavaScript">
				var myJSvar = 
			</SCRIPT>
			</HEAD>
			<BODY BGCOLOR="<? echo $ScheduleColor; ?>">
			</BODY>
			</HTML>


_______________________________________________

Multidimensional arrays

ASP/JS		var myArray = new Array;
			for (i=0, i<20,i++) {
				var myArray[i] = new Array;
			}
			myArray[n][m] = 
ASP/VB		Dim myVar, myArray(50, 20)
			myArray(n,m) =
			
JSP			

Perl		my ($myVar, @myArray, %myHash);

PHP			?


_______________________________________________

_______________________________________________

$ENV - Environment Variables 
(subtle differences from CGI standard? )

ASP/JS		see ASP in a Nutshell, p. 372
ASP/VB		see ASP in a Nutshell, p. 372
Perl		
PHP
Java		
JavaScript	

Time functions/methods

ASP			Now()
Perl		($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$isdst) = localtime();
			($day,$mon,$yr) = (localtime)[3,4,5];
			$yr returns years since 1900
PHP
Java		
JavaScript	date(), time()
VBScript	

URL escape method

ASP/VB		Server.URLEncode()
Perl		URI::Escape module  uri_escape uri,[regexp]
PHP
Java		
JavaScript	escape()

Porting problems

Sometimes a .pl page invokes "Save As.." 
VB to Perl
JavaScript "strings" with \ needs \\ to run in Perl

______________________

Date handling (especially differences)

ASP/JS		
ASP/VB		DateDiff
Java		
JavaScript	
Perl		Use Date-Calc.pm	
PHP

Can we get GMT (TZ Offset) of Server?

ASP/JS		?? What kind of server doesn't know what time it is?
ASP/VB		??
Java		?
JavaScript	-
Perl		Yes (isdst)
PHP			Yes

Date Notes
	Date format in db (YYYY/MM/DD HH:MM:SS)
	(MM/DD/YYYY US vs. DD/MM/YYYY Europe problem)
	(use our standard? yyyymmddhhmmss)
	POSIX 21-second problem (Perl)
	Daylight Savings Time problem (locale dependent)
	Calendar code licenses?
	iCal standards
	locale issues - get local time, including DST? (Admin enter?)
	Can we query time over the Internet?
	Server always GMT? - not bad - can we inhibit DST? Yes.
	Administrator enters TZ (will work)
	Get Server time zone (= diff GMT - local time)
	Get Browser Time Zone Offset (= diff GMT - browser time)
_______________________


Edit 
Language: fr  | it  | de  | es  | pt  | ar  | he  | da  | nl  | zh  | ja  | ko  | none 
skyCalendar

This Version:
Archived at: https://www.skybuilders.com/Tools/skyPorter.20001007183229.html

Requests
 Version: 50243 | Series: 50243