/* Copyright 2000 by Ralph Hartley This software is licenced under the terms of the Gnu Public Licence */ import java.security.*; import java.io.*; import java.text.*; import java.util.*; /** This class is used to keep track of which version of carto is running. *It has only static fields and can niether be subclassed nor instantiated. */ public final class Version implements java.io.Serializable{ /** Versions of carto with different serialversion *cannot read each others files. New serialversions *must be used sparingly if at all after any users *have the program. Even then, conversion programs would *have to be written. */ private static final long serialVersionUID = -48513234512356439L; public int majorversion = 0; public int minorversion = 0; /**The revision is automatically incremented each time the the program is uploaded */ public int rev = 0; public String date = "11/10/00 10:00 AM"; public Version() { try { read(getClass().getResource("version.txt").openStream()); } catch (IOException e) {ErrorLog.exception(e,"Trouble reading version info from jar"); } catch (NumberFormatException e) {ErrorLog.exception(e,"bad version info in jar"); } } public Version(String name) { try { read(new FileInputStream(name)); } catch (IOException e) {ErrorLog.exception(e,"Trouble reading version info from "+name); } catch (NumberFormatException e) {ErrorLog.exception(e,"bad version info in "+name); } } public void read(InputStream instr) throws IOException,NumberFormatException { BufferedReader in = new BufferedReader(new InputStreamReader(instr)); in.readLine(); in.readLine(); majorversion = Integer.parseInt(in.readLine()); in.readLine(); minorversion = Integer.parseInt(in.readLine()); in.readLine(); rev = Integer.parseInt(in.readLine()); in.readLine(); date = in.readLine(); } /** Returns the current version as a string. */ public String getVersion() { // if (branch.length()>0) // return(""+majorversion+"."+minorversion+"."+rev+"."+branch); // else return(""+majorversion+"."+minorversion+"."+rev); } static public long getSUID() { return(serialVersionUID); } public String getAbout() { return( "Copyright (C) 2000 Ralph Hartley\n"+ "CMAP2XML comes with ABSOLUTELY NO WARRANTY\n"+ "CMAP2XML is free software, you may redistribute under the\n"+ "terms of the Gnu Public Licence. For details see the file gpl.txt\n\n"+ "CMAP2XML version: "+getVersion()+ "\nUploaded on: "+date+ "\nJava runtime version: " + System.getProperty("java.version") +"\n"); } static public void main(String[] args) { Version current = new Version(); if (args.length==0) System.out.println(current.getVersion()); else try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); PrintStream out = new PrintStream(new FileOutputStream(args[1])); if (args.length>2 && args[2].charAt(0)=='r') current.rev++; if (args.length>2 && args[2].charAt(0)=='i') { current.minorversion++; current.rev=0; } if (args.length>2 && args[2].charAt(0)=='m') { current.majorversion++; current.rev=current.minorversion=0; } for (String line = in.readLine(); line!=null; line = in.readLine()) { line = replace(line,"@@"+"@",current.getVersion()); line = replace(line,"%%%"+"m",""+current.majorversion); line = replace(line,"%%%"+"i",""+current.minorversion); line = replace(line,"%%%"+"r",""+current.rev); line = replace(line,"%%%"+"d", DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT).format(new Date())); line = replace(line,"##"+"#",current.date); out.println(line); } } catch (IOException e) {} } static String replace(String line,String pattern,String newvalue) { for (int place=line.indexOf(pattern); place != -1; place = line.indexOf(pattern,place)) line = line.substring(0,place) + newvalue +line.substring(place+pattern.length()); return(line); } }