1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_codemaker.hxx" 30*cdf0e10cSrcweir #include <stdio.h> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "corbaoptions.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir using namespace rtl; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir sal_Bool CorbaOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile) 37*cdf0e10cSrcweir throw( IllegalArgument ) 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir sal_Bool ret = sal_True; 40*cdf0e10cSrcweir sal_uInt16 i=0; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir if (!bCmdFile) 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir bCmdFile = sal_True; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir m_program = av[0]; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir if (ac < 2) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir fprintf(stderr, "%s", prepareHelp().getStr()); 51*cdf0e10cSrcweir ret = sal_False; 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir i = 1; 55*cdf0e10cSrcweir } else 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir i = 0; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir char *s=NULL; 61*cdf0e10cSrcweir for (i; i < ac; i++) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir if (av[i][0] == '-') 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir switch (av[i][1]) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir case 'O': 68*cdf0e10cSrcweir if (av[i][2] == '\0') 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-') 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir i++; 73*cdf0e10cSrcweir s = av[i]; 74*cdf0e10cSrcweir } else 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir OString tmp("'-O', please check"); 77*cdf0e10cSrcweir if (i <= ac - 1) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'"; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir throw IllegalArgument(tmp); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir } else 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir s = av[i] + 2; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir m_options["-O"] = OString(s); 90*cdf0e10cSrcweir break; 91*cdf0e10cSrcweir case 'H': 92*cdf0e10cSrcweir if (av[i][2] == '\0') 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-') 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir i++; 97*cdf0e10cSrcweir s = av[i]; 98*cdf0e10cSrcweir } else 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir OString tmp("'-H', please check"); 101*cdf0e10cSrcweir if (i <= ac - 1) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'"; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir throw IllegalArgument(tmp); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } else 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir s = av[i] + 2; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir m_options["-H"] = OString(s); 114*cdf0e10cSrcweir break; 115*cdf0e10cSrcweir case 'B': 116*cdf0e10cSrcweir if (av[i][2] == '\0') 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-') 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir i++; 121*cdf0e10cSrcweir s = av[i]; 122*cdf0e10cSrcweir } else 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir OString tmp("'-B', please check"); 125*cdf0e10cSrcweir if (i <= ac - 1) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'"; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir throw IllegalArgument(tmp); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir } else 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir s = av[i] + 2; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir m_options["-B"] = OString(s); 138*cdf0e10cSrcweir break; 139*cdf0e10cSrcweir case 'T': 140*cdf0e10cSrcweir if (av[i][2] == '\0') 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-') 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir i++; 145*cdf0e10cSrcweir s = av[i]; 146*cdf0e10cSrcweir } else 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir OString tmp("'-T', please check"); 149*cdf0e10cSrcweir if (i <= ac - 1) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'"; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir throw IllegalArgument(tmp); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } else 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir s = av[i] + 2; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir if (m_options.count("-T") > 0) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir OString tmp(m_options["-T"]); 164*cdf0e10cSrcweir tmp = tmp + ";" + s; 165*cdf0e10cSrcweir m_options["-T"] = tmp; 166*cdf0e10cSrcweir } else 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir m_options["-T"] = OString(s); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir break; 171*cdf0e10cSrcweir case 'G': 172*cdf0e10cSrcweir if (av[i][2] != '\0') 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir OString tmp("'-G', please check"); 175*cdf0e10cSrcweir if (i <= ac - 1) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir tmp += " your input '" + OString(av[i]) + "'"; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir throw IllegalArgument(tmp); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir m_options["-G"] = OString(""); 184*cdf0e10cSrcweir break; 185*cdf0e10cSrcweir default: 186*cdf0e10cSrcweir throw IllegalArgument("the option is unknown" + OString(av[i])); 187*cdf0e10cSrcweir break; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir } else 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir if (av[i][0] == '@') 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir FILE* cmdFile = fopen(av[i]+1, "r"); 194*cdf0e10cSrcweir if( cmdFile == NULL ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir fprintf(stderr, "%s", prepareHelp().getStr()); 197*cdf0e10cSrcweir ret = sal_False; 198*cdf0e10cSrcweir } else 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir int rargc=0; 201*cdf0e10cSrcweir char* rargv[512]; 202*cdf0e10cSrcweir char buffer[512]; 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir while ( fscanf(cmdFile, "%s", buffer) != EOF ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir rargv[rargc]= strdup(buffer); 207*cdf0e10cSrcweir rargc++; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir fclose(cmdFile); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir ret = initOptions(rargc, rargv, bCmdFile); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir for (long i=0; i < rargc; i++) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir free(rargv[i]); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir } else 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir m_inputFiles.push_back(av[i]); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir printf("-T: %s\n", m_options["-T"].getStr()); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir return ret; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir OString CorbaOptions::prepareHelp() 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir OString help("\nusing: "); 232*cdf0e10cSrcweir help += m_program + " [-options] file_1 ... file_n\nOptions:\n"; 233*cdf0e10cSrcweir help += " -O<file> = file name for the generated output.\n"; 234*cdf0e10cSrcweir help += " The output directory tree is generated under this directory.\n"; 235*cdf0e10cSrcweir help += " -T<name> = name specifies a type or a list of types. The output for this\n"; 236*cdf0e10cSrcweir help += " [t1;...] type is generated. If no '-T' option is specified,\n"; 237*cdf0e10cSrcweir help += " then output for all types is generated.\n"; 238*cdf0e10cSrcweir help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"; 239*cdf0e10cSrcweir help += " -B<name> = name specifies the base node. All types are searched under this\n"; 240*cdf0e10cSrcweir help += " node. Default is the root '/' of the registry files.\n"; 241*cdf0e10cSrcweir help += " -G = generate only target files which does not exists.\n"; 242*cdf0e10cSrcweir help += " -H<header> = include CORBA generated <header>.\n"; 243*cdf0e10cSrcweir help += prepareVersion(); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir return help; 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir OString CorbaOptions::prepareVersion() 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir OString version(m_program); 251*cdf0e10cSrcweir version += m_program + " Version 2.0\n\n"; 252*cdf0e10cSrcweir return version; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir 256