advgetopt 2.0.47
Parse complex command line arguments and configuration files in C++.
advgetopt_access.cpp
Go to the documentation of this file.
1// Copyright (c) 2006-2024 Made to Order Software Corp. All Rights Reserved
2//
3// https://snapwebsites.org/project/advgetopt
4// contact@m2osw.com
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this program; if not, write to the Free Software Foundation, Inc.,
18// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
27// self
28//
29#include "advgetopt/advgetopt.h"
30
31
32// advgetopt
33//
34#include "advgetopt/exception.h"
35
36
37// last include
38//
39#include <snapdev/poison.h>
40
41
42
43namespace advgetopt
44{
45
46
69void getopt::parse_program_name(char * argv[])
70{
71 if(argv == nullptr)
72 {
73 throw getopt_logic_error("argv pointer cannot be nullptr");
74 }
75 if(argv[0] != nullptr)
76 {
77 f_program_fullname = argv[0];
78 }
79
80 std::string::size_type p(f_program_fullname.find_last_of('/'));
81 if(p == std::string::npos)
82 {
83 // MS-Windows path uses \ instead of /
84 //
85 p = f_program_fullname.find_last_of('\\');
86 }
87 if(p != std::string::npos)
88 {
89 // remove the path
90 //
91 f_program_name = f_program_fullname.substr(p + 1);
92 }
93 else
94 {
96 }
97}
98
99
124{
125 return f_program_fullname;
126}
127
128
141std::string getopt::get_program_name() const
142{
143 return f_program_name;
144}
145
146
191std::string getopt::get_project_name() const
192{
194 {
195 return std::string();
196 }
198}
199
200
201
202
214std::string getopt::get_group_name() const
215{
217 {
218 return std::string();
219 }
221}
222
223
235{
238 {
240 }
241
244 {
246 }
247
248 return std::string();
249}
250
251
252
253} // namespace advgetopt
254// vim: ts=4 sw=4 et
Definitions of the advanced getopt class.
std::string get_group_name() const
Retrieve the group name if one is defined.
std::string get_group_or_project_name() const
Retrieve the group or project name.
options_environment f_options_environment
Definition advgetopt.h:224
std::string f_program_name
Definition advgetopt.h:222
std::string get_program_fullname() const
Get the full name of the program.
std::string f_program_fullname
Definition advgetopt.h:221
void parse_program_name(char *argv[])
Transform the argv[0] parameter in the program name.
std::string get_program_name() const
Get the basename of the program.
std::string get_project_name() const
Retrieve the project name if one is defined.
Definitions of the advanced getopt exceptions.
The advgetopt environment to parse command line options.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.