clBtnFaceDEFAULT_CHARSETclWindowText-11'MS Sans Serif'False9613
然后编出具体的代码,实现这一步的转换,我也坐了一小步,实现了dpr->xml的一部分,即转换工程名,Uses段和资源段,初始化段上为实施。如下,程序使用Windows Scripting Host写的,很业余,运行请保存为*.js双击即可。
// Windows Script Host to convert delphi's project file into xml file
//
// ------------------------------------------------------------------------
// Copyright (C) 2001 hcstudio
//
// You have a royalty-free right to use, modify, reproduce and distribute
// the Application Files (and/or any modified version) in any way
// you find useful, provided that you agree that hcstudio has no warranty,
// obligations or liability for any Application Files.
// ------------------------------------------------------------------------
// This script will convert delphi's project file into xml file.
var source;
var program,uses,resource;
var program=new Array();
var uses = new Array();
filename="Project1.dpr";
source=ReadFile(filename);
program=FindProgram(source);
uses=FindUses(program[1]);
resource=FindResource(uses[uses.length-1]);
program=program[0];
CreateXml(program,uses,resource);
//////////////////////////////////////////////////////////////////////////////////
//
// ReadFile to parse and return the file content as string
//
function ReadFile(filename)
{
var fso,file,stream,source;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.GetFile(filename);
stream = file.OpenAsTextStream(1,-2);
source=stream.readall();
return(source);
}
//////////////////////////////////////////////////////////////////////////////////
//
// Find the Program name and return the rest
//
function FindProgram(source)
{
var program,next,uptarget,downtarget,up,down;
var toReturn;
uptarget=/program/;
downtarget=/;/;
up=source.search(uptarget);
down=source.search(downtarget);
program=source.substring(up,down);
uptarget=/\s/;
up=program.search(uptarget);
program=program.slice(up);
next=source.slice(down+1);
var toReturn=new Array();
toReturn[0]=program;
toReturn[1]=next;
return(toReturn);
}
//////////////////////////////////////////////////////////////////////////////////
//
// A group of function to find uses
//
function FindUses(source)
{
var uses;
uses=new Array();
var Uses,uptarget,downtarget,up,down;
uptarget=/uses/;
downtarget=/;/;
up=source.search(uptarget);
down=source.search(downtarget);
Uses=source.substring(up,down);
uptarget=/\s/;
up=Uses.search(uptarget);
Uses=Uses.slice(up);
uses=FindUsesDetail(Uses);
next=source.slice(down+1);
uses[uses.length]=next;
return(uses);
}
function FindUsesDetail(Uses)
{
var auses,first,second,ifin,ifleft,ifright,i;
first=new Array();
auses=new Array();
first=Uses.split(",");
ifin=/\sin\s/;
ifleft=/'*'/;
ifright=/\./;
for(i=0;i.search(ifin)==-1)
{
auses[i*2]=first;
auses[i*2+1]=0;
}
else
{
auses[i*2]=first.substring(0,first.search(ifin));
auses[i*2+1]=first.substring(first.search(ifleft)+1,first.search(ifright)+4);
}
}
return(auses);
}
//////////////////////////////////////////////////////////////////////////////////
//
// Find the Resource and return the next
//
function FindResource(source)
{
var ifres,resource, j,found;
ifres=/{/;
var resource=new Array();
j=0;
do
{
if(found!=-1)
{
found=source.search(ifres);
resource[j]=source.substring((found+3),source.search(/}/));
j++;
source=source.slice(source.search(/}/)+1);
}
}
while (found!=-1);
resource[resource.length]=source;
return(resource);
}
//////////////////////////////////////////////////////////////////////////////////
//
// to createXml file using program,uses(array of string)
//
function CreateXml(program,uses,resource)
{
var filename;
filename="delphi.xml";
WriteFlag(filename);
var i;
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.load(filename);
var rootElement=xmlDoc.createElement("delphi");
var projectElement=xmlDoc.createElement("Project");
var programElement=xmlDoc.createElement("program");
var programElementText=xmlDoc.createTextNode(program);
programElement.appendChild(programElementText);
projectElement.appendChild(programElement);
for(i=0;i);
var usespathElementText=xmlDoc.createTextNode(uses[i+1]);
usesnameElement.appendChild(usesnameElementText);
usespathElement.appendChild(usespathElementText);
usesElement.appendChild(usesnameElement);
usesElement.appendChild(usespathElement);
projectElement.appendChild(usesElement);
}
for(i=0;i);
resourceElement.appendChild(resourceElementText);
projectElement.appendChild(resourceElement);
}
rootElement.appendChild(projectElement);
xmlDoc.appendChild(rootElement);
xmlDoc.save(filename);
}
function WriteFlag(filename)
{
var fso,file,stream,source;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.CreateTextFile(filename,true);
file.WriteLine("");
file.Close();
}
//////////////////////////////////////////////////////////////////////////////////
//
// for debug use
//
function Display(program)
{
var WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Popup(program);
}
最后综合各种语言的xml描述形式,定出XPML(Extensive Programming Markup Language)的标准。关键的互译开始了.