File: file_option.cpp

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 (83 lines) | stat: -rw-r--r-- 2,142 bytes parent folder | download | duplicates (3)
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
/*
 * $Log: file_option.cpp,v $
 * Revision 1.3  2005/07/04 21:59:42  martin
 * added logging to all files
 *
 */
#include "file_option.h"
#include "cppdir.h"

using namespace CppDir;

Arg::FileOptionRule::FileOptionRule( FILE type )
  : AnyStringRule(),
    type( type )
{
  continue_on_fail = false;

  error = "value is not a valid ";

  switch( type )
    {
    case FILE::DIR:     description = "DIR";  error += " directory";         break;
    case FILE::LINK:    description = "LINK"; error += " symlink";           break;
    case FILE::REGULAR: description = "FILE"; error += " regular file";      break;
    case FILE::ANY:     description = "FILE"; error += " file or directory"; break;
    case FILE::LINK_TO_DIR: description = "LINK"; error += " link to directory"; break;
    case FILE::LINK_TO_REGULAR: description = "LINK"; error += " link to a regular file"; break;
	case FILE::FIRST__:
	case FILE::LAST__:
		break;
    }
}

bool Arg::FileOptionRule::match( const std::string &name ) const
{
  File file( name );

  if( !file )
    return false;

  switch( type )
    {
    case FILE::LINK_TO_DIR: if( (file.get_type() == EFILE::DIR) && file.is_link() ) return true; break;
    case FILE::LINK_TO_REGULAR: if( file.get_type() == EFILE::REGULAR && file.is_link() ) return true; break;
    case FILE::DIR:     if( file.get_type() == EFILE::DIR ) return true; break;
    case FILE::LINK:    if( file.is_link() ) return true; break;
    case FILE::REGULAR: if( file.get_type() == EFILE::REGULAR ) return true; break;
    case FILE::ANY:     return true;
	case FILE::FIRST__:
	case FILE::LAST__:
		break;
    }

  return false;
}


Arg::FileOption::FileOption( FILE type )
  : StringOption()
{
  value_rule = new FileOptionRule( type );

  setMaxValues( 1 );
  setMinValues( 1 );
}

Arg::FileOption::FileOption( const std::string &name, FILE type )
  : StringOption( name )
{
  value_rule = new FileOptionRule( type );

  setMaxValues( 1 );
  setMinValues( 1 );
}

Arg::EmptyFileOption::EmptyFileOption( FILE type )
  : EmptyStringOption()
{
  value_rule = new FileOptionRule( type );

  setMaxValues( 1 );
  setMinValues( 1 );
}