MiKTeX 26.5-next
A scalable TeX distribution
Loading...
Searching...
No Matches
CommandLineBuilder.h
1/* miktex/Core/CommandLineBuilder.h: -*- C++ -*-
2
3 Copyright (C) 1996-2021 Christian Schenk
4
5 This file is part of the MiKTeX Core Library.
6
7 The MiKTeX Core Library is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2, or
10 (at your option) any later version.
11
12 The MiKTeX Core Library is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with the MiKTeX Core Library; if not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22#pragma once
23
24#if !defined(CE888532B67E451F851FB7072C37704A)
25#define CE888532B67E451F851FB7072C37704A
26
27#include <miktex/Core/config.h>
28
29#include <cstddef>
30
31#include <memory>
32#include <ostream>
33#include <string>
34#include <vector>
35
36#include <miktex/Util/PathName>
37
38#include "Debug.h"
39
40MIKTEX_CORE_BEGIN_NAMESPACE;
41
43class Argv
44{
45public:
46 MIKTEXCOREEXPORT MIKTEXTHISCALL Argv();
47
48public:
49 Argv(const Argv& other) = delete;
50
51public:
52 Argv& operator=(const Argv& other) = delete;
53
54public:
55 MIKTEXCOREEXPORT MIKTEXTHISCALL Argv(Argv&& other);
56
57public:
58 Argv& operator=(Argv&& other) = delete;
59
60public:
61 virtual MIKTEXCOREEXPORT MIKTEXTHISCALL ~Argv() noexcept;
62
63public:
64 explicit MIKTEXCOREEXPORT MIKTEXTHISCALL Argv(const std::string& commandLine);
65
66public:
67 explicit MIKTEXCOREEXPORT MIKTEXTHISCALL Argv(const std::vector<std::string>& arguments);
68
69public:
70 MIKTEXCORETHISAPI(void) Append(const std::string& arguments);
71
72public:
73 MIKTEXCORETHISAPI(const char* const*) GetArgv() const;
74
75public:
76 MIKTEXCORETHISAPI(int) GetArgc() const;
77
78public:
79 MIKTEXCORETHISAPI(const char*) operator[](std::size_t idx) const;
80
81public:
82 MIKTEXCORETHISAPI(std::vector<std::string>) ToStringVector() const;
83
84public:
85 MIKTEXCORETHISAPI(char**) CloneFreeable() const;
86
87private:
88 class impl;
89 std::unique_ptr<impl> pimpl;
90};
91
94{
95 None,
96 GNU,
97 Xt,
98 DOS
99};
100
103{
104 None,
105 Whitespace,
106 Bat
107};
108
110class CommandLineBuilder
111{
112public:
113 MIKTEXCOREEXPORT MIKTEXTHISCALL CommandLineBuilder();
114
115public:
116 MIKTEXCOREEXPORT MIKTEXTHISCALL CommandLineBuilder(const CommandLineBuilder& other);
117
118public:
119 MIKTEXCORETHISAPI(CommandLineBuilder&) operator=(const CommandLineBuilder& other);
120
121public:
122 CommandLineBuilder(CommandLineBuilder&& other) = delete;
123
124public:
125 CommandLineBuilder& operator=(CommandLineBuilder&& other) = delete;
126
127public:
128 virtual MIKTEXCOREEXPORT MIKTEXTHISCALL ~CommandLineBuilder() noexcept;
129
130public:
131 explicit MIKTEXCOREEXPORT MIKTEXTHISCALL CommandLineBuilder(const std::string& argument);
132
133public:
134 MIKTEXCOREEXPORT MIKTEXTHISCALL CommandLineBuilder(const std::string& argument1, const std::string& argument2);
135
136public:
137 MIKTEXCOREEXPORT MIKTEXTHISCALL CommandLineBuilder(const std::string& argument1, const std::string& argument2, const std::string& argument3);
138
139public:
140 explicit MIKTEXCOREEXPORT MIKTEXTHISCALL CommandLineBuilder(const std::vector<std::string>& arguments);
141
142public:
143 MIKTEXCOREEXPORT MIKTEXTHISCALL CommandLineBuilder(int argc, const char* const* argv);
144
145public:
146 MIKTEXCORETHISAPI(void) SetOptionConvention(OptionConvention optionConvention);
147
148public:
149 MIKTEXCORETHISAPI(void) SetQuotingConvention(QuotingConvention quotingConvention);
150
151public:
152 MIKTEXCORETHISAPI(void) Clear();
153
154public:
155 MIKTEXCORETHISAPI(void) AppendArgument(const std::string& argument);
156
157public:
158 void AppendArgument(const MiKTeX::Util::PathName& argument)
159 {
160 AppendArgument(argument.ToString());
161 }
162
163public:
164 void AppendArgument(const char* argument)
165 {
166 MIKTEX_ASSERT_STRING(argument);
167 AppendArgument(std::string(argument));
168 }
169
170public:
171 MIKTEXCORETHISAPI(void) AppendUnquoted(const std::string& text);
172
173public:
174 MIKTEXCORETHISAPI(void) AppendArguments(int argc, const char* const* argv);
175
176public:
177 MIKTEXCORETHISAPI(void) AppendArguments(const std::vector<std::string>& argv);
178
179public:
180 MIKTEXCORETHISAPI(void) AppendArguments(const Argv& argv);
181
182public:
183 MIKTEXCORETHISAPI(void) AppendOption(const std::string& name, const std::string& value);
184
185public:
186 void AppendOption(const std::string& name)
187 {
188 AppendOption(name, std::string());
189 }
190
191public:
192 void AppendOption(const std::string& name, const MiKTeX::Util::PathName& value)
193 {
194 AppendOption(name, value.ToString());
195 }
196
197public:
198 void AppendOption(const std::string& name, const char* value)
199 {
200 MIKTEX_ASSERT_STRING(value);
201 AppendOption(name, std::string(value));
202 }
203
204public:
205 MIKTEXCORETHISAPI(void) AppendRedirection(const MiKTeX::Util::PathName& path, std::string direction);
206
207public:
208 void AppendStdoutRedirection(const MiKTeX::Util::PathName& path, bool append)
209 {
210 return AppendRedirection(path, append ? ">>" : ">");
211 }
212
213public:
214 void AppendStdoutRedirection(const MiKTeX::Util::PathName& path)
215 {
216 return AppendStdoutRedirection(path, false);
217 }
218
219public:
220 void AppendStdinRedirection(const MiKTeX::Util::PathName& path)
221 {
222 return AppendRedirection(path, "<");
223 }
224
225public:
226 MIKTEXCORETHISAPI(std::string) ToString() const;
227
228private:
229 class impl;
230 std::unique_ptr<impl> pimpl;
231};
232
233inline std::ostream& operator<<(std::ostream& os, const CommandLineBuilder& cmd)
234{
235 return os << cmd.ToString();
236}
237
238MIKTEX_CORE_END_NAMESPACE;
239
240#endif
An argv wrapper class.
Definition CommandLineBuilder.h:44
An instance of this class builds a command-line.
Definition CommandLineBuilder.h:111
std::basic_string< CharType > ToString() const
Definition CharBuffer.h:242
Instances of this class can be used to store path names.
Definition PathName.h:64
QuotingConvention
Quoting convention.
Definition CommandLineBuilder.h:103
OptionConvention
Option parsing convention.
Definition CommandLineBuilder.h:94