0024147: Update of CSharp sample
[occt.git] / dox / occdoc.tcl
1 # -----------------------------------------------------------------------
2 #  Script name: CompileDocs.tcl
3 #  This script compiles OCCT documents from *.md files to HTML pages
4 #  Author: omy
5 # -----------------------------------------------------------------------
6
7 # Generates Doxygen configuration file for Overview documentation
8 proc OverviewDoc_MakeDoxyfile {casDir outDir tagFileDir {doxyFileName} {generatorMode ""} DocFilesList verboseMode} {
9
10     if {$verboseMode == "YES"} {
11         puts "INFO: Doxygen is now generating Doxyfile..."
12     }
13
14     set doxyFile [open $doxyFileName "w"]
15     set casroot  $casDir
16     set inputDir $casDir/dox
17
18     # Common configs
19     puts $doxyFile "DOXYFILE_ENCODING      = UTF-8"
20     puts $doxyFile "PROJECT_NAME           = \"Open CASCADE Technology\""
21     puts $doxyFile "PROJECT_NUMBER         = 6.6.0"
22     puts $doxyFile "PROJECT_BRIEF          = "
23     puts $doxyFile "PROJECT_LOGO           = $inputDir/resources/occt_logo.png"
24
25     puts $doxyFile "OUTPUT_DIRECTORY       = $outDir"
26     puts $doxyFile "CREATE_SUBDIRS         = NO"
27     puts $doxyFile "OUTPUT_LANGUAGE        = English"
28     puts $doxyFile "ABBREVIATE_BRIEF       = \"The \$name class\" \
29                                              \"The \$name widget\" \
30                                              \"The \$name file\" \
31                                              is \
32                                              provides \
33                                              specifies \
34                                              contains \
35                                              represents \
36                                              a \
37                                              an \
38                                              the"
39
40     puts $doxyFile "FULL_PATH_NAMES        = YES"
41     puts $doxyFile "INHERIT_DOCS           = YES"
42     puts $doxyFile "TAB_SIZE               = 4"
43     puts $doxyFile "MARKDOWN_SUPPORT       = YES"
44     puts $doxyFile "EXTRACT_ALL            = YES"
45     puts $doxyFile "CASE_SENSE_NAMES       = NO"
46     puts $doxyFile "INLINE_INFO            = YES"
47     puts $doxyFile "SORT_MEMBER_DOCS       = YES"
48     puts $doxyFile "WARNINGS               = YES"
49     puts $doxyFile "WARN_IF_UNDOCUMENTED   = YES"
50     puts $doxyFile "WARN_IF_DOC_ERROR      = YES"
51     puts $doxyFile "WARN_NO_PARAMDOC       = NO"
52     puts $doxyFile "WARN_FORMAT            = \"\$file:\$line: \$text\""
53     puts $doxyFile "INPUT_ENCODING         = UTF-8"
54     puts $doxyFile "FILE_PATTERNS          = *.md *.dox "
55     puts $doxyFile "RECURSIVE              = YES"
56     puts $doxyFile "SOURCE_BROWSER         = NO"
57     puts $doxyFile "INLINE_SOURCES         = YES"
58     puts $doxyFile "COLS_IN_ALPHA_INDEX    = 5"
59     
60     # Generation options
61     puts $doxyFile "GENERATE_DOCSET        = NO"
62     puts $doxyFile "GENERATE_HTMLHELP      = NO"
63     puts $doxyFile "GENERATE_CHI           = NO"
64     puts $doxyFile "GENERATE_QHP           = NO"
65     puts $doxyFile "GENERATE_ECLIPSEHELP   = NO"
66     puts $doxyFile "GENERATE_RTF           = NO"
67     puts $doxyFile "GENERATE_MAN           = NO"
68     puts $doxyFile "GENERATE_XML           = NO"
69     puts $doxyFile "GENERATE_DOCBOOK       = NO"
70     puts $doxyFile "GENERATE_AUTOGEN_DEF   = NO"
71     puts $doxyFile "GENERATE_PERLMOD       = NO"
72
73     set PARAM_INPUT "INPUT                  = "
74     set PARAM_IMAGEPATH "IMAGE_PATH         = $inputDir/resources/ "
75
76     foreach docFile $DocFilesList {
77         set NEW_IMG_PATH [file normalize [file dirname "$inputDir/$docFile"]]
78         if { [string compare $NEW_IMG_PATH $casroot] != 0 } {
79           if {[file isdirectory "$NEW_IMG_PATH/images"]} {
80             append PARAM_IMAGEPATH " " "$NEW_IMG_PATH/images"
81           }
82         }
83         append PARAM_INPUT " " $inputDir/$docFile
84     }
85     puts $doxyFile $PARAM_INPUT
86     puts $doxyFile $PARAM_IMAGEPATH
87     
88     if { $generatorMode == "PDF_ONLY"} {
89         set PARAM_LATEX_EF "LATEX_EXTRA_FILES      ="
90         foreach docFile $DocFilesList {
91             set NEW_LEF_PATH [file normalize [file dirname "$inputDir/$docFile"]]
92             if { [string compare $NEW_LEF_PATH $casroot] != 0 } {
93                 append PARAM_LATEX_EF " " "$NEW_LEF_PATH/images"
94             }
95         }
96         puts $doxyFile $PARAM_LATEX_EF
97     }
98
99     if { $generatorMode == "HTML_ONLY"} {
100         # Set a reference to a TAGFILE
101         if { $tagFileDir != "" } {
102             if {[file exists $tagFileDir/OCCT.tag] == 1} {
103                 set tagPath [OverviewDoc_GetRelPath $tagFileDir $outDir/html]
104                 puts $doxyFile "TAGFILES               = $tagFileDir/OCCT.tag=$tagPath/html"
105             }
106         }
107
108         # HTML Output
109         puts $doxyFile "GENERATE_LATEX         = NO"
110         puts $doxyFile "GENERATE_HTML          = YES"
111         puts $doxyFile "HTML_COLORSTYLE_HUE    = 220"
112         puts $doxyFile "HTML_COLORSTYLE_SAT    = 100"
113         puts $doxyFile "HTML_COLORSTYLE_GAMMA  = 80"
114         puts $doxyFile "HTML_TIMESTAMP         = YES"
115         puts $doxyFile "HTML_DYNAMIC_SECTIONS  = YES"
116         puts $doxyFile "HTML_INDEX_NUM_ENTRIES = 100"
117         puts $doxyFile "DISABLE_INDEX          = YES"
118         puts $doxyFile "GENERATE_TREEVIEW      = YES"
119         puts $doxyFile "ENUM_VALUES_PER_LINE   = 8"
120         puts $doxyFile "TREEVIEW_WIDTH         = 250"
121         puts $doxyFile "EXTERNAL_PAGES         = NO"
122         puts $doxyFile "SEARCHENGINE           = YES"
123         puts $doxyFile "SERVER_BASED_SEARCH    = NO"
124         puts $doxyFile "EXTERNAL_SEARCH        = NO"
125         puts $doxyFile "SEARCHDATA_FILE        = searchdata.xml"
126         puts $doxyFile "SKIP_FUNCTION_MACROS   = YES"
127         # Formula options
128         puts $doxyFile "FORMULA_FONTSIZE       = 12"
129         puts $doxyFile "FORMULA_TRANSPARENT    = YES"
130         puts $doxyFile "USE_MATHJAX            = YES"
131         puts $doxyFile "MATHJAX_FORMAT         = HTML-CSS"
132         puts $doxyFile "MATHJAX_RELPATH        = http://cdn.mathjax.org/mathjax/latest"
133         
134     } elseif { $generatorMode == "PDF_ONLY"} {
135         
136         puts $doxyFile "GENERATE_HTML          = NO"
137         puts $doxyFile "DISABLE_INDEX          = YES"
138         puts $doxyFile "GENERATE_TREEVIEW      = NO"
139         puts $doxyFile "PREDEFINED             = PDF_ONLY"
140         puts $doxyFile "GENERATE_LATEX         = YES"
141         puts $doxyFile "COMPACT_LATEX          = YES"
142         puts $doxyFile "PDF_HYPERLINKS         = YES"
143         puts $doxyFile "USE_PDFLATEX           = YES"
144         puts $doxyFile "LATEX_BATCHMODE        = YES"
145         puts $doxyFile "LATEX_OUTPUT           = latex"
146         puts $doxyFile "LATEX_CMD_NAME         = latex"
147         puts $doxyFile "MAKEINDEX_CMD_NAME     = makeindex"
148     }
149
150     close $doxyFile 
151 }
152
153 # Returns the relative path between two directories
154 proc OverviewDoc_GetRelPath {targetFile currentpath} {
155   set cc [file split [file normalize $currentpath]]
156   set tt [file split [file normalize $targetFile]]
157   
158   if {![string equal [lindex $cc 0] [lindex $tt 0]]} {
159       # not on *n*x then
160       return -code error "$targetFile not on same volume as $currentpath"
161   }
162   while {[string equal [lindex $cc 0] [lindex $tt 0]] && [llength $cc] > 0} {
163       # discard matching components from the front
164       set cc [lreplace $cc 0 0]
165       set tt [lreplace $tt 0 0]
166   }
167   set prefix ""
168   if {[llength $cc] == 0} {
169       # just the file name, so targetFile is lower down (or in same place)
170       set prefix "."
171   }
172   # step up the tree
173   for {set i 0} {$i < [llength $cc]} {incr i} {
174       append prefix " .."
175   }
176   # stick it all together (the eval is to flatten the targetFile list)
177   return [eval file join $prefix $tt]
178 }
179
180 # Prints Help message
181 proc OverviewDoc_PrintHelpMessage {} {
182     puts "\nUsage : occdoc \[-h\] \[-html\] \[-pdf\] \[-m=<list of files>\] \[-l=<document name>\] \[-v\]"
183     puts ""
184     puts " Options are : "
185     puts "    -html                : To generate HTML files"
186     puts "                           (cannot be used with -pdf)"
187     puts "    -pdf                 : To generate PDF files"
188     puts "                           (cannot be used with -html)"
189     puts "    -m=<modules_list>    : Specifies list of documents to generate."
190     puts "                           If it is not specified, all files, "
191     puts "                           mentioned in FILES.txt are processed."
192     puts "    -l=<document_name>   : Specifies the document caption "
193     puts "                           for a single document"
194     puts "    -h                   : Prints help message"
195     puts "    -v                   : Specifies the Verbose mode"
196     puts "                           (info on all script actions is shown)"
197 }
198
199 # Parses command line arguments
200 proc OverviewDoc_ParseArguments {arguments} {
201     global args_names
202     global args_values
203     set args_names {}
204     array set args_values {}
205
206     foreach arg $arguments {
207         if {[regexp {^(-)[a-z]+$} $arg] == 1} {
208             set name [string range $arg 1 [string length $arg]-1]
209             lappend args_names $name
210             set args_values($name) "NULL"
211             continue
212         } elseif {[regexp {^(-)[a-z]+=.+$} $arg] == 1} {
213             set equal_symbol_position [string first "=" $arg]
214             set name [string range $arg 1 $equal_symbol_position-1]
215             lappend args_names $name
216             set value [string range $arg $equal_symbol_position+1 [string length $arguments]-1]
217             
218             # To parse a list of values for -m parameter
219             if { [string first "," $value] != -1 } {
220                 set value [split $value ","];
221             }
222             set args_values($name) $value
223         } else {
224             puts "Error in argument $arg"
225             return 1
226         }
227     }
228     return 0
229 }
230
231 # Loads a list of docfiles from file FILES.txt
232 proc OverviewDoc_LoadFilesList {} {
233
234     set INPUTDIR [file normalize [file dirname [info script]]]
235     
236     global available_docfiles
237     set available_docfiles {}
238
239     # Read data from file
240     if { [file exists "$INPUTDIR/FILES.txt"] == 1 } {
241         set FILE [open "$INPUTDIR/FILES.txt" r]
242         while {1} {
243             set line [gets $FILE]
244             if {$line != ""} {
245               lappend available_docfiles $line
246             }
247
248             if {[eof $FILE]} {
249                 close $FILE
250                 break
251             }
252         }
253     } else {
254         return -1
255     }
256     return 0
257 }
258
259 # Writes new tex file for conversion from tex to pdf for a specific doc
260 proc OverviewDoc_MakeRefmanTex {fileName latexDir docLabel verboseMode} {
261
262     if {$verboseMode == "YES"} {
263         puts "INFO: Making refman.tex file for $fileName"
264     }
265     set DOCNAME "$latexDir/refman.tex"
266     if {[file exists $DOCNAME] == 1} {
267         file delete -force $DOCNAME
268     }
269     set texfile [open $DOCNAME w]
270
271     puts $texfile "\\batchmode"
272     puts $texfile "\\nonstopmode"
273     puts $texfile "\\documentclass\[oneside\]{article}"
274     puts $texfile "\n% Packages required by doxygen"
275     puts $texfile "\\usepackage{calc}"
276     puts $texfile "\\usepackage{doxygen}"
277     puts $texfile "\\usepackage{graphicx}"
278     puts $texfile "\\usepackage\[utf8\]{inputenc}"
279     puts $texfile "\\usepackage{makeidx}"
280     puts $texfile "\\usepackage{multicol}"
281     puts $texfile "\\usepackage{multirow}"
282     puts $texfile "\\usepackage{textcomp}"
283     puts $texfile "\\usepackage{amsmath}"
284     puts $texfile "\\usepackage\[table\]{xcolor}"
285     puts $texfile "\\usepackage{indentfirst}"
286     puts $texfile ""
287     puts $texfile "% Font selection"
288     puts $texfile "\\usepackage\[T1\]{fontenc}"
289     puts $texfile "\\usepackage{mathptmx}"
290     puts $texfile "\\usepackage\[scaled=.90\]{helvet}"
291     puts $texfile "\\usepackage{courier}"
292     puts $texfile "\\usepackage{amssymb}"
293     puts $texfile "\\usepackage{sectsty}"
294     puts $texfile "\\renewcommand{\\familydefault}{\\sfdefault}"
295     puts $texfile "\\allsectionsfont{%"
296     puts $texfile "  \\fontseries{bc}\\selectfont%"
297     puts $texfile "  \\color{darkgray}%"
298     puts $texfile "}"
299     puts $texfile "\\renewcommand{\\DoxyLabelFont}{%"
300     puts $texfile "  \\fontseries{bc}\\selectfont%"
301     puts $texfile "  \\color{darkgray}%"
302     puts $texfile "}"
303     puts $texfile ""
304     puts $texfile "% Page & text layout"
305     puts $texfile "\\usepackage{geometry}"
306     puts $texfile "\\geometry{%"
307     puts $texfile "  a4paper,%"
308     puts $texfile "  top=2.5cm,%"
309     puts $texfile "  bottom=2.5cm,%"
310     puts $texfile "  left=2.5cm,%"
311     puts $texfile "  right=2.5cm%"
312     puts $texfile "}"
313     puts $texfile "\\tolerance=750"
314     puts $texfile "\\hfuzz=15pt"
315     puts $texfile "\\hbadness=750"
316     puts $texfile "\\setlength{\\emergencystretch}{15pt}"
317     puts $texfile "\\setlength{\\parindent}{0.75cm}"
318     puts $texfile "\\setlength{\\parskip}{0.2cm}"
319     puts $texfile "\\makeatletter"
320     puts $texfile "\\renewcommand{\\paragraph}{%"
321     puts $texfile "  \@startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{%"
322     puts $texfile "\\normalfont\\normalsize\\bfseries\\SS@parafont%"
323     puts $texfile "  }%"
324     puts $texfile "}"
325     puts $texfile "\\renewcommand{\\subparagraph}{%"
326     puts $texfile "  \\@startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{%"
327     puts $texfile "\\normalfont\\normalsize\\bfseries\\SS@subparafont%"
328     puts $texfile "  }%"
329     puts $texfile "}"
330     puts $texfile "\\makeatother"
331     puts $texfile ""
332     puts $texfile "% Headers & footers"
333     puts $texfile "\\usepackage{fancyhdr}"
334     puts $texfile "\\pagestyle{fancyplain}"
335     puts $texfile "\\fancyhead\[LE\]{\\fancyplain{}{\\bfseries\\thepage}}"
336     puts $texfile "\\fancyhead\[CE\]{\\fancyplain{}{}}"
337     puts $texfile "\\fancyhead\[RE\]{\\fancyplain{}{\\bfseries\\leftmark}}"
338     puts $texfile "\\fancyhead\[LO\]{\\fancyplain{}{\\bfseries\\rightmark}}"
339     puts $texfile "\\fancyhead\[CO\]{\\fancyplain{}{}}"
340     puts $texfile "\\fancyhead\[RO\]{\\fancyplain{}{\\bfseries\\thepage}}"
341     puts $texfile "\\fancyfoot\[LE\]{\\fancyplain{}{}}"
342     puts $texfile "\\fancyfoot\[CE\]{\\fancyplain{}{}}"
343     puts $texfile "\\fancyfoot\[RE\]{\\fancyplain{}{\\bfseries\\scriptsize Â© Open CASCADE Technology 2001\-2013}}"
344     puts $texfile "\\fancyfoot\[LO\]{\\fancyplain{}{\\bfseries\\scriptsize Â© Open CASCADE Technology 2001\-2013}}"
345     puts $texfile "\\fancyfoot\[CO\]{\\fancyplain{}{}}"
346     puts $texfile "\\fancyfoot\[RO\]{\\fancyplain{}{}}"
347     puts $texfile "\\renewcommand{\\footrulewidth}{0.4pt}"
348     puts $texfile "\\renewcommand{\\sectionmark}\[1\]{%"
349     puts $texfile "  \\markright{\\thesection\\ #1}%"
350     puts $texfile "}"
351     puts $texfile ""
352     puts $texfile "% Indices & bibliography"
353     puts $texfile "\\usepackage{natbib}"
354     puts $texfile "\\usepackage\[titles\]{tocloft}"
355     puts $texfile "\\renewcommand{\\cftsecleader}{\\cftdotfill{\\cftdotsep}}"
356     puts $texfile "\\setcounter{tocdepth}{3}"
357     puts $texfile "\\setcounter{secnumdepth}{5}"
358     puts $texfile "\\makeindex"
359     puts $texfile ""
360     puts $texfile "% Hyperlinks (required, but should be loaded last)"
361     puts $texfile "\\usepackage{ifpdf}"
362     puts $texfile "\\ifpdf"
363     puts $texfile "  \\usepackage\[pdftex,pagebackref=true\]{hyperref}"
364     puts $texfile "\\else"
365     puts $texfile "  \\usepackage\[ps2pdf,pagebackref=true\]{hyperref}"
366     puts $texfile "\\fi"
367     puts $texfile "\\hypersetup{%"
368     puts $texfile "  colorlinks=true,%"
369     puts $texfile "  linkcolor=black,%"
370     puts $texfile "  citecolor=black,%"
371     puts $texfile "  urlcolor=blue,%"
372     puts $texfile "  unicode%"
373     puts $texfile "}"
374     puts $texfile ""
375     puts $texfile "% Custom commands"
376     puts $texfile "\\newcommand{\\clearemptydoublepage}{%"
377     puts $texfile "  \\newpage{\\pagestyle{empty}\\cleardoublepage}%"
378     puts $texfile "}"
379     puts $texfile "\n"
380     puts $texfile "%===== C O N T E N T S =====\n"
381     puts $texfile "\\begin{document}"
382     puts $texfile ""
383     puts $texfile "% Titlepage & ToC"
384     puts $texfile "\\hypersetup{pageanchor=false}"
385     puts $texfile "\\pagenumbering{roman}"
386     puts $texfile "\\begin{titlepage}"
387     puts $texfile "\\vspace*{7cm}"
388     puts $texfile "\\begin{center}%"
389     puts $texfile "\\includegraphics\[width=0.75\\textwidth, height=0.2\\textheight\]{occttransparent.png}\\\\\\\\"
390     puts $texfile "{\\Large Open C\\-A\\-S\\-C\\-A\\-D\\-E Technology \\\\\[1ex\]\\Large 6.\\-6.\\-0 }\\\\"
391     puts $texfile "\\vspace*{1cm}"
392     puts $texfile "{\\Large $docLabel}\\\\"
393     puts $texfile "\\vspace*{1cm}"
394     puts $texfile "{\\large Generated by Doxygen 1.8.4}\\\\"
395     puts $texfile "\\vspace*{0.5cm}"
396     puts $texfile "{\\small \\today}\\"
397     puts $texfile "\\end{center}"
398     puts $texfile "\\end{titlepage}"
399     puts $texfile "\\clearpage"
400     puts $texfile "\\pagenumbering{roman}"
401     puts $texfile "\\tableofcontents"
402     puts $texfile "\\newpage"
403     puts $texfile "\\pagenumbering{arabic}"
404     puts $texfile "\\hypersetup{pageanchor=true}"
405     puts $texfile ""
406     puts $texfile "\\hypertarget{$fileName}{}"
407     puts $texfile "\\input{$fileName}"
408     puts $texfile ""
409     puts $texfile "% Index"
410     puts $texfile "\\newpage"
411     puts $texfile "\\phantomsection"
412     puts $texfile "\\addcontentsline{toc}{part}{Index}"
413     puts $texfile "\\printindex\n"
414     puts $texfile "\\end{document}"
415
416     close $texfile
417 }
418
419 # Postprocesses generated TeX files
420 proc OverviewDoc_ProcessTex {{texFiles {}} {latexDir} verboseMode} {
421
422     foreach TEX $texFiles {
423         if {$verboseMode == "YES"} {
424             puts "INFO: Preprocessing file $TEX"
425         }
426         set IN_F  [open "$TEX" r]
427         set TMPFILENAME "$latexDir/temp.tex"
428         set OUT_F [open $TMPFILENAME w]
429         
430         while {1} {
431             set line [gets $IN_F]
432             if { [string first "\\includegraphics" $line] != -1 } {
433                 # Center images in TeX files
434                 set line "\\begin{center}\n $line\n\\end{center}"
435             } elseif { [string first "\\subsection" $line] != -1 } {
436                 # Replace \subsection with \section tag
437                 regsub -all "\\\\subsection" $line "\\\\section" line
438             } elseif { [string first "\\subsubsection" $line] != -1 } {
439                 # Replace \subsubsection with \subsection tag
440                 regsub -all "\\\\subsubsection" $line "\\\\subsection" line
441             } elseif { [string first "\\paragraph" $line] != -1 } {
442                 # Replace \paragraph with \subsubsection tag
443                 regsub -all "\\\\paragraph" $line "\\\\subsubsection" line
444             }
445             puts $OUT_F $line
446             
447             if {[eof $IN_F]} {
448                 close $IN_F
449                 close $OUT_F
450                 break
451             }
452         }
453         file delete -force $TEX
454         file rename $TMPFILENAME $TEX
455     }
456 }
457
458 # Main procedure for documents compilation
459 proc OverviewDoc_Main { {docfiles {}} generatorMode docLabel verboseMode} {
460
461     set INDIR      [file normalize [file dirname [info script]]]
462     set CASROOT    [file normalize [file dirname "$INDIR/../../"]]
463     set OUTDIR     $CASROOT/doc
464     set PDFDIR     $OUTDIR/overview/pdf
465     set HTMLDIR    $OUTDIR/overview/html
466     set LATEXDIR   $OUTDIR/overview/latex
467     set TAGFILEDIR $OUTDIR/refman
468     set DOXYFILE   $OUTDIR/OCCT.cfg
469
470     # Create or clean the output folders
471     if {[file exists $OUTDIR] == 0} {
472         file mkdir $OUTDIR
473     } 
474     if {[file exists $HTMLDIR] == 0} {
475         file mkdir $HTMLDIR
476     }
477     if {[file exists $LATEXDIR] == 0} {
478         file mkdir $LATEXDIR
479     }
480     if {[file exists $PDFDIR] == 0} {
481         file mkdir $PDFDIR
482     }
483
484     # Run tools to compile documents
485     puts ""
486     puts " [clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Generation process started..."
487     puts ""
488     puts " Please, wait while Doxygen finishes it\'s work"
489     OverviewDoc_MakeDoxyfile $CASROOT "$OUTDIR/overview" $TAGFILEDIR $DOXYFILE $generatorMode $docfiles $verboseMode
490
491     # Run doxygen tool
492     if { $generatorMode == "HTML_ONLY"} {
493         puts " [clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Doxygen is now generating HTML files...\n"
494     }
495     set RESULT [catch {exec doxygen $DOXYFILE > $OUTDIR/doxygen_out.log} DOX_ERROR] 
496     if {$RESULT != 0} {
497         if {[llength [split $DOX_ERROR "\n"]] > 1} {
498             if {$verboseMode == "YES"} {
499                 puts "INFO: See Doxygen messages in $OUTDIR/doxygen_warnings_and_errors.log"
500             }
501             set DOX_ERROR_FILE [open "$OUTDIR/doxygen_warnings_and_errors.log" "w"]
502             puts $DOX_ERROR_FILE $DOX_ERROR
503             close $DOX_ERROR_FILE
504         } else {
505             puts $DOX_ERROR
506         }
507     }
508     # Close the Doxygen application
509     after 300
510
511     # Start PDF generation routine
512     if { $generatorMode == "PDF_ONLY" } {
513         puts ""
514         puts " [clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Doxygen is now generating PDF files...\n"
515
516         set OS $::tcl_platform(platform)
517         if { $OS == "unix" } {
518             set PREFIX ".sh"
519         } elseif { $OS == "windows" } {
520             set PREFIX ".bat"
521         }
522
523         # Prepare a list of TeX files, generated by Doxygen
524         cd $LATEXDIR
525         
526         set TEXFILES [glob $LATEXDIR -type f -directory $LATEXDIR -tails "*.tex" ]
527         set REFMAN_IDX [lsearch $TEXFILES "refman.tex"]
528         set TEXFILES [lreplace $TEXFILES $REFMAN_IDX $REFMAN_IDX]
529         set REFMAN_IDX [lsearch $TEXFILES "index.tex"]
530         set TEXFILES [lreplace $TEXFILES $REFMAN_IDX $REFMAN_IDX]
531
532         set IDX [lsearch $TEXFILES "$LATEXDIR"]
533         while { $IDX != -1} {
534             set TEXFILES [lreplace $TEXFILES $IDX $IDX]
535             set IDX [lsearch $TEXFILES "$LATEXDIR"]
536         }
537
538         # Preprocess generated TeX files
539         OverviewDoc_ProcessTex $TEXFILES $LATEXDIR $verboseMode
540
541         # Generate PDF files from 
542         foreach TEX $TEXFILES {
543             # Rewrite existing REFMAN.tex file...
544             set TEX [string range $TEX 0 [ expr "[string length $TEX] - 5"]]
545             OverviewDoc_MakeRefmanTex $TEX $LATEXDIR $docLabel $verboseMode
546             
547             if {$verboseMode == "YES"} {
548                 puts "INFO: Generating PDF file from $TEX"
549             }
550             # ...and use it to generate PDF from TeX...
551             set RESULT [catch {eval exec [auto_execok $LATEXDIR/make$PREFIX] > "$OUTDIR/pdflatex_out.log"} LaTeX_ERROR]
552             if {$RESULT != 0} {
553                 if {[llength [split $LaTeX_ERROR "\n"]] > 1} {
554                     set LaTeX_ERROR_FILE [open "$OUTDIR/pdflatex_warnings_and_errors.log" "w"]
555                     puts $LaTeX_ERROR_FILE $LaTeX_ERROR
556                     close $LaTeX_ERROR_FILE
557                 } else {
558                     puts $DOX_ERROR
559                 }
560             }
561
562             # ...and place it to the specific folder
563             if { [file exists $PDFDIR/$TEX.pdf] == 1 } {
564                 file delete -force $PDFDIR/$TEX.pdf
565             }
566             file rename $LATEXDIR/refman.pdf "$PDFDIR/$TEX.pdf"
567         }
568         if {$verboseMode == "YES"} {
569             puts "INFO: See LaTeX messages in $OUTDIR/pdflatex_warnings_and_errors.log"
570         }
571     }
572
573     cd $INDIR
574     puts " [clock format [clock seconds] -format {%Y.%m.%d %H:%M}] Generation process finished..."
575     puts ""
576     puts "--------------------------------------------------------------------"
577     if { $generatorMode == "HTML_ONLY" } {
578         puts " You can look at generated HTML pages by opening: "
579         set RESFILE $OUTDIR/overview/html/index.html
580         puts " $RESFILE"
581     }
582     if { $generatorMode == "PDF_ONLY" } {
583         puts " You can look at generated PDF files in: "
584         puts " $OUTDIR/overview/pdf folder"
585     }
586     puts ""
587     puts " Copyright \u00a9 Open CASCADE Technology 2001-2013"
588     puts "--------------------------------------------------------------------\n"
589 }
590
591 # A command for User Documentation compilation
592 proc occdoc {args} {
593     # Programm options
594     set GEN_HTML  "NO"
595     set GEN_PDF   "NO"
596     set DOCFILES  {}
597     set DOCLABEL  "Default OCCT Document"
598     set VERB_MODE "NO"
599     set GEN_MODE  "DEFAULT"
600     global available_docfiles
601     global args_names
602     global args_values
603
604     # Load list of docfiles
605     if { [OverviewDoc_LoadFilesList] != 0 } {
606         puts "ERROR: File FILES.txt was not found"
607         return
608     }
609
610     # Parse CL arguments
611     if {[OverviewDoc_ParseArguments $args] == 1} {
612         return
613     }
614     if {$args_names == {}} {
615         set GEN_HTML "YES"
616         set VERB_MODE "YES"
617     } else {
618         foreach arg_n $args_names {
619             if {$arg_n == "h"} {
620               OverviewDoc_PrintHelpMessage
621               return
622             } elseif {$arg_n == "html"} {
623                 set GEN_HTML "YES"
624             } elseif {$arg_n == "pdf"} {
625                 set GEN_PDF "YES"
626             } elseif {$arg_n == "v"} {
627                 set VERB_MODE "YES"
628             } elseif {$arg_n == "m"} {
629                 if {$args_values(m) != "NULL"} {
630                     set DOCFILES $args_values(m)
631                 } else {
632                     puts "Error in argument m"
633                     return
634                 }
635                 # Check if all chosen docfiles are correct
636                 foreach docfile $DOCFILES {
637                     if { [lsearch $available_docfiles $docfile] == -1 } {
638                         puts "File \"$docfile\" is not presented in the list of available docfiles"
639                         puts "Please, specify the correct docfile name"
640                         return
641                     } else {
642                         puts "File $docfile is presented in FILES.TXT"
643                     }
644                 }
645             } elseif {$arg_n == "l"} {
646                 if { [llength $DOCFILES] <= 1 } {
647                     if {$args_values(l) != "NULL"} {
648                         set DOCLABEL $args_values(l)
649                     } else {
650                         puts "Error in argument l"
651                         return
652                     }
653                 }
654             } else {
655                 puts "\nWrong argument: $arg_n"
656                 OverviewDoc_PrintHelpMessage
657                 return
658             }
659         }
660     }
661
662     # Specify generation mode
663     if {$GEN_HTML == "YES" && $GEN_PDF == "NO"} {
664         set GEN_MODE "HTML_ONLY"
665     } elseif {$GEN_PDF == "YES"} {
666         set GEN_MODE "PDF_ONLY"
667     }
668     # Check if -v is the only option
669     if {$GEN_MODE == "DEFAULT"} {
670         if { $VERB_MODE == "YES" } {
671             puts "\nArgument -v can't be used without -pdf or -html argument"
672             OverviewDoc_PrintHelpMessage
673         }
674         return
675     }
676     
677     # Specify verbose mode
678     if { $GEN_PDF != "YES" && [llength $DOCFILES] > 1 } {
679         set DOCLABEL ""
680     }
681     
682     # If we don't specify list for docfiles with -m argument,
683     # we assume that we have to generate all docfiles
684     if { [llength $DOCFILES] == 0 } {
685         set DOCFILES $available_docfiles
686     }
687
688     # Start main activities
689     OverviewDoc_Main $DOCFILES $GEN_MODE $DOCLABEL $VERB_MODE
690 }