#! /n/gnu/bin/gawk -f # Last edited on 2000-02-02 02:48:13 by stolfi # Reads a stream of element-factored words, extracts crust prefix and # full core+mantle separated by "-". /^ *$/{next;} /./{ # Delete dummy (empty) factors: gsub(/{[_]*}/, "", $0); gsub(/[_][_]*/, "", $0); # Map "ch" and "sh" to "C" and "S" to simplify processing: gsub(/ch/, "C", $0); gsub(/sh/, "S", $0); # Delete trailing non-mantle, non-core elements: gsub(/[}][^CSktpfech]*$/, "}", $0); gsub(/^[^CSktpfech]*$/, "", $0); if (length($0) == 0) { next; } # Must have at least one core-mantle element: if ($0 !~ /[{].*[CSktpfech].*[}]$/) { error(("bad format = «" $0 "»")); } # Insert "-" between prefix and core-mantle: $0 = gensub(/^([^CSktpfech]*)[{]/, "\\1-{", "g", $0); # Delete braces gsub(/[{}]/, "", $0); # Restore "cs" and 'sh": gsub(/C/, "ch", $0); gsub(/S/, "sh", $0); print $0; } function error(msg) { printf "line %d: %s\n", NR, msg >> "/dev/stderr"; abort = 1; exit 1; }