MechaniQue, the programming language for Interactive Fiction
Copyright (C) 2007 G.J.G.T. (Gabor) de Mooij
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation (highest version applies !!).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
---MECHANIQUESOFT/GABOR DE MOOIJ
public class toolbox
{
public static void say(String str)
{
System.out.println(str);
}
public static String ask()
{
String inp = "";
try{
InputStreamReader ISR = new InputStreamReader(System.in);
BufferedReader STDIN = new BufferedReader(ISR);
System.out.print(">");
inp = STDIN.readLine();
}
catch(Exception e)
{
}
return inp;
}
public static String rot13(String arg) {
String s = arg;
String n = "";
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 'a' && c <= 'm') c += 13;
else if (c >= 'n' && c <= 'z') c -= 13;
else if (c >= 'A' && c <= 'M') c += 13;
else if (c >= 'A' && c <= 'Z') c -= 13;
n += c;
}
return n;
}
public static boolean toFile(String fname, String contents){
FileOutputStream f;
try
{ f = new FileOutputStream (fname);
new PrintStream(f).println(contents);
f.close(); return true;
}
catch (IOException e)
{
System.out.println("[toolbox.toFile] ERROR :"+e);
return false;
}
}
public static boolean serialize(String fname, Serializable o)
{
try{
FileOutputStream fs = new FileOutputStream(fname);
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(o);
os.close();
return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
public static String fromFile(String fname){
StringBuffer content = new StringBuffer("");
try{
FileReader freader = new FileReader(fname);
BufferedReader buff = new BufferedReader(freader);
boolean firstline = true;
String line = "";
while (line!=null){
if (!firstline) content.append(line+"\n"); else firstline=false;
line=buff.readLine();
public static void speak(String text)
{
try{
Runtime.getRuntime().exec("say "+text);
}
catch(Exception e){
System.out.println("Speech not supported on this system.");
System.exit(0);
}
public static String[] regex(String text,String pattern)
{
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(text);
boolean b = false;
b = m.find();
if (b){
String[] groups = new String[m.groupCount()+1];
for(int j = 0; j <= m.groupCount(); j++)
{
groups[j] = m.group(j);
}
return groups;
} else {
String[] groups = new String[0];
return groups;
}