Subject: Java for 3.0 Includes
From: [email-masked] (Bob Leurck)
Date: Wed, 23 Jul 1997 21:40:06 GMT
Newsgroups: comp.databases.informix

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);
			}

	}
	public Vector getTokens(String str)
	{
		String theDelimiters = "\t\n\r ,()";
		StringTokenizer tok=new
StringTokenizer(str,theDelimiters);
		Vector ret=new Vector();

		while(tok.hasMoreElements())
			ret.addElement(tok.nextElement());

		return ret;
	}
	public String getIncludeName(String str)
	{
		String theDelimiters = "\t\n\r ,()\"";
		StringTokenizer tok=new
StringTokenizer(str,theDelimiters);
		String theName = null;
		boolean flag = false;
		String lower = "include";
		String upper = "INCLUDE";

		while(tok.hasMoreElements() && flag == false)
		{
		    String theTest = (String) tok.nextElement();
			if ( theTest != null) {
			    if( (theTest.equals(lower) ||
theTest.equals(upper) )
				    && tok.hasMoreElements())
				   {
				    theName = (String)
tok.nextElement();
					if (theName != null ) {
					    theName =
theName.toLowerCase();
					    flag = true;
						}
				}	
			}
        }

		return theName;
	}
	public String getFuncName(String str)
	{
		String theDelimiters = "\t\n\r ,()";
		StringTokenizer tok=new
StringTokenizer(str,theDelimiters);
		String theFuncName = null;
		boolean flag = false;
		String function = "function";
		String FUNCTION = "FUNCTION";

		while(tok.hasMoreElements() && flag == false)
		{
		    String theTest = (String) tok.nextElement();
			if ( theTest != null) {
			    if( (theTest.equals(function) ||
theTest.equals(FUNCTION) )
				    && tok.hasMoreElements())
				   {
				    theFuncName = (String)
tok.nextElement();
					flag = true;
				}	
			}
        }
		return theFuncName;
	}
	public  void  buildRPTHash() {
		Vector vector = new Vector();
		vector.addElement(new
StringBuffer(String.valueOf("createPartitionMgr")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("main_partition")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("before_group")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_defaults")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_destin")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getControl")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_int_exit")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_int_handler")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("after_group")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("lookup_printer")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("on_every_row")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_after_break")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_before_break")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_getCount")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_curs_null")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_define_cur")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_fetch")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_next_null")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_output")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ml_curs_prep")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("before_process_control")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("after_process_control")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("isCanceled")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getProcCanceled")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setProcessWasCanceled")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("process_control")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setProcessText")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getProcessText")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_parse")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("report_defaults")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("createPartitionMgr")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("load_control")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("unload_control")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("process_status")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("process_error")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt1")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish1")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt2")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish2")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt3")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish3")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt4")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish4")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt5")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish5")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt6")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish6")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt7")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish7")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt8")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish8")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt9")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish9")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_start_rpt10")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_finish10")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("start_screenx")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("finish_screenx")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate1")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate2")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate3")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate4")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate5")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate6")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate7")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate8")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate9")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_terminate10")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("startPart")).toString());
	    String astring[] = new String[vector.size()];
		vector.copyInto(astring);
		for(int i=0;i<vector.size();i++) {

theRPTFuncs.put(vector.elementAt(i),vector.elementAt(i));
		}
	}

	public  void  buildEXHash() {
		Vector vector = new Vector();
		vector.addElement(new
StringBuffer(String.valueOf("calc_dates")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("day_month")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_catgyv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("chk_open_inv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("valid_chk_no")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("dup_invoice")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_minorv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_remitv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getloc_xfrd")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_secure")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_termsv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_brdgev")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_caccrv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_vmacc")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_vendrv")).toString());
		String astring[] = new String[vector.size()];
		vector.copyInto(astring);
		for(int i=0;i<vector.size();i++) {

theEXFuncs.put(vector.elementAt(i),vector.elementAt(i));
		}
		//return astring;
	}
	public  void  buildCMHash() {
		Vector vector = new Vector();
		vector.addElement(new
StringBuffer(String.valueOf("cm_vmacc_2")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cm_vmacc")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cm_secure")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cm_run_hist")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cm_ltrdate")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cm_init")).toString());
		String astring[] = new String[vector.size()];
		vector.copyInto(astring);
		for(int i=0;i<vector.size();i++) {

theCMFuncs.put(vector.elementAt(i),vector.elementAt(i));
		}
		//return astring;
	}
	public  void buildGLHash() {
		Vector vector = new Vector();
		vector.addElement(new
StringBuffer(String.valueOf("formulav")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("gl_vmacc")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("gl_bdgtv")).toString());
		//System.out.println(" size " + vector.size());
		String astring[] = new String[vector.size()];
		vector.copyInto(astring);
		for(int i=0;i<vector.size();i++) {

theGLFuncs.put(vector.elementAt(i),vector.elementAt(i));
		}
		//return astring;
	}
	public void buildSPHash() {
		Vector vector = new Vector();
		vector.addElement(new
StringBuffer(String.valueOf("fetchOneIxRow")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("prepAndfetchManyRows")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("err_disp")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("control")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ctrl_display")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setClientSerialNo")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getClientSerialNo")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setServerSerialNo")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getServerSerialNo")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("load_ctrl_hdr")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("load_ctrl_dtl")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("unload_ctrl_hdr")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("unload_ctrl_dtl")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("load_ret_ctrl_detail")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("del_error_detail")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("retrieve_detail")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("insCsxctrld")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("updCsxctrld1")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("updCsxctrld2")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getCountItems")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("do_curry_conv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("curry_conv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("xchng_rate")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cx_curryv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cx_locnrv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("zc2_init")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("chartvalid")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("chartvalany")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("chartdesc")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("period_end_date")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("colchartvalid")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("chart_fetch")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("chart_fetch_any")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("alt_lang_desc")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("zc2_nv_null")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cx_locnrv")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("gl_unflex_acct")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("gl_flex_acct")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("zc3_init")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_file")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cdi_getxcmpdb")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getxcmpdb")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_cwd")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_pid")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ct_display")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("locktable")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("init")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getUserID")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getuser")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_user")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setProg")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getprog")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_prog")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getaccess")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_access")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_module")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getmodule")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setSetup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("get_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("is_jc_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ex_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cm_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("invtry_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("gl_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("fa_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ordent_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("extbill_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("log_setup")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getCompany")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getLanguageCode")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("connectDataBase")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setDatabaseName")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getDatabaseName")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("setOnline")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("isOnline")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("checkOnline")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("unload_error")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("init_vmacc")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("vmaccuser")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("vmaccpolcy")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask0001")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask0011")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask1012")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask1000")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask0000")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask1001")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask1002")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask1011")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask2011")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask3011")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask3911")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("mask9100")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("next_entry")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("perioda")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ret_disp")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("ret_resp")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("set_dash")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("set_disp")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("set_rept")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("cr_srctemp")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("proc_srcjrn")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("report_srcjrn")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("report_def_srcjrn")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("start_srcrpt")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("summary_rpt")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("start_locsumrpt")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("report_def_locsum")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("set_resp")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("begin_work")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("commit_work")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("rollback_work")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getloc_ledger")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("periodwa")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("gl_curr_yr")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("putEnvValue")).toString());
		vector.addElement(new
StringBuffer(String.valueOf("getEnvValue")).toString());
		String astring[] = new String[vector.size()];
		vector.copyInto(astring);
		for(int i=0;i<vector.size();i++) {

theSPFuncs.put(vector.elementAt(i),vector.elementAt(i));
		}
		//return astring;
	}
    public boolean isWif(String theFileName) {
	    boolean theReturn = false;
	    int thePeriod =
theFileName.toUpperCase().lastIndexOf(".4GL");
		String theWifName = theFileName.substring(0,thePeriod
).toLowerCase() + ".wif";
		File theTest = new File(theWifName);
		if ( theTest.exists() == true ) theReturn = true;
		theTest = new File(theWifName.toUpperCase());
		if ( theTest.exists() == true ) theReturn = true;
		//System.out.println( theFileName);
		//System.out.println( theWifName );
		return theReturn;
	}
	public void doAllFilesIndicated() {

		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) {
					     if ( isCommentBlock() ==
false ) {
						     addTokens(s);
						 }
						 s =
noComments(bf.readLine());
					   }
					bf.close();
					testForFuncs(files[i]);
				}catch(Exception t) {
					t.printStackTrace();
					System.exit(255);
				}
             }
         }
		//System.out.println("Done");

	}
	public void testForFuncs(String fileName) {
		String theImportList = "";
		String theSuffix = "\"\n";
		String theInclude = "INCLUDE \"";
		if (hasSPFunc() == true)
		  if ( isAlreadyIncluded(fileName,sp) == false)
		      theImportList = theImportList + theInclude + sp
+ theSuffix;
		if (hasRPTFunc() == true)
    	  if ( isAlreadyIncluded(fileName,rpt) == false)
		      theImportList = theImportList + theInclude + rpt
+ theSuffix;
		if (hasEXFunc() == true)
    	  if ( isAlreadyIncluded(fileName,ex) == false)
		      theImportList = theImportList + theInclude + ex
+ theSuffix;
		if (hasGLFunc() == true)
    	  if ( isAlreadyIncluded(fileName,gl) == false)
		      theImportList = theImportList + theInclude + gl
+ theSuffix;
		if (hasCMFunc() == true)
    	  if ( isAlreadyIncluded(fileName,cm) == false)
		      theImportList = theImportList + theInclude + cm
+ theSuffix;
		if (theImportList != "")
insertImportList(fileName,theImportList);
		theHashTable = new Hashtable(100);

	}
	public boolean isCommentBlock() {
	    return commentBlock;
	}
	public String noComments(String theLine) {
	    if (theLine == null ) return theLine;
	    if (theLeftBrace.search(theLine) == true){
		    if ( thePound.search(theLeftBrace.result().left())
== false
			     &&

theTwoDashes.search(theLeftBrace.result().left()) == false
				 )
				 {
				 if
(theRightBrace.search(theLeftBrace.result().right()) == false )
				    {
					  commentBlock = true; // a {
without a # or -- preceding
					  theLine =
theLeftBrace.result().left();
					  return theLine;
					}
                 else // a { with a } on the same line
				    {
					 if
(thePound.search(theRightBrace.result().left()) == false
						 &&

theTwoDashes.search(theRightBrace.result().left()) == false
						 )
						 {
					      theLine =
theLeftBrace.result().left() + theRightBrace.result().right();
					      return theLine;
						 }
                      else // } has been commented out
					     {
					      commentBlock = true; //
a { without a # or -- preceding
					      theLine =
theLeftBrace.result().left();
					      return theLine;
						 }
				    }

				 }
		}
		if (thePound.search(theLine) == true) theLine =
thePound.result().left();
		if (theTwoDashes.search(theLine) == true ) theLine =
theTwoDashes.result().left();

        if (theRightBrace.search(theLine) == true ) {
		    commentBlock = false;
			theLine = theRightBrace.result().right();
			}

	    return theLine;
	}
	public void insertImportList(String theFileName, String
theImportList) {
	    int thePeriod =
theFileName.toUpperCase().lastIndexOf(".4GL");
		String theTmpName = theFileName.substring(0,thePeriod
).toLowerCase() + ".tmp";
	    try {
			 out = new PrintWriter(new BufferedWriter(new
FileWriter(theTmpName)));
		}
		catch (IOException iex) {
			 System.out.println("IOexception out is NULL"
);
		}

		if (out != null ) {
		    out.println(theImportList);
			try {
				FileReader ff=new
FileReader(theFileName);
				BufferedReader bf=new
BufferedReader(ff);
				String s = bf.readLine();
				while(s != null) {
					 if (s != null )
out.println(s);
					 s = bf.readLine();
				   }
			    bf.close();
                }
            catch (Exception t) {
					t.printStackTrace();
					System.out.println("Fatal
Error Exiting");
					System.exit(255);
				}

			out.close();
			reWriteFile(theFileName,theTmpName);
		}
	}
	public void reWriteFile(String theOrigName, String theTmpName)
{
        PrintWriter out = null;
		File theTmpFile = new File(theTmpName);
	    try {
			 out = new PrintWriter(new BufferedWriter(new
FileWriter(theOrigName)));
		}
		catch (IOException iex) {
			 System.out.println("IOexception out is NULL"
);
		}

		if (out != null ) {
			try {
				FileReader ff=new
FileReader(theTmpName);
				BufferedReader bf=new
BufferedReader(ff);
				String s = bf.readLine();
				while(s != null) {
					 if (s != null )
out.println(s);
					 s = bf.readLine();
				   }
			    bf.close();
                }
            catch (Exception t) {
					t.printStackTrace();
					System.out.println("Fatal
Error Exiting");
					System.exit(255);
				}

			out.close();
            if ( theTmpFile.delete() != true)
System.out.println("Could Not Delete " + theTmpName);
			}

	}
	Regex dpat;
	PrintWriter out = null;
	Hashtable theHashTable = new Hashtable(100);
	Hashtable theSPFuncs = new Hashtable();
	Hashtable theGLFuncs = new Hashtable();
	Hashtable theEXFuncs = new Hashtable();
	Hashtable theCMFuncs = new Hashtable();
	Hashtable theRPTFuncs = new Hashtable();
	Hashtable localFuncs = new Hashtable();
	Vector localFuncVector = new Vector();
	Hashtable localIncludes = new Hashtable();
	Vector localIncludeVector = new Vector();
	String theFilter = "*.4gl";
	boolean commentBlock = false;
	Regex thePound =  new Regex("#");
	Regex theTwoDashes = new Regex("--");
	Regex theLeftBrace = new Regex("{");
	Regex theRightBrace = new Regex("}");
	String rpt = "rpt.4gh";
	String cm  = "cm.4gh";
	String ex  = "ex.4gh";
	String gl  = "gl.4gh";
	String sp  = "sp.4gh";
}