1 28 29 package org.objectweb.util.cpp.lib; 30 31 import java.io.File ; 32 import java.io.OutputStream ; 33 import java.util.Hashtable ; 34 import java.util.Map ; 35 import java.util.Vector ; 36 37 import org.objectweb.util.cmdline.lib.DefaultConsoleHolder; 38 import org.objectweb.util.cpp.api.Preprocessor; 39 import org.objectweb.util.misc.api.ExceptionWrapper; 40 41 42 59 public abstract class PreprocessorBase 60 extends DefaultConsoleHolder 61 implements Preprocessor 62 { 63 69 70 protected boolean generateLineInformation_; 71 72 73 protected Vector arguments_; 74 75 76 protected Vector includeDirectories_ ; 77 78 79 protected Hashtable macros_; 80 81 87 88 public PreprocessorBase() { 89 generateLineInformation_ = false; 91 arguments_ = new Vector (); 92 includeDirectories_ = new Vector (); 93 macros_ = new Hashtable (); 94 } 95 96 102 108 115 public File preprocess(String fileName) { 116 File tmpFile = null; 117 try { 118 tmpFile = File.createTempFile("OW_preprocessor",".tmp"); 120 } catch(java.io.IOException exc) { 121 throw new ExceptionWrapper(exc); 123 } 124 125 boolean status = preprocess(fileName, tmpFile); 126 127 if (!status) { 129 tmpFile.delete(); 130 return null; 131 } 132 133 return tmpFile; 135 } 136 137 145 public abstract boolean 146 preprocess(String fileName, File tmpFile); 147 148 156 public abstract boolean 157 preprocess(String fileName, OutputStream output); 158 159 165 170 public boolean getGenerateLineInformation() { 171 return generateLineInformation_; 172 } 173 174 179 public void setGenerateLineInformation(boolean b) { 180 generateLineInformation_ = b; 181 } 182 183 188 public void addIncludeDirectory(String directory) { 189 arguments_.addElement("-I" + directory); 190 includeDirectories_.addElement(directory); 191 } 192 193 198 public String [] getIncludeDirectory() { 199 return (String [])includeDirectories_.toArray(new String [0]); 200 } 201 202 207 public void setIncludeDirectory(String [] directories) { 208 includeDirectories_ = new Vector (); 210 211 for(int i=0; i<directories.length; i++) { 213 arguments_.addElement("-I" + directories[i]); 214 addIncludeDirectory(directories[i]); 215 } 216 } 217 218 223 public void addMacro(String name) { 224 arguments_.addElement("-D" + name); 225 macros_.put(name, "1"); 226 } 227 228 234 public void addMacro(String name, String value) { 235 arguments_.addElement("-D" + name + '=' + value); 236 macros_.put(name, value); 237 } 238 239 244 public void removeMacro(String name) { 245 arguments_.addElement("-U" + name); 246 macros_.remove(name); 247 } 248 249 254 public Map getMacro() { 255 throw new RuntimeException ("NOT IMPLEMENTED!!!"); 257 } 258 259 264 public void setMacro(Map macros) { 265 throw new RuntimeException ("NOT IMPLEMENTED!!!"); 267 } 268 } 269 | Popular Tags |