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