E-MailRelay
gbatchfile.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 
32 namespace G
33 {
34  class BatchFile ;
35 }
36 
37 /// \class G::BatchFile
38 /// A class for reading and writing windows-style startup batch files
39 /// containing a single command-line, optionally using "start".
40 ///
42 {
43 public:
44  G_EXCEPTION( Error , "batch file error" ) ;
45  struct NoThrow /// Overload discriminator for G::BatchFile.
46  {} ;
47 
48  explicit BatchFile( const G::Path & ) ;
49  ///< Constructor that reads from a file.
50 
51  BatchFile( const G::Path & , NoThrow ) ;
52  ///< Constructor that reads from a file that might be missing
53  ///< or empty.
54 
55  explicit BatchFile( std::istream & , const std::string & stream_name = std::string() ) ;
56  ///< Constructor that reads from a stream.
57 
58  std::string line() const ;
59  ///< Returns the main command-line from within the batchfile, with normalised
60  ///< spaces, without any "start" prefix, and including quotes.
61 
62  std::string name() const ;
63  ///< Returns the "start" window name, if any.
64 
65  const G::StringArray & args() const ;
66  ///< Returns the startup command-line broken up into de-quoted pieces.
67  ///< The first item in the list will be the executable.
68 
69  static void write( const G::Path & , const StringArray & args ,
70  const std::string & start_window_name = std::string() ) ;
71  ///< Writes a startup batch file, including a "start" prefix.
72  ///< If the "start" window name is not supplied then it is
73  ///< derived from the command-line.
74 
75 private:
76  BatchFile( const BatchFile & ) ;
77  void operator=( const BatchFile & ) ;
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 
87 private:
88  std::string m_line ;
89  std::string m_name ;
90  G::StringArray m_args ;
91 } ;
92 
93 #endif
std::string line() const
Returns the main command-line from within the batchfile, with normalised spaces, without any "start" ...
Definition: gbatchfile.cpp:138
static void write(const G::Path &, const StringArray &args, const std::string &start_window_name=std::string())
Writes a startup batch file, including a "start" prefix.
Definition: gbatchfile.cpp:159
BatchFile(const G::Path &)
Constructor that reads from a file.
Definition: gbatchfile.cpp:29
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
std::string name() const
Returns the "start" window name, if any.
Definition: gbatchfile.cpp:143
const G::StringArray & args() const
Returns the startup command-line broken up into de-quoted pieces.
Definition: gbatchfile.cpp:148
Low-level classes.
Definition: garg.h:29
A class for reading and writing windows-style startup batch files containing a single command-line...
Definition: gbatchfile.h:41
Overload discriminator for G::BatchFile.
Definition: gbatchfile.h:45
A Path object represents a file system path.
Definition: gpath.h:72