import gnu.getopt.LongOpt; import gnu.getopt.Getopt; import java.io.*; class mycopy5 { public static void main (String args[]) { final String _executable = "mycopy5"; /* Don't know how to set this automatically in Java */ final String VERSION = "3.0"; final int EOF = - 1; /* Is EOF predefined in Java? */ int i; int c; int length; OutputStreamWriter output_file; InputStreamReader input_file; boolean ofile = false, ifile = false; Cmdline cl = new Cmdline (args); if (cl.v ()) { System.out.println (_executable + " version " + VERSION); System.exit (0); } try { length = cl.o ().length (); if (length != 0) { output_file = new OutputStreamWriter (new FileOutputStream (cl.o ())); ofile = true; } else { output_file = new OutputStreamWriter (System.out); } if (cl.next_param () != 0) { input_file = new InputStreamReader (new FileInputStream (args[cl.next_param ()])); ifile = true; } else { input_file = new InputStreamReader (System.in); } for (i = 0; i < cl.i (); i++) { c = input_file.read (); while (c != EOF) { output_file.write (c); c = input_file.read (); } if (ifile) { input_file.close (); input_file = new InputStreamReader (new FileInputStream (args[cl.next_param ()])); } } input_file.close (); output_file.close (); } catch (IOException ex) { System.out.println ("File I/O error: " + ex); } System.exit (0); } }