E-MailRelay
gbatchfile.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gbatchfile.h
19///
20
21#ifndef G_BATCH_FILE_H
22#define G_BATCH_FILE_H
23
24#include "gdef.h"
25#include "gpath.h"
26#include "gstrings.h"
27#include "gexception.h"
28#include <iostream>
29#include <string>
30#include <vector>
31#include <new>
32
33namespace G
34{
35 class BatchFile ;
36}
37
38//| \class G::BatchFile
39/// A class for reading and writing windows-style startup batch files
40/// containing a single command-line, optionally using "start".
41///
43{
44public:
45 G_EXCEPTION( Error , "batch file error" ) ;
46
47 explicit BatchFile( const Path & ) ;
48 ///< Constructor that reads from a file.
49
50 BatchFile( const Path & , std::nothrow_t ) ;
51 ///< Constructor that reads from a file that might be missing
52 ///< or empty.
53
54 explicit BatchFile( std::istream & , const std::string & stream_name = std::string() ) ;
55 ///< Constructor that reads from a stream.
56
57 std::string line() const ;
58 ///< Returns the main command-line from within the batchfile, with normalised
59 ///< spaces, without any "start" prefix, and including quotes.
60
61 std::string name() const ;
62 ///< Returns the "start" window name, if any.
63
64 const StringArray & args() const ;
65 ///< Returns the startup command-line broken up into de-quoted pieces.
66 ///< The first item in the list will be the executable.
67
68 std::size_t lineArgsPos() const ;
69 ///< Returns the position in line() where the arguments start.
70
71 static void write( const Path & , const StringArray & args ,
72 const std::string & start_window_name = std::string() ) ;
73 ///< Writes a startup batch file, including a "start" prefix.
74 ///< If the "start" window name is not supplied then it is
75 ///< derived from the command-line.
76
77private:
78 static std::string quote( const std::string & ) ;
79 static std::string percents( const std::string & ) ;
80 static void dequote( std::string & ) ;
81 std::string readFrom( std::istream & , const std::string & , bool ) ;
82 static StringArray split( const std::string & ) ;
83 static bool ignorable( const std::string & line ) ;
84 static bool relevant( const std::string & line ) ;
85 static std::string join( const std::string & file_name , unsigned int line_number ) ;
86
87private:
88 std::string m_line ;
89 std::string m_name ;
90 StringArray m_args ;
91} ;
92
93#endif
A class for reading and writing windows-style startup batch files containing a single command-line,...
Definition: gbatchfile.h:43
static void write(const Path &, const StringArray &args, const std::string &start_window_name=std::string())
Writes a startup batch file, including a "start" prefix.
Definition: gbatchfile.cpp:190
const StringArray & args() const
Returns the startup command-line broken up into de-quoted pieces.
Definition: gbatchfile.cpp:150
std::size_t lineArgsPos() const
Returns the position in line() where the arguments start.
Definition: gbatchfile.cpp:155
std::string name() const
Returns the "start" window name, if any.
Definition: gbatchfile.cpp:145
BatchFile(const Path &)
Constructor that reads from a file.
Definition: gbatchfile.cpp:31
std::string line() const
Returns the main command-line from within the batchfile, with normalised spaces, without any "start" ...
Definition: gbatchfile.cpp:140
A Path object represents a file system path.
Definition: gpath.h:72
Low-level classes.
Definition: galign.h:28
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31