summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorMark Donszelmann <Mark.Donszelmann@gmail.com>2006-08-15 20:36:06 +0000
committerMark Donszelmann <Mark.Donszelmann@gmail.com>2006-08-15 20:36:06 +0000
commit6c00635e2ac7134a58fd47c3232991452ca623a5 (patch)
tree774cdab6e99b6d9d9058e4984229bb573daf094c /src/net
parent95a2fc6f26b8c026cfe6092a672d274f60431a84 (diff)
downloadcpptasks-parallel-6c00635e2ac7134a58fd47c3232991452ca623a5.tar.gz
cpptasks-parallel-6c00635e2ac7134a58fd47c3232991452ca623a5.tar.bz2
cpptasks-parallel-6c00635e2ac7134a58fd47c3232991452ca623a5.tar.xz
cpptasks-parallel-6c00635e2ac7134a58fd47c3232991452ca623a5.zip
Fixed mime-types, eol-style and keywords
Diffstat (limited to 'src/net')
-rw-r--r--src/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java458
-rw-r--r--src/net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java444
2 files changed, 464 insertions, 438 deletions
diff --git a/src/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java b/src/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java
index 6693ab9..1b13e54 100644
--- a/src/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java
+++ b/src/net/sf/antcontrib/cpptasks/borland/BorlandLibrarian.java
@@ -1,219 +1,239 @@
-/*
- *
- * Copyright 2002-2005 The Ant-Contrib project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.antcontrib.cpptasks.borland;
-import java.io.File;
-import java.io.IOException;
-import java.util.Vector;
-import org.apache.tools.ant.BuildException;
-
-import net.sf.antcontrib.cpptasks.CUtil;
-import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;
-import net.sf.antcontrib.cpptasks.compiler.LinkType;
-import net.sf.antcontrib.cpptasks.compiler.Linker;
-import net.sf.antcontrib.cpptasks.CCTask;
-import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;
-import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
-
-/**
- * Adapter for the Borland(r) tlib Librarian
- *
- * @author Curt Arnold
- */
-public class BorlandLibrarian extends CommandLineLinker {
- private static final BorlandLibrarian instance = new BorlandLibrarian();
- public static BorlandLibrarian getInstance() {
- return instance;
- }
- private BorlandLibrarian() {
- super("tlib", "--version", new String[]{".obj"}, new String[0], ".lib", false,
- null);
- }
- protected void addBase(long base, Vector args) {
- }
- protected void addFixed(Boolean fixed, Vector args) {
- }
- protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
- }
- protected void addIncremental(boolean incremental, Vector args) {
- }
- protected void addMap(boolean map, Vector args) {
- }
- protected void addStack(int stack, Vector args) {
- }
- /* (non-Javadoc)
- * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
- */
- protected void addEntry(String entry, Vector args) {
- }
-
- protected String getCommandFileSwitch(String cmdFile) {
- //
- // tlib requires quotes around paths containing -
- // ilink32 doesn't like them
- StringBuffer buf = new StringBuffer("@");
- BorlandProcessor.quoteFile(buf, cmdFile);
- return buf.toString();
- }
- public File[] getLibraryPath() {
- return CUtil.getPathFromEnvironment("LIB", ";");
- }
- public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
- return BorlandProcessor.getLibraryPatterns(libnames, libType);
- }
- public Linker getLinker(LinkType type) {
- return BorlandLinker.getInstance().getLinker(type);
- }
- public int getMaximumCommandLength() {
- return 1024;
- }
- public String[] getOutputFileSwitch(String outFile) {
- return BorlandProcessor.getOutputFileSwitch(outFile);
- }
- public boolean isCaseSensitive() {
- return BorlandProcessor.isCaseSensitive();
- }
- /**
- * Gets identifier for the linker.
- *
- * TLIB will lockup when attempting to get version
- * information. Since the Librarian version isn't critical
- * just return a stock response.
- */
- public String getIdentifier() {
- return "TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation";
- }
-
- /**
- * Prepares argument list for exec command.
- *
- * @param outputFile
- * linker output file
- * @param sourceFiles
- * linker input files (.obj, .o, .res)
- * @param args
- * linker arguments
- * @return arguments for runTask
- */
- protected String[] prepareArguments(
- CCTask task,
- String outputDir,
- String outputName,
- String[] sourceFiles,
- CommandLineLinkerConfiguration config) {
- String[] preargs = config.getPreArguments();
- String[] endargs = config.getEndArguments();
- StringBuffer buf = new StringBuffer();
- Vector execArgs = new Vector(preargs.length + endargs.length + 10
- + sourceFiles.length);
-
- execArgs.addElement(this.getCommand());
- String outputFileName = new File(outputDir, outputName).toString();
- execArgs.addElement(quoteFilename(buf, outputFileName));
-
- for (int i = 0; i < preargs.length; i++) {
- execArgs.addElement(preargs[i]);
- }
-
- //
- // add a place-holder for page size
- //
- int pageSizeIndex = execArgs.size();
- execArgs.addElement(null);
-
- int objBytes = 0;
-
- for (int i = 0; i < sourceFiles.length; i++) {
- String last4 = sourceFiles[i]
- .substring(sourceFiles[i].length() - 4).toLowerCase();
- if (last4.equals(".def")) {
- } else {
- if (last4.equals(".res")) {
- } else {
- if (last4.equals(".lib")) {
- } else {
- execArgs.addElement("+" + quoteFilename(buf, sourceFiles[i]));
- objBytes += new File(sourceFiles[i]).length();
- }
- }
- }
- }
-
- for (int i = 0; i < endargs.length; i++) {
- execArgs.addElement(endargs[i]);
- }
-
- String[] execArguments = new String[execArgs.size()];
- execArgs.copyInto(execArguments);
-
- int minPageSize = objBytes >> 16;
- int pageSize = 0;
- for(int i = 4; i <= 15; i++) {
- pageSize = 1 << i;
- if (pageSize > minPageSize) break;
- }
- execArguments[pageSizeIndex] = "/P" + Integer.toString(pageSize);
-
- return execArguments;
- }
-
- /**
- * Prepares argument list to execute the linker using a response file.
- *
- * @param outputFile
- * linker output file
- * @param args
- * output of prepareArguments
- * @return arguments for runTask
- */
- protected String[] prepareResponseFile(File outputFile, String[] args)
- throws IOException {
- String[] cmdargs = BorlandProcessor.prepareResponseFile(outputFile, args, " & \n");
- cmdargs[cmdargs.length - 1] = getCommandFileSwitch(cmdargs[cmdargs.length -1]);
- return cmdargs;
- }
-
- /**
- * Builds a library
- *
- */
- public void link(CCTask task,
- File outputFile,
- String[] sourceFiles,
- CommandLineLinkerConfiguration config)
- throws BuildException
- {
- //
- // delete any existing library
- outputFile.delete();
- //
- // build a new library
- super.link(task, outputFile, sourceFiles, config);
- }
-
- /**
- * Encloses problematic file names within quotes.
- * @param buf string buffer
- * @param filename source file name
- * @returns filename potentially enclosed in quotes.
- */
- protected String quoteFilename(StringBuffer buf,String filename) {
- buf.setLength(0);
- BorlandProcessor.quoteFile(buf, filename);
- return buf.toString();
- }
-
-}
+/*
+ *
+ * Copyright 2002-2005 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.borland;
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
+import org.apache.tools.ant.BuildException;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinker;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.CCTask;
+import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration;
+import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
+
+/**
+ * Adapter for the Borland(r) tlib Librarian
+ *
+ * @author Curt Arnold
+ */
+public class BorlandLibrarian extends CommandLineLinker {
+ private static final BorlandLibrarian instance = new BorlandLibrarian();
+ public static BorlandLibrarian getInstance() {
+ return instance;
+ }
+ private BorlandLibrarian() {
+ super("tlib", "--version", new String[]{".obj"}, new String[0], ".lib", false,
+ null);
+ }
+ protected void addBase(long base, Vector args) {
+ }
+ protected void addFixed(Boolean fixed, Vector args) {
+ }
+ protected void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
+ }
+ protected void addIncremental(boolean incremental, Vector args) {
+ }
+ protected void addMap(boolean map, Vector args) {
+ }
+ protected void addStack(int stack, Vector args) {
+ }
+ /* (non-Javadoc)
+ * @see net.sf.antcontrib.cpptasks.compiler.CommandLineLinker#addEntry(int, java.util.Vector)
+ */
+ protected void addEntry(String entry, Vector args) {
+ }
+
+ protected String getCommandFileSwitch(String cmdFile) {
+
+ //
+
+ // tlib requires quotes around paths containing -
+
+ // ilink32 doesn't like them
+
+ StringBuffer buf = new StringBuffer("@");
+
+ BorlandProcessor.quoteFile(buf, cmdFile);
+
+ return buf.toString();
+ }
+ public File[] getLibraryPath() {
+ return CUtil.getPathFromEnvironment("LIB", ";");
+ }
+ public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
+ return BorlandProcessor.getLibraryPatterns(libnames, libType);
+ }
+ public Linker getLinker(LinkType type) {
+ return BorlandLinker.getInstance().getLinker(type);
+ }
+ public int getMaximumCommandLength() {
+ return 1024;
+ }
+ public String[] getOutputFileSwitch(String outFile) {
+ return BorlandProcessor.getOutputFileSwitch(outFile);
+ }
+ public boolean isCaseSensitive() {
+ return BorlandProcessor.isCaseSensitive();
+ }
+ /**
+ * Gets identifier for the linker.
+ *
+ * TLIB will lockup when attempting to get version
+ * information. Since the Librarian version isn't critical
+ * just return a stock response.
+ */
+ public String getIdentifier() {
+ return "TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation";
+ }
+
+ /**
+ * Prepares argument list for exec command.
+ *
+ * @param outputFile
+ * linker output file
+ * @param sourceFiles
+ * linker input files (.obj, .o, .res)
+ * @param args
+ * linker arguments
+ * @return arguments for runTask
+ */
+ protected String[] prepareArguments(
+ CCTask task,
+ String outputDir,
+ String outputName,
+ String[] sourceFiles,
+ CommandLineLinkerConfiguration config) {
+ String[] preargs = config.getPreArguments();
+ String[] endargs = config.getEndArguments();
+ StringBuffer buf = new StringBuffer();
+ Vector execArgs = new Vector(preargs.length + endargs.length + 10
+ + sourceFiles.length);
+
+ execArgs.addElement(this.getCommand());
+ String outputFileName = new File(outputDir, outputName).toString();
+ execArgs.addElement(quoteFilename(buf, outputFileName));
+
+ for (int i = 0; i < preargs.length; i++) {
+ execArgs.addElement(preargs[i]);
+ }
+
+ //
+ // add a place-holder for page size
+ //
+ int pageSizeIndex = execArgs.size();
+ execArgs.addElement(null);
+
+ int objBytes = 0;
+
+ for (int i = 0; i < sourceFiles.length; i++) {
+ String last4 = sourceFiles[i]
+ .substring(sourceFiles[i].length() - 4).toLowerCase();
+ if (last4.equals(".def")) {
+ } else {
+ if (last4.equals(".res")) {
+ } else {
+ if (last4.equals(".lib")) {
+ } else {
+ execArgs.addElement("+" + quoteFilename(buf, sourceFiles[i]));
+ objBytes += new File(sourceFiles[i]).length();
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < endargs.length; i++) {
+ execArgs.addElement(endargs[i]);
+ }
+
+ String[] execArguments = new String[execArgs.size()];
+ execArgs.copyInto(execArguments);
+
+ int minPageSize = objBytes >> 16;
+ int pageSize = 0;
+ for(int i = 4; i <= 15; i++) {
+ pageSize = 1 << i;
+ if (pageSize > minPageSize) break;
+ }
+ execArguments[pageSizeIndex] = "/P" + Integer.toString(pageSize);
+
+ return execArguments;
+ }
+
+ /**
+ * Prepares argument list to execute the linker using a response file.
+ *
+ * @param outputFile
+ * linker output file
+ * @param args
+ * output of prepareArguments
+ * @return arguments for runTask
+ */
+ protected String[] prepareResponseFile(File outputFile, String[] args)
+ throws IOException {
+ String[] cmdargs = BorlandProcessor.prepareResponseFile(outputFile, args, " & \n");
+ cmdargs[cmdargs.length - 1] = getCommandFileSwitch(cmdargs[cmdargs.length -1]);
+
+ return cmdargs;
+
+ }
+
+ /**
+ * Builds a library
+ *
+ */
+ public void link(CCTask task,
+ File outputFile,
+ String[] sourceFiles,
+ CommandLineLinkerConfiguration config)
+ throws BuildException
+ {
+ //
+ // delete any existing library
+ outputFile.delete();
+ //
+ // build a new library
+ super.link(task, outputFile, sourceFiles, config);
+ }
+
+
+ /**
+
+ * Encloses problematic file names within quotes.
+
+ * @param buf string buffer
+
+ * @param filename source file name
+
+ * @returns filename potentially enclosed in quotes.
+
+ */
+
+ protected String quoteFilename(StringBuffer buf,String filename) {
+
+ buf.setLength(0);
+
+ BorlandProcessor.quoteFile(buf, filename);
+
+ return buf.toString();
+
+ }
+
+
+}
diff --git a/src/net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java b/src/net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java
index bbfeba8..3dfef2d 100644
--- a/src/net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java
+++ b/src/net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java
@@ -1,219 +1,225 @@
-/*
- *
- * Copyright 2002-2005 The Ant-Contrib project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.antcontrib.cpptasks.borland;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.Vector;
-import java.io.FileWriter;
-
-import net.sf.antcontrib.cpptasks.CUtil;
-import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
-/**
- * A add-in class for Borland(r) processor adapters
- *
- *
- */
-public final class BorlandProcessor {
- public static void addWarningSwitch(Vector args, int level) {
- switch (level) {
- case 0 :
- args.addElement("-w-");
- break;
- case 5 :
- args.addElement("-w!");
- break;
- default :
- args.addElement("-w");
- break;
- }
- }
- public static void getDefineSwitch(StringBuffer buffer, String define,
- String value) {
- buffer.append("-D");
- buffer.append(define);
- if (value != null && value.length() > 0) {
- buffer.append('=');
- buffer.append(value);
- }
- }
- /**
- * This method extracts path information from the appropriate .cfg file in
- * the install directory.
- *
- * @param toolName
- * Tool name, for example, "bcc32", "brc32", "ilink32"
- * @param switchChar
- * Command line switch character, for example "L" for libraries
- * @param defaultRelativePaths
- * default paths relative to executable directory
- * @return path
- */
- public static File[] getEnvironmentPath(String toolName, char switchChar,
- String[] defaultRelativePath) {
- if (toolName == null) {
- throw new NullPointerException("toolName");
- }
- if (defaultRelativePath == null) {
- throw new NullPointerException("defaultRelativePath");
- }
- String[] path = defaultRelativePath;
- File exeDir = CUtil.getExecutableLocation(toolName + ".exe");
- if (exeDir != null) {
- File cfgFile = new File(exeDir, toolName + ".cfg");
- if (cfgFile.exists()) {
- try {
- Reader reader = new BufferedReader(new FileReader(cfgFile));
- BorlandCfgParser cfgParser = new BorlandCfgParser(
- switchChar);
- path = cfgParser.parsePath(reader);
- reader.close();
- } catch (IOException ex) {
- //
- // could be logged
- //
- }
- }
- } else {
- //
- // if can't find the executable,
- // assume current directory to resolve relative paths
- //
- exeDir = new File(System.getProperty("user.dir"));
- }
- int nonExistant = 0;
- File[] resourcePath = new File[path.length];
- for (int i = 0; i < path.length; i++) {
- resourcePath[i] = new File(path[i]);
- if (!resourcePath[i].isAbsolute()) {
- resourcePath[i] = new File(exeDir, path[i]);
- }
- //
- // if any of the entries do not exist or are
- // not directories, null them out
- if (!(resourcePath[i].exists() && resourcePath[i].isDirectory())) {
- resourcePath[i] = null;
- nonExistant++;
- }
- }
- //
- // if there were some non-existant or non-directory
- // entries in the configuration file then
- // create a shorter array
- if (nonExistant > 0) {
- File[] culled = new File[resourcePath.length - nonExistant];
- int index = 0;
- for (int i = 0; i < resourcePath.length; i++) {
- if (resourcePath[i] != null) {
- culled[index++] = resourcePath[i];
- }
- }
- resourcePath = culled;
- }
- return resourcePath;
- }
- public static String getIncludeDirSwitch(String includeOption,
- String includeDir) {
- StringBuffer buf = new StringBuffer(includeOption);
- quoteFile(buf, includeDir);
- return buf.toString();
- }
- public static String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
- StringBuffer buf = new StringBuffer();
- String[] patterns = new String[libnames.length];
- for (int i = 0; i < libnames.length; i++) {
- buf.setLength(0);
- buf.append(libnames[i]);
- buf.append(".lib");
- patterns[i] = buf.toString();
- }
- return patterns;
- }
- public static String[] getOutputFileSwitch(String outFile) {
- return new String[0];
- }
- public static void getUndefineSwitch(StringBuffer buffer, String define) {
- buffer.append("-U");
- buffer.append(define);
- }
- public static boolean isCaseSensitive() {
- return false;
- }
- public static void quoteFile(StringBuffer buf, String outPath) {
- if (outPath.charAt(0) != '\"'
- && (outPath.indexOf(' ') >= 0
- || outPath.indexOf('-') >= 0
- || outPath.indexOf('/') >= 0)) {
- buf.append('\"');
- buf.append(outPath);
- buf.append('\"');
- } else {
- buf.append(outPath);
- }
- }
-
- /**
- * Prepares argument list to execute the linker using a response file.
- *
- * @param outputFile
- * linker output file
- * @param args
- * output of prepareArguments
- * @return arguments for runTask
- */
- public static String[] prepareResponseFile(File outputFile,
- String[] args,
- String continuation)
- throws IOException {
- String baseName = outputFile.getName();
- File commandFile = new File(outputFile.getParent(), baseName + ".rsp");
- FileWriter writer = new FileWriter(commandFile);
- for (int i = 1; i < args.length - 1; i++) {
- writer.write(args[i]);
- //
- // if either the current argument ends with
- // or next argument starts with a comma then
- // don't split the line
- if (args[i].endsWith(",") || args[i + 1].startsWith(",")) {
- writer.write(' ');
- } else {
- //
- // split the line to make it more readable
- //
- writer.write(continuation);
- }
- }
- //
- // write the last argument
- //
- if (args.length > 1) {
- writer.write(args[args.length - 1]);
- }
- writer.close();
- String[] execArgs = new String[2];
- execArgs[0] = args[0];
- //
- // left for the caller to decorate
- execArgs[1] = commandFile.toString();
- return execArgs;
- }
-
- private BorlandProcessor() {
- }
-}
+/*
+ *
+ * Copyright 2002-2005 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.borland;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Vector;
+import java.io.FileWriter;
+
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
+/**
+ * A add-in class for Borland(r) processor adapters
+ *
+ *
+ */
+public final class BorlandProcessor {
+ public static void addWarningSwitch(Vector args, int level) {
+ switch (level) {
+ case 0 :
+ args.addElement("-w-");
+ break;
+ case 5 :
+ args.addElement("-w!");
+ break;
+ default :
+ args.addElement("-w");
+ break;
+ }
+ }
+ public static void getDefineSwitch(StringBuffer buffer, String define,
+ String value) {
+ buffer.append("-D");
+ buffer.append(define);
+ if (value != null && value.length() > 0) {
+ buffer.append('=');
+ buffer.append(value);
+ }
+ }
+ /**
+ * This method extracts path information from the appropriate .cfg file in
+ * the install directory.
+ *
+ * @param toolName
+ * Tool name, for example, "bcc32", "brc32", "ilink32"
+ * @param switchChar
+ * Command line switch character, for example "L" for libraries
+ * @param defaultRelativePaths
+ * default paths relative to executable directory
+ * @return path
+ */
+ public static File[] getEnvironmentPath(String toolName, char switchChar,
+ String[] defaultRelativePath) {
+ if (toolName == null) {
+ throw new NullPointerException("toolName");
+ }
+ if (defaultRelativePath == null) {
+ throw new NullPointerException("defaultRelativePath");
+ }
+ String[] path = defaultRelativePath;
+ File exeDir = CUtil.getExecutableLocation(toolName + ".exe");
+ if (exeDir != null) {
+ File cfgFile = new File(exeDir, toolName + ".cfg");
+ if (cfgFile.exists()) {
+ try {
+ Reader reader = new BufferedReader(new FileReader(cfgFile));
+ BorlandCfgParser cfgParser = new BorlandCfgParser(
+ switchChar);
+ path = cfgParser.parsePath(reader);
+ reader.close();
+ } catch (IOException ex) {
+ //
+ // could be logged
+ //
+ }
+ }
+ } else {
+ //
+ // if can't find the executable,
+ // assume current directory to resolve relative paths
+ //
+ exeDir = new File(System.getProperty("user.dir"));
+ }
+ int nonExistant = 0;
+ File[] resourcePath = new File[path.length];
+ for (int i = 0; i < path.length; i++) {
+ resourcePath[i] = new File(path[i]);
+ if (!resourcePath[i].isAbsolute()) {
+ resourcePath[i] = new File(exeDir, path[i]);
+ }
+ //
+ // if any of the entries do not exist or are
+ // not directories, null them out
+ if (!(resourcePath[i].exists() && resourcePath[i].isDirectory())) {
+ resourcePath[i] = null;
+ nonExistant++;
+ }
+ }
+ //
+ // if there were some non-existant or non-directory
+ // entries in the configuration file then
+ // create a shorter array
+ if (nonExistant > 0) {
+ File[] culled = new File[resourcePath.length - nonExistant];
+ int index = 0;
+ for (int i = 0; i < resourcePath.length; i++) {
+ if (resourcePath[i] != null) {
+ culled[index++] = resourcePath[i];
+ }
+ }
+ resourcePath = culled;
+ }
+ return resourcePath;
+ }
+ public static String getIncludeDirSwitch(String includeOption,
+ String includeDir) {
+ StringBuffer buf = new StringBuffer(includeOption);
+ quoteFile(buf, includeDir);
+ return buf.toString();
+ }
+ public static String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
+ StringBuffer buf = new StringBuffer();
+ String[] patterns = new String[libnames.length];
+ for (int i = 0; i < libnames.length; i++) {
+ buf.setLength(0);
+ buf.append(libnames[i]);
+ buf.append(".lib");
+ patterns[i] = buf.toString();
+ }
+ return patterns;
+ }
+ public static String[] getOutputFileSwitch(String outFile) {
+ return new String[0];
+ }
+ public static void getUndefineSwitch(StringBuffer buffer, String define) {
+ buffer.append("-U");
+ buffer.append(define);
+ }
+ public static boolean isCaseSensitive() {
+ return false;
+ }
+ public static void quoteFile(StringBuffer buf, String outPath) {
+ if (outPath.charAt(0) != '\"'
+
+ && (outPath.indexOf(' ') >= 0
+
+ || outPath.indexOf('-') >= 0
+
+ || outPath.indexOf('/') >= 0)) {
+ buf.append('\"');
+ buf.append(outPath);
+ buf.append('\"');
+ } else {
+ buf.append(outPath);
+ }
+ }
+
+ /**
+ * Prepares argument list to execute the linker using a response file.
+ *
+ * @param outputFile
+ * linker output file
+ * @param args
+ * output of prepareArguments
+ * @return arguments for runTask
+ */
+ public static String[] prepareResponseFile(File outputFile,
+ String[] args,
+ String continuation)
+ throws IOException {
+ String baseName = outputFile.getName();
+ File commandFile = new File(outputFile.getParent(), baseName + ".rsp");
+ FileWriter writer = new FileWriter(commandFile);
+ for (int i = 1; i < args.length - 1; i++) {
+ writer.write(args[i]);
+ //
+ // if either the current argument ends with
+ // or next argument starts with a comma then
+ // don't split the line
+ if (args[i].endsWith(",") || args[i + 1].startsWith(",")) {
+ writer.write(' ');
+ } else {
+ //
+ // split the line to make it more readable
+ //
+ writer.write(continuation);
+ }
+ }
+ //
+ // write the last argument
+ //
+ if (args.length > 1) {
+ writer.write(args[args.length - 1]);
+ }
+ writer.close();
+ String[] execArgs = new String[2];
+ execArgs[0] = args[0];
+
+ //
+
+ // left for the caller to decorate
+ execArgs[1] = commandFile.toString();
+ return execArgs;
+ }
+
+ private BorlandProcessor() {
+ }
+}