230
230
#if !defined(ISC) && !defined(__UNIXWARE__)
231
231
#if defined(__OpenBSD__) || defined(__NetBSD__)
232
/* look in machine subdir first */
233
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
234
section + len_cat, MACHINE, page, COMPRESSION_EXTENSION);
235
if ( (file = Uncompress(man_globals, filename)) != NULL)
232
/* look in machine subdir first */
233
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
234
section + len_cat, MACHINE, page, COMPRESSION_EXTENSION);
235
if ((file = Uncompress(man_globals, filename)) != NULL)
238
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
239
section + len_cat, page, COMPRESSION_EXTENSION);
240
if ( (file = Uncompress(man_globals, filename)) != NULL)
238
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
239
section + len_cat, page, COMPRESSION_EXTENSION);
240
if ((file = Uncompress(man_globals, filename)) != NULL)
242
242
#ifdef GZIP_EXTENSION
244
244
#if defined(__OpenBSD__) || defined(__NetBSD__)
245
/* look in machine subdir first */
246
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
247
section + len_cat, MACHINE, page, GZIP_EXTENSION);
248
if ( (file = Uncompress(man_globals, filename)) != NULL)
245
/* look in machine subdir first */
246
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
247
section + len_cat, MACHINE, page, GZIP_EXTENSION);
248
if ((file = Uncompress(man_globals, filename)) != NULL)
251
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
252
section + len_cat, page, GZIP_EXTENSION);
253
if ( (file = Uncompress(man_globals, filename)) != NULL)
251
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
252
section + len_cat, page, GZIP_EXTENSION);
253
if ((file = Uncompress(man_globals, filename)) != NULL)
257
257
#ifdef BZIP2_EXTENSION
258
258
#if defined(__OpenBSD__) || defined(__NetBSD__)
259
/* look in machine subdir first */
260
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
261
section + len_cat, MACHINE, page, BZIP2_EXTENSION);
262
if ( (file = Uncompress(man_globals, filename)) != NULL)
259
/* look in machine subdir first */
260
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
261
section + len_cat, MACHINE, page, BZIP2_EXTENSION);
262
if ((file = Uncompress(man_globals, filename)) != NULL)
266
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
267
section + len_cat, page, BZIP2_EXTENSION);
268
if ( (file = Uncompress(man_globals, filename)) != NULL)
266
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
267
section + len_cat, page, BZIP2_EXTENSION);
268
if ((file = Uncompress(man_globals, filename)) != NULL)
272
272
#ifdef LZMA_EXTENSION
274
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
275
section + len_cat, page, LZMA_EXTENSION);
276
if ( (file = Uncompress(man_globals, filename)) != NULL)
274
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
275
section + len_cat, page, LZMA_EXTENSION);
276
if ((file = Uncompress(man_globals, filename)) != NULL)
281
for(i = 0; i < strlen(COMPRESSION_EXTENSIONS); i++) {
282
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%c", path, CAT,
283
section + len_cat, page, COMPRESSION_EXTENSIONS[i]);
284
uncompress_format = uncompress_formats[i];
281
for (i = 0; i < strlen(COMPRESSION_EXTENSIONS); i++) {
282
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%c", path, CAT,
283
section + len_cat, page, COMPRESSION_EXTENSIONS[i]);
284
uncompress_format = uncompress_formats[i];
286
printf("Trying .%c ...\n", COMPRESSION_EXTENSIONS[i]);
286
printf("Trying .%c ...\n", COMPRESSION_EXTENSIONS[i]);
288
if ( (file = Uncompress(man_globals, filename)) != NULL)
288
if ((file = Uncompress(man_globals, filename)) != NULL)
298
298
* HP does it this way (really :-).
301
snprintf(filename, sizeof(filename), "%s/%s%s.%s/%s", path, CAT,
302
section + len_cat, COMPRESSION_EXTENSION, page);
303
if ( (file = Uncompress(man_globals, filename)) != NULL)
301
snprintf(filename, sizeof(filename), "%s/%s%s.%s/%s", path, CAT,
302
section + len_cat, COMPRESSION_EXTENSION, page);
303
if ((file = Uncompress(man_globals, filename)) != NULL)
306
306
* We did not find any preformatted manual pages, try to format it.
309
return(Format(man_globals, entry));
309
return (Format(man_globals, entry));
313
/* Emulate mkstemp to allow use of a common API in the many calls below */
315
Xmkstemp (char *template)
320
if (strlen(template) >= sizeof(tmp))
322
/* save copy of unmodified template in case we have to try again */
323
strcpy(tmp, template);
327
strcpy(template, tmp);
328
if ((mktemp(template) == NULL) || (template[0] == '\0'))
330
fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
331
} while ((fd == -1) && (errno == EEXIST || errno == EINTR));
312
337
/* Function Namecompress
313
338
* Description: This function will attempt to find a compressed man
314
339
* page and uncompress it.
315
* Arguments: man_globals - the psuedo global info.
340
* Arguments: man_globals - the pseudo global info.
316
341
* filename - name of file to uncompress.
317
342
* Returns:; a pointer to the file or NULL.
321
Uncompress(ManpageGlobals * man_globals, char * filename)
346
Uncompress(ManpageGlobals * man_globals, const char *filename)
323
char tmp_file[BUFSIZ];
327
if ( !UncompressNamed(man_globals, filename, tmp_file) )
330
else if ((file = fopen(tmp_file, "r")) == NULL) {
331
PopupWarning(man_globals, "Something went wrong in retrieving the "
332
"uncompressed manual page try cleaning up /tmp.");
335
if (!UncompressNamed(man_globals, filename, tmp_file, &file)) {
336
PopupWarning(man_globals, "Something went wrong in retrieving the "
337
"uncompressed manual page try cleaning up /tmp.");
342
unlink(tmp_file); /* remove name in tree, it will remain
343
until we close the fd, however. */
348
char tmp_file[BUFSIZ];
351
if (!UncompressNamed(man_globals, filename, tmp_file, &file)) {
352
PopupWarning(man_globals, "Something went wrong in retrieving the "
353
"uncompressed manual page try cleaning up /tmp.");
357
remove(tmp_file); /* remove name in tree, it will remain
358
until we close the fd, however. */
347
362
/* Function Name: UncompressNamed
348
363
* Description: This function will attempt to find a compressed man
349
364
* page and uncompress it.
350
* Arguments: man_globals - the psuedo global info.
365
* Arguments: man_globals - the pseudo global info.
351
366
* filename - name of file to uncompress.
352
367
* RETURNED output - the file name output (must be an allocated string).
353
368
* Returns:; TRUE if the file was found.
358
UncompressNamed(ManpageGlobals * man_globals, char * filename, char * output)
361
UncompressNamed(ManpageGlobals * man_globals, char * filename, char * output,
372
UncompressNamed(ManpageGlobals * man_globals, const char *filename,
373
char *output, FILE ** output_file)
365
char tmp[BUFSIZ], cmdbuf[BUFSIZ], error_buf[BUFSIZ];
375
char tmp[BUFSIZ], cmdbuf[BUFSIZ], error_buf[BUFSIZ];
371
if (stat(filename, &junk) != 0) { /* Check for existance of the file. */
372
if (errno != ENOENT) {
373
snprintf(error_buf, sizeof(error_buf),
374
"Error while stating file %s, errno = %d", filename, errno);
375
PopupWarning(man_globals, error_buf);
379
if (stat(filename, &junk) != 0) { /* Check for existence of the file. */
380
if (errno != ENOENT) {
381
snprintf(error_buf, sizeof(error_buf),
382
"Error while stating file %s, errno = %d", filename,
384
PopupWarning(man_globals, error_buf);
381
* Using stdin is necessary to fool zcat since we cannot guarentee
390
* Using stdin is necessary to fool zcat since we cannot guarantee
382
391
* the .Z extension.
385
strcpy(tmp, MANTEMP); /* get a temp file. */
391
PopupWarning(man_globals, "Error creating a temp file");
394
*output_fd = fdopen(fd, "r");
394
strcpy(tmp, MANTEMP); /* get a temp file. */
397
PopupWarning(man_globals, "Error creating a temp file");
400
*output_file = fdopen(fd, "r");
401
if (*output_file == NULL) {
404
PopupWarning(man_globals, "Error opening temp file");
398
409
#ifdef GZIP_EXTENSION
399
if (streq(filename + strlen(filename) - strlen(GZIP_EXTENSION),
401
snprintf(cmdbuf, sizeof(cmdbuf), GUNZIP_FORMAT, filename, output);
410
if (streq(filename + strlen(filename) - strlen(GZIP_EXTENSION),
412
snprintf(cmdbuf, sizeof(cmdbuf), GUNZIP_FORMAT, filename, output);
404
415
#ifdef BZIP2_EXTENSION
405
if (streq(filename + strlen(filename) - strlen(BZIP2_EXTENSION),
407
snprintf(cmdbuf, sizeof(cmdbuf), BUNZIP2_FORMAT, filename, output);
416
if (streq(filename + strlen(filename) - strlen(BZIP2_EXTENSION),
418
snprintf(cmdbuf, sizeof(cmdbuf), BUNZIP2_FORMAT, filename, output);
410
421
#ifdef LZMA_EXTENSION
411
if (streq(filename + strlen(filename) - strlen(LZMA_EXTENSION),
413
snprintf(cmdbuf, sizeof(cmdbuf), UNLZMA_FORMAT, filename, output);
422
if (streq(filename + strlen(filename) - strlen(LZMA_EXTENSION),
424
snprintf(cmdbuf, sizeof(cmdbuf), UNLZMA_FORMAT, filename, output);
416
snprintf(cmdbuf, sizeof(cmdbuf), UNCOMPRESS_FORMAT, filename, output);
417
if(system(cmdbuf) == 0) /* execute search. */
427
snprintf(cmdbuf, sizeof(cmdbuf), UNCOMPRESS_FORMAT, filename, output);
428
if (system(cmdbuf) == 0) /* execute search. */
420
snprintf(error_buf, sizeof(error_buf),
421
"Error while uncompressing, command was: %s", cmdbuf);
422
PopupWarning(man_globals, error_buf);
431
snprintf(error_buf, sizeof(error_buf),
432
"Error while uncompressing, command was: %s", cmdbuf);
433
PopupWarning(man_globals, error_buf);
426
437
#if defined(SMAN) && defined(SFORMAT)
427
438
/* Function Name: SgmlToRoffNamed
428
439
* Description: This function will attempt to find an SGML man
429
440
* page and convert it to roff format.
430
* Arguments: man_globals - the psuedo global info.
441
* Arguments: man_globals - the pseudo global info.
431
442
* filename - name of file to uncompress.
432
443
* RETURNED output - the file name output (must be an allocated string).
433
444
* Returns:; TRUE if the file was found.
438
SgmlToRoffNamed(ManpageGlobals * man_globals, char * filename, char * output)
441
SgmlToRoffNamed(ManpageGlobals * man_globals, char * filename, char * output,
448
SgmlToRoffNamed(ManpageGlobals * man_globals, char *filename, char *output,
445
char tmp[BUFSIZ], cmdbuf[BUFSIZ], error_buf[BUFSIZ];
451
if (stat(filename, &junk) != 0) { /* Check for existance of the file. */
452
if (errno != ENOENT) {
453
snprintf(error_buf, sizeof(error_buf),
454
"Error while stating file %s, errno = %d", filename, errno);
455
PopupWarning(man_globals, error_buf);
460
strcpy(tmp, MANTEMP); /* get a temp file. */
466
PopupWarning(man_globals, "Error creating a temp file");
469
*output_fd = fdopen(fd, "r");
473
snprintf(cmdbuf, sizeof(cmdbuf), "%s %s > %s", SFORMAT, filename, output);
474
if(system(cmdbuf) == 0) /* execute search. */
477
snprintf(error_buf, sizeof(error_buf),
478
"Error while converting from sgml, command was: %s", cmdbuf);
479
PopupWarning(man_globals, error_buf);
451
char tmp[BUFSIZ], cmdbuf[BUFSIZ], error_buf[BUFSIZ];
455
if (stat(filename, &junk) != 0) { /* Check for existence of the file. */
456
if (errno != ENOENT) {
457
snprintf(error_buf, sizeof(error_buf),
458
"Error while stating file %s, errno = %d", filename,
460
PopupWarning(man_globals, error_buf);
465
strcpy(tmp, MANTEMP); /* get a temp file. */
468
PopupWarning(man_globals, "Error creating a temp file");
471
*output_file = fdopen(fd, "r");
472
if (*output_file == NULL) {
475
PopupWarning(man_globals, "Error opening temp file");
480
snprintf(cmdbuf, sizeof(cmdbuf), "%s %s >> %s", SFORMAT, filename, output);
481
if (system(cmdbuf) == 0) /* execute search. */
484
snprintf(error_buf, sizeof(error_buf),
485
"Error while converting from sgml, command was: %s", cmdbuf);
486
PopupWarning(man_globals, error_buf);
482
#endif /* defined (SMAN) && defined(SFORMAT) */
489
#endif /* defined (SMAN) && defined(SFORMAT) */
484
491
/* Function Name: Format
485
* Description: This funtion formats the manual pages and interfaces
492
* Description: This function formats the manual pages and interfaces
487
* Arguments: man_globals - the psuedo globals
494
* Arguments: man_globals - the pseudo globals
488
495
* file - the file pointer to use and return
489
496
* entry - the current entry struct.
490
497
* current_box - The current directory being displayed.
497
Format(ManpageGlobals * man_globals, char * entry)
503
Format(ManpageGlobals * man_globals, const char *entry)
503
Widget manpage = man_globals->manpagewidgets.manpage;
504
char cmdbuf[BUFSIZ], tmp[BUFSIZ], filename[BUFSIZ], error_buf[BUFSIZ];
505
char path[BUFSIZ], sect[BUFSIZ];
507
Position x,y; /* location to pop up the
508
"would you like to save" widget. */
511
if ( !UncompressUnformatted(man_globals, entry, filename) ) {
513
if ( !UncompressUnformatted(man_globals, entry, filename, &file) ) {
515
/* We Really could not find it, this should never happen, yea right. */
516
snprintf(error_buf, sizeof(error_buf),
517
"Could not open manual page, %s", entry);
518
PopupWarning(man_globals, error_buf);
519
XtPopdown( XtParent(man_globals->standby) );
524
if ((file = fopen(filename, "r")) != NULL) {
530
if (fgets(line, sizeof(line), file) != NULL) {
531
if (strncmp(line, ".so ", 4) == 0) {
532
line[strlen(line) - 1] = '\0';
535
if (line[4] != '/') {
539
if ((ptr = rindex(tmp, '/')) != NULL) {
541
if ((ptr = rindex(tmp, '/')) != NULL)
547
snprintf(filename, sizeof(filename), "%s%s", tmp, line + 4);
549
return (Format(man_globals, filename));
555
Popup(XtParent(man_globals->standby), XtGrabExclusive);
556
while ( !XCheckTypedWindowEvent(XtDisplay(man_globals->standby),
557
XtWindow(man_globals->standby),
559
XtDispatchEvent( &event );
560
XFlush(XtDisplay(man_globals->standby));
562
strcpy(tmp,MANTEMP); /* Get a temp file. */
567
file = fdopen(fd, "r");
569
strcpy(man_globals->tempfile, tmp);
571
ParseEntry(entry, path, sect, NULL);
508
Widget manpage = man_globals->manpagewidgets.manpage;
509
char cmdbuf[BUFSIZ], tmp[BUFSIZ], filename[BUFSIZ], error_buf[BUFSIZ];
510
char path[BUFSIZ], sect[BUFSIZ];
512
Position x, y; /* location to pop up the
513
"would you like to save" widget. */
515
if (!UncompressUnformatted(man_globals, entry, filename, &file)) {
516
/* We Really could not find it, this should never happen, yea right. */
517
snprintf(error_buf, sizeof(error_buf),
518
"Could not open manual page, %s", entry);
519
PopupWarning(man_globals, error_buf);
520
XtPopdown(XtParent(man_globals->standby));
527
if (fgets(line, sizeof(line), file) != NULL) {
528
if (strncmp(line, ".so ", 4) == 0) {
529
line[strlen(line) - 1] = '\0';
532
if (line[4] != '/') {
536
if ((ptr = strrchr(tmp, '/')) != NULL) {
538
if ((ptr = strrchr(tmp, '/')) != NULL)
544
snprintf(filename, sizeof(filename), "%s%s", tmp, line + 4);
546
return (Format(man_globals, filename));
552
Popup(XtParent(man_globals->standby), XtGrabExclusive);
553
while (!XCheckTypedWindowEvent(XtDisplay(man_globals->standby),
554
XtWindow(man_globals->standby),
556
XtDispatchEvent(&event);
557
XFlush(XtDisplay(man_globals->standby));
559
strcpy(tmp, MANTEMP); /* Get a temp file. */
562
file = fdopen(fd, "r");
571
PopupWarning(man_globals, "Something went wrong in opening the "
572
"temp file, try cleaning up /tmp");
575
strcpy(man_globals->tempfile, tmp);
577
ParseEntry(entry, path, sect, NULL);
573
579
#ifndef HANDLE_ROFFSEQ
575
snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s > %s %s", path, TBL,
576
filename, FORMAT, man_globals->tempfile, "2> /dev/null");
578
snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s >> %s %s", path, TBL,
579
filename, FORMAT, man_globals->tempfile, "2> /dev/null");
582
/* Handle more flexible way of specifying the formatting pipeline */
583
if (! ConstructCommand(cmdbuf, path, filename, man_globals->tempfile)) {
584
PopupWarning(man_globals, "Constructed command was too long!");
588
#endif /* HANDLE_ROFFSEQ */
580
snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s >> %s %s", path, TBL,
581
filename, FORMAT, man_globals->tempfile, "2> /dev/null");
583
/* Handle more flexible way of specifying the formatting pipeline */
584
if (!ConstructCommand(cmdbuf, path, filename, man_globals->tempfile)) {
585
PopupWarning(man_globals, "Constructed command was too long!");
590
#endif /* HANDLE_ROFFSEQ */
590
if(system(cmdbuf) != 0) { /* execute search. */
591
snprintf(error_buf, sizeof(error_buf),
592
"Something went wrong trying to run the command: %s", cmdbuf);
593
PopupWarning(man_globals, error_buf);
598
if ((file = fopen(man_globals->tempfile,"r")) == NULL) {
599
PopupWarning(man_globals, "Something went wrong in retrieving the "
600
"temp file, try cleaning up /tmp");
592
if (system(cmdbuf) != 0) { /* execute search. */
593
snprintf(error_buf, sizeof(error_buf),
594
"Something went wrong trying to run the command: %s", cmdbuf);
595
PopupWarning(man_globals, error_buf);
605
XtPopdown( XtParent(man_globals->standby) );
607
if ( (man_globals->save == NULL) ||
608
(man_globals->manpagewidgets.manpage == NULL) )
609
unlink(man_globals->tempfile);
611
char * ptr, catdir[BUFSIZ];
614
* If the catdir is writeable then ask the user if he/she wants to
615
* write the man page to it.
618
strcpy(catdir, man_globals->save_file);
619
if ( (ptr = rindex(catdir, '/')) != NULL) {
622
if ( access(catdir, W_OK) != 0 )
623
unlink(man_globals->tempfile);
625
x = (Position) Width(man_globals->manpagewidgets.manpage)/2;
626
y = (Position) Height(man_globals->manpagewidgets.manpage)/2;
627
XtTranslateCoords(manpage, x, y, &x, &y);
628
PositionCenter( man_globals->save, (int) x, (int) y, 0, 0, 0, 0);
629
XtPopup( man_globals->save, XtGrabExclusive);
633
unlink(man_globals->tempfile);
601
XtPopdown(XtParent(man_globals->standby));
603
if ((man_globals->save == NULL) ||
604
(man_globals->manpagewidgets.manpage == NULL))
605
remove(man_globals->tempfile);
607
char *ptr, catdir[BUFSIZ];
610
* If the catdir is writable then ask the user if he/she wants to
611
* write the man page to it.
614
strcpy(catdir, man_globals->save_file);
615
if ((ptr = strrchr(catdir, '/')) != NULL) {
618
if (access(catdir, W_OK) != 0)
619
remove(man_globals->tempfile);
621
x = (Position) Width(man_globals->manpagewidgets.
623
y = (Position) Height(man_globals->manpagewidgets.
625
XtTranslateCoords(manpage, x, y, &x, &y);
626
PositionCenter(man_globals->save, (int) x, (int) y, 0,
628
XtPopup(man_globals->save, XtGrabExclusive);
632
remove(man_globals->tempfile);
641
* If the original was compressed or in another format, delete temporary file.
643
if (man_globals->deletetempfile)
638
* If the original was compressed or in another format, delete temporary file.
640
if (man_globals->deletetempfile)
649
646
#ifdef HANDLE_ROFFSEQ
659
656
* be too long (more than BUFSIZ characters)
662
ConstructCommand(cmdbuf, path, filename, tempfile)
663
char *cmdbuf, *path, *filename, *tempfile;
659
ConstructCommand(char *cmdbuf, const char *path,
660
const char *filename, const char *tempfile)
665
/* The original code did the following to produce a command line:
666
* sprintf(cmdbuf,"cd %s ; %s %s %s > %s %s", path, TBL,
667
* filename, FORMAT, man_globals->tempfile, "2> /dev/null");
668
* We are more flexible and follow more or less the algorithm used
669
* by the Linux man command:
670
* + Obtain a string of letters from the following sources in order
672
* + a command line option (not implemented in xman; it's probably not
674
* + the first line of the manpage source, if it is of the form:
676
* + the MANROFFSEQ environment variable
677
* + a default string; this is "".
678
* + Interpret the string as a pipeline of filters:
679
* + e = eqn g = grap p = pic t = tbl v = vgrind r = refer
680
* + zsoelim is always run as the first preprocessor in any case.
682
* Strictly speaking we should save a catpage iff the string comes
683
* from the file or is the default.
685
* You'll notice that we format a man page into ASCII text output and then
686
* attempt to interpret things like L^HL as bold and so forth. This
687
* is so obviously the Wrong Thing it's untrue.
689
char *c = cmdbuf; /* current posn in buffer */
690
int left = BUFSIZ; /* space left in buffer */
695
int gotfmt = 0; /* set to 1 if we got a directive from source */
696
char fname[PATH_MAX];
702
/* If you have a command line option that gives a setting for fmt,
706
/* This is the tricky bit: extract a format string from the source file
707
* Annoyingly, filename might be relative or absolute. We cheat and
708
* use system to get the thing to a known absoute filename.
710
if (filename[0] == '/') {
711
snprintf(fname, sizeof(fname), "%s", filename);
713
snprintf(fname, sizeof(fname), "%s/%s", path, filename);
715
if ((file = fopen(fname, "r")) &&
716
(fgets(fmtbuf, sizeof(fmtbuf), file)) &&
717
(!memcmp(fmtbuf, "'\\\" ", 4))) {
718
/* that's squote-backslash-dquote-space */
722
if (len && (fmt[len-1] == '\n')) {
727
if (!gotfmt) /* not there or some error */
729
fmt = getenv("MANROFFSEQ");
735
fmt = DEFAULT_MANROFFSEQ;
739
/* Start with the first fixed part of the command line */
741
for (i = 0; i < strlen(path); i++) {
745
used = snprintf(c, left, "cd %s & %s %s ", path, ZSOELIM, filename);
747
used = snprintf(c, left, "cd %s; %s %s ", path, ZSOELIM, filename);
754
/* Now add preprocessors of the form '| processor' */
662
/* The original code did the following to produce a command line:
663
* sprintf(cmdbuf,"cd %s ; %s %s %s > %s %s", path, TBL,
664
* filename, FORMAT, man_globals->tempfile, "2> /dev/null");
665
* We are more flexible and follow more or less the algorithm used
666
* by the Linux man command:
667
* + Obtain a string of letters from the following sources in order
669
* + a command line option (not implemented in xman; it's probably not
671
* + the first line of the manpage source, if it is of the form:
673
* + the MANROFFSEQ environment variable
674
* + a default string; this is "".
675
* + Interpret the string as a pipeline of filters:
676
* + e = eqn g = grap p = pic t = tbl v = vgrind r = refer
677
* + zsoelim is always run as the first preprocessor in any case.
679
* Strictly speaking we should save a catpage iff the string comes
680
* from the file or is the default.
682
* You'll notice that we format a man page into ASCII text output and then
683
* attempt to interpret things like L^HL as bold and so forth. This
684
* is so obviously the Wrong Thing it's untrue.
686
char *c = cmdbuf; /* current posn in buffer */
687
int left = BUFSIZ; /* space left in buffer */
693
/* If you have a command line option that gives a setting for fmt,
697
/* This is the tricky bit: extract a format string from the source file
698
* Annoyingly, filename might be relative or absolute. We cheat and
699
* use system to get the thing to a known absolute filename.
702
int gotfmt = 0; /* set to 1 if we got a directive from source */
703
char fname[PATH_MAX];
705
if (filename[0] == '/') {
706
snprintf(fname, sizeof(fname), "%s", filename);
709
snprintf(fname, sizeof(fname), "%s/%s", path, filename);
711
if ((file = fopen(fname, "r")) != NULL) {
712
if ((fgets(fmtbuf, sizeof(fmtbuf), file)) &&
713
(!memcmp(fmtbuf, "'\\\" ", 4))) {
714
/* that's squote-backslash-dquote-space */
715
int len = strlen(fmtbuf);
717
if (len && (fmtbuf[len - 1] == '\n')) {
725
if (!gotfmt) { /* not there or some error */
726
fmt = getenv("MANROFFSEQ");
731
fmt = DEFAULT_MANROFFSEQ;
734
/* Start with the first fixed part of the command line */
735
used = snprintf(c, left, "cd %s; %s %s ", path, ZSOELIM, filename);
741
/* Now add preprocessors of the form '| processor' */
742
for (; *fmt; fmt++) {
784
used = snprintf(c, left, " | %s ", filter);
792
/* Now add the fixed trailing part 'formatprog > tempfile 2> /dev/null' */
794
used = snprintf(c, left, " | %s > %s 2>NUL", FORMAT, tempfile);
797
used = snprintf(c, left, " | %s > %s 2>/dev/null", FORMAT, tempfile);
799
used = snprintf(c, left, " | %s >> %s 2>/dev/null", FORMAT, tempfile);
801
#endif /* __UNIXOS2__ */
769
used = snprintf(c, left, " | %s ", filter);
777
/* Now add the fixed trailing part 'formatprog > tempfile 2> /dev/null' */
778
used = snprintf(c, left, " | %s >> %s 2>/dev/null", FORMAT, tempfile);
808
#endif /* HANDLE_ROFFSEQ */
785
#endif /* HANDLE_ROFFSEQ */
810
787
/* Function Name: UncompressUnformatted
811
788
* Description: Finds an uncompressed unformatted manual page.
812
* Arguments: man_globals - the psuedo global structure.
789
* Arguments: man_globals - the pseudo global structure.
813
790
* entry - the manual page entry.
814
791
* RETURNED filename - location to put the name of the file.
815
792
* Returns: TRUE if the file was found.
820
UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
823
UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
824
char * filename, FILE **file)
796
UncompressUnformatted(ManpageGlobals * man_globals, const char *entry,
797
char *filename, FILE ** file)
827
char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], input[BUFSIZ];
828
int len_cat = strlen(CAT), len_man = strlen(MAN);
799
char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], input[BUFSIZ];
800
int len_cat = strlen(CAT), len_man = strlen(MAN);
829
802
#if defined(SMAN) && defined(SFORMAT)
830
int len_sman = strlen(SMAN);
803
int len_sman = strlen(SMAN);
833
ParseEntry(entry, path, section, page);
806
ParseEntry(entry, path, section, page);
835
man_globals->bzip2 = FALSE;
836
man_globals->lzma = FALSE;
808
man_globals->bzip2 = FALSE;
809
man_globals->lzma = FALSE;
838
811
#if defined(__OpenBSD__) || defined(__NetBSD__)
840
* look for uncompressed file in machine subdir first
842
snprintf(filename, BUFSIZ, "%s/%s%s/%s/%s", path, MAN,
843
section + len_cat, MACHINE, page);
844
if ( access( filename, R_OK ) == 0 ) {
845
man_globals->compress = FALSE;
846
man_globals->gzip = FALSE;
847
man_globals->deletetempfile = FALSE;
848
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
849
"%s/%s%s/%s/%s", path, CAT, section + len_cat, MACHINE, page);
853
* Then for compressed files in an uncompressed directory.
855
snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
857
if ( UncompressNamed(man_globals, input, filename) ) {
859
if ( UncompressNamed(man_globals, input, filename, file) ) {
861
man_globals->compress = TRUE;
862
man_globals->deletetempfile = TRUE;
863
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
864
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
865
COMPRESSION_EXTENSION);
813
* look for uncompressed file in machine subdir first
815
snprintf(filename, BUFSIZ, "%s/%s%s/%s/%s", path, MAN,
816
section + len_cat, MACHINE, page);
817
if (access(filename, R_OK) == 0) {
818
man_globals->compress = FALSE;
819
man_globals->gzip = FALSE;
820
man_globals->deletetempfile = FALSE;
821
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
822
"%s/%s%s/%s/%s", path, CAT, section + len_cat, MACHINE, page);
826
* Then for compressed files in an uncompressed directory.
828
snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
829
if (UncompressNamed(man_globals, input, filename, file)) {
830
man_globals->compress = TRUE;
831
man_globals->deletetempfile = TRUE;
832
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
833
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
834
COMPRESSION_EXTENSION);
868
837
#ifdef GZIP_EXTENSION
870
snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
872
if ( UncompressNamed(man_globals, input, filename) ) {
874
if ( UncompressNamed(man_globals, input, filename, file) ) {
876
man_globals->compress = TRUE;
877
man_globals->gzip = TRUE;
878
man_globals->deletetempfile = TRUE;
879
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
880
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
839
snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
840
if (UncompressNamed(man_globals, input, filename, file)) {
841
man_globals->compress = TRUE;
842
man_globals->gzip = TRUE;
843
man_globals->deletetempfile = TRUE;
844
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
845
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
885
#endif /* GZIP_EXTENSION */
886
#endif /* __OpenBSD__ || __NetBSD__ */
850
#endif /* GZIP_EXTENSION */
851
#endif /* __OpenBSD__ || __NetBSD__ */
888
853
#ifdef BZIP2_EXTENSION
890
snprintf(input, sizeof(input), "%s.%s", filename, BZIP2_EXTENSION);
892
if ( UncompressNamed(man_globals, input, filename) ) {
894
if ( UncompressNamed(man_globals, input, filename, file) ) {
896
man_globals->compress = TRUE;
897
man_globals->gzip = FALSE;
898
man_globals->bzip2 = TRUE;
899
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
900
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
855
snprintf(input, sizeof(input), "%s.%s", filename, BZIP2_EXTENSION);
856
if (UncompressNamed(man_globals, input, filename, file)) {
857
man_globals->compress = TRUE;
858
man_globals->gzip = FALSE;
859
man_globals->bzip2 = TRUE;
860
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
861
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
905
#endif /* BZIP2_EXTENSION */
866
#endif /* BZIP2_EXTENSION */
907
868
#ifdef LZMA_EXTENSION
909
snprintf(input, sizeof(input), "%s.%s", filename, LZMA_EXTENSION);
911
if ( UncompressNamed(man_globals, input, filename) ) {
913
if ( UncompressNamed(man_globals, input, filename, file) ) {
915
man_globals->compress = TRUE;
916
man_globals->gzip = FALSE;
917
man_globals->lzma = TRUE;
918
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
919
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
870
snprintf(input, sizeof(input), "%s.%s", filename, LZMA_EXTENSION);
871
if (UncompressNamed(man_globals, input, filename, file)) {
872
man_globals->compress = TRUE;
873
man_globals->gzip = FALSE;
874
man_globals->lzma = TRUE;
875
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
876
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
924
#endif /* LZMA_EXTENSION */
881
#endif /* LZMA_EXTENSION */
927
884
* Look for uncompressed file first.
930
snprintf(filename, BUFSIZ, "%s/%s%s/%s", path, MAN, section + len_man, page);
931
if ( access( filename, R_OK ) == 0 ) {
932
man_globals->compress = FALSE;
933
man_globals->gzip = FALSE;
934
man_globals->deletetempfile = FALSE;
935
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
936
"%s/%s%s/%s", path, CAT, section + len_cat, page);
887
snprintf(filename, BUFSIZ, "%s/%s%s/%s", path, MAN, section + len_man,
889
if (access(filename, R_OK) == 0) {
890
man_globals->compress = FALSE;
891
man_globals->gzip = FALSE;
892
man_globals->deletetempfile = FALSE;
893
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
894
"%s/%s%s/%s", path, CAT, section + len_cat, page);
940
898
#if defined(SMAN) && defined(SFORMAT)
942
* Look for uncompressed sgml file next.
900
* Look for uncompressed sgml file next.
945
snprintf(input, BUFSIZ, "%s/%s%s/%s", path, SMAN, section + len_sman, page);
947
if ( SgmlToRoffNamed(man_globals, input, filename) ) {
949
if ( SgmlToRoffNamed(man_globals, input, filename, file) ) {
951
man_globals->compress = FALSE;
952
man_globals->gzip = FALSE;
953
man_globals->deletetempfile = TRUE;
954
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
955
"%s/%s%s/%s", path, CAT, section + len_cat, page);
903
snprintf(input, BUFSIZ, "%s/%s%s/%s", path, SMAN, section + len_sman, page);
904
if (SgmlToRoffNamed(man_globals, input, filename, file)) {
905
man_globals->compress = FALSE;
906
man_globals->gzip = FALSE;
907
man_globals->deletetempfile = TRUE;
908
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
909
"%s/%s%s/%s", path, CAT, section + len_cat, page);
961
915
* Then for compressed files in an uncompressed directory.
964
snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
966
if ( UncompressNamed(man_globals, input, filename) ) {
968
if ( UncompressNamed(man_globals, input, filename, file) ) {
970
man_globals->compress = TRUE;
971
man_globals->deletetempfile = TRUE;
972
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
973
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
974
COMPRESSION_EXTENSION);
918
snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
919
if (UncompressNamed(man_globals, input, filename, file)) {
920
man_globals->compress = TRUE;
921
man_globals->deletetempfile = TRUE;
922
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
923
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
924
COMPRESSION_EXTENSION);
977
927
#ifdef GZIP_EXTENSION
979
snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
981
if ( UncompressNamed(man_globals, input, filename) ) {
983
if ( UncompressNamed(man_globals, input, filename, file) ) {
985
man_globals->compress = TRUE;
986
man_globals->gzip = TRUE;
987
man_globals->deletetempfile = TRUE;
988
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
989
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
929
snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
930
if (UncompressNamed(man_globals, input, filename, file)) {
931
man_globals->compress = TRUE;
932
man_globals->gzip = TRUE;
933
man_globals->deletetempfile = TRUE;
934
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
935
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
996
942
#ifdef BZIP2_EXTENSION
998
snprintf(input, sizeof(input), "%s.%s", filename, BZIP2_EXTENSION);
1000
if ( UncompressNamed(man_globals, input, filename) ) {
1002
if ( UncompressNamed(man_globals, input, filename, file) ) {
1004
man_globals->compress = TRUE;
1005
man_globals->gzip = TRUE;
1006
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
1007
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
944
snprintf(input, sizeof(input), "%s.%s", filename, BZIP2_EXTENSION);
945
if (UncompressNamed(man_globals, input, filename, file)) {
946
man_globals->compress = TRUE;
947
man_globals->gzip = TRUE;
948
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
949
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
1014
956
#ifdef LZMA_EXTENSION
1016
snprintf(input, sizeof(input), "%s.%s", filename, LZMA_EXTENSION);
1018
if ( UncompressNamed(man_globals, input, filename) ) {
1020
if ( UncompressNamed(man_globals, input, filename, file) ) {
1022
man_globals->compress = TRUE;
1023
man_globals->lzma = TRUE;
1024
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
1025
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
958
snprintf(input, sizeof(input), "%s.%s", filename, LZMA_EXTENSION);
959
if (UncompressNamed(man_globals, input, filename, file)) {
960
man_globals->compress = TRUE;
961
man_globals->lzma = TRUE;
962
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
963
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
1033
971
* And lastly files in a compressed directory.
1036
snprintf(input, sizeof(input), "%s/%s%s.%s/%s", path,
1037
MAN, section + len_man, COMPRESSION_EXTENSION, page);
1039
if ( UncompressNamed(man_globals, input, filename) ) {
1041
if ( UncompressNamed(man_globals, input, filename, file) ) {
1043
man_globals->compress = TRUE;
1044
man_globals->deletetempfile = TRUE;
1045
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
1046
"%s/%s%s.%s/%s", path, CAT, section + len_cat,
1047
COMPRESSION_EXTENSION, page);
974
snprintf(input, sizeof(input), "%s/%s%s.%s/%s", path,
975
MAN, section + len_man, COMPRESSION_EXTENSION, page);
976
if (UncompressNamed(man_globals, input, filename, file)) {
977
man_globals->compress = TRUE;
978
man_globals->deletetempfile = TRUE;
979
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
980
"%s/%s%s.%s/%s", path, CAT, section + len_cat,
981
COMPRESSION_EXTENSION, page);
1053
987
/* Function Name: AddCursor