#!/usr/bin/gawk -f

BEGIN {
    printf("/*\n");
    printf("\tGenerated by make-actions from %s\n", infile);
    printf("*/\n\n");

    if ( type == "defines" ) {
        printf("#ifndef GNUBVERSION_ACTION_MAP_H\n");
        printf("#define GNUBVERSION_ACTION_MAP_H\n");

        printf("#include <glib.h>\n");

        printf("typedef struct gnubversion_action_map_t \n");
        printf("{\n");
        printf("    guint32 mask;\n");
        printf("    char *str;\n");
        printf("} gnubversion_action_map_t;\n");

        printf("extern gnubversion_action_map_t gnubversion_action_map[];\n");

        printf("#define GVN_ACTION_NONE 0\n\n");
    } else {
        printf("#include \"gnubversion-private.h\"\n");
        printf("#include \"gnubversion-action-map.h\"\n");
        printf("\n");

        printf("gnubversion_action_map_t gnubversion_action_map[] = {\n");
    }

    bitno = 0;
}

/^[ \t]*#/ { next; }

{
    def=$1;
    text=$0;
    gsub("^[A-Z]*[ \t]*", "", text);

    if (def == "")
        next;

    if ( type == "defines" ) {
        printf("#define GVN_ACTION_%s\t( 1 << %d )\n", def, bitno);
    } else {
        printf("\t{ GVN_ACTION_%s, \"%s\" },\n", def, text);
    }

    bitno ++;
}

END {
    if (type == "defines" ) {
        printf("\n#endif /* ! GNUBVERSION_ACTIONS_H */\n");
    } else {
        printf("\t{ 0, NULL }\n");
        printf("};\n");
    }
}
