_common.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /* */
00003 /*  _common.tcl*/
00004 /* */
00005 /*  (c) 2001 Andreas Kupries <andreas_kupries@sourceforge.net>*/
00006 /*  (c) 2002 Andreas Kupries <andreas_kupries@sourceforge.net>*/
00007 
00008 /* */
00009 /*  The code here contains general definitions for API functions and*/
00010 /*  state information. They are used by several formatters to simplify*/
00011 /*  their own code.*/
00012 
00013 global    state
00014 array  state =  {}
00015 
00016 ret  fmt_initialize () {
00017     global    state
00018     unset     state
00019 
00020     set state(pass)   unknown ; # Not relevant before a pass
00021     set state(begun)  unknown ; # is active
00022     set state(mdesc)  {}      ; # Text, module desciption
00023     #set state(tdesc) {}      ; # Text, title of manpage
00024     set state(copyright) {}   ; # Text, copyright assignment (list)
00025     return
00026 }
00027 
00028 ret  fmt_shutdown      ()             {return}
00029 ret  fmt_numpasses     ()             {return 2}
00030 ret  fmt_postprocess   (type text)         {return $text}
00031 ret  fmt_plain_text    (type text)         {return $text}
00032 ret  fmt_listvariables ()             {return {}}
00033 ret  fmt_varset        (type varname , type text) {return}
00034 
00035 ret  fmt_setup (type n) {
00036     # Called to setup a pass through the input.
00037 
00038     global state
00039     set    state(pass)  $n  ; # We are in pass 'n' through the text.
00040     set    state(begun) 0   ; # No manpage_begin yet
00041 
00042     if {$n == 1} {c_xref_init}
00043 
00044     SetPassProcs $n
00045     return
00046 }
00047 
00048 /* */
00049 /*  Functions made available to the formatter to access the common*/
00050 /*  state managed here.*/
00051 
00052 ret  c_inpass () {global state ; return $state(pass)}
00053 
00054 ret  c_begin () {global state ; set     state(begun) 1 ; return}
00055 ret  c_begun () {global state ; return $state(begun)}
00056 
00057 ret  c_get_module ()     {global state ; return $state(mdesc)}
00058 ret  c_set_module (type text) {global state ; set     state(mdesc) $text ; return}
00059 
00060 ret  c_set_title (type text) {global state ; set state(tdesc) $text ; return}
00061 ret  c_get_title () {
00062     global state
00063     if {![info exists state(tdesc)]} {
00064     return $state(mdesc)
00065     }
00066     return $state(tdesc)
00067 }
00068 
00069 ret  c_copyrightsymbol () {return "(c)"}
00070 ret  c_set_copyright (type text) {global state ; lappend state(copyright) $text ; return}
00071 ret  c_get_copyright ()     {
00072     global state
00073 
00074     set cc $state(copyright)
00075     if {$cc == {}} {set cc [dt_copyright]}
00076     if {$cc == {}} {return {}}
00077 
00078     return "Copyright [c_copyrightsymbol] [join $cc "\nCopyright [c_copyrightsymbol] "]"
00079 }
00080 
00081 ret  c_provenance () {
00082     return "Generated from file '[dt_file]' by tcllib/doctools with format '[dt_format]'"
00083 }
00084 
00085 /* */
00086 /*  Manage pass-dependent procedure definitions.*/
00087 
00088 global PassProcs
00089 
00090 /*  pass $passNo procName procArgs { body  } --*/
00091 /*  Specifies procedure definition for pass $n.*/
00092 /* */
00093 ret  c_pass (type pass , type proc , type arguments , type body) {
00094     global  PassProcs
00095     lappend PassProcs($pass) $proc $arguments $body
00096 }
00097 ret  SetPassProcs (type pass) {
00098     global PassProcs
00099     foreach {proc args body} $PassProcs($pass) {
00100     proc $proc $args $body
00101     }
00102 }
00103 
00104 
00105 /* */
00106 /*  Manage a set of buffers to hold information between passes.*/
00107 /*  Each buffer holds a list of lines.*/
00108 
00109 global Buffers
00110 
00111 /*  holdBuffers buffer ? buffer ...? --*/
00112 /*  Declare a list of hold buffers,*/
00113 /*  to collect data in one pass and output it later.*/
00114 /* */
00115 ret  c_holdBuffers (type args) {
00116     global Buffers
00117     foreach arg $args {
00118     set Buffers($arg) [list]
00119     }
00120 }
00121 
00122 ret  c_holdRemove (type args) {
00123     global Buffers
00124     foreach arg $args {
00125     catch {unset Buffers($arg)}
00126     }
00127     return
00128 }
00129 
00130 /*  hold buffer text --*/
00131 /*  Append text to named buffer*/
00132 /* */
00133 ret  c_hold (type buffer , type entry) {
00134     global  Buffers
00135     lappend Buffers($buffer) $entry
00136 
00137     #puts "$buffer -- $entry"
00138     return
00139 }
00140 
00141 ret  c_holding (type buffer) {
00142     global  Buffers
00143     set l 0
00144     catch {set l [llength $Buffers($buffer)]}
00145     return $l
00146 }
00147 
00148 /*  held buffer --*/
00149 /*  Returns current contents of named buffer and empty the buffer.*/
00150 /* */
00151 ret  c_held (type buffer) {
00152     global Buffers
00153     set content [join $Buffers($buffer) "\n"]
00154     set Buffers($buffer) [list]
00155     return $content
00156 }
00157 
00158 /* */
00159 /*  Nested counter*/
00160 
00161 global counters cnt
00162     counters =  [list]
00163     cnt =  0
00164 
00165 ret  c_cnext () {global cnt ; incr cnt}
00166 ret  c_cinit () {
00167     global counters cnt
00168     set counters [linsert $counters 0 $cnt]
00169     set cnt      0
00170     return
00171 }
00172 ret  c_creset () {
00173     global counters cnt
00174     set cnt      [lindex $counters 0]
00175     set counters [lrange $counters 1 end]
00176     return
00177 }
00178 
00179 
00180 /* */
00181 /*  Utilities.*/
00182 /* */
00183 
00184 ret  NOP (type args) { }        ;/*  do nothing*/
00185 ret  NYI (optional message ={)} {
00186     return -code error [append message " Not Yet Implemented"]
00187 }
00188 
00189 ######################################################################
00190 # Cross-reference tracking (for a single file).
00191 #
00192 global SectionNames ;# array mapping 'section name' to 'reference id'
00193 global SectionList      ;# List of sections, their ids, and levels, in
00194 set    SectionList {}   ;# order of definition.
00195 
00196 # sectionId --
00197 #   Format section name as an XML ID.
00198 #
00199 proc c_sectionId {name} {
00200     # Identical to '__sid' in checker.tcl
00201     regsub -all {[  ]+} [string tolower [string trim $name]] _ id
00202     regsub -all {"} $id _ id
00203     return $id
00204 }
00205 
00206 /*  possibleReference text gi --*/
00207 /*  Check if $text is a potential cross-reference;*/
00208 /*  if so, format as a reference;*/
00209 /*  otherwise format as a $gi element.*/
00210 /* */
00211 ret  c_possibleReference (type text , type gi , optional label ={)} {
00212     global SectionNames
00213     if {![string length $label]} { label =  $text}
00214      id =  [c_sectionId $text]
00215     if {[info exists SectionNames($id)]} {
00216         return "[startTag ref refid $id]$label[endTag ref]"
00217     } else {
00218         return [wrap $label $gi]
00219     }
00220 }
00221 
00222 ret  c_newSection (type name , type level , type location) {
00223     global SectionList SectionNames
00224     set id          [c_sectionId $name]
00225 
00226     set SectionNames($id) .
00227     set SectionList [linsert $SectionList $location $name $id $level]
00228     return
00229 }
00230 
00231 ret  c_clrSections () {
00232     global SectionList SectionNames
00233     set    SectionList {}
00234     catch {unset SectionNames}
00235 }
00236 
00237 /* */
00238 /*  Conversion specification.*/
00239 /* */
00240 /*  Two-pass processing.  The first pass collects text for the*/
00241 /*  SYNOPSIS, SEE ALSO, and KEYWORDS sections, and the second pass*/
00242 /*  produces output.*/
00243 /* */
00244 
00245 c_holdBuffers synopsis see_also keywords precomments
00246 
00247 /* */
00248 /*  Management of see-also and keyword cross-references*/
00249 
00250 ret  c_xref_init () {
00251     global seealso  seealso__  ; set seealso  [list] ; catch {unset seealso__}  ; array set seealso__  {}
00252     global keywords keywords__ ; set keywords [list] ; catch {unset keywords__} ; array set keywords__ {}
00253 }
00254 
00255 ret  c_xref_seealso  () {global seealso  ; return $seealso}
00256 ret  c_xref_keywords () {global keywords ; return $keywords}
00257 
00258 c_pass 1 fmt_see_also {args} {
00259     global seealso seealso__
00260     foreach ref $args {
00261     if {[info exists seealso__($ref)]} continue
00262     lappend seealso $ref
00263          seealso = __($ref) .
00264     }
00265     return
00266 }
00267 
00268 c_pass 1 fmt_keywords {args} {
00269     global keywords keywords__
00270     foreach ref $args {
00271     if {[info exists keywords__($ref)]} continue
00272     lappend keywords $ref
00273          keywords = __($ref) .
00274     }
00275     return
00276 }
00277 
00278 c_pass 2 fmt_see_also {args} NOP
00279 c_pass 2 fmt_keywords {args} NOP
00280 
00281 /* */
00282 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1