1 /*
2 * #%L
3 * Native ARchive plugin for Maven
4 * %%
5 * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6 * %%
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * #L%
19 */
20 package com.github.maven_nar.cpptasks.openwatcom;
21
22 import java.util.Vector;
23
24 import com.github.maven_nar.cpptasks.types.LibraryTypeEnum;
25
26 /**
27 * A add-in class for OpenWatcom processors.
28 *
29 *
30 */
31 public final class OpenWatcomProcessor {
32 /**
33 * Adds warning command line options.
34 *
35 * @param args
36 * Vector list of options
37 * @param level
38 * int value of WarningLevelEnum
39 */
40 public static void addWarningSwitch(final Vector<String> args, final int level) {
41 switch (level) {
42 case 0:
43 args.addElement("/w0");
44 break;
45 case 1:
46 args.addElement("/w1");
47 break;
48 case 2:
49 break;
50 case 3:
51 args.addElement("/w2");
52 break;
53 case 4:
54 args.addElement("/w3");
55 break;
56 case 5:
57 args.addElement("/we");
58 break;
59 default:
60 args.addElement("/w1");
61 break;
62 }
63 }
64
65 /**
66 * Gets command line option to read from an option file.
67 *
68 * @param cmdFile
69 * String file name for option file
70 * @return String Command line option
71 */
72 public static String getCommandFileSwitch(final String cmdFile) {
73 final StringBuffer buf = new StringBuffer("@");
74 if (cmdFile.indexOf(' ') >= 0) {
75 buf.append('\"');
76 buf.append(cmdFile.replace('/', '\\'));
77 buf.append('\"');
78 } else {
79 buf.append(cmdFile);
80 }
81 return buf.toString();
82 }
83
84 /**
85 * Creates a command line option to define a preprocessor macro.
86 *
87 * @param buffer
88 * StringBuffer destination buffer
89 * @param define
90 * String parameter to define
91 * @param value
92 * String value, may be null
93 */
94 public static void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
95 buffer.append("/d");
96 buffer.append(define);
97 if (value != null && value.length() > 0) {
98 buffer.append('=');
99 buffer.append(value);
100 }
101 }
102
103 /**
104 * Create a command line option to add a directory to the include path.
105 *
106 * @param includeDir
107 * String directory
108 * @return String command line option
109 */
110 public static String getIncludeDirSwitch(final String includeDir) {
111 return "/i=" + includeDir.replace('/', '\\');
112 }
113
114 /**
115 * Get file selectors for specified libraries.
116 *
117 * @param libnames
118 * library names
119 * @param libType
120 * library type
121 * @return file selectors
122 */
123 public static String[] getLibraryPatterns(final String[] libnames, final LibraryTypeEnum libType) {
124 final StringBuffer buf = new StringBuffer();
125 final String[] patterns = new String[libnames.length];
126 for (int i = 0; i < libnames.length; i++) {
127 buf.setLength(0);
128 buf.append(libnames[i]);
129 buf.append(".lib");
130 patterns[i] = buf.toString();
131 }
132 return patterns;
133 }
134
135 /**
136 * Builds command line options to specify the output file names.
137 *
138 * @param outPath
139 * String path to output file
140 * @return String[] command line options
141 */
142 public static String[] getOutputFileSwitch(final String outPath) {
143 final StringBuffer buf = new StringBuffer("/fo=");
144 if (outPath.indexOf(' ') >= 0) {
145 buf.append('\"');
146 buf.append(outPath);
147 buf.append('\"');
148 } else {
149 buf.append(outPath);
150 }
151 final String[] retval = new String[] {
152 buf.toString()
153 };
154 return retval;
155 }
156
157 /**
158 * Builds a command line option to undefine a preprocessor macro.
159 *
160 * @param buffer
161 * StringBuffer destination
162 * @param define
163 * String macro to be undefined
164 */
165 public static void getUndefineSwitch(final StringBuffer buffer, final String define) {
166 buffer.append("/u");
167 buffer.append(define);
168 }
169
170 /**
171 * Gets whether processor tratement of file names is case-sensitive.
172 *
173 * @return boolean true if case sensitive
174 */
175 public static boolean isCaseSensitive() {
176 return false;
177 }
178
179 /**
180 * Private constructor.
181 */
182 private OpenWatcomProcessor() {
183 }
184
185 }