# This file is part of mailfrom filter. # Copyright (C) 2006 Sergey Poznyakoff # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA BEGIN { if (SELECT) { gsub(/,$/,"", SELECT) n = split(SELECT, a, ",") for (i = 1; i <= n; i++) select[a[i]] = 1 } } function error(s) { print "extract.awk: " ARGV[1] ":" NR ": " s > "/dev/stderr" } function output(file, s) { if (!notified) { print "Creating file `" file "'" notified = 1 } print s > file } function sprintf_multitab(s, a, n, i, r) { sub(/@(head)?item/, "", s) n = split(s, a, /@tab/) r = "" for (i = 1; i <= n; i++) r = r "" sprintf("%-*s", multitable[i-1], a[i]) return r } function flush_mtline( s) { if (match(mtline, "@headitem")) { s = sprintf_multitab(mtline) output(file, "# " s) gsub(/./, "-", s) output(file, "# " s) } else output(file, "# " sprintf_multitab(mtline)) } state == 0 && /^@deftypefn[ \t]+{Sample[ \t]+Function}/ { name = $5 if (SELECT && !select[name]) next file = name ".mf" notified = 0 state = 1 if (match($0, ".*@$")) { save0 = substr($0, 1, length($0)-1) while (getline > 0 && match($0, ".*@$")) save0 = save0 substr($0, 1, length($0)-1) $0 = save0 $0 } } state == 0 { next } /@end[ \t]+deftypefn/ { close(file) state = 0 next } state == 1 && /^[ \t]*@smallexample/ { state = 2; next } state == 2 && /^@end[ \t]+smallexample/ { state = 1; next } state == 2 && /#include/ { s = $2 gsub(/[<>\"]/,"",s) gsub(/\.mf$/,"",s) if (SELECT && !select[s]) print "Require " s } state == 1 && /^[ \t]*@table/ { state = 3; table = $2; next } state == 3 && /^@end[ \t]+table/ { state = 1; next } state == 1 && /^[ \t]*@multitable/ { state = 6; delete multitable mtcount = 0 for (i = 3; i <= NF; i++) multitable[mtcount++] = $i * 78 next } state == 6 && /^@end[ \t]+multitable/ { flush_mtline(); state = 1; next } # Parse texinfo commands: /^[ \t]*@c[ \t]/ { next } /^[ \t]*@comment[ \t]/ { next } /^[ \t]*@ignore/ { oldstate = state; state = 4; next } state == 4 && /^[ \t]*@end ignore/ { state = oldstate; next } /^[ \t]*@example-output/ { oldstate = state; state = 5; next } state == 5 && /^}$/ { state = oldstate; next } state == 3 && /^@itemx*/ { if (table == "@samp") output(file, "# `" $2 "'") if (table == "@var") output(file, "# " toupper($2) ) else output(file, "# " $2) next } # Remove texinfo markers { gsub(/@{/, "{") gsub(/@}/, "}") gsub(/@result{}/, "=>") $0 = gensub(/@samp{([^}]*)}/, "`\\1'", "g") while (match($0, "@var{[^}]*}")) { $0 = substr($0, 1, RSTART-1) \ toupper(substr($0, RSTART+5, RLENGTH-6)) \ substr($0, RSTART+RLENGTH) } $0 = gensub(/@[a-z]+{([^}]*)}/, "\\1", "g") } /^@deftypefn[ \t]+{Sample[ \t]+Function}/ { s = "" for (i = 4; i <= NF; i++) s = s " " $i $0 = s } state == 6 && /@item/ { flush_mtline(); mtline = $0; next } state == 6 && /@headitem/ { flush_mtline(); mtline = $0; next } state == 6 { mtline = mtline " " $0; next } # Remove any leftover commands /^[ \t]*@.*/ { next } state == 3 || state == 5 { output(file, "# " $0) next } { if (state == 1) output(file, "# " $0) else output(file, $0) }