summaryrefslogtreecommitdiffstats
path: root/test/AS/fixture/myas_args.py
blob: c7ca31534e83091a5cb1a3c7b5d80a7328ff9fb3 (plain)
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
import sys

if sys.platform == 'win32':
    args = sys.argv[1:]
    inf = None
    optstring = ''
    while args:
        a = args[0]
        if a == '-o':
            out = args[1]
            args = args[2:]
            continue
        args = args[1:]
        if not a[0] in '/-':
            if not inf:
                inf = a
            continue
        if a[:2] == '/c':
            continue
        if a[:3] == '/Fo':
            out = a[3:]
            continue
        optstring = optstring + ' ' + a
    infile = open(inf, 'rb')
    outfile = open(out, 'wb')
    outfile.write(bytearray(optstring + "\n",'utf-8'))
    for l in infile.readlines():
        if l[:3] != b'#as':
            outfile.write(l)
    sys.exit(0)
else:
    import getopt
    opts, args = getopt.getopt(sys.argv[1:], 'co:x')
    optstring = ''

    for opt, arg in opts:
        if opt == '-o': out = arg
        else: optstring = optstring + ' ' + opt

    infile = open(args[0], 'rb')
    outfile = open(out, 'wb')
    outfile.write(bytearray(optstring + "\n",'utf-8'))

    for l in infile.readlines():
        if l[:3] != b'#as':
            outfile.write(l)

    sys.exit(0)