123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- BEGIN{
- out="/dev/null"
- out_count=0
- err=0
- sort=0
- array[""]=""
- }
- NR==1 && out == "/dev/null" {
- print "out=output.file must be given on the command line"
-
-
- }
- $1 == "PNG_DFN_START_SORT"{
- sort=0+$2
- next
- }
- $1 ~ /^PNG_DFN_END_SORT/{
-
-
- for (entry in array) {
- while (array[entry] != "") {
- key = entry
- value = array[key]
- array[key] = ""
- for (alt in array) {
- if (array[alt] != "" && alt < key) {
- array[key] = value
- value = array[alt]
- key = alt
- array[alt] = ""
- }
- }
- print value >out
- }
- }
- sort=0
- next
- }
- /^[^"]*PNG_DFN *".*"[^"]*$/{
-
-
-
-
-
-
-
-
-
- orig=$0
- line=$0
- lineno=FNR
- if (lineno == "") lineno=NR
- if (sub(/^[^"]*PNG_DFN *"/,"",line) != 1) {
- print "line", lineno ": processing failed:"
- print orig
- err=1
- next
- } else {
- ++out_count
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- while (1) {
-
- if (line ~ /@"/) {
- if (line ~ /@".*"@/) {
-
-
- if (!sub(/@" *"@/, "", line)) {
-
-
-
- if (!sub(/@" */, "", line) || !sub(/ *"@/, "", line)) {
- print "line", lineno, ": internal error:", orig
- exit 1
- }
- }
- }
-
- else while (1) {
- if (getline nextline) {
-
-
- if (nextline !~ /^#/) {
- line = line " " nextline
- break
- }
- } else {
-
- print "line", lineno ": unbalanced @\" ... \"@ pair"
- err=1
- next
- }
- }
-
- continue
- }
-
-
- if (sub(/"[^"]*$/, "", line))
- break
- # Read another line
- while (1) {
- if (getline nextline) {
- if (nextline !~ /^#/) {
- line = line " " nextline
-
- break
- }
- } else {
- print "line", lineno ": unterminated PNG_DFN string"
- err=1
- next
- }
- }
- }
-
-
- gsub(/@'/,"\"", line)
-
-
- sub(/ *$/, "", line)
- # Remove trailing CR
- sub(/
$/, "", line)
- if (sort) {
- if (split(line, parts) < sort) {
- print "line", lineno ": missing sort field:", line
- err=1
- } else
- array[parts[sort]] = line
- }
- else
- print line >out
- next
- }
- /PNG_DFN/{
- print "line", NR, "incorrectly formatted PNG_DFN line:"
- print $0
- err = 1
- }
- END{
- if (out_count > 0 || err > 0)
- exit err
- print "no definition lines found"
- exit 1
- }
|