PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/rdbmaker/source/rdbmaker/rdboptions.cxx

https://bitbucket.org/mst/ooo340
C++ | 381 lines | 317 code | 36 blank | 28 comment | 68 complexity | e24a170d9155265984d989f3e5af5fa7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  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. #include <stdio.h>
  28. #include <string.h>
  29. #include "rdboptions.hxx"
  30. using namespace rtl;
  31. sal_Bool RdbOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
  32. throw( IllegalArgument )
  33. {
  34. sal_Bool ret = sal_True;
  35. sal_uInt16 i=0;
  36. if (!bCmdFile)
  37. {
  38. bCmdFile = sal_True;
  39. m_program = av[0];
  40. if (ac < 2)
  41. {
  42. fprintf(stderr, "%s", prepareHelp().getStr());
  43. ret = sal_False;
  44. }
  45. i = 1;
  46. } else
  47. {
  48. i = 0;
  49. }
  50. char *s=NULL;
  51. for (; i < ac; i++)
  52. {
  53. if (av[i][0] == '-')
  54. {
  55. switch (av[i][1])
  56. {
  57. case 'O':
  58. if (av[i][2] == '\0')
  59. {
  60. if (i < ac - 1 && av[i+1][0] != '-')
  61. {
  62. i++;
  63. s = av[i];
  64. } else
  65. {
  66. OString tmp("'-O', please check");
  67. if (i <= ac - 1)
  68. {
  69. tmp += " your input '" + OString(av[i+1]) + "'";
  70. }
  71. throw IllegalArgument(tmp);
  72. }
  73. } else
  74. {
  75. s = av[i] + 2;
  76. }
  77. m_options["-O"] = OString(s);
  78. break;
  79. case 'X':
  80. if (av[i][2] == '\0')
  81. {
  82. if (i < ac - 1 && av[i+1][0] != '-')
  83. {
  84. i++;
  85. s = av[i];
  86. } else
  87. {
  88. OString tmp("'-X', please check");
  89. if (i <= ac - 1)
  90. {
  91. tmp += " your input '" + OString(av[i+1]) + "'";
  92. }
  93. throw IllegalArgument(tmp);
  94. }
  95. } else
  96. {
  97. s = av[i] + 2;
  98. }
  99. m_options["-X"] = OString(s);
  100. break;
  101. case 'R':
  102. if (av[i][2] == '\0')
  103. {
  104. if (i < ac - 1 && av[i+1][0] != '-')
  105. {
  106. i++;
  107. s = av[i];
  108. } else
  109. {
  110. OString tmp("'-R', please check");
  111. if (i <= ac - 1)
  112. {
  113. tmp += " your input '" + OString(av[i+1]) + "'";
  114. }
  115. throw IllegalArgument(tmp);
  116. }
  117. } else
  118. {
  119. s = av[i] + 2;
  120. }
  121. m_options["-R"] = OString(s);
  122. break;
  123. case 'B':
  124. if (av[i][2] == '\0')
  125. {
  126. if (i < ac - 1 && av[i+1][0] != '-')
  127. {
  128. i++;
  129. s = av[i];
  130. } else
  131. {
  132. OString tmp("'-B', please check");
  133. if (i <= ac - 1)
  134. {
  135. tmp += " your input '" + OString(av[i+1]) + "'";
  136. }
  137. throw IllegalArgument(tmp);
  138. }
  139. } else
  140. {
  141. s = av[i] + 2;
  142. }
  143. m_options["-B"] = OString(s);
  144. break;
  145. case 'b':
  146. if (av[i][2] == '\0')
  147. {
  148. if (i < ac - 1 && av[i+1][0] != '-')
  149. {
  150. i++;
  151. s = av[i];
  152. } else
  153. {
  154. OString tmp("'-b', please check");
  155. if (i <= ac - 1)
  156. {
  157. tmp += " your input '" + OString(av[i+1]) + "'";
  158. }
  159. throw IllegalArgument(tmp);
  160. }
  161. } else
  162. {
  163. s = av[i] + 2;
  164. }
  165. m_options["-b"] = OString(s);
  166. break;
  167. case 'T':
  168. if (av[i][2] == '\0')
  169. {
  170. if (i < ac - 1 && av[i+1][0] != '-')
  171. {
  172. i++;
  173. s = av[i];
  174. } else
  175. {
  176. OString tmp("'-T', please check");
  177. if (i <= ac - 1)
  178. {
  179. tmp += " your input '" + OString(av[i+1]) + "'";
  180. }
  181. throw IllegalArgument(tmp);
  182. }
  183. } else
  184. {
  185. s = av[i] + 2;
  186. }
  187. if (m_options.count("-T") > 0)
  188. {
  189. OString tmp(m_options["-T"]);
  190. tmp = tmp + ";" + s;
  191. m_options["-T"] = tmp;
  192. } else
  193. {
  194. m_options["-T"] = OString(s);
  195. }
  196. break;
  197. case 'F':
  198. if (av[i][2] == 'T')
  199. {
  200. if (av[i][3] == '\0')
  201. {
  202. if (i < ac - 1 && av[i+1][0] != '-')
  203. {
  204. i++;
  205. s = av[i];
  206. } else
  207. {
  208. OString tmp("'-FT', please check");
  209. if (i <= ac - 1)
  210. {
  211. tmp += " your input '" + OString(av[i+1]) + "'";
  212. }
  213. throw IllegalArgument(tmp);
  214. }
  215. } else
  216. {
  217. s = av[i] + 3;
  218. }
  219. if (m_options.count("-FT") > 0)
  220. {
  221. OString tmp(m_options["-FT"]);
  222. tmp = tmp + ";" + s;
  223. m_options["-FT"] = tmp;
  224. } else
  225. {
  226. m_options["-FT"] = OString(s);
  227. }
  228. } else
  229. {
  230. if (av[i][2] == '\0')
  231. {
  232. if (i < ac - 1 && av[i+1][0] != '-')
  233. {
  234. i++;
  235. s = av[i];
  236. } else
  237. {
  238. OString tmp("'-F', please check");
  239. if (i <= ac - 1)
  240. {
  241. tmp += " your input '" + OString(av[i+1]) + "'";
  242. }
  243. throw IllegalArgument(tmp);
  244. }
  245. } else
  246. {
  247. s = av[i] + 2;
  248. }
  249. m_options["-F"] = OString(s);
  250. }
  251. break;
  252. case 'L':
  253. if (av[i][2] != '\0')
  254. {
  255. OString tmp("'-L', please check");
  256. if (i <= ac - 1)
  257. {
  258. tmp += " your input '" + OString(av[i+1]) + "'";
  259. }
  260. throw IllegalArgument(tmp);
  261. }
  262. m_options["-L"] = OString();
  263. m_generateTypeList = sal_True;
  264. break;
  265. default:
  266. throw IllegalArgument("the option is unknown" + OString(av[i]));
  267. }
  268. } else
  269. {
  270. if (av[i][0] == '@')
  271. {
  272. FILE* cmdFile = fopen(av[i]+1, "r");
  273. if( cmdFile == NULL )
  274. {
  275. fprintf(stderr, "%s", prepareHelp().getStr());
  276. ret = sal_False;
  277. } else
  278. {
  279. int rargc=0;
  280. char* rargv[512];
  281. char buffer[512];
  282. while ( fscanf(cmdFile, "%s", buffer) != EOF )
  283. {
  284. rargv[rargc]= strdup(buffer);
  285. rargc++;
  286. }
  287. fclose(cmdFile);
  288. ret = initOptions(rargc, rargv, bCmdFile);
  289. for (long j=0; j < rargc; j++)
  290. {
  291. free(rargv[j]);
  292. }
  293. }
  294. } else
  295. {
  296. m_inputFiles.push_back(av[i]);
  297. }
  298. }
  299. }
  300. return ret;
  301. }
  302. OString RdbOptions::prepareHelp()
  303. {
  304. OString help("\nusing: ");
  305. help += m_program + " [-options] (-R<regname> | file_1 [... file_n])\n";
  306. help += "The rdbmaker supports 2 modes:\n";
  307. help += " 1. using the internal UNO type description manager -> use -R<regname>\n"
  308. " where regname specifies the type library used by the UNO type description manager\n"
  309. " after UNO is bootstrapped. This option disables the use of any other type libraries.\n"
  310. " The tpye library must be a valid product type library which means that all types are\n"
  311. " stored under the global base node UCR (Uno Core Reflection data).\n";
  312. help += " 2. using one or more type library files -> use file_1 ... file_n\n"
  313. " file_1 .. file_n specifies one or more valid type library files which are used to\n"
  314. " find the needed type information. The used type libraries have to support the same base\n"
  315. " node (-B option).\n";
  316. help += "Options:\n";
  317. help += " -O<filename> = filename specifies the name of the generated registry\n";
  318. help += " or text file.\n";
  319. help += " -L = specifies that only a text file is generated with the\n";
  320. help += " names of the specified types and their dependencies.\n";
  321. help += " Default is that a registry file will be created\n";
  322. // help += " -X<xmlfile> = xmlfile specifies the name of an xml description where\n";
  323. // help += " all types are specified which will be generated.\n";
  324. help += " -T<name> = name specifies a type or a list of types. The output for\n";
  325. help += " [t1;...] this type is generated.\n";
  326. help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
  327. help += " -FT<name> = name specifies a type or a list of types. For this types\n";
  328. help += " [t1;...] nothing will be generated.\n";
  329. help += " |F<file> = file specifies an text file. For the specified types in\n" ;
  330. help += " this file nothing will be generated.\n";
  331. help += " -B<name> = name specifies the base node. All types are searched under\n";
  332. help += " this node. Default is the root '/' of the registry files.\n";
  333. help += " This option takes effect using run mode 2 only.\n";
  334. help += " -b<name> = name specifies the base node of the output registry. All\n";
  335. help += " types will be generated under this node. Default is the\n";
  336. help += " root '/' of the registry file.\n";
  337. help += prepareVersion();
  338. return help;
  339. }
  340. OString RdbOptions::prepareVersion()
  341. {
  342. OString version("\nSun Microsystems (R) ");
  343. version += m_program + " Version 2.0\n\n";
  344. return version;
  345. }