1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include <stdio.h> 28 #include <string.h> 29 30 #include "rdboptions.hxx" 31 32 using namespace rtl; 33 34 sal_Bool RdbOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile) 35 throw( IllegalArgument ) 36 { 37 sal_Bool ret = sal_True; 38 sal_uInt16 i=0; 39 40 if (!bCmdFile) 41 { 42 bCmdFile = sal_True; 43 44 m_program = av[0]; 45 46 if (ac < 2) 47 { 48 fprintf(stderr, "%s", prepareHelp().getStr()); 49 ret = sal_False; 50 } 51 52 i = 1; 53 } else 54 { 55 i = 0; 56 } 57 58 char *s=NULL; 59 for (; i < ac; i++) 60 { 61 if (av[i][0] == '-') 62 { 63 switch (av[i][1]) 64 { 65 case 'O': 66 if (av[i][2] == '\0') 67 { 68 if (i < ac - 1 && av[i+1][0] != '-') 69 { 70 i++; 71 s = av[i]; 72 } else 73 { 74 OString tmp("'-O', please check"); 75 if (i <= ac - 1) 76 { 77 tmp += " your input '" + OString(av[i+1]) + "'"; 78 } 79 80 throw IllegalArgument(tmp); 81 } 82 } else 83 { 84 s = av[i] + 2; 85 } 86 87 m_options["-O"] = OString(s); 88 break; 89 case 'X': 90 if (av[i][2] == '\0') 91 { 92 if (i < ac - 1 && av[i+1][0] != '-') 93 { 94 i++; 95 s = av[i]; 96 } else 97 { 98 OString tmp("'-X', please check"); 99 if (i <= ac - 1) 100 { 101 tmp += " your input '" + OString(av[i+1]) + "'"; 102 } 103 104 throw IllegalArgument(tmp); 105 } 106 } else 107 { 108 s = av[i] + 2; 109 } 110 111 m_options["-X"] = OString(s); 112 break; 113 case 'R': 114 if (av[i][2] == '\0') 115 { 116 if (i < ac - 1 && av[i+1][0] != '-') 117 { 118 i++; 119 s = av[i]; 120 } else 121 { 122 OString tmp("'-R', please check"); 123 if (i <= ac - 1) 124 { 125 tmp += " your input '" + OString(av[i+1]) + "'"; 126 } 127 128 throw IllegalArgument(tmp); 129 } 130 } else 131 { 132 s = av[i] + 2; 133 } 134 135 m_options["-R"] = OString(s); 136 break; 137 case 'B': 138 if (av[i][2] == '\0') 139 { 140 if (i < ac - 1 && av[i+1][0] != '-') 141 { 142 i++; 143 s = av[i]; 144 } else 145 { 146 OString tmp("'-B', please check"); 147 if (i <= ac - 1) 148 { 149 tmp += " your input '" + OString(av[i+1]) + "'"; 150 } 151 152 throw IllegalArgument(tmp); 153 } 154 } else 155 { 156 s = av[i] + 2; 157 } 158 159 m_options["-B"] = OString(s); 160 break; 161 case 'b': 162 if (av[i][2] == '\0') 163 { 164 if (i < ac - 1 && av[i+1][0] != '-') 165 { 166 i++; 167 s = av[i]; 168 } else 169 { 170 OString tmp("'-b', please check"); 171 if (i <= ac - 1) 172 { 173 tmp += " your input '" + OString(av[i+1]) + "'"; 174 } 175 176 throw IllegalArgument(tmp); 177 } 178 } else 179 { 180 s = av[i] + 2; 181 } 182 183 m_options["-b"] = OString(s); 184 break; 185 case 'T': 186 if (av[i][2] == '\0') 187 { 188 if (i < ac - 1 && av[i+1][0] != '-') 189 { 190 i++; 191 s = av[i]; 192 } else 193 { 194 OString tmp("'-T', please check"); 195 if (i <= ac - 1) 196 { 197 tmp += " your input '" + OString(av[i+1]) + "'"; 198 } 199 200 throw IllegalArgument(tmp); 201 } 202 } else 203 { 204 s = av[i] + 2; 205 } 206 207 if (m_options.count("-T") > 0) 208 { 209 OString tmp(m_options["-T"]); 210 tmp = tmp + ";" + s; 211 m_options["-T"] = tmp; 212 } else 213 { 214 m_options["-T"] = OString(s); 215 } 216 break; 217 case 'F': 218 if (av[i][2] == 'T') 219 { 220 if (av[i][3] == '\0') 221 { 222 if (i < ac - 1 && av[i+1][0] != '-') 223 { 224 i++; 225 s = av[i]; 226 } else 227 { 228 OString tmp("'-FT', please check"); 229 if (i <= ac - 1) 230 { 231 tmp += " your input '" + OString(av[i+1]) + "'"; 232 } 233 234 throw IllegalArgument(tmp); 235 } 236 } else 237 { 238 s = av[i] + 3; 239 } 240 241 if (m_options.count("-FT") > 0) 242 { 243 OString tmp(m_options["-FT"]); 244 tmp = tmp + ";" + s; 245 m_options["-FT"] = tmp; 246 } else 247 { 248 m_options["-FT"] = OString(s); 249 } 250 } else 251 { 252 if (av[i][2] == '\0') 253 { 254 if (i < ac - 1 && av[i+1][0] != '-') 255 { 256 i++; 257 s = av[i]; 258 } else 259 { 260 OString tmp("'-F', please check"); 261 if (i <= ac - 1) 262 { 263 tmp += " your input '" + OString(av[i+1]) + "'"; 264 } 265 266 throw IllegalArgument(tmp); 267 } 268 } else 269 { 270 s = av[i] + 2; 271 } 272 273 m_options["-F"] = OString(s); 274 } 275 break; 276 case 'L': 277 if (av[i][2] != '\0') 278 { 279 OString tmp("'-L', please check"); 280 if (i <= ac - 1) 281 { 282 tmp += " your input '" + OString(av[i+1]) + "'"; 283 } 284 285 throw IllegalArgument(tmp); 286 } 287 288 m_options["-L"] = OString(); 289 m_generateTypeList = sal_True; 290 break; 291 default: 292 throw IllegalArgument("the option is unknown" + OString(av[i])); 293 } 294 } else 295 { 296 if (av[i][0] == '@') 297 { 298 FILE* cmdFile = fopen(av[i]+1, "r"); 299 if( cmdFile == NULL ) 300 { 301 fprintf(stderr, "%s", prepareHelp().getStr()); 302 ret = sal_False; 303 } else 304 { 305 int rargc=0; 306 char* rargv[512]; 307 char buffer[512]; 308 309 while ( fscanf(cmdFile, "%s", buffer) != EOF ) 310 { 311 rargv[rargc]= strdup(buffer); 312 rargc++; 313 } 314 fclose(cmdFile); 315 316 ret = initOptions(rargc, rargv, bCmdFile); 317 318 for (long j=0; j < rargc; j++) 319 { 320 free(rargv[j]); 321 } 322 } 323 } else 324 { 325 m_inputFiles.push_back(av[i]); 326 } 327 } 328 } 329 330 return ret; 331 } 332 333 OString RdbOptions::prepareHelp() 334 { 335 OString help("\nusing: "); 336 help += m_program + " [-options] (-R<regname> | file_1 [... file_n])\n"; 337 help += "The rdbmaker supports 2 modes:\n"; 338 help += " 1. using the internal UNO type description manager -> use -R<regname>\n" 339 " where regname specifies the type library used by the UNO type description manager\n" 340 " after UNO is bootstrapped. This option disables the use of any other type libraries.\n" 341 " The tpye library must be a valid product type library which means that all types are\n" 342 " stored under the global base node UCR (Uno Core Reflection data).\n"; 343 help += " 2. using one or more type library files -> use file_1 ... file_n\n" 344 " file_1 .. file_n specifies one or more valid type library files which are used to\n" 345 " find the needed type information. The used type libraries have to support the same base\n" 346 " node (-B option).\n"; 347 help += "Options:\n"; 348 help += " -O<filename> = filename specifies the name of the generated registry\n"; 349 help += " or text file.\n"; 350 help += " -L = specifies that only a text file is generated with the\n"; 351 help += " names of the specified types and their dependencies.\n"; 352 help += " Default is that a registry file will be created\n"; 353 // help += " -X<xmlfile> = xmlfile specifies the name of an xml description where\n"; 354 // help += " all types are specified which will be generated.\n"; 355 help += " -T<name> = name specifies a type or a list of types. The output for\n"; 356 help += " [t1;...] this type is generated.\n"; 357 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; 358 help += " -FT<name> = name specifies a type or a list of types. For this types\n"; 359 help += " [t1;...] nothing will be generated.\n"; 360 help += " |F<file> = file specifies an text file. For the specified types in\n" ; 361 help += " this file nothing will be generated.\n"; 362 help += " -B<name> = name specifies the base node. All types are searched under\n"; 363 help += " this node. Default is the root '/' of the registry files.\n"; 364 help += " This option takes effect using run mode 2 only.\n"; 365 help += " -b<name> = name specifies the base node of the output registry. All\n"; 366 help += " types will be generated under this node. Default is the\n"; 367 help += " root '/' of the registry file.\n"; 368 help += prepareVersion(); 369 370 return help; 371 } 372 373 OString RdbOptions::prepareVersion() 374 { 375 OString version("\nSun Microsystems (R) "); 376 version += m_program + " Version 2.0\n\n"; 377 378 return version; 379 } 380 381 382