/[dtapublic]/pubs/books/ucbka/trunk/scripts/cp_script.tcl
ViewVC logotype

Diff of /pubs/books/ucbka/trunk/scripts/cp_script.tcl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4 by dashley, Thu Oct 6 03:15:02 2016 UTC revision 139 by dashley, Mon Jul 3 01:58:00 2017 UTC
# Line 1  Line 1 
1  #----------------------------------------------------------------------------------------  #----------------------------------------------------------------------------------------
2  #$Header: /home/dashley/cvsrep/e3ft_gpl01/e3ft_gpl01/dtaipubs/esrgubka/scripts/cp_script.tcl,v 1.40 2009/08/14 03:38:57 dashley Exp $  #$Header$
3  #----------------------------------------------------------------------------------------  #----------------------------------------------------------------------------------------
4  # Dave Ashley  # Dave Ashley
5  # DAVEASHLEY@DAVEASHLEY.COM  # DASHLEY@GMAIL.COM
6  # DTASHLEY@AOL.COM  #----------------------------------------------------------------------------------------
7  #----------------------------------------------------------------------------------------  # Tcl script (using Tk extensions, so it must be run under Tk/Wish) to build and package
8  # Tcl script (using Tk extensions, so it must be run under Tk/Wish) to build and package  # both Dave Ashley's microcontroller software book, and the associated ESRG Tool set.  This
9  # both Dave Ashley's microcontroller software book, and the associated ESRG Tool set.  This  # script is also included with the source code of either so that the script can be used
10  # script is also included with the source code of either so that the script can be used  # by those who have purchased or otherwise obtained the LaTeX source for the book or the
11  # by those who have purchased or otherwise obtained the LaTeX source for the book or the  # source for the ESRG Tool Set to do the build.
12  # source for the ESRG Tool Set to do the build.  #----------------------------------------------------------------------------------------
13  #----------------------------------------------------------------------------------------  #The version control information below is extracted by this Tcl script and incorporated
14  #The version control information below is extracted by this Tcl script and incorporated  #into the back of the title page.  This takes the place of the "main .TEX file" information
15  #into the back of the title page.  This takes the place of the "main .TEX file" information  #that was there previously.  Since the main files are now generated on the fly by the Tcl
16  #that was there previously.  Since the main files are now generated on the fly by the Tcl  #script, this is the logical replacement.  Version control information is included so
17  #script, this is the logical replacement.  Version control information is included so  #that if anything goes awry, the origin and what was being used can be tracked down.
18  #that if anything goes awry, the origin and what was being used can be tracked down.  #
19  #  #AUTOMATIC MARKER:  BEGIN SCRIPT VERSION CONTROL INFORMATION
20  #AUTOMATIC MARKER:  BEGIN SCRIPT VERSION CONTROL INFORMATION  #$RCSfile: cp_script.tcl,v $
21  #$RCSfile: cp_script.tcl,v $  #$Source: /home/dashley/cvsrep/e3ft_gpl01/e3ft_gpl01/dtaipubs/esrgubka/scripts/cp_script.tcl,v $
22  #$Source: /home/dashley/cvsrep/e3ft_gpl01/e3ft_gpl01/dtaipubs/esrgubka/scripts/cp_script.tcl,v $  #$Revision: 1.40 $
23  #$Revision: 1.40 $  #$Author: dashley $
24  #$Author: dashley $  #$Date: 2009/08/14 03:38:57 $
25  #$Date: 2009/08/14 03:38:57 $  #AUTOMATIC MARKER:  END SCRIPT VERSION CONTROL INFORMATION
26  #AUTOMATIC MARKER:  END SCRIPT VERSION CONTROL INFORMATION  #
27  #  #****************************************************************************************
28  #****************************************************************************************  #****************************************************************************************
29  #****************************************************************************************  #****    U T I L I T Y    F U N C T I O N S    ******************************************
30  #****    U T I L I T Y    F U N C T I O N S    ******************************************  #****************************************************************************************
31  #****************************************************************************************  #****************************************************************************************
32  #****************************************************************************************  # Exit procedure.  Exits unconditionally.  Clicked in response
33  # Exit procedure.  Exits unconditionally.  Clicked in response  # to the button marked EXIT.
34  # to the button marked EXIT.  #
35  #  proc exitProc { } { \
36  proc exitProc { } { \     global buildlogfilehandle
37     global buildlogfilehandle  
38       #Put the system date and time into the build log and on the console.
39     #Put the system date and time into the build log and on the console.     set buildendtimestamp [clock seconds]
40     set buildendtimestamp [clock seconds]     set s0 [clock format $buildendtimestamp -format "Execution ending at: %A, %B %d, %Y; %I:%M:%S %p."]
41     set s0 [clock format $buildendtimestamp -format "Execution ending at: %A, %B %d, %Y; %I:%M:%S %p."]     outboth $s0
42     outboth $s0     thickhlineboth
43     thickhlineboth     close $buildlogfilehandle
44     close $buildlogfilehandle     exit 0
45     exit 0     }
46     }  
47    #-----------------------------------------------------------------------------
48  #-----------------------------------------------------------------------------  #Writes a contiguous group of a number of characters (or strings) to a stream,
49  #Writes a contiguous group of a number of characters (or strings) to a stream,  #without a terminating newline.
50  #without a terminating newline.  
51    proc contiggrouptostream { thestream thechar howmany } {
52  proc contiggrouptostream { thestream thechar howmany } {     for {set i 0} {$i < $howmany} {incr i} {
53     for {set i 0} {$i < $howmany} {incr i} {        puts -nonewline $thestream $thechar
54        puts -nonewline $thestream $thechar        }
55        }        
56             return
57     return     }
58     }  
59    #----------------------------------------------------------------------------------------
60  #----------------------------------------------------------------------------------------  #Copies (binary) from src to dest, destroying dest in advance.
61  #Copies (binary) from src to dest, destroying dest in advance.  proc destructive_binary_copy { src dest } {
62  proc destructive_binary_copy { src dest } {     #Delete dest, if it exists.
63     #Delete dest, if it exists.     file delete $dest
64     file delete $dest    
65         set srchandle [open $src  "r"]
66     set srchandle [open $src  "r"]     set dsthandle [open $dest "w"]  
67     set dsthandle [open $dest "w"]    
68       fconfigure $srchandle -translation binary
69     fconfigure $srchandle -translation binary     fconfigure $dsthandle -translation binary
70     fconfigure $dsthandle -translation binary    
71         fcopy $srchandle $dsthandle
72     fcopy $srchandle $dsthandle    
73         close $srchandle
74     close $srchandle     close $dsthandle
75     close $dsthandle    
76         return
77     return     }
78     }  
79    #****************************************************************************************
80  #****************************************************************************************  #****************************************************************************************
81  #****************************************************************************************  #****    N U M B E R I N G    F U N C T I O N S    **************************************
82  #****    N U M B E R I N G    F U N C T I O N S    **************************************  #****************************************************************************************
83  #****************************************************************************************  #****************************************************************************************
84  #****************************************************************************************  # Each function here has to do with numbering parts, chapters, etc.
85  # Each function here has to do with numbering parts, chapters, etc.  #
86  #  # Returns the lower-case string corresponding to a digit.
87  # Returns the lower-case string corresponding to a digit.  proc lower_case_number_string { arg } { \
88  proc lower_case_number_string { arg } { \     switch -exact $arg {
89     switch -exact $arg {        "0"     { return zero                        }
90        "0"     { return zero                        }        "1"     { return one                         }
91        "1"     { return one                         }        "2"     { return two                         }
92        "2"     { return two                         }        "3"     { return three                       }
93        "3"     { return three                       }        "4"     { return four                        }
94        "4"     { return four                        }        "5"     { return five                        }
95        "5"     { return five                        }        "6"     { return six                         }
96        "6"     { return six                         }        "7"     { return seven                       }
97        "7"     { return seven                       }        "8"     { return eight                       }
98        "8"     { return eight                       }        "9"     { return nine                        }
99        "9"     { return nine                        }        default { return INTERNAL_FUNCTION_PAR_ERROR }
100        default { return INTERNAL_FUNCTION_PAR_ERROR }        }
101        }     }
102     }  
103    
104    # Returns the upper-case string corresponding to the
105  # Returns the upper-case string corresponding to the  # roman numerals of a decimal number.  Algorithm is simple
106  # roman numerals of a decimal number.  Algorithm is simple  # case because numbers won't get large enough to prevent
107  # case because numbers won't get large enough to prevent  # enumeration.
108  # enumeration.  proc upper_case_roman_numeral_string { arg } { \
109  proc upper_case_roman_numeral_string { arg } { \     switch -exact $arg {
110     switch -exact $arg {        "0"     { return ZERO_NOT_SUPPORTED_ROMAN    }
111        "0"     { return ZERO_NOT_SUPPORTED_ROMAN    }        "1"     { return I                           }
112        "1"     { return I                           }        "2"     { return II                          }
113        "2"     { return II                          }        "3"     { return III                         }
114        "3"     { return III                         }        "4"     { return IV                          }
115        "4"     { return IV                          }        "5"     { return V                           }
116        "5"     { return V                           }        "6"     { return VI                          }
117        "6"     { return VI                          }        "7"     { return VII                         }
118        "7"     { return VII                         }        "8"     { return VIII                        }
119        "8"     { return VIII                        }        "9"     { return IX                          }
120        "9"     { return IX                          }       "10"     { return X                           }
121       "10"     { return X                           }       "11"     { return XI                          }
122       "11"     { return XI                          }       "12"     { return XII                         }
123       "12"     { return XII                         }       "13"     { return XIII                        }
124       "13"     { return XIII                        }       "14"     { return XIV                         }
125       "14"     { return XIV                         }       "15"     { return XV                          }
126       "15"     { return XV                          }       "16"     { return XVI                         }
127       "16"     { return XVI                         }       "17"     { return XVII                        }
128       "17"     { return XVII                        }       "18"     { return XVIII                       }
129       "18"     { return XVIII                       }       "19"     { return XIX                         }
130       "19"     { return XIX                         }       "20"     { return XX                          }
131       "20"     { return XX                          }       "21"     { return XXI                         }
132       "21"     { return XXI                         }       "22"     { return XXII                        }
133       "22"     { return XXII                        }       "23"     { return XXIII                       }
134       "23"     { return XXIII                       }       "24"     { return XXIV                        }
135       "24"     { return XXIV                        }       "25"     { return XXV                         }
136       "25"     { return XXV                         }       "26"     { return XXVI                        }
137       "26"     { return XXVI                        }       "27"     { return XXVII                       }
138       "27"     { return XXVII                       }       "28"     { return XXVIII                      }
139       "28"     { return XXVIII                      }       "29"     { return XXIX                        }
140       "29"     { return XXIX                        }       "30"     { return XXX                         }
141       "30"     { return XXX                         }       "31"     { return XXXI                        }
142       "31"     { return XXXI                        }       "32"     { return XXXII                       }
143       "32"     { return XXXII                       }       "33"     { return XXXIII                      }
144       "33"     { return XXXIII                      }       "34"     { return XXXIV                       }
145       "34"     { return XXXIV                       }       "35"     { return XXXV                        }
146       "35"     { return XXXV                        }       "36"     { return XXXVI                       }
147       "36"     { return XXXVI                       }       "37"     { return XXXVII                      }
148       "37"     { return XXXVII                      }       "38"     { return XXXVIII                     }
149       "38"     { return XXXVIII                     }       "39"     { return XXXIX                       }
150       "39"     { return XXXIX                       }       "40"     { return XXXX                        }
151       "40"     { return XXXX                        }       "41"     { return XXXXI                       }
152       "41"     { return XXXXI                       }       "42"     { return XXXXII                      }
153       "42"     { return XXXXII                      }       "43"     { return XXXXIII                     }
154       "43"     { return XXXXIII                     }       "44"     { return XXXXIV                      }
155       "44"     { return XXXXIV                      }       "45"     { return XXXXV                       }
156       "45"     { return XXXXV                       }       "46"     { return XXXXVI                      }
157       "46"     { return XXXXVI                      }       "47"     { return XXXXVII                     }
158       "47"     { return XXXXVII                     }       "48"     { return XXXXVIII                    }
159       "48"     { return XXXXVIII                    }       "49"     { return IL                          }
160       "49"     { return IL                          }        default { return INTERNAL_FUNCTION_PAR_ERROR }
161        default { return INTERNAL_FUNCTION_PAR_ERROR }        }
162        }     }
163     }  
164    #****************************************************************************************
165  #****************************************************************************************  #****************************************************************************************
166  #****************************************************************************************  #****    T E X T    M A N I P U L A T I O N    F U N C T I O N S    *********************
167  #****    T E X T    M A N I P U L A T I O N    F U N C T I O N S    *********************  #****************************************************************************************
168  #****************************************************************************************  #****************************************************************************************
169  #****************************************************************************************  #
170  #  # Replaces all digits in a string with their textual strings.  This is used to form
171  # Replaces all digits in a string with their textual strings.  This is used to form  # commands whose names the LaTeX compiler will accept.
172  # commands whose names the LaTeX compiler will accept.  proc replace_digits_with_alphas { arg } { \
173  proc replace_digits_with_alphas { arg } { \     set result ""
174     set result ""     set N [string length $arg]
175     set N [string length $arg]  
176       for {set i 0} {$i < $N} {incr i} { \
177     for {set i 0} {$i < $N} {incr i} { \        set c [string index $arg $i]
178        set c [string index $arg $i]  
179          if {[string first $c "0123456789"] == -1} { \
180        if {[string first $c "0123456789"] == -1} { \           #Isn't a digit, just append.
181           #Isn't a digit, just append.           append result $c
182           append result $c           } \
183           } \        else {
184        else {           #Is a digit, must expand and append.
185           #Is a digit, must expand and append.           append result [lower_case_number_string $c]
186           append result [lower_case_number_string $c]           }
187           }        }
188        }  
189       return $result
190     return $result     }
191     }  
192    #Replaces any spaces in a string with the HTML code %20.  This is necessary to
193  #Replaces any spaces in a string with the HTML code %20.  This is necessary to  #to achieve the proper HTML syntax when putting filenames in in come contexts.
194  #to achieve the proper HTML syntax when putting filenames in in come contexts.  #
195  #  proc replace_spaces_with_HTML_codes { tgt } { \
196  proc replace_spaces_with_HTML_codes { tgt } { \     set tgt [string map {" " "%20"} $tgt]
197     set tgt [string map {" " "%20"} $tgt]     return $tgt
198     return $tgt     }
199     }  
200    
201    #****************************************************************************************
202  #****************************************************************************************  #****************************************************************************************
203  #****************************************************************************************  #****    V E R S I O N    C O N T R O L    E X T R A C T I O N    F U N C T I O N S    **
204  #****    V E R S I O N    C O N T R O L    E X T R A C T I O N    F U N C T I O N S    **  #****************************************************************************************
205  #****************************************************************************************  #****************************************************************************************
206  #****************************************************************************************  #Extracts the version control information lines (marked automatically above) from this
207  #Extracts the version control information lines (marked automatically above) from this  #file and returns them as a string.  The string includes all newline characters.
208  #file and returns them as a string.  The string includes all newline characters.  
209    proc extract_this_scripts_version_control_information { } { \
210  proc extract_this_scripts_version_control_information { } { \     #Define the strings that we'll accept as beginning the
211     #Define the strings that we'll accept as beginning the     #block of version control information and the strings
212     #block of version control information and the strings     #that we'll accept as terminating it.
213     #that we'll accept as terminating it.     set begin_string "AUTOMATIC MARKER:  BEGIN SCRIPT VERSION CONTROL INFORMATION"
214     set begin_string "AUTOMATIC MARKER:  BEGIN SCRIPT VERSION CONTROL INFORMATION"     set end_string   "AUTOMATIC MARKER:  END SCRIPT VERSION CONTROL INFORMATION"
215     set end_string   "AUTOMATIC MARKER:  END SCRIPT VERSION CONTROL INFORMATION"  
216       #Initialize our return value to nothing so far.
217     #Initialize our return value to nothing so far.     set rv ""
218     set rv ""  
219       #Open the script for extraction.
220     #Open the script for extraction.     set script_handle [open scripts/cp_script.tcl r]
221     set script_handle [open scripts/cp_script.tcl r]  
222       #Leaf through the file until we hit the end of file or else the beginning string.
223     #Leaf through the file until we hit the end of file or else the beginning string.     set eof_found 0
224     set eof_found 0     set beginstring_found 0
225     set beginstring_found 0     while {!$eof_found && !$beginstring_found} { \
226     while {!$eof_found && !$beginstring_found} { \        set current_line [gets $script_handle]
227        set current_line [gets $script_handle]        set beginstring_found_index [string first $begin_string $current_line]
228        set beginstring_found_index [string first $begin_string $current_line]        set beginstring_found [expr $beginstring_found_index >= 0]
229        set beginstring_found [expr $beginstring_found_index >= 0]        set eof_found [eof $script_handle]
230        set eof_found [eof $script_handle]        }
231        }  
232       if {!$eof_found} { \
233     if {!$eof_found} { \        #If we're here, we got the begin string we were looking for.  Copy over
234        #If we're here, we got the begin string we were looking for.  Copy over        #until the end string is encountered or until end of file.
235        #until the end string is encountered or until end of file.        set endstring_found 0
236        set endstring_found 0        while {!$eof_found && !$endstring_found} { \
237        while {!$eof_found && !$endstring_found} { \           set current_line [gets $script_handle]
238           set current_line [gets $script_handle]  
239             #If the first character of the line is a Tcl comment delimieter (which it
240           #If the first character of the line is a Tcl comment delimieter (which it           #most likely is), trash it.
241           #most likely is), trash it.           set current_line [string trimleft $current_line "#"]
242           set current_line [string trimleft $current_line "#"]  
243             set endstring_found_index [string first $end_string $current_line]
244           set endstring_found_index [string first $end_string $current_line]           set endstring_found [expr $endstring_found_index >= 0]
245           set endstring_found [expr $endstring_found_index >= 0]           set eof_found [eof $script_handle]
246           set eof_found [eof $script_handle]           if {!$endstring_found} { \
247           if {!$endstring_found} { \              append rv $current_line "\n"
248              append rv $current_line "\n"              }
249              }           }
250           }        }
251        }  
252       #Close the script file.
253     #Close the script file.     close $script_handle
254     close $script_handle  
255       #Return the extracted version control information.
256     #Return the extracted version control information.     return $rv
257     return $rv     }
258     }  
259    #****************************************************************************************
260  #****************************************************************************************  #****************************************************************************************
261  #****************************************************************************************  #****    L O G G I N G    F U N C T I O N S    ******************************************
262  #****    L O G G I N G    F U N C T I O N S    ******************************************  #****************************************************************************************
263  #****************************************************************************************  #****************************************************************************************
264  #****************************************************************************************  # Each function in this category is called as an aid in maintaing a log file and a
265  # Each function in this category is called as an aid in maintaing a log file and a  # console display which say exactly the same thing.
266  # console display which say exactly the same thing.  #----------------------------------------------------------------------------------------
267  #----------------------------------------------------------------------------------------  #Writes a contiguous group of a number of characters to the standard output,
268  #Writes a contiguous group of a number of characters to the standard output,  #plus to the build log file.
269  #plus to the build log file.  
270    proc contiggrouptoboth { thechar howmany } {
271  proc contiggrouptoboth { thechar howmany } {     global buildlogfilehandle
272     global buildlogfilehandle    
273         contiggrouptostream $buildlogfilehandle $thechar  $howmany
274     contiggrouptostream $buildlogfilehandle $thechar  $howmany     contiggrouptostream stdout              $thechar  $howmany
275     contiggrouptostream stdout              $thechar  $howmany        
276             return
277     return     }
278     }  
279    #-----------------------------------------------------------------------------
280  #-----------------------------------------------------------------------------  #Writes a line of $loglinelength hyphens followed by a newline to only the
281  #Writes a line of $loglinelength hyphens followed by a newline to only the  #console, but not the build log file.
282  #console, but not the build log file.  
283    proc hlineconsole {} {
284  proc hlineconsole {} {     global loglinelength
285     global loglinelength    
286         contiggrouptostream stdout - $loglinelength
287     contiggrouptostream stdout - $loglinelength     puts ""
288     puts ""    
289         return
290     return     }
291     }  
292    #-----------------------------------------------------------------------------
293  #-----------------------------------------------------------------------------  #Writes a line of $loglinelength hyphens followed by a newline to both the
294  #Writes a line of $loglinelength hyphens followed by a newline to both the  #console and the build log file.
295  #console and the build log file.  
296    proc hlineboth {} {
297  proc hlineboth {} {     global loglinelength
298     global loglinelength     global buildlogfilehandle
299     global buildlogfilehandle    
300         contiggrouptoboth - $loglinelength
301     contiggrouptoboth - $loglinelength     puts $buildlogfilehandle ""
302     puts $buildlogfilehandle ""     puts ""
303     puts ""    
304         return
305     return     }
306     }  
307    #-----------------------------------------------------------------------------
308  #-----------------------------------------------------------------------------  #Writes a line of $loglinelength "=" chars followed by a newline to only the
309  #Writes a line of $loglinelength "=" chars followed by a newline to only the  #console but not the build log file.
310  #console but not the build log file.  
311    proc thickhlineconsole {} {
312  proc thickhlineconsole {} {     global loglinelength
313     global loglinelength    
314         contiggrouptostream stdout = $loglinelength
315     contiggrouptostream stdout = $loglinelength     puts ""
316     puts ""    
317         return
318     return     }
319     }  
320    #-----------------------------------------------------------------------------
321  #-----------------------------------------------------------------------------  #Writes a line of $loglinelength "=" chars followed by a newline to both the
322  #Writes a line of $loglinelength "=" chars followed by a newline to both the  #console and the build log file.
323  #console and the build log file.  
324    proc thickhlineboth {} {
325  proc thickhlineboth {} {     global loglinelength
326     global loglinelength     global buildlogfilehandle
327     global buildlogfilehandle    
328         contiggrouptoboth = $loglinelength
329     contiggrouptoboth = $loglinelength     puts $buildlogfilehandle ""
330     puts $buildlogfilehandle ""     puts ""
331     puts ""    
332         return
333     return     }
334     }  
335    #-----------------------------------------------------------------------------
336  #-----------------------------------------------------------------------------  #Dumps output to both the console and the log file, with newline attached.
337  #Dumps output to both the console and the log file, with newline attached.  proc outboth { arg } {
338  proc outboth { arg } {     global buildlogfilehandle
339     global buildlogfilehandle    
340         puts $buildlogfilehandle $arg
341     puts $buildlogfilehandle $arg     puts $arg
342     puts $arg    
343         return  
344     return       }  
345     }    
346    #-----------------------------------------------------------------------------
347  #-----------------------------------------------------------------------------  #Dumps output to both the console and the log file, without newline attached.
348  #Dumps output to both the console and the log file, without newline attached.  proc outbothnonl { arg } {
349  proc outbothnonl { arg } {     global buildlogfilehandle
350     global buildlogfilehandle    
351         puts -nonewline $buildlogfilehandle $arg
352     puts -nonewline $buildlogfilehandle $arg     puts -nonewline $arg
353     puts -nonewline $arg    
354         return  
355     return       }  
356     }    
357    #-----------------------------------------------------------------------------
358  #-----------------------------------------------------------------------------  #Prints a banner to the passed stream indicating success or failure of a build
359  #Prints a banner to the passed stream indicating success or failure of a build  #script.  The two messages are "*OK*" and "FAIL".  The failflag, if 0, means
360  #script.  The two messages are "*OK*" and "FAIL".  The failflag, if 0, means  #success, or if non-zero, means failure.  The banner will be centered
361  #success, or if non-zero, means failure.  The banner will be centered  #in the output.  $nearpadchar and $farpadchar are the characters used to pad
362  #in the output.  $nearpadchar and $farpadchar are the characters used to pad  #the centering near the banner letters and farther away.  $nearfarmargin is
363  #the centering near the banner letters and farther away.  $nearfarmargin is  #the number of characters for which the near characters extend.  
364  #the number of characters for which the near characters extend.    proc passfailbannertostream { thestream passfailflag nearpadchar farpadchar nearfarmargin} {
365  proc passfailbannertostream { thestream passfailflag nearpadchar farpadchar nearfarmargin} {  
366        global loglinelength
367      global loglinelength      
368            set passbanner {
369      set passbanner {         " OOOOO   K     K" \
370         " OOOOO   K     K" \         "O     O  K   K  " \
371         "O     O  K   K  " \         "O     O  K K    " \
372         "O     O  K K    " \         "O     O  KK     " \
373         "O     O  KK     " \         "O     O  K K    " \
374         "O     O  K K    " \         "O     O  K  K   " \
375         "O     O  K  K   " \         "O     O  K   K  " \
376         "O     O  K   K  " \         "O     O  K    K " \
377         "O     O  K    K " \         " OOOOO   K     K" \
378         " OOOOO   K     K" \         }
379         }      set failbanner {
380      set failbanner {         "FFFFFFF    AAA      III    L      " \
381         "FFFFFFF    AAA      III    L      " \         "F         A   A      I     L      " \
382         "F         A   A      I     L      " \         "F        A     A     I     L      " \
383         "F        A     A     I     L      " \         "F        A     A     I     L      " \
384         "F        A     A     I     L      " \         "FFFFFF   AAAAAAA     I     L      " \
385         "FFFFFF   AAAAAAA     I     L      " \         "F        A     A     I     L      " \
386         "F        A     A     I     L      " \         "F        A     A     I     L      " \
387         "F        A     A     I     L      " \         "F        A     A     I     L      " \
388         "F        A     A     I     L      " \         "F        A     A    III    LLLLLLL" \
389         "F        A     A    III    LLLLLLL" \         }
390         }  
391       #First we need to calculate the number of chars on the left with which
392     #First we need to calculate the number of chars on the left with which     #to pad the the result.
393     #to pad the the result.    
394         if {$passfailflag != 0} {
395     if {$passfailflag != 0} {        #Fail
396        #Fail        set banner $failbanner
397        set banner $failbanner        } \
398        } \     else {
399     else {        #Pass
400        #Pass        set banner $passbanner
401        set banner $passbanner        }
402        }        
403             #Determine the width of the banner which applies.
404     #Determine the width of the banner which applies.     set bannerwidth [string length [lindex $banner 0] ]
405     set bannerwidth [string length [lindex $banner 0] ]    
406         #Calculate the size in chars to use for the far padding.
407     #Calculate the size in chars to use for the far padding.     set farpadwidth [expr "($loglinelength - $bannerwidth - (2 * $nearfarmargin ) ) >> 1"]    
408     set farpadwidth [expr "($loglinelength - $bannerwidth - (2 * $nearfarmargin ) ) >> 1"]        
409         #If by poor choice of all values we ended up with a negative number, clip it to zero.
410     #If by poor choice of all values we ended up with a negative number, clip it to zero.     if {$farpadwidth < 0} {
411     if {$farpadwidth < 0} {        set farpadwidth 0
412        set farpadwidth 0        }
413        }        
414             #Iterate to output the lines of the banner.
415     #Iterate to output the lines of the banner.     foreach curline $banner {
416     foreach curline $banner {        for {set i 0} {$i < $farpadwidth} {incr i} {
417        for {set i 0} {$i < $farpadwidth} {incr i} {           puts -nonewline $thestream $farpadchar
418           puts -nonewline $thestream $farpadchar           }
419           }          
420                  for {set i 0} {$i < $nearfarmargin} {incr i} {
421        for {set i 0} {$i < $nearfarmargin} {incr i} {           puts -nonewline $thestream $nearpadchar
422           puts -nonewline $thestream $nearpadchar           }
423           }          
424                  puts -nonewline $thestream $curline
425        puts -nonewline $thestream $curline        
426                for {set i 0} {$i < $nearfarmargin} {incr i} {
427        for {set i 0} {$i < $nearfarmargin} {incr i} {           puts -nonewline $thestream $nearpadchar
428           puts -nonewline $thestream $nearpadchar           }
429           }  
430          for {set i 0} {$i < $farpadwidth} {incr i} {
431        for {set i 0} {$i < $farpadwidth} {incr i} {           puts -nonewline $thestream $farpadchar
432           puts -nonewline $thestream $farpadchar           }
433           }  
434          puts $thestream ""              
435        puts $thestream ""                      }
436        }            
437                 return  
438     return       }  
439     }    
440    #****************************************************************************************
441  #****************************************************************************************  #****************************************************************************************
442  #****************************************************************************************  #****    D A T A    S T R U C T U R E    U T I L I T Y    F U N C T I O N S    **********
443  #****    D A T A    S T R U C T U R E    U T I L I T Y    F U N C T I O N S    **********  #****************************************************************************************
444  #****************************************************************************************  #****************************************************************************************
445  #****************************************************************************************  # Each function in this category provides a function related to the data structures
446  # Each function in this category provides a function related to the data structures  # embedded in the script.  Generally, errors are all fatal.
447  # embedded in the script.  Generally, errors are all fatal.  #----------------------------------------------------------------------------------------
448  #----------------------------------------------------------------------------------------  # Indexes the volume list by the 4-letter tag.  This is done for lookup speed.
449  # Indexes the volume list by the 4-letter tag.  This is done for lookup speed.  proc IndexVolumeList { } { \
450  proc IndexVolumeList { } { \     global bookVolumeList
451     global bookVolumeList     global bookVolumeListStructSize
452     global bookVolumeListStructSize     global bookVolumeListIndex
453     global bookVolumeListIndex  
454       outboth "Indexing volume list."
455     outboth "Indexing volume list."  
456       set N [llength $bookVolumeList]
457     set N [llength $bookVolumeList]  
458       for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
459     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        set elem [lindex $bookVolumeList $i]
460        set elem [lindex $bookVolumeList $i]  
461          set bookVolumeListIndex($elem) $i
462        set bookVolumeListIndex($elem) $i  
463          outboth "   bookVolumeList($elem) = $i"
464        outboth "   bookVolumeList($elem) = $i"        }
465        }  
466       hlineboth
467     hlineboth     }
468     }  
469    #----------------------------------------------------------------------------------------
470  #----------------------------------------------------------------------------------------  # Indexes the chapter list by the 4-letter tag.  This is done for lookup speed.
471  # Indexes the chapter list by the 4-letter tag.  This is done for lookup speed.  proc IndexChapterList { } { \
472  proc IndexChapterList { } { \     global chapterList
473     global chapterList     global chapterListStructSize
474     global chapterListStructSize     global chapterListIndex
475     global chapterListIndex  
476       outboth "Indexing chapter list."
477     outboth "Indexing chapter list."  
478       set N [llength $chapterList]
479     set N [llength $chapterList]  
480       for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \
481     for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \        set elem [lindex $chapterList $i]
482        set elem [lindex $chapterList $i]  
483          set chapterListIndex($elem) $i
484        set chapterListIndex($elem) $i  
485          outboth "   chapterList($elem) = $i"
486        outboth "   chapterList($elem) = $i"        }
487        }  
488       hlineboth
489     hlineboth     }
490     }  
491    #****************************************************************************************
492  #****************************************************************************************  #****************************************************************************************
493  #****************************************************************************************  #****    C H A P T E R    T A B L E    L O O K U P    F U N C T I O N S    **************
494  #****    C H A P T E R    T A B L E    L O O K U P    F U N C T I O N S    **************  #****************************************************************************************
495  #****************************************************************************************  #****************************************************************************************
496  #****************************************************************************************  # Functions which look up chapter table information.
497  # Functions which look up chapter table information.  #----------------------------------------------------------------------------------------
498  #----------------------------------------------------------------------------------------  #
499  #  # Returns the single-volume long title for a chapter.  Input is the 4-character
500  # Returns the single-volume long title for a chapter.  Input is the 4-character  # chapter tag.  Chapter table must have been indexed in advance.
501  # chapter tag.  Chapter table must have been indexed in advance.  proc get_chap_long_single_volume_title { ctag } { \
502  proc get_chap_long_single_volume_title { ctag } { \     global chapterList
503     global chapterList     global chapterListIndex
504     global chapterListIndex  
505       set i $chapterListIndex($ctag)
506     set i $chapterListIndex($ctag)  
507       return [lindex $chapterList [expr $i + 1]]
508     return [lindex $chapterList [expr $i + 1]]     }
509     }  
510    # Returns the single-volume short title for a chapter.  Input is the 4-character
511  # Returns the single-volume short title for a chapter.  Input is the 4-character  # chapter tag.  Chapter table must have been indexed in advance.
512  # chapter tag.  Chapter table must have been indexed in advance.  proc get_chap_short_single_volume_title { ctag } { \
513  proc get_chap_short_single_volume_title { ctag } { \     global chapterList
514     global chapterList     global chapterListIndex
515     global chapterListIndex  
516       set i $chapterListIndex($ctag)
517     set i $chapterListIndex($ctag)  
518       return [lindex $chapterList [expr $i + 2]]
519     return [lindex $chapterList [expr $i + 2]]     }
520     }  
521    #Mark an individual chapter (by tag) used.
522  #Mark an individual chapter (by tag) used.  proc mark_chapter_used { ctag } { \
523  proc mark_chapter_used { ctag } { \     global chapterList
524     global chapterList     global chapterListIndex
525     global chapterListIndex  
526       #outboth "Inside chapter marking function, ctag is : $ctag"
527     #outboth "Inside chapter marking function, ctag is : $ctag"  
528       set i $chapterListIndex($ctag)
529     set i $chapterListIndex($ctag)  
530       set i [expr $i + 7]
531     set i [expr $i + 7]  
532       #outboth "Element selected for marking is : $i"
533     #outboth "Element selected for marking is : $i"  
534       #outboth "Current value is: [lindex $chapterList $i]"
535     #outboth "Current value is: [lindex $chapterList $i]"  
536       set chapterList [lreplace $chapterList $i $i 1]
537     set chapterList [lreplace $chapterList $i $i 1]  
538       #outboth "New value is: [lindex $chapterList $i]"
539     #outboth "New value is: [lindex $chapterList $i]"     }
540     }  
541    
542    #Inquire if a given chapter (by tag) has its used flag set.
543  #Inquire if a given chapter (by tag) has its used flag set.  #Result is "1" if used, "0" otherwise.
544  #Result is "1" if used, "0" otherwise.  proc get_chap_used_flag { ctag } { \
545  proc get_chap_used_flag { ctag } { \     global chapterList
546     global chapterList     global chapterListStructSize
547     global chapterListStructSize     global chapterListIndex
548     global chapterListIndex  
549       set i $chapterListIndex($ctag)
550     set i $chapterListIndex($ctag)  
551       set i [expr $i + 7]
552     set i [expr $i + 7]  
553       return [lindex $chapterList $i]
554     return [lindex $chapterList $i]     }
555     }  
556    
557    #Marks each of the chapters as unused (resets all of the "used" flags to zero).
558  #Marks each of the chapters as unused (resets all of the "used" flags to zero).  proc mark_all_chaps_unused { } { \
559  proc mark_all_chaps_unused { } { \     global chapterList
560     global chapterList     global chapterListStructSize
561     global chapterListStructSize  
562       set N [llength $chapterList]
563     set N [llength $chapterList]  
564       for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \
565     for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \        set j [expr $i + 7]
566        set j [expr $i + 7]  
567          set chapterList [lreplace $chapterList $j $j 0]
568        set chapterList [lreplace $chapterList $j $j 0]        }
569        }     }
570     }  
571    #****************************************************************************************
572  #****************************************************************************************  #****************************************************************************************
573  #****************************************************************************************  #****    V O L U M E    T A B L E    L O O K U P    F U N C T I O N S    ****************
574  #****    V O L U M E    T A B L E    L O O K U P    F U N C T I O N S    ****************  #****************************************************************************************
575  #****************************************************************************************  #****************************************************************************************
576  #****************************************************************************************  # Functions which lookup volume table information.
577  # Functions which lookup volume table information.  #----------------------------------------------------------------------------------------
578  #----------------------------------------------------------------------------------------  # Returns the part string associated with a volume record in the volume table.  
579  # Returns the part string associated with a volume record in the volume table.    # Input is the 4-character volume tag.  Volume table must have been indexed in advance.
580  # Input is the 4-character volume tag.  Volume table must have been indexed in advance.  proc get_vol_part_title { vtag } { \
581  proc get_vol_part_title { vtag } { \     global bookVolumeList
582     global bookVolumeList     global bookVolumeListIndex
583     global bookVolumeListIndex  
584       set i $bookVolumeListIndex($vtag)
585     set i $bookVolumeListIndex($vtag)  
586       return [lindex $bookVolumeList [expr $i + 3]]
587     return [lindex $bookVolumeList [expr $i + 3]]     }
588     }  
589    # Returns the multiple-volume long title associated with a volume.                
590  # Returns the multiple-volume long title associated with a volume.                  # Input is the 4-character volume tag.  Volume table must have been indexed in advance.
591  # Input is the 4-character volume tag.  Volume table must have been indexed in advance.  proc get_multi_vol_long_title { vtag } { \
592  proc get_multi_vol_long_title { vtag } { \     global bookVolumeList
593     global bookVolumeList     global bookVolumeListIndex
594     global bookVolumeListIndex  
595       set i $bookVolumeListIndex($vtag)
596     set i $bookVolumeListIndex($vtag)  
597       return [lindex $bookVolumeList [expr $i + 4]]
598     return [lindex $bookVolumeList [expr $i + 4]]     }
599     }  
600    #Marks each of the volumes as unused (resets all of the "used" flags to zero).
601  #Marks each of the volumes as unused (resets all of the "used" flags to zero).  proc mark_all_volumes_unused { } { \
602  proc mark_all_volumes_unused { } { \     global bookVolumeList
603     global bookVolumeList     global bookVolumeListStructSize
604     global bookVolumeListStructSize  
605       set N [llength $bookVolumeList]
606     set N [llength $bookVolumeList]  
607       for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
608     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        set j [expr $i + 7]
609        set j [expr $i + 7]  
610          set bookVolumeList [lreplace $bookVolumeList $j $j 0]
611        set bookVolumeList [lreplace $bookVolumeList $j $j 0]        }
612        }     }
613     }  
614    #Mark an individual volume (by tag) used.
615  #Mark an individual volume (by tag) used.  proc mark_volume_used { vtag } { \
616  proc mark_volume_used { vtag } { \     global bookVolumeList
617     global bookVolumeList     global bookVolumeListIndex
618     global bookVolumeListIndex  
619       set i $bookVolumeListIndex($vtag)
620     set i $bookVolumeListIndex($vtag)  
621       set i [expr $i + 7]
622     set i [expr $i + 7]  
623       set bookVolumeList [lreplace $bookVolumeList $i $i 1]
624     set bookVolumeList [lreplace $bookVolumeList $i $i 1]     }
625     }  
626    
627    #Inquire if a given volume (by tag) has its used flag set.
628  #Inquire if a given volume (by tag) has its used flag set.  #Result is "1" if used, "0" otherwise.
629  #Result is "1" if used, "0" otherwise.  proc get_volume_used_flag { vtag } { \
630  proc get_volume_used_flag { vtag } { \     global bookVolumeList
631     global bookVolumeList     global bookVolumeListStructSize
632     global bookVolumeListStructSize     global bookVolumeListIndex
633     global bookVolumeListIndex  
634       set i $bookVolumeListIndex($vtag)
635     set i $bookVolumeListIndex($vtag)  
636       set i [expr $i + 7]
637     set i [expr $i + 7]  
638       return [lindex $bookVolumeList $i]
639     return [lindex $bookVolumeList $i]     }
640     }  
641    
642    #****************************************************************************************
643  #****************************************************************************************  #****************************************************************************************
644  #****************************************************************************************  #****    L A T E X    C O M P I L E    F U N C T I O N S    *****************************
645  #****    L A T E X    C O M P I L E    F U N C T I O N S    *****************************  #****************************************************************************************
646  #****************************************************************************************  #****************************************************************************************
647  #****************************************************************************************  # Each function in this category performs a function related to LaTeX compilation or
648  # Each function in this category performs a function related to LaTeX compilation or  # indexing.                        
649  # indexing.                          #----------------------------------------------------------------------------------------
650  #----------------------------------------------------------------------------------------  # Performs the LaTeX compile of the passed filename, in the "root" directory of the book.
651  # Performs the LaTeX compile of the passed filename, in the "root" directory of the book.  # Any errors will cause the script to terminate.  It gets more attention that way, when
652  # Any errors will cause the script to terminate.  It gets more attention that way, when  # an error kills the script.
653  # an error kills the script.  #
654  #  proc LatexCompileFile { filename } { \
655  proc LatexCompileFile { filename } { \     global execLatexCompiler
656     global execLatexCompiler     global errorCode
657     global errorCode  
658       #The error-handling strategy taken in this function is to terminate with a log file
659     #The error-handling strategy taken in this function is to terminate with a log file     #entry if the LaTeX compiler chokes.  First of all, generally the LaTeX code is
660     #entry if the LaTeX compiler chokes.  First of all, generally the LaTeX code is     #debugged in the 4AllTex GUI, so we shouldn't be compiling bad LaTeX code here.
661     #debugged in the 4AllTex GUI, so we shouldn't be compiling bad LaTeX code here.     #Second, this is a utility script, and not required to be graceful.  Third,
662     #Second, this is a utility script, and not required to be graceful.  Third,     #terminating the program will definitely get the user's attention, whereas any
663     #terminating the program will definitely get the user's attention, whereas any     #lesser approach might not.
664     #lesser approach might not.     outbothnonl "Using LaTeX to compile: $filename"
665     outbothnonl "Using LaTeX to compile: $filename"     outboth .
666     outboth .     hlineboth
667     hlineboth  
668       #The full path to the LaTeX compiler has already been calculated for us at
669     #The full path to the LaTeX compiler has already been calculated for us at     #script startup.
670     #script startup.  
671       #Delete existing intermediate files if they exist.
672     #Delete existing intermediate files if they exist.     file delete tcl00out.txt
673     file delete tcl00out.txt     file delete tcl00err.txt
674     file delete tcl00err.txt                
675                     #Open the intermediate files for writing.
676     #Open the intermediate files for writing.     set stdouthandle [open "tcl00out.txt" "w"]
677     set stdouthandle [open "tcl00out.txt" "w"]     set stderrhandle [open "tcl00err.txt" "w"]
678     set stderrhandle [open "tcl00err.txt" "w"]  
679       #Execute exec and suppress errors.
680     #Execute exec and suppress errors.     set catchreturncode 0
681     set catchreturncode 0     set catchreturncode [catch {exec -- $execLatexCompiler -progname=latex &latex $filename >@ $stdouthandle 2>@ $stderrhandle}]
682     set catchreturncode [catch {exec -- $execLatexCompiler -progname=latex &latex $filename >@ $stdouthandle 2>@ $stderrhandle}]     set catcherrorcode $errorCode
683     set catcherrorcode $errorCode  
684       #Close both open files.
685     #Close both open files.     close $stderrhandle
686     close $stderrhandle     close $stdouthandle
687     close $stdouthandle          
688               if {$catchreturncode} {
689     if {$catchreturncode} {        outbothnonl "$execLatexCompiler generated errors (information follows): $catchreturncode $catcherrorcode"
690        outbothnonl "$execLatexCompiler generated errors (information follows): $catchreturncode $catcherrorcode"        outboth "."
691        outboth "."        outboth "The build must be aborted."
692        outboth "The build must be aborted."        set compilefailed 1
693        set compilefailed 1        hlineboth
694        hlineboth        } \
695        } \     else {
696     else {        outboth "$execLatexCompiler did not generate errors."
697        outboth "$execLatexCompiler did not generate errors."        set compilefailed 0
698        set compilefailed 0        hlineboth
699        hlineboth        }
700        }  
701       set stdouthandle [open "tcl00out.txt" "r"]
702     set stdouthandle [open "tcl00out.txt" "r"]     set stderrhandle [open "tcl00err.txt" "r"]
703     set stderrhandle [open "tcl00err.txt" "r"]     set stdoutoutput [read $stdouthandle]
704     set stdoutoutput [read $stdouthandle]     set stderroutput [read $stderrhandle]
705     set stderroutput [read $stderrhandle]     close $stdouthandle
706     close $stdouthandle     close $stderrhandle
707     close $stderrhandle  
708       #Delete existing intermediate files if they exist.
709     #Delete existing intermediate files if they exist.     file delete tcl00out.txt
710     file delete tcl00out.txt     file delete tcl00err.txt
711     file delete tcl00err.txt          
712               outboth "Standard output stream from $execLatexCompiler invocation:"
713     outboth "Standard output stream from $execLatexCompiler invocation:"     hlineboth
714     hlineboth     outboth $stdoutoutput
715     outboth $stdoutoutput     hlineboth
716     hlineboth     outboth "Standard error stream from $execLatexCompiler invocation:"
717     outboth "Standard error stream from $execLatexCompiler invocation:"     hlineboth
718     hlineboth     outboth $stderroutput
719     outboth $stderroutput     hlineboth
720     hlineboth  
721       if {$compilefailed} { \
722     if {$compilefailed} { \        outboth "Compile has failed.  Must abort script."
723        outboth "Compile has failed.  Must abort script."        exitProc
724        exitProc        }
725        }  
726       update
727     update     }
728     }  
729    #----------------------------------------------------------------------------------------
730  #----------------------------------------------------------------------------------------  # Runs the MAKEINDEX program for a file located in the root directory of the book.
731  # Runs the MAKEINDEX program for a file located in the root directory of the book.  # File parameter passed is just the "base" file name.
732  # File parameter passed is just the "base" file name.  #
733  #  proc MakeOrdinaryIndexFile { filename } { \
734  proc MakeOrdinaryIndexFile { filename } { \     global execMakeindex
735     global execMakeindex     global errorCode
736     global errorCode  
737       #The error-handling strategy taken in this function is to terminate with a log file
738     #The error-handling strategy taken in this function is to terminate with a log file     #entry if the Makeindex utility chokes.  First of all, generally the LaTeX code is
739     #entry if the Makeindex utility chokes.  First of all, generally the LaTeX code is     #debugged in the 4AllTex GUI, so we shouldn't be compiling bad LaTeX code here.
740     #debugged in the 4AllTex GUI, so we shouldn't be compiling bad LaTeX code here.     #Second, this is a utility script, and not required to be graceful.  Third,
741     #Second, this is a utility script, and not required to be graceful.  Third,     #terminating the program will definitely get the user's attention, whereas any
742     #terminating the program will definitely get the user's attention, whereas any     #lesser approach might not.
743     #lesser approach might not.     outbothnonl "Using MAKEINDEX to process: $filename"
744     outbothnonl "Using MAKEINDEX to process: $filename"     outboth .
745     outboth .     hlineboth
746     hlineboth  
747       #The full path to the MAKEINDEX utility has already been calculated for us at
748     #The full path to the MAKEINDEX utility has already been calculated for us at     #script startup.
749     #script startup.  
750       #Delete existing intermediate files if they exist.
751     #Delete existing intermediate files if they exist.     file delete tcl00out.txt
752     file delete tcl00out.txt     file delete tcl00err.txt
753     file delete tcl00err.txt                
754                     #Open the intermediate files for writing.
755     #Open the intermediate files for writing.     set stdouthandle [open "tcl00out.txt" "w"]
756     set stdouthandle [open "tcl00out.txt" "w"]     set stderrhandle [open "tcl00err.txt" "w"]
757     set stderrhandle [open "tcl00err.txt" "w"]  
758       #Execute exec and suppress errors.
759     #Execute exec and suppress errors.     set catchreturncode 0
760     set catchreturncode 0     set catchreturncode [catch {exec -- $execMakeindex $filename >@ $stdouthandle 2>@ $stderrhandle}]
761     set catchreturncode [catch {exec -- $execMakeindex $filename >@ $stdouthandle 2>@ $stderrhandle}]     set catcherrorcode $errorCode
762     set catcherrorcode $errorCode  
763       #Close both open files.
764     #Close both open files.     close $stderrhandle
765     close $stderrhandle     close $stdouthandle
766     close $stdouthandle          
767               if {$catchreturncode} {
768     if {$catchreturncode} {        outbothnonl "$execMakeindex generated errors (information follows): $catchreturncode $catcherrorcode"
769        outbothnonl "$execMakeindex generated errors (information follows): $catchreturncode $catcherrorcode"        outboth "."
770        outboth "."        outboth "The build must be aborted."
771        outboth "The build must be aborted."        set compilefailed 1
772        set compilefailed 1        hlineboth
773        hlineboth        } \
774        } \     else {
775     else {        outboth "$execMakeindex did not generate errors."
776        outboth "$execMakeindex did not generate errors."        set compilefailed 0
777        set compilefailed 0        hlineboth
778        hlineboth        }
779        }  
780       set stdouthandle [open "tcl00out.txt" "r"]
781     set stdouthandle [open "tcl00out.txt" "r"]     set stderrhandle [open "tcl00err.txt" "r"]
782     set stderrhandle [open "tcl00err.txt" "r"]     set stdoutoutput [read $stdouthandle]
783     set stdoutoutput [read $stdouthandle]     set stderroutput [read $stderrhandle]
784     set stderroutput [read $stderrhandle]     close $stdouthandle
785     close $stdouthandle     close $stderrhandle
786     close $stderrhandle  
787       #Delete existing intermediate files if they exist.
788     #Delete existing intermediate files if they exist.     file delete tcl00out.txt
789     file delete tcl00out.txt     file delete tcl00err.txt
790     file delete tcl00err.txt          
791               outboth "Standard output stream from $execMakeindex invocation:"
792     outboth "Standard output stream from $execMakeindex invocation:"     hlineboth
793     hlineboth     outboth $stdoutoutput
794     outboth $stdoutoutput     hlineboth
795     hlineboth     outboth "Standard error stream from $execMakeindex invocation:"
796     outboth "Standard error stream from $execMakeindex invocation:"     hlineboth
797     hlineboth     outboth $stderroutput
798     outboth $stderroutput     hlineboth
799     hlineboth  
800       if {$compilefailed} { \
801     if {$compilefailed} { \        outboth "$execMakeindex has failed.  Must abort script."
802        outboth "$execMakeindex has failed.  Must abort script."        exitProc
803        exitProc        }
804        }  
805       update
806     update     }
807     }  
808    #----------------------------------------------------------------------------------------
809  #----------------------------------------------------------------------------------------  # Runs the DVIPS program to generate postscript output for a file located in the root
810  # Runs the DVIPS program to generate postscript output for a file located in the root  # directory of the book.  File parameter passed is just the "base" file name.
811  # directory of the book.  File parameter passed is just the "base" file name.  #
812  #  proc RunDvipsToGenPsOutput { filename } { \
813  proc RunDvipsToGenPsOutput { filename } { \     global execDvips
814     global execDvips     global errorCode
815     global errorCode     global pathUcBookA
816     global pathUcBookA  
817       #The error-handling strategy taken in this function is to terminate with a log file
818     #The error-handling strategy taken in this function is to terminate with a log file     #entry if the DVIPS utility chokes.  First of all, generally the LaTeX code is
819     #entry if the DVIPS utility chokes.  First of all, generally the LaTeX code is     #debugged in the 4AllTex GUI, so we shouldn't be compiling bad LaTeX code here.
820     #debugged in the 4AllTex GUI, so we shouldn't be compiling bad LaTeX code here.     #Second, this is a utility script, and not required to be graceful.  Third,
821     #Second, this is a utility script, and not required to be graceful.  Third,     #terminating the program will definitely get the user's attention, whereas any
822     #terminating the program will definitely get the user's attention, whereas any     #lesser approach might not.
823     #lesser approach might not.     outbothnonl "Using DVIPS to process: $filename"
824     outbothnonl "Using DVIPS to process: $filename"     outboth .
825     outboth .     hlineboth
826     hlineboth  
827       #The full path to the DVIPS utility has already been calculated for us at
828     #The full path to the DVIPS utility has already been calculated for us at     #script startup.
829     #script startup.  
830       #Delete existing intermediate files if they exist.
831     #Delete existing intermediate files if they exist.     file delete tcl00out.txt
832     file delete tcl00out.txt     file delete tcl00err.txt
833     file delete tcl00err.txt                
834                     #Open the intermediate files for writing.
835     #Open the intermediate files for writing.     set stdouthandle [open "tcl00out.txt" "w"]
836     set stdouthandle [open "tcl00out.txt" "w"]     set stderrhandle [open "tcl00err.txt" "w"]
837     set stderrhandle [open "tcl00err.txt" "w"]  
838       #Generate the full path names of interest.  We need to convert the forward slashes
839     #Generate the full path names of interest.  We need to convert the forward slashes     #in both names to backslashes because DVIPS accepts the file name and opens the file
840     #in both names to backslashes because DVIPS accepts the file name and opens the file     #itself.
841     #itself.     set dvips_input ""
842     set dvips_input ""     append dvips_input $pathUcBookA / $filename .dvi
843     append dvips_input $pathUcBookA / $filename .dvi     set dvips_input [string map {/ \\} $dvips_input]
844     set dvips_input [string map {/ \\} $dvips_input]     set dvips_output ""
845     set dvips_output ""     append dvips_output $pathUcBookA / $filename .ps
846     append dvips_output $pathUcBookA / $filename .ps     set dvips_output [string map {/ \\} $dvips_output]
847     set dvips_output [string map {/ \\} $dvips_output]  
848       #outboth $dvips_input
849     #outboth $dvips_input     #outboth $dvips_output
850     #outboth $dvips_output  
851       #d:\4tex5.0\bin\win32\dvips.exe -P ljfive -o"c:\esrgubka\llr0.ps" "c:\esrgubka\llr0.dvi"
852     #d:\4tex5.0\bin\win32\dvips.exe -P ljfive -o"c:\esrgubka\llr0.ps" "c:\esrgubka\llr0.dvi"  
853       #Execute exec and suppress errors.
854     #Execute exec and suppress errors.     set catchreturncode 0
855     set catchreturncode 0     set catchreturncode [catch {exec -- $execDvips -T 8.5in,11in -o$dvips_output $dvips_input >@ $stdouthandle 2>@ $stderrhandle}]
856     set catchreturncode [catch {exec -- $execDvips -T 8.5in,11in -o$dvips_output $dvips_input >@ $stdouthandle 2>@ $stderrhandle}]     set catcherrorcode $errorCode
857     set catcherrorcode $errorCode  
858       #Close both open files.
859     #Close both open files.     close $stderrhandle
860     close $stderrhandle     close $stdouthandle
861     close $stdouthandle          
862               if {$catchreturncode} {
863     if {$catchreturncode} {        outbothnonl "$execDvips generated errors (information follows): $catchreturncode $catcherrorcode"
864        outbothnonl "$execDvips generated errors (information follows): $catchreturncode $catcherrorcode"        outboth "."
865        outboth "."        outboth "The build must be aborted."
866        outboth "The build must be aborted."        set compilefailed 1
867        set compilefailed 1        hlineboth
868        hlineboth        } \
869        } \     else {
870     else {        outboth "$execDvips did not generate errors."
871        outboth "$execDvips did not generate errors."        set compilefailed 0
872        set compilefailed 0        hlineboth
873        hlineboth        }
874        }  
875       set stdouthandle [open "tcl00out.txt" "r"]
876     set stdouthandle [open "tcl00out.txt" "r"]     set stderrhandle [open "tcl00err.txt" "r"]
877     set stderrhandle [open "tcl00err.txt" "r"]     set stdoutoutput [read $stdouthandle]
878     set stdoutoutput [read $stdouthandle]     set stderroutput [read $stderrhandle]
879     set stderroutput [read $stderrhandle]     close $stdouthandle
880     close $stdouthandle     close $stderrhandle
881     close $stderrhandle  
882       #Delete existing intermediate files if they exist.
883     #Delete existing intermediate files if they exist.     file delete tcl00out.txt
884     file delete tcl00out.txt     file delete tcl00err.txt
885     file delete tcl00err.txt          
886               outboth "Standard output stream from $execDvips invocation:"
887     outboth "Standard output stream from $execDvips invocation:"     hlineboth
888     hlineboth     outboth $stdoutoutput
889     outboth $stdoutoutput     hlineboth
890     hlineboth     outboth "Standard error stream from $execDvips invocation:"
891     outboth "Standard error stream from $execDvips invocation:"     hlineboth
892     hlineboth     outboth $stderroutput
893     outboth $stderroutput     hlineboth
894     hlineboth  
895       if {$compilefailed} { \
896     if {$compilefailed} { \        outboth "$execDvips has failed.  Must abort script."
897        outboth "$execDvips has failed.  Must abort script."        exitProc
898        exitProc        }
899        }  
900       update
901     update     }
902     }  
903    #----------------------------------------------------------------------------------------
904  #----------------------------------------------------------------------------------------  # Modifies a PS file generated by DVIPS to be duplex.  This is done in a very crude way,
905  # Modifies a PS file generated by DVIPS to be duplex.  This is done in a very crude way,  # by inserting PostScript.  It can probably be done more elegantly by using the configuration
906  # by inserting PostScript.  It can probably be done more elegantly by using the configuration  # and startup files of DVIPS
907  # and startup files of DVIPS  #
908  #  proc ModifyPsToDuplex { filebasename } { \
909  proc ModifyPsToDuplex { filebasename } { \     global errorCode
910     global errorCode     global pathUcBookA
911     global pathUcBookA  
912       outbothnonl "Modifying postscript to get duplex form of: $filebasename"
913     outbothnonl "Modifying postscript to get duplex form of: $filebasename"     outboth .
914     outboth .     update
915     update  
916       #Form the full path of both file names.
917     #Form the full path of both file names.     set mod_input  ""
918     set mod_input  ""     set mod_output ""
919     set mod_output ""     append mod_input  $pathUcBookA / $filebasename .ps
920     append mod_input  $pathUcBookA / $filebasename .ps     append mod_output $pathUcBookA / $filebasename _duplex.ps
921     append mod_output $pathUcBookA / $filebasename _duplex.ps  
922       set inhandle  [open $mod_input  "r"]
923     set inhandle  [open $mod_input  "r"]     set outhandle [open $mod_output "w"]
924     set outhandle [open $mod_output "w"]  
925       #Set larger buffers to speed the I/O operations.
926     #Set larger buffers to speed the I/O operations.     fconfigure $inhandle  -buffering full -buffersize 200000
927     fconfigure $inhandle  -buffering full -buffersize 200000     fconfigure $outhandle -buffering full -buffersize 200000
928     fconfigure $outhandle -buffering full -buffersize 200000  
929       set oneshot 0
930     set oneshot 0  
931       while {! [eof $inhandle] } { \
932     while {! [eof $inhandle] } { \        set line [gets $inhandle]
933        set line [gets $inhandle]        puts $outhandle $line
934        puts $outhandle $line  
935          if { ! $oneshot } { \
936        if { ! $oneshot } { \               if { [string match "*DVIPSSource*" $line] } { \
937               if { [string match "*DVIPSSource*" $line] } { \                      puts $outhandle "<< /Duplex true >> setpagedevice"
938                      puts $outhandle "<< /Duplex true >> setpagedevice"                          set oneshot 1
939                          set oneshot 1                      }
940                      }               }
941               }        }
942        }  
943       #Close both open files.
944     #Close both open files.     close $inhandle
945     close $inhandle     close $outhandle
946     close $outhandle  
947       hlineboth
948     hlineboth  
949       update
950     update     }
951     }  
952    
953    #****************************************************************************************
954  #****************************************************************************************  #****************************************************************************************
955  #****************************************************************************************  #****    L A T E X    S O U R C E    F I L E    G E N E R A T I O N    ******************
956  #****    L A T E X    S O U R C E    F I L E    G E N E R A T I O N    ******************  #****************************************************************************************
957  #****************************************************************************************  #****************************************************************************************
958  #****************************************************************************************  #Outputs the file title line of a LaTeX book source file.
959  #Outputs the file title line of a LaTeX book source file.  #
960  #  proc output_title_line { handle filename desc} { \
961  proc output_title_line { handle filename desc} { \     puts $handle "%[string toupper $filename]:  $desc"
962     puts $handle "%[string toupper $filename]:  $desc"     puts $handle "%"
963     puts $handle "%"  
964       set preamble {
965     set preamble {        "%-----------------------------------------------------------------------------------"                   \
966        "%-----------------------------------------------------------------------------------"                   \        "%This is an automatically generated file and not version-controlled.  This file is"                     \
967        "%This is an automatically generated file and not version-controlled.  This file is"                     \        "%generated by the script CP_SCRIPT.TCL."                                                                \
968        "%generated by the script CP_SCRIPT.TCL."                                                                \        "%-----------------------------------------------------------------------------------"                   \
969        "%-----------------------------------------------------------------------------------"                   \        "%"                                                                                                      \
970        "%"                                                                                                      \        }
971        }  
972       for {set i 0} {$i < [llength $preamble]} {incr i} { \
973     for {set i 0} {$i < [llength $preamble]} {incr i} { \        puts $handle [lindex $preamble $i]
974        puts $handle [lindex $preamble $i]        }
975        }     }
976     }  
977    #Outputs the LaTeX document class and package includes.
978  #Outputs the LaTeX document class and package includes.  #
979  #  proc output_doc_class_and_package_includes { handle } { \
980  proc output_doc_class_and_package_includes { handle } { \     set preamble {
981     set preamble {        "\\documentclass[letterpaper,10pt,titlepage]\{custbook\}"                                                \
982        "\\documentclass[letterpaper,10pt,titlepage]\{custbook\}"                                                \        "%"                                                                                                      \
983        "%"                                                                                                      \        "\\pagestyle\{headings\}"                                                                                \
984        "\\pagestyle\{headings\}"                                                                                \        "%"                                                                                                      \
985        "%"                                                                                                      \        "\\usepackage\{amsmath\}"                                                                                \
986        "\\usepackage\{amsmath\}"                                                                                \        "\\usepackage\{amsfonts\}"                                                                               \
987        "\\usepackage\{amsfonts\}"                                                                               \        "\\usepackage\{amssymb\}"                                                                                \
988        "\\usepackage\{amssymb\}"                                                                                \        "\\usepackage[ansinew]\{inputenc\}"                                                                      \
989        "\\usepackage[ansinew]\{inputenc\}"                                                                      \        "\\usepackage[OT1]\{fontenc\}"                                                                           \
990        "\\usepackage[OT1]\{fontenc\}"                                                                           \        "\\usepackage\{graphicx\}"                                                                               \
991        "\\usepackage\{graphicx\}"                                                                               \        "\\usepackage\{makeidx\}"                                                                                \
992        "\\usepackage\{makeidx\}"                                                                                \        "%"                                                                                                      \
993        "%"                                                                                                      \        }
994        }  
995       for {set i 0} {$i < [llength $preamble]} {incr i} { \
996     for {set i 0} {$i < [llength $preamble]} {incr i} { \        puts $handle [lindex $preamble $i]
997        puts $handle [lindex $preamble $i]        }
998        }     }
999     }  
1000    
1001    #Outputs the final matter in both types of volumes.  The "final matter" is the
1002  #Outputs the final matter in both types of volumes.  The "final matter" is the  #stuff after the chapter includes up until but not including final
1003  #stuff after the chapter includes up until but not including final  #file annunciator.
1004  #file annunciator.  #
1005  #  proc output_tex_volume_final_matter { handle } { \
1006  proc output_tex_volume_final_matter { handle } { \     set final_matter {
1007     set final_matter {        "%Glossary Of Terms"                                                                                     \
1008        "%Glossary Of Terms"                                                                                     \        "\\cleardoublepage"                                                                                      \
1009        "\\cleardoublepage"                                                                                      \        "\\addcontentsline\{toc\}\{chapter\}\{Glossary Of Terms\}"                                               \
1010        "\\addcontentsline\{toc\}\{chapter\}\{Glossary Of Terms\}"                                               \        "\\input\{c_glo0/c_glo0\}"                                                                               \
1011        "\\input\{c_glo0/c_glo0\}"                                                                               \        "%"                                                                                                      \
1012        "%"                                                                                                      \        "%Glossary Of Mathematical Notation"                                                                     \
1013        "%Glossary Of Mathematical Notation"                                                                     \        "\\cleardoublepage"                                                                                      \
1014        "\\cleardoublepage"                                                                                      \        "\\addcontentsline\{toc\}\{chapter\}\{Glossary Of Mathematical Notation\}"                               \
1015        "\\addcontentsline\{toc\}\{chapter\}\{Glossary Of Mathematical Notation\}"                               \        "\\input\{c_glo1/c_glo1\}"                                                                               \
1016        "\\input\{c_glo1/c_glo1\}"                                                                               \        "%"                                                                                                      \
1017        "%"                                                                                                      \        "%Bibliography"                                                                                          \
1018        "%Bibliography"                                                                                          \        "\\cleardoublepage"                                                                                      \
1019        "\\cleardoublepage"                                                                                      \        "\\addcontentsline\{toc\}\{chapter\}\{Bibliography\}"                                                    \
1020        "\\addcontentsline\{toc\}\{chapter\}\{Bibliography\}"                                                    \        "\\input\{volshare/workbibl\}"                                                                           \
1021        "\\input\{volshare/workbibl\}"                                                                           \        "%"                                                                                                      \
1022        "%"                                                                                                      \        "%Index Must Be Formed At This Directory Level"                                                          \
1023        "%Index Must Be Formed At This Directory Level"                                                          \        "\\cleardoublepage"                                                                                      \
1024        "\\cleardoublepage"                                                                                      \        "\\addcontentsline\{toc\}\{chapter\}\{Index\}"                                                           \
1025        "\\addcontentsline\{toc\}\{chapter\}\{Index\}"                                                           \        "\\printindex"                                                                                           \
1026        "\\printindex"                                                                                           \        "%"                                                                                                      \
1027        "%"                                                                                                      \        "\\end\{document\}"                                                                                      \
1028        "\\end\{document\}"                                                                                      \        "%"                                                                                                      \
1029        "%"                                                                                                      \        }
1030        }  
1031       for {set i 0} {$i < [llength $final_matter]} {incr i} { \
1032     for {set i 0} {$i < [llength $final_matter]} {incr i} { \        puts $handle [lindex $final_matter $i]
1033        puts $handle [lindex $final_matter $i]        }
1034        }     }
1035     }  
1036    
1037    #Marks the end of a TEX volume file, for aesthetics.
1038  #Marks the end of a TEX volume file, for aesthetics.  proc mark_end_of_tex_volume_files_for_aesthetics { handle filename } { \
1039  proc mark_end_of_tex_volume_files_for_aesthetics { handle filename } { \     puts $handle "%End of file [string toupper $filename]."
1040     puts $handle "%End of file [string toupper $filename]."     }
1041     }  
1042    
1043    #Output code to import the external document labels, used for cross-referencing
1044  #Output code to import the external document labels, used for cross-referencing  #This is a bit tricky because don't want to include ourselves.  This applies
1045  #This is a bit tricky because don't want to include ourselves.  This applies  #to the multi-volume work only.  For the single-volume work, all reference are
1046  #to the multi-volume work only.  For the single-volume work, all reference are  #internal.
1047  #internal.  proc output_external_document_symbol_imports { handle vtag }  { \
1048  proc output_external_document_symbol_imports { handle vtag }  { \     global bookVolumeList
1049     global bookVolumeList     global bookVolumeListStructSize
1050     global bookVolumeListStructSize  
1051       puts $handle "%External document symbol imports.  These imports allow one volume"
1052     puts $handle "%External document symbol imports.  These imports allow one volume"     puts $handle "%to cross-reference to another, and create one large namespace for"
1053     puts $handle "%to cross-reference to another, and create one large namespace for"     puts $handle "%LaTeX symbols."
1054     puts $handle "%LaTeX symbols."  
1055       set N [llength $bookVolumeList]
1056     set N [llength $bookVolumeList]  
1057       #Iterate through the list.  Everything gets output unless
1058     #Iterate through the list.  Everything gets output unless     #it is our tag name.
1059     #it is our tag name.     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
1060     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \
1061        if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \           set iter_vtag [lindex $bookVolumeList $i]
1062           set iter_vtag [lindex $bookVolumeList $i]           if {[string compare $iter_vtag $vtag]} { \
1063           if {[string compare $iter_vtag $vtag]} { \              set lineout \\externaldocument\{$iter_vtag\}
1064              set lineout \\externaldocument\{$iter_vtag\}              puts $handle $lineout
1065              puts $handle $lineout              }
1066              }           }
1067           }        }
1068        }  
1069       puts $handle "%"
1070     puts $handle "%"     }
1071     }  
1072    #Outputs the common things in a document, from the "\makeindex" command
1073  #Outputs the common things in a document, from the "\makeindex" command  #through the "\begin{document}" command.
1074  #through the "\begin{document}" command.  #
1075  #  proc output_common_lines_through_begindoc { handle } { \
1076  proc output_common_lines_through_begindoc { handle } { \     set preamble {
1077     set preamble {        "%Embarrassingly, I've forgotten why \"makeindex\" is necessary ..."                                     \
1078        "%Embarrassingly, I've forgotten why \"makeindex\" is necessary ..."                                     \        "\\makeindex"                                                                                            \
1079        "\\makeindex"                                                                                            \        "%"                                                                                                      \
1080        "%"                                                                                                      \        "%Shared mathematical definitions"                                                                       \
1081        "%Shared mathematical definitions"                                                                       \        "\\input\{volshare/workmdef\}"                                                                           \
1082        "\\input\{volshare/workmdef\}"                                                                           \        "%"                                                                                                      \
1083        "%"                                                                                                      \        "%Hyphenation exceptions"                                                                                \
1084        "%Hyphenation exceptions"                                                                                \        "\\input\{volshare/workhxcp\}"                                                                           \
1085        "\\input\{volshare/workhxcp\}"                                                                           \        "%"                                                                                                      \
1086        "%"                                                                                                      \        "%New environments, etc."                                                                                \
1087        "%New environments, etc."                                                                                \        "\\input\{volshare/worknenv\}"                                                                           \
1088        "\\input\{volshare/worknenv\}"                                                                           \        "%"                                                                                                      \
1089        "%"                                                                                                      \        "\\begin\{document\}"                                                                                    \
1090        "\\begin\{document\}"                                                                                    \        "%"                                                                                                      \
1091        "%"                                                                                                      \        "%Index \"see\" definitions"                                                                             \
1092        "%Index \"see\" definitions"                                                                             \        "\\input\{volshare/workidxs\}"                                                                           \
1093        "\\input\{volshare/workidxs\}"                                                                           \        "%"                                                                                                      \
1094        "%"                                                                                                      \        }
1095        }  
1096       for {set i 0} {$i < [llength $preamble]} {incr i} { \
1097     for {set i 0} {$i < [llength $preamble]} {incr i} { \        puts $handle [lindex $preamble $i]
1098        puts $handle [lindex $preamble $i]        }
1099        }     }
1100     }  
1101    #Outputs multi-volume volume and chapter definitions for a specific
1102  #Outputs multi-volume volume and chapter definitions for a specific  #volume.
1103  #volume.  #
1104  #  #Inputs:
1105  #Inputs:  #  handle : File handle to write to.
1106  #  handle : File handle to write to.  #  vtag   : Volume tag of the volume whose master file is being formed.
1107  #  vtag   : Volume tag of the volume whose master file is being formed.  #  volnum : The ordinal number of the volume, as a decimal integer.
1108  #  volnum : The ordinal number of the volume, as a decimal integer.  #           This is used to create ordinary numbers, roman numbers,
1109  #           This is used to create ordinary numbers, roman numbers,  #           etc.
1110  #           etc.  #  
1111  #    proc output_multi_volume_volume_and_chapter_definitions { handle vtag volnum } { \
1112  proc output_multi_volume_volume_and_chapter_definitions { handle vtag volnum } { \     global bookVolumeList
1113     global bookVolumeList     global bookVolumeListStructSize
1114     global bookVolumeListStructSize     global mcl
1115     global mcl  
1116       #Get the roman-numeral representation of the volume.
1117     #Get the roman-numeral representation of the volume.     set volnum_roman [upper_case_roman_numeral_string $volnum]
1118     set volnum_roman [upper_case_roman_numeral_string $volnum]  
1119       #Get the long title of the volume.
1120     #Get the long title of the volume.     set vol_long_title [get_multi_vol_long_title $vtag]
1121     set vol_long_title [get_multi_vol_long_title $vtag]  
1122       #Output the "current volume" LaTeX commands.
1123     #Output the "current volume" LaTeX commands.     puts $handle "%Constants for the current volume."
1124     puts $handle "%Constants for the current volume."     puts $handle "\\newcommand\\curvolarabic\{$volnum\}"
1125     puts $handle "\\newcommand\\curvolarabic\{$volnum\}"     puts $handle "\\newcommand\\curvolroman\{$volnum_roman\}"
1126     puts $handle "\\newcommand\\curvolroman\{$volnum_roman\}"     puts $handle "\\newcommand\\curvoltitle\{$vol_long_title\}"
1127     puts $handle "\\newcommand\\curvoltitle\{$vol_long_title\}"     puts $handle "\\newcommand\\curvoltitlepagesep\{:  \}"
1128     puts $handle "\\newcommand\\curvoltitlepagesep\{:  \}"     puts $handle "\\newcommand\\curvoltitlepageprefix\{Volume \}"
1129     puts $handle "\\newcommand\\curvoltitlepageprefix\{Volume \}"     puts $handle "%"
1130     puts $handle "%"  
1131       #Output definitions for all volumes.  There is no need to exclude the
1132     #Output definitions for all volumes.  There is no need to exclude the     #current volume, as this could just as well be cited in this framework.
1133     #current volume, as this could just as well be cited in this framework.     puts $handle "%Constants for all volumes."
1134     puts $handle "%Constants for all volumes."     puts $handle "%"
1135     puts $handle "%"     set temp_ordinal_volume_number 0
1136     set temp_ordinal_volume_number 0     set N [llength $bookVolumeList]
1137     set N [llength $bookVolumeList]     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
1138     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        set cur_iter_volume [lindex $bookVolumeList $i]
1139        set cur_iter_volume [lindex $bookVolumeList $i]  
1140          if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \
1141        if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \           incr temp_ordinal_volume_number
1142           incr temp_ordinal_volume_number           puts $handle "%%%% [string toupper [lindex $bookVolumeList $i]]:  Volume $temp_ordinal_volume_number:  [get_multi_vol_long_title [lindex $bookVolumeList $i]] %%%%"
1143           puts $handle "%%%% [string toupper [lindex $bookVolumeList $i]]:  Volume $temp_ordinal_volume_number:  [get_multi_vol_long_title [lindex $bookVolumeList $i]] %%%%"           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]arabic\{$temp_ordinal_volume_number\}"
1144           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]arabic\{$temp_ordinal_volume_number\}"           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]roman\{[upper_case_roman_numeral_string $temp_ordinal_volume_number]\}"
1145           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]roman\{[upper_case_roman_numeral_string $temp_ordinal_volume_number]\}"           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]title\{[get_multi_vol_long_title [lindex $bookVolumeList $i]]\}"
1146           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]title\{[get_multi_vol_long_title [lindex $bookVolumeList $i]]\}"           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]citecomma\{[string toupper [lindex $bookVolumeList $i]], \}"
1147           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]citecomma\{[string toupper [lindex $bookVolumeList $i]], \}"           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]citehyphen\{[string toupper [lindex $bookVolumeList $i]]-\}"
1148           puts $handle "\\newcommand\\v[replace_digits_with_alphas [lindex $bookVolumeList $i]]citehyphen\{[string toupper [lindex $bookVolumeList $i]]-\}"           puts $handle "%"        
1149           puts $handle "%"          
1150             #Output definitions for all chapters which are enclosed by the current volume.  This is a bit tricky
1151           #Output definitions for all chapters which are enclosed by the current volume.  This is a bit tricky           #because must traverse the mcl table and pick out the right portion.
1152           #because must traverse the mcl table and pick out the right portion.           set state 0
1153           set state 0              #"state" is a state variable which keeps track of where we are parsing the mcl table.
1154              #"state" is a state variable which keeps track of where we are parsing the mcl table.              #State values are as follows:
1155              #State values are as follows:              #  0 -- have not yet found the right volume.
1156              #  0 -- have not yet found the right volume.              #  1 -- are in the midst of the right volume.
1157              #  1 -- are in the midst of the right volume.              #  2 -- are into subsequent volumes.
1158              #  2 -- are into subsequent volumes.  
1159             set cur_vol ""
1160           set cur_vol ""           set chapter_or_appendix ""
1161           set chapter_or_appendix ""  
1162             for {set j 0} {$j < [llength $mcl]} {incr j 4} { \
1163           for {set j 0} {$j < [llength $mcl]} {incr j 4} { \              set rectype [lindex $mcl [expr $j + 0]]
1164              set rectype [lindex $mcl [expr $j + 0]]              set par1    [lindex $mcl [expr $j + 1]]
1165              set par1    [lindex $mcl [expr $j + 1]]              set par2    [lindex $mcl [expr $j + 2]]
1166              set par2    [lindex $mcl [expr $j + 2]]              set par3    [lindex $mcl [expr $j + 3]]
1167              set par3    [lindex $mcl [expr $j + 3]]          
1168                        if {$state == 0} { \
1169              if {$state == 0} { \                 if {! [string compare $rectype v] || ! [string compare $rectype w]} { \
1170                 if {! [string compare $rectype v] || ! [string compare $rectype w]} { \                    #This is a volume record that has meaning for us.  In either case,
1171                    #This is a volume record that has meaning for us.  In either case,                    #the vtag comes from par1.
1172                    #the vtag comes from par1.  
1173                      #Have not yet encountered our volume of interest.  If this is
1174                    #Have not yet encountered our volume of interest.  If this is                    #it, record and change state.
1175                    #it, record and change state.                    if {![string compare $cur_iter_volume $par1]} { \
1176                    if {![string compare $cur_iter_volume $par1]} { \                       set cur_vol $par1
1177                       set cur_vol $par1                       set chapter_or_appendix "Chapter"
1178                       set chapter_or_appendix "Chapter"                       set state 1
1179                       set state 1                       }
1180                       }                    }
1181                    }                 } \
1182                 } \              elseif {$state == 1} { \
1183              elseif {$state == 1} { \                 #We are within the volume of interest.  Looking for chapter records.
1184                 #We are within the volume of interest.  Looking for chapter records.                 if {! [string compare $rectype c] || ! [string compare $rectype e]} { \
1185                 if {! [string compare $rectype c] || ! [string compare $rectype e]} { \                    set cur_chap_lc $par1
1186                    set cur_chap_lc $par1                    set cur_chap_uc [string toupper $cur_chap_lc]
1187                    set cur_chap_uc [string toupper $cur_chap_lc]                    set cur_chap_idstring [replace_digits_with_alphas $cur_chap_lc]
1188                    set cur_chap_idstring [replace_digits_with_alphas $cur_chap_lc]                    set cur_chap_short_title [get_chap_short_single_volume_title $cur_chap_lc]
1189                    set cur_chap_short_title [get_chap_short_single_volume_title $cur_chap_lc]                    set cur_chap_long_title [get_chap_long_single_volume_title $cur_chap_lc]
1190                    set cur_chap_long_title [get_chap_long_single_volume_title $cur_chap_lc]                    set cur_chap_vol_arabic $temp_ordinal_volume_number
1191                    set cur_chap_vol_arabic $temp_ordinal_volume_number                    set cur_chap_vol_roman [upper_case_roman_numeral_string $temp_ordinal_volume_number]
1192                    set cur_chap_vol_roman [upper_case_roman_numeral_string $temp_ordinal_volume_number]                    set cur_chap_vol_title [get_multi_vol_long_title [lindex $bookVolumeList $i]]
1193                    set cur_chap_vol_title [get_multi_vol_long_title [lindex $bookVolumeList $i]]  
1194                      puts $handle "%%%% Chapter C$cur_chap_uc:  $cur_chap_long_title %%%%"
1195                    puts $handle "%%%% Chapter C$cur_chap_uc:  $cur_chap_long_title %%%%"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1196                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "volarabic\{$cur_chap_vol_arabic\}"
1197                    puts $handle "volarabic\{$cur_chap_vol_arabic\}"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1198                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "volroman\{$cur_chap_vol_roman\}"
1199                    puts $handle "volroman\{$cur_chap_vol_roman\}"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1200                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "voltitle\{$cur_chap_vol_title\}"
1201                    puts $handle "voltitle\{$cur_chap_vol_title\}"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1202                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "shorttitle\{$cur_chap_short_title\}"
1203                    puts $handle "shorttitle\{$cur_chap_short_title\}"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1204                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "title\{$cur_chap_long_title\}"
1205                    puts $handle "title\{$cur_chap_long_title\}"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1206                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "longtitle\{$cur_chap_long_title\}"
1207                    puts $handle "longtitle\{$cur_chap_long_title\}"  
1208                      puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1209                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"  
1210                      #For the cite, there are two cases to cover.  If the chapter is in the
1211                    #For the cite, there are two cases to cover.  If the chapter is in the                    #volume we're doing, the cite is the empty string.  Otherwise, it
1212                    #volume we're doing, the cite is the empty string.  Otherwise, it                    #is the volume tag.
1213                    #is the volume tag.                    if {![string compare $vtag $cur_iter_volume]} { \
1214                    if {![string compare $vtag $cur_iter_volume]} { \                       set cur_chap_xref_cite ""
1215                       set cur_chap_xref_cite ""                       } \
1216                       } \                    else {
1217                    else {                       set cur_chap_xref_cite "[string toupper [lindex $bookVolumeList $i]]"
1218                       set cur_chap_xref_cite "[string toupper [lindex $bookVolumeList $i]]"                       }
1219                       }  
1220                      if {[string length $cur_chap_xref_cite]} { \
1221                    if {[string length $cur_chap_xref_cite]} { \                       puts $handle "xrefhyphen\{$cur_chap_xref_cite-\}"
1222                       puts $handle "xrefhyphen\{$cur_chap_xref_cite-\}"                                       } \
1223                                       } \                                    else {
1224                                    else {                       puts $handle "xrefhyphen\{\}"
1225                       puts $handle "xrefhyphen\{\}"                                       }
1226                                       }  
1227                      puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1228                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"  
1229                      if {[string length $cur_chap_xref_cite]} { \
1230                    if {[string length $cur_chap_xref_cite]} { \                       puts $handle "xrefcomma\{$cur_chap_xref_cite, \}"
1231                       puts $handle "xrefcomma\{$cur_chap_xref_cite, \}"                                       } \
1232                                       } \                                    else {
1233                                    else {                       puts $handle "xrefcomma\{\}"
1234                       puts $handle "xrefcomma\{\}"                                       }
1235                                       }  
1236                      puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1237                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "mcclass\{$chapter_or_appendix\}"
1238                    puts $handle "mcclass\{$chapter_or_appendix\}"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1239                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "ucclass\{[string toupper $chapter_or_appendix]\}"
1240                    puts $handle "ucclass\{[string toupper $chapter_or_appendix]\}"                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"
1241                    puts -nonewline $handle "\\newcommand\\c$cur_chap_idstring"                    puts $handle "lcclass\{[string tolower $chapter_or_appendix]\}"
1242                    puts $handle "lcclass\{[string tolower $chapter_or_appendix]\}"                    puts $handle "%"
1243                    puts $handle "%"                    } \
1244                    } \                 elseif {! [string compare $rectype y]} { \
1245                 elseif {! [string compare $rectype y]} { \                    #This is the beginning of the appendix material for a multi-volume work.
1246                    #This is the beginning of the appendix material for a multi-volume work.                    set chapter_or_appendix "Appendix"
1247                    set chapter_or_appendix "Appendix"                    } \
1248                    } \                 elseif {! [string compare $rectype v] || ! [string compare $rectype w]} { \
1249                 elseif {! [string compare $rectype v] || ! [string compare $rectype w]} { \                    set state 2
1250                    set state 2                    }
1251                    }                 } \
1252                 } \              elseif {$state == 2} { \
1253              elseif {$state == 2} { \                 #Do nothing.  We are in the parsing state where we have done the volume of interest
1254                 #Do nothing.  We are in the parsing state where we have done the volume of interest                 #and can't do more.
1255                 #and can't do more.                 } \
1256                 } \              else {
1257              else {                 error "Bad state variable."
1258                 error "Bad state variable."                 }
1259                 }              }
1260              }           }
1261           }        }
1262        }     }
1263     }  
1264    
1265    #Outputs the matter between the volume and chapter definitions and
1266  #Outputs the matter between the volume and chapter definitions and  #the chapters.
1267  #the chapters.  proc output_matter_between_chapter_defs_and_chapters { handle vtag script_vcinfo sv_or_mv} { \
1268  proc output_matter_between_chapter_defs_and_chapters { handle vtag script_vcinfo sv_or_mv} { \     puts $handle "%Title page(s)"
1269     puts $handle "%Title page(s)"     puts $handle "\\input\{volshare/workttla\}"
1270     puts $handle "\\input\{volshare/workttla\}"     puts $handle "%"
1271     puts $handle "%"     puts $handle "\\vspace\{-0.45in\}"
1272     puts $handle "\\vspace\{-0.45in\}"     puts $handle "%"
1273     puts $handle "%"     puts $handle "%Version control information for this script."
1274     puts $handle "%Version control information for this script."     puts $handle "\\noindent\\begin\{minipage\}\{\\textwidth\}"
1275     puts $handle "\\noindent\\begin\{minipage\}\{\\textwidth\}"     puts $handle "\\noindent\\rule\[-0.25in\]\{\\textwidth\}\{1pt\}"
1276     puts $handle "\\noindent\\rule\[-0.25in\]\{\\textwidth\}\{1pt\}"     puts $handle "\\begin\{tiny\}"
1277     puts $handle "\\begin\{tiny\}"     puts $handle "\\begin\{verbatim\}"
1278     puts $handle "\\begin\{verbatim\}"     puts -nonewline $handle $script_vcinfo
1279     puts -nonewline $handle $script_vcinfo     puts $handle "\\end\{verbatim\}"
1280     puts $handle "\\end\{verbatim\}"     puts $handle "\\end\{tiny\}"
1281     puts $handle "\\end\{tiny\}"     puts $handle "\\noindent\\rule\[0.25in\]\{\\textwidth\}\{1pt\}"
1282     puts $handle "\\noindent\\rule\[0.25in\]\{\\textwidth\}\{1pt\}"     puts $handle "\\end\{minipage\}"
1283     puts $handle "\\end\{minipage\}"     puts $handle "%"
1284     puts $handle "%"     puts $handle "%Declare this as frontmatter, the front portion before the meat"
1285     puts $handle "%Declare this as frontmatter, the front portion before the meat"     puts $handle "%of the book."
1286     puts $handle "%of the book."     puts $handle "\\frontmatter\{\}"
1287     puts $handle "\\frontmatter\{\}"     puts $handle "%"
1288     puts $handle "%"     puts $handle "%Preface"
1289     puts $handle "%Preface"  
1290       copy_preface_to_stream $handle $sv_or_mv
1291     copy_preface_to_stream $handle $sv_or_mv  
1292       puts $handle "%"
1293     puts $handle "%"     puts $handle "%Acknowledgements"
1294     puts $handle "%Acknowledgements"     puts $handle "\\input\{volshare/workacks\}"
1295     puts $handle "\\input\{volshare/workacks\}"     puts $handle "%"
1296     puts $handle "%"     puts $handle "%Table of contents"
1297     puts $handle "%Table of contents"     puts $handle "\\tableofcontents"
1298     puts $handle "\\tableofcontents"     puts $handle "%"
1299     puts $handle "%"     puts $handle "%List of tables"
1300     puts $handle "%List of tables"     puts $handle "\\listoftables"
1301     puts $handle "\\listoftables"     puts $handle "%"
1302     puts $handle "%"     puts $handle "%List of figures"
1303     puts $handle "%List of figures"     puts $handle "\\listoffigures"
1304     puts $handle "\\listoffigures"     puts $handle "%"
1305     puts $handle "%"     puts $handle "%List of algorithms"
1306     puts $handle "%List of algorithms"     puts $handle "\\listofalgorithms"
1307     puts $handle "\\listofalgorithms"     puts $handle "%"
1308     puts $handle "%"     puts $handle "%Everything after this is the main matter, the \"meat\""
1309     puts $handle "%Everything after this is the main matter, the \"meat\""     puts $handle "%of the book."
1310     puts $handle "%of the book."     puts $handle "\\mainmatter\{\}"
1311     puts $handle "\\mainmatter\{\}"     puts $handle "%"
1312     puts $handle "%"     }
1313     }  
1314    #Copies the contents of the preface to the master file being formed.  To accomodate
1315  #Copies the contents of the preface to the master file being formed.  To accomodate  #single-volume versus multi-volume builds, the two tags "<sv>" and "<mv>", which
1316  #single-volume versus multi-volume builds, the two tags "<sv>" and "<mv>", which  #must occur starting in column 1, are supported.  These two tags indicate that the
1317  #must occur starting in column 1, are supported.  These two tags indicate that the  #line goes only to the single-volume build or the multi-volume build files.
1318  #line goes only to the single-volume build or the multi-volume build files.  #The paramter sv or mv must be "s" or "m" for single or multi.
1319  #The paramter sv or mv must be "s" or "m" for single or multi.  #
1320  #  proc copy_preface_to_stream { handle sv_or_mv } { \
1321  proc copy_preface_to_stream { handle sv_or_mv } { \     #Set the compare tag based on the input parameter.
1322     #Set the compare tag based on the input parameter.     if {![string compare $sv_or_mv "s"]} { \
1323     if {![string compare $sv_or_mv "s"]} { \        set compare_tag "<sv>"
1324        set compare_tag "<sv>"        } \
1325        } \     elseif {![string compare $sv_or_mv "m"]} {
1326     elseif {![string compare $sv_or_mv "m"]} {        set compare_tag "<mv>"
1327        set compare_tag "<mv>"        } \
1328        } \     else {
1329     else {        error
1330        error        }
1331        }  
1332       #Open the preface for processing.
1333     #Open the preface for processing.     set phandle [open volshare/workprfa.tex r]
1334     set phandle [open volshare/workprfa.tex r]  
1335       #For each line, just copy it in, discarding lines with the wrong tag.
1336     #For each line, just copy it in, discarding lines with the wrong tag.     set eof_found 0
1337     set eof_found 0     while {!$eof_found} { \
1338     while {!$eof_found} { \        #Grab a line.
1339        #Grab a line.        set line_in [gets $phandle]
1340        set line_in [gets $phandle]  
1341          #Set a boolean if it contains a tag of any sort.  Remove the tag from the line.
1342        #Set a boolean if it contains a tag of any sort.  Remove the tag from the line.        set tag ""
1343        set tag ""        set tag_found 0
1344        set tag_found 0        set sf_result_1 [string first "<" $line_in]
1345        set sf_result_1 [string first "<" $line_in]        set sf_result_2 [string first ">" $line_in]
1346        set sf_result_2 [string first ">" $line_in]        set sf_result_3 [string first $compare_tag $line_in]
1347        set sf_result_3 [string first $compare_tag $line_in]        if {( $sf_result_1 == 0 ) && ( $sf_result_2 == 3 ) } { \
1348        if {( $sf_result_1 == 0 ) && ( $sf_result_2 == 3 ) } { \           set tag_found 1
1349           set tag_found 1           }
1350           }  
1351          if {$tag_found && ! ($sf_result_3 == 0)} { \
1352        if {$tag_found && ! ($sf_result_3 == 0)} { \           #There was a tag, but it is not for us.  Discard the line.
1353           #There was a tag, but it is not for us.  Discard the line.           } \
1354           } \        elseif {$tag_found && ($sf_result_3 == 0)} {
1355        elseif {$tag_found && ($sf_result_3 == 0)} {           #The tag was found, and it is for us.  Remove the tag from the line and
1356           #The tag was found, and it is for us.  Remove the tag from the line and           #put the line to the output.
1357           #put the line to the output.           set line_in [string range $line_in 4 end]
1358           set line_in [string range $line_in 4 end]           puts $handle $line_in
1359           puts $handle $line_in           } \
1360           } \        else {
1361        else {           #There was no tag found.  Just pass the line through.
1362           #There was no tag found.  Just pass the line through.           puts $handle $line_in
1363           puts $handle $line_in           }
1364           }  
1365          set eof_found [eof $phandle]      
1366        set eof_found [eof $phandle]              }
1367        }  
1368       #Close the preface, we are done with it.
1369     #Close the preface, we are done with it.     close $phandle
1370     close $phandle     }
1371     }  
1372    
1373    #Outputs the chapter and appendix includes for one volume of a multi-volume work
1374  #Outputs the chapter and appendix includes for one volume of a multi-volume work  #
1375  #  proc output_multi_volume_chapter_and_appendix_includes { handle vtag } { \
1376  proc output_multi_volume_chapter_and_appendix_includes { handle vtag } { \     global mcl
1377     global mcl  
1378       #Output definitions for all chapters which are enclosed by the current volume.  This is a bit tricky
1379     #Output definitions for all chapters which are enclosed by the current volume.  This is a bit tricky     #because must traverse the mcl table and pick out the right portion.
1380     #because must traverse the mcl table and pick out the right portion.     set state 0
1381     set state 0        #"state" is a state variable which keeps track of where we are parsing the mcl table.
1382        #"state" is a state variable which keeps track of where we are parsing the mcl table.        #State values are as follows:
1383        #State values are as follows:        #  0 -- have not yet found the right volume.
1384        #  0 -- have not yet found the right volume.        #  1 -- are in the midst of the right volume.
1385        #  1 -- are in the midst of the right volume.        #  2 -- are into subsequent volumes.
1386        #  2 -- are into subsequent volumes.  
1387       for {set i 0} {$i < [llength $mcl]} {incr i 4} { \
1388     for {set i 0} {$i < [llength $mcl]} {incr i 4} { \        set rectype [lindex $mcl [expr $i + 0]]
1389        set rectype [lindex $mcl [expr $i + 0]]        set par1    [lindex $mcl [expr $i + 1]]
1390        set par1    [lindex $mcl [expr $i + 1]]        set par2    [lindex $mcl [expr $i + 2]]
1391        set par2    [lindex $mcl [expr $i + 2]]        set par3    [lindex $mcl [expr $i + 3]]
1392        set par3    [lindex $mcl [expr $i + 3]]          
1393                  if {$state == 0} { \
1394        if {$state == 0} { \           if {! [string compare $rectype v] || ! [string compare $rectype w]} { \
1395           if {! [string compare $rectype v] || ! [string compare $rectype w]} { \              #This is a volume record that has meaning for us.  In either case,
1396              #This is a volume record that has meaning for us.  In either case,              #the vtag comes from par1.
1397              #the vtag comes from par1.  
1398                #Have not yet encountered our volume of interest.  If this is
1399              #Have not yet encountered our volume of interest.  If this is              #it, record and change state.
1400              #it, record and change state.              if {![string compare $vtag $par1]} { \
1401              if {![string compare $vtag $par1]} { \                 set cur_vol $par1
1402                 set cur_vol $par1                 set chapter_or_appendix "Chapter"
1403                 set chapter_or_appendix "Chapter"                 set state 1
1404                 set state 1                 }
1405                 }              }
1406              }           } \
1407           } \        elseif {$state == 1} { \
1408        elseif {$state == 1} { \           #We are within the volume of interest.  Looking for chapter records.
1409           #We are within the volume of interest.  Looking for chapter records.           if {! [string compare $rectype c] || ! [string compare $rectype e]} { \
1410           if {! [string compare $rectype c] || ! [string compare $rectype e]} { \              set cur_chap_lc $par1
1411              set cur_chap_lc $par1              set cur_chap_uc [string toupper $cur_chap_lc]
1412              set cur_chap_uc [string toupper $cur_chap_lc]              set cur_chap_idstring [replace_digits_with_alphas $cur_chap_lc]
1413              set cur_chap_idstring [replace_digits_with_alphas $cur_chap_lc]              set cur_chap_short_title [get_chap_short_single_volume_title $cur_chap_lc]
1414              set cur_chap_short_title [get_chap_short_single_volume_title $cur_chap_lc]              set cur_chap_long_title [get_chap_long_single_volume_title $cur_chap_lc]
1415              set cur_chap_long_title [get_chap_long_single_volume_title $cur_chap_lc]  
1416                puts $handle "%%%% $chapter_or_appendix C$cur_chap_uc:  $cur_chap_long_title %%%%"
1417              puts $handle "%%%% $chapter_or_appendix C$cur_chap_uc:  $cur_chap_long_title %%%%"              puts $handle "\\input\{c_$cur_chap_lc/c_$cur_chap_lc\}"
1418              puts $handle "\\input\{c_$cur_chap_lc/c_$cur_chap_lc\}"              puts $handle "%"
1419              puts $handle "%"              } \
1420              } \           elseif {! [string compare $rectype y]} { \
1421           elseif {! [string compare $rectype y]} { \              #This is the beginning of the appendix material for a multi-volume work.
1422              #This is the beginning of the appendix material for a multi-volume work.              set chapter_or_appendix "Appendix"
1423              set chapter_or_appendix "Appendix"              puts $handle "\\appendix"
1424              puts $handle "\\appendix"              puts $handle "%"
1425              puts $handle "%"              } \
1426              } \           elseif {! [string compare $rectype v] || ! [string compare $rectype w]} { \
1427           elseif {! [string compare $rectype v] || ! [string compare $rectype w]} { \              set state 2
1428              set state 2              }
1429              }           } \
1430           } \        elseif {$state == 2} { \
1431        elseif {$state == 2} { \           #Do nothing.  We are in the parsing state where we have done the volume of interest
1432           #Do nothing.  We are in the parsing state where we have done the volume of interest           #and can't do more.
1433           #and can't do more.           } \
1434           } \        else {
1435        else {           error "Bad state variable."
1436           error "Bad state variable."           }
1437           }        }
1438        }     }
1439     }  
1440    
1441    #Builds one volume of a multi-volume work, passed the volume tag and the volume
1442  #Builds one volume of a multi-volume work, passed the volume tag and the volume  #number.  The volume number is an ordinal number, and is used for normal
1443  #number.  The volume number is an ordinal number, and is used for normal  #and roman numerals and stuff.
1444  #and roman numerals and stuff.  #
1445  #  proc createMultiVolumeWork { vtag volume_number script_vcinfo } { \
1446  proc createMultiVolumeWork { vtag volume_number script_vcinfo } { \     #Form the filename, based on the input tag.  All that is required is a .TEX
1447     #Form the filename, based on the input tag.  All that is required is a .TEX     #suffix.
1448     #suffix.     set filename $vtag
1449     set filename $vtag     append filename .tex
1450     append filename .tex  
1451       #Open the file for writing.
1452     #Open the file for writing.     set handle [open $filename w]
1453     set handle [open $filename w]  
1454       #Insert the title line.
1455     #Insert the title line.     output_title_line $handle $filename "Volume of multi-volume work."
1456     output_title_line $handle $filename "Volume of multi-volume work."  
1457       #Insert the document class and package includes.
1458     #Insert the document class and package includes.     output_doc_class_and_package_includes $handle
1459     output_doc_class_and_package_includes $handle  
1460       #For the multi-volume only, use the "XR" package.
1461     #For the multi-volume only, use the "XR" package.     puts $handle "%Must use \"xr\" package to import symbols from other volumes."
1462     puts $handle "%Must use \"xr\" package to import symbols from other volumes."     puts $handle "\\usepackage\{xr\}"
1463     puts $handle "\\usepackage\{xr\}"     puts $handle "%"
1464     puts $handle "%"  
1465       #Insert the external document symbol imports.
1466     #Insert the external document symbol imports.     output_external_document_symbol_imports $handle $vtag
1467     output_external_document_symbol_imports $handle $vtag  
1468       #Insert common lines through the begindoc.
1469     #Insert common lines through the begindoc.     output_common_lines_through_begindoc $handle
1470     output_common_lines_through_begindoc $handle  
1471       #Insert the volume and chapter definitions.
1472     #Insert the volume and chapter definitions.     output_multi_volume_volume_and_chapter_definitions $handle $vtag $volume_number
1473     output_multi_volume_volume_and_chapter_definitions $handle $vtag $volume_number  
1474       #Insert the matter after the volume and chapter definitions but before
1475     #Insert the matter after the volume and chapter definitions but before     #the chapters and appendices.
1476     #the chapters and appendices.     output_matter_between_chapter_defs_and_chapters $handle $vtag $script_vcinfo m
1477     output_matter_between_chapter_defs_and_chapters $handle $vtag $script_vcinfo m  
1478       #Insert the chapter and appendix includes.
1479     #Insert the chapter and appendix includes.     output_multi_volume_chapter_and_appendix_includes $handle $vtag
1480     output_multi_volume_chapter_and_appendix_includes $handle $vtag  
1481       #Output the final matter.
1482     #Output the final matter.     output_tex_volume_final_matter $handle
1483     output_tex_volume_final_matter $handle  
1484       #Output the final line of the file, with the file name, for aesthetics.
1485     #Output the final line of the file, with the file name, for aesthetics.     mark_end_of_tex_volume_files_for_aesthetics $handle $filename
1486     mark_end_of_tex_volume_files_for_aesthetics $handle $filename  
1487       #Close the file.
1488     #Close the file.     close $handle
1489     close $handle     }
1490     }  
1491    #
1492  #  # Builds the two single-volume works (the two source files SVF.TEX and SVD.TEX).  These
1493  # Builds the two single-volume works (the two source files SVF.TEX and SVD.TEX).  These  # are quite a bit simpler than the multi-volume generations.
1494  # are quite a bit simpler than the multi-volume generations.  #
1495  #  proc createSingleVolumeWorks { script_vcinfo } { \
1496  proc createSingleVolumeWorks { script_vcinfo } { \     global mcl
1497     global mcl  
1498       #Define the preamble number 1 for both of the files.  This is text up until the chapter
1499     #Define the preamble number 1 for both of the files.  This is text up until the chapter     #definitions.
1500     #definitions.     set preamble1 {
1501     set preamble1 {        "%Definitions For Chapter Citations"                                                                     \
1502        "%Definitions For Chapter Citations"                                                                     \        "%--------------------------------------------------------------"                                        \
1503        "%--------------------------------------------------------------"                                        \        "%These definitions are created automatically by the Wish Script"                                        \
1504        "%These definitions are created automatically by the Wish Script"                                        \        "%\"CP_SCRIPT.TCL\"."                                                                                    \
1505        "%\"CP_SCRIPT.TCL\"."                                                                                    \        "%--------------------------------------------------------------"                                        \
1506        "%--------------------------------------------------------------"                                        \        "%Note that for the single-volume works, there is no concept of"                                         \
1507        "%Note that for the single-volume works, there is no concept of"                                         \        "%the \"xref\" prefix, as everything is in the same volume."                                             \
1508        "%the \"xref\" prefix, as everything is in the same volume."                                             \        "%That is why this prefix is set to the empty string in all"                                             \
1509        "%That is why this prefix is set to the empty string in all"                                             \        "%cases."                                                                                                \
1510        "%cases."                                                                                                \        "%--------------------------------------------------------------"                                        \
1511        "%--------------------------------------------------------------"                                        \        }
1512        }  
1513       #Define the matter between the chapter constants and the start of the version control information
1514     #Define the matter between the chapter constants and the start of the version control information     #for this script.
1515     #for this script.     set midamble1 {
1516     set midamble1 {        "\\newcommand\\curvoltitle\{\Full Edition (All Content)\}"                                               \
1517        "\\newcommand\\curvoltitle\{\Full Edition (All Content)\}"                                               \        "\\newcommand\\curvolroman\{\}"                                                                          \
1518        "\\newcommand\\curvolroman\{\}"                                                                          \        "\\newcommand\\curvoltitlepagesep\{\}"                                                                   \
1519        "\\newcommand\\curvoltitlepagesep\{\}"                                                                   \        "\\newcommand\\curvoltitlepageprefix\{\}"                                                                \
1520        "\\newcommand\\curvoltitlepageprefix\{\}"                                                                \        ""                                                                                                       \
1521        ""                                                                                                       \        }
1522        }  
1523       #Define the matter between the main volume's version control information and the start of the chapter
1524     #Define the matter between the main volume's version control information and the start of the chapter     #includes.
1525     #includes.     set midamble2 {
1526     set midamble2 {        ""                                                                                                       \
1527        ""                                                                                                       \        }
1528        }  
1529       #outboth "Generating single-volume work main TEX source files (SVF.TEX, SVD.TEX)."
1530     #outboth "Generating single-volume work main TEX source files (SVF.TEX, SVD.TEX)."     outboth "Generating single-volume work main TEX source file (SVF.TEX)."
1531     outboth "Generating single-volume work main TEX source file (SVF.TEX)."  
1532       #Open the two files we want to write.
1533     #Open the two files we want to write.     set fhandle [open svf.tex w]
1534     set fhandle [open svf.tex w]  
1535       #Output the title and descriptions for the files.
1536     #Output the title and descriptions for the files.     output_title_line $fhandle SVF.TEX "Final Version Of Single-Volume Work"
1537     output_title_line $fhandle SVF.TEX "Final Version Of Single-Volume Work"  
1538       #Insert the document class and package includes.
1539     #Insert the document class and package includes.     output_doc_class_and_package_includes $fhandle
1540     output_doc_class_and_package_includes $fhandle  
1541       #Output common things through "begindoc"
1542     #Output common things through "begindoc"     output_common_lines_through_begindoc $fhandle
1543     output_common_lines_through_begindoc $fhandle  
1544       #Output the first preamble to the files.
1545     #Output the first preamble to the files.     for {set i 0} {$i < [llength $preamble1]} {incr i} { \
1546     for {set i 0} {$i < [llength $preamble1]} {incr i} { \        #puts $dhandle [lindex $preamble1 $i]
1547        #puts $dhandle [lindex $preamble1 $i]        puts $fhandle [lindex $preamble1 $i]
1548        puts $fhandle [lindex $preamble1 $i]        }
1549        }  
1550       #Remembers whether the fundamental unit (the chapter) is a chapter or an
1551     #Remembers whether the fundamental unit (the chapter) is a chapter or an     #appendix.  After the LaTeX "appendix" mark, everything gets numbered as
1552     #appendix.  After the LaTeX "appendix" mark, everything gets numbered as     #an appendix (A, B, C, etc.).  This is included because if one Chapter or
1553     #an appendix (A, B, C, etc.).  This is included because if one Chapter or     #Appendix needs to refer to another one symbolically (or to itself for that
1554     #Appendix needs to refer to another one symbolically (or to itself for that     #matter) it needs to know if it is a chapter or appendix.  This preserves
1555     #matter) it needs to know if it is a chapter or appendix.  This preserves     #the ability to have something be an appendix in one compilation and a chapter
1556     #the ability to have something be an appendix in one compilation and a chapter     #in another compilation.
1557     #in another compilation.     set chapter_or_appendix Chapter
1558     set chapter_or_appendix Chapter  
1559       #Output the chapter citations for the files.  The chapter citations are how one
1560     #Output the chapter citations for the files.  The chapter citations are how one     #chapter refers to another.  For the "single-volume" works, there is no concept
1561     #chapter refers to another.  For the "single-volume" works, there is no concept     #of volume (there is only one), so the cites are just straight chapter cites.
1562     #of volume (there is only one), so the cites are just straight chapter cites.     for {set i 0} {$i < [llength $mcl]} {incr i 4} { \
1563     for {set i 0} {$i < [llength $mcl]} {incr i 4} { \        set rectype [lindex $mcl $i]
1564        set rectype [lindex $mcl $i]          
1565                  if {! [string compare $rectype d] || ! [string compare $rectype e]} { \
1566        if {! [string compare $rectype d] || ! [string compare $rectype e]} { \           #This is a chapter record that we need to be concerned with.
1567           #This is a chapter record that we need to be concerned with.                
1568                           #Get the chapter tag.
1569           #Get the chapter tag.           set ctag [lindex $mcl [expr $i + 1]]
1570           set ctag [lindex $mcl [expr $i + 1]]  
1571             #Output a header line to both files indicating which chapter.
1572           #Output a header line to both files indicating which chapter.           #puts -nonewline $dhandle %C
1573           #puts -nonewline $dhandle %C           puts -nonewline $fhandle %C
1574           puts -nonewline $fhandle %C           set ucctag [string toupper $ctag]
1575           set ucctag [string toupper $ctag]           #puts -nonewline $dhandle $ucctag
1576           #puts -nonewline $dhandle $ucctag           puts -nonewline $fhandle $ucctag
1577           puts -nonewline $fhandle $ucctag           #puts -nonewline $dhandle ": "
1578           #puts -nonewline $dhandle ": "           puts -nonewline $fhandle ": "
1579           puts -nonewline $fhandle ": "           #puts $dhandle [get_chap_long_single_volume_title $ctag]
1580           #puts $dhandle [get_chap_long_single_volume_title $ctag]           puts $fhandle [get_chap_long_single_volume_title $ctag]
1581           puts $fhandle [get_chap_long_single_volume_title $ctag]                    
1582                               #Output the data for the chapter, as LaTeX commands.
1583           #Output the data for the chapter, as LaTeX commands.           set textag [replace_digits_with_alphas $ctag]
1584           set textag [replace_digits_with_alphas $ctag]  
1585             #xref command.  This is how one chapter refers to another (the
1586           #xref command.  This is how one chapter refers to another (the           #prefix).  Set constant empty here, because no prefix required.
1587           #prefix).  Set constant empty here, because no prefix required.           set linebuf ""
1588           set linebuf ""           append linebuf \\newcommand \\ c $textag xrefhyphen \{ \}
1589           append linebuf \\newcommand \\ c $textag xrefhyphen \{ \}           #puts $dhandle $linebuf
1590           #puts $dhandle $linebuf           puts $fhandle $linebuf
1591           puts $fhandle $linebuf           set linebuf ""
1592           set linebuf ""           append linebuf \\newcommand \\ c $textag xrefcomma \{ \}
1593           append linebuf \\newcommand \\ c $textag xrefcomma \{ \}           #puts $dhandle $linebuf
1594           #puts $dhandle $linebuf           puts $fhandle $linebuf
1595           puts $fhandle $linebuf  
1596             #Long title.  This is normally used for the chapter unless there
1597           #Long title.  This is normally used for the chapter unless there           #are space constraints, such as would occur on page headers.
1598           #are space constraints, such as would occur on page headers.           set linebuf ""
1599           set linebuf ""           append linebuf \\newcommand \\ c $textag longtitle \{ [get_chap_long_single_volume_title $ctag] \}
1600           append linebuf \\newcommand \\ c $textag longtitle \{ [get_chap_long_single_volume_title $ctag] \}           #puts $dhandle $linebuf
1601           #puts $dhandle $linebuf           puts $fhandle $linebuf
1602           puts $fhandle $linebuf  
1603             #Title (same as long title).
1604           #Title (same as long title).           set linebuf ""
1605           set linebuf ""           append linebuf \\newcommand \\ c $textag title \{ [get_chap_long_single_volume_title $ctag] \}
1606           append linebuf \\newcommand \\ c $textag title \{ [get_chap_long_single_volume_title $ctag] \}           #puts $dhandle $linebuf
1607           #puts $dhandle $linebuf           puts $fhandle $linebuf
1608           puts $fhandle $linebuf          
1609                     #Short title.  This is used in confined areas, such as on page headers.
1610           #Short title.  This is used in confined areas, such as on page headers.           set linebuf ""
1611           set linebuf ""           append linebuf \\newcommand \\ c $textag shorttitle \{ [get_chap_short_single_volume_title $ctag] \}
1612           append linebuf \\newcommand \\ c $textag shorttitle \{ [get_chap_short_single_volume_title $ctag] \}           #puts $dhandle $linebuf
1613           #puts $dhandle $linebuf           puts $fhandle $linebuf
1614           puts $fhandle $linebuf  
1615             #Fill in the "Class", whether this is a chapter or an appendix.
1616           #Fill in the "Class", whether this is a chapter or an appendix.           set linebuf ""
1617           set linebuf ""           append linebuf \\newcommand \\ c $textag mcclass \{ $chapter_or_appendix \}
1618           append linebuf \\newcommand \\ c $textag mcclass \{ $chapter_or_appendix \}           puts $fhandle $linebuf
1619           puts $fhandle $linebuf           set linebuf ""
1620           set linebuf ""           append linebuf \\newcommand \\ c $textag ucclass \{ [string toupper $chapter_or_appendix] \}
1621           append linebuf \\newcommand \\ c $textag ucclass \{ [string toupper $chapter_or_appendix] \}           puts $fhandle $linebuf
1622           puts $fhandle $linebuf           set linebuf ""
1623           set linebuf ""           append linebuf \\newcommand \\ c $textag lcclass \{ [string tolower $chapter_or_appendix] \}
1624           append linebuf \\newcommand \\ c $textag lcclass \{ [string tolower $chapter_or_appendix] \}           puts $fhandle $linebuf
1625           puts $fhandle $linebuf  
1626             #Put in a blank line for aesthetics
1627           #Put in a blank line for aesthetics           #puts $dhandle ""
1628           #puts $dhandle ""           puts $fhandle ""
1629           puts $fhandle ""           } \
1630           } \        elseif {! [string compare $rectype z]} {
1631        elseif {! [string compare $rectype z]} {           #This tag indicates the location of the beginning of the appendices.  We
1632           #This tag indicates the location of the beginning of the appendices.  We           #need to switch from chapter to appendix.
1633           #need to switch from chapter to appendix.           set chapter_or_appendix Appendix
1634           set chapter_or_appendix Appendix           }
1635           }        }
1636        }  
1637       #Put in the "midamble" before the version control information.
1638     #Put in the "midamble" before the version control information.     for {set i 0} {$i < [llength $midamble1]} {incr i} { \
1639     for {set i 0} {$i < [llength $midamble1]} {incr i} { \        #puts $dhandle [lindex $midamble1 $i]
1640        #puts $dhandle [lindex $midamble1 $i]        puts $fhandle [lindex $midamble1 $i]
1641        puts $fhandle [lindex $midamble1 $i]        }
1642        }  
1643       #Put in matter including title page and version control information.
1644     #Put in matter including title page and version control information.     output_matter_between_chapter_defs_and_chapters $fhandle "" $script_vcinfo s
1645     output_matter_between_chapter_defs_and_chapters $fhandle "" $script_vcinfo s  
1646       #Put in the "midamble" until the chapter includes.
1647     #Put in the "midamble" until the chapter includes.     for {set i 0} {$i < [llength $midamble2]} {incr i} { \
1648     for {set i 0} {$i < [llength $midamble2]} {incr i} { \        #puts $dhandle [lindex $midamble2 $i]
1649        #puts $dhandle [lindex $midamble2 $i]        puts $fhandle [lindex $midamble2 $i]
1650        puts $fhandle [lindex $midamble2 $i]        }
1651        }  
1652       #Put in the chapter includes.  This will involve looping through the mcl table and
1653     #Put in the chapter includes.  This will involve looping through the mcl table and     #inserting things.  There is a differentiation between draft chapters and non-draft
1654     #inserting things.  There is a differentiation between draft chapters and non-draft     #chapters.
1655     #chapters.     set chapter_or_appendix Chapter
1656     set chapter_or_appendix Chapter     for {set i 0} {$i < [llength $mcl]} {incr i 4} { \
1657     for {set i 0} {$i < [llength $mcl]} {incr i 4} { \        set rectype [lindex $mcl $i]
1658        set rectype [lindex $mcl $i]          
1659                  if {! [string compare $rectype d] || ! [string compare $rectype e]} { \
1660        if {! [string compare $rectype d] || ! [string compare $rectype e]} { \           #This is a chapter record that we need to be concerned with.
1661           #This is a chapter record that we need to be concerned with.           #Can easily form the file name by a simple string concat with the
1662           #Can easily form the file name by a simple string concat with the           #tag.  For aesthetics, will also throw in the title.
1663           #tag.  For aesthetics, will also throw in the title.           set ctag [lindex $mcl [expr $i + 1]]
1664           set ctag [lindex $mcl [expr $i + 1]]           set ctitle [get_chap_long_single_volume_title $ctag]
1665           set ctitle [get_chap_long_single_volume_title $ctag]  
1666             set line1 "%$chapter_or_appendix:  $ctitle"
1667           set line1 "%$chapter_or_appendix:  $ctitle"           set line2 ""
1668           set line2 ""           append line2 \\input\{c_ $ctag /c_ $ctag \}
1669           append line2 \\input\{c_ $ctag /c_ $ctag \}  
1670             #puts $dhandle $line1
1671           #puts $dhandle $line1           puts $fhandle $line1
1672           puts $fhandle $line1           #puts $dhandle $line2
1673           #puts $dhandle $line2           puts $fhandle $line2
1674           puts $fhandle $line2           #puts $dhandle ""
1675           #puts $dhandle ""           puts $fhandle ""
1676           puts $fhandle ""           } \
1677           } \        elseif {! [string compare $rectype p] || ! [string compare $rectype w]} {
1678        elseif {! [string compare $rectype p] || ! [string compare $rectype w]} {           #This indicates that we need to spin a new part in the book.  There are
1679           #This indicates that we need to spin a new part in the book.  There are           #two cases to consider.  Either we yank the title from the volume information,
1680           #two cases to consider.  Either we yank the title from the volume information,           #or else we yank the title from the par2 of the record.  Set the title.
1681           #or else we yank the title from the par2 of the record.  Set the title.           set par1 [lindex $mcl [expr $i + 1]]
1682           set par1 [lindex $mcl [expr $i + 1]]           set par2 [lindex $mcl [expr $i + 2]]
1683           set par2 [lindex $mcl [expr $i + 2]]  
1684             if {[string length $par2]} { \
1685           if {[string length $par2]} { \              set part_title $par2
1686              set part_title $par2              } \
1687              } \           else {
1688           else {              set part_title [get_vol_part_title $par1]
1689              set part_title [get_vol_part_title $par1]              }
1690              }  
1691             #We have the part title.  Output the part record.
1692           #We have the part title.  Output the part record.           set line1 "% New part: $part_title"
1693           set line1 "% New part: $part_title"           set line2 "\\part\{$part_title\}"
1694           set line2 "\\part\{$part_title\}"           #puts $dhandle $line1
1695           #puts $dhandle $line1           puts $fhandle $line1
1696           puts $fhandle $line1           #puts $dhandle $line2
1697           #puts $dhandle $line2           puts $fhandle $line2
1698           puts $fhandle $line2           #puts $dhandle ""
1699           #puts $dhandle ""           puts $fhandle ""
1700           puts $fhandle ""           } \
1701           } \        elseif {! [string compare $rectype z]} {
1702        elseif {! [string compare $rectype z]} {           #This tag indicates the location of the beginning of the appendices.  We
1703           #This tag indicates the location of the beginning of the appendices.  We           #need to switch from chapter to appendix.
1704           #need to switch from chapter to appendix.           set chapter_or_appendix Appendix
1705           set chapter_or_appendix Appendix  
1706             #Also need to decorate the output files to reflect that we're going into
1707           #Also need to decorate the output files to reflect that we're going into           #appendix mode.
1708           #appendix mode.           set appendix_mark {
1709           set appendix_mark {              "%Mark the start of appendices.  This causes numbering to be with letters"                         \
1710              "%Mark the start of appendices.  This causes numbering to be with letters"                         \              "%instead of numbers."                                                                             \
1711              "%instead of numbers."                                                                             \              "\\appendix"                                                                                       \
1712              "\\appendix"                                                                                       \              ""                                                                                                 \
1713              ""                                                                                                 \              }
1714              }           for {set j 0} {$j < [llength $appendix_mark]} {incr j} { \
1715           for {set j 0} {$j < [llength $appendix_mark]} {incr j} { \              #puts $dhandle [lindex $appendix_mark $j]
1716              #puts $dhandle [lindex $appendix_mark $j]              puts $fhandle [lindex $appendix_mark $j]
1717              puts $fhandle [lindex $appendix_mark $j]              }
1718              }           }
1719           }        }
1720        }  
1721       #Now can put in the final matter.
1722     #Now can put in the final matter.     output_tex_volume_final_matter $fhandle
1723     output_tex_volume_final_matter $fhandle  
1724       #Mark the end of the files, for aesthetics.
1725     #Mark the end of the files, for aesthetics.     mark_end_of_tex_volume_files_for_aesthetics $fhandle svf.tex
1726     mark_end_of_tex_volume_files_for_aesthetics $fhandle svf.tex  
1727       #Close the files.
1728     #Close the files.     #close $dhandle
1729     #close $dhandle     close $fhandle
1730     close $fhandle  
1731       hlineboth
1732     hlineboth     }
1733     }  
1734    
1735    #Write the preamble to the _README_.HTM file.  This is everything up to the variable part that depends
1736  #Write the preamble to the _README_.HTM file.  This is everything up to the variable part that depends  #on the parts and sections defined in the script.
1737  #on the parts and sections defined in the script.  proc rebuildReadmeWritePreamble { fhandle } {
1738  proc rebuildReadmeWritePreamble { fhandle } {     set preamble {
1739     set preamble {        "<html>"                                                                                                 \
1740        "<html>"                                                                                                 \        ""                                                                                                       \
1741        ""                                                                                                       \        "<head>"                                                                                                 \
1742        "<head>"                                                                                                 \        "<title>README File:&nbsp; CD Accompanying &quot;A Practitioner's Guide ...&quot;</title>"               \
1743        "<title>README File:&nbsp; CD Accompanying &quot;A Practitioner's Guide ...&quot;</title>"               \        "</head>"                                                                                                \
1744        "</head>"                                                                                                \        ""                                                                                                       \
1745        ""                                                                                                       \        "<body BACKGROUND=\"wbbkgnds/bkblue01.gif\" TEXT=\"\#000000\">"                                          \
1746        "<body BACKGROUND=\"wbbkgnds/bkblue01.gif\" TEXT=\"\#000000\">"                                          \        ""                                                                                                       \
1747        ""                                                                                                       \        "<h1 ALIGN=\"center\">README File:  CD Accompanying \"A Practitioner's Guide ...\"</h1>"                 \
1748        "<h1 ALIGN=\"center\">README File:  CD Accompanying \"A Practitioner's Guide ...\"</h1>"                 \        ""                                                                                                       \
1749        ""                                                                                                       \        "<hr>"                                                                                                   \
1750        "<hr>"                                                                                                   \        ""                                                                                                       \
1751        ""                                                                                                       \        "<p>This HTML file contains links to all of the files distributed with the book"                         \
1752        "<p>This HTML file contains links to all of the files distributed with the book"                         \        "&quot;A Practitioner's Guide To The Design And Development Of Small Microcontroller Software&quot;, and"\
1753        "&quot;A Practitioner's Guide To The Design And Development Of Small Microcontroller Software&quot;, and"\        "explains what each of the files is.&nbsp; This file is automatically generated by the Wish script"      \
1754        "explains what each of the files is.&nbsp; This file is automatically generated by the Wish script"      \        "SCRIPTS\\CP_SCRIPT.TCL.&nbsp; Note that some chapter titles"                                            \
1755        "SCRIPTS\\CP_SCRIPT.TCL.&nbsp; Note that some chapter titles"                                            \        "and other information in this HTML file may differ subtly from the book, because the Wish script"       \
1756        "and other information in this HTML file may differ subtly from the book, because the Wish script"       \        "is aware of both long and short names for many titles -- the"                                           \
1757        "is aware of both long and short names for many titles -- the"                                           \        "long titles are used here, but the short titles may be used in some places in"                          \
1758        "long titles are used here, but the short titles may be used in some places in"                          \        "the book.&nbsp; For LaTeX builds of the book,&nbsp; it is assumed that the"                             \
1759        "the book.&nbsp; For LaTeX builds of the book,&nbsp; it is assumed that the"                             \        "contents of this CD are present, with the subdirectory tree prserved, in the"                           \
1760        "contents of this CD are present, with the subdirectory tree prserved, in the"                           \        "directory C:\\ESRGUBKA, i.e. so that the full"                                                           \
1761        "directory C:\\ESRGUBKA, i.e. so that the full"                                                           \        "path of this HTML file is C:\\ESRGUBKA\\_README_.HTM.&nbsp; All path names supplied"                     \
1762        "path of this HTML file is C:\\ESRGUBKA\\_README_.HTM.&nbsp; All path names supplied"                     \        "below are with respect to C:\\ESRGUBKA.</p>"                                                             \
1763        "below are with respect to C:\\ESRGUBKA.</p>"                                                             \        ""                                                                                                       \
1764        ""                                                                                                       \        "<hr>"                                                                                                   \
1765        "<hr>"                                                                                                   \        ""                                                                                                       \
1766        ""                                                                                                       \        }
1767        }  
1768       for {set i 0} {$i < [llength $preamble]} {incr i} { \
1769     for {set i 0} {$i < [llength $preamble]} {incr i} { \        puts $fhandle [lindex $preamble $i]
1770        puts $fhandle [lindex $preamble $i]        }
1771        }     }
1772     }  
1773    
1774    #Write the "meat" to the file.  This is the table and variable stuff.
1775  #Write the "meat" to the file.  This is the table and variable stuff.  proc rebuildReadmeWriteMeat { fhandle } {
1776  proc rebuildReadmeWriteMeat { fhandle } {     global readme_build_list
1777     global readme_build_list  
1778       #For indentation, the code supplied by Microsoft Front page was used as a guide.
1779     #For indentation, the code supplied by Microsoft Front page was used as a guide.  
1780       #Write the start of the table.
1781     #Write the start of the table.     puts $fhandle "<table border=\"1\" width=\"100%\">"
1782     puts $fhandle "<table border=\"1\" width=\"100%\">"  
1783       #Set state variables to remember if anything must be closed as we iterate.
1784     #Set state variables to remember if anything must be closed as we iterate.     set tr_active 0
1785     set tr_active 0        #True if in a <tr> block.
1786        #True if in a <tr> block.     set td_active 0
1787     set td_active 0        #True if in a <td> block.
1788        #True if in a <td> block.     set ul_active 0
1789     set ul_active 0        #True if in a <ul> block.
1790        #True if in a <ul> block.     set li_active 0
1791     set li_active 0        #True if in a <li> item.
1792        #True if in a <li> item.  
1793       #Loop through the list, processing each record.  Front Page HTML was used as a
1794     #Loop through the list, processing each record.  Front Page HTML was used as a     #guide.
1795     #guide.     for {set i 0} {$i < [llength $readme_build_list]} {incr i} { \
1796     for {set i 0} {$i < [llength $readme_build_list]} {incr i} { \        #Loop effort-savers.
1797        #Loop effort-savers.            set cur_rec [lindex $readme_build_list $i]
1798            set cur_rec [lindex $readme_build_list $i]            set cur_tag [string range $cur_rec 0 0]
1799            set cur_tag [string range $cur_rec 0 0]            set cur_meat [string range $cur_rec 2 end]
1800            set cur_meat [string range $cur_rec 2 end]  
1801          #puts $cur_rec
1802        #puts $cur_rec  
1803          #Split into cases, one for each possible tag.
1804        #Split into cases, one for each possible tag.        if {! [string compare -nocase $cur_tag F]} { \
1805        if {! [string compare -nocase $cur_tag F]} { \           #If a <tr> block is not active, must start one.
1806           #If a <tr> block is not active, must start one.           if {! $tr_active} { \
1807           if {! $tr_active} { \              puts $fhandle "  <tr>"
1808              puts $fhandle "  <tr>"              set tr_active 1
1809              set tr_active 1              }
1810              }           #If a <td> block is not active, must start one.
1811           #If a <td> block is not active, must start one.           if {! $td_active} { \
1812           if {! $td_active} { \              puts $fhandle "    <td width=\"100%\">"
1813              puts $fhandle "    <td width=\"100%\">"              set td_active 1
1814              set td_active 1              }
1815              }           #If a <ul> block is not active, must start one.
1816           #If a <ul> block is not active, must start one.           if {! $ul_active} { \
1817           if {! $ul_active} { \              puts $fhandle "      <ul>"
1818              puts $fhandle "      <ul>"              set ul_active 1
1819              set ul_active 1              }
1820              }           #OK, can now write the filename and the associated markers.  Will start
1821           #OK, can now write the filename and the associated markers.  Will start           #a list item in this endeavor, so must set this flag TRUE.
1822           #a list item in this endeavor, so must set this flag TRUE.           #If a <li> block is active, must end it.
1823           #If a <li> block is active, must end it.           if {$li_active} { \
1824           if {$li_active} { \              puts $fhandle "        </li>"
1825              puts $fhandle "        </li>"              set li_active 0
1826              set li_active 0              }
1827              }           set li_active 1
1828           set li_active 1           puts $fhandle "        <li><b><a href=\"" nonewline
1829           puts $fhandle "        <li><b><a href=\"" nonewline           #When we stuff the file name in this context, need to change spaces to
1830           #When we stuff the file name in this context, need to change spaces to           #the string "%20".  The reasons for this are HTML syntax.
1831           #the string "%20".  The reasons for this are HTML syntax.           puts $fhandle [replace_spaces_with_HTML_codes [string tolower $cur_meat]] nonewline
1832           puts $fhandle [replace_spaces_with_HTML_codes [string tolower $cur_meat]] nonewline           puts $fhandle "\">" nonewline
1833           puts $fhandle "\">" nonewline           puts $fhandle [string toupper $cur_meat] nonewline
1834           puts $fhandle [string toupper $cur_meat] nonewline           puts $fhandle "</a>:</b>&nbsp; "
1835           puts $fhandle "</a>:</b>&nbsp; "           } \
1836           } \        elseif {! [string compare -nocase $cur_tag M]} { \
1837        elseif {! [string compare -nocase $cur_tag M]} { \           #The first thing we need to do is close out any nested blocks that we are in.
1838           #The first thing we need to do is close out any nested blocks that we are in.           #If a <li> block is active, must end it.
1839           #If a <li> block is active, must end it.           if {$li_active} { \
1840           if {$li_active} { \              puts $fhandle "        </li>"
1841              puts $fhandle "        </li>"              set li_active 0
1842              set li_active 0              }
1843              }           #If a <ul> block is active, must end it.
1844           #If a <ul> block is active, must end it.           if {$ul_active} { \
1845           if {$ul_active} { \              puts $fhandle "      </ul>"
1846              puts $fhandle "      </ul>"              set ul_active 0
1847              set ul_active 0              }
1848              }           #If a <td> block is active, must end it.
1849           #If a <td> block is active, must end it.           if {$td_active} { \
1850           if {$td_active} { \              puts $fhandle "    </td>"
1851              puts $fhandle "    </td>"              set td_active 0
1852              set td_active 0              }
1853              }           #If a <tr> block is active, must end it.
1854           #If a <tr> block is active, must end it.           if {$tr_active} { \
1855           if {$tr_active} { \              puts $fhandle "  </tr>"
1856              puts $fhandle "  </tr>"              set tr_active 0
1857              set tr_active 0              }
1858              }  
1859                 #Manually-generated header.  Just stuff it in.
1860               #Manually-generated header.  Just stuff it in.                   puts $fhandle "  <tr>"
1861                   puts $fhandle "  <tr>"                   puts $fhandle "    <td width=\"100%\"><b><font size=\"5\">" nonewline
1862                   puts $fhandle "    <td width=\"100%\"><b><font size=\"5\">" nonewline                   puts $fhandle "[string toupper $cur_meat]" nonewline
1863                   puts $fhandle "[string toupper $cur_meat]" nonewline                   puts $fhandle "</font></b></td>"
1864                   puts $fhandle "</font></b></td>"                   puts $fhandle "  </tr>"
1865                   puts $fhandle "  </tr>"               } \
1866               } \        elseif {! [string compare -nocase $cur_tag C]} { \
1867        elseif {! [string compare -nocase $cur_tag C]} { \           #If a <li> block is active, must end it.
1868           #If a <li> block is active, must end it.           if {$li_active} { \
1869           if {$li_active} { \              puts $fhandle "        </li>"
1870              puts $fhandle "        </li>"              set li_active 0
1871              set li_active 0              }
1872              }           #If a <ul> block is active, must end it.
1873           #If a <ul> block is active, must end it.           if {$ul_active} { \
1874           if {$ul_active} { \              puts $fhandle "      </ul>"
1875              puts $fhandle "      </ul>"              set ul_active 0
1876              set ul_active 0              }
1877              }           #If a <td> block is active, must end it.
1878           #If a <td> block is active, must end it.           if {$td_active} { \
1879           if {$td_active} { \              puts $fhandle "    </td>"
1880              puts $fhandle "    </td>"              set td_active 0
1881              set td_active 0              }
1882              }           #If a <tr> block is active, must end it.
1883           #If a <tr> block is active, must end it.           if {$tr_active} { \
1884           if {$tr_active} { \              puts $fhandle "  </tr>"
1885              puts $fhandle "  </tr>"              set tr_active 0
1886              set tr_active 0              }
1887              }  
1888                 #This is one with a chapter tag.  We need to look up the tag.
1889               #This is one with a chapter tag.  We need to look up the tag.           set mc_ct [get_chap_long_single_volume_title $cur_meat]
1890           set mc_ct [get_chap_long_single_volume_title $cur_meat]                   set uc_ct [string toupper $mc_ct]
1891                   set uc_ct [string toupper $mc_ct]                   puts $fhandle "  <tr>"
1892                   puts $fhandle "  <tr>"                   puts $fhandle "    <td width=\"100%\"><b><font size=\"5\">" nonewline
1893                   puts $fhandle "    <td width=\"100%\"><b><font size=\"5\">" nonewline                   puts $fhandle "CHAPTER " nonewline
1894                   puts $fhandle "CHAPTER " nonewline           puts $fhandle [string toupper $cur_meat] nonewline
1895           puts $fhandle [string toupper $cur_meat] nonewline           puts $fhandle ":&nbsp;  " nonewline
1896           puts $fhandle ":&nbsp;  " nonewline                   puts $fhandle $uc_ct nonewline
1897                   puts $fhandle $uc_ct nonewline                   puts $fhandle "</font></b></td>"
1898                   puts $fhandle "</font></b></td>"                   puts $fhandle "  </tr>"
1899                   puts $fhandle "  </tr>"               } \
1900               } \        elseif {! [string compare -nocase $cur_tag D]} { \
1901        elseif {! [string compare -nocase $cur_tag D]} { \           #For descriptions, we just dump it in verbatim.  There is no need to do any processing.
1902           #For descriptions, we just dump it in verbatim.  There is no need to do any processing.           puts $fhandle "          " nonewline
1903           puts $fhandle "          " nonewline           puts $fhandle $cur_meat
1904           puts $fhandle $cur_meat               } \
1905               } \        else {
1906        else {               error "Unexpected tag in readme_build_list."
1907               error "Unexpected tag in readme_build_list."               }
1908               }        }
1909        }  
1910       #Write the end of the table.
1911     #Write the end of the table.     puts $fhandle "</table>"
1912     puts $fhandle "</table>"     puts $fhandle ""
1913     puts $fhandle ""     }
1914     }  
1915      
1916      #Write the postamble to the file.  This is everything after the variable part.
1917  #Write the postamble to the file.  This is everything after the variable part.  proc rebuildReadmeWritePostamble { fhandle } {
1918  proc rebuildReadmeWritePostamble { fhandle } {     #First, grab the time as seconds since a time mark unknown.
1919     #First, grab the time as seconds since a time mark unknown.     set tref [clock seconds]
1920     set tref [clock seconds]  
1921       #Convert the time obtained to date.
1922     #Convert the time obtained to date.     set date [clock format $tref -format "%m/%d/%y"]
1923     set date [clock format $tref -format "%m/%d/%y"]  
1924       #Convert the time obtained to hour and minute.
1925     #Convert the time obtained to hour and minute.     set time [clock format $tref -format "%H:%M"]
1926     set time [clock format $tref -format "%H:%M"]  
1927       #This part has to be manually generated because of the date and time.
1928     #This part has to be manually generated because of the date and time.     puts $fhandle ""
1929     puts $fhandle ""     puts $fhandle "<hr>"
1930     puts $fhandle "<hr>"     puts $fhandle ""
1931     puts $fhandle ""     puts $fhandle "<p align=\"center\">This file automatically generated on " nonewline
1932     puts $fhandle "<p align=\"center\">This file automatically generated on " nonewline     puts $fhandle $date nonewline
1933     puts $fhandle $date nonewline     puts $fhandle " at " nonewline
1934     puts $fhandle " at " nonewline     puts $fhandle $time nonewline
1935     puts $fhandle $time nonewline     puts $fhandle            " by "
1936     puts $fhandle            " by "     puts $fhandle "Wish script SCRIPTS\\CP_SCRIPT.TCL.</p>"
1937     puts $fhandle "Wish script SCRIPTS\\CP_SCRIPT.TCL.</p>"     puts $fhandle ""
1938     puts $fhandle ""     puts $fhandle "<hr noshade size=\"10\" color=\"\#000000\">"
1939     puts $fhandle "<hr noshade size=\"10\" color=\"\#000000\">"     puts $fhandle "</body>"
1940     puts $fhandle "</body>"     puts $fhandle "</html>"
1941     puts $fhandle "</html>"     }
1942     }  
1943    #****************************************************************************************
1944  #****************************************************************************************  #****************************************************************************************
1945  #****************************************************************************************  #****    B U T T O N    P R E S S    F U N C T I O N S    *******************************
1946  #****    B U T T O N    P R E S S    F U N C T I O N S    *******************************  #****************************************************************************************
1947  #****************************************************************************************  #****************************************************************************************
1948  #****************************************************************************************  # Each of the functions in this category is called in response to a button on the main
1949  # Each of the functions in this category is called in response to a button on the main  # graphical window being pressed.
1950  # graphical window being pressed.  #----------------------------------------------------------------------------------------
1951  #----------------------------------------------------------------------------------------  # Performs a full LaTeX compilation and indexing of all volumes.  It isn't necessary to
1952  # Performs a full LaTeX compilation and indexing of all volumes.  It isn't necessary to  # subdivide this operation any further because the full build is rare enough that any    
1953  # subdivide this operation any further because the full build is rare enough that any      # reasonable amount of time is OK.  In the long term, it will be necessary to have the
1954  # reasonable amount of time is OK.  In the long term, it will be necessary to have the  # tools build a full index spanning all volumes, but this isn't done yet.              
1955  # tools build a full index spanning all volumes, but this isn't done yet.                #
1956  #  proc fullLatexCompileAndIndexProc { } { \
1957  proc fullLatexCompileAndIndexProc { } { \     global bookVolumeList
1958     global bookVolumeList     global bookVolumeListStructSize
1959     global bookVolumeListStructSize     global pathUcBookA
1960     global pathUcBookA     global execAcrobatDistiller
1961     global execAcrobatDistiller     global mcl
1962     global mcl     global chapterList
1963     global chapterList     global chapterListStructSize
1964     global chapterListStructSize  
1965       outboth "BUTTON PRESS:  Full LaTeX compile and index."
1966     outboth "BUTTON PRESS:  Full LaTeX compile and index."     hlineboth
1967     hlineboth  
1968       #As a first step, extract this script's version control information.  This is used in
1969     #As a first step, extract this script's version control information.  This is used in     #building the .TEX main files, to stamp them with the script's version control
1970     #building the .TEX main files, to stamp them with the script's version control     #information.
1971     #information.     set script_vcinfo [extract_this_scripts_version_control_information]
1972     set script_vcinfo [extract_this_scripts_version_control_information]  
1973       #Set up the list of volumes and chapters to be processed.  This involves scanning the mcl to see
1974     #Set up the list of volumes and chapters to be processed.  This involves scanning the mcl to see     #what is used and what is not used, and setting flags accordingly.  Volume "used" flags affect
1975     #what is used and what is not used, and setting flags accordingly.  Volume "used" flags affect     #how volumes are numbered and how they are cross-referenced.  Chapter "used" flags are safely
1976     #how volumes are numbered and how they are cross-referenced.  Chapter "used" flags are safely     #ignored--it does no harm to include chapter cite information in the LaTeX output files--what will
1977     #ignored--it does no harm to include chapter cite information in the LaTeX output files--what will     #happen is if the referenced chapter isn't included, the unresolvable references will be "pushed"
1978     #happen is if the referenced chapter isn't included, the unresolvable references will be "pushed"     #onto LaTeX.
1979     #onto LaTeX.  
1980       #Zero out all of the volume used flags.
1981     #Zero out all of the volume used flags.     outbothnonl "Marking all volumes unused ... "
1982     outbothnonl "Marking all volumes unused ... "     mark_all_volumes_unused
1983     mark_all_volumes_unused     outboth "done."
1984     outboth "done."  
1985       #Zero out all of the chapter used flags.
1986     #Zero out all of the chapter used flags.     outbothnonl "Marking all chapters unused ... "
1987     outbothnonl "Marking all chapters unused ... "     mark_all_chaps_unused
1988     mark_all_chaps_unused     outboth "done."
1989     outboth "done."  
1990       #Iterate through the mcl list, figuring out which volumes and chapters are used.  A "volume" is used
1991     #Iterate through the mcl list, figuring out which volumes and chapters are used.  A "volume" is used     #if it contains at least one chapter in the mcl list.  A "chapter" is used if it appears either as
1992     #if it contains at least one chapter in the mcl list.  A "chapter" is used if it appears either as     #part of a volume or in the standalone work.
1993     #part of a volume or in the standalone work.     outbothnonl "Scanning mcl list for used volumes and used chapters ... "
1994     outbothnonl "Scanning mcl list for used volumes and used chapters ... "     set used_volumes 0
1995     set used_volumes 0     set unused_volumes [expr [llength $bookVolumeList] / $bookVolumeListStructSize]
1996     set unused_volumes [expr [llength $bookVolumeList] / $bookVolumeListStructSize]     set used_chapters 0
1997     set used_chapters 0     set unused_chapters [expr [llength $chapterList] / $chapterListStructSize]
1998     set unused_chapters [expr [llength $chapterList] / $chapterListStructSize]     set cur_vol ""
1999     set cur_vol ""     set N [llength $mcl]
2000     set N [llength $mcl]     #Iterate through the list, taking notes.
2001     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i 4} { \
2002     for {set i 0} {$i < $N} {incr i 4} { \        set mcl_rectype [lindex $mcl [expr $i + 0]]
2003        set mcl_rectype [lindex $mcl [expr $i + 0]]        set mcl_par1    [lindex $mcl [expr $i + 1]]
2004        set mcl_par1    [lindex $mcl [expr $i + 1]]        set mcl_par2    [lindex $mcl [expr $i + 2]]
2005        set mcl_par2    [lindex $mcl [expr $i + 2]]        set mcl_par3    [lindex $mcl [expr $i + 3]]
2006        set mcl_par3    [lindex $mcl [expr $i + 3]]  
2007          if {! [string compare $mcl_rectype v] || ! [string compare $mcl_rectype w]} \
2008        if {! [string compare $mcl_rectype v] || ! [string compare $mcl_rectype w]} \           {
2009           {           #The v record type declares a new volume, and the w declares both a new volume and
2010           #The v record type declares a new volume, and the w declares both a new volume and           #a new part.  Either of these record types mean that we've hit a new volume boundary.
2011           #a new part.  Either of these record types mean that we've hit a new volume boundary.           #Remember this.
2012           #Remember this.           set cur_vol $mcl_par1
2013           set cur_vol $mcl_par1           } \
2014           } \        elseif {! [string compare $mcl_rectype c] || ! [string compare $mcl_rectype e]} { \
2015        elseif {! [string compare $mcl_rectype c] || ! [string compare $mcl_rectype e]} { \           #Either of these declare a chapter in the current volume.  Process.
2016           #Either of these declare a chapter in the current volume.  Process.           #Mark the chapter as used, and update chapter statistics.
2017           #Mark the chapter as used, and update chapter statistics.           if {[get_chap_used_flag $mcl_par1]} { \
2018           if {[get_chap_used_flag $mcl_par1]} { \              #The chapter is already used.  Don't want to count the chapter as used
2019              #The chapter is already used.  Don't want to count the chapter as used              #again.
2020              #again.              } \
2021              } \           else {
2022           else {  
2023                #outboth "Marking $mcl_par1"
2024              #outboth "Marking $mcl_par1"  
2025                #The chapter isn't yet marked used.
2026              #The chapter isn't yet marked used.              mark_chapter_used $mcl_par1
2027              mark_chapter_used $mcl_par1              incr used_chapters
2028              incr used_chapters              incr unused_chapters -1
2029              incr unused_chapters -1              }
2030              }           #Mark the volume used if it is used.
2031           #Mark the volume used if it is used.           if {[string length $cur_vol]} { \
2032           if {[string length $cur_vol]} { \              if {![get_volume_used_flag $cur_vol]} { \
2033              if {![get_volume_used_flag $cur_vol]} { \                 #Mark that volume (the nearest above enclosing one) as used.
2034                 #Mark that volume (the nearest above enclosing one) as used.                 mark_volume_used $cur_vol
2035                 mark_volume_used $cur_vol                 incr used_volumes
2036                 incr used_volumes                 incr unused_volumes -1
2037                 incr unused_volumes -1                 }
2038                 }              }
2039              }           }
2040           }        }
2041        }  
2042       outboth "done."
2043     outboth "done."  
2044       #Output statistics about what is used and not used.  This is helpful for diagnosis.
2045     #Output statistics about what is used and not used.  This is helpful for diagnosis.     outbothnonl "Used chapters:  $used_chapters  Unused chapters:  $unused_chapters"
2046     outbothnonl "Used chapters:  $used_chapters  Unused chapters:  $unused_chapters"     outboth .
2047     outboth .     outboth "Enumeration of unused chapters (if any):"
2048     outboth "Enumeration of unused chapters (if any):"     set N [llength $chapterList]
2049     set N [llength $chapterList]     #Iterate through the list, taking notes.
2050     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \
2051     for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \        #outboth "i: $i"
2052        #outboth "i: $i"        if { ! [get_chap_used_flag [lindex $chapterList $i]]} { \
2053        if { ! [get_chap_used_flag [lindex $chapterList $i]]} { \           outboth "   [lindex $chapterList $i]"
2054           outboth "   [lindex $chapterList $i]"           }
2055           }        }
2056        }  
2057       outbothnonl "Used volumes:   $used_volumes   Unused volumes:   $unused_volumes"
2058     outbothnonl "Used volumes:   $used_volumes   Unused volumes:   $unused_volumes"     outboth .
2059     outboth .     outboth "Enumeration of used volumes (if any):"
2060     outboth "Enumeration of used volumes (if any):"     set N [llength $bookVolumeList]
2061     set N [llength $bookVolumeList]     #Iterate through the list, taking notes.
2062     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
2063     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        #outboth "i: $i"
2064        #outboth "i: $i"        if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \
2065        if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \           outboth "   [lindex $bookVolumeList $i]"
2066           outboth "   [lindex $bookVolumeList $i]"           }
2067           }        }
2068        }     outboth "Enumeration of unused volumes (if any):"
2069     outboth "Enumeration of unused volumes (if any):"     set N [llength $bookVolumeList]
2070     set N [llength $bookVolumeList]     #Iterate through the list, taking notes.
2071     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
2072     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        #outboth "i: $i"
2073        #outboth "i: $i"        if { ! [get_volume_used_flag [lindex $bookVolumeList $i]]} { \
2074        if { ! [get_volume_used_flag [lindex $bookVolumeList $i]]} { \           outboth "   [lindex $bookVolumeList $i]"
2075           outboth "   [lindex $bookVolumeList $i]"           }
2076           }        }
2077        }  
2078       #Delete all the output files.  This guards against misunderstandings and accidents.  In the deletion of output
2079     #Delete all the output files.  This guards against misunderstandings and accidents.  In the deletion of output     #files, whether volumes are used or not is not taken into account.  The reason for this is neatness--if
2080     #files, whether volumes are used or not is not taken into account.  The reason for this is neatness--if     #the list of used volumes changes, it is helpful to get all of those files gone.
2081     #the list of used volumes changes, it is helpful to get all of those files gone.  
2082       #Delete the two single-volume files.
2083     #Delete the two single-volume files.     set pathbase ""
2084     set pathbase ""     append pathbase $pathUcBookA / sv
2085     append pathbase $pathUcBookA / sv     #set svlist {f.dvi f.ps f.pdf d.dvi d.ps d.pdf}
2086     #set svlist {f.dvi f.ps f.pdf d.dvi d.ps d.pdf}     set svlist {f.dvi f.ps f.pdf}
2087     set svlist {f.dvi f.ps f.pdf}     set N [llength $svlist]
2088     set N [llength $svlist]  
2089       #Iterate through, delete each single-volume file.
2090     #Iterate through, delete each single-volume file.     for {set i 0} {$i < $N} {incr i} { \
2091     for {set i 0} {$i < $N} {incr i} { \        set target $pathbase
2092        set target $pathbase        append target [lindex $svlist $i]
2093        append target [lindex $svlist $i]  
2094          if {[file exists $target]} { \
2095        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2096           outbothnonl "Deleting $target"           outboth .
2097           outboth .           file delete $target
2098           file delete $target           } \
2099           } \        else {
2100        else {           outboth "Skipping $target : file does not exist."
2101           outboth "Skipping $target : file does not exist."           }
2102           }        }        
2103        }          
2104       #Get number of elements in the list of volumes.
2105     #Get number of elements in the list of volumes.     set N [llength $bookVolumeList]
2106     set N [llength $bookVolumeList]  
2107       #Iterate through, delete each file.
2108     #Iterate through, delete each file.     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \
2109     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \        set voltag [lindex $bookVolumeList $volnum]
2110        set voltag [lindex $bookVolumeList $volnum]  
2111          set target ""
2112        set target ""        append target $pathUcBookA / $voltag .dvi
2113        append target $pathUcBookA / $voltag .dvi  
2114          if {[file exists $target]} { \
2115        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2116           outbothnonl "Deleting $target"           outboth .
2117           outboth .           file delete $target
2118           file delete $target           } \
2119           } \        else {
2120        else {           outboth "Skipping $target : file does not exist."
2121           outboth "Skipping $target : file does not exist."           }
2122           }  
2123          set target ""
2124        set target ""        append target $pathUcBookA / $voltag .ps
2125        append target $pathUcBookA / $voltag .ps  
2126          if {[file exists $target]} { \
2127        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2128           outbothnonl "Deleting $target"           outboth .
2129           outboth .           file delete $target
2130           file delete $target           } \
2131           } \        else {
2132        else {           outboth "Skipping $target : file does not exist."
2133           outboth "Skipping $target : file does not exist."           }
2134           }  
2135          set target ""
2136        set target ""        append target $pathUcBookA / $voltag .pdf
2137        append target $pathUcBookA / $voltag .pdf  
2138          if {[file exists $target]} { \
2139        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2140           outbothnonl "Deleting $target"           outboth .
2141           outboth .           file delete $target
2142           file delete $target           } \
2143           } \        else {
2144        else {           outboth "Skipping $target : file does not exist."
2145           outboth "Skipping $target : file does not exist."           }
2146           }  
2147          set target ""
2148        set target ""        append target $pathUcBookA / $voltag .idx
2149        append target $pathUcBookA / $voltag .idx  
2150          if {[file exists $target]} { \
2151        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2152           outbothnonl "Deleting $target"           outboth .
2153           outboth .           file delete $target
2154           file delete $target           } \
2155           } \        else {
2156        else {           outboth "Skipping $target : file does not exist."
2157           outboth "Skipping $target : file does not exist."           }
2158           }  
2159          set target ""
2160        set target ""        append target $pathUcBookA / $voltag .ilg
2161        append target $pathUcBookA / $voltag .ilg  
2162          if {[file exists $target]} { \
2163        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2164           outbothnonl "Deleting $target"           outboth .
2165           outboth .           file delete $target
2166           file delete $target           } \
2167           } \        else {
2168        else {           outboth "Skipping $target : file does not exist."
2169           outboth "Skipping $target : file does not exist."           }
2170           }  
2171          set target ""
2172        set target ""        append target $pathUcBookA / $voltag .ind
2173        append target $pathUcBookA / $voltag .ind  
2174          if {[file exists $target]} { \
2175        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2176           outbothnonl "Deleting $target"           outboth .
2177           outboth .           file delete $target
2178           file delete $target           } \
2179           } \        else {
2180        else {           outboth "Skipping $target : file does not exist."
2181           outboth "Skipping $target : file does not exist."           }
2182           }  
2183          set target ""
2184        set target ""        append target $pathUcBookA / $voltag .toc
2185        append target $pathUcBookA / $voltag .toc  
2186          if {[file exists $target]} { \
2187        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2188           outbothnonl "Deleting $target"           outboth .
2189           outboth .           file delete $target
2190           file delete $target           } \
2191           } \        else {
2192        else {           outboth "Skipping $target : file does not exist."
2193           outboth "Skipping $target : file does not exist."           }
2194           }  
2195          set target ""
2196        set target ""        append target $pathUcBookA / $voltag .aux
2197        append target $pathUcBookA / $voltag .aux  
2198          if {[file exists $target]} { \
2199        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2200           outbothnonl "Deleting $target"           outboth .
2201           outboth .           file delete $target
2202           file delete $target           } \
2203           } \        else {
2204        else {           outboth "Skipping $target : file does not exist."
2205           outboth "Skipping $target : file does not exist."           }
2206           }  
2207          }
2208        }     hlineboth
2209     hlineboth  
2210       #Create the master files for the two single volume works (the draft and the final).
2211     #Create the master files for the two single volume works (the draft and the final).     createSingleVolumeWorks $script_vcinfo
2212     createSingleVolumeWorks $script_vcinfo  
2213       #Create the master files for the volumes.  The volumes are automatically numbered,
2214     #Create the master files for the volumes.  The volumes are automatically numbered,     #based on those that are used, starting with 1.
2215     #based on those that are used, starting with 1.     set volume_number 0
2216     set volume_number 0     set N [llength $bookVolumeList]
2217     set N [llength $bookVolumeList]     #Iterate through, delete each file.
2218     #Iterate through, delete each file.     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \
2219     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \        set voltag [lindex $bookVolumeList $volnum]
2220        set voltag [lindex $bookVolumeList $volnum]  
2221          if {[get_volume_used_flag $voltag]} { \
2222        if {[get_volume_used_flag $voltag]} { \           incr volume_number
2223           incr volume_number           createMultiVolumeWork $voltag $volume_number $script_vcinfo
2224           createMultiVolumeWork $voltag $volume_number $script_vcinfo           }
2225           }        }  
2226        }    
2227       #Do four full rounds of LaTeX compiles and index builds.  This is necessary
2228     #Do four full rounds of LaTeX compiles and index builds.  This is necessary     #to resolve cross-dependencies and be sure no page numbering changes.
2229     #to resolve cross-dependencies and be sure no page numbering changes.     for {set round 0} {$round < 4} {incr round} { \
2230     for {set round 0} {$round < 4} {incr round} { \        outbothnonl "LaTeX compile, Round "
2231        outbothnonl "LaTeX compile, Round "        outbothnonl $round
2232        outbothnonl $round        outboth .
2233        outboth .        hlineboth
2234        hlineboth  
2235          #Do the single-volume works.
2236        #Do the single-volume works.        #LatexCompileFile svd.tex
2237        #LatexCompileFile svd.tex        #MakeOrdinaryIndexFile svd
2238        #MakeOrdinaryIndexFile svd        LatexCompileFile svf.tex
2239        LatexCompileFile svf.tex        MakeOrdinaryIndexFile svf
2240        MakeOrdinaryIndexFile svf  
2241          #Get number of elements in the list of volumes.  Compile only the used ones.
2242        #Get number of elements in the list of volumes.  Compile only the used ones.        set N [llength $bookVolumeList]
2243        set N [llength $bookVolumeList]  
2244          #Iterate through, compile each file.
2245        #Iterate through, compile each file.        for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \
2246        for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \           set voltag [lindex $bookVolumeList $volnum]
2247           set voltag [lindex $bookVolumeList $volnum]           if {[get_volume_used_flag $voltag]} { \
2248           if {[get_volume_used_flag $voltag]} { \              outbothnonl "Latex compile: $voltag"
2249              outbothnonl "Latex compile: $voltag"              outboth .
2250              outboth .              hlineboth
2251              hlineboth  
2252                set fullfilename ""
2253              set fullfilename ""              append fullfilename $voltag .tex
2254              append fullfilename $voltag .tex  
2255                LatexCompileFile $fullfilename
2256              LatexCompileFile $fullfilename  
2257                MakeOrdinaryIndexFile $voltag
2258              MakeOrdinaryIndexFile $voltag              }
2259              }           }
2260           }        update
2261        update        }
2262        }  
2263       #DVIPS the single-volume file.
2264     #DVIPS the single-volume file.     outbothnonl "DVIPS: svf"
2265     outbothnonl "DVIPS: svf"     RunDvipsToGenPsOutput svf
2266     RunDvipsToGenPsOutput svf  
2267       #Modify the postscript in the single volume file to
2268     #Modify the postscript in the single volume file to     #generate a duplex file.
2269     #generate a duplex file.     ModifyPsToDuplex svf
2270     ModifyPsToDuplex svf  
2271       #PDF the two single-volume file.
2272     #PDF the two single-volume file.     set psfilepath ""
2273     set psfilepath ""     append psfilepath $pathUcBookA / svf.ps
2274     append psfilepath $pathUcBookA / svf.ps     exec $execAcrobatDistiller $psfilepath &
2275     exec $execAcrobatDistiller $psfilepath &  
2276       #Get number of elements in the list of volumes.
2277     #Get number of elements in the list of volumes.     set N [llength $bookVolumeList]
2278     set N [llength $bookVolumeList]  
2279       #Iterate through, DVIPS each file.
2280     #Iterate through, DVIPS each file.     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \
2281     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \        set voltag [lindex $bookVolumeList $volnum]
2282        set voltag [lindex $bookVolumeList $volnum]        if {[get_volume_used_flag $voltag]} { \
2283        if {[get_volume_used_flag $voltag]} { \           outbothnonl "DVIPS: $voltag"
2284           outbothnonl "DVIPS: $voltag"           outboth .
2285           outboth .           hlineboth
2286           hlineboth  
2287             RunDvipsToGenPsOutput $voltag
2288           RunDvipsToGenPsOutput $voltag           ModifyPsToDuplex      $voltag
2289           ModifyPsToDuplex      $voltag  
2290             set psfilepath ""
2291           set psfilepath ""           append psfilepath $pathUcBookA / $voltag .ps
2292           append psfilepath $pathUcBookA / $voltag .ps  
2293             #There is no barrier at this point to also running Distiller.  Distiller gives us
2294           #There is no barrier at this point to also running Distiller.  Distiller gives us           #no information back.
2295           #no information back.           exec $execAcrobatDistiller $psfilepath &
2296           exec $execAcrobatDistiller $psfilepath &           }
2297           }        update
2298        update        }
2299        }  
2300       outboth "DONE:  BUTTON PRESS:  Full LaTeX compile and index."
2301     outboth "DONE:  BUTTON PRESS:  Full LaTeX compile and index."     hlineboth
2302     hlineboth     update
2303     update     }
2304     }  
2305    #----------------------------------------------------------------------------------------
2306  #----------------------------------------------------------------------------------------  # Rebuilds all the master files.  This operation can be useful if one isn't using 4AllTex
2307  # Rebuilds all the master files.  This operation can be useful if one isn't using 4AllTex  # but wants to build the automatically-generated files anyway, perhaps to use another
2308  # but wants to build the automatically-generated files anyway, perhaps to use another  # version of LaTeX.
2309  # version of LaTeX.  #
2310  #  proc masterFileRebuildProc { } { \
2311  proc masterFileRebuildProc { } { \     global bookVolumeList
2312     global bookVolumeList     global bookVolumeListStructSize
2313     global bookVolumeListStructSize     global pathUcBookA
2314     global pathUcBookA     global execAcrobatDistiller
2315     global execAcrobatDistiller     global mcl
2316     global mcl     global chapterList
2317     global chapterList     global chapterListStructSize
2318     global chapterListStructSize  
2319       outboth "BUTTON PRESS:  Rebuild single-volume and multi-volume master files."
2320     outboth "BUTTON PRESS:  Rebuild single-volume and multi-volume master files."     hlineboth
2321     hlineboth  
2322       #As a first step, extract this script's version control information.  This is used in
2323     #As a first step, extract this script's version control information.  This is used in     #building the .TEX main files, to stamp them with the script's version control
2324     #building the .TEX main files, to stamp them with the script's version control     #information.
2325     #information.     set script_vcinfo [extract_this_scripts_version_control_information]
2326     set script_vcinfo [extract_this_scripts_version_control_information]  
2327       #Set up the list of volumes and chapters to be processed.  This involves scanning the mcl to see
2328     #Set up the list of volumes and chapters to be processed.  This involves scanning the mcl to see     #what is used and what is not used, and setting flags accordingly.  Volume "used" flags affect
2329     #what is used and what is not used, and setting flags accordingly.  Volume "used" flags affect     #how volumes are numbered and how they are cross-referenced.  Chapter "used" flags are safely
2330     #how volumes are numbered and how they are cross-referenced.  Chapter "used" flags are safely     #ignored--it does no harm to include chapter cite information in the LaTeX output files--what will
2331     #ignored--it does no harm to include chapter cite information in the LaTeX output files--what will     #happen is if the referenced chapter isn't included, the unresolvable references will be "pushed"
2332     #happen is if the referenced chapter isn't included, the unresolvable references will be "pushed"     #onto LaTeX.
2333     #onto LaTeX.  
2334       #Zero out all of the volume used flags.
2335     #Zero out all of the volume used flags.     outbothnonl "Marking all volumes unused ... "
2336     outbothnonl "Marking all volumes unused ... "     mark_all_volumes_unused
2337     mark_all_volumes_unused     outboth "done."
2338     outboth "done."  
2339       #Zero out all of the chapter used flags.
2340     #Zero out all of the chapter used flags.     outbothnonl "Marking all chapters unused ... "
2341     outbothnonl "Marking all chapters unused ... "     mark_all_chaps_unused
2342     mark_all_chaps_unused     outboth "done."
2343     outboth "done."  
2344       #Iterate through the mcl list, figuring out which volumes and chapters are used.  A "volume" is used
2345     #Iterate through the mcl list, figuring out which volumes and chapters are used.  A "volume" is used     #if it contains at least one chapter in the mcl list.  A "chapter" is used if it appears either as
2346     #if it contains at least one chapter in the mcl list.  A "chapter" is used if it appears either as     #part of a volume or in the standalone work.
2347     #part of a volume or in the standalone work.     outbothnonl "Scanning mcl list for used volumes and used chapters ... "
2348     outbothnonl "Scanning mcl list for used volumes and used chapters ... "     set used_volumes 0
2349     set used_volumes 0     set unused_volumes [expr [llength $bookVolumeList] / $bookVolumeListStructSize]
2350     set unused_volumes [expr [llength $bookVolumeList] / $bookVolumeListStructSize]     set used_chapters 0
2351     set used_chapters 0     set unused_chapters [expr [llength $chapterList] / $chapterListStructSize]
2352     set unused_chapters [expr [llength $chapterList] / $chapterListStructSize]     set cur_vol ""
2353     set cur_vol ""     set N [llength $mcl]
2354     set N [llength $mcl]     #Iterate through the list, taking notes.
2355     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i 4} { \
2356     for {set i 0} {$i < $N} {incr i 4} { \        set mcl_rectype [lindex $mcl [expr $i + 0]]
2357        set mcl_rectype [lindex $mcl [expr $i + 0]]        set mcl_par1    [lindex $mcl [expr $i + 1]]
2358        set mcl_par1    [lindex $mcl [expr $i + 1]]        set mcl_par2    [lindex $mcl [expr $i + 2]]
2359        set mcl_par2    [lindex $mcl [expr $i + 2]]        set mcl_par3    [lindex $mcl [expr $i + 3]]
2360        set mcl_par3    [lindex $mcl [expr $i + 3]]  
2361          if {! [string compare $mcl_rectype v] || ! [string compare $mcl_rectype w]} \
2362        if {! [string compare $mcl_rectype v] || ! [string compare $mcl_rectype w]} \           {
2363           {           #The v record type declares a new volume, and the w declares both a new volume and
2364           #The v record type declares a new volume, and the w declares both a new volume and           #a new part.  Either of these record types mean that we've hit a new volume boundary.
2365           #a new part.  Either of these record types mean that we've hit a new volume boundary.           #Remember this.
2366           #Remember this.           set cur_vol $mcl_par1
2367           set cur_vol $mcl_par1           } \
2368           } \        elseif {! [string compare $mcl_rectype c] || ! [string compare $mcl_rectype e]} { \
2369        elseif {! [string compare $mcl_rectype c] || ! [string compare $mcl_rectype e]} { \           #Either of these declare a chapter in the current volume.  Process.
2370           #Either of these declare a chapter in the current volume.  Process.           #Mark the chapter as used, and update chapter statistics.
2371           #Mark the chapter as used, and update chapter statistics.           if {[get_chap_used_flag $mcl_par1]} { \
2372           if {[get_chap_used_flag $mcl_par1]} { \              #The chapter is already used.  Don't want to count the chapter as used
2373              #The chapter is already used.  Don't want to count the chapter as used              #again.
2374              #again.              } \
2375              } \           else {
2376           else {  
2377                #outboth "Marking $mcl_par1"
2378              #outboth "Marking $mcl_par1"  
2379                #The chapter isn't yet marked used.
2380              #The chapter isn't yet marked used.              mark_chapter_used $mcl_par1
2381              mark_chapter_used $mcl_par1              incr used_chapters
2382              incr used_chapters              incr unused_chapters -1
2383              incr unused_chapters -1              }
2384              }           #Mark the volume used if it is used.
2385           #Mark the volume used if it is used.           if {[string length $cur_vol]} { \
2386           if {[string length $cur_vol]} { \              if {![get_volume_used_flag $cur_vol]} { \
2387              if {![get_volume_used_flag $cur_vol]} { \                 #Mark that volume (the nearest above enclosing one) as used.
2388                 #Mark that volume (the nearest above enclosing one) as used.                 mark_volume_used $cur_vol
2389                 mark_volume_used $cur_vol                 incr used_volumes
2390                 incr used_volumes                 incr unused_volumes -1
2391                 incr unused_volumes -1                 }
2392                 }              }
2393              }           }
2394           }        }
2395        }  
2396       outboth "done."
2397     outboth "done."  
2398       #Output statistics about what is used and not used.  This is helpful for diagnosis.
2399     #Output statistics about what is used and not used.  This is helpful for diagnosis.     outbothnonl "Used chapters:  $used_chapters  Unused chapters:  $unused_chapters"
2400     outbothnonl "Used chapters:  $used_chapters  Unused chapters:  $unused_chapters"     outboth .
2401     outboth .     outboth "Enumeration of unused chapters (if any):"
2402     outboth "Enumeration of unused chapters (if any):"     set N [llength $chapterList]
2403     set N [llength $chapterList]     #Iterate through the list, taking notes.
2404     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \
2405     for {set i 0} {$i < $N} {incr i $chapterListStructSize} { \        #outboth "i: $i"
2406        #outboth "i: $i"        if { ! [get_chap_used_flag [lindex $chapterList $i]]} { \
2407        if { ! [get_chap_used_flag [lindex $chapterList $i]]} { \           outboth "   [lindex $chapterList $i]"
2408           outboth "   [lindex $chapterList $i]"           }
2409           }        }
2410        }  
2411       outbothnonl "Used volumes:   $used_volumes   Unused volumes:   $unused_volumes"
2412     outbothnonl "Used volumes:   $used_volumes   Unused volumes:   $unused_volumes"     outboth .
2413     outboth .     outboth "Enumeration of used volumes (if any):"
2414     outboth "Enumeration of used volumes (if any):"     set N [llength $bookVolumeList]
2415     set N [llength $bookVolumeList]     #Iterate through the list, taking notes.
2416     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
2417     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        #outboth "i: $i"
2418        #outboth "i: $i"        if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \
2419        if {[get_volume_used_flag [lindex $bookVolumeList $i]]} { \           outboth "   [lindex $bookVolumeList $i]"
2420           outboth "   [lindex $bookVolumeList $i]"           }
2421           }        }
2422        }     outboth "Enumeration of unused volumes (if any):"
2423     outboth "Enumeration of unused volumes (if any):"     set N [llength $bookVolumeList]
2424     set N [llength $bookVolumeList]     #Iterate through the list, taking notes.
2425     #Iterate through the list, taking notes.     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \
2426     for {set i 0} {$i < $N} {incr i $bookVolumeListStructSize} { \        #outboth "i: $i"
2427        #outboth "i: $i"        if { ! [get_volume_used_flag [lindex $bookVolumeList $i]]} { \
2428        if { ! [get_volume_used_flag [lindex $bookVolumeList $i]]} { \           outboth "   [lindex $bookVolumeList $i]"
2429           outboth "   [lindex $bookVolumeList $i]"           }
2430           }        }
2431        }  
2432       #Delete all the output files.  This guards against misunderstandings and accidents.  In the deletion of output
2433     #Delete all the output files.  This guards against misunderstandings and accidents.  In the deletion of output     #files, whether volumes are used or not is not taken into account.  The reason for this is neatness--if
2434     #files, whether volumes are used or not is not taken into account.  The reason for this is neatness--if     #the list of used volumes changes, it is helpful to get all of those files gone.
2435     #the list of used volumes changes, it is helpful to get all of those files gone.  
2436       #Delete the two single-volume files.
2437     #Delete the two single-volume files.     set pathbase ""
2438     set pathbase ""     append pathbase $pathUcBookA / sv
2439     append pathbase $pathUcBookA / sv     #set svlist {f.dvi f.ps f.pdf d.dvi d.ps d.pdf}
2440     #set svlist {f.dvi f.ps f.pdf d.dvi d.ps d.pdf}     set svlist {f.dvi f.ps f.pdf}
2441     set svlist {f.dvi f.ps f.pdf}     set N [llength $svlist]
2442     set N [llength $svlist]  
2443       #Iterate through, delete each single-volume file.
2444     #Iterate through, delete each single-volume file.     for {set i 0} {$i < $N} {incr i} { \
2445     for {set i 0} {$i < $N} {incr i} { \        set target $pathbase
2446        set target $pathbase        append target [lindex $svlist $i]
2447        append target [lindex $svlist $i]  
2448          if {[file exists $target]} { \
2449        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2450           outbothnonl "Deleting $target"           outboth .
2451           outboth .           file delete $target
2452           file delete $target           } \
2453           } \        else {
2454        else {           outboth "Skipping $target : file does not exist."
2455           outboth "Skipping $target : file does not exist."           }
2456           }        }        
2457        }          
2458       #Get number of elements in the list of volumes.
2459     #Get number of elements in the list of volumes.     set N [llength $bookVolumeList]
2460     set N [llength $bookVolumeList]  
2461       #Iterate through, delete each file.
2462     #Iterate through, delete each file.     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \
2463     for {set volnum 0} {$volnum < $N} {incr volnum $bookVolumeListStructSize} { \        set voltag [lindex $bookVolumeList $volnum]
2464        set voltag [lindex $bookVolumeList $volnum]  
2465          set target ""
2466        set target ""        append target $pathUcBookA / $voltag .dvi
2467        append target $pathUcBookA / $voltag .dvi  
2468          if {[file exists $target]} { \
2469        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2470           outbothnonl "Deleting $target"           outboth .
2471           outboth .           file delete $target
2472           file delete $target           } \
2473           } \        else {
2474        else {           outboth "Skipping $target : file does not exist."
2475           outboth "Skipping $target : file does not exist."           }
2476           }  
2477          set target ""
2478        set target ""        append target $pathUcBookA / $voltag .ps
2479        append target $pathUcBookA / $voltag .ps  
2480          if {[file exists $target]} { \
2481        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2482           outbothnonl "Deleting $target"           outboth .
2483           outboth .           file delete $target
2484           file delete $target           } \
2485           } \        else {
2486        else {           outboth "Skipping $target : file does not exist."
2487           outboth "Skipping $target : file does not exist."           }
2488           }  
2489          set target ""
2490        set target ""        append target $pathUcBookA / $voltag .pdf
2491        append target $pathUcBookA / $voltag .pdf  
2492          if {[file exists $target]} { \
2493        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2494           outbothnonl "Deleting $target"           outboth .
2495           outboth .           file delete $target
2496           file delete $target           } \
2497           } \        else {
2498        else {           outboth "Skipping $target : file does not exist."
2499           outboth "Skipping $target : file does not exist."           }
2500           }  
2501          set target ""
2502        set target ""        append target $pathUcBookA / $voltag .idx
2503        append target $pathUcBookA / $voltag .idx  
2504          if {[file exists $target]} { \
2505        if {[file exists $target]} { \           outbothnonl "Deleting $target"
2506           outbothnonl "Deleting $target"           outboth .