1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. 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, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_codemaker.hxx" 26 #include <stdio.h> 27 28 #include "cunooptions.hxx" 29 30 using namespace rtl; 31 32 sal_Bool CunoOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile) 33 { 34 sal_Bool ret = sal_True; 35 sal_uInt16 i=0; 36 37 if (!bCmdFile) 38 { 39 bCmdFile = sal_True; 40 41 m_program = av[0]; 42 43 if (ac < 2) 44 { 45 fprintf(stderr, "%s", prepareHelp().getStr()); 46 ret = sal_False; 47 } 48 49 i = 1; 50 } else 51 { 52 i = 0; 53 } 54 55 char *s=NULL; 56 for (i; i < ac; i++) 57 { 58 if (av[i][0] == '-') 59 { 60 switch (av[i][1]) 61 { 62 case 'O': 63 if (av[i][2] == 'C') 64 { 65 if (av[i][3] == '\0') 66 { 67 if (i < ac - 1 && av[i+1][0] != '-') 68 { 69 i++; 70 s = av[i]; 71 } else 72 { 73 OString tmp("'-OC', please check"); 74 if (i <= ac - 1) 75 { 76 tmp += " your input '" + OString(av[i+1]) + "'"; 77 } 78 79 throw IllegalArgument(tmp); 80 } 81 } else 82 { 83 s = av[i] + 3; 84 } 85 86 m_options["-OC"] = OString(s); 87 break; 88 } else 89 if (av[i][2] == '\0') 90 { 91 if (i < ac - 1 && av[i+1][0] != '-') 92 { 93 i++; 94 s = av[i]; 95 } else 96 { 97 OString tmp("'-O', please check"); 98 if (i <= ac - 1) 99 { 100 tmp += " your input '" + OString(av[i+1]) + "'"; 101 } 102 103 throw IllegalArgument(tmp); 104 } 105 } else 106 { 107 s = av[i] + 2; 108 } 109 110 m_options["-O"] = OString(s); 111 break; 112 case 'B': 113 if (av[i][2] == '\0') 114 { 115 if (i < ac - 1 && av[i+1][0] != '-') 116 { 117 i++; 118 s = av[i]; 119 } else 120 { 121 OString tmp("'-B', please check"); 122 if (i <= ac - 1) 123 { 124 tmp += " your input '" + OString(av[i+1]) + "'"; 125 } 126 127 throw IllegalArgument(tmp); 128 } 129 } else 130 { 131 s = av[i] + 2; 132 } 133 134 m_options["-B"] = OString(s); 135 break; 136 case 'T': 137 if (av[i][2] == '\0') 138 { 139 if (i < ac - 1 && av[i+1][0] != '-') 140 { 141 i++; 142 s = av[i]; 143 } else 144 { 145 OString tmp("'-T', please check"); 146 if (i <= ac - 1) 147 { 148 tmp += " your input '" + OString(av[i+1]) + "'"; 149 } 150 151 throw IllegalArgument(tmp); 152 } 153 } else 154 { 155 s = av[i] + 2; 156 } 157 158 if (m_options.count("-T") > 0) 159 { 160 OString tmp(m_options["-T"]); 161 tmp = tmp + ";" + s; 162 m_options["-T"] = tmp; 163 } else 164 { 165 m_options["-T"] = OString(s); 166 } 167 break; 168 case 'U': 169 if (av[i][2] != '\0') 170 { 171 OString tmp("'-U', please check"); 172 if (i <= ac - 1) 173 { 174 tmp += " your input '" + OString(av[i]) + "'"; 175 } 176 177 throw IllegalArgument(tmp); 178 } 179 180 m_options["-U"] = OString(""); 181 break; 182 /* 183 case 'L': 184 if (av[i][2] != '\0') 185 { 186 OString tmp("'-L', please check"); 187 if (i <= ac - 1) 188 { 189 tmp += " your input '" + OString(av[i]) + "'"; 190 } 191 192 throw IllegalArgument(tmp); 193 } 194 195 if (isValid("-C") || isValid("-CS")) 196 { 197 OString tmp("'-L' could not be combined with '-C' or '-CS' option"); 198 throw IllegalArgument(tmp); 199 } 200 m_options["-L"] = OString(""); 201 break; 202 */ 203 case 'C': 204 if (av[i][2] != '\0') 205 { 206 OString tmp("'-C', please check"); 207 if (i <= ac - 1) 208 { 209 tmp += " your input '" + OString(av[i]) + "'"; 210 } 211 212 throw IllegalArgument(tmp); 213 } 214 215 if (isValid("-L") || isValid("-CS")) 216 { 217 OString tmp("'-C' could not be combined with '-L' or '-CS' option"); 218 throw IllegalArgument(tmp); 219 } 220 m_options["-C"] = OString(""); 221 break; 222 case 'G': 223 if (av[i][2] == 'c') 224 { 225 if (av[i][3] != '\0') 226 { 227 OString tmp("'-Gc', please check"); 228 if (i <= ac - 1) 229 { 230 tmp += " your input '" + OString(av[i]) + "'"; 231 } 232 233 throw IllegalArgument(tmp); 234 } 235 236 m_options["-Gc"] = OString(""); 237 break; 238 } else 239 if (av[i][2] != '\0') 240 { 241 OString tmp("'-G', please check"); 242 if (i <= ac - 1) 243 { 244 tmp += " your input '" + OString(av[i]) + "'"; 245 } 246 247 throw IllegalArgument(tmp); 248 } 249 250 m_options["-G"] = OString(""); 251 break; 252 default: 253 throw IllegalArgument("the option is unknown" + OString(av[i])); 254 break; 255 } 256 } else 257 { 258 if (av[i][0] == '@') 259 { 260 FILE* cmdFile = fopen(av[i]+1, "r"); 261 if( cmdFile == NULL ) 262 { 263 fprintf(stderr, "%s", prepareHelp().getStr()); 264 ret = sal_False; 265 } else 266 { 267 int rargc=0; 268 char* rargv[512]; 269 char buffer[512]; 270 271 while ( fscanf(cmdFile, "%s", buffer) != EOF ) 272 { 273 rargv[rargc]= strdup(buffer); 274 rargc++; 275 } 276 fclose(cmdFile); 277 278 ret = initOptions(rargc, rargv, bCmdFile); 279 280 for (long i=0; i < rargc; i++) 281 { 282 free(rargv[i]); 283 } 284 } 285 } else 286 { 287 m_inputFiles.push_back(av[i]); 288 } 289 } 290 } 291 292 return ret; 293 } 294 295 OString CunoOptions::prepareHelp() 296 { 297 OString help("\nusing: "); 298 help += m_program + " [-options] file_1 ... file_n\nOptions:\n"; 299 help += " -O<path> = path describes the root directory for the generated output.\n"; 300 help += " The output directory tree is generated under this directory.\n"; 301 help += " -T<name> = name specifies a type or a list of types. The output for this\n"; 302 help += " [t1;...] type is generated. If no '-T' option is specified,\n"; 303 help += " then output for all types is generated.\n"; 304 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; 305 help += " -B<name> = name specifies the base node. All types are searched under this\n"; 306 help += " node. Default is the root '/' of the registry files.\n"; 307 help += " -U = activate the generating of a getCppuType_<name> function.\n"; 308 // help += " -L = getCppuType function with a known leak.\n"; 309 help += " -C = getCppuType_<name> function keeps comprehensive type information.\n"; 310 help += " -G = generate only target files which does not exists.\n"; 311 help += " -Gc = generate only target files which content will be changed.\n"; 312 help += prepareVersion(); 313 314 return help; 315 } 316 317 OString CunoOptions::prepareVersion() 318 { 319 OString version(m_program); 320 version += " Version 1.0\n\n"; 321 return version; 322 } 323