home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2002 December
/
PCWorld_2002-12_cd.bin
/
Software
/
Komercni
/
Baltik
/
katB.exe
/
katB
/
DESIGN
/
DESIGN_C.XML
< prev
next >
Wrap
Text File
|
2002-09-24
|
13KB
|
276 lines
////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------//
//-----project DESINGER, copyright 2002 Libor Bareτ-------------------------//
//----------------------------------------------------------------------------//
DIAGRAMCELL* Cells=0;
int * zorder=0;
int nSize=0;
long Src;
string GetVisibility(long nType){
if(nType & 0x00000002L/*TYPE_OA_PRIVATE*/) return "private";
else if(nType & 0x00000001L/*TYPE_OA_PROTECTED*/) return "protected";
else return "public";
}
string OperationParser(CLASSITEM* pItem, string & vis, string & type, string & name, string & param){
string strHTML;
vis = GetVisibility(pItem->nType);
string ToParser = pItem->strText;
type = "";
name = "";
param = "";
int nPos;
param = "";
int nLen = StrDélka(ToParser);
char nName = 0;
int nParam = 0;
for(nPos=0;nPos < nLen;nPos++){
if(ToParser[nPos]=='('){
name = trim(StrKopie(ToParser,0,nPos));
nName =1;
unsigned end = StrPozicePod²et╪zce(ToParser,0,")");
if(end != 0xffff){
int nX,id=0;
string str;
for(nPos++;nPos < end && ToParser[nPos] != ')';nPos++){
int nX=nPos;
for(;nPos < nLen && ToParser[nPos] != ')' && ToParser[nPos] != ',';nPos++){}
str = trim(StrKopie(ToParser,nX,nPos-nX));
if(str != ""){
//-Box__AddItem(21/*IDC_PARA_LIST*/,id,strx,0);id++;
int x,i = StrPozicePod²et╪zce(str,0,":");
if(StrKopie(str,0,5)=="inout"){x=6;}
else if ((StrKopie(str,0,3)=="out")){x=4;}
else if ((StrKopie(str,0,2)=="in")){x=3;}
else {x=0;}
if(nParam != 0)param+=", ";
else {
strHTML = "<TR><TD width=\"100\"><FONT face=\"Tahoma\" size=\"2\"></FONT></TD><TD width=\"100\" vAlign=\"top\" align=\"middle\"><span class=\"Labels\">parametry :</span></TD><TD>";
strHTML+="<TABLE cellSpacing=\"0\" cellPadding=\"0\" border=\"0\" width=\"350\" >";
}
param+=trim(StrKopie(str,i+1,-1))+" "+trim(StrKopie(str,x,i-x));
nParam++;
strHTML+="<TR><TD width=10></TD><TD><span class=\"Types\">"+trim(StrKopie(str,i+1,-1))+"</span></TD><td><FONT face=\"Tahoma\" size=\"2\">"+trim(StrKopie(str,x,i-x))+"</FONT></td></TR>";
}
}
}
}
if(ToParser[nPos]==':'){ // read type
if(nName==0) name = trim(StrKopie(ToParser,0,nPos));
type = trim(StrKopie(ToParser,nPos+1,-1));
}
}
param = trim(param);
name = trim(name);
type = trim(type);
if(strHTML != ""){
strHTML +="</TABLE></TD></TR>";
}
return strHTML;
}
void VariableParser(CLASSITEM* pItem, string & vis, string & type, string & name){
vis = GetVisibility(pItem->nType);
// name and type
unsigned pos = StrPozicePod²et╪zce(pItem->strText,0," : ");
if(pos == 0xffff){name = pItem->strText; type = "";}
else {
name = StrKopie(pItem->strText,0,pos);
type = StrKopie(pItem->strText,pos+3,StrDélka(pItem->strText)-pos-3);
}
}
void EXPORT_HTML(string tofile){
TxtPiτⁿet╪zec("\nExportuji náhled t²íd do "+tofile);
// if(SouborExistuje(tofile))SouborSmaº(tofile);
long Dest = SouborOtev²i(tofile,SouborP²ístupZápis|SouborP²ístupTextov∞);
SouborU²ízni(Dest);
SouborNastavPozici(Dest,0,SouborPoziceOdZaćtku);
int nPos = 0;
SouborPiτⁿet╪zec(Dest,"<HTML><HEAD><META http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1250\">");
SouborPiτⁿet╪zec(Dest,"<style> .Types {font-size: x-small;color: blue;font-family: Tahoma;} .Labels {font-weight: bold;font-size: x-small;color: indigo;font-family: Tahoma;}</style></HEAD>");
SouborPiτⁿet╪zec(Dest,"<BODY>");
{
// class
DIAGRAMCELL * pCell=NULL;
string vis,name,type,param;
for(nPos =0; nPos < nSize; nPos++){
pCell = &Cells[nPos];
if(pCell->nType < 3){
SouborPiτⁿet╪zec(Dest,"<TABLE style=\"WIDTH: 571px; HEIGHT: 27px\" width=\"570\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" bgColor=\"lightgrey\"><tbody bgColor=\"white\"><tr><td colspan=\"5\" bgColor=\"#cadfff\"><STRONG> ");
SouborPiτⁿet╪zec(Dest,"<FONT color=\"midnightblue\" face=\"Arial\" size=\"5\">");
SouborPiτⁿet╪zec(Dest,pCell->ClassName);
SouborPiτⁿet╪zec(Dest,"</FONT></STRONG></td></tr>");
{
SouborPiτⁿet╪zec(Dest,"<TR><TD colspan=\"5\" bgColor=\"snow\"><FONT face=\"Tahoma\" color=\"gray\"><STRONG> Atributy :</STRONG> </FONT></TD></TR>");
SouborPiτⁿet╪zec(Dest,"<TR bgColor=\"peachpuff\"><TD width=\"100\" align=\"middle\"><span class=\"Labels\">viditelnost</span> </TD><TD width=\"100\" align=\"middle\"><span class=\"Labels\">typ</span></TD><TD colSpan=\"3\" align=\"middle\">");
SouborPiτⁿet╪zec(Dest,"<span class=\"Labels\">nßzev atributu</span></TD></TR>");
{
// variables
int nVariable=0;
for(;nVariable < pCell->nSizeVariable;nVariable++){
VariableParser(&(((CLASSITEM*)pCell->pVariable)[nVariable]),vis,type,name);
SouborPiτⁿet╪zec(Dest,"<TR><TD width='100'><FONT face=\"Tahoma\" size=\"2\"> "+vis+"</FONT></TD><TD width='100'><span class=\"Types\"> "+type+"</span></TD><TD colSpan=\"3\">");
SouborPiτⁿet╪zec(Dest,"<FONT face=\"Tahoma\" size=\"2\"> <FONT size=\"3\">"+name+"</FONT></FONT>");
}
}
}
{
// operations
SouborPiτⁿet╪zec(Dest,"<TR><TD width=\"100\" colspan=\"5\" bgColor=\"snow\"><FONT face=\"Tahoma\" color=\"dimgray\"><STRONG> Operace :</STRONG></FONT></TD></TR>");
SouborPiτⁿet╪zec(Dest,"<TR bgColor=\"peachpuff\"><TD width=\"100\"><P align=\"center\"><span class=\"Labels\">viditelnost</span></P>");
SouborPiτⁿet╪zec(Dest,"</TD><TD width=\"100\" align=\"middle\"><span class=\"Labels\">nßvratov² typ</span></TD><TD colSpan=\"3\" align=\"middle\"><span class=\"Labels\">nßzev operace</span></TD></TR>");
{
// operations
int nOperation=0;
for(;nOperation < pCell->nSizeOperation;nOperation++){
string strH = OperationParser(&(((CLASSITEM*)pCell->pOperation)[nOperation]),vis,type,name,param);
SouborPiτⁿet╪zec(Dest,"<TR><TD width=\"100\"><FONT face=\"Tahoma\"> <FONT size=\"2\">"+vis+"</FONT></FONT></TD><TD width=\"100\"><span class=\"Types\"> "+type+"</span></TD><TD colSpan=\"3\">");
SouborPiτⁿet╪zec(Dest,"<FONT face=\"Arial\" size=\"2\"> <FONT size=\"3\">"+name+"</FONT></FONT></TR>");
if(strH != "")SouborPiτⁿet╪zec(Dest,strH);
}
}
}
SouborPiτⁿet╪zec(Dest,"</table><br><br>");
}
}
}
SouborPiτⁿet╪zec(Dest,"</BODY></HTML>");
SouborZav²i(Dest);
}
void EXPORT_CPLUSPLUS(int idclass,string file){
DIAGRAMCELL * pCell = &Cells[idclass];
string hfile = file + pCell->ClassName+".h";
file += pCell->ClassName+".cpp";
TxtPiτⁿet╪zec("\nExportuji t²ídu '"+pCell->ClassName+"' implementation : "+file+"\n interface : "+hfile);
if(SouborExistuje(file))SouborSmaº(file);
long DestCpp = SouborOtev²i(file,SouborP²ístupZápis|SouborP²ístupTextov∞);
long DestH = SouborOtev²i(hfile,SouborP²ístupZápis|SouborP²ístupTextov∞);
SouborU²ízni(DestCpp);
SouborU²ízni(DestH);
SouborNastavPozici(DestH,0,SouborPoziceOdZaćtku);
SouborNastavPozici(DestCpp,0,SouborPoziceOdZaćtku);
SouborPiτⁿet╪zec(DestCpp,"//////////////////////////////////////////////////////////////////\n// Class : "+pCell->ClassName+"\n"+
+"// File : "+pCell->ClassName+".cpp - implementation \n//\n"+
+"// Created by SoftDesigner Professional Edition for UML\n//////////////////////////////////////////////////////////////////\n\n");
SouborPiτⁿet╪zec(DestH,"//////////////////////////////////////////////////////////////////\n// Class : "+pCell->ClassName+"\n"+
+"// File : "+pCell->ClassName+".h - interface \n//\n"+
+"// Created by SoftDesigner Professional Edition for UML\n//////////////////////////////////////////////////////////////////\n\n");
SouborPiτⁿet╪zec(DestCpp,"#include \""+pCell->ClassName+".h\"\n\n\n");
if(pCell->dwFlags & 0x100){
SouborPiτⁿet╪zec(DestH,"virtual ");
}
SouborPiτⁿet╪zec(DestH,"class "+pCell->ClassName+" ");
int nSizeParent=0;
int nPos;
DIAGRAMCELL * pDep;
for(nPos=0;pCell->nSizeDependents > nPos;nPos++){
pDep = &Cells[pCell->pDependents[nPos]];
if(pDep->nType == 4 && pDep->dwFlags & 1 && pDep->nBreakB == idclass){
if(nSizeParent != 0) SouborPiτⁿet╪zec(DestH,", ");
else SouborPiτⁿet╪zec(DestH," : ");
nSizeParent++;
SouborPiτⁿet╪zec(DestH,Cells[pDep->nBreakA].ClassName);
}
}
SouborPiτⁿet╪zec(DestH," {\n");
string vis,name,type,param;
{
// output variables;
SouborPiτⁿet╪zec(DestH,"\n // Variables ");
SouborPiτNov∞ⁿádek(DestH);
// HERE OUTPUT
int nVariable=0;
for(;nVariable < pCell->nSizeVariable;nVariable++){
VariableParser(&(((CLASSITEM*)pCell->pVariable)[nVariable]),vis,type,name);
SouborPiτⁿet╪zec(DestH," "+vis+" "+type+" "+name+";\n");
}
SouborPiτNov∞ⁿádek(DestH);
}
{
// output operations;
SouborPiτⁿet╪zec(DestH,"\n // Operations ");
string ext="";
SouborPiτNov∞ⁿádek(DestH);
int nOperation=0;
for(;nOperation < pCell->nSizeOperation;nOperation++){
OperationParser(&(((CLASSITEM*)pCell->pOperation)[nOperation]),vis,type,name,param);
if((((CLASSITEM*)pCell->pOperation)[nOperation]).nType & 0x100) ext = "virtual ";
else ext="";
SouborPiτⁿet╪zec(DestH," "+ext+vis+" "+type+" "+name+"( "+param+" );\n");
SouborPiτⁿet╪zec(DestCpp,type+" "+pCell->ClassName+"::"+name+"("+param+")\n{\n // TODO : Here add your code ... \n\n}\n");
}
// HERE OUTPUT
SouborPiτNov∞ⁿádek(DestH);
}
SouborPiτⁿet╪zec(DestH,"\n\n\n}");
SouborZav²i(DestH);
SouborZav²i(DestCpp);
}
void IMPORT_CPLUSPLUS(string file){
// CZE
// program umi importovat z *.Cpp a *.H, tedy z definici imlementace a rozhrani jazyka C++
//
//
// poznamka k implementaci : Jazyk C++ je velmi rozsahly a pokryt veskerou sktrukturu jazyka by bylo
// pomerne casove narocne a program i tak by nemohl nektere struktury zobrazit.
// Soucastna verze parseru proto neobsahuje dekodery pro tyto typy C++ konstrukci
// : parametrizovane tridy, class v class, typedefy, define, atd...
// ve skutecnosti tento jednoduchy parser zapozdri pouze jednoduchou orientaci v kodu,
// je sice pravda, ze komletni parser by nebylo narocne udelat, jenze ... bylo by nutne
// zahrnost defacto i vlastni minicopiler kodu, ktery by byl schopen resit konstrukce definici apod.
//
long Cpp = SouborOtev²i(file,SouborP²ístupZápis|SouborP²ístupTextov∞);
string strLastOp;
string strLine;
char bComments; /* */
while(!SouborKonec(Cpp)){
Soubor¼tiSⁿet╪zec(Cpp,strLine);
}
}