diff --git a/src/com/webcodepro/applecommander/ui/ac.java b/src/com/webcodepro/applecommander/ui/ac.java new file mode 100644 index 0000000..cd016d4 --- /dev/null +++ b/src/com/webcodepro/applecommander/ui/ac.java @@ -0,0 +1,239 @@ +/* + * ac - an AppleCommander command line utility + * Copyright (C) 2002 by Robert Greene + * robgreene at users.sourceforge.net + * Copyright (C) 2003 by John B. Matthews + * jmatthews at wight dot edu + * + * 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; either version 2 of the License, or (at your + * option) any later version. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.webcodepro.applecommander.ui; + +import com.webcodepro.applecommander.storage.DirectoryEntry; +import com.webcodepro.applecommander.storage.Disk; +import com.webcodepro.applecommander.storage.DiskFullException; +import com.webcodepro.applecommander.storage.FileEntry; +import com.webcodepro.applecommander.storage.FileFilter; +import com.webcodepro.applecommander.storage.FormattedDisk; +import com.webcodepro.applecommander.storage.ProdosFormatDisk; + +import java.io.IOException; +import java.util.List; + +public class ac { + + public static void main(String[] args) throws IOException { + try { + if (args.length == 0) { + help(); + } else if ("-l".equalsIgnoreCase(args[0])) { + showDirectory(args[1]); + } else if ("-e".equalsIgnoreCase(args[0])) { + getFile(args[1], args[2], true); + } else if ("-g".equalsIgnoreCase(args[0])) { + getFile(args[1], args[2], false); + } else if ("-p".equalsIgnoreCase(args[0])) { + putFile(args[1], args[2], args[3], args[4]); + } else if ("-d".equalsIgnoreCase(args[0])) { + deleteFile(args[1], args[2]); + } else if ("-p140".equalsIgnoreCase(args[0])) { + createPDisk(args[1], args[2], ProdosFormatDisk.APPLE_140KB_DISK); + } else if ("-p800".equalsIgnoreCase(args[0])) { + createPDisk(args[1], args[2], ProdosFormatDisk.APPLE_800KB_DISK); + } else { + help(); + } + } catch (Exception ex) { + System.err.println("Error: " + ex); + ex.printStackTrace(); + help(); + } + } + + /** + * Put into the file named fileName on the disk named imageName; + * Note: only volume level supported, 32K limit. + */ + static void putFile(String fileName, String fileType, + String address, String imageName) + throws IOException, DiskFullException { + + byte[] buf = new byte[32768]; + Disk disk = new Disk(imageName); + FormattedDisk[] formattedDisks = disk.getFormattedDisks(); + FormattedDisk formattedDisk = formattedDisks[0]; + int byteCount = System.in.read(buf); + byte[] data = new byte[byteCount]; + System.arraycopy(buf, 0, data, 0, byteCount); + FileEntry entry = formattedDisk.createFile(); + entry.setFilename(fileName); + entry.setFiletype(fileType); + if (entry.needsAddress()) { + entry.setAddress(stringToInt(address)); + } + entry.setFileData(data); + formattedDisk.save(); + } + + /** + * Delete the file named fileName from the disk named imageName. + */ + static void deleteFile(String fileName, String imageName) + throws IOException { + Disk disk = new Disk(imageName); + FormattedDisk[] formattedDisks = disk.getFormattedDisks(); + for (int i=0; i. + */ + static void getFile(String fileName, String imageName, boolean filter) + throws IOException { + Disk disk = new Disk(imageName); + FormattedDisk[] formattedDisks = disk.getFormattedDisks(); + for (int i=0; i list directory of image."); + System.err.println("-e export file from image to stdout."); + System.err.println("-g get raw file from image to stdout."); + System.err.println("-p put stdin"); + System.err.println(" in destname on image, using file type and address."); + System.err.println("-d delete file from image."); + System.err.println("-p140 create a 140K ProDOS image."); + System.err.println("-p800 create a 800K ProDOS image."); + } + +}