/* Dump.java * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software 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 README * file for more details. * */ /* * Written by Benjamin Fallenstein */ package org.gzigzag; import java.util.*; import java.io.*; /** A class to dump part of a zzspace in a cvsable way. * XXX sort for id when dumping! (elsewise, cvs won't be usable) * XXX make spans work correctly * XXX make work for dumping */ public class Dump { public static final String rcsid = "$Id: Dump.java,v 1.3 2000/12/24 13:54:20 bfallenstein Exp $"; public static final boolean dbg = true; static final void p(String s) { if(dbg) System.out.println(s); } static final void pa(String s) { System.out.println(s); } static final int fmtversion = 2; // Version of Dump format /** Retrieve and check id for cell. * IDs must either be numbers (given as Strings XXX should use Integer?) * or correct Java identifiers. */ private static String id(ZZCell c, Hashtable ids) { String s = (String)ids.get(c); if(s.length() == 0) throw new ZZError("Empty Dump cell id"); // Check if it's a number; if not, the exception is thrown try { Integer.parseInt(s); } catch(NumberFormatException e) { // Not a number. Now, test if it's a valid Java identifier. if(!Character.isJavaIdentifierStart(s.charAt(0))) throw new ZZError("Bad Dump cell id: '"+s+"'"); for(int i=1; ibetween them on * the dimensions given, exclusively. * @param ids A hashtable mapping cells to ids. This must contain an entry * for every cell in cells[], and there may not be any entry * for a cell not in cells[]. */ public static void writeDump(ZZCell[] cells, String[] dims, Hashtable ids, int nextid, String title, Writer writer) { PrintWriter w = new PrintWriter(writer); w.println("HEADER"); w.println(); w.println("Format: Dump "+fmtversion); w.println("Title: "+title); w.println("rcsid: $Id: Dump.java,v 1.3 2000/12/24 13:54:20 bfallenstein Exp $"); if(nextid >= 0) w.println("Next free ID: "+nextid); w.println(); w.println(); w.println("CONTENTS"); w.println(); for(int i=0; i 0) { ZZCell c1 = (ZZCell)todo.elementAt(0); todo.removeElementAt(0); for(int i=0; i