File: idx.nroff

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (101 lines) | stat: -rw-r--r-- 2,586 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- tcl -*-
# Engine to convert a docidx document into nroff.
#
# Copyright (c) 2003 Andreas Kupries <andreas_kupries@sourceforge.net>
# Freely redistributable.
#
######################################################################

dt_source _idx_common.tcl
dt_source _nroff.tcl

######################################################################
# Conversion specification.
#
# One-pass processing.

proc idx_postprocess {nroff} {
    # Postprocessing after generation ...
    # Strip empty lines out of the generated nroff source
    # and trim leading blanks, except in code samples.

    set lines [list]
    foreach line [split $nroff "\n"] {
	set line [string trim $line]
	if {0 == [string length $line]} {
	    continue
	}
	lappend lines $line
    } 
    return [nroff_postprocess [join $lines \n]]
}

#proc fmt_plain_text {text} {if {$text != {}} {return \n} else {return {}}}
proc fmt_plain_text {text} {return {}}

################################################################
## Backend for NROFF markup

global map ; array set map {}
global key ; set key {}
global max ; set max 0

global prec ok haskey
set    prec   ""
set    ok     0
set    haskey 0

proc fmt_index_begin     {label title}      {
    global prec ok
    set ok 1
    set     hdr [nr_comment {}]\n
    if {$prec != {}} {
	set hdr [nr_comment $prec]\n
    }
    append  hdr [nr_comment [c_provenance]]\n
    append  hdr [nr_title "\"[string trimleft $label :]\" n"]\n
    append  hdr [nr_read man.macros]\n
    append  hdr [nr_bolds]\n
    append  hdr [nr_section INDEX]\n
    append  hdr $title[nr_in]\n
    return $hdr
}

proc fmt_index_end {} {
    global map
    foreach key [lsort [array names map]] {
	append r $key [nr_in] \n
	foreach ref  $map($key) {
	foreach {file label} $ref break
	    append r [Man $file $label]
	}
	append r [nr_out] \n
    }
    
    append r [nr_out]
    return $r
}

proc fmt_key     {text}       { global key     ; set key $text ; return }
proc fmt_manpage {file label} { global map key ; lappend map($key) [list $file $label] ; return }
proc fmt_url     {url  label} { global map key ; lappend map($key) [list $url  $label] ; return }

proc Key {text} {
    global haskey
    set res ""
    if {$haskey} {append res [nr_out]\n}
    append res $text[nr_in]\n
    set haskey 1
    return $res
}

proc Man {file label} {return [nr_blt [nr_bld]$file[nr_rst]]\n$label\n}

proc fmt_comment {text} {
    global prec ok
    if {$ok} { return [nr_comment $text] }
    append prec $text \n
    return
}

################################################################