From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libjava/gnu/gcj/convert/Convert.java | 189 +++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 libjava/gnu/gcj/convert/Convert.java (limited to 'libjava/gnu/gcj/convert/Convert.java') diff --git a/libjava/gnu/gcj/convert/Convert.java b/libjava/gnu/gcj/convert/Convert.java new file mode 100644 index 000000000..e0662b710 --- /dev/null +++ b/libjava/gnu/gcj/convert/Convert.java @@ -0,0 +1,189 @@ +/* Copyright (C) 1999, 2002, 2005, 2006, 2007, 2008, 2009, 2010, 2011 + Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.convert; +import java.io.*; + +public class Convert +{ + static void error (String message) + { + System.err.print("jv-convert: "); + System.err.println(message); + System.err.println("Try `jv-convert --help' for more information."); + System.exit(1); + } + + static void help () + { + System.out.println("Usage: jv-convert [OPTIONS] [INPUTFILE [OUTPUTFILE]]"); + System.out.println(); + System.out.println("Convert from one encoding to another."); + System.out.println(); + System.out.println(" --encoding FROM"); + System.out.println(" --from FROM use FROM as source encoding name"); + System.out.println(" --to TO use TO as target encoding name"); + System.out.println(" -i FILE read from FILE"); + System.out.println(" -o FILE print output to FILE"); + System.out.println(" --reverse swap FROM and TO encodings"); + System.out.println(" --help print this help, then exit"); + System.out.println(" --version print version number, then exit"); + System.out.println(); + System.out.println("`-' as a file name argument can be used to refer to stdin or stdout."); + System.exit(0); + } + + static void version () + { + System.out.println("jv-convert (" + + System.getProperty("java.vm.name") + + ") " + + System.getProperty("java.vm.version")); + System.out.println(); + System.out.println("Copyright (C) 2011 Free Software Foundation, Inc."); + System.out.println("This is free software; see the source for copying conditions. There is NO"); + System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); + System.exit(0); + } + + static void missing (String arg) + { + error("missing arg after `" + arg + "' option"); + } + + public static void main (String[] args) + { + String inName = "-"; + String outName = "-"; + String inEncodingName = null; + String outEncodingName = "JavaSrc"; + int seenNames = 0; + boolean reverse = false; + + for (int i = 0; i < args.length; i++) + { + String arg = args[i]; + if (arg.length() == 0) + error("zero-length argument"); + if (arg.charAt(0) == '-') + { + if (arg.equals("-encoding") || arg.equals("--encoding") + || args.equals("-from") || arg.equals("--from")) + { + if (++i == args.length) missing(arg); + inEncodingName = args[i]; + } + else if (arg.equals("-to") || arg.equals("--to")) + { + if (++i == args.length) missing(arg); + outEncodingName = args[i]; + } + else if (arg.equals("-i")) + { + if (++i == args.length) missing(arg); + inName = args[i]; + } + else if (arg.equals("-o")) + { + if (++i == args.length) missing(arg); + outName = args[i]; + } + else if (arg.equals("-reverse") || arg.equals("--reverse")) + { + reverse = true; + } + else if (arg.equals("-help") || arg.equals("--help")) + { + help (); + } + else if (arg.equals("-version") || arg.equals("--version")) + { + version (); + } + else if (arg.equals("-")) + { + switch (seenNames) + { + case 0: + inName = "-"; + seenNames++; + break; + case 1: + outName = "-"; + seenNames++; + break; + default: + error("too many `-' arguments"); + } + } + else + error("unrecognized argument `" + arg + "'"); + } + else + { + switch (seenNames) + { + case 0: + inName = arg; + seenNames++; + break; + case 1: + outName = arg; + seenNames++; + break; + default: + error("too many filename arguments"); + } + } + } + + if (reverse) + { + String tmp = inEncodingName; + inEncodingName = outEncodingName; + outEncodingName = tmp; + } + + try + { + InputStream inStream = inName.equals("-") ? System.in + : new FileInputStream(inName); + OutputStream outStream; + if (outName.equals("-")) + outStream = System.out; + else + outStream = new FileOutputStream(outName); + InputStreamReader in + = (inEncodingName == null + ? new InputStreamReader(inStream) + : new InputStreamReader(inStream, inEncodingName)); + OutputStreamWriter out + = (outEncodingName == null + ? new OutputStreamWriter(outStream) + : new OutputStreamWriter(outStream, outEncodingName)); + char[] buffer = new char[2048]; + for (;;) + { + int count = in.read(buffer); + if (count < 0) + break; + out.write(buffer, 0, count); + } + + in.close(); + out.close(); + } + catch (java.io.IOException ex) + { + System.err.print("jv-convert exception: "); + System.err.println(ex); + System.exit(-1); + } + } +} -- cgit v1.2.3