2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-12 18:11:58 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-17 02:36:38 +00:00
|
|
|
|
2002-02-21 10:35:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2006-03-15 08:13:03 +00:00
|
|
|
|
2002-11-20 15:20:29 +00:00
|
|
|
#include "cppuoptions.hxx"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2011-02-24 10:51:05 +01:00
|
|
|
#ifdef SAL_UNX
|
|
|
|
#define SEPARATOR '/'
|
|
|
|
#else
|
|
|
|
#define SEPARATOR '\\'
|
|
|
|
#endif
|
|
|
|
|
2014-04-04 11:20:05 +02:00
|
|
|
bool CppuOptions::initOptions(int ac, char* av[], bool bCmdFile)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2014-02-15 14:52:41 +01:00
|
|
|
bool ret = true;
|
2017-02-25 10:10:02 +01:00
|
|
|
int i=0;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
if (!bCmdFile)
|
|
|
|
{
|
2014-04-04 11:20:05 +02:00
|
|
|
bCmdFile = true;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2011-02-24 10:51:05 +01:00
|
|
|
OString name(av[0]);
|
|
|
|
sal_Int32 index = name.lastIndexOf(SEPARATOR);
|
2017-07-07 08:42:54 +02:00
|
|
|
m_program = name.copy(index > 0 ? index+1 : 0);
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
if (ac < 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s", prepareHelp().getStr());
|
2014-02-15 14:52:41 +01:00
|
|
|
ret = false;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = 1;
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 10:11:36 +01:00
|
|
|
char *s=nullptr;
|
2004-04-21 12:53:08 +00:00
|
|
|
for( ; i < ac; i++)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
if (av[i][0] == '-')
|
|
|
|
{
|
|
|
|
switch (av[i][1])
|
|
|
|
{
|
|
|
|
case 'O':
|
|
|
|
if (av[i][2] == '\0')
|
|
|
|
{
|
|
|
|
if (i < ac - 1 && av[i+1][0] != '-')
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
s = av[i];
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-O', please check"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i+1] + "'";
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
s = av[i] + 2;
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-O"_ostr] = OString(s);
|
2000-09-18 14:29:57 +00:00
|
|
|
break;
|
2013-09-12 15:28:11 +02:00
|
|
|
case 'n':
|
|
|
|
if (av[i][2] != 'D' || av[i][3] != '\0')
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
OString tmp = OString::Concat("'-nD', please check your input '") + av[i] + "'";
|
2013-09-12 15:28:11 +02:00
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-nD"_ostr] = OString();
|
2013-09-12 15:28:11 +02:00
|
|
|
break;
|
2000-09-18 14:29:57 +00:00
|
|
|
case 'T':
|
|
|
|
if (av[i][2] == '\0')
|
|
|
|
{
|
|
|
|
if (i < ac - 1 && av[i+1][0] != '-')
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
s = av[i];
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-T', please check"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i+1] + "'";
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
s = av[i] + 2;
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
if (m_options.count("-T"_ostr) > 0)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp = m_options["-T"_ostr] + ";" + s;
|
|
|
|
m_options["-T"_ostr] = tmp;
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-T"_ostr] = OString(s);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
if (av[i][2] != '\0')
|
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-L', please check"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i] + "'";
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
if (isValid("-C"_ostr) || isValid("-CS"_ostr))
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
throw IllegalArgument("'-L' could not be combined with '-C' or '-CS' option"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-L"_ostr] = OString();
|
2000-09-18 14:29:57 +00:00
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
if (av[i][2] == 'S')
|
|
|
|
{
|
|
|
|
if (av[i][3] != '\0')
|
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-CS', please check"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i] + "'";
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
if (isValid("-L"_ostr) || isValid("-C"_ostr))
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
throw IllegalArgument("'-CS' could not be combined with '-L' or '-C' option"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-CS"_ostr] = OString();
|
2000-09-18 14:29:57 +00:00
|
|
|
break;
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else if (av[i][2] != '\0')
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-C', please check"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i] + "'";
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
if (isValid("-L"_ostr) || isValid("-CS"_ostr))
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
throw IllegalArgument("'-C' could not be combined with '-L' or '-CS' option"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-C"_ostr] = OString();
|
2000-09-18 14:29:57 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
if (av[i][2] == 'c')
|
|
|
|
{
|
|
|
|
if (av[i][3] != '\0')
|
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-Gc', please check"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i] + "'";
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-Gc"_ostr] = OString();
|
2000-09-18 14:29:57 +00:00
|
|
|
break;
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else if (av[i][2] != '\0')
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-G', please check"_ostr);
|
2000-09-18 14:29:57 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i] + "'";
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
|
|
|
|
2023-11-20 07:30:46 +01:00
|
|
|
m_options["-G"_ostr] = OString();
|
2000-09-18 14:29:57 +00:00
|
|
|
break;
|
2002-07-31 11:46:45 +00:00
|
|
|
case 'X': // support for eXtra type rdbs
|
|
|
|
{
|
|
|
|
if (av[i][2] == '\0')
|
|
|
|
{
|
|
|
|
if (i < ac - 1 && av[i+1][0] != '-')
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
s = av[i];
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2002-07-31 11:46:45 +00:00
|
|
|
{
|
2023-11-20 07:30:46 +01:00
|
|
|
OString tmp("'-X', please check"_ostr);
|
2002-07-31 11:46:45 +00:00
|
|
|
if (i <= ac - 1)
|
|
|
|
{
|
2021-04-20 21:07:42 +02:00
|
|
|
tmp += OString::Concat(" your input '") + av[i+1] + "'";
|
2002-07-31 11:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw IllegalArgument(tmp);
|
|
|
|
}
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2002-07-31 11:46:45 +00:00
|
|
|
{
|
|
|
|
s = av[i] + 2;
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:55:37 +02:00
|
|
|
m_extra_input_files.emplace_back(s );
|
2002-07-31 11:46:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-09-18 14:29:57 +00:00
|
|
|
default:
|
2021-04-20 21:07:42 +02:00
|
|
|
throw IllegalArgument(OString::Concat("the option is unknown") + av[i]);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (av[i][0] == '@')
|
|
|
|
{
|
|
|
|
FILE* cmdFile = fopen(av[i]+1, "r");
|
2015-11-10 10:11:36 +01:00
|
|
|
if( cmdFile == nullptr )
|
2012-10-26 12:41:27 +01:00
|
|
|
{
|
2000-09-18 14:29:57 +00:00
|
|
|
fprintf(stderr, "%s", prepareHelp().getStr());
|
2014-02-15 14:52:41 +01:00
|
|
|
ret = false;
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
int rargc=0;
|
|
|
|
char* rargv[512];
|
|
|
|
char buffer[512];
|
|
|
|
|
2014-10-06 17:29:29 +01:00
|
|
|
while (fscanf(cmdFile, "%511s", buffer) != EOF && rargc < 512)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
rargv[rargc]= strdup(buffer);
|
|
|
|
rargc++;
|
|
|
|
}
|
|
|
|
fclose(cmdFile);
|
|
|
|
|
|
|
|
ret = initOptions(rargc, rargv, bCmdFile);
|
|
|
|
|
2017-08-14 08:28:13 +02:00
|
|
|
for (int j=0; j < rargc; j++)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2006-06-20 01:23:45 +00:00
|
|
|
free(rargv[j]);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-26 12:41:27 +01:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2017-09-08 16:55:37 +02:00
|
|
|
m_inputFiles.emplace_back(av[i]);
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
OString CppuOptions::prepareHelp()
|
|
|
|
{
|
2019-09-30 15:09:07 +02:00
|
|
|
OString help = "\nusing: " +
|
|
|
|
m_program + " [-options] file_1 ... file_n\nOptions:\n"
|
|
|
|
" -O<path> = path describes the root directory for the generated output.\n"
|
|
|
|
" The output directory tree is generated under this directory.\n"
|
|
|
|
" -T<name> = name specifies a type or a list of types. The output for this\n"
|
|
|
|
" [t1;...] type is generated. If no '-T' option is specified,\n"
|
|
|
|
" then output for all types is generated.\n"
|
|
|
|
" Example: 'com.sun.star.uno.XInterface' is a valid type.\n"
|
|
|
|
" -L = UNO type functions are generated lightweight, that means only\n"
|
|
|
|
" the name and typeclass are given and everything else is retrieved\n"
|
|
|
|
" from the type library dynamically. The default is that UNO type\n"
|
|
|
|
" functions provides enough type information for bootstrapping C++.\n"
|
|
|
|
" '-L' should be the default for external components.\n"
|
|
|
|
" -C = UNO type functions are generated comprehensive that means all\n"
|
|
|
|
" necessary information is available for bridging the type in UNO.\n"
|
|
|
|
" -nD = no dependent types are generated.\n"
|
|
|
|
" -G = generate only target files which does not exists.\n"
|
|
|
|
" -Gc = generate only target files which content will be changed.\n"
|
2019-10-28 10:35:49 +02:00
|
|
|
" -X<file> = extra types which will not be taken into account for generation.\n\n" +
|
|
|
|
prepareVersion();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
return help;
|
|
|
|
}
|
|
|
|
|
2017-10-19 11:09:13 +02:00
|
|
|
OString CppuOptions::prepareVersion() const
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2016-07-30 02:01:21 +05:30
|
|
|
OString version = m_program + " Version 2.0\n\n";
|
2000-09-18 14:29:57 +00:00
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-14 08:30:07 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|