1 28 29 package org.objectweb.util.cpp.lib; 30 31 import java.io.File ; 32 import java.io.FileReader ; 33 import java.io.OutputStream ; 34 import java.io.PrintStream ; 35 36 import org.objectweb.util.misc.api.ExceptionWrapper; 37 38 39 45 public class PreprocessorCPP 46 extends PreprocessorBase 47 { 48 54 55 private String cppPath_; 56 57 63 64 public PreprocessorCPP() { 65 this("cpp"); 67 } 68 69 74 public PreprocessorCPP(String cppPath) { 75 cppPath_ = cppPath; 76 } 77 78 84 90 98 public boolean preprocess(String fileName, File tmpFile) { 99 101 104 int nb_arguments = arguments_.size(); 105 String [] cmd = null; 106 107 111 if(!getGenerateLineInformation()) { 112 cmd = new String [3 + nb_arguments]; 113 } else { 114 cmd = new String [4 + nb_arguments]; 115 } 116 117 int i = 0; 119 cmd[i] = cppPath_; i++; 120 121 if(getGenerateLineInformation()) { 123 cmd[i] = "-P"; i++; 124 } 125 126 for(int j=0; j<nb_arguments; j++) { 128 cmd[i] = (String )arguments_.elementAt(j); i++; 129 } 130 131 cmd[i] = fileName; i++; 133 134 cmd[i] = tmpFile.toString(); i++; 136 137 Process cpp = null; 139 try { 140 cpp = Runtime.getRuntime().exec(cmd); 141 } catch(java.io.IOException exc) { 142 throw new ExceptionWrapper(exc); 144 } 145 146 int status = 0; 147 try { 148 status = cpp.waitFor(); 150 } catch(java.lang.InterruptedException exc) { 151 throw new ExceptionWrapper(exc); 153 } 154 155 IOHelper.dump(cpp.getInputStream(), getConsole().getOutputStream()); 157 IOHelper.dump(cpp.getErrorStream(), getConsole().getErrorStream()); 158 159 return status == 0; 161 } 162 163 169 public boolean preprocess(String fileName, OutputStream output) { 170 File tmpFile = preprocess(fileName); 172 if(tmpFile == null) 173 return false; 174 175 try { 176 IOHelper.dump(new FileReader (tmpFile), new PrintStream (output)); 178 } catch(java.io.IOException exc) { 179 throw new ExceptionWrapper(exc); 181 } finally { 182 tmpFile.delete(); 184 } 185 186 return true; 187 } 188 189 } 195 | Popular Tags |