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 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_codemaker.hxx" 30 #include <stdio.h> 31 #include <string.h> 32 #include "javaoptions.hxx" 33 #include "osl/process.h" 34 #include "osl/thread.h" 35 36 #ifdef SAL_UNX 37 #define SEPARATOR '/' 38 #else 39 #define SEPARATOR '\\' 40 #endif 41 42 using namespace rtl; 43 44 sal_Bool JavaOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile) 45 throw( IllegalArgument ) 46 { 47 sal_Bool ret = sal_True; 48 sal_uInt16 i=0; 49 50 if (!bCmdFile) 51 { 52 bCmdFile = sal_True; 53 54 OString name(av[0]); 55 sal_Int32 index = name.lastIndexOf(SEPARATOR); 56 m_program = name.copy((index > 0 ? index+1 : 0)); 57 58 if (ac < 2) 59 { 60 fprintf(stderr, "%s", prepareHelp().getStr()); 61 ret = sal_False; 62 } 63 64 i = 1; 65 } else 66 { 67 i = 0; 68 } 69 70 char *s=NULL; 71 for( ; i < ac; i++) 72 { 73 if (av[i][0] == '-') 74 { 75 switch (av[i][1]) 76 { 77 case 'O': 78 if (av[i][2] == '\0') 79 { 80 if (i < ac - 1 && av[i+1][0] != '-') 81 { 82 i++; 83 s = av[i]; 84 } else 85 { 86 OString tmp("'-O', please check"); 87 if (i <= ac - 1) 88 { 89 tmp += " your input '" + OString(av[i+1]) + "'"; 90 } 91 92 throw IllegalArgument(tmp); 93 } 94 } else 95 { 96 s = av[i] + 2; 97 } 98 99 m_options["-O"] = OString(s); 100 break; 101 case 'B': 102 if (av[i][2] == '\0') 103 { 104 if (i < ac - 1 && av[i+1][0] != '-') 105 { 106 i++; 107 s = av[i]; 108 } else 109 { 110 OString tmp("'-B', please check"); 111 if (i <= ac - 1) 112 { 113 tmp += " your input '" + OString(av[i+1]) + "'"; 114 } 115 116 throw IllegalArgument(tmp); 117 } 118 } else 119 { 120 s = av[i] + 2; 121 } 122 123 m_options["-B"] = OString(s); 124 break; 125 case 'n': 126 if (av[i][2] != 'D' || av[i][3] != '\0') 127 { 128 OString tmp("'-nD', please check"); 129 tmp += " your input '" + OString(av[i]) + "'"; 130 throw IllegalArgument(tmp); 131 } 132 133 m_options["-nD"] = OString(""); 134 break; 135 case 'T': 136 if (av[i][2] == '\0') 137 { 138 if (i < ac - 1 && av[i+1][0] != '-') 139 { 140 i++; 141 s = av[i]; 142 } else 143 { 144 OString tmp("'-T', please check"); 145 if (i <= ac - 1) 146 { 147 tmp += " your input '" + OString(av[i+1]) + "'"; 148 } 149 150 throw IllegalArgument(tmp); 151 } 152 } else 153 { 154 s = av[i] + 2; 155 } 156 157 if (m_options.count("-T") > 0) 158 { 159 OString tmp(m_options["-T"]); 160 tmp = tmp + ";" + s; 161 m_options["-T"] = tmp; 162 } else 163 { 164 m_options["-T"] = OString(s); 165 } 166 break; 167 case 'G': 168 if (av[i][2] == 'c') 169 { 170 if (av[i][3] != '\0') 171 { 172 OString tmp("'-Gc', please check"); 173 if (i <= ac - 1) 174 { 175 tmp += " your input '" + OString(av[i]) + "'"; 176 } 177 178 throw IllegalArgument(tmp); 179 } 180 181 m_options["-Gc"] = OString(""); 182 break; 183 } else 184 if (av[i][2] != '\0') 185 { 186 OString tmp("'-G', please check"); 187 if (i <= ac - 1) 188 { 189 tmp += " your input '" + OString(av[i]) + "'"; 190 } 191 192 throw IllegalArgument(tmp); 193 } 194 195 m_options["-G"] = OString(""); 196 break; 197 case 'X': // support for eXtra type rdbs 198 { 199 if (av[i][2] == '\0') 200 { 201 if (i < ac - 1 && av[i+1][0] != '-') 202 { 203 i++; 204 s = av[i]; 205 } else 206 { 207 OString tmp("'-X', please check"); 208 if (i <= ac - 1) 209 { 210 tmp += " your input '" + OString(av[i+1]) + "'"; 211 } 212 213 throw IllegalArgument(tmp); 214 } 215 } else 216 { 217 s = av[i] + 2; 218 } 219 220 m_extra_input_files.push_back( s ); 221 break; 222 } 223 224 default: 225 throw IllegalArgument("the option is unknown" + OString(av[i])); 226 } 227 } else 228 { 229 if (av[i][0] == '@') 230 { 231 FILE* cmdFile = fopen(av[i]+1, "r"); 232 if( cmdFile == NULL ) 233 { 234 fprintf(stderr, "%s", prepareHelp().getStr()); 235 ret = sal_False; 236 } else 237 { 238 int rargc=0; 239 char* rargv[512]; 240 char buffer[512]; 241 242 while ( fscanf(cmdFile, "%s", buffer) != EOF ) 243 { 244 rargv[rargc]= strdup(buffer); 245 rargc++; 246 } 247 fclose(cmdFile); 248 249 ret = initOptions(rargc, rargv, bCmdFile); 250 251 for (long j=0; j < rargc; j++) 252 { 253 free(rargv[j]); 254 } 255 } 256 } else 257 { 258 if (bCmdFile) 259 { 260 m_inputFiles.push_back(av[i]); 261 } else 262 { 263 OUString system_filepath; 264 if (osl_getCommandArg( i-1, &system_filepath.pData ) 265 != osl_Process_E_None) 266 { 267 OSL_ASSERT(false); 268 } 269 m_inputFiles.push_back(OUStringToOString(system_filepath, osl_getThreadTextEncoding())); 270 } 271 } 272 } 273 } 274 275 return ret; 276 } 277 278 OString JavaOptions::prepareHelp() 279 { 280 OString help("\nusing: "); 281 help += m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n"; 282 help += " -O<path> = path describes the root directory for the generated output.\n"; 283 help += " The output directory tree is generated under this directory.\n"; 284 help += " -T<name> = name specifies a type or a list of types. The output for this\n"; 285 help += " [t1;...] type and all dependent types are generated. If no '-T' option is \n"; 286 help += " specified, then output for all types is generated.\n"; 287 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; 288 help += " -B<name> = name specifies the base node. All types are searched under this\n"; 289 help += " node. Default is the root '/' of the registry files.\n"; 290 help += " -nD = no dependent types are generated.\n"; 291 help += " -G = generate only target files which does not exists.\n"; 292 help += " -Gc = generate only target files which content will be changed.\n"; 293 help += " -X<file> = extra types which will not be taken into account for generation.\n\n"; 294 help += prepareVersion(); 295 296 return help; 297 } 298 299 OString JavaOptions::prepareVersion() 300 { 301 OString version(m_program); 302 version += " Version 2.0\n\n"; 303 return version; 304 } 305 306 307