jlhafrontend-0.1.6/org/ 40755 0 0 0 10432532743 12020 5ustar 0 0 jlhafrontend-0.1.6/org/jlhafrontend/ 40755 0 0 0 10663743241 14501 5ustar 0 0 jlhafrontend-0.1.6/AUTHORS100644 0 0 56 10432532624 12335 0ustar 0 0 Ying-Chun Liu (PaulLiu) jlhafrontend-0.1.6/COPYING100644 0 0 2441 10441257272 12363 0ustar 0 0 Copyright (c) 2006 Ying-Chun Liu (PaulLiu) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jlhafrontend-0.1.6/README100644 0 0 540 10435014100 12146 0ustar 0 0 This program implements the interface of the jLHA library. It is a command-line front-end for compressing/decompressing LHA files. The core library is written by Michel Ishizuka which can be found at http://homepage1.nifty.com/dangan/en/Content/Program/Java/jLHA/LhaLibrary.html The project homepage: http://sourceforge.net/projects/jlhafrontend/ jlhafrontend-0.1.6/TODO100644 0 0 272 10466653165 12010 0ustar 0 0 * display the correct compression rate when compressing files * display progress when compress/decompress * display correct OSID and related extra information * handle UNIX symlinks jlhafrontend-0.1.6/build.xml100644 0 0 7426 10663742537 13172 0ustar 0 0 jlhafrontend-0.1.6/org/jlhafrontend/DOS2UnixOutputStream.java100644 0 0 6752 10541263046 21416 0ustar 0 0 /** * DOS2UnixOutputStream.java * * Copyright (c) 2006 Ying-Chun Liu (PaulLiu) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1. Redistributions of source code must retain the copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package org.jlhafrontend; import java.io.*; /** * This class convert DOS text files to Unix text files when output * */ public class DOS2UnixOutputStream extends java.io.FilterOutputStream { private boolean lastByteFlag = false; private int lastByte = 0; /** * Creates an output stream built on top of the specified underlying * output stream. * * @param out the underlying output stream to be assigned */ public DOS2UnixOutputStream(java.io.OutputStream out) { super(out); } /** * Writes the specified byte to the output stream * * @param b the byte */ public void write(int b) throws java.io.IOException { b = b & 0x00ff; if (!lastByteFlag) { if (b != '\r' ) { super.write(b); return; } else { lastByteFlag=true; lastByte = b; return; } } else { lastByteFlag=false; if (b != '\n') { super.write(lastByte); } super.write(b); } } /** * Writes len bytes from the specified byte array starting at * offset off to this output stream. * * @param b the data * @param off the start offset * @param len the number of bytes to write */ public void write(byte[] b, int off, int len) throws java.io.IOException{ int i; for (i=0 ; i= 0x7f) { b++; } lastByte = lastByte/2+0x71; if (lastByte >= 0xa0) { lastByte += 0x40; } b = b & 0xff; lastByte = lastByte & 0xff; super.write(lastByte); super.write(b); } } lastByte=0; } } /** * Writes len bytes from the specified byte array starting at * offset off to this output stream. * * @param b the data * @param off the start offset * @param len the number of bytes to write */ public void write(byte[] b, int off, int len) throws java.io.IOException{ int i; for (i=0 ; i0) { ret = new String[n]; for (i=filenameList.iterator(),j=0; i.hasNext() && j0) { ret = new String[n]; for (j=0; j0) { ret = new String[n]; for (j=0; j 2) { filesFilename = new String[args.length-2]; for (i=2 ; i=4 && filename.charAt(filename.length()-4)=='.' && filename.substring(filename.length()-3).compareToIgnoreCase("bak")!=0) { bakfilename = filename.substring(0,filename.length()-3)+"bak"; } else { bakfilename = filename+".bak"; } } catch (IndexOutOfBoundsException e) { mylogger.severe("generate bakfilename error "+e.toString()); return null; } try { fd=new File(bakfilename); if (fd.exists()) { fd.delete(); } } catch (SecurityException e) { mylogger.info("delete old file error"); } try { fd = new File(filename); if (fd.exists()) { fd.renameTo(new File(bakfilename)); } } catch (SecurityException e) { mylogger.info("rename file"); } return bakfilename; } /** * execute add command * * @param useropts Options input by users * @param archiveFilename the filename of the archive file * @param filesFilename the array of filenames to be extracted */ public void add(Opts useropts, String archiveFilename, String[] filesFilename) { String[] list; int i=0; File fl=null; String backupFilename=null; LhaFile backupFile=null; LhaWithEntropyOutputStream lio=null; FileList fileList=null; /* open archive file */ try { fl = (new File(archiveFilename)); } catch (Exception e) { mylogger.warning("Open "+archiveFilename+" error:"+e.toString()); return; } /* if the file is not exist, call create */ try { if (!fl.exists()) { create(useropts,archiveFilename,filesFilename); return; } } catch (SecurityException e) { mylogger.severe("Cannot test exist"); return; } /* make backup */ backupFilename = mkbackup(archiveFilename); /* open new archive file */ try { lio = new LhaWithEntropyOutputStream(new FileOutputStream(archiveFilename)); } catch (Exception e) { mylogger.severe("new LhaImeediateOutputStream with "+archiveFilename+" error: "+e.toString()); return; } /* generate list */ fileList = new FileList(filesFilename); list = fileList.getFiles(); /* open backup file */ try { backupFile = new LhaFile (new File(backupFilename)); } catch (FileNotFoundException e) { System.err.println("LHa: Fatal error: "+archiveFilename+": No such file or directory"); return; } catch (Exception e) { mylogger.warning("Open "+archiveFilename+" error:"+e.toString()); System.err.println("LHa: Warning: Checksum error (LHarc file?)"); System.err.println("LHa: Fatal error: Unkonwn header (lha file?)"); return; } transferBackupToArchive(backupFile,lio,list); /* compress new entries */ for (i=0 ; i oldmodtime) { fileList.setFileMark(list[i]); } } list = fileList.getMarkedFiles(); transferBackupToArchive(backupFile,lio,list); /* compress new entries */ if (list != null) { for (i=0 ; i0) { ratio_avg = pack_sum*1000/size_sum; } else { ratio_avg = -1; } if (quiet==0) { System.out.print("---------- ----------- ------- ------ ------------"); if (!verbose) { System.out.print(" --------------------"); } System.out.println(""); System.out.print(" Total "); System.out.print(" "); System.out.print(lf.toField(Integer.toString(N),5,false)); if (N==1) { System.out.print(" file "); } else { System.out.print(" files"); } System.out.print(" "); System.out.print(lf.toField(Long.toString(size_sum),7,false)); System.out.print(" "); if (ratio_avg >= 0) { System.out.print(lf.toField(Long.toString(ratio_avg/10)+"."+Long.toString(ratio_avg%10)+"%",6,false)); } else { System.out.print("******"); } System.out.print(" "); System.out.print(ListFormatter.genFileDate(archiveFilename)); System.out.println(""); } } /** * execute verbose list command * * @param useropts Options input by users * @param archiveFilename the filename of the archive file * @param filesFilename the array of filenames to be processed */ public void verboseList(Opts useropts, String archiveFilename, String[] filesFilename) { LhaHeader[] data; int i,N=0,quiet=0; ListFormatter lf=new ListFormatter(); long size_sum=0,pack_sum=0,ratio_avg=-1; boolean verbose=false; verbose=useropts.getVerbose(); quiet=useropts.getQuiet(); data = listCore(useropts,archiveFilename,filesFilename); if (quiet==0) { System.out.print(" PERMSSN UID GID PACKED SIZE RATIO METHOD CRC STAMP"); if (!verbose) { System.out.print(" NAME"); } System.out.println(""); System.out.print("---------- ----------- ------- ------- ------ ---------- ------------"); if (!verbose) { System.out.print(" -------------"); } System.out.println(""); } if (data==null) { System.err.println("LHa: Warning: Checksum error (LHarc file?)"); System.err.println("LHa: Fatal error: Unkonwn header (lha file?)"); return; } for (i=0 ; i0) { ratio_avg = pack_sum*1000/size_sum; } else { ratio_avg = -1; } if (quiet==0) { System.out.print("---------- ----------- ------- ------- ------ ---------- ------------"); if (!verbose) { System.out.print(" -------------"); } System.out.println(""); System.out.print(" Total "); System.out.print(" "); System.out.print(lf.toField(Integer.toString(N),5,false)); if (N==1) { System.out.print(" file "); } else { System.out.print(" files"); } System.out.print(" "); System.out.print(lf.toField(Long.toString(pack_sum),7,false)); System.out.print(" "); System.out.print(lf.toField(Long.toString(size_sum),7,false)); System.out.print(" "); if (ratio_avg >= 0) { System.out.print(lf.toField(Long.toString(ratio_avg/10)+"."+Long.toString(ratio_avg%10)+"%",6,false)); } else { System.out.print("******"); } System.out.print(" "); System.out.print(" "); System.out.print(" "); System.out.print(ListFormatter.genFileDate(archiveFilename)); System.out.println(""); } } /** * compress a file into a LhaOutputStream * * @param useropts Options input by users * @param lio the LhaOutputStream for an archive file * @param filename the file need to be compressed */ public void createFile(Opts useropts, LhaWithEntropyOutputStream lio, String filename) { LhaHeader header = new LhaHeader( filename ); FileInputStream raf = null; File fl; int i,j,quiet=0; boolean fileNotCompress=false,deleteFiles=false; ListFormatter lf = new ListFormatter(); int compressMethod=0; long compressedSize=0; OutputStream liodata; compressMethod = useropts.getCompressionMethod(); fileNotCompress = useropts.getFileNotCompress(); deleteFiles = useropts.getDeleteFiles(); quiet = useropts.getQuiet(); try { fl = new File(filename); } catch (Exception e) { mylogger.severe("new File error: "+e.toString()); return; } try { raf = new FileInputStream( fl ); } catch (Exception e) { mylogger.severe("new FileInputStream: "+e.toString()); return; } if (useropts.getHeaderLevel() != -1) { header.setHeaderLevel(useropts.getHeaderLevel()); } header.setLastModified( new Date( fl.lastModified() ) ); header.setOriginalSize( fl.length()); header.setOSID((byte)0); if (compressMethod == 5) { header.setCompressMethod ( CompressMethod.LH5 ); } else if (compressMethod == 6) { header.setCompressMethod ( CompressMethod.LH6 ); } else if (compressMethod == 7) { header.setCompressMethod ( CompressMethod.LH7 ); } if (fileNotCompress) { header.setCompressMethod ( CompressMethod.LH0 ); } try { lio.putNextEntry( header ); } catch (IOException e) { mylogger.severe("putNextEntry error #1: "+e.toString()); } if (quiet==0) { System.out.print(filename); System.out.print("\t- Frozen"); System.out.flush(); } liodata = lio; if (useropts.getTextMode()) { liodata = new Unix2DOSOutputStream(liodata); } if (useropts.getEUCMode()) { liodata = new EUCJP2SJISOutputStream(liodata); } j=transferTo(raf,liodata); try { lio.closeEntry(); } catch (IOException e) { mylogger.severe("lio.closeEntry #1: "+e.toString()); } if (quiet==0) { //compressedSize = header.getCompressedSize(); compressedSize = lio.getEntropyLength(); /* FIXME: display correct compression rate */ if (header.getOriginalSize() > 0 && header.getOriginalSize() > compressedSize) { System.out.print(lf.toField("("+Long.toString(compressedSize*100/header.getOriginalSize())+"%)",6,true)); } else { System.out.print(lf.toField("(100%)",6,true)); } for (i=0 ; i specify working directory" ," d delete files after (a/u/c)", " i ignore directory path (x/e)", " z files not compress (a/u)", " 0/1/2 header level (a/u)", " e TEXT code convert from/to EUC-JP" , " y filename multibyte convert" }; System.out.print(ListFormatter._toField("jLHA",27,true)); System.out.println("Copyright(C) 2002 Michel Ishizuka"); System.out.print(ListFormatter._toField("jlhafrontend",27,true)); System.out.println("Copyright(C) 2006 Ying-Chun Liu"); System.out.println("usage: JLHAFrontEnd [-]{axelvudmcpt[q[num]][vnfodizg012]}[w=] archive_file [file...]"); for (i=0 ; i1) { quiet=Integer.parseInt(mat_str.substring(1)); } else { quiet++; } } } catch (Exception e) { } break; case 3: if (mat_str.compareTo("v")==0) { verbose = true; } break; case 4: if (mat_str.compareTo("n")==0) { notExecute=true; } break; case 5: if (mat_str.compareTo("f")==0) { force = true; } break; case 6: try { if (mat_str.charAt(0) == 'o') { if (mat_str.length()>1) { compressionMethod=Integer.parseInt(mat_str.substring(1)); } } } catch (Exception e) { } break; case 7: if (mat_str.compareTo("d")==0) { deleteFiles=true; } break; case 8: if (mat_str.compareTo("i")==0) { ignorePath=true; } break; case 9: if (mat_str.compareTo("z")==0) { fileNotCompress=true; } break; case 10: if (mat_str.compareTo("g")==0) { genericFormat=true; } break; case 11: if (mat_str.compareTo("0")==0) { headerLevel=0; } else if (mat_str.compareTo("1")==0) { headerLevel=1; } else if (mat_str.compareTo("2")==0) { headerLevel=2; } /* headerLevel = 3 is not supported by the non-free lha, thus we disable it now */ /*else if (mat_str.compareTo("3")==0) { headerLevel=3; }*/ break; case 12: if (mat_str.compareTo("e")==0) { eucMode = true; } break; case 13: if (mat_str.compareTo("y")==0) { try { java.util.Locale.setDefault(java.util.Locale.JAPAN); /* FIXME: ugly, but work */ } catch (Exception e) { mylogger.warning("Set locale to Japan error: "+e.toString()); } } break; case 14: if (mat_str.compareTo("t")==0) { textMode = true; } break; case 15: try { if (mat_str.charAt(0) == 'w' && mat_str.charAt(1)== '=') { if (mat_str.length()>2) { specifyExtractDirectory=mat_str.substring(2); } } } catch (Exception e) { } break; default: break; } } } else { mylogger.log(Level.INFO,"Not match"); } return ret; } /** * * testing function */ public static void main (String[] args) { Opts o1 = new Opts(); Logger.getLogger("org.jlhafrontend").setLevel(Level.ALL); Logger.getLogger("org.jlhafrontend").addHandler(new ConsoleHandler()); o1.setOpts(args[0]); } } jlhafrontend-0.1.6/org/jlhafrontend/SJIS2EUCJPOutputStream.java100644 0 0 7641 10541262117 21460 0ustar 0 0 /** * SJIS2EUCJPOutputStream.java * * Copyright (c) 2006 Ying-Chun Liu (PaulLiu) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1. Redistributions of source code must retain the copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ package org.jlhafrontend; import java.io.*; /** * This class re-encodes SHIFT-JIS to EUC-JP when output * */ public class SJIS2EUCJPOutputStream extends java.io.FilterOutputStream { private boolean lastByteFlag = false; private int lastByte = 0; /** * Creates an output stream built on top of the specified underlying * output stream. * * @param out the underlying output stream to be assigned */ public SJIS2EUCJPOutputStream(java.io.OutputStream out) { super(out); } /** * Writes the specified byte to the output stream * * @param b the byte */ public void write(int b) throws java.io.IOException { b = b & 0x00ff; if (!lastByteFlag) { if (b <= 0x80 || b > 0xfc) { /* US-ASCII compatible */ super.write(b); return; } else if (0xa0 <= b && b < 0xe0) { /* kana */ super.write(0x8e); super.write(b); return; } else { lastByteFlag=true; lastByte = b; return; } } else { lastByteFlag=false; if (lastByte >= 0xa0) { lastByte -= 0x40; } lastByte = (lastByte-0x81)*2+0x21; if (b >= 0x9f) { b = b - 0x9f + 0x21; lastByte++; } else { if (b >= 0x7f) { b--; } b -= 0x1f; } b = b & 0xff; lastByte = lastByte & 0xff; b = b | 0x80; lastByte = lastByte | 0x80; super.write(lastByte); lastByte=0; super.write(b); } } /** * Writes len bytes from the specified byte array starting at * offset off to this output stream. * * @param b the data * @param off the start offset * @param len the number of bytes to write */ public void write(byte[] b, int off, int len) throws java.io.IOException{ int i; for (i=0 ; i 0xfc) { /* US-ASCII compatible */ super.write(b); return; } else if (0xa0 <= b && b < 0xe0) { /* kana */ super.write(0x8e); super.write(b); return; } else { lastByteFlag=true; lastByte = b; return; } } else { lastByteFlag=false; if (lastByte >= 0xa0) { lastByte -= 0x40; } lastByte = (lastByte-0x81)*2+0x21; if (b >= 0x9f) { b = b - 0x9f + 0x21; lastByte++; } else { if (b >= 0x7f) { b--; } b -= 0x1f; } b = b & 0xff; lastByte = lastByte & 0xff; b = b | 0x80; lastByte = lastByte | 0x80; super.write(lastByte); lastByte=0; super.write(b); } } /** * Writes len bytes from the specified byte array starting at * offset off to this output stream. * * @param b the data * @param off the start offset * @param len the number of bytes to write */ public void write(byte[] b, int off, int len) throws java.io.IOException{ int i; for (i=0 ; i