Methods Summary |
---|
private java.lang.String | ConstructOutputFileName(java.lang.String strCppFile)
String strOutputFile = new String(strCppFile);
//System.out.println(strOutputFile);
int iIndex = strOutputFile.indexOf(".");
if(iIndex == -1){
System.out.println("Invalid name for a cpp file : " + strCppFile);
System.exit(1);
}
strOutputFile = strOutputFile.substring(0, iIndex) + ".java";
return strOutputFile;
|
public java.lang.String | GetOutputFileName()Purpose: Returns the output file name return m_strOutputFile;
|
public void | MatchAndReplace()Purpose: Reads an output file and replaces found strings as specified
Note: similar to sed utility
StringPair stPair1 = new StringPair("char * ","String ");
StringPair stPair2 = new StringPair("char* ","String ");
StringPair stPair3 = new StringPair("const char * " ,"String ");
StringPair stPair4 = new StringPair(" & ", " ");
StringPair stPair5 = new StringPair("*", " ");
StringPair stPair6 = new StringPair("->", ".");
StringPair stPair7 = new StringPair("unsigned int " ,"int ");
StringPair stPair8 = new StringPair("unsigned long ","int ");
StringPair stPair9 = new StringPair("unsigned char ", "char ");
StringPair stPair10 = new StringPair("unsigned ","int ");
StringPair stPair11 = new StringPair("const " , "static final ");
StringPair stPair12 = new StringPair("BOOL ", "boolean ");
StringPair stPair13 = new StringPair("NULL", "null");
Vector v = new Vector();
v.addElement(stPair1);
v.addElement(stPair2);
v.addElement(stPair3);
v.addElement(stPair4);
v.addElement(stPair5);
v.addElement(stPair6);
v.addElement(stPair7);
v.addElement(stPair8);
v.addElement(stPair9);
v.addElement(stPair10);
v.addElement(stPair11);
v.addElement(stPair12);
v.addElement(stPair13);
Replacer rep = new Replacer(m_strOutputFile, v);
rep.MatchAndReplace();
(new File(m_strTempFile)).delete();
|
public void | ParseCppFile()Purpose: parses a cpp file containig the implementation of the class defined in
header file
m_Parser.OpenInputFile(m_strCppFile);
m_Parser.SetParseMethod(true);
while(m_Parser.readClass(m_bDefnOnly));
//m_Parser.m_membersArray.WriteOut();
m_Parser.addGlobals();
m_Parser.CloseAllFiles();
m_tos.close();
m_fosFileOut.close();
|
public void | ParseHeaderFile()Purpose: parses a header file containing class definitions
Note: Should be called first
boolean bFirstClass = true;
m_Parser.SetParseMethod(false);
m_Parser.OpenInputFile(m_strHeaderFile);
while(m_Parser.readClass(m_bDefnOnly));
for(ClassRepresentation c = m_Parser.class_info; c!=null; c = c.GetNext()){
c.print(m_tos, bFirstClass);
if(bFirstClass) bFirstClass = false;
}
|
public void | WeaveItTogether()Purpose: Calls the preprocessor
//m_Parser.m_membersArray.WriteOut();
PrimitivePreprocessor prep = new PrimitivePreprocessor(new String(m_strTempFile), new String(m_strOutputFile),
m_Parser.m_membersArray);
prep.ProcessFile();
|
public static void | main(java.lang.String[] args)
String strHeaderFile = new String();
String strCppFile = new String();
if(args.length >= 2){
strHeaderFile = new String(args[0]);
strCppFile = new String(args[1]);
if(args.length == 3 && args[2].equalsIgnoreCase("-DefnOnly"))
C2J.m_bDefnOnly = true;
}
else{
System.out.println("Usage: Java C2J Source.h Source.cpp [-DefnOnly]");
System.exit(1);
}
C2J trans = new C2J(strHeaderFile, strCppFile);
trans.ParseHeaderFile();
trans.ParseCppFile();
trans.WeaveItTogether();
trans.MatchAndReplace();
System.out.println(trans.GetOutputFileName() + " is created");
System.out.println("Enjoy!");
//Runtime run = Runtime.getRuntime(); //works only under Windows NT
//run.exec("write " + trans.GetOutputFileName());
|