File: help2c.awk

package info (click to toggle)
gliv 1.9.7-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 5,780 kB
  • ctags: 4,039
  • sloc: ansic: 30,070; sh: 5,207; makefile: 740; yacc: 291; awk: 185; sed: 16
file content (69 lines) | stat: -rw-r--r-- 1,499 bytes parent folder | download | duplicates (4)
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
BEGIN {
    print "/* Generated by help2c.awk */"
    print "#include \"gliv.h\""
    print "#include \"help_text.h\""
    print "#include \"messages.h\""
    print ""
    print "/* Forward declaration. */"
    print "static gchar **get_sized_array(void);"
    print ""
    print "gchar **get_help_lines(void)"
    print "{"
    print "    gchar **array, **ptr;"
    print ""
    print "    ptr = array = get_sized_array();"
    print ""

    help_lines = 0
}

$0 == "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" {
    if (started) {
        # The end.
        print  "    *--ptr = NULL;"
        print  ""
        print  "    return array;"
        print  "}"
        print  ""
        print  "static gchar **get_sized_array(void)"
        print  "{"
        printf "    return g_new(gchar *, %d);\n", help_lines
        print  "}"
        exit
    }

    # The beginning.
    started = 1
    getline
}

/.*: .*/ { # A keyboard accelerator line.
    if (started) {
        printf "    *ptr++ = _(\"%s\");\n", $0
        print  "    *ptr++ = \"\\n\";"
        print  ""
        help_lines += 2
    }
}

$0 == "" {
    if (started) {
        # End of keyboard accelerators.
        misc = 1
        RS = "\n\n"
        print "    *ptr++ = \"\\n\";"
        print ""
        help_lines++
        getline
    }
}

{
    if (misc) {
        gsub(/(\n|  )/, " ")
        printf "    *ptr++ = _(\"%s\");\n", $0
        print  "    *ptr++ = \"\\n\\n\";"
        help_lines += 2
        print  ""
    }
}