import java.io.*; import java.util.*; import java.security.*; public class Genjava { boolean cli_quiet; int cli_maxviews; static boolean cli_log; static int cli_keysize = 8; static boolean cli_metafile = false; static boolean cli_javadoc = false; static boolean cli_nobp = false; static int abbrsize; static String filename; static String directory; static String fullpath; static String packagename; static String filesep; Database theSchema; Parser theParser; CodeGenerator theGenerator; Genjava() { theSchema = new Database(); theParser = new Parser( theSchema ); theGenerator = new CodeGenerator( theSchema ); } public static void main(String[] args) { int i; boolean filefound = false; String cwd; try { Genjava.filesep = System.getProperty("file.separator"); cwd = System.getProperty("user.dir"); for( i = 0; i < args.length; ++i ) { if( args[i].charAt(0) != '-' ) { if ( filefound ) { System.out.println("GENJAVA-F-BADCMD, unknown value " + args[i] + " specified in command line" ); System.exit(-1); } filefound = true; int location = args[i].lastIndexOf(Genjava.filesep.charAt(0)); if( location == -1 ) { System.out.println("GENJAVA-F-FULLPATH, must give full file path for " + " file " + args[i]); System.exit(-1); } Genjava.fullpath = args[i]; Genjava.directory = args[i].substring(0, location); Genjava.filename = args[i].substring(location + 1); location = Genjava.filename.lastIndexOf('.'); if( location == -1 ) { Genjava.packagename = Genjava.filename; } else { Genjava.packagename = Genjava.filename.substring(0, location); } System.out.println("directory = " + Genjava.directory); System.out.println("filename = " + Genjava.filename); if( Genjava.directory.equalsIgnoreCase(cwd) ) { System.out.println("GENJAVA-F-BADLOC, can't generate output in " + cwd + " - will overwrite Genjava source!!"); System.exit(-1); } } // if( args[i].charAt(0) != '-' ) System.gc(); if( args[i].compareTo("-metafile") == 0 ) { Genjava.cli_metafile = true; } if( args[i].compareTo("-javadoc") == 0 ) { Genjava.cli_javadoc = true; } if( args[i].startsWith("-keysize=") ) { try { Genjava.cli_keysize = Integer.parseInt(args[i].substring(9)); } catch( Exception e ) { System.err.println("GENJAVA-F-BADKEYSIZE, invalid key size \"" + e.getMessage() + "\" specified - must be 8 or 12"); System.exit(-1); } if( Genjava.cli_keysize != 8 && Genjava.cli_keysize != 12 ) { System.err.println("GENJAVA-F-BADKEYSIZE, invalid key size \"" + Genjava.cli_keysize + "\" specified - must be 8 or 12"); System.exit(-1); } } /* Modified on 12/07/2002 to add logging facility */ if(args[i].compareTo("-log") == 0) Genjava.cli_log = true; } // for( i = 0; i < args.length; ++i ) Genjava theApp = new Genjava(); theApp.theParser.Parse(Genjava.fullpath); if( Genjava.cli_metafile ) theApp.OutputMetafile(); theApp.theGenerator.GenerateTables(); theApp.theGenerator.GenerateRows(); theApp.theGenerator.GenerateKey(); theApp.theGenerator.GenerateTableSeqListType(); theApp.theGenerator.GenerateDatabase(); try { if (Genjava.cli_log) { Gen_pr_log gen_pr_log = new Gen_pr_log(theApp.theGenerator); gen_pr_log.Generate_pr_log(); GenUtils genutils=new GenUtils(theApp.theGenerator); } } catch(IOException e) { System.err.println("IOException thrown: "+e); } if( Genjava.cli_javadoc ) theApp.theGenerator.GenerateDocfiles(); /* Modified on 12/07/2002 to add logging facility */ } catch ( SecurityException se ) { System.err.println("Security Exception thrown: " + se); System.exit(-1); } } public void OutputMetafile() { String filename = Genjava.directory + Genjava.filesep + Genjava.packagename + "_genjava.msdat"; try { BufferedWriter output = new BufferedWriter ( new FileWriter( filename ) ); output.write("SV010001\tPJ010001\t"); output.write( Genjava.filename ); output.write("\tGENJAVA v1.0\tGENJAVA"); output.newLine(); output.flush(); theSchema.TTtab.dumpTable(output); theSchema.TAtab.dumpTable(output); output.close(); } catch( IOException e ) { System.err.println( e.getMessage() ); System.exit(-1); } } }