Debian Codegraph @

utils/texdoctk/texdoctk.pl

raw
1 #! /usr/bin/env perl
2 ###############################################################################
3 # texdoctk - GUI for TeX documentation access
4 # Copyright (C) 2000-2004 Thomas Ruedas
5 # Updated in 2010 by Manuel Pegourie-Gonnard
6 # Trivial non-code updates in 2012 by Karl Berry
7 # Patch from Debian for "texdoctk-warn-missing-perltk" installed in 2019
8 # by Karl Berry.
9 # (This program is looking for a maintainer, email [email protected].)
10 #
11 # This program is provided under the GNU Public License; see the texdoctk
12 # README for details about requirements, installation, configuration,
13 # and the full disclaimer.
14 ###############################################################################
15 my ($version, $date) = ("0.6.1", "2012-12-23");
16 use strict;
17 use Getopt::Long;
18 Getopt::Long::config('bundling');
19 use File::Basename;
20
21 BEGIN {
22 Win32::SetChildShowWindow(0) if defined &Win32::SetChildShowWindow;
23 }
24
25 my $IsWin32 = ($^O =~ /MSWin32/i);
26
27 if ($IsWin32) {
28 require Win32::API;
29 # Win32::API->import( qw(
30 # &something
31 # ));
32 }
33
34 eval { require Tk; };
35 if ($@) {
36 if (-x "/usr/bin/xmessage") {
37 `xmessage -center -buttons Quit "The program texdoctk needs the package perl-tk, please install it!"`;
38 } else {
39 printf STDERR "The program texdoctk needs the package perl-tk, please install it!\n";
40 }
41 exit(1);
42 # that didn't work out, so warn the user and continue with text mode
43 } else {
44 Tk->import;
45 }
46
47
48 # initialization of some internal variables
49 $|=1;
50 my $quiet=1;
51 my $autoview;
52 my $xfmt_viewer=1,
53 my @tdcolors;
54 my %butcol;
55 my $srchentry;
56 my $srchflag=0;
57 my $srchtype; # 0 = database, 1 = texdoc
58 my $tmpfno;
59 # system variables
60 my ($texmfmain,$texmfdist,$texmfdoc,$texmflocal,$texmfhome,
61 $texdocpath,$distdocpath,$docdocpath,$localdocpath,$homedocpath,
62 $datadir,
63 $dvi_viewer,$dvips_conv,$ps_viewer,$pdf_viewer,
64 $pdfps_conv,$html_viewer,$htmlps_conv,$htmlps_redir,
65 $txt_viewer,$txtps_conv,$txtps_redir,$print_cmd);
66
67 # defaults: unix values
68 my $qq="'";
69 my $HomeEnv=$ENV{HOME};
70 my $TeXDocRcDefaults="texdocrc.defaults";
71 my $TempDir; $TempDir=$ENV{TMPDIR} or $TempDir="/tmp";
72 my $CmdConsole="xterm -e ";
73
74 if ($IsWin32) {
75 $qq = "\"";
76 $HomeEnv = $ENV{'USERPROFILE'};
77 chomp $HomeEnv;
78 $TeXDocRcDefaults = "texdocrc-win32.defaults";
79 $TempDir = &GetTempPath;
80 $CmdConsole = "cmd /c ";
81 }
82
83 my $myrc="${HomeEnv}/.texdocrc"; # optional personal settings file
84
85 my ($line,@dummy);
86 my @tmpfiles;
87 # read system-wide defaults from texdocrc.defaults
88 my $sysrc=`kpsewhich --progname=texdoctk --format=${qq}other text files${qq} ${TeXDocRcDefaults}`;
89 my $database=`kpsewhich --progname=texdoctk --format=${qq}other text files${qq} texdoctk.dat`;
90 my $locdatabase=`kpsewhich --progname=texdoctk --format=${qq}other text files${qq} texdoctk-local.dat`;
91 my $homedatabase=`kpsewhich --progname=texdoctk --format=${qq}other text files${qq} texdoctk-pers.dat`;
92 chomp $locdatabase;
93 chomp $homedatabase;
94 chomp $sysrc;
95 &readrc($sysrc,1);
96 @dummy=split("/",$sysrc);
97 pop @dummy;
98 $datadir=join('/',@dummy);
99 # possibly use personal settings instead of defaults
100 if (-e $myrc) { &readrc($myrc,2); }
101 # command line options
102 GetOptions('v'=>\$quiet,'a'=>\$autoview);
103 my $special=0;
104 my @button;
105 $button[17]="Miscellaneous";
106 my (@packname,@topic,@doc,@keywords,@maxind,%stydoc);
107 # read database file
108 my $i=-1;
109 my $j;
110 open(DATABASE,"$database") || &fatalmsg("Couldn't open database $database.\n");
111 while ($line = <DATABASE>) {
112 LINETYPE: {
113 ($line =~ /^\@/) && do { # category
114 ++$i;
115 if ($i == $#button) {
116 pop @button;
117 push @button,(substr($line,1,-1));
118 $special=1;
119 } else {
120 $button[$i]=substr($line,1,-1);
121 }
122 $j=0;
123 last LINETYPE;
124 };
125 ($line =~ /^(#|$)/) && do { # comment or empty line
126 last LINETYPE;
127 };
128 # list item
129 @dummy=split(";",$line);
130 $packname[$i][$j]=$dummy[0];
131 $topic[$i][$j]=$dummy[1];
132 $doc[$i][$j]=$dummy[2];
133 $keywords[$i][$j]=$dummy[3];
134 if ($doc[$i][$j] =~ /sty$/ && $keywords[$i][$j]) {
135 $stydoc{"$doc[$i][$j]"}=substr($keywords[$i][$j],1,1);
136 unless ($stydoc{"$doc[$i][$j]"} =~ /^\d$/) {
137 $stydoc{"$doc[$i][$j]"}=0;
138 }
139 }
140 $maxind[$i]=$j;
141 ++$j;
142 };
143 }
144 close(DATABASE);
145 # Read site-local and user's database(s) if it/they exist(s)
146 foreach my $dbfile ($locdatabase,$homedatabase) {
147 if (-e "$dbfile") {
148 open(DATABASE,"$dbfile") ||
149 print "Couldn't open additional database $dbfile.\n";
150 $i=17; # local/user: if no category is specified in database, add to "Misc"
151 while ($line = <DATABASE>) {
152 LINETYPE: {
153 ($line =~ /^\@/) && do { # category
154 $i=&arrindex(@button,substr($line,1,-1));
155 if ($i >= $#button) {
156 $i=$#button;
157 pop @button;
158 push @button,(substr($line,1,-1));
159 $special=1;
160 }
161 last LINETYPE;
162 };
163 ($line =~ /^(#|$)/) && do { # comment or empty line
164 last LINETYPE;
165 };
166 # list item
167 @dummy=split(";",$line);
168 $j=&arrindex(@{$packname[$i]},$dummy[0]);
169 if ($j > $#{$packname[$i]}) {
170 $packname[$i][$j]=$dummy[0];
171 $topic[$i][$j]=$dummy[1];
172 $doc[$i][$j]=$dummy[2];
173 $keywords[$i][$j]=$dummy[3];
174 if ($doc[$i][$j] =~ /sty$/ && $keywords[$i][$j]) {
175 $stydoc{"$doc[$i][$j]"}=substr($keywords[$i][$j],1,1);
176 unless ($stydoc{"$doc[$i][$j]"} =~ /^\d$/) {
177 $stydoc{"$doc[$i][$j]"}=0;
178 }
179 }
180 $maxind[$i]=$j;
181 ++$j;
182 }
183 };
184 }
185 close(DATABASE);
186 $special=1 if ($i == 17 && $j > 0);
187 }
188 }
189
190 # Tk
191 # hash table for toplevel windows; used to avoid multiple calls of same window
192 my %tlwins;
193 my %buttonlist;
194 # create frames for main window: commands on top, frame for buttons below
195 my $main=new MainWindow;
196 $tlwins{'mainwindow'}{'addr'}=$main;
197 $main->resizable(0,0);
198 $main->title("TeX Documentation Browser");
199 $main->bind('all','<Control-q>'=>\&clean_exit);
200 $main->bind('all','<Control-m>'=>sub { $main->raise(); });
201 $main->bind('all','<Control-h>'=>\&helptext);
202 $main->bind('all','<Control-s>'=>sub { $main->raise(); &mksrch; });
203 $main->bind('all','<Control-t>'=>\&settings);
204 my $cmdframe=$main->Frame(-background=>"#ffcc99");
205 my $buttonframe=$main->Frame;
206 $cmdframe->pack(-side=>'top',-fill=>'x');
207 $buttonframe->pack(-side=>'bottom');
208 # normal cursor
209 my $defcursor=$main->cget(-cursor);
210 # make buttons for command frame
211 my $Qbut=$cmdframe->Button(-text=>'Quit',%butcol,
212 -command=>\&clean_exit)->pack(-side=>'left');
213 $tlwins{'mainwindow'}{'buttons'}[0]=$Qbut;
214 # define common default font for labels and text explicitly
215 my $deffont=$Qbut->cget(-font);
216 # ensure readability on high-res screens (suggested by R.Kotucha)
217 $deffont='Helvetica -16 bold' if &x_resolution > 1200;
218 $Qbut->configure(-font=>$deffont);
219 $tlwins{'mainwindow'}{'buttons'}[1]=$cmdframe->Button(
220 -text=>'Database search',
221 -font=>$deffont,%butcol,
222 -command=>[\&mksrch, 0]
223 )->pack(-side=>'left');
224 $tlwins{'mainwindow'}{'buttons'}[2]=$cmdframe->Button(
225 -text=>'File search',
226 -font=>$deffont,%butcol,
227 -command=>[\&mksrch, 1]
228 )->pack(-side=>'left');
229 $tlwins{'mainwindow'}{'buttons'}[3]=$cmdframe->Button(-text=>'Help/About',
230 -font=>$deffont,%butcol,
231 -command=>\&helptext
232 )->pack(-side=>'right');
233 $tlwins{'mainwindow'}{'buttons'}[4]=$cmdframe->Button(-text=>'Settings',
234 -font=>$deffont,%butcol,
235 -command=>\&settings
236 )->pack(-side=>'right');
237 # make buttons for category button frame
238 my $lbut=0;
239 my $l;
240 foreach (@button) { $l=length $_; $lbut=$l if ( $l > $lbut) }
241 my @catg;
242 my ($i2,$i3);
243 my $nbutt=scalar @button;
244 my $ncols=$nbutt/3-1;
245 foreach (0..$ncols) {
246 $i=$_;
247 $i2=$i+$nbutt/3;
248 $i3=$i+2*$nbutt/3;
249 $catg[$i]=$buttonframe->Button(-text=>$button[$i],
250 -font=>$deffont,%butcol,
251 -width=>$lbut,
252 -command=>[\&tpslct,$i,\@dummy])->grid
253 ($catg[$i2]=$buttonframe->Button(-text=>$button[$i2],
254 -font=>$deffont,%butcol,
255 -width=>$lbut,
256 -command=>[\&tpslct,$i2,\@dummy]),
257 $catg[$i3]=$buttonframe->Button(-text=>$button[$i3],
258 -font=>$deffont,%butcol,
259 -width=>$lbut,
260 -command=>[\&tpslct,$i3,\@dummy]));
261 }
262 # disable last button (lower right) if no local specials are found in list
263 my $ncat;
264 if ($special == 0) {
265 $catg[$#button]->configure(-state=>'disabled');
266 $ncat=$nbutt-1;
267 } else {
268 $ncat=$nbutt;
269 }
270 for ($i=0,$j=5; $i<@catg; ++$i,++$j) {
271 $tlwins{'mainwindow'}{'buttons'}[$j]=$catg[$i];
272 }
273 MainLoop();
274
275 ########## SUBROUTINES ########################################################
276 # toplevel for selecting a topic of a category for viewing or printing
277 sub tpslct {
278 my($opt,@srchitems)=@_;
279 my (@lbitems,@lbdocs,$dspselect,$docselect,$wtitle);
280 if ($opt >= 0) {
281 # main window buttons
282 # see if toplevel window is already there
283 if (Exists($tlwins{$opt}{'addr'})) {
284 $tlwins{$opt}{'addr'}->deiconify();
285 $tlwins{$opt}{'addr'}->raise();
286 return;
287 }
288 for ($j=0; $j <= $maxind[$opt]; ++$j) {
289 push @lbitems,$topic[$opt][$j];
290 push @lbdocs,$doc[$opt][$j];
291 }
292 $wtitle=$button[$opt];
293 } else {
294 # search results
295 my $spec_wtitle=shift @srchitems;
296 for ($j=0; $j < $#srchitems; $j+=2) {
297 my $k=$j+1;
298 push @lbitems,$topic[$srchitems[$j]][$srchitems[$k]];
299 push @lbdocs,$doc[$srchitems[$j]][$srchitems[$k]];
300 }
301 $wtitle = ($srchtype ? "File" : "Database")
302 . " search results for $spec_wtitle";
303 }
304 # toplevel window of category $opt with two frames
305 my $tpwin=$main->Toplevel(-title=>$wtitle);
306 $tlwins{$opt}{'addr'}=$tpwin;
307 my $tpdsp=$tpwin->Frame(-relief=>'groove')->pack(-side=>'top');
308 my $tpslc=$tpwin->Frame()->pack(-side=>'top');
309 # selection frame with listbox and buttons
310 # label for listbox
311 my $tplabel=$tpslc->Label(-text=>($srchtype ? "Files" : "Topics"),
312 -font=>$deffont)->pack(-anchor=>'w',
313 -side=>'top');
314 # listbox with optional scrollbar
315 my $tplist=$tpslc->Scrolled("Listbox",
316 -font=>$deffont,
317 -scrollbars=>'osoe',
318 # -height=>0,
319 -width=>0,
320 -selectmode=>'single',
321 -exportselection=>0,
322 -cursor=>'hand2')->pack(-side=>'left',
323 -fill=>'y',
324 -expand=>1);
325 $tplist->insert('end',@lbitems); # fill topics into listbox
326 # buttons frame
327 my $tpbframe=$tpslc->Frame(-borderwidth=>8);
328 $tpbframe->pack(-side=>'right');
329 # make buttons for command frame
330 my $n_buttons = 0;
331 $tlwins{$opt}{'buttons'}[$n_buttons++]=
332 $tpbframe->Button(-text=>'View',
333 -font=>$deffont,%butcol,
334 -command=>sub{ &viewslc($docselect,$tpbframe);},
335 -width=>6)->pack(-side=>'top');
336 if (! $IsWin32) {
337 $tlwins{$opt}{'buttons'}[$n_buttons++]=
338 $tpbframe->Button(-text=>'Print',
339 -font=>$deffont,%butcol,
340 -command=>sub{ &prtslc($docselect,$tpbframe);},
341 -width=>6)->pack(-side=>'top');
342 }
343 $tlwins{$opt}{'buttons'}[$n_buttons++]=
344 $tpbframe->Button(-text=>'Cancel',
345 -font=>$deffont,%butcol,
346 -command=>sub{ destroy $tpwin; undef $tlwins{$opt};},
347 -width=>6)->pack(-side=>'bottom');
348 # if only 1 item is in the list (most likely in search results), select it
349 if (scalar @lbitems == 1) {
350 $tplist->selectionSet(0);
351 $dspselect=$lbitems[0];
352 $docselect=$lbdocs[0];
353 &viewslc($docselect,$tpbframe)
354 if ($autoview && $wtitle =~ /^Search results/);
355 }
356 # display frame
357 my $dsplabel=$tpdsp->Label(-text=>'Selection:',
358 -font=>$deffont)->pack(-anchor=>'w',,
359 -fill=>'x',
360 -side=>'left');
361 my $dspslc=$tpdsp->Label(-textvariable=>\$dspselect,
362 -font=>$deffont,
363 -borderwidth=>2)->pack(-anchor=>'w',
364 -fill=>'x',
365 -side=>'right');
366 # handle selection; only one selection possible
367 $tplist->bind('<Button-1>'=>sub{my ($slctind)=$tplist->curselection();
368 $dspselect=$lbitems[$slctind];
369 $docselect=$lbdocs[$slctind];});
370 # key bindings
371 $tplist->bind('<Double-Button-1>'=>sub{
372 &viewslc($docselect,$tpbframe);});
373 $tpwin->bind('<Control-v>'=>sub{
374 &viewslc($docselect,$tpbframe);});
375 $tpwin->bind('<Control-p>'=>sub{
376 &prtslc($docselect,$tpbframe);});
377 $tpwin->bind('<Control-c>'=>sub{destroy $tpwin; undef $tlwins{$opt};});
378 $tplist->bind('<Button-3>'=>sub{
379 if ($docselect) {
380 &showpath($docselect,$tpbframe);
381 } else {
382 &popmsg(2,"No selection;\nuse left mouse button.",$tpbframe);
383 }});
384 }
385
386 # view document selected in listbox
387 sub viewslc {
388 my($slc,$parframe)=@_;
389 my $viewer;
390 my $itype=-1;
391 my $browser=0;
392 my $styflag=0;
393 unless (defined $slc) {
394 &popmsg(2,"No selection was made.",$parframe);
395 return;
396 }
397 $parframe->configure(-cursor=>'watch');
398 chomp $slc;
399 my @dummy=split('\.',$slc);
400 DOC_FORMAT: { # determine document type
401 ($dummy[-1] =~ /dvi/) && do { $viewer=$dvi_viewer; last DOC_FORMAT; };
402 ($dummy[-1] =~ /ps/) && do { $viewer=$ps_viewer; last DOC_FORMAT; };
403 ($dummy[-1] =~ /pdf/) && do { $viewer=$pdf_viewer; last DOC_FORMAT; };
404 ($dummy[-1] =~ /txt/ || $dummy[-1] =~ /faq$/) && do {
405 $viewer=($txt_viewer eq "TDK_OWN" ||
406 $txt_viewer =~ /xterm/) ?
407 $txt_viewer : "${CmdConsole} $txt_viewer";
408 last DOC_FORMAT;
409 };
410 ($dummy[-1] =~ /README/i || $dummy[-2] =~ /\/README$/i) && do {
411 $viewer=($txt_viewer eq "TDK_OWN" ||
412 $txt_viewer =~ /xterm/) ?
413 $txt_viewer : "${CmdConsole} $txt_viewer";
414 last DOC_FORMAT;
415 };
416 ($dummy[-1] =~ /htm/) && do {
417 $viewer=$html_viewer;
418 if ($html_viewer =~ /netscape/i) { # check if Netscape is open
419 my $lockfile="${HomeEnv}/.netscape/lock";
420 $browser=1 if (-e $lockfile || -l $lockfile);
421 } elsif ($html_viewer =~ /mozilla/i) { # check if Mozilla is open
422 my $mozcheck=
423 `mozilla -remote 'openFile($texmfmain/doc/index.html)'`;
424 $browser=1 unless ($?);
425 }
426 last DOC_FORMAT;
427 };
428 # some packages have no normal documentation but useful info in the .sty
429 ($dummy[-1] =~ /sty$/) && do {
430 $viewer=($txt_viewer eq "TDK_OWN" ||
431 $txt_viewer =~ /xterm/) ?
432 $txt_viewer : "${CmdConsole} $txt_viewer";
433 $slc="../tex/$slc"; # .sty files are in ${tex,local}docpath/../tex/
434 $styflag=1;
435 last DOC_FORMAT;
436 };
437 $parframe->configure(-cursor=>$defcursor);
438 if ($xfmt_viewer != 1) {
439 &popmsg(2,"$dummy[-1]: not a known document format",$parframe);
440 return;
441 }
442 };
443 if ($viewer eq "") {
444 if ($xfmt_viewer == 1) {
445 &popmsg(-1,'Unknown format; assuming plain text.',$parframe);
446 $viewer=($txt_viewer eq "TDK_OWN" ||
447 $txt_viewer =~ /xterm/) ?
448 $txt_viewer : "${CmdConsole} $txt_viewer";
449 } else {
450 &popmsg(2,"$dummy[-1]: no viewer available/specified for this format",
451 $parframe);
452 $parframe->configure(-cursor=>$defcursor);
453 return;
454 }
455 }
456 # build complete path and start viewer if file exists
457 my $slcdoc;
458 $slcdoc=&finddoc($slcdoc,$slc,$parframe);
459 if ($slcdoc ne "") {
460 # change to doc directory in case there are pictures
461 my $docpath=substr($slcdoc,0,(rindex($slcdoc,'/',(length $slcdoc))));
462 chomp $slcdoc;
463 chdir ($docpath);
464 # try to get doc out of .sty file
465 if ($styflag) {
466 &popmsg(-1,'Trying to extract documentation out of .sty file;
467 might be cluttered with program comments.',
468 $parframe);
469 $slcdoc=&stripsty($slcdoc,substr($slc,7));
470 }
471 # for text files use built-in text viewer if set
472 if ($IsWin32) {
473 if ($viewer eq "TDK_OWN") {
474 &ShellExecute('open', $slcdoc);
475 $parframe->configure(-cursor=>$defcursor);
476 return;
477 }
478 else {
479 system("$viewer $slcdoc");
480 }
481 }
482 else {
483 if ($viewer eq "TDK_OWN") {
484 &textview($slcdoc);
485 $parframe->configure(-cursor=>$defcursor);
486 return;
487 }
488 if ($quiet == 0) { # show messages
489 if ($browser == 0) { # normal viewers or new Netscape/Mozilla
490 system("$viewer $slcdoc &");
491 } else { # open doc in existing Netscape/Mozilla window
492 system("$viewer -remote 'openFile($slcdoc)' &");
493 &popmsg(-1,"Opening document in existing $viewer window.",
494 $parframe);
495 }
496 } else { # viewer messages written to /dev/null instead of terminal
497 if ($browser == 0) { # normal viewers or new Netscape/Mozilla
498 system("perl -we 'use strict; \
499 my \$dump=\"\"; \
500 open(NULL,\">/dev/null\"); \
501 open (VIEWQ,\"$viewer $slcdoc |\"); \
502 while (\$dump=<VIEWQ>) { print NULL \$dump; } \
503 close(VIEWQ); \
504 close(NULL);' &");
505 } else { # open doc in existing window (Netscape or Mozilla)
506 # not quiet; I didn't get an inline perl call like in
507 # the other branch working
508 system("$viewer -remote 'openFile($slcdoc)' &");
509 &popmsg(-1,"Opening document in existing $viewer window.",
510 $parframe);
511 }
512 }
513 }
514 }
515 $parframe->configure(-cursor=>$defcursor);
516 }
517
518 # Tk widget for text document
519 sub textview {
520 my($txtfile)=@_;
521 # see if toplevel window with this file is already there
522 if (Exists($tlwins{$txtfile}{'addr'})) {
523 $tlwins{$txtfile}{'addr'}->deiconify();
524 $tlwins{$txtfile}{'addr'}->raise();
525 return;
526 }
527 my $tfv_tk=$main->Toplevel(-title=>"Text file viewer");
528 $tfv_tk->resizable(0,1);
529 $tlwins{$txtfile}{'addr'}=$tfv_tk;
530 $tfv_tk->Label(-text=>"File: $txtfile",
531 -font=>$deffont,
532 -relief=>'ridge',
533 -borderwidth=>3)->pack(-side=>'top',
534 -fill=>'x',
535 -ipady=>10,
536 -anchor=>'s');
537 my $txtbody=$tfv_tk->Scrolled("Text",
538 -relief=>'flat',
539 -font=>$deffont,
540 -height=>20,
541 -width=>80,
542 -scrollbars=>"e")->pack(-side=>'top',
543 -fill=>'y',
544 -expand=>1);
545 open(TXTFILE,"$txtfile");
546 while (<TXTFILE>) { $txtbody->insert('end',$_); }
547 close(TXTFILE);
548 $txtbody->configure(-state=>'disabled');
549 $tlwins{$txtfile}{'buttons'}[0]=
550 $tfv_tk->Button(-text=>'Close',
551 -font=>$deffont,%butcol,
552 -command=>sub{ destroy $tfv_tk;
553 undef $tlwins{$txtfile};
554 })->pack(-side=>'bottom',
555 -fill=>'x');
556 $tfv_tk->bind('<Control-c>'=>sub{destroy $tfv_tk;
557 undef $tlwins{$txtfile};
558 });
559 }
560
561 # print document selected in listbox
562 sub prtslc {
563 my($slc,$parframe)=@_;
564 $tmpfno=&randname;
565 my $pstmpfile="${TempDir}/texdoc_$tmpfno.ps";
566 push @tmpfiles,$pstmpfile;
567 my $status;
568 chomp $slc;
569 unless (defined $slc) {
570 &popmsg(2,"No selection was made.",$parframe);
571 return;
572 }
573 if ($print_cmd eq "") {
574 &popmsg(2,"No printer specified.",$parframe);
575 return;
576 }
577 # build complete path and check existence of file
578 my @dummy=split('\.',$slc);
579 if ($dummy[-1] =~ /sty$/) {
580 $slc="../tex/$slc"; # .sty files are in ${tex,local,home}docpath/../tex
581 }
582 my $slcdoc;
583 $slcdoc=&finddoc($slcdoc,$slc,$parframe);
584 return if ($slcdoc eq "");
585 # change to doc directory in case there are pictures
586 my $docpath=substr($slcdoc,0,(rindex($slcdoc,'/',(length $slcdoc))));
587 chdir ($docpath);
588 DOC_FORMAT: { # determine document type
589 # convert dvi files to ps before printing
590 ($dummy[-1] =~ /dvi/) && do {
591 if ($dvips_conv eq "") {
592 &popmsg(2,"No converter available for dvi->ps conversion.",
593 $parframe);
594 return;
595 }
596 &popmsg(-1,"Converting dvi to ps for printing and sending file to print...",$parframe);
597 $status=system("$dvips_conv $slcdoc -o $pstmpfile");
598 if ($status != 0) {
599 &popmsg(2,"Error: Conversion dvi->ps failed!",$parframe);
600 }
601 last DOC_FORMAT;
602 };
603 # PostScript is printed directly
604 ($dummy[-1] =~ /ps/) && do {
605 &popmsg(-1,"Sending file to $print_cmd...",$parframe);
606 $pstmpfile=$slcdoc;
607 last DOC_FORMAT;
608 };
609 # convert pdf files to ps before printing
610 ($dummy[-1] =~ /pdf/) && do {
611 if ($pdfps_conv eq "") {
612 &popmsg(2,"No converter available for pdf->ps conversion.",
613 $parframe);
614 return;
615 }
616 &popmsg(-1,"Converting pdf to ps for printing and sending file to print...",$parframe);
617 system("$pdfps_conv $slcdoc $pstmpfile");
618 last DOC_FORMAT;
619 };
620 # convert html files to ps before printing
621 ($dummy[-1] =~ /htm/) && do {
622 if ($htmlps_conv eq "") {
623 &popmsg(2,"No converter available for html->ps conversion.",
624 $parframe);
625 return;
626 }
627 &popmsg(-1,"Converting html to ps for printing and sending file to print...",$parframe);
628 my $htmlps_redir_sign=($htmlps_redir == 1) ? ">" :"";
629 system("$htmlps_conv $slcdoc $htmlps_redir_sign $pstmpfile");
630 last DOC_FORMAT;
631 };
632 # convert txt files to ps before printing
633 ($dummy[-1] =~ /txt/ || $dummy[-1] =~ /faq$/
634 || $dummy[-1] =~ /README/i) && do {
635 if ($txtps_conv eq "") {
636 &popmsg(2,"No converter available for txt->ps conversion.",
637 $parframe);
638 return;
639 }
640 &popmsg(-1,"Converting txt to ps for printing and sending file to print...",$parframe);
641 my $txtps_redir_sign=($txtps_redir == 1) ? ">" :"";
642 system("$txtps_conv $slcdoc $txtps_redir_sign $pstmpfile");
643 last DOC_FORMAT;
644 };
645 # convert extracted comments from sty files to ps before printing
646 ($dummy[-1] =~ /sty$/) && do {
647 if ($txtps_conv eq "") {
648 &popmsg(2,"No converter available for sty(txt)->ps conversion.",
649 $parframe);
650 return;
651 }
652 &popmsg(-1,"Converting sty(txt) to ps for printing and sending file to print...",$parframe);
653 # try to get doc out of .sty file
654 &popmsg(-1,'Trying to extract documentation out of .sty file;
655 might be cluttered with program comments.',
656 $parframe);
657 $slcdoc=&stripsty($slcdoc,substr($slc,7));
658 my $txtps_redir_sign=($txtps_redir == 1) ? ">" :"";
659 system("$txtps_conv $slcdoc $txtps_redir_sign $pstmpfile");
660 last DOC_FORMAT;
661 };
662 &popmsg(2,"$dummy[-1]: cannot print document format",$parframe);
663 return;
664 };
665 system("$print_cmd $pstmpfile");
666 }
667
668 # test existence and search a documentation which is not in specified place
669 sub finddoc {
670 my($slcdoc,$slc,$parframe)=@_;
671 my ($dummy,$status);
672 SLCDOCFIND: foreach ($texdocpath,$distdocpath,$docdocpath) {
673 $slcdoc="$_/$slc";
674 if (-e $slcdoc) {
675 # found where it should be
676 return $slcdoc;
677 } else {
678 # see if the documentation file is in the local doc tree...
679 my @srchslcdoc=($slcdoc);
680 if ($localdocpath) {
681 push @srchslcdoc,"$localdocpath/$slc";
682 return $srchslcdoc[-1] if (-e $srchslcdoc[-1]);
683 }
684 # ... or the user's doc tree...
685 if ($homedocpath) {
686 push @srchslcdoc,"$homedocpath/$slc";
687 return $srchslcdoc[-1] if (-e $srchslcdoc[-1]);
688 }
689 # ... otherwise proceed with searching
690 $status=-1;
691 # see if the documentation file is compressed
692 CMPREND: foreach my $cmprtype ("gz","bz2","zip") {
693 foreach (@srchslcdoc) {
694 $dummy="$_.$cmprtype";
695 if (-e $dummy) { # yes, it is compressed
696 $tmpfno=&randname;
697 my $rawname=basename($slc,"");
698 $slcdoc="${TempDir}/texdoc_$tmpfno$rawname";
699 push @tmpfiles,$slcdoc;
700 my ($dcmp,$dcmp_opt);
701 COMPRESS: { # determine compression type
702 ($cmprtype eq "gz") && do {
703 $dcmp="gzip";
704 $dcmp_opt="-cd";
705 last COMPRESS;
706 };
707 ($cmprtype eq "bz2") && do {
708 $dcmp="bzip2";
709 $dcmp_opt="-cd";
710 last COMPRESS;
711 };
712 ($cmprtype eq "zip") && do {
713 $dcmp="zip";
714 $dcmp_opt="-p";
715 last COMPRESS;
716 };
717 };
718 # try to decompress
719 $status=system("$dcmp $dcmp_opt $dummy > $slcdoc");
720 if ($status != 0) { # failure
721 &popmsg(2,
722 "$dcmp: Couldn't decompress file, cancelling.",
723 $parframe);
724 $slcdoc="";
725 return $slcdoc;
726 }
727 # last CMPREND; does not work, what we need is:
728 return $slcdoc;
729 }
730 }
731 }
732 }
733 }
734 if ($status != 0) {
735 $parframe->configure(-cursor=>'watch');
736 # try to find it elsewhere with kpsewhich
737 my $rawname=basename($slc,"");
738 $slcdoc=($slcdoc =~ /\.sty$/) ?
739 `kpsewhich $rawname` :
740 `kpsewhich --format=${qq}TeX system documentation${qq} $rawname`;
741 if ($slcdoc eq "") { # nothing found; cancel
742 &popmsg(2,"$rawname not found, cancelling.",$parframe);
743 $slcdoc="";
744 }
745 $parframe->configure(-cursor=>$defcursor);
746 }
747 return $slcdoc;
748 }
749
750 # determine existence and show paths of files (Button-3)
751 sub showpath {
752 my ($docselect,$tpbframe)=@_;
753 my $found=0;
754 if ($docselect =~ /\.sty$/) {
755 STYPATH: foreach my $fullpath ("$texmfmain/tex/$docselect",
756 "$texmfdist/tex/$docselect",
757 "$texmflocal/tex/$docselect",
758 "$texmfhome/tex/$docselect") {
759 if (-e $fullpath) {
760 &popmsg(0,"Selected file:\n$fullpath",$tpbframe);
761 $found=1;
762 last STYPATH;
763 }
764 }
765 if (!$found) {
766 &popmsg(2,"Selected file:\n$docselect\ndoes not exist.",$tpbframe) }
767 } else {
768 DOCPATH: foreach my $fullpath ("$texdocpath/$docselect",
769 "$distdocpath/$docselect",
770 "$docdocpath/$docselect",
771 "$localdocpath/$docselect",
772 "$homedocpath/$docselect") {
773 foreach ('','.gz','.bz2','.zip') {
774 my $fullpathext="$fullpath$_";
775 if (-e $fullpathext) {
776 &popmsg(0,"Selected file:\n$fullpathext",$tpbframe);
777 $found=1;
778 last DOCPATH;
779 }
780 }
781 }
782 if (!$found) {
783 &popmsg(2,"Selected file:\n$docselect\ndoes not exist (neither in normal form nor compressed).",$tpbframe) }
784 }
785 }
786
787 # make or destroy search entry widget
788 sub mksrch {
789 my ($type) = @_;
790 if ($srchflag == 1) {
791 if ($type == $srchtype) {
792 destroy $srchentry;
793 $srchflag=0;
794 } else {
795 $srchtype = $type;
796 }
797 } else {
798 $srchtype = $type;
799 # get the search string
800 $srchentry=$cmdframe->Entry(-cursor=>'xterm',
801 -font=>$deffont,
802 -width=>20,
803 -takefocus=>1)->pack(-side=>'left');
804 $srchentry->focus();
805 $srchentry->bind('<Return>'=>[\&srchstr, $srchentry]);
806 $srchflag=1;
807 # key binding
808 $srchentry->bind('<Control-c>'=>sub{destroy $srchentry; $srchflag=0;});
809 $srchentry->bind('<Escape>'=>sub{destroy $srchentry; $srchflag=0;});
810 }
811 }
812
813 # call search routine and display results
814 sub srchstr {
815 my $string;
816 my @reslist;
817 $string=$srchentry->get();
818 # search
819 $main->Busy(-recurse => 1);
820 if ($srchtype == 0) {
821 @reslist = &srchdb($string);
822 } else {
823 @reslist = &srchtd($string);
824 }
825 $main->Unbusy();
826 # destroy entry widget and show results
827 destroy $srchentry;
828 $srchflag=0;
829 if (scalar @reslist == 0) {
830 &popmsg(0, ($srchtype == 0 ? 'Database' : 'File').
831 " search for $string: no matches found.\n".
832 "You may want to try a ".
833 ($srchtype == 0 ? 'File' : 'Databse') . " search.\n\n".
834 "If nothing else works, CTAN offers an online search form:\n".
835 "http://ctan.org/search.html\n",
836 $cmdframe);
837 } else {
838 &tpslct(-1, $string, @reslist);
839 }
840 }
841
842 # search using texdoc
843 sub srchtd {
844 my ($string) = @_;
845 my @res;
846 my $tdout = `texdoc -M -l $string`;
847 if ($?) {
848 &popmsg(0,"texdoc failed, sorry: $!\n".
849 "Please report this problem on the texlive mailing list.\n");
850 return;
851 } else {
852 my $i = 0;
853 for my $line (split /\n/, $tdout) {
854 my @fields = split /\t/, $line;
855 $doc[$ncat][$i] = $fields[2];
856 $topic[$ncat][$i] = basename($fields[2]);
857 $packname[$ncat][$i] = "no package name";
858 push @res, ($ncat, $i++);
859 }
860 return @res;
861 }
862 }
863
864 # search a string in @packname, @topic and @keywords
865 sub srchdb {
866 my ($string) = @_;
867 my (@results, @reslist);
868 if ($string) {
869 for ($i=0; $i<$ncat; ++$i) {
870 for ($j=0; $j<$maxind[$i]+1; ++$j) {
871 SRCH: {
872 ($topic[$i][$j] =~ /$string/i) && do {
873 push @results,($i,$j);
874 last SRCH;
875 };
876 (defined $keywords[$i][$j]) && do {
877 if ($keywords[$i][$j] =~ /$string/i) {
878 push @results,($i,$j);
879 last SRCH;
880 }
881 };
882 ($packname[$i][$j] =~ /$string/i) && do {
883 push @results,($i,$j);
884 last SRCH;
885 };
886 };
887 }
888 }
889 } else { # return full database
890 $string='all database entries';
891 for ($i=0; $i<$ncat; ++$i) {
892 for ($j=0; $j<$maxind[$i]+1; ++$j) { push @results,($i,$j); }
893 }
894 }
895 unless (scalar @results == 0) {
896 # cancel multiple entries
897 my ($omit,$pack1,$pack2);
898 @reslist=($results[0],$results[1]);
899 for ($i=0; $i<$#results; $i+=2) {
900 $omit=0;
901 $pack1=$packname[$results[$i]][$results[$i+1]];
902 for ($j=0; $j<$#reslist; $j+=2) {
903 $pack2=$packname[$reslist[$j]][$reslist[$j+1]];
904 if ($pack1 eq $pack2) { $omit=1; last; }
905 }
906 if ($omit == 0) { push @reslist,($results[$i],$results[$i+1]); }
907 }
908 }
909 return @reslist;
910 }
911
912 # extract documentation of .sty files; a flag in the @keywords array shows
913 # where the doc is located:
914 # -0-: no specific place; -1-: at end, behind \endinput; -2-: at beginning,
915 # terminated by %%%%%%; -3-: at beginning, terminated with blank line
916 sub stripsty {
917 my ($slcdoc,$slc)=@_;
918 my @stydoc;
919 $tmpfno=&randname;
920 my $tmpslcdoc="${TempDir}/texdoc_$tmpfno.txt";
921 push @tmpfiles,$tmpslcdoc;
922 open (STY,"$slcdoc");
923 LOC: {
924 ($stydoc{$slc} == 0) && do { # no specific place, suck in everything :-(
925 while ($line = <STY>) { push @stydoc,$line if ($line =~ /^%/); }
926 last LOC;
927 };
928 ($stydoc{$slc} == 1) && do { # at end, behind \endinput
929 while ($line = <STY>) {
930 last if ($line =~ /^\s*\\endinput/ && !($line =~ /^%/));
931 }
932 while ($line = <STY>) { push @stydoc,$line; }
933 last LOC;
934 };
935 ($stydoc{$slc} == 2) && do { # up to a certain %%%%%%%, hopefully the 1st
936 for (my $i=0; $i<9; ++$i) { $stydoc[$i]=<STY>; } # after the 8th line
937 while ($line = <STY>) {
938 last if ($line =~ /^%{4,}/);
939 push @stydoc,$line;
940 }
941 last LOC;
942 };
943 ($stydoc{$slc} == 3) && do { # up to 1st blank/apparently empty line
944 while ($line = <STY>) {
945 last if ($line =~ /^\s*$/);
946 push @stydoc,$line;
947 }
948 last LOC;
949 };
950 };
951 close(STY);
952 open(TMPSTY,">$tmpslcdoc");
953 foreach (@stydoc) { print TMPSTY $_; }
954 close(TMPSTY);
955 return $tmpslcdoc;
956 }
957
958 # pop up a note or an error or warning message toplevel window
959 sub popmsg {
960 my($level,$msg,$parframe)=@_;
961 my $degree;
962 LEVEL: {
963 ($level == -1) && do { $degree="Info"; last LEVEL; };
964 ($level == 0) && do { $degree="Note"; last LEVEL; };
965 ($level == 1) && do {
966 return if ($quiet == 1);
967 $degree="Warning";
968 last LEVEL
969 };
970 ($level == 2) && do { $degree="Error"; last LEVEL; };
971 };
972 my $msgwin=$parframe->Toplevel(-title=>$degree);
973 my $lbl=$msgwin->Label(-text=>uc($degree),
974 -font=>$deffont)->pack(-side=>'top', -fill=>'x');
975 # get size of message text
976 my @dummy=split("\n",$msg);
977 my $nline=scalar @dummy;
978 my $msgwidth=0;
979 my $lline;
980 foreach (@dummy) {
981 $lline=length $_;
982 if ($lline > $msgwidth) { $msgwidth=$lline; }
983 }
984 my $message=$msgwin->Text(-relief=>'flat',
985 -font=>$deffont,
986 -height=>$nline,
987 -width=>$msgwidth)->pack(-side=>'top');
988 $message->insert('end',$msg);
989 $message->configure(-state=>'disabled');
990 if ($level < 0) { # transient message window
991 $msgwin->after(3000,sub{destroy $msgwin});
992 } else { # persistent message window
993 $msgwin->Button(-text=>'Close',
994 -font=>$deffont,%butcol,
995 -command=>sub{destroy $msgwin})->pack(-side=>'bottom',
996 -fill=>'x');
997 $msgwin->bind('<Control-c>'=>sub{destroy $msgwin});
998 }
999 }
1000
1001 # show/change settings (don't show this to an expert :-/ )
1002 sub settings {
1003 my ($homedocpath_tmp,$quiet_tmp,$autoview_tmp,$xfmt_viewer_tmp,
1004 $dvi_viewer_tmp,$dvips_conv_tmp,
1005 $ps_viewer_tmp,$pdf_viewer_tmp,$pdfps_conv_tmp,
1006 $html_viewer_tmp,$htmlps_conv_tmp,$htmlps_redir_tmp,
1007 $txt_viewer_tmp,$txtps_conv_tmp,$txtps_redir_tmp,$print_cmd_tmp)=
1008 ($homedocpath,$quiet,$autoview,$xfmt_viewer,
1009 $dvi_viewer,$dvips_conv,$ps_viewer,
1010 $pdf_viewer,$pdfps_conv,$html_viewer,
1011 $htmlps_conv,$htmlps_redir,$txt_viewer,
1012 $txtps_conv,$txtps_redir,$print_cmd);
1013 my @tdcolors_tmp=@tdcolors;
1014 # see if toplevel window is already there
1015 if (Exists($tlwins{"setmenu"}{'addr'})) {
1016 $tlwins{"setmenu"}{'addr'}->deiconify();
1017 $tlwins{"setmenu"}{'addr'}->raise();
1018 return;
1019 }
1020 my $setmenu=$main->Toplevel(-title=>'Settings');
1021 $setmenu->resizable(0,0);
1022 $tlwins{"setmenu"}{'addr'}=$setmenu;
1023 # documentation path
1024 my $datlabel;
1025 $datlabel="Database file(s) used: teTeX";
1026 $datlabel.=", local database" if (-e $locdatabase);
1027 $datlabel.=", user database" if (-e $homedatabase);
1028 my $docframe=$setmenu->Frame(-relief=>'groove',
1029 -borderwidth=>2)->pack(-side=>'top',
1030 -fill=>'x',
1031 -expand=>1);
1032 my $docframestring="\nDistribution documentation root path(s):\n$texdocpath";
1033 $docframestring.=", $distdocpath" if (-e $distdocpath);
1034 $docframestring.=", $docdocpath" if (length $docdocpath);
1035 if ($localdocpath && $localdocpath ne $texdocpath) {
1036 $docframestring.="\nLocal documentation root path: $localdocpath\n";
1037 }
1038 $docframe->Label(-text=>"$docframestring",
1039 -font=>$deffont)->pack(-side=>'top',
1040 -anchor=>'w',
1041 -fill=>'x',
1042 -expand=>1);
1043 if (defined $texmfhome && -d $texmfhome) {
1044 $homedocpath_tmp=basename($homedocpath_tmp,"");
1045 my $usrdocframe=$docframe->Frame(-relief=>'flat')->pack(-side=>'top',
1046 -fill=>'x');
1047 my $usrdoclabel=$usrdocframe->Label(-text=>"User's documentation root path: $texmfhome/",
1048 -font=>$deffont)->pack(-side=>'left');
1049 my $usrdocentry=$usrdocframe->Entry(-textvariable=>\$homedocpath_tmp,
1050 -font=>$deffont)->pack(-side=>'left');
1051 }
1052 $docframe->Label(-text=>"$datlabel.",
1053 -font=>$deffont)->pack(-side=>'top',
1054 -anchor=>'w',
1055 -ipady=>2,
1056 -fill=>'x',
1057 -expand=>1);
1058 # General viewer behaviour
1059 my $genvframe=$setmenu->Frame(-label=>'General viewer behaviour',
1060 -relief=>'groove',
1061 -borderwidth=>2)->pack(-side=>'top',
1062 -fill=>'x',
1063 -ipady=>6,
1064 -expand=>1);
1065 my $genvframe1=$genvframe->Frame()->pack(-side=>'left');
1066 my $genvsub1=$genvframe1->Frame()->pack(-side=>'top',
1067 -anchor=>'w',
1068 -ipady=>3);
1069 my $genvecbut=$genvsub1->
1070 Checkbutton(-variable=>\$quiet_tmp)->pack(-side=>'left',
1071 -anchor=>'sw');
1072 my $genvelabel=$genvsub1->Label(-text=>'Suppress error messages',
1073 -font=>$deffont)->pack(-side=>'left',
1074 -anchor=>'sw');
1075 my $genvsub2=$genvframe1->Frame()->pack(-side=>'top',
1076 -anchor=>'w');
1077 my $genvscbut=$genvsub2->
1078 Checkbutton(-variable=>\$autoview_tmp)->pack(-side=>'left',
1079 -anchor=>'sw');
1080 my $genvslabel=$genvsub2->Label(-text=>'Autostart viewer for one-item listboxes',
1081 -font=>$deffont)->pack(-side=>'left',
1082 -anchor=>'sw');
1083 my $genvsub3=$genvframe1->Frame()->pack(-side=>'top',
1084 -anchor=>'w');
1085 my $genvxcbut=$genvsub3->
1086 Checkbutton(-variable=>\$xfmt_viewer_tmp)->pack(-side=>'left',
1087 -anchor=>'sw');
1088 my $genvxlabel=$genvsub3->Label(-text=>'Use text viewer for unknown file format',
1089 -font=>$deffont)->pack(-side=>'left',
1090 -anchor=>'sw');
1091 # colours of GUI
1092 my @tdcolors_d=@tdcolors_tmp;
1093 $tlwins{'setmenu'}{'buttons'}[0]=
1094 $genvframe->Button(-text=>'Change viewer colours',
1095 -command=>sub {
1096 @tdcolors_tmp=&popcolor($setmenu,@tdcolors_tmp);
1097 @tdcolors_d=@tdcolors_tmp;
1098 },
1099 -font=>$deffont,%butcol)->pack(-side=>'right');
1100 # DVI
1101 my $dviframe=$setmenu->Frame(-label=>'DVI',
1102 -relief=>'groove',
1103 -borderwidth=>2)->pack(-side=>'top',
1104 -fill=>'x',
1105 -ipady=>6,
1106 -expand=>1);
1107 my $dvisub1=$dviframe->Frame()->pack(-side=>'top',
1108 -anchor=>'w');
1109 my $dvisub2=$dviframe->Frame()->pack(-side=>'top',
1110 -anchor=>'w',
1111 -ipady=>6);
1112 my $dvivlabel=$dvisub1->Label(-text=>'Viewer command',
1113 -anchor=>'w',
1114 -font=>$deffont)->pack(-side=>'left');
1115 my $dviventry=$dvisub1->Entry(-textvariable=>\$dvi_viewer_tmp,
1116 -font=>$deffont)->pack(-side=>'left');
1117 my $dviclabel=$dvisub2->Label(-text=>'DVI->PS converter command',
1118 -anchor=>'w',
1119 -font=>$deffont)->pack(-side=>'left',
1120 -anchor=>'sw');
1121 my $dvilbwidth=length 'DVI->PS converter command';
1122 $dvivlabel->configure(-width=>1.1*$dvilbwidth);
1123 $dviclabel->configure(-width=>1.1*$dvilbwidth);
1124 my $dvicentry=$dvisub2->Entry(-textvariable=>\$dvips_conv_tmp,
1125 -font=>$deffont)->pack(-side=>'left',
1126 -anchor=>'sw');
1127 # PostScript
1128 my $psframe=$setmenu->Frame(-label=>'PostScript',
1129 -relief=>'groove',
1130 -borderwidth=>2)->pack(-side=>'top',
1131 -fill=>'x',
1132 -ipady=>10,
1133 -expand=>1);
1134 my $psvlabel=$psframe->Label(-text=>'Viewer command',
1135 -font=>$deffont)->pack(-side=>'left',
1136 -anchor=>'w');
1137 my $psventry=$psframe->Entry(-textvariable=>\$ps_viewer_tmp,
1138 -font=>$deffont)->pack(-side=>'left');
1139 # PDF
1140 my $pdfframe=$setmenu->Frame(-label=>'PDF',
1141 -relief=>'groove',
1142 -borderwidth=>2)->pack(-side=>'top',
1143 -fill=>'x',
1144 -ipady=>6,
1145 -expand=>1);
1146 my $pdfsub1=$pdfframe->Frame()->pack(-side=>'top',
1147 -anchor=>'w');
1148 my $pdfsub2=$pdfframe->Frame()->pack(-side=>'top',
1149 -anchor=>'w',
1150 -ipady=>6);
1151 my $pdfvlabel=$pdfsub1->Label(-text=>'Viewer command',
1152 -font=>$deffont)->pack(-side=>'left',
1153 -anchor=>'w');
1154 my $pdfventry=$pdfsub1->Entry(-textvariable=>\$pdf_viewer_tmp,
1155 -font=>$deffont)->pack(-side=>'left');
1156 my $pdfclabel=$pdfsub2->Label(-text=>'PDF->PS converter command',
1157 -font=>$deffont)->pack(-side=>'left',
1158 -anchor=>'sw');
1159 my $pdfcentry=$pdfsub2->Entry(-textvariable=>\$pdfps_conv_tmp,
1160 -font=>$deffont)->pack(-side=>'left',
1161 -anchor=>'sw');
1162 # HTML
1163 my $htmlframe=$setmenu->Frame(-label=>'HTML',
1164 -relief=>'groove',
1165 -borderwidth=>2)->pack(-side=>'top',
1166 -fill=>'x',
1167 -ipady=>6,
1168 -expand=>1);
1169 my $htmlsub1=$htmlframe->Frame()->pack(-side=>'top',
1170 -anchor=>'w');
1171 my $htmlsub2=$htmlframe->Frame()->pack(-side=>'top',
1172 -anchor=>'w',
1173 -ipady=>6);
1174 my $htmlvlabel=$htmlsub1->Label(-text=>'Viewer command',
1175 -font=>$deffont)->pack(-side=>'left',
1176 -anchor=>'w');
1177 my $htmlventry=$htmlsub1->Entry(-textvariable=>\$html_viewer_tmp,
1178 -font=>$deffont)->pack(-side=>'left');
1179 my $htmlclabel=$htmlsub2->Label(-text=>'HTML->PS converter command',
1180 -font=>$deffont)->pack(-side=>'left',
1181 -anchor=>'sw');
1182 my $htmlcentry=$htmlsub2->Entry(-textvariable=>\$htmlps_conv_tmp,
1183 -font=>$deffont)->pack(-side=>'left',
1184 -anchor=>'sw');
1185 my $htmlrlabel=$htmlsub2->Label(-text=>'Output redirect needed',
1186 -font=>$deffont)->pack(-side=>'left',
1187 -anchor=>'sw');
1188 my $htmlrcbut=$htmlsub2->
1189 Checkbutton(-variable=>\$htmlps_redir_tmp)->pack(-side=>'left',
1190 -anchor=>'sw');
1191 # plain text
1192 my $txtframe=$setmenu->Frame(-label=>'Plain text',
1193 -relief=>'groove',
1194 -borderwidth=>2)->pack(-side=>'top',
1195 -fill=>'x',
1196 -ipady=>6,
1197 -expand=>1);
1198 my $txtsub1=$txtframe->Frame()->pack(-side=>'top',
1199 -anchor=>'w');
1200 my $txtsub2=$txtframe->Frame()->pack(-side=>'top',
1201 -anchor=>'w',
1202 -ipady=>6);
1203 my $txtvlabel=$txtsub1->Label(-text=>'Viewer command',
1204 -font=>$deffont)->pack(-side=>'left',
1205 -anchor=>'w');
1206 my $txtventry=$txtsub1->Entry(-textvariable=>\$txt_viewer_tmp,
1207 -font=>$deffont)->pack(-side=>'left');
1208 my $txt_view_flag;
1209 if ($txt_viewer_tmp eq "TDK_OWN") {
1210 $txt_view_flag=1;
1211 $txtventry->configure(-state=>'disabled');
1212 } else {
1213 $txt_view_flag=0;
1214 $txtventry->configure(-state=>'normal');
1215 }
1216 my $txtvilabel=$txtsub1->Label(-text=>"\tUse texdoctk\'s own viewer",
1217 -font=>$deffont)->pack(-side=>'left',
1218 -anchor=>'sw');
1219 my $txtvcbut=$txtsub1->
1220 Checkbutton(-variable=>\$txt_view_flag,
1221 -command=>sub {
1222 if ($txt_view_flag == 1) {
1223 $txt_viewer_tmp="TDK_OWN";
1224 $txtventry->configure(-state=>'disabled');
1225 } else {
1226 $txt_viewer_tmp=$txt_viewer;
1227 $txtventry->configure(-state=>'normal');
1228 $txtventry->focus();
1229 }
1230 })->pack(-side=>'left',
1231 -anchor=>'sw');
1232 my $txtclabel=$txtsub2->Label(-text=>'Text->PS converter command',
1233 -font=>$deffont)->pack(-side=>'left',
1234 -anchor=>'sw');
1235 my $txtcentry=$txtsub2->Entry(-textvariable=>\$txtps_conv_tmp,
1236 -font=>$deffont)->pack(-side=>'left',
1237 -anchor=>'sw');
1238 my $txtrlabel=$txtsub2->Label(-text=>'Output redirect needed',
1239 -font=>$deffont)->pack(-side=>'left',
1240 -anchor=>'sw');
1241 my $txtrcbut=$txtsub2->
1242 Checkbutton(-variable=>\$txtps_redir_tmp)->pack(-side=>'left',
1243 -anchor=>'sw');
1244 # printer
1245 my $prtframe=$setmenu->Frame(-label=>'Printer',
1246 -relief=>'groove',
1247 -borderwidth=>2)->pack(-side=>'top',
1248 -fill=>'x',
1249 -ipady=>10,
1250 -expand=>1);
1251 my $prtclabel=$prtframe->Label(-text=>'Command',
1252 -font=>$deffont)->pack(-side=>'left',
1253 -anchor=>'w');
1254 my $prtcentry=$prtframe->Entry(-textvariable=>\$print_cmd_tmp,
1255 -font=>$deffont)->pack(-side=>'left');
1256 # buttons and key bindings
1257 my $setbfr=$setmenu->Frame()->pack(-side=>'bottom');
1258 $tlwins{'setmenu'}{'buttons'}[1]=
1259 $setbfr->Button(-text=>'OK',
1260 -font=>$deffont,%butcol,
1261 -command=>sub{
1262 $homedocpath="$texmfhome/$homedocpath_tmp";
1263 ($quiet,$autoview,$xfmt_viewer,
1264 $dvi_viewer,$dvips_conv,
1265 $ps_viewer,$pdf_viewer,
1266 $pdfps_conv,$html_viewer,
1267 $htmlps_conv,$htmlps_redir,
1268 $txt_viewer,$txtps_conv,$txtps_redir,$print_cmd)=
1269 ($quiet_tmp,$autoview_tmp,$xfmt_viewer_tmp,
1270 $dvi_viewer_tmp,$dvips_conv_tmp,
1271 $ps_viewer_tmp,
1272 $pdf_viewer_tmp,$pdfps_conv_tmp,
1273 $html_viewer_tmp,
1274 $htmlps_conv_tmp,$htmlps_redir_tmp,
1275 $txt_viewer_tmp,$txtps_conv_tmp,
1276 $txtps_redir_tmp,$print_cmd_tmp);
1277 @tdcolors=@tdcolors_tmp;
1278 %butcol=('-background'=>$tdcolors[0],
1279 '-foreground'=>$tdcolors[1],
1280 '-activebackground'=>$tdcolors[2],
1281 '-activeforeground'=>$tdcolors[3]);
1282 foreach my $tlkey (keys %tlwins) {
1283 foreach (@{$tlwins{$tlkey}{'buttons'}}) {
1284 $_->configure(%butcol);
1285 }
1286 }
1287 if ($txt_viewer eq "" &&
1288 defined $ENV{PAGER}) {
1289 $txt_viewer=$ENV{PAGER};
1290 }
1291 destroy $setmenu},
1292 -width=>6)->pack(-side=>'left',
1293 -padx=>10,
1294 -pady=>10);
1295 $tlwins{'setmenu'}{'buttons'}[2]=
1296 $setbfr->Button(-text=>'Save',
1297 -font=>$deffont,%butcol,
1298 -command=>sub{
1299 $setmenu->configure(-cursor=>'watch');
1300 &popmsg(-1,"Writing settings to $myrc",$setmenu);
1301 my $tdcolors_tmp=join(' ',@tdcolors_tmp);
1302 &writerc($homedocpath_tmp,
1303 $quiet_tmp,$autoview_tmp,$xfmt_viewer_tmp,
1304 $tdcolors_tmp,
1305 $dvi_viewer_tmp,$dvips_conv_tmp,
1306 $ps_viewer_tmp,
1307 $pdf_viewer_tmp,$pdfps_conv_tmp,
1308 $html_viewer_tmp,
1309 $htmlps_conv_tmp,$htmlps_redir_tmp,
1310 $txt_viewer_tmp,$txtps_conv_tmp,
1311 $txtps_redir_tmp,$print_cmd_tmp,$setmenu);
1312 $setmenu->configure(-cursor=>$defcursor);
1313 })->pack(-side=>'left',
1314 -padx=>10);
1315 $tlwins{'setmenu'}{'buttons'}[3]=
1316 $setbfr->Button(-text=>'Cancel',
1317 -font=>$deffont,%butcol,
1318 -command=>sub{destroy $setmenu;
1319 undef $tlwins{"setmenu"};
1320 })->pack(-side=>'left',
1321 -padx=>10);
1322 $setmenu->bind('<Control-c>'=>sub{destroy $setmenu;
1323 undef $tlwins{"setmenu"};});
1324 }
1325
1326 # dialog toplevel for color settings
1327 sub popcolor {
1328 my ($parframe,@entryvar)=@_;
1329 # see if toplevel window is already there
1330 if (Exists($tlwins{'chngcol'}{'addr'})) {
1331 $tlwins{'chngcol'}{'addr'}->deiconify();
1332 $tlwins{'chngcol'}{'addr'}->raise();
1333 return;
1334 }
1335 my $dlgwin=$parframe->Toplevel(-title=>'Change colours');
1336 $dlgwin->resizable(0,0);
1337 $tlwins{'chngcol'}{'addr'}=$dlgwin;
1338 # entry widgets for default/active back/foreground
1339 $dlgwin->Label(-text=>'Enter colours as names or RGB #xxxxxx values',
1340 -font=>$deffont)->pack(-side=>'top');
1341 my $dlgdef=$dlgwin->Frame()->pack(-side=>'top');
1342 my $dlgact=$dlgwin->Frame()->pack(-side=>'top');
1343 my $dlgdef1=$dlgdef->Frame()->pack(-side=>'left');
1344 my $dlgtfr0=$dlgdef1->Frame()->pack(-side=>'top');
1345 my $dlgtfr1=$dlgdef1->Frame()->pack(-side=>'top');
1346 my $dlgact1=$dlgact->Frame()->pack(-side=>'left');
1347 my $dlgtfr2=$dlgact1->Frame()->pack(-side=>'top');
1348 my $dlgtfr3=$dlgact1->Frame()->pack(-side=>'top');
1349 $dlgtfr0->Label(-text=>"Default background",
1350 -anchor=>'w',
1351 -width=>18,
1352 -font=>$deffont)->pack(-side=>'left');
1353 $dlgtfr0->Entry(-textvariable=>\$entryvar[0],
1354 -font=>$deffont)->pack(-side=>'left');
1355 $dlgtfr1->Label(-text=>"Default foreground",
1356 -anchor=>'w',
1357 -width=>18,
1358 -font=>$deffont)->pack(-side=>'left');
1359 $dlgtfr1->Entry(-textvariable=>\$entryvar[1],
1360 -font=>$deffont)->pack(-side=>'left');
1361 my $deflabel=$dlgdef->Label(-text=>'Default',
1362 -relief=>'ridge',
1363 -width=>10,
1364 -height=>2)->pack(-side=>'right',
1365 -padx=>7);
1366 $dlgtfr2->Label(-text=>"Active background",
1367 -anchor=>'w',
1368 -width=>18,
1369 -font=>$deffont)->pack(-side=>'left');
1370 $dlgtfr2->Entry(-textvariable=>\$entryvar[2],
1371 -font=>$deffont)->pack(-side=>'left');
1372 $dlgtfr3->Label(-text=>"Active foreground",
1373 -anchor=>'w',
1374 -width=>18,
1375 -font=>$deffont)->pack(-side=>'left');
1376 $dlgtfr3->Entry(-textvariable=>\$entryvar[3],
1377 -font=>$deffont)->pack(-side=>'left');
1378 my $actlabel=$dlgact->Label(-text=>'Active',
1379 -background=>$entryvar[2],
1380 -foreground=>$entryvar[3],
1381 -relief=>'ridge',
1382 -width=>10,
1383 -height=>2)->pack(-side=>'right',
1384 -padx=>7);
1385 # buttons
1386 my $setbfr=$dlgwin->Frame()->pack(-side=>'bottom');
1387 my $chngflag=0;
1388 $tlwins{'chngcol'}{'buttons'}[0]=
1389 $setbfr->Button(-text=>'OK',
1390 -font=>$deffont,%butcol,
1391 -command=>sub {
1392 foreach (@entryvar) { # RGB form with leading #
1393 $_="#$_" if (/^[A-Fa-f0-9]{6}$/);
1394 }
1395 $chngflag=1 if (&colcheck($dlgwin,@entryvar));
1396 },
1397 -width=>6)->pack(-side=>'left',
1398 -padx=>5,
1399 -pady=>10);
1400 $tlwins{'chngcol'}{'buttons'}[1]=
1401 $setbfr->Button(-text=>'Preview',
1402 -font=>$deffont,%butcol,
1403 -command=>sub {
1404 foreach (@entryvar) { # RGB form with leading #
1405 $_="#$_" if (/^[A-Fa-f0-9]{6}$/);
1406 }
1407 if (&colcheck($dlgwin,@entryvar)) {
1408 $deflabel->
1409 configure(-background=>$entryvar[0],
1410 -foreground=>$entryvar[1]);
1411 $actlabel->
1412 configure(-background=>$entryvar[2],
1413 -foreground=>$entryvar[3]);
1414 }
1415 },
1416 -width=>6)->pack(-side=>'left',
1417 -padx=>5,
1418 -pady=>10);
1419 $tlwins{'chngcol'}{'buttons'}[2]=
1420 $setbfr->Button(-text=>'Cancel',
1421 -font=>$deffont,%butcol,
1422 -command=>sub{destroy $dlgwin;
1423 undef $tlwins{'chngcol'};
1424 })->pack(-side=>'right',
1425 -padx=>5,
1426 -pady=>10);
1427 $dlgwin->bind('<Control-c>'=>sub{destroy $dlgwin;
1428 undef $tlwins{'chngcol'}; });
1429 $dlgwin->waitVariable(\$chngflag);
1430 destroy $dlgwin;
1431 undef $tlwins{'chngcol'};
1432 return @entryvar;
1433 }
1434
1435 # check colours set in popcolor; relies on the existence of X11's showrgb
1436 sub colcheck {
1437 my ($dlgwin,@entryvar)=@_;
1438 my $ecnt=0;
1439 foreach (@entryvar) { # all colours defined?
1440 last unless ($_);
1441 ++$ecnt;
1442 }
1443 &popmsg(2,'Some colours undefined.',$dlgwin) if ($ecnt != 4);
1444 my $defcol=0;
1445 if (`which showrgb`) { # test for proper name
1446 my @rgb=`showrgb`;
1447 my @norgb;
1448 foreach my $colour (@entryvar) {
1449 if ($colour =~ /^#[A-Fa-f0-9]{6}$/ || grep /\b$colour\b/i,@rgb) {
1450 ++$defcol;
1451 } else {
1452 push @norgb,$colour;
1453 }
1454 }
1455 if ($defcol != 4) {
1456 my $norgb=join("\n",@norgb);
1457 &popmsg(2,"Some colours invalid:\n$norgb",$dlgwin);
1458 }
1459 } else { $defcol=4; }
1460 return ($ecnt == 4 && $defcol == 4) ? 1 : 0;
1461 }
1462
1463 # write user's ~/.texdocrc
1464 sub writerc {
1465 use File::Copy qw/cp mv/;
1466 my ($homedocpath_tmp,$quiet_tmp,$autoview_tmp,$xfmt_viewer_tmp,
1467 $tdcolors_tmp,
1468 $dvi_viewer_tmp,$dvips_conv_tmp,
1469 $ps_viewer_tmp,
1470 $pdf_viewer_tmp,$pdfps_conv_tmp,
1471 $html_viewer_tmp,
1472 $htmlps_conv_tmp,$htmlps_redir_tmp,
1473 $txt_viewer_tmp,$txtps_conv_tmp,
1474 $txtps_redir_tmp,$print_cmd_tmp,$parframe)=@_;
1475 my $err=0;
1476 mv $myrc,"$myrc.save" if (-e $myrc);
1477 open(MYRC,">$myrc");
1478 print MYRC "# user's .texdocrc, generated by program\n
1479 # root of user's doc directory (from \$HOMETEXMF)
1480 # can be left empty if \$TEXMFHOME is undefined
1481 HOMEDOCPATH=$homedocpath_tmp
1482 # general viewer behaviour (y or yes to make active)
1483 QUIET=$quiet_tmp
1484 AUTOVIEW=$autoview_tmp
1485 XFMT_VIEWER=$xfmt_viewer_tmp
1486 # button colours: default and active back-/foreground
1487 # names and RGB values are both allowed; use the form #xxxxxx for RGB
1488 TDCOLORS=$tdcolors_tmp
1489 # the following variables contain whole commands, i.e. options can be given
1490 # DVI settings
1491 DVI_VIEWER=$dvi_viewer_tmp
1492 DVIPS_CONV=$dvips_conv_tmp
1493 # PostScript handling
1494 PS_VIEWER=$ps_viewer_tmp
1495 # PDF handling
1496 PDF_VIEWER=$pdf_viewer_tmp
1497 PDFPS_CONV=$pdfps_conv_tmp
1498 # HTML handling
1499 HTML_VIEWER=$html_viewer_tmp
1500 HTMLPS_CONV=$htmlps_conv_tmp
1501 # HTMLPS_REDIR must be on, if the html->ps converter normally writes its output
1502 # to stdout instead of a file (e.g. as html2ps) (y or yes to make active)
1503 HTMLPS_REDIR=$htmlps_redir_tmp
1504 # Plain text handling
1505 # TDK_OWN is texdoctk's own text file viewer
1506 TXT_VIEWER=$txt_viewer_tmp
1507 TXTPS_CONV=$txtps_conv_tmp
1508 # TXTPS_REDIR must be on, if the txt->ps converter normally writes its output
1509 # to stdout instead of a file (e.g. as a2ps) (y or yes to make active)
1510 TXTPS_REDIR=$txtps_redir_tmp
1511 # printer
1512 PRINT_CMD=$print_cmd_tmp
1513 \n# end of config\n";
1514 close(MYRC);
1515 }
1516
1517 # help window (toplevel)
1518 sub helptext {
1519 # see if toplevel window is already there
1520 if (Exists($tlwins{"helptext"}{'addr'})) {
1521 $tlwins{"helptext"}{'addr'}->deiconify();
1522 $tlwins{"helptext"}{'addr'}->raise();
1523 return;
1524 }
1525 my $help=$main->Toplevel(-title=>'Help/About');
1526 $help->resizable(0,1);
1527 $tlwins{'helptext'}{'addr'}=$help;
1528 $help->Label(-text=>"texdoctk
1529 TeX documentation browser
1530 v$version ($date)",
1531 -font=>$deffont)->pack(-side=>'top',
1532 -ipady=>10,
1533 -anchor=>'s');
1534 my $helpbody=$help->Scrolled("Text",
1535 -relief=>'flat',
1536 -font=>$deffont,
1537 -height=>20,
1538 -width=>60,
1539 -scrollbars=>"e")->pack(-side=>'top',
1540 -fill=>'y',
1541 -expand=>1);
1542 my $pos=tell DATA;
1543 while (<DATA>) {
1544 $_ =~ s/\$sysrc/$sysrc/;
1545 last if (/^#/);
1546 $helpbody->insert('end',$_);
1547 }
1548 seek(DATA,$pos,0);
1549 $helpbody->configure(-state=>'disabled');
1550 $tlwins{'helptext'}{'buttons'}[0]=
1551 $help->Button(-text=>'Close',
1552 -font=>$deffont,%butcol,
1553 -command=>sub{destroy $help;
1554 undef $tlwins{"helptext"};
1555 })->pack(-side=>'bottom',
1556 -fill=>'x');
1557 $help->bind('<Control-c>'=>sub{destroy $help; undef $tlwins{"helptext"};});
1558 }
1559
1560 # read config file; personal settings override the default settings
1561 sub readrc {
1562 my($rcfile,$icall)=@_;
1563 my ($var,$val);
1564 my $pathflag=0;
1565 my $pathflagl=0;
1566 my $pathflagh=0;
1567 my $tdcolors='';
1568 # for backward compatibility of converter/printer options
1569 my ($dvips_opts,$pdfps_opts,$print_opts);
1570 # read defaults resp. local/personal settings
1571 CALL: {
1572 ($icall == 1) && do {
1573 open (RC,"$rcfile") ||
1574 &fatalmsg("Couldn't open system-wide default config file ${TeXDocRcDefaults}.\n");
1575 last CALL;
1576 };
1577 ($icall == 2) && do {
1578 open (RC,"$rcfile") ||
1579 &fatalmsg("Couldn't open personal config file ~/.texdocrc.\n");
1580 last CALL;
1581 };
1582 };
1583 while ($line = <RC>) {
1584 next if ($line =~ /^($|#)/);
1585 chomp $line;
1586 ($var,$val)=split("=",$line,2);
1587 RCVARS: {
1588 ($var =~ /texdocpath/i) && do { # TEXDOCPATH
1589 if (length $val > 0) {
1590 $pathflag=1;
1591 eval(join("",("\$",lc($var),"=\$val")));
1592 }
1593 last RCVARS;
1594 };
1595 ($var =~ /localdocpath/i) && do { # LOCALDOCPATH
1596 if (length $val > 0) {
1597 $pathflagl=1;
1598 eval(join("",("\$",lc($var),"=\$val")));
1599 }
1600 last RCVARS;
1601 };
1602 ($var =~ /homedocpath/i) && do { # HOMEDOCPATH
1603 if ($icall == 2 && length $val > 0) { # set only in ~/.texdocrc
1604 $pathflagh=1;
1605 eval(join("",("\$",lc($var),"=\$val")));
1606 }
1607 last RCVARS;
1608 };
1609 # other variables
1610 eval(join("",("\$",lc($var),"=\$val")));
1611 };
1612 }
1613 close(RC);
1614 # find texmf/doc, and possibly other distribution texmf trees
1615 if ($rcfile eq $sysrc || $pathflag == 1) {
1616 $texmfmain=`kpsewhich --expand-path=${qq}\$TEXMFMAIN${qq}`;
1617 chomp $texmfmain;
1618 $texdocpath="$texmfmain/$texdocpath";
1619 $texmfdist=`kpsewhich --expand-path=${qq}\$TEXMFDIST${qq}`;
1620 chomp $texmfdist;
1621 $distdocpath=join('/',"$texmfdist",basename($texdocpath,""))
1622 if (length $texmfdist);
1623 # TeXLive has this texmf-doc
1624 $texmfdoc=join('/',"$texmfmain-doc",basename($texdocpath,""));
1625 if (-e $texmfdoc) {
1626 chomp $texmfdoc;
1627 $docdocpath="$texmfdoc/$docdocpath";
1628 }
1629 }
1630 # find texmf-local/doc, if there is one
1631 if ($rcfile eq $sysrc || $pathflagl == 1) {
1632 $texmflocal=`kpsewhich --expand-path=${qq}\$TEXMFLOCAL${qq}`;
1633 chomp $texmflocal;
1634 if (length $texmflocal) {
1635 # if LOCALDOCPATH is not explicitly defined, it equals TEXDOCPATH
1636 unless (defined $localdocpath) {
1637 $localdocpath=basename($texdocpath,"");
1638 }
1639 $localdocpath="$texmflocal/$localdocpath";
1640 }
1641 }
1642 # find user's $HOMETEXMF/doc, if there is one
1643 if ($icall == 2 || $pathflagh == 1) {
1644 $texmfhome=`kpsewhich --expand-path=${qq}\$HOMETEXMF${qq}`;
1645 chomp $texmfhome;
1646 if (length $texmfhome) {
1647 # if HOMEDOCPATH is not explicitly defined, it equals TEXDOCPATH
1648 unless (defined $homedocpath) {
1649 $homedocpath=basename($texdocpath,"");
1650 }
1651 $homedocpath="$texmfhome/$homedocpath";
1652 }
1653 }
1654 # colours: create array
1655 @tdcolors=split(' ',$tdcolors);
1656 if (scalar @tdcolors != 4) { # if old texdocrc file is used
1657 if (!(-e $myrc) || (-e $myrc && $icall == 2)) {
1658 print "NOTE: Button colours not set in $rcfile; using defaults.\n";
1659 @tdcolors=('#d9d9d9','Black','#ececec','red');
1660 }
1661 }
1662 %butcol=('-background'=>$tdcolors[0],
1663 '-foreground'=>$tdcolors[1],
1664 '-activebackground'=>$tdcolors[2],
1665 '-activeforeground'=>$tdcolors[3]);
1666 # viewer: suppress viewer warnings/use $PAGER if no $txt_viewer is defined
1667 $quiet=($quiet =~ /y/i || $quiet eq "1") ? 1 : 0;
1668 if (!(defined $txt_viewer) && defined $ENV{PAGER}) {
1669 $txt_viewer=$ENV{PAGER};
1670 }
1671 # viewer: autostart viewer if listbox of search results contains only 1 item
1672 $autoview=($autoview =~ /y/i || $autoview eq "1") ? 1 : 0;
1673 # viewer: use text viewer to open files with unrecognized format
1674 $xfmt_viewer=($xfmt_viewer =~ /y/i || $xfmt_viewer eq "1") ? 1 : 0;
1675 # converter: output redirection flags for HTML/Text->PS converters
1676 $htmlps_redir=($htmlps_redir =~ /(y|1)/i) ? 1 : 0;
1677 $txtps_redir=($txtps_redir =~ /(y|1)/i) ? 1 : 0;
1678 # for backward compatibility of converter/printer options
1679 $dvips_conv.=" $dvips_opts" if ($dvips_opts);
1680 $pdfps_conv.=" $pdfps_opts" if ($pdfps_opts);
1681 $print_cmd.=" $print_opts" if ($print_opts);
1682 }
1683
1684 # determine resolution if xwininfo is available
1685 # slightly modified from a patch contributed by Reinhard Kotucha
1686 sub x_resolution {
1687 my $x_res;
1688 if ($IsWin32) {
1689 $x_res = &GetScreenWidth;
1690 }
1691 else {
1692 open(XINF,"xwininfo -root|") or return 1200;
1693 while (<XINF>) {
1694 chop;
1695 if (/Width:/) { ($x_res=$_)=/Width:\s+(\d+)/; last; }
1696 }
1697 close(XINF);
1698 }
1699 return $x_res;
1700 }
1701
1702 # generate a random name for temporary files
1703 sub randname {
1704 my $namestr;
1705 my @chars=("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
1706 my $time=time;
1707 my $maxcnt=3+substr($time,-1);
1708 for (my $i=0; $i<=$maxcnt; $i++) { $namestr.=$chars[rand(51)] }
1709 my @tmp=split(/./,$time/$$);
1710 $namestr.=$tmp[1];
1711 until (length($namestr) > 16) { $namestr.=int(rand(1000000)) }
1712 return $namestr;
1713 }
1714
1715 # find index of an array entry
1716 sub arrindex {
1717 my @array=@_;
1718 my $item=pop @array;
1719 my $i=0;
1720 foreach (@array) {
1721 last if ($_ eq $item);
1722 ++$i;
1723 }
1724 return $i;
1725 }
1726
1727 # clean up and exit
1728 sub clean_exit {
1729 foreach (@tmpfiles) { if (-e $_) { unlink $_; } }
1730 exit;
1731 }
1732
1733 # alternative main window, launched for fatal error messages on startup
1734 sub fatalmsg {
1735 my($msg)=@_;
1736 print STDERR $msg; # also print to stderr
1737 # create frame for main window
1738 my $main=new MainWindow;
1739 $main->resizable(0,0);
1740 $main->title("TeX Documentation Browser");
1741 $main->bind('<Control-q>'=>sub { exit });
1742 $main->bind('<Control-k>'=>sub { exit });
1743 my $msgframe=$main->Frame(-background=>"#ffcc99");
1744 my $cmdframe=$main->Frame;
1745 $msgframe->pack(-side=>'top');
1746 $cmdframe->pack(-side=>'bottom',-fill=>'x');
1747 # make buttons for command frame
1748 my $Qbut=$cmdframe->Button(-text=>'Kill',%butcol,
1749 -command=>sub { exit })->pack(-fill=>'x');
1750 # define common default font for labels and text explicitly
1751 my @deffont=$Qbut->configure(-font);
1752 # ensure readability on high-res screens (suggested by R.Kotucha)
1753 $deffont='Helvetica -16 bold' if &x_resolution > 1200;
1754 $Qbut->configure(-font=>$deffont);
1755 $msgframe->Label(-text=>'FATAL ERROR',
1756 -font=>$deffont)->pack(-side=>'top', -fill=>'x');
1757 # get size of message text
1758 my @dummy=split("\n",$msg);
1759 my $nline=scalar @dummy;
1760 my $msgwidth=0;
1761 my $lline;
1762 foreach (@dummy) {
1763 $lline=length $_;
1764 if ($lline > $msgwidth) { $msgwidth=$lline; }
1765 }
1766 my $message=$msgframe->Text(-relief=>'flat',
1767 -font=>$deffont,
1768 -height=>$nline,
1769 -width=>$msgwidth)->pack(-side=>'top');
1770 $message->insert('end',$msg);
1771 $message->configure(-state=>'disabled');
1772 MainLoop();
1773 }
1774
1775 if ($IsWin32) {
1776 sub GetScreenWidth {
1777 my $GetDeviceCaps = new Win32::API('gdi32', 'GetDeviceCaps', 'NN', 'N');
1778 my $HORZRES = 8; # from WinGDI.h
1779 if(not defined $GetDeviceCaps) {
1780 die "Can't import API GetDeviceCaps: $!\n";
1781 }
1782 return $GetDeviceCaps->Call(0, $HORZRES);
1783 }
1784
1785 sub GetTempPath {
1786 my $GetTempPath = new Win32::API('kernel32', 'GetTempPath', 'NP', 'N');
1787 if(not defined $GetTempPath) {
1788 die "Can't import API GetTempPath: $!\n";
1789 }
1790 my $lpBuffer = " " x 260;
1791
1792 $GetTempPath->Call(80, $lpBuffer);
1793 }
1794
1795 sub ShellExecute {
1796 my ($command, $file) = @_;
1797 my $ShellExecute = new Win32::API('shell32', 'ShellExecute', 'NPPPPN', 'N');
1798 if(not defined $ShellExecute) {
1799 die "Can't import API ShellExecute: $!\n";
1800 }
1801 $ShellExecute->Call(0, $command, $file, '', '', 0);
1802 }
1803
1804 sub GetHomeDir {
1805 my $home = $ENV{'HOME'};
1806 # Should check for CSIDL_...
1807 return $home;
1808 }
1809 }
1810 __END__
1811 Many TeX programmers provide more or less detailed manuals for
1812 their programs or packages. They are usually available as .dvi,
1813 .ps, .pdf, .html or plain text files (sometimes included in the
1814 .sty files instead of a separate documentation file) and can be
1815 accessed with this browser, which is simply an interface to find a
1816 documentation more easily. It starts the respective viewer for
1817 reading the selected documentation making use of a database file
1818 which contains the path entries according to the current teTeX
1819 texmf/doc structure; additional usage of a system-wide local and
1820 of individual user texmf trees with corresponding databases is also
1821 possible.
1822 The documentations are grouped in several categories shown in the
1823 main window; pressing one of its buttons lists all documentations
1824 belonging to this topic.
1825 The topic window lets you select one documentation file, view or
1826 send it to the default printer. By right-clicking on the selected
1827 item you get the complete path of the file.
1828 The search button of the main window allows you to search the
1829 database for a string; it does not search file names. Enter the
1830 string and hit <Return> to start the search or <Control-c> to
1831 cancel. Just hitting <Return> without typing something in will
1832 show the full list of files in the database.
1833 Defaults for the documentation root directory, the viewers, the
1834 converters, certain options and the printer are set in the global
1835 configuration file $sysrc.
1836 However, each user can put a copy of it as .texdocrc into his home
1837 directory to modify them according to his needs; modification or
1838 generation of ~/.texdocrc can also be done with the Settings menu.
1839 Additionally, the settings can be changed temporarily with this
1840 menu.
1841
1842 The following key shortcuts are defined for use with the browser:
1843 <Ctrl-q> Quit browser
1844 <Ctrl-m> Raise the Main window to the foreground
1845 <Ctrl-s> Search a keyword in database (case insensitive)
1846 <Ctrl-c> Cancel/close subwindow or search entry widget
1847 <Ctrl-v> View selected document (topic windows)
1848 <Ctrl-p> Print selected document (topic windows)
1849 <Ctrl-t> Open settings menu
1850 <Ctrl-k> Kill fatal error message window (same as
1851 <Ctrl-q>)
1852 <Ctrl-h> Open this help
1853 <Return> Equivalent to button press;
1854 OK in selection menu and search
1855 <Tab> Next/previous widget
1856
1857 There are the following command line options:
1858 -a autostart viewer if a listbox of search results
1859 contains only one item; can also be set in a
1860 configuration file
1861 -v disable suppression of viewer messages sent to
1862 stderr and of certain permanent message popup
1863 windows, in case this was not set in a
1864 configuration file; default: off
1865
1866 Some more information is available in the manpage of texdoctk.
1867
1868 Comments and suggestions to:
1869 Thomas Ruedas
1870 [email protected] or [email protected]
1871 # Local Variables:
1872 # mode: perl
1873 # auto-fill-hook: do-auto-fill
1874 # End:
1875 # vim: ts=8 sw=4 noexpandtab