Skip to content

Commit

Permalink
Reworked mainline, added commandline checking, added --langfile= supp…
Browse files Browse the repository at this point in the history
…ort.
  • Loading branch information
icculus committed Jan 7, 2001
1 parent 875bcde commit 86a8f28
Showing 1 changed file with 89 additions and 10 deletions.
99 changes: 89 additions & 10 deletions last/toby/Toby.java
Expand Up @@ -19,6 +19,10 @@

package last.toby;

// !!! ugh.
import java.io.*;
import java.net.*;

import last.toby.gui.*;
import last.toby.util.*;

Expand All @@ -33,6 +37,8 @@ public final class Toby
public static final String TITLE = "Toby";
public static final String VERSION = "v1.0alpha5";

public static String sourceToLoad = null;

private static void kickOffGUI(String fileName)
{
TobyFrame toby = null;
Expand Down Expand Up @@ -76,21 +82,94 @@ private static void kickOffGUI(String fileName)
toby.openFile(fileName);
} // kickOffGUI

public static void printUsage()
{
System.err.println(TobyLanguage.USAGE);
System.err.println();
} // printUsage

public static void main(String[] args)
public static boolean checkCommandLine(String[] args)
{
if (Incompatibilities.checkForIncompatibilities() == false)
System.exit(0);
else
int max = args.length;
boolean tooManyFiles = false;

for (int i = 0; i < max; i++)
{
if (args.length <= 1)
kickOffGUI((args.length == 1) ? args[0] : null);
else
String arg = args[i].trim();

if (arg.startsWith("--") == true)
{
if (arg.startsWith("--langfile=") == true)
{
// !!! this is a bad system.
String s = arg.substring(11);
URL url = null;
try
{
url = new URL(s);
} // try
catch (MalformedURLException murle)
{
s = "file:///" + s;
try
{
url = new URL(s);
}
catch (MalformedURLException murle2)
{
// can't localize this.
System.err.println("Bad URL in --langfile!");
return(false);
} // catch
} // catch

try
{
System.out.println("loading from URL [" + url.toString() + "].");
TobyLanguage.loadLanguage(url);
} // try
catch (IOException ioe)
{
// can't localize this.
System.err.println("IOException reading langfile.");
System.err.println(ioe.getMessage());
return(false);
} // catch
} // if

else
{
printUsage();
return(false);
} // else
} // if

else // a non "--commandline" ...
{
System.err.println(TobyLanguage.USAGE);
System.err.println();
System.exit(0);
if (sourceToLoad != null)
tooManyFiles = true;
else
sourceToLoad = arg;
} // else
} // for

// this is here so --langfile gets processed before output.
if (tooManyFiles)
{
System.err.println(TobyLanguage.TOOMANYFILES);
return(false);
} // if

return(true);
} // checkCommandLine


public static void main(String[] args)
{
if (checkCommandLine(args) == true)
{
if (Incompatibilities.checkForIncompatibilities() == true)
kickOffGUI(sourceToLoad);
} // else
} // main

Expand Down

0 comments on commit 86a8f28

Please sign in to comment.