#!/bin/awk -f # # Copyright © 2021, 2023 Nick Bowler # # Hackjob to try and find all the relevant wordlist items from the gperf # output, in order to produce (at runtime) a list of those commands, in # the same order as they are listed in the gperf input file. # # The output is a definition of the object-like macro CMD_SEQ, which # can be used to initialize an array with static storage duration. # Each element of the array represents offsets into the wordlist table, # in sequence. # # License WTFPL2: Do What The Fuck You Want To Public License, version 2. # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. END { print "/*" if (FILENAME) { print " * Automatically generated by gen-cmdlist.awk from " FILENAME } else { print " * Automatically generated by gen-cmdlist.awk" } print " * Do not edit." print " */" } BEGIN { maxline = 0 } $1 == "char" && get_stringpool_id($2) { sub(/[^"]*"/, "", $2) sub(/".*/, "", $2) pool[ID] = $2 } $1 ~ /^#line/ { line = $2 if (line > maxline) { maxline = line } } get_stringpool_id($0) && $0 ~ "cmd_" pool[ID] { sub(/^stringpool_str/, "", ID) indices[line] = ID } END { seq = "" for (i = 1; i <= maxline; i++) { if (i in indices) { if (seq) { seq = seq ", " indices[i] } else { seq = indices[i] } } } print "#define CMD_SEQ { " seq " }" } function get_stringpool_id(s) { if (sub(/.*stringpool_str/, "stringpool_str", s) && sub(/[,[].*/, "", s)) { ID = s; return 1 } return 0 }