File: main.cc

package info (click to toggle)
icmake 13.05.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,132 kB
  • sloc: cpp: 11,595; fortran: 883; makefile: 853; sh: 546; pascal: 342
file content (96 lines) | stat: -rw-r--r-- 2,260 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
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
#define XERR
#include "main.ih"

// When called from icmake: the bim-file must be the first argument following
// icmake's -e option. The initial .bim file and any subsequent arguments 
// are passed to icm-exec
//
// When called directly as '/usr/lib/icmake/icm-exec /tmp/input.bim:
//     ICM-EXEC ARGS: /usr/lib/icmake/icm-exec /tmp/input.bim 
// arguments:
//     nargs: 1, args: /tmp/input.bim

// When called as 'icmake -e /tmp/input.bim:
//     ICM-EXEC ARGS: /usr/lib/icmake/icm-exec /tmp/input.bim 
// program name:
//     icm-exec
// arguments:
//     nargs: 1, args: /tmp/input.bim

// When called as 'icmake -e /tmp/input.bim -t:
//     ICM-EXEC ARGS: /usr/lib/icmake/icm-exec /tmp/input.bim -t
// program name:
//     icm-exec
// arguments:
//     nargs: 1, args: /tmp/input.bim
// and /tmp/input.bim is removed

namespace
{
    option options[] =
    {
        { "help",               no_argument, 0, 'h' },
        { "no-version-check",   no_argument, 0, 'n' },
        { "version",            no_argument, 0, 'v' },
        { 0 }
    };
}

int main(int argc, char **argv)
try
{
    int opt;
    bool versionCheck = true;

    string program{ basename(*argv) };

    opterr = 0;
    while (true)
    {
        opt = getopt_long(argc, argv, "+hnv", options,  0);

        if (opt == -1)
            break;

        switch (opt)
        {
            case 'h':
                usage(program);
            return 0;

            case 'v':
                cout << program << " V" VERSION "\n";
            return 0;

            case 'n':
                versionCheck = false;
            break;

            case '?':
            throw Exception{} << '`' << argv[optind] << 
                        "': not a valid icm_exec option";
        };
    }

    if (optind == argc)
    {
        usage(program);
        return 1;
    }

    cerr << hex;

    Stack stack(optind, argc, argv);

    // read the .bim-file header
    BimHeader bimHdr{ argv[optind], VERSION, versionCheck };

    CPU cpu{ bimHdr, stack };   // create the icmake cpu processing bim-file
                                // instructions. This bootstraps the cpu

    return cpu.run();           // run the program in the .bim file
}
catch (...)
{
    return handleException();
}