/** File: Switches.java */ /** * File Switches class used to parse the switches from the command line * args passed as argsV[]. The parsed switches are stored in the Globals * variables through the main class HTMLtools cvt instance. * Until we [REFACTOR] the JTV (Java TreeView) converter to * a separate application, the variables reside here. * *
 * List of Methods
 * parseSwitches() - parse the command line args and set Global variables.
 * getCleanArgList() - Remove # prefaced and "" lines and resize argsV.
 * parseGBSswitches() - parse curSW switch to see if it is a GBS option.
 * parseTIswitches() - parse curSW switch to see if it is a TI option
 * parseJTVswitches() - parse JTV command line args and set Global variables.
 * createHeaderNameMapTable() - create header name map table and lists, flags.
 * 
*

* This code is available at the HTMLtools project on SourceForge at * http://htmltools.sourceforge.net/ * under the "Common Public License Version 1.0" * * http://www.opensource.org/licenses/cpl1.0.php.

*

* It was derived and refactored from the open source * MAExplorer (http://maexplorer.sourceforge.net/), and * Open2Dprot (http://Open2Dprot.sourceforge.net/) Table modules. *

* $Date: 2009/11/14 11:45:56 $ $Revision: 1.36 $ *
* Copyright 2008, 2009 by Peter Lemkin * E-Mail: lemkin@users.sourceforge.net * http://lemkingroup.com/ *
*/ public class Switches { /* Note all global variables are in Globals.java except the help * messages which are in HelpMsgs.java. */ public HTMLtools cvt; /** Global fileTable instance */ public FileTable fio; /** * Switches() - Constructor. * Note: should only be called after set up fio in cvt. */ public Switches(HTMLtools cvt) { /* Switches */ this.cvt= cvt; this.fio= cvt.fio; } /* Switches */ /** * parseSwitches() - parse the arg list and set global switches and * variables. Note some of the switches may have multiple instances * including: -files, -hrefData, -hrefHeaderRow -dropColumn, -keepColumn, * -reorderColumn, -sortTableByColumn, -mapQuestionmarks. * You only need to enter the minimum part of the switch described * in the {@link HelpMsgs#COMMAND_MSG} documentation. * See documentation in HelpMsgs.java for details. * Note: the switches are case sensitive. * @param argsV is list of command line switches * @return true if succeed, false if fail or just need to go on to * the next param set to process * * @see FileTable#readFileAsString * @see UtilCM#cvs2Array * @see UtilCM#cvs2i * @see UtilCM#cvs2f * @see UtilCM#setLogMsgs * @see UtilCM#getLogMsgs * @see UtilCM#logMsgs * @see FileTable#readFileAsTable * @see FileTable#setHasTableHeaderFlag * @see FileTable#setRmvTrailingBlankLinesFlag * @see FileTable#setRmvTrailingEmptyColumnsFlag */ public boolean parseSwitches(String argsV[]) { /* parseSwitches */ String curSW= null; int i= 0; boolean flag= true; /* clear DEBUG (name,value) list */ UtilCM.clearDebugNameValuePairs(); for(i= 0; i < argsV.length; i++) { /* special switch pre-processing */ curSW= argsV[i]; if(curSW.startsWith("#") || curSW.equals("")) continue; /* ignore comments and blank lines */ else if(curSW.startsWith("-addE")) { /* "-addEpilogueFile:{opt. file}" */ cvt.epilogueFile= "epilogue.html"; int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.epilogueFile= curSW.substring(idxColon + 1); } } else if(curSW.startsWith("-addO")) { /* "-addOutfilePostfix:{postfix name}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.addOutfilePostfixName= curSW.substring(idxColon + 1); } if(cvt.addOutfilePostfixName==null) cvt.addOutfilePostfixName= ""; /* must not be null */ } else if(curSW.startsWith("-addP")) { /* "-addPrologFile:{opt file}" */ cvt.prologFile= "prolog.html"; int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.prologFile= curSW.substring(idxColon + 1); } } else if(curSW.startsWith("-addRow")) { /* "-addRowNumbers" */ cvt.addRowNumbersFlag= true; } else if(curSW.startsWith("-addT")) { /* "-addTableName:{table name to use}" */ cvt.addTableNameFlag= true; int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.addTableName= curSW.substring(idxColon + 1); } else { UtilCM.logMsg("Bad -addTableName:{table name to use}" + " switch usage.\n"); flag= false; break; } } else if(curSW.startsWith("-allowH")) { /* "-allowHdrDups" */ cvt.ignoreDuplicateFieldsFlag= true; } else if(curSW.startsWith("-alt")) { /* "-alternateRowBackgroundColor:{background color}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String cName= curSW.substring(idxColon + 1); cvt.altRowBackgroundColor= UtilCM.cvtHTMLcolorNameToHex(cName); } else { UtilCM.logMsg("Bad -alternateRowBackgroundColor:" + "{background color}" + " switch usage.\n"); flag= false; break; } } else if(curSW.startsWith("-batchP")) { /* "-batchProcess:{file of param specs, opt. new working dir}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg and setup the batch process list */ String sTmp= curSW.substring(idxColon + 1); String sTmpA[]= UtilCM.cvs2Array(sTmp,","); cvt.batchProcessFile= sTmpA[0]; if(sTmpA.length>1) cvt.batchCwd= sTmpA[1]; else cvt.batchCwd= null; cvt.batchProcessStr= fio.readFileAsString(cvt.batchProcessFile); if(cvt.batchProcessStr==null) { /* Fatal error - save log and exit */ UtilCM.logMsg("Missing file '"+cvt.batchProcessFile+ "'in -batchProcess:{file of param spec.}" + " switch.\n"); cvt.closeProgram(-1); /* Close this down big time!!! */ } String bpStr2= UtilCM.mapCRLF2space(cvt.batchProcessStr); cvt.batchParamsSpecs= UtilCM.cvs2Array(bpStr2," "); cvt.maxBatchParamsSpecs= cvt.batchParamsSpecs.length; cvt.curBatchParamsSpecs= 0; cvt.batchProcessFlag= true; return(true); /* ignore the other switches and return now */ } /* get the arg and setup the batch process list */ else { UtilCM.logMsg("Bad -batchProcess:{file of param spec.}" + " switch usage.\n"); cvt.batchProcessFile= null; cvt.batchCwd= null; flag= false; break; } } /* "-batchProcess:{file of param specs, opt. new working dir}" */ else if(curSW.startsWith("-concat")) { /* "-concatTables:{outputConcatenateFile.txt,opt. noHTML}" */ cvt.concatInputFilesWithSameFieldsFlag= true; cvt.ftConcat= null; String baseCatFile= null, catFile= null, sMOD= null; int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1), sData[]= UtilCM.cvs2Array(sTmp,","); catFile= sData[0]; if(sData.length>1) sMOD= sData[1]; if(catFile.endsWith(".txt") || catFile.endsWith(".map") || catFile.endsWith(".htm")) baseCatFile= catFile.substring(0, catFile.length()-4); if(catFile.endsWith(".html")) baseCatFile= catFile.substring(0, catFile.length()-5); } else { UtilCM.logMsg("Bad -concatTables:{outputConcatenateFile.txt,opt. noHTML}" + " switch usage.\n"); cvt.batchProcessFile= null; cvt.batchCwd= null; flag= false; break; } cvt.concatOutputTxtFile= catFile; /* use what they tell us to use */ if(sMOD!=null && sMOD.equalsIgnoreCase("noTXT")) { cvt.makeTXTflag= false; /* default is true */ } if(sMOD==null || !sMOD.equalsIgnoreCase("noHTML")) cvt.concatOutputHtmlFile= baseCatFile + ".html"; else { cvt.concatOutputHtmlFile= null; cvt.makeHTMLflag= false; /* default is true */ } } /* "-concatTables:{outputConcatenateFile.txt,opt. noHTML}" */ else if(curSW.startsWith("-copyF")) { /* "-copyFile:{srcFile,dstFile}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1); /* parse the strings */ int idxComma= sTmp.indexOf(","); if(idxComma!=-1) { /* push it onto the copy tree lists */ if(cvt.nCopyFile==0) { /* allocate storage first time need it */ cvt.copySrcFile= new String[cvt.MAX_COPY_FILES_AND_TREES]; cvt.copyDstFile= new String[cvt.MAX_COPY_FILES_AND_TREES]; } /* Save instance of "-copyFile:{srcFile,dstFile}" */ cvt.copyFileFlag= true; cvt.copySrcFile[cvt.nCopyFile]= sTmp.substring(0, idxComma); cvt.copyDstFile[cvt.nCopyFile++]= sTmp.substring(idxComma + 1); } } /* get the arg */ else { cvt.copyTreeDataFlag= false; UtilCM.logMsg("Bad -copyFile:{srcTreeFiles,destPath}" + " switch usage - ignoring switch.\n"); flag= false; break; } } /* "-copyFile:{srcFile,dstFile}" */ else if(curSW.startsWith("-copyT")) { /* "-copyTree:{srcTreeFiles,destPath}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1); /* parse the strings */ int idxComma= sTmp.indexOf(","); if(idxComma!=-1) { /* push it onto the copy tree lists */ if(cvt.nCopyTreeDir==0) { /* allocate storage first time need it */ cvt.copyTreeSrcDir= new String[cvt.MAX_COPY_FILES_AND_TREES]; cvt.copyTreeDstDir= new String[cvt.MAX_COPY_FILES_AND_TREES]; } /* Save instance of "-copyTree:{srcTreeFiles,destPath}" */ cvt.copyTreeDataFlag= true; cvt.copyTreeSrcDir[cvt.nCopyTreeDir]= sTmp.substring(0, idxComma); cvt.copyTreeDstDir[cvt.nCopyTreeDir++]= sTmp.substring(idxComma + 1); } } /* get the arg */ else { cvt.copyTreeDataFlag= false; UtilCM.logMsg("Bad -copyTree:{srcTreeFiles,destPath}" + " switch usage - ignoring switch.\n"); flag= false; break; } } /* "-copyTree:{srcTreeFiles,destPath}" */ else if(curSW.startsWith("-dataP")) { /*'-dataPrecisionHTMLtable:{nbr digits precision}' */ cvt.dataPrecisionHTMLtable= -1; int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg(s) */ String sTmp= curSW.substring(idxColon + 1); cvt.dataPrecisionHTMLtable= UtilCM.cvs2i(sTmp,-1); } } else if(curSW.startsWith("-debug")) { /* "-debug:{debugName,debugValue}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg(s) */ String sTmp= curSW.substring(idxColon + 1); String sTmpA[]= UtilCM.cvs2Array(sTmp,","); if(sTmpA.length!=2) { UtilCM.logMsg("Bad -debug:{debugName,debugValue}" + " switch usage - ignoring switch '"+curSW+"'\n"); } else { /* save switch */ String debugName= sTmpA[0], debugValue= sTmpA[1]; if(!UtilCM.setDebugNameValue(debugName,debugValue)) { UtilCM.logMsg("Problem, too many -debug:{debugName,debugValue}" + " switchs usage - ignoring switch '"+curSW+"'\n"); } } /* save switch */ } /* get the arg(s) */ }/* "-debug:{debugName,debugValue" */ else if(curSW.startsWith("-dirI")) { /* "-dirIndexHtml:{dir,'O'verride}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1); /* parse the strings */ int idxComma= sTmp.indexOf(","); if(idxComma!=-1) { /* push it onto the copy tree lists */ if(cvt.nDirIndexHtml==0) { /* allocate storage first time need it */ cvt.dirIndexHtmlFlag= true; cvt.dirIndexHtml= new String[cvt.MAX_COPY_FILES_AND_TREES]; cvt.dirIndexHtmlOverrideFlag= new boolean[cvt.MAX_COPY_FILES_AND_TREES]; } /* Save instance of "-dirIndexHtml:{dir,'O'verride}" */ cvt.dirIndexHtml[cvt.nDirIndexHtml]= sTmp.substring(0, idxComma); String sOveride= sTmp.substring(idxComma + 1,idxComma+2); boolean overrideFlag= (sOveride.equalsIgnoreCase("O")); cvt.dirIndexHtmlOverrideFlag[cvt.nDirIndexHtml++]= overrideFlag; } } /* get the arg */ else { cvt.dirIndexHtmlFlag= false; UtilCM.logMsg("Bad -dirIndexHtml:{dir,'O'verride}" + " switch usage - ignoring switch '"+curSW+"'\n"); flag= false; break; } } /* "-dirIndexHtml:{dir,'O'verride}" */ else if(curSW.startsWith("-dropC")) { /* "-dropColumnName:{column header name}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ if(cvt.dropColNames==null) cvt.dropColNames= new String[cvt.MAX_COL_EDITS]; String sDrop= curSW.substring(idxColon + 1); cvt.dropColNames[cvt.nDropColNames++]= sDrop; } else { UtilCM.logMsg("Bad -dropColumnName:{column header name}" + " switch usage.\n"); flag= false; break; } } else if(curSW.startsWith("-exportB")) { /* "-exportBigCellsToHTMLfile:{opt. size for big}" */ cvt.exportBigCellsToHTMLfileFlag= true; cvt.bigExportCellThr= cvt.EXPORT_BIG_CELL_SIZE; int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1); cvt.bigExportCellThr= UtilCM.cvs2i(sTmp, cvt.EXPORT_BIG_CELL_SIZE); } } /* "-exportBigCellsToHTMLfile:{opt. size for big}" */ else if(curSW.startsWith("-extractR")) { /* "-extractRow:{colName,rowNbr,resourceTblFile,htmlStyle}" */ /* cvt.extractColName, cvt.extractRowNbr, * cvt.extractResTblFile, cvt.extractHtmlStyle */ int idxColon= curSW.indexOf(":"), idxComma= -1, idxComma2= -1, idxComma3= -1, rowNbr= -1; String sColName= null, sRowNbr= null, sResTblFile= null, sHtmlStyle= null, sTmp2= null, sTmp3= null; if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1); /* parse the colHdrName and urlBaseLink strings */ idxComma= sTmp.indexOf(","); sColName= sTmp.substring(0, idxComma); sTmp2= sTmp.substring(idxComma + 1); idxComma2= sTmp2.indexOf(","); if(idxComma2 != -1) { /* get the 2nd, 3rd, & 4th args */ sRowNbr= sTmp2.substring(0, idxComma2); sTmp3= sTmp2.substring(idxComma2 + 1); idxComma3= sTmp3.indexOf(","); if(idxComma3 != -1) { /* get the 3rd, & 4th args */ sResTblFile= sTmp3.substring(0, idxComma3); sHtmlStyle= sTmp3.substring(idxComma3 + 1); sHtmlStyle= sHtmlStyle.toUpperCase(); } } } /* get the args */ rowNbr= UtilCM.cvs2i(sRowNbr,-1); /* make sure good # */ if(idxColon==-1 || idxComma==-1 || idxComma2==-1 || idxComma3==-1) { UtilCM.logMsg("Bad -extractRow:{colName,rowNbr," + "resourceTblFile,htmlStyle}} switch usage.\n" + "Missing arguments.\n"); flag= false; break; } else if(rowNbr<=-1) { UtilCM.logMsg("Bad -extractRow:{colName,rowNbr," + "resourceTblFile,htmlStyle}} switch usage.\n" + "Missing arguments.\n"); flag= false; break; } else if(!sHtmlStyle.equals("DL") && !sHtmlStyle.equals("OL") && !sHtmlStyle.equals("UL") &&!sHtmlStyle.equals("TABLE")) { UtilCM.logMsg("Bad -extractRow:{colName,rowNbr," + "resourceTblFile,htmlStyle}} switch usage.\n" + "HtmlStyle must be DT, OL, UL or TABLE.\n"); flag= false; break; } /* OK save it - process it later after get the keyword * from the table we will be processing. Lookup the resource * table at that time. */ cvt.extractRowFromResTblAsHTMLflag= true; cvt.extractColName= sColName; cvt.extractRowNbr= rowNbr; cvt.extractResTblFile= sResTblFile; cvt.extractHtmlStyle= sHtmlStyle; } /* "-extractRow:{colName,rowNbr,resourceTblFile,htmlStyle}" */ else if(curSW.startsWith("-fastE")) { /* '-fastEditFile:{opt. output file}' */ cvt.fastEditFileFlag= true; cvt.saveEditHTMLflag= false; cvt.makeHTMLflag= false; int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.saveEditedTable2File= curSW.substring(idxColon + 1); } } else if(curSW.startsWith("-files")) { /* "-files:{f1,f2,...,fn}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ String sFileList= curSW.substring(idxColon + 1); if(cvt.specificInputFileList == null) cvt.specificInputFileList= sFileList; else cvt.specificInputFileList+= "," + sFileList; } else { UtilCM.logMsg("Bad -files:{f1,f2,...,fn}" + " switch usage.\n"); flag= false; break; } } /* "-files:{f1,f2,...,fn}" */ else if(curSW.startsWith("-flipA")) { /* "-flipAclass:{flipAclass}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ cvt.flipAclass= curSW.substring(idxColon + 1); if(cvt.flipBclass!=null) cvt.reportFoldChangeFlag= true; } /* get the args */ else { UtilCM.logMsg("Bad -flipAclass:{flipAclass}"+ " switch usage.\n"); flag= false; break; } } /* "-flipAclass:{flipAclass}" */ else if(curSW.startsWith("-flipB")) { /* "-flipBclass:{flipBclass}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ cvt.flipBclass= curSW.substring(idxColon + 1); if(cvt.flipAclass!=null) cvt.reportFoldChangeFlag= true; } /* get the args */ else { UtilCM.logMsg("Bad -flipBclass:{flipBclass}"+ " switch usage.\n"); flag= false; break; } } /* "-flipBclass:{flipBclass}" */ else if(curSW.startsWith("-flipC")) { /* "-flipColumnName:{flipColumnFile,flipColumnNames}" or * "-flipColumnName:{*LIST*,flipColumnNames,v1,v2,...,vn}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1), tmpArgs[]= UtilCM.cvs2Array(sTmp,","); int nArgs= tmpArgs.length; if(nArgs<2) { UtilCM.logMsg("Bad -flipColumnName:{flipColumnFile,flipColumnNames}" + " switch usage.\n"); flag= false; break; } String flipColFile= tmpArgs[0], flipColName= tmpArgs[1], flipColValues[]= null; if(flipColFile.equals("*LIST*")) { /* build value list */ flipColValues= new String[nArgs-2]; for(int k=0;k0.0F) cvt.flipFCthrFlag= true; } /* get the args */ else { UtilCM.logMsg("Bad -flipFCthreshold:{flipFCthreshold}"+ " switch usage.\n"); cvt.flipFCthrFlag= true; flag= false; break; } } /* "-flipDirectory:{flipDirectory}" */ else if(curSW.startsWith("-flipO")) { /* "-flipOrderHdrColNames:{colHdrName1,colHdrName2,...,colHdrNameN}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1); /* Save column header order names */ String sList[]= UtilCM.cvs2Array(sTmp,","); cvt.flipOrderHdrColList= sList; cvt.nFlipOrderHdrColList= sList.length; } /* get the args */ else { UtilCM.logMsg("Bad -flipOrderHdrColNames:{colHdrName1,colHdrName2,"+ "...,colHdrNameN} switch usage.\n"); flag= false; break; } } /* "-flipOrderHdrColNames:{colHdrName1,colHdrName2,...,colHdrNameN}" */ else if(curSW.startsWith("-flipRowF")) { /* "-flipRowFilterNamesFile:{flipRowFilterNamesfile}" or * -flipRowFilterNames:{*LIST*,name1,name2,...,nameK} */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1), tmpArgs[]= UtilCM.cvs2Array(sTmp,","); int nArgs= tmpArgs.length; if(nArgs>1 && tmpArgs[0].equals("*LIST*")) { /* just get the list from the switches */ cvt.flipRowFilterNamesFile= tmpArgs[0]; /* "*LIST*" */ cvt.flipRowFilterNames= new String[nArgs-1]; cvt.nFlipRowFilterNames= nArgs-1; for(int k=0;k=2) { cvt.flipDataFile= sList[0]; cvt.flipIndexMapFile= sList[1]; if(sList.length>=3) cvt.maxFlipSeekRowsToExtract= UtilCM.cvs2i(sList[2],100); cvt.flipTableByIndexMapFlag= true; } } /* get the args */ if(!cvt.flipTableByIndexMapFlag) { UtilCM.logMsg("Bad -flipTableByIndexMap:{flipDataFile,"+ "flipIndexMapFile,(opt)maxRows} " + "switch usage.\n"); flag= false; break; } } /* "-flipTableByIndexMap:{flipDataFile,flipIndexMapFile,(opt)maxRows" */ else if(curSW.startsWith("-flipU")) { /* "-flipUseExactColumnNameMatch:{TRUE | FALSE}" */ int idxColon= curSW.indexOf(":"); cvt.flipTableUseExactMatchFlag= false; if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1); cvt.flipTableUseExactMatchFlag= true; /* Default */ if(sTmp.startsWith("F") || sTmp.startsWith("f")) cvt.flipTableUseExactMatchFlag= false; } } /* "-flipUseExactColumnNameMatch:{TRUE | FALSE}" */ else if(curSW.startsWith("-font")) { /* "-fontSizeHtml:{font Size modifier}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ /* Use an HTML font size!= 0, i.e. +1, +2, -1, -2, etc. */ cvt.useHTMLfontSize= curSW.substring(idxColon + 1); } else { UtilCM.logMsg("Bad -fontSizeHtml:{font Size modifier}" + " switch usage.\n"); flag= false; break; } } /* "-fontSizeHtml:{font Size modifier}" */ else if(curSW.startsWith("-gui")) { /* "-gui" - start the Converter GUI version */ cvt.createCvtGUI(); flag= false; break; } /* "-gui" - start the Converter GUI version */ else if(curSW.startsWith("-help") || curSW.equals("?")) { /* "-help" */ UtilCM.setLogMsgs(true); UtilCM.logMsg(cvt.title+"\n"+ cvt.programName+" program\n"+ "Convert tab-delimited text file Tables to HTML files and other mappings.\n"+ "Date: "+cvt.date+"\n"); UtilCM.logMsg("Read the "+cvt.referenceManual+ " file for full documentation.\n"); /* Following is available in case someone else wants to read it. */ //String loggingStr= UtilCM.getLogMsgs(); flag= false; /* no more processing of the command list */ break; } else if(curSW.startsWith("-hasE")) { /* "-hasEmptyLineBeforeTable" */ cvt.hasEmptyLineBeforeTableFlag= true; } else if(curSW.startsWith("-hdrL")) { /* "-hdrLines:{nbr of lines in header}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ /* Use an HTML font size!= 0, i.e. +1, +2, -1, -2, etc. */ String sTmp= curSW.substring(idxColon + 1); cvt.nbrTableHdrLines= UtilCM.cvs2i(sTmp, 1); } else { UtilCM.logMsg("Bad -hdrLines:{nbr of lines in header}" + " switch usage.\n"); flag= false; break; } } /* "-hdrLines:{nbr of lines in header}" */ else if(curSW.startsWith("-hdrM")) { /* "-hdrMapName:{oldHdrColName,newHdrColName}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1); /* parse the oldHdrColName and newHdrColName strings */ int idxComma= sTmp.indexOf(","); if(idxComma!=-1) { String keyword= sTmp.substring(0, idxComma), toString= sTmp.substring(idxComma + 1); if(cvt.nHdrMapColNames==0) { cvt.oldHdrMapColNames= new String[cvt.MAX_COL_EDITS]; cvt.newHdrMapColNames= new String[cvt.MAX_COL_EDITS]; } cvt.oldHdrMapColNames[cvt.nHdrMapColNames]= keyword; cvt.newHdrMapColNames[cvt.nHdrMapColNames++]= toString; } } /* get the arg */ else { cvt.nHdrMapColNames= 0; UtilCM.logMsg("Bad -hdrMapName:{oldHdrColName,newHdrColName}" + " switch usage - ignoring these switches.\n"); flag= false; break; } } /* "-hdrMapName:{oldHdrColName,newHdrColName}" */ else if(curSW.startsWith("-hrefD")) { /* "-hrefData:{colHdrName,UrlBaseLink,mapTokenInUrl}" */ int idxColon= curSW.indexOf(":"), idxComma= -1, idxComma2= -1; if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1); /* parse the colHdrName and urlBaseLink strings */ idxComma= sTmp.indexOf(","); if(cvt.nColUrlHmapData == 0) { /* Allocate at this time */ cvt.colHdrNameHmapData= new String[cvt.MAX_COL2URL_MAPS]; cvt.urlBaseLinkHmapData= new String[cvt.MAX_COL2URL_MAPS]; cvt.mapTokenInUrlHmapData= new String[cvt.MAX_COL2URL_MAPS]; } String sColName= sTmp.substring(0, idxComma), sTmp2= sTmp.substring(idxComma + 1), sHREF= null, sMapTok= null; idxComma2= sTmp2.indexOf(","); if(idxComma2 == -1) sHREF= sTmp2; /* just use 2nd arg */ else { /* get the 2nd & 3rd arg */ sHREF= sTmp2.substring(0, idxComma2); sMapTok= sTmp2.substring(idxComma2 + 1); } cvt.colHdrNameHmapData[cvt.nColUrlHmapData]= sColName; cvt.urlBaseLinkHmapData[cvt.nColUrlHmapData]= sHREF; cvt.mapTokenInUrlHmapData[cvt.nColUrlHmapData]= sMapTok; cvt.nColUrlHmapData++; } /* get the args */ if(idxColon==-1 || idxComma==-1) { UtilCM.logMsg("Bad -hrefData:{colHdrName,UrlBaseLink," + "mapTokenInUrl} switch usage.\n"); return(false); } } /* "-hrefData:{colHdrName,UrlBaseLink,mapTokenInUrl}" */ else if(curSW.startsWith("-hrefH")) { /* "-hrefHeaderRow" */ cvt.hrefHeaderRowFlag= true; } else if(curSW.startsWith("-inputD")) { /* "-inputDir:{inputTXTdir}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.inputDataDir= curSW.substring(idxColon + 1); if(!cvt.inputDataDir.endsWith("/") && !cvt.inputDataDir.endsWith("\\")) cvt.inputDataDir += cvt.fileSep; } else { UtilCM.logMsg("Bad -inputDir:{inputTXTdir} switch usage.\n"); flag= false; break; } } /* "-inputDir:{inputTXTdir}" */ else if(curSW.startsWith("-joinT")) { /* "-joinTableFile:{joinTableFile}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.joinTableFile= curSW.substring(idxColon + 1); if(cvt.joinTableFile==null || cvt.joinTableFile.length()==0) cvt.joinTableFile= null; } else { cvt.joinTableFile= null; UtilCM.logMsg("Bad -joinTableFile:{joinTableFile} switch usage.\n"); flag= false; break; } } else if(curSW.startsWith("-keepC")) { /* "-keepColumnName:{column header name}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ if(cvt.keepColNames==null) cvt.keepColNames= new String[cvt.MAX_COL_EDITS]; String sDrop= curSW.substring(idxColon + 1); cvt.keepColNames[cvt.nKeepColNames++]= sDrop; } else { UtilCM.logMsg("Bad -keepColumnName:{column header name}" + " switch usage.\n"); flag= false; break; } } /* "-keepColumnName:{column header name}" */ else if(curSW.startsWith("-limitM")) { /* "-limitMaxTableRows:{maxNbrRows,(opt.)sortFirstByColName, (opt.)'A'scending or 'D'escending}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1); String sList[]= UtilCM.cvs2Array(sTmp,","); int maxKeepRows= UtilCM.cvs2i(sList[0],0); if(maxKeepRows>0) { cvt.limitMaxTableRows= maxKeepRows; cvt.limitMaxTableRowsFlag= true; cvt.limitRowsSortByColName= null; cvt.limitRowsSortAscendingFlag= false; if(sList.length>=2) cvt.limitRowsSortByColName= sList[1]; if(sList.length>=3) { char cAscending= sList[2].charAt(0); if(cAscending=='A' ||cAscending=='a') cvt.limitRowsSortAscendingFlag= true; } } } }/* "-limitMaxTableRows:{maxNbrRows,(opt.)sortFirstByColName, (opt.)'A'scending or 'D'escending}" */ else if(curSW.startsWith("-log")) { /* "-logging:{new log file name}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the args */ String tmp= curSW.substring(idxColon + 1); if(tmp.endsWith(".log")) cvt.logFileName= tmp; } } /* "-logging:{new log file name}" */ else if(curSW.startsWith("-makeI")) { /* '-makeIndexMapFile:{colName1,...,colNameN}' */ int idxColon= curSW.indexOf(":"); String colNameList[]= null; if(idxColon != -1) { /* get list of column names */ String sTmp= curSW.substring(idxColon + 1); colNameList= UtilCM.cvs2Array(sTmp,","); if(colNameList!=null && colNameList.length>=1) { /* Stuff switches with rest of args */ cvt.makeIndexMapFile= null; /* will be input file w/ ".idx" */ cvt.nColNameIndexMap= colNameList.length; cvt.colNameIndexMap= colNameList; cvt.makeIndexMapFileFlag= true; } } /* get index map name, keyRowWord and list of column names */ else { UtilCM.logMsg("Bad -makeIndexMapFile:{colName1,...,colNameN}'" + " switch usage.\n"); flag= false; break; } } /* '-makeIndexMapFile:{colName1,...,colNameN}' */ else if(curSW.startsWith("-makeM")) { /* -makeMapFile:{mapTblFileName,orderedCommaColumnList} */ int idxColon= curSW.indexOf(":"), idxComma= -1; if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1); /* parse the colHdrName and urlBaseLink strings */ idxComma= sTmp.indexOf(","); if(idxComma!=-1) { /* parse args */ String mapNameFile= sTmp.substring(0, idxComma), orderedCommaColList= sTmp.substring(idxComma + 1), colList[]= UtilCM.cvs2Array(orderedCommaColList,","); if(colList==null) idxComma= -1; /* force error */ else { /* save args */ cvt.makeMapTblFileName= mapNameFile; if(colList[0].equals("")) { /* no list indicates to use ftConcat.tFields[] list */ cvt.makeMapColNames= null; /* used as a flag */ cvt.nMakeMapColNames= -1; /* used as a flag */ } else { /* Save the mapping list */ cvt.makeMapColNames= colList; cvt.nMakeMapColNames= colList.length; } } } /* parse args */ } /* get the args */ if(idxColon==-1 || idxComma==-1) { UtilCM.logMsg("Bad -makeMapFile:{mapTblFileName," + "orderedCommaColumnList} switch usage.\n"); cvt.makeMapTblFileName= null; cvt.makeMapColNames= null; cvt.nMakeMapColNames= 0; flag= false; break; } } /* -makeMapFile:{mapTblFileName,orderedCommaColumnList} */ else if(curSW.startsWith("-makeP")) { /* "-makePrefaceHTML" */ cvt.makePrefaceHTMLflag= true; } else if(curSW.startsWith("-makeS")) { /* "-makeStatisticsIndexMapFile" */ cvt.makeStatisticsIndexMapFlag= true; } else if(curSW.startsWith("-makeT")) { /* -makeTestsIntersectionTable:{testsToDoFile} */ int idxColon= curSW.indexOf(":"), idxComma= -1; cvt.makeTestsIntersectionTableFlag= false; if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1), colList[]= UtilCM.cvs2Array(sTmp,","); if(colList.length!=1) { UtilCM.logMsg("Bad -makeTestsIntersectionTable:"+ "{testsToDoFile} switch usage.\n"); flag= false; break; } cvt.testsToDoTblFile= colList[0]; cvt.makeTestsIntersectionTableFlag= true; } } /* -makeTestsIntersectionTable:{testsToDoFile} */ else if(curSW.startsWith("-mapD")) { /* "-mapDollarsigns:{keyword, toString}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1); /* parse the keyword and toString strings */ int idxComma= sTmp.indexOf(","); if(idxComma!=-1) { String keyword= sTmp.substring(0, idxComma), toString= sTmp.substring(idxComma + 1); if(cvt.mapDkeywords==null) { cvt.mapDkeywords= new String[cvt.MAX_MAP_DOLLARSIGNS]; cvt.mapDtoString= new String[cvt.MAX_MAP_DOLLARSIGNS]; cvt.mapDollarsignsFlag= true; } cvt.mapDkeywords[cvt.nMapDollarsigns]= keyword; cvt.mapDtoString[cvt.nMapDollarsigns++]= toString; } } /* get the arg */ else { cvt.mapQuestionmarksFlag= false; UtilCM.logMsg("Bad -mapDollarsigns:{keyword, toString}" + " switch usage - ignoring these switches.\n"); flag= false; break; } } /* "-mapDollarsigns:{keyword, toString}" */ else if(curSW.startsWith("-mapH")) { /* "-mapHdrNames:{mapFile,fromHdrName,toHdrName}" */ int idxColon= curSW.indexOf(":"); String mapNameFile= null, fromHdrName= null, toHdrName= null; if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1), mapArgs[]= UtilCM.cvs2Array(sTmp,","); if(mapArgs.length==3) { /* get the args */ mapNameFile= mapArgs[0]; fromHdrName= mapArgs[1]; toHdrName= mapArgs[2]; cvt.mapHdrNamesFile= mapNameFile; } } /* get the arg */ /* Create header name map table and lists and set flags. * This reads the mapFile Table into cvt.ftL2S. It must contain the * fromHdrName and toHdrName fields. It then creates * cvt.fromLongHdrNamesMap[cvt.nLong2ShortHdrNamesMap] and * cvt.toShortHdrNamesMap[cvt.nLong2ShortHdrNamesMap] lists that can * be used for mapping during file conversion and set the * cvt.mapLongToShortHdrNamesFlag. */ if(!createHeaderNameMapTable(mapNameFile,fromHdrName,toHdrName)) { UtilCM.logMsg("Bad -mapHdrNames:{mapNameFile,fromHdrName,"+ "toHdrName} switch usage.\n"); flag= false; break; } } /* "-mapHdrNames:{mapFile,fromFieldName,toFieldName}" */ else if(curSW.startsWith("-mapL")) { /* "-mapLongToShortHdrNames:{L2S names map,toColumnNbr}" */ /* [DEPRICATE] when fully convert mapping code to '-mapHdrNames'. */ UtilCM.logMsg("DRYROT [DEPRICATED] switch used "+ "'-mapLongToShortHdrNames:{L2SNamesMap,toColumnNbr}'.\n"); flag= false; break; } /* "-mapLongToShortHdrNames:{L2S names map, toColumnNbr}" */ else if(curSW.startsWith("-mapO")) { /* "-mapOptionsList" */ cvt.makeOptionsListFromSemicolonListFlag= true; } else if(curSW.startsWith("-mapQ")) { /* "-mapQuestionmarks:{keyword, toString}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ String sTmp= curSW.substring(idxColon + 1); /* parse the keyword and toString strings */ int idxComma= sTmp.indexOf(","); if(idxComma!=-1) { String keyword= sTmp.substring(0, idxComma), toString= sTmp.substring(idxComma + 1); if(cvt.mapQkeywords==null) { cvt.mapQkeywords= new String[cvt.MAX_MAP_QUESTIONMARKS]; cvt.mapQtoString= new String[cvt.MAX_MAP_QUESTIONMARKS]; cvt.mapQuestionmarksFlag= true; } cvt.mapQkeywords[cvt.nMapQuestionmarks]= keyword; cvt.mapQtoString[cvt.nMapQuestionmarks++]= toString; } } /* get the arg */ else { cvt.mapQuestionmarksFlag= false; UtilCM.logMsg("Bad -mapQuestionmarks:{keyword, toString}" + " switch usage - ignoring these switches.\n"); flag= false; break; } } /* "-mapQuestionmarks:{keyword, toString}" */ else if(curSW.startsWith("-noB")) { /* "-noBorder" */ cvt.noBorderFlag= true; } else if(curSW.startsWith("-noHeader")) { /* "-noHeader" */ cvt.hasTableHeaderRowFlag= false; } else if(curSW.startsWith("-noHTML")) { /* "-noHTML" */ cvt.makeHTMLflag= false; /* default is true */ } /* "-noHTML" */ else if(curSW.startsWith("-outputD")) { /* "-outputDir:{outputHTMLdir}" */ int idxColon= curSW.indexOf(":"); if(idxColon != -1) { /* get the arg */ cvt.outputDataDir= curSW.substring(idxColon + 1); if(!cvt.outputDataDir.endsWith("/") && !cvt.outputDataDir.endsWith("\\")) cvt.outputDataDir += cvt.fileSep; } else { UtilCM.logMsg("Bad -outputDir:{outputHTMLdir} switch usage.\n"); flag= false; break; } } /* "-outputDir:{outputHTMLdir}" */ else if(curSW.startsWith("-reorderC")) { /* "-reorderColumn:{colName,newColNbr}" */ int idxColon= curSW.indexOf(":"), idxComma=-1; if(idxColon != -1) { /* get the args */ String sTmp= curSW.substring(idxColon + 1); /* parse the colName, newColNbr strings */ idxComma= sTmp.indexOf(","); if(cvt.nReorderColName == 0) { /* Allocate at this time */ cvt.reorderColName= new String[cvt.MAX_COL2URL_MAPS]; cvt.reorderColNbr= new int[cvt.MAX_COL2URL_MAPS]; for(int k=0;k0 && cvt.nKeepColNames>0) { UtilCM.logMsg("Illegal switch combination. \n" + " Can't use both '-dropColumns' and '-keepColumns' " + "at the same time.\n"); flag= false; } if(cvt.nMakeMapColNames>0 && !cvt.concatInputFilesWithSameFieldsFlag) { UtilCM.logMsg("Illegal switch combination. \n" + " Can't use '-makeMapFile' without '-concatTables' " + " - ignoring '-makeMapFile'.\n"); cvt.nMakeMapColNames= 0; } if(cvt.saveEditedTable2File!=null && cvt.concatInputFilesWithSameFieldsFlag) { UtilCM.logMsg("Illegal switch combination. \n" + " Can't use '-concatTables' and " + "'-saveEditedTable2File' at the same time.\n"); flag= false; } /* Must only use "-hrefHeaderRow" is set as well as * "-hrefData:{colHdrName,UrlBaseLink,mapTokenInUrl} was * specified. Just clear it if set. */ if(cvt.nColUrlHmapData==0 && cvt.hrefHeaderRowFlag) cvt.hrefHeaderRowFlag= false; /* Can't use '-fastEditFile:{opt. output file}' and * '-saveEditedTable2File' at the same time. */ if(cvt.fastEditFileFlag && cvt.saveEditTableFlag) { UtilCM.logMsg("Illegal switch combination. \n" + " Can't use '-fastEditFile' and " + "'-saveEditedTable2File' at the same time.\n"); flag= false; } if(cvt.fastEditFileFlag && cvt.concatInputFilesWithSameFieldsFlag) { UtilCM.logMsg("Illegal switch combination. \n" + " Can't use '-concatTables' and " + "'-fastEditFile' switches at the same time.\n"); flag= false; } if(cvt.fastEditFileFlag && cvt.joinTableFile!=null) { UtilCM.logMsg("Illegal switch combination. \n" + " Can't use '-joinTableFile' and " + "'-fastEditFile' switches at the same time.\n"); flag= false; } if(cvt.genBatchScriptFlag) { /* make sure other switches are set */ if(cvt.genMapEGdetails==null || cvt.genMapIntroduction==null) { UtilCM.logMsg("Illegal switch combination.\n"+ "Must specify both -genMapEGdetails & -genMapIntroduction " + "with -genBatchScripts switch.\n"); flag= false; } } if(cvt.makeIndexMapFileFlag && cvt.makeStatisticsIndexMapFlag) { UtilCM.logMsg("Illegal switch combination. \n" + " Can't use '-makeIndexMapFile' and " + "'-makeStatisticsIndexMapFile' switches at the same time.\n"); flag= false; } return(flag); } /* parseSwitches */ /** * getCleanArgList() - Remove # prefaced comments and "" lines and make * argsV the exact size. * @param argsV - the command line or batch arg list * @return cleanArgsV[] if succeed, else null. */ public String[] getCleanArgList(String argsV[]) { /* getCleanArgList */ if(argsV==null) return(null); /* Remove # prefaced comments and "" lines and make argsV the * exact size. */ int nSW= argsV.length, nCleanSW= 0; /* Compute the number of clean switches not "" or starting with "#" */ for(int k=0;k