#! /usr/bin/awk -f BEGIN { xlat[".HP"] = ".Pp" xlat[".PP"] = ".Pp" xlat[".SH"] = ".Sh" xlat[".SS"] = ".Sh" xlat[".TH"] = ".Dt" debug = 0 comment = ".\\\"" section = section? section : "1" volume = volume? volume : "GnuCOBOL 2.2.0" } /It was generated by help2man/ { print ".Dd $Mdocdate$" next } /^[.]br/ { next } /^[.](PP|SH|SS|TH)/ { if( list ) { print list list = "" if (debug) { print comment, "end list" } } if( $1 == ".TH" ) { name = tolower($2) if (debug) { printf "%s name: '%s'\n", comment, name } # .Dt title number volume printf ".Dt %s \\&%s \"%s\"\n", toupper(name), section, volume print ".Os Linux" next } gsub($1, xlat[$1]) gsub(/\n +/, "\n") if( $1 == ".Sh" ) { section = $2 if (debug) { printf "%s section: '%s'\n", comment, section } if( section == "NAME" ) { print getline gsub(/\n$/, "") split($0, L, / [\\-]+ /) printf ".Nm %s\n.Nd %s\n", name, L[2] next } } } /^[.]B / { if (debug) { print comment, "printing bold in", section } if( section == "SYNOPSIS" ) { print ".Nm" getline gsub(/^\[[\\]fI[\\]-/, ".Op ") gsub(/^[\\]fI[\\]-/, " Ar ") gsub(/^[\\]fR[\\]-/, "") } else { gsub(/^[.]B /, ".Ic \"") gsub(/$/, "\"") } } /^[.]IP/ { print ".Pp\n.Bd -literal -offset indent" list = ".Ed" next } /^[.](HP|TP)/ && section == "OPTIONS" { if( list == ".Ed" ) { print list list = "" } if( !list ) { print ".Bl -tag" list = ".El" } if (debug) { print comment, "printing option line", NR } getline if (debug) { print comment, "processing:", $0 } gsub(/[\\]fB[\\]-/, "Fl ") gsub(/[\\]fI/, " Ns Ar ") while( match($0, /=?\\fR *<[[:alnum:]_#]+>/) ) { arg = substr($0, RSTART + 1, RLENGTH - 2) start = 1 + index(arg, "<") if (debug) { printf comment " arg is '%s', start is %d\n", arg, start } if( "=" == substr($0, RSTART, 1) ) { sub(/<[[:alnum:]_]+>/, " Ns Ar " substr(arg, start)) } else { sub(/<[[:alnum:]_]+>/, " Ar " substr(arg, start)) } sub(/,/, " ,") } gsub(/[[]/, " Op ") gsub(/[]]/, "") gsub(/[\\](fR|[\/])/, "") if( match($0, /^[\\]-./) ) { gsub(/^[\\]-/, "Fl Ar ") } sub(/Os$/, "O\\\\&s") print ".It", $0 next } /^[.]Sh/ && $2 ~ /AUTHORS?/ { print ".Bd -literal -offset indent" list = ".Ed" } { # If the line contains font manipulation that doesn't start a line, # break it up. while( match($0, /[\\]fB[\\]-[[:alnum:]]+/) > 1 ) { arg = substr($0, RSTART + 5, RLENGTH - 5) if (debug) { print comment, "input: ", $0 printf comment " implicit flag argument '%s' from %d, len %d\n", \ arg, RSTART, RLENGTH } sub(/[\\]fB[\\]-[[:alnum:]]+/, "\n.Fl " arg "\n") sub(/[\\]fR/, "") } while( match($0, /<[[:alnum:]_]+>/) ) { if (debug) { print comment, "input:", $0 print comment, "replacing with .Ar" } arg = substr($0, RSTART + 1, RLENGTH - 2) nl = RSTART == 1? "" : "\n" sub(/<[[:alnum:]_]+>/, sprintf("%s.Ar %s\n", nl, arg)) } gsub(/[\\]fB[\\]-/, "Fl ") gsub(/[\\]fI/, " Ar ") gsub(/[\\]fR/, "") gsub(/[\\][\/]/, "") gsub(/^ +/, "") gsub(/\n+ */, "\n") gsub(/\n+/, "\n") gsub(/\n+$/, "") print } END { print list }