1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "options.hxx"
22 #include "osl/diagnose.h"
32 Options::Options (char const * program
)
40 bool Options::checkArgument(std::vector
< std::string
> & rArgs
, char const * arg
, size_t len
)
42 bool result
= ((arg
!= 0) && (len
> 0));
43 OSL_PRECOND(result
, "registry::tools::Options::checkArgument(): invalid arguments");
46 OSL_TRACE("registry::tools:Options::checkArgument(): \"%s\"", arg
);
54 result
= Options::checkCommandFile(rArgs
, &(arg
[1]));
62 std::string
option (&(arg
[0]), 2);
63 rArgs
.push_back(option
);
67 std::string
param(&(arg
[2]), len
- 2);
68 rArgs
.push_back(param
);
73 rArgs
.push_back(std::string(arg
, len
));
81 bool Options::checkCommandFile(std::vector
< std::string
> & rArgs
, char const * filename
)
83 FILE * fp
= fopen(filename
, "r");
86 fprintf(stderr
, "ERROR: Can't open command file \"%s\"\n", filename
);
95 while ((c
= fgetc(fp
)) != EOF
)
110 if (!checkArgument(rArgs
, buffer
.c_str(), buffer
.size()))
121 // quoted white-space fall through
122 buffer
.push_back(sal::static_int_cast
<char>(c
));
126 return fclose(fp
) == 0;
129 bool Options::initOptions (std::vector
< std::string
> & rArgs
)
131 return initOptions_Impl (rArgs
);
134 bool Options::badOption (char const * reason
, char const * option
) const
136 (void) fprintf(stderr
, "%s: %s option '%s'\n", m_program
.c_str(), reason
, option
);
140 bool Options::printUsage() const
147 } // namespace registry
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */