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  ""
    }
}
