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 "idloptions.hxx" 29 30 using namespace rtl; 31 32 sal_Bool IdlOptions::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] == '\0') 64 { 65 if (i < ac - 1 && av[i+1][0] != '-') 66 { 67 i++; 68 s = av[i]; 69 } else 70 { 71 OString tmp("'-O', please check"); 72 if (i <= ac - 1) 73 { 74 tmp += " your input '" + OString(av[i+1]) + "'"; 75 } 76 77 throw IllegalArgument(tmp); 78 } 79 } else 80 { 81 s = av[i] + 2; 82 } 83 84 m_options["-O"] = OString(s); 85 break; 86 case 'B': 87 if (av[i][2] == '\0') 88 { 89 if (i < ac - 1 && av[i+1][0] != '-') 90 { 91 i++; 92 s = av[i]; 93 } else 94 { 95 OString tmp("'-B', please check"); 96 if (i <= ac - 1) 97 { 98 tmp += " your input '" + OString(av[i+1]) + "'"; 99 } 100 101 throw IllegalArgument(tmp); 102 } 103 } else 104 { 105 s = av[i] + 2; 106 } 107 108 m_options["-B"] = OString(s); 109 break; 110 case 'T': 111 if (av[i][2] == '\0') 112 { 113 if (i < ac - 1 && av[i+1][0] != '-') 114 { 115 i++; 116 s = av[i]; 117 } else 118 { 119 OString tmp("'-T', please check"); 120 if (i <= ac - 1) 121 { 122 tmp += " your input '" + OString(av[i+1]) + "'"; 123 } 124 125 throw IllegalArgument(tmp); 126 } 127 } else 128 { 129 s = av[i] + 2; 130 } 131 132 if (m_options.count("-T") > 0) 133 { 134 OString tmp(m_options["-T"]); 135 tmp = tmp + ";" + s; 136 m_options["-T"] = tmp; 137 } else 138 { 139 m_options["-T"] = OString(s); 140 } 141 break; 142 case 'G': 143 if (av[i][2] == 'c') 144 { 145 if (av[i][3] != '\0') 146 { 147 OString tmp("'-Gc', please check"); 148 if (i <= ac - 1) 149 { 150 tmp += " your input '" + OString(av[i]) + "'"; 151 } 152 153 throw IllegalArgument(tmp); 154 } 155 156 m_options["-Gc"] = OString(""); 157 break; 158 } else 159 if (av[i][2] != '\0') 160 { 161 OString tmp("'-G', please check"); 162 if (i <= ac - 1) 163 { 164 tmp += " your input '" + OString(av[i]) + "'"; 165 } 166 167 throw IllegalArgument(tmp); 168 } 169 170 m_options["-G"] = OString(""); 171 break; 172 default: 173 throw IllegalArgument("the option is unknown" + OString(av[i])); 174 break; 175 } 176 } else 177 { 178 if (av[i][0] == '@') 179 { 180 FILE* cmdFile = fopen(av[i]+1, "r"); 181 if( cmdFile == NULL ) 182 { 183 fprintf(stderr, "%s", prepareHelp().getStr()); 184 ret = sal_False; 185 } else 186 { 187 int rargc=0; 188 char* rargv[512]; 189 char buffer[512]; 190 191 while ( fscanf(cmdFile, "%s", buffer) != EOF ) 192 { 193 rargv[rargc]= strdup(buffer); 194 rargc++; 195 } 196 fclose(cmdFile); 197 198 ret = initOptions(rargc, rargv, bCmdFile); 199 200 for (long i=0; i < rargc; i++) 201 { 202 free(rargv[i]); 203 } 204 } 205 } else 206 { 207 m_inputFiles.push_back(av[i]); 208 } 209 } 210 } 211 212 return ret; 213 } 214 215 OString IdlOptions::prepareHelp() 216 { 217 OString help("\nusing: "); 218 help += m_program + " [-options] file_1 ... file_n\nOptions:\n"; 219 help += " -O<path> = path describes the root directory for the generated output.\n"; 220 help += " The output directory tree is generated under this directory.\n"; 221 help += " -T<name> = name specifies a type or a list of types. The output for this\n"; 222 help += " [t1;...] type is generated. If no '-T' option is specified,\n"; 223 help += " then output for all types is generated.\n"; 224 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; 225 help += " -B<name> = name specifies the base node. All types are searched under this\n"; 226 help += " node. Default is the root '/' of the registry files.\n"; 227 help += " -G = generate only target files which does not exists.\n"; 228 help += " -Gc = generate only target files which content will be changed.\n"; 229 help += "IMPORTANT: You lose enum values and struct, exception inheritance!\n"; 230 help += " Parameter name Object is translated to _Object!\n"; 231 help += " The type type is translated to CORBA::TypeCode!\n"; 232 help += " Sequences are expanded to a typedef name Sequence_..._\"name\"!\n"; 233 help += prepareVersion(); 234 235 return help; 236 } 237 238 OString IdlOptions::prepareVersion() 239 { 240 OString version(m_program); 241 version += " Version 2.0\n\n"; 242 return version; 243 } 244