version 1.1, 2023/11/17 21:51:37 |
version 1.2, 2024/02/05 17:07:23 |
|
|
# Process the input line LINE and save it for later output. |
# Process the input line LINE and save it for later output. |
|
|
function process_input_line(line, \ |
function process_input_line(line, \ |
f, field, end, i, n, r, startdef, \ |
f, field, end, n, outline, r, \ |
linkline, ruleline, zoneline) |
linkline, ruleline, zoneline) |
{ |
{ |
# Remove comments, normalize spaces, and append a space to each line. |
# Remove comments, normalize spaces, and append a space to each line. |
|
|
} |
} |
|
|
# Abbreviate "max", "min", "only" and month names. |
# Abbreviate "max", "min", "only" and month names. |
gsub(/ max /, " ma ", line) |
# Although "max" and "min" can both be abbreviated to just "m", |
gsub(/ min /, " mi ", line) |
# the longer forms "ma" and "mi" are needed with zic 2023d and earlier. |
|
gsub(/ max /, dataform == "vanguard" ? " m " : " ma ", line) |
|
gsub(/ min /, dataform == "vanguard" ? " m " : " mi ", line) |
gsub(/ only /, " o ", line) |
gsub(/ only /, " o ", line) |
gsub(/ Jan /, " Ja ", line) |
gsub(/ Jan /, " Ja ", line) |
gsub(/ Feb /, " F ", line) |
gsub(/ Feb /, " F ", line) |
|
|
rule_used[r] = 1 |
rule_used[r] = 1 |
} |
} |
|
|
# If this zone supersedes an earlier one, delete the earlier one |
|
# from the saved output lines. |
|
startdef = "" |
|
if (zoneline) |
if (zoneline) |
zonename = startdef = field[2] |
zonename = startdef = field[2] |
else if (linkline) |
else if (linkline) |
zonename = startdef = field[3] |
zonename = startdef = field[3] |
else if (ruleline) |
else if (ruleline) |
zonename = "" |
zonename = "" |
if (startdef) { |
|
i = zonedef[startdef] |
|
if (i) { |
|
do |
|
output_line[i - 1] = "" |
|
while (output_line[i++] ~ /^[-+0-9]/); |
|
} |
|
} |
|
zonedef[zonename] = nout + 1 |
|
|
|
# Save the line for later output. |
# Save the information for later output. |
output_line[nout++] = make_line(n, field) |
outline = make_line(n, field) |
|
if (ruleline) |
|
rule_output_line[nrule_out++] = outline |
|
else if (linkline) { |
|
# In vanguard format with Gawk, links are output sorted by destination. |
|
if (dataform == "vanguard" && PROCINFO["version"]) |
|
linkdef[zonename] = field[2] |
|
else |
|
link_output_line[nlink_out++] = outline |
|
}else |
|
zonedef[zonename] = (zoneline ? "" : zonedef[zonename] "\n") outline |
} |
} |
|
|
function omit_unused_rules( \ |
function omit_unused_rules( \ |
i, field) |
i, field) |
{ |
{ |
for (i = 0; i < nout; i++) { |
for (i = 0; i < nrule_out; i++) { |
split(output_line[i], field) |
split(rule_output_line[i], field) |
if (field[1] == "R" && !rule_used[field[2]]) { |
if (!rule_used[field[2]]) |
output_line[i] = "" |
rule_output_line[i] = "" |
} |
|
} |
} |
} |
} |
|
|
function abbreviate_rule_names( \ |
function abbreviate_rule_names( \ |
abbr, f, field, i, n, r) |
abbr, f, field, i, n, newdef, newline, r, \ |
|
zoneline, zonelines, zonename) |
{ |
{ |
for (i = 0; i < nout; i++) { |
for (i = 0; i < nrule_out; i++) { |
n = split(output_line[i], field) |
n = split(rule_output_line[i], field) |
if (n) { |
if (n) { |
f = field[1] == "Z" ? 4 : field[1] == "L" ? 0 : 2 |
r = field[2] |
r = field[f] |
|
if (r ~ /^[^-+0-9]/) { |
if (r ~ /^[^-+0-9]/) { |
abbr = rule[r] |
abbr = rule[r] |
if (!abbr) { |
if (!abbr) { |
rule[r] = abbr = gen_rule_name(r) |
rule[r] = abbr = gen_rule_name(r) |
} |
} |
field[f] = abbr |
field[2] = abbr |
output_line[i] = make_line(n, field) |
rule_output_line[i] = make_line(n, field) |
} |
} |
} |
} |
} |
} |
|
for (zonename in zonedef) { |
|
zonelines = split(zonedef[zonename], zoneline, /\n/) |
|
newdef = "" |
|
for (i = 1; i <= zonelines; i++) { |
|
newline = zoneline[i] |
|
n = split(newline, field) |
|
f = i == 1 ? 4 : 2 |
|
r = rule[field[f]] |
|
if (r) { |
|
field[f] = r |
|
newline = make_line(n, field) |
|
} |
|
newdef = (newdef ? newdef "\n" : "") newline |
|
} |
|
zonedef[zonename] = newdef |
|
} |
} |
} |
|
|
function output_saved_lines( \ |
function output_saved_lines( \ |
i) |
i, zonename) |
{ |
{ |
for (i = 0; i < nout; i++) |
for (i = 0; i < nrule_out; i++) |
if (output_line[i]) |
if (rule_output_line[i]) |
print output_line[i] |
print rule_output_line[i] |
|
|
|
# When using gawk, output zones sorted by name. |
|
# This makes the output a bit more compressible. |
|
PROCINFO["sorted_in"] = "@ind_str_asc" |
|
for (zonename in zonedef) |
|
print zonedef[zonename] |
|
|
|
if (nlink_out) |
|
for (i = 0; i < nlink_out; i++) |
|
print link_output_line[i] |
|
else { |
|
# When using gawk, output links sorted by destination. |
|
# This also helps compressibility a bit. |
|
PROCINFO["sorted_in"] = "@val_type_asc" |
|
for (zonename in linkdef) |
|
printf "L %s %s\n", linkdef[zonename], zonename |
|
} |
} |
} |
|
|
BEGIN { |
BEGIN { |