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 32 #include "corbaoptions.hxx" 33 34 using namespace rtl; 35 36 sal_Bool CorbaOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile) 37 throw( IllegalArgument ) 38 { 39 sal_Bool ret = sal_True; 40 sal_uInt16 i=0; 41 42 if (!bCmdFile) 43 { 44 bCmdFile = sal_True; 45 46 m_program = av[0]; 47 48 if (ac < 2) 49 { 50 fprintf(stderr, "%s", prepareHelp().getStr()); 51 ret = sal_False; 52 } 53 54 i = 1; 55 } else 56 { 57 i = 0; 58 } 59 60 char *s=NULL; 61 for (i; i < ac; i++) 62 { 63 if (av[i][0] == '-') 64 { 65 switch (av[i][1]) 66 { 67 case 'O': 68 if (av[i][2] == '\0') 69 { 70 if (i < ac - 1 && av[i+1][0] != '-') 71 { 72 i++; 73 s = av[i]; 74 } else 75 { 76 OString tmp("'-O', please check"); 77 if (i <= ac - 1) 78 { 79 tmp += " your input '" + OString(av[i+1]) + "'"; 80 } 81 82 throw IllegalArgument(tmp); 83 } 84 } else 85 { 86 s = av[i] + 2; 87 } 88 89 m_options["-O"] = OString(s); 90 break; 91 case 'H': 92 if (av[i][2] == '\0') 93 { 94 if (i < ac - 1 && av[i+1][0] != '-') 95 { 96 i++; 97 s = av[i]; 98 } else 99 { 100 OString tmp("'-H', please check"); 101 if (i <= ac - 1) 102 { 103 tmp += " your input '" + OString(av[i+1]) + "'"; 104 } 105 106 throw IllegalArgument(tmp); 107 } 108 } else 109 { 110 s = av[i] + 2; 111 } 112 113 m_options["-H"] = OString(s); 114 break; 115 case 'B': 116 if (av[i][2] == '\0') 117 { 118 if (i < ac - 1 && av[i+1][0] != '-') 119 { 120 i++; 121 s = av[i]; 122 } else 123 { 124 OString tmp("'-B', please check"); 125 if (i <= ac - 1) 126 { 127 tmp += " your input '" + OString(av[i+1]) + "'"; 128 } 129 130 throw IllegalArgument(tmp); 131 } 132 } else 133 { 134 s = av[i] + 2; 135 } 136 137 m_options["-B"] = OString(s); 138 break; 139 case 'T': 140 if (av[i][2] == '\0') 141 { 142 if (i < ac - 1 && av[i+1][0] != '-') 143 { 144 i++; 145 s = av[i]; 146 } else 147 { 148 OString tmp("'-T', please check"); 149 if (i <= ac - 1) 150 { 151 tmp += " your input '" + OString(av[i+1]) + "'"; 152 } 153 154 throw IllegalArgument(tmp); 155 } 156 } else 157 { 158 s = av[i] + 2; 159 } 160 161 if (m_options.count("-T") > 0) 162 { 163 OString tmp(m_options["-T"]); 164 tmp = tmp + ";" + s; 165 m_options["-T"] = tmp; 166 } else 167 { 168 m_options["-T"] = OString(s); 169 } 170 break; 171 case 'G': 172 if (av[i][2] != '\0') 173 { 174 OString tmp("'-G', please check"); 175 if (i <= ac - 1) 176 { 177 tmp += " your input '" + OString(av[i]) + "'"; 178 } 179 180 throw IllegalArgument(tmp); 181 } 182 183 m_options["-G"] = OString(""); 184 break; 185 default: 186 throw IllegalArgument("the option is unknown" + OString(av[i])); 187 break; 188 } 189 } else 190 { 191 if (av[i][0] == '@') 192 { 193 FILE* cmdFile = fopen(av[i]+1, "r"); 194 if( cmdFile == NULL ) 195 { 196 fprintf(stderr, "%s", prepareHelp().getStr()); 197 ret = sal_False; 198 } else 199 { 200 int rargc=0; 201 char* rargv[512]; 202 char buffer[512]; 203 204 while ( fscanf(cmdFile, "%s", buffer) != EOF ) 205 { 206 rargv[rargc]= strdup(buffer); 207 rargc++; 208 } 209 fclose(cmdFile); 210 211 ret = initOptions(rargc, rargv, bCmdFile); 212 213 for (long i=0; i < rargc; i++) 214 { 215 free(rargv[i]); 216 } 217 } 218 } else 219 { 220 m_inputFiles.push_back(av[i]); 221 } 222 } 223 } 224 printf("-T: %s\n", m_options["-T"].getStr()); 225 226 return ret; 227 } 228 229 OString CorbaOptions::prepareHelp() 230 { 231 OString help("\nusing: "); 232 help += m_program + " [-options] file_1 ... file_n\nOptions:\n"; 233 help += " -O<file> = file name for the generated output.\n"; 234 help += " The output directory tree is generated under this directory.\n"; 235 help += " -T<name> = name specifies a type or a list of types. The output for this\n"; 236 help += " [t1;...] type is generated. If no '-T' option is specified,\n"; 237 help += " then output for all types is generated.\n"; 238 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; 239 help += " -B<name> = name specifies the base node. All types are searched under this\n"; 240 help += " node. Default is the root '/' of the registry files.\n"; 241 help += " -G = generate only target files which does not exists.\n"; 242 help += " -H<header> = include CORBA generated <header>.\n"; 243 help += prepareVersion(); 244 245 return help; 246 } 247 248 OString CorbaOptions::prepareVersion() 249 { 250 OString version(m_program); 251 version += m_program + " Version 2.0\n\n"; 252 return version; 253 } 254 255 256