| 1 | # -*- tcl -*- |
|---|
| 2 | # |
|---|
| 3 | # $Id: idx.nroff,v 1.6 2005/09/28 04:51:19 andreas_kupries Exp $ |
|---|
| 4 | # |
|---|
| 5 | # Engine to convert a docidx document into nroff. |
|---|
| 6 | # |
|---|
| 7 | # Copyright (c) 2003 Andreas Kupries <andreas_kupries@sourceforge.net> |
|---|
| 8 | # Freely redistributable. |
|---|
| 9 | # |
|---|
| 10 | ###################################################################### |
|---|
| 11 | |
|---|
| 12 | dt_source _idx_common.tcl |
|---|
| 13 | dt_source _nroff.tcl |
|---|
| 14 | |
|---|
| 15 | ###################################################################### |
|---|
| 16 | # Conversion specification. |
|---|
| 17 | # |
|---|
| 18 | # One-pass processing. |
|---|
| 19 | |
|---|
| 20 | proc idx_postprocess {nroff} { |
|---|
| 21 | # Postprocessing after generation ... |
|---|
| 22 | # Strip empty lines out of the generated nroff source |
|---|
| 23 | # and trim leading blanks, except in code samples. |
|---|
| 24 | |
|---|
| 25 | set lines [list] |
|---|
| 26 | foreach line [split $nroff "\n"] { |
|---|
| 27 | set line [string trim $line] |
|---|
| 28 | if {0 == [string length $line]} { |
|---|
| 29 | continue |
|---|
| 30 | } |
|---|
| 31 | lappend lines $line |
|---|
| 32 | } |
|---|
| 33 | return [nroff_postprocess [join $lines \n]] |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | #proc fmt_plain_text {text} {if {$text != {}} {return \n} else {return {}}} |
|---|
| 37 | proc fmt_plain_text {text} {return {}} |
|---|
| 38 | |
|---|
| 39 | ################################################################ |
|---|
| 40 | ## Backend for NROFF markup |
|---|
| 41 | |
|---|
| 42 | global prec ok haskey |
|---|
| 43 | set prec "" |
|---|
| 44 | set ok 0 |
|---|
| 45 | set haskey 0 |
|---|
| 46 | |
|---|
| 47 | proc fmt_index_begin {label title} { |
|---|
| 48 | global prec ok |
|---|
| 49 | set ok 1 |
|---|
| 50 | set hdr [nr_comment {}]\n |
|---|
| 51 | if {$prec != {}} { |
|---|
| 52 | set hdr [nr_comment $prec]\n |
|---|
| 53 | } |
|---|
| 54 | append hdr [nr_comment [c_provenance]]\n |
|---|
| 55 | append hdr [nr_include man.macros]\n |
|---|
| 56 | append hdr [nr_title "\"[string trimleft $label :]\" n"]\n |
|---|
| 57 | append hdr [nr_bolds]\n |
|---|
| 58 | append hdr [nr_section INDEX]\n |
|---|
| 59 | append hdr $title[nr_in]\n |
|---|
| 60 | return $hdr |
|---|
| 61 | } |
|---|
| 62 | proc fmt_index_end {} {return [nr_out]} |
|---|
| 63 | proc fmt_key {text} { |
|---|
| 64 | global haskey |
|---|
| 65 | set res "" |
|---|
| 66 | if {$haskey} {append res [nr_out]\n} |
|---|
| 67 | append res $text[nr_in]\n |
|---|
| 68 | set haskey 1 |
|---|
| 69 | return $res |
|---|
| 70 | } |
|---|
| 71 | proc fmt_manpage {file label} {return [nr_blt [nr_bld]$file[nr_rst]]\n$label\n} |
|---|
| 72 | proc fmt_url {url label} {return [nr_blt [nr_bld]$url[nr_rst]]\n$label\n} |
|---|
| 73 | |
|---|
| 74 | proc fmt_comment {text} { |
|---|
| 75 | global prec ok |
|---|
| 76 | if {$ok} {return [nr_comment $text]} |
|---|
| 77 | append prec $text \n |
|---|
| 78 | return {} |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | ################################################################ |
|---|