Java for 3.0 Includes
Posted in 1997
Below is a java program that determines if your 4GL program requires an include file from your own libraries. It is useful as an educational program . We are using it to port from 3.11 to 95 . The basic design is to build lists of functions by library, as well as the locally defined functions in the project and finally a list of symbols used in the program. The symbol list is compared to each library function list and if a function from the library is used and not locally overriden , then the libray is added to the programs include list. The program uses, File, StingTokenizer, and Hashtable classes as well as the regular expression libraries of Steve Brandt http://www.win.net/~stevesoft/pat . package origjava.jdbctest; import COM.stevesoft.pat.Regex; import COM.stevesoft.pat.RegRes; import COM.stevesoft.pat.FileRegex; import COM.stevesoft.pat.Pattern; import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.Vector; import java.util.Hashtable; import java.util.StringTokenizer; import java.util.Enumeration; import java.applet.Applet; public class Funclist extends Applet { public void init() {} public void start() {} public void stop() {} public static void main( String[] args ) { new DoFuncList(); } } class DoFuncList extends Object { public DoFuncList() { //theFilter = "lowlevel.4gl"; init(); } public void init() { buildLocalFunctList(); buildSPHash(); buildRPTHash(); buildCMHash(); buildGLHash(); buildEXHash(); doAllFilesIndicated(); if (out != null ) out.close(); } public void buildLocalFunctList() { String dpat = theFilter;//t2.getText(); String[] files = FileRegex.list(dpat); for(int i=0;i<files.length;i++) { if (isWif(files[i]) != true) { try { //System.out.println("Searching file "+files[i]); FileReader ff=new FileReader(files[i]); BufferedReader bf=new BufferedReader(ff); String s = noComments(bf.readLine()); while(s != null) { // exclude comments // exclude comment blocks if (isCommentBlock() == false ) { putLocalFunc(s,files[i]); } s = noComments(bf.readLine()); } bf.close(); }catch(Exception t) { t.printStackTrace(); System.exit(255); } } } //System.out.println("Done buildLocalFuncList"); } public void putLocalFunc(String theLine, String theFileName) { String theIncludeName = getIncludeName(theLine); String theFuncName = getFuncName(theLine); if (theFuncName != null ) addLocalFuncName(theFuncName); if (theIncludeName != null ) addIncludeName(theIncludeName, theFileName); } public void addIncludeName(String theName,String theFileName) { int i = localIncludeVector.size(); localIncludeVector.addElement(new StringBuffer(String.valueOf(theName)).toString()); if (localIncludes.containsKey(theFileName) ) { Hashtable theTable = (Hashtable) localIncludes.get(theFileName); theTable.put(localIncludeVector.elementAt(i), localIncludeVector.elementAt(i)); } else { Hashtable theTable = new Hashtable(); theTable.put(localIncludeVector.elementAt(i), localIncludeVector.elementAt(i)); localIncludes.put(theFileName, theTable); } } public void addLocalFuncName(String theName) { int i = localFuncVector.size(); localFuncVector.addElement(new StringBuffer(String.valueOf(theName)).toString()); localFuncs.put(localFuncVector.elementAt(i), localFuncVector.elementAt(i)); } public boolean isLocalFunc(Object theTest) { boolean flag = false; if (localFuncs.containsKey(theTest)) { flag = true; //System.out.println("found Local Func " + theTest.toString()); } return flag; } public boolean isAlreadyIncluded(String theFileName, String theIncludeFile) { boolean flag = false; Object theKey = (Object) theFileName; Object theTest = (Object) theIncludeFile; Hashtable theHashTable = (Hashtable) localIncludes.get(theKey); if (theHashTable == null ) return false; if (theHashTable.containsKey(theTest) == true ) { flag = true; } return flag; } public boolean hasSPFunc() { boolean flag = false; Enumeration theList = theHashTable.keys(); while ( flag != true && theList.hasMoreElements()) { Object theTest = theList.nextElement(); if (theSPFuncs.containsKey(theTest)) { if ( isLocalFunc(theTest) != true ) { flag = true; //System.out.println("found SP Func " + theTest.toString()); } } } return flag; } public boolean hasRPTFunc() { boolean flag = false; Enumeration theList = theHashTable.keys(); while ( flag != true && theList.hasMoreElements()) { Object theTest = theList.nextElement(); if (theRPTFuncs.containsKey(theTest)) { if ( isLocalFunc(theTest) != true ) { flag = true; //System.out.println("found RPT Func " + theTest.toString()); } } } return flag; } public boolean hasEXFunc() { boolean flag = false; Enumeration theList = theHashTable.keys(); while ( flag != true && theList.hasMoreElements()) { Object theTest = theList.nextElement(); if (theEXFuncs.containsKey(theTest)) { if ( isLocalFunc(theTest) != true ) { flag = true; //System.out.println("found EX Func " + theTest.toString()); } } } return flag; } public boolean hasCMFunc() { boolean flag = false; Enumeration theList = theHashTable.keys(); while ( flag != true && theList.hasMoreElements()) { Object theTest = theList.nextElement(); if (theCMFuncs.containsKey(theTest)) { if ( isLocalFunc(theTest) != true ) { flag = true; //System.out.println("found CM Func " + theTest.toString()); } } } return flag; } public boolean hasGLFunc() { boolean flag = false; Enumeration theList = theHashTable.keys(); while ( flag != true && theList.hasMoreElements()) { Object theTest = theList.nextElement(); if (theGLFuncs.containsKey(theTest)) { if ( isLocalFunc(theTest) != true ) { flag = true; //System.out.println("found GL Func " + theTest.toString()); } } } return flag; } public void addTokens(String str) { String theDelimiters = "\\t\\n\\r ,()"; StringTokenizer tok=new StringTokenizer(str,theDelimiters); while(tok.hasMoreElements()){ Object theObj = tok.nextElement(); theHashTable.put(theObj,theObj); } }@@