File: options.cc

package info (click to toggle)
yodl 4.04.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,720 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 164
file content (79 lines) | stat: -rw-r--r-- 1,976 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
#include "main.ih"

void options(Process &process, Line &line, int argc, char **argv)
{
    string progName = fs::path{argv[0]}.filename();

    bool all = false;
    try
    {
        while (true)
        {
            switch(int c =  getopt(argc, argv, "aAnNs:S:T:t:V"))
            {
                case 'A':
                    line.ignore();
                [[fallthrough]];

                case 'a':
                    process.all();
                    all = true;
                continue;
    
                case 's':
                    process.indent(stoul(optarg), ' ');
                continue;
    
                case 't':
                    process.indent(stoul(optarg), '\t');
                continue;
    
                case 'S':
                    process.vindent(stoul(optarg), ' ');
                continue;
    
                case 'T':
                    process.vindent(stoul(optarg), '\t');
                continue;
    
                case 'N':
                    process.noVerbEndl();
                continue;
    
                case 'n':
                    process.numberLines();
                continue;
    
                case 'V':
                    process.noVerb();
                continue;
    
                case -1:
                throw true;             // ends option recognition
    
                default:
                    throw string{ "option `"} + static_cast<char>(c) +
                                "' not supported";
            }
        }
    }
    catch (bool)             // catches the -1
    {}
                // remaining arguments (argc - optind) must be 2 if -a was not
                // specified, because then a marker is required, and 1 if -a
                // was not specified.  the last option remains argv[arc - 1]
    if (argc - optind != 2 - all)
        usage(progName);

    if (not all)
        process.setTarget(argv[optind]);

    line.open(argv[argc - 1]);
}