import java.io.File;
import java.util.*;
public class Jute
{public static void main(String[] args)
throws UnrecognizedOPtion,
InvalidLinend
{String token[];
String subToken[];
String arguments = java.util.Arrays.toString(args);
String language = new String("en");
String country = new String("US");
Locale currentLocale = new Locale(language, country);
ResourceBundle messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
Map<String, String> globalSettings = new HashMap<String, String>();
final static String DISPLAY_MESSAGES = "displayMessages";
final static String DISPLAY_WINDOW = "displayWindow";
final static String LOCK_FILE = "lockFile";
final static String MAKE_DIFF = "makeDiff";
final static String RUN_PROFILE = "runProfile";
final static String PROFILE_NAME = "profileName";
final static String DIFF_TYPE = "diffType";
final static String LINEND = "linend";
final static String WIDTH = "width";
globalSettings.put(DISPLAY_MESSAGES, "true");
globalSettings.put(DISPLAY_WINDOW, "true");
globalSettings.put(LOCK_FILE, "false");
globalSettings.put(MAKE_DIFF, "false");
globalSettings.put(RUN_PROFILE, "true");
globalSettings.put(PROFILE_NAME, "profile");
globalSettings.put(DIFF_TYPE, "diff");
globalSettings.put(LINEND, "nl"); // TODO: make this dependent on the hosting OS.
globalSettings.put(WIDTH, "1000");
while (arguments.length > 0)
token = arguments;
if (arguments.startsWith("-") )
{token = token.split("[\s=]", 1);
switch (token[0].toLowerCase() )
{case isAbbrevIgnoreCase(token[0], "-Diff", 2):
globalSettings.put("makeDiff", "true");
break;
case isAbbrevIgnoreCase(token[0], "-NODiff", 4):
break;
case isAbbrevIgnoreCase(token[0], "-Git", 2):
globalSettings.put("diffType", "git");
break;
case isAbbrevIgnoreCase(token[0], "-Svn", 1):
globalSettings.put("diffType", "svn");
break;
case isAbbrevIgnoreCase(token[0], "-Help", 2):
/* Display usage info. and quit. */
break;
case isAbbrevIgnoreCase(token[0], "-Linend", 2):
{subToken = token[1].split("\s", 2);
if (subToken[0].matches("^\\p{Digit}+$") ) /* integer */
globalSettings.put("linend", token[0]);
else if (subToken[0].matches("^(\\p{Punct}).*\1") ) /* delimitedSstring */
{subToken = token[1].split(token[1].charAt(1), 2);
globalSettings.put("linend", subToken[1]);
}
else if (subToken[0].compareToIgnoreCase("nl") )
globalSettings.put("linend", "nl");
else if (subToken[0].compareToIgnoreCase("crnl") )
globalSettings.put("linend", "crnl");
else if (subToken[0].compareToIgnoreCase("crlf") )
globalSettings.put("linend", "crlf");
else
throw new InvalidLinend(subToken[0]);
break;
}
case isAbbrevIgnoreCase(token[0], "-LOck", 3):
globalSettings.put("lockFile", "true");
break;
case isAbbrevIgnoreCase(token[0], "-NOLock", 4):
break;
case isAbbrevIgnoreCase(token[0], "-Msg", 2):
break;
case isAbbrevIgnoreCase(token[0], "-NOMsg", 4):
globalSettings.put("displayMessages", "false");
break;
case isAbbrevIgnoreCase(token[0], "-Profile", 2):
subToken = token[1].split("\s", 2);
globalSettings.put("profileName", subToken[1]);
break;
case isAbbrevIgnoreCase(token[0], "-NOProfile", 4):
globalSettings.put("runProfile", "false");
break;
case isAbbrevIgnoreCase(token[0], "-WINdow", 4):
break;
case isAbbrevIgnoreCase(token[0], "-NOWindow", 4):
globalSettings.put("displayWindow", "false");
break;
case isAbbrevIgnoreCase(token[0], "-Width", 2):
subToken = token[1].split("\s", 2);
globalSettings.put("width", subToken[1]);
break;
default:
throw new UnrecognizedOPtion(token[0]);
}
}
arguments = token[1];
}
/* else */
/* {for (int A = 0; A < args.length; A++) */
/* frame.addDocument(new File(args[A])); */
/* */
/* if (displayWindow) */
/* {MainFrame frame = new MainFrame(); */
/* frame.insertNewDocument(); */
/* } */
/* } */
/* frame.setVisible(true); */
}
/* ================================================================================= */
/* Return true if testWord is an abbreviation of fullWord. Case must match. */
public static boolean isAbbrev(String testWord, String fullWord, int minLength)
{if (minLength <= testWord.length() &&
fullWord.length() >= testWord.length() &&
fullWord.startsWith(testWord)
)
return true;
return false;
}
/* --------------------------------------------------------------------------------- */
/* Return true if testWord is an abbreviation of fullWord. Case need not match. */
public static boolean isAbbrevIgnoreCase(String testWord, String fullWord, int minLength)
{String tw = testWord.toLowerCase();
String fw = fullWord.toLowerCase();
if (minLength <= tw.length() &&
fw.length() >= tw.length() &&
fw.startsWith(tw)
)
return true;
return false;
}
/* ================================================================================= */
/* Return fullWord if testWord is an abbreviation of fullWord, else null. */
/* Case must match. */
public static String isAbbrev(String testWord, String fullWord, int minLength)
{if (minLength <= testWord.length() &&
fullWord.length() >= testWord.length() &&
fullWord.startsWith(testWord)
)
return fullWord;
return null;
}
/* --------------------------------------------------------------------------------- */
/* Return fullWord if testWord is an abbreviation of fullWord; else null. */
/* Case need not match. */
public static String isAbbrevIgnoreCase(String testWord, String fullWord, int minLength)
{String tw = testWord;
String fw = fullWord;
if (minLength <= tw.length() &&
fw.length() >= tw.length() &&
fw.startsWith(tw)
)
return fullWord;
return null;
}
/* ================================================================================= */
/* Return the number of space-delimited words in phrase. */
public static int words(String phrase)
{Pattern pattern = Pattern.compile("\s");
Matcher matcher = pattern.matcher(phrase);
int numWords = 0;
while (matcher.find())
numWords += 1;
return numWords;
}
/* --------------------------------------------------------------------------------- */
/* Return the Wth word of phrase. */
public static String word(String phrase, int wordNum)
{String[] part;
part = phrase.split("\s", wordNum);
return part[wordNum - 1];
}
/* --------------------------------------------------------------------------------- */
/* Return N words of phrase starting with the Wth word. */
public static String subWord(String phrase, int wordNum, int numWords)
{String[] parts;
parts = phrase.split("\s");
return copyOfRange(parts, wordNum - 1, numWords);
}
/* ================================================================================= */
public class UnrecognizedOption extends Exception
{System.err.println(messages.getString("Jute001E");
System.err.println(messages.getString("Jute003I");
exit(1);
}
/* --------------------------------------------------------------------------------- */
public class InvalidLinend extends Exception
{System.err.println(messages.getString("Jute002E");
System.err.println(messages.getString("Jute003I");
exit(1);
}
/* ================================================================================= */
}