File: setbase.cc

package info (click to toggle)
filtermail 1.06.00-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,688 kB
  • sloc: cpp: 2,487; fortran: 249; makefile: 106; ansic: 51; sh: 36
file content (43 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download | duplicates (2)
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
//#define XERR
#include "options.ih"

void Options::setBase()
{
    if (not d_inspect)
        s_base = d_arg[0];
    else
    {
        char const *base = getenv("HOME");
        if (base == 0)
            throw Exception{} << "no `HOME' environment variable available";
        
        s_base = base;
    }

    string canon = canonical(s_base, s_ec);
    if (s_ec)
        throw Exception{} << "`--base " << s_base << 
                                            "' must be an absolute path";
    s_base = canon;
}

// static
void Options::setBase(string &path)
{
    if (path.front() == '~')            // replace ~ by s_base
        path.replace(0, 1, s_base);

    else if (path.front() != '/')       // or prefix config dir for plain
        path.insert(0, s_configDir);    // filenames 

    path = absolute(path, s_ec);
    if (not exists(path, s_ec))
        ofstream{path};

    path = canonical(path, s_ec);

    if (s_ec or path.front() != '/')
        throw Exception{} << '`' << path << "' must be an absolute path";
}