File: toc.text

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 (106 lines) | stat: -rw-r--r-- 2,462 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
102
103
104
105
106
# -*- tcl -*-
# Engine to convert a doctoc document into plain text.
#
# Copyright (c) 2003-2019 Andreas Kupries <andreas_kupries@sourceforge.net>
# Freely redistributable.
#
######################################################################

dt_source _toc_common.tcl
dt_source _text.tcl

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

rename toc_postprocess {}
rename text_postprocess toc_postprocess

proc fmt_plain_text {text} {return {}}

################################################################
## Backend for TEXT markup

global seclist ; set seclist {}
global max     ; set max 0

proc InitSections {} {
    global seclist ; set seclist {} ;# list of items in this division
    global max     ; set max 0      ;# length of longest file path in the division
    return
}

proc ProcessSections {} {
    global seclist max
    
    if {![llength $seclist]} {
	# Division is empty, nothing to do
	return
    }

    incr max 2  ; set rmargin [RMargin  $max]
    incr max -1 ; set blank   [Blank    $max]
    incr max -1 ; set dots   "[Repeat . $max] "

    # Example wrt max handling, blank, and dots:
    #
    # string = "longest",  max = 7 +2 => max = lmargin = 9
    # blank  = "________" (max = 8, using _ as visible placeholder)
    # dots   = "......._" (max = 7 (dots))
    
    foreach {file desc} $seclist {
	Text [InFlow $desc $rmargin [ReHead $dots "$file "] $blank]
	CloseParagraph [Verbatim]
    }

    set seclist {}
    return
}

proc fmt_toc_begin {label title} {
    set title "$label -- $title"
    
    TextInitialize
    lappend   hdr "Table of contents [Provenance]"
    lappend   hdr ""
    SectTitle hdr $title
    Text [Compose hdr]    
    CloseParagraph [Verbatim]
    return
}

proc fmt_toc_end {} {
    ProcessSections
    return
}

proc fmt_division_start {title symfile} {
    # We may have sections before the new division
    ProcessSections

    InitSections
    SubsectTitle hdr $title
    Text [Compose hdr]
    CloseParagraph [Verbatim]

    ContextPush ;# Ref (a)
    ContextNew Division { MarginIn }
    return
}

proc fmt_division_end   {}      {
    ProcessSections
    ContextPop ;# Ref (a)
    return
}

proc fmt_item {file label desc} {
    global  seclist max
    lappend seclist $file $desc
    MaxLen max $file
    return
}

proc fmt_comment {text} {return}

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