xref: /trunk/main/codemaker/source/idlmaker/idloptions.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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    "idloptions.hxx"
33 
34 using namespace rtl;
35 
36 sal_Bool IdlOptions::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 'B':
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("'-B', 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["-B"] = OString(s);
114                     break;
115                 case 'T':
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("'-T', 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                     if (m_options.count("-T") > 0)
138                     {
139                         OString tmp(m_options["-T"]);
140                         tmp = tmp + ";" + s;
141                         m_options["-T"] = tmp;
142                     } else
143                     {
144                         m_options["-T"] = OString(s);
145                     }
146                     break;
147                 case 'G':
148                     if (av[i][2] == 'c')
149                     {
150                         if (av[i][3] != '\0')
151                         {
152                             OString tmp("'-Gc', please check");
153                             if (i <= ac - 1)
154                             {
155                                 tmp += " your input '" + OString(av[i]) + "'";
156                             }
157 
158                             throw IllegalArgument(tmp);
159                         }
160 
161                         m_options["-Gc"] = OString("");
162                         break;
163                     } else
164                     if (av[i][2] != '\0')
165                     {
166                         OString tmp("'-G', please check");
167                         if (i <= ac - 1)
168                         {
169                             tmp += " your input '" + OString(av[i]) + "'";
170                         }
171 
172                         throw IllegalArgument(tmp);
173                     }
174 
175                     m_options["-G"] = OString("");
176                     break;
177                 default:
178                     throw IllegalArgument("the option is unknown" + OString(av[i]));
179                     break;
180             }
181         } else
182         {
183             if (av[i][0] == '@')
184             {
185                 FILE* cmdFile = fopen(av[i]+1, "r");
186                 if( cmdFile == NULL )
187                 {
188                     fprintf(stderr, "%s", prepareHelp().getStr());
189                     ret = sal_False;
190                 } else
191                 {
192                     int rargc=0;
193                     char* rargv[512];
194                     char  buffer[512];
195 
196                     while ( fscanf(cmdFile, "%s", buffer) != EOF )
197                     {
198                         rargv[rargc]= strdup(buffer);
199                         rargc++;
200                     }
201                     fclose(cmdFile);
202 
203                     ret = initOptions(rargc, rargv, bCmdFile);
204 
205                     for (long i=0; i < rargc; i++)
206                     {
207                         free(rargv[i]);
208                     }
209                 }
210             } else
211             {
212                 m_inputFiles.push_back(av[i]);
213             }
214         }
215     }
216 
217     return ret;
218 }
219 
220 OString IdlOptions::prepareHelp()
221 {
222     OString help("\nusing: ");
223     help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
224     help += "    -O<path>   = path describes the root directory for the generated output.\n";
225     help += "                 The output directory tree is generated under this directory.\n";
226     help += "    -T<name>   = name specifies a type or a list of types. The output for this\n";
227     help += "      [t1;...]   type is generated. If no '-T' option is specified,\n";
228     help += "                 then output for all types is generated.\n";
229     help += "                 Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
230     help += "    -B<name>   = name specifies the base node. All types are searched under this\n";
231     help += "                 node. Default is the root '/' of the registry files.\n";
232     help += "    -G         = generate only target files which does not exists.\n";
233     help += "    -Gc        = generate only target files which content will be changed.\n";
234     help += "IMPORTANT:       You lose enum values and struct, exception inheritance!\n";
235     help += "                 Parameter name Object is translated to _Object!\n";
236     help += "                 The type type is translated to CORBA::TypeCode!\n";
237     help += "                 Sequences are expanded to a typedef name Sequence_..._\"name\"!\n";
238     help += prepareVersion();
239 
240     return help;
241 }
242 
243 OString IdlOptions::prepareVersion()
244 {
245     OString version(m_program);
246     version += " Version 2.0\n\n";
247     return version;
248 }
249 
250 
251