File: setup.h

package info (click to toggle)
xstow 1.0.2-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,064 kB
  • ctags: 1,073
  • sloc: cpp: 7,264; sh: 1,216; makefile: 196; awk: 26
file content (210 lines) | stat: -rw-r--r-- 4,383 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * $Log: setup.h,v $
 * Revision 1.2  2005/07/04 21:59:42  martin
 * added logging to all files
 *
 */
#ifndef setup_h
#define setup_h

#include "setup_config.h"
#include "ref.h"

#ifdef CAN_USE_NIGNORE
class NIgnoreChain;
#endif

struct Setup
{
  struct Debug : public Section
  {
    struct WrapFreeze
    {
      struct Freeze
      {
	bool freeze;
	
	void operator()( bool f ) { freeze = f; }
	bool operator()() { return freeze; }
	
	Freeze() : freeze( false ) {}
      } freeze;
    };

    struct DIntValue : public IntValue, public WrapFreeze
    {
      DIntValue( const std::string &s, const std::string &k ) : IntValue( s, k ), WrapFreeze() {}

      ON_INI( void read_ini( Leo::Ini &ini ) { if( !freeze() ) IntValue::read_ini( ini ); } )
    } level;

    struct MValue : public Value<DModule>, public WrapFreeze
    {      
      MValue( const std::string &s, const std::string &k ) : Value<DModule>( s, k ), WrapFreeze() {}
      DModule string2data( const std::string &s ) { return string2module( s ); }

      ON_INI( void read_ini( Leo::Ini &ini ) { if( !freeze() ) Value<DModule>::read_ini( ini ); } )
    };

    MValue module;

    Debug( const std::string &section );

  } debug;

  struct TraversableLinks : public Section
  {
    VecDirChecker checker;

    BoolValue           keep_targets;
    VecStringValue      links;
    VecStringValue      add_if_targets;
    RegExVecStringValue add_if_targets_regex;

    TraversableLinks( const std::string &s );

  } traversable_links;

  struct KeepDirs : public Section
  {    
    VecStringValue dirs;

    KeepDirs( const std::string &s );

  } keep_dirs;

  struct Matches : public Section
  {
    VecStringValue      ignore;
    RegExVecStringValue ignore_regex;
    VecStringValue      copy; 
    RegExVecStringValue copy_regex;   
    VecStringValue      nignore;
    VecStringValue      ignore_file_in_dir;
    VecStringValue      copy_file_in_dir; 

    Matches( const std::string &s );

  } matches;

  struct StowDirs : public Section
  {
    VecDirChecker checker;

    VecStringValue      dirs;
    VecStringValue      auto_add_dirs;
    RegExVecStringValue auto_add_dirs_regex;

    StowDirs( const std::string &s );

  } stow_dirs;

  struct ProtectDirs : public Section
  {
    VecDirChecker checker;

    VecStringValue      dirs;
    VecStringValue      auto_add_dirs;
    RegExVecStringValue auto_add_dirs_regex;
    VecStringValue      targets;
    BoolValue           targets_add_traversable;

    ProtectDirs( const std::string &s );

  } protect_dirs;

  struct ConfigFiles : public Section
  {
    VecStringValue files;
    BoolValue      in_home;
    BoolValue      in_stow_dir;
    BoolValue      in_other_stow_dirs;    

    ConfigFiles( const std::string &s );

  } config_files;

  struct Links : public Section
  {
    BoolValue          absolute_paths;

    Links( const std::string &s );
  } links;

#ifdef CAN_USE_INI
  struct Exec : public Section
  {
    Value<std::string>  match;
    Value<std::string>  exec;     
    Value<std::string>  exec_unstow;

    Exec();
  };

  std::vector<Exec> exec;
#endif

#ifdef CAN_USE_NIGNORE
    struct IniNIgnore : public Section // for syntax check only
    {
	Value<std::string> dir;
	BoolValue          follow;

	IniNIgnore( const std::string &section );
    };
#endif

  BoolValue no_changes;
  BoolValue conflicts;
  Value<std::string> working_dir;
  Value<std::string> target_dir;
  IntValue           verbose_level;
  VecStringValue     packages;
  BoolValue          unstow;
  BoolValue          restow;
  BoolValue          simulate;
  BoolValue          force;
  BoolValue          use_curses;
  Value<std::string> current_package;

#ifdef CAN_USE_NIGNORE
  std::vector< Ref<NIgnoreChain> > nignores;
#endif

  void read_ini();

  Setup();

  void handle_keep_dirs();
  void handle_protect_dirs();

private:

  std::vector<Section*> sections;
  
  void add( Section* s );

  void handle_config_files();

#ifdef CAN_USE_NIGNORE
  void read_nignore( Leo::Ini &ini );
#endif

#ifdef CAN_USE_INI
  void read_exec( Leo::Ini &ini );

  void check_ini( Leo::Ini &ini );
#endif

public:
  
  friend std::ostream& operator<<( std::ostream& out, const Setup &setup );
  
};

extern Setup setup;

std::ostream& operator<<( std::ostream& out, const Setup &setup );
std::ostream& operator<<( std::ostream& out, const vec_string &v );

#endif