#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "globals.h"
#include "vendor.h"
#include <X11/Xos.h>
#include <sys/stat.h>
#include <errno.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Shell.h>
static FILE * Uncompress(ManpageGlobals * man_globals, char * filename);
#ifndef HAS_MKSTEMP
static Boolean UncompressNamed(ManpageGlobals * man_globals, char * filename,
char * output);
static Boolean UncompressUnformatted(ManpageGlobals * man_globals,
char * entry, char * filename);
#else
static Boolean UncompressNamed(ManpageGlobals * man_globals, char * filename,
char * output, FILE ** output_fd);
static Boolean UncompressUnformatted(ManpageGlobals * man_globals,
char * entry, char * filename,
FILE **file);
#endif
#ifdef HANDLE_ROFFSEQ
static Boolean ConstructCommand(char * cmdbuf, char * path, char * filename, char * tempfile);
#endif
#if defined(ISC) || defined(__SCO__) || defined(__UNIXWARE__)
static char *uncompress_format = NULL;
static char *uncompress_formats[] =
{ UNCOMPRESS_FORMAT_1,
UNCOMPRESS_FORMAT_2,
UNCOMPRESS_FORMAT_3
};
#endif
static Widget warnShell, warnDialog;
static void
PopdownWarning(Widget w, XtPointer client, XtPointer call)
{
XtPopdown((Widget)client);
}
void
PopupWarning(ManpageGlobals * man_globals, char * string)
{
int n;
Arg wargs[3];
Dimension topX, topY;
char buffer[BUFSIZ];
Boolean hasPosition;
snprintf( buffer, sizeof(buffer), "Xman Warning: %s", string);
hasPosition = FALSE;
if (top)
{
n=0;
XtSetArg(wargs[n], XtNx, &topX); n++;
XtSetArg(wargs[n], XtNy, &topY); n++;
XtGetValues(top, wargs, n);
hasPosition = TRUE;
}
if (man_globals != NULL)
ChangeLabel(man_globals->label, buffer);
if (man_globals->label == NULL) {
n=0;
if (hasPosition)
{
XtSetArg(wargs[n], XtNx, topX); n++;
XtSetArg(wargs[n], XtNy, topY); n++;
}
XtSetArg(wargs[n], XtNtransientFor, top); n++;
warnShell = XtCreatePopupShell("warnShell", transientShellWidgetClass,
initial_widget, wargs, n);
XtSetArg(wargs[0], XtNlabel, buffer);
warnDialog = XtCreateManagedWidget("warnDialog", dialogWidgetClass,
warnShell, wargs, 1);
XawDialogAddButton(warnDialog, "dismiss", PopdownWarning,
(XtPointer)warnShell);
XtRealizeWidget(warnShell);
Popup(warnShell, XtGrabNone);
}
}
void
PrintError(char * string)
{
fprintf(stderr,"Xman Error: %s\n",string);
exit(EXIT_FAILURE);
}
void
OpenFile(ManpageGlobals * man_globals, FILE * file)
{
Arg arglist[1];
Cardinal num_args = 0;
if (man_globals->curr_file) {
#if 0
fclose(man_globals->curr_file);
#endif
}
man_globals->curr_file = file;
XtSetArg(arglist[num_args], XtNfile, man_globals->curr_file); num_args++;
XtSetValues(man_globals->manpagewidgets.manpage, arglist, num_args);
}
FILE *
FindManualFile(ManpageGlobals * man_globals, int section_num, int entry_num)
{
FILE * file;
char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], *temp;
char filename[BUFSIZ];
char * entry = manual[section_num].entries[entry_num];
int len_cat = strlen(CAT);
#if defined(ISC) || defined(__SCO__) || defined(__UNIXWARE__)
int i;
#endif
temp = CreateManpageName(entry, 0, 0);
snprintf(man_globals->manpage_title, sizeof(man_globals->manpage_title),
"The current manual page is: %s.", temp);
XtFree(temp);
ParseEntry(entry, path, section, page);
#if defined(__OpenBSD__) || defined(__NetBSD__)
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s", path, CAT,
section + len_cat, MACHINE, page);
if ( (file = fopen(filename,"r")) != NULL)
return(file);
#endif
snprintf(filename, sizeof(filename), "%s/%s%s/%s",
path, CAT, section + len_cat, page);
if ( (file = fopen(filename,"r")) != NULL)
return(file);
#if !defined(ISC) && !defined(__UNIXWARE__)
#if defined(__OpenBSD__) || defined(__NetBSD__)
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
section + len_cat, MACHINE, page, COMPRESSION_EXTENSION);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
#endif
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
section + len_cat, page, COMPRESSION_EXTENSION);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
#ifdef GZIP_EXTENSION
else {
#if defined(__OpenBSD__) || defined(__NetBSD__)
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
section + len_cat, MACHINE, page, GZIP_EXTENSION);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
#endif
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%s", path, CAT,
section + len_cat, page, GZIP_EXTENSION);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
}
#endif
#ifdef BZIP2_EXTENSION
#if defined(__OpenBSD__) || defined(__NetBSD__)
snprintf(filename, sizeof(filename), "%s/%s%s/%s/%s.%s", path, CAT,
section + len_cat, MACHINE, page, BZIP2_EXTENSION);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
#endif
{
sprintf(filename, "%s/%s%s/%s.%s", path, CAT,
section + len_cat, page, BZIP2_EXTENSION);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
}
#endif
#ifdef LZMA_EXTENSION
{
sprintf(filename, "%s/%s%s/%s.%s", path, CAT,
section + len_cat, page, LZMA_EXTENSION);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
}
#endif
#else
for(i = 0; i < strlen(COMPRESSION_EXTENSIONS); i++) {
snprintf(filename, sizeof(filename), "%s/%s%s/%s.%c", path, CAT,
section + len_cat, page, COMPRESSION_EXTENSIONS[i]);
uncompress_format = uncompress_formats[i];
#ifdef DEBUG
printf("Trying .%c ...\n", COMPRESSION_EXTENSIONS[i]);
#endif
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
}
#endif
snprintf(filename, sizeof(filename), "%s/%s%s.%s/%s", path, CAT,
section + len_cat, COMPRESSION_EXTENSION, page);
if ( (file = Uncompress(man_globals, filename)) != NULL)
return(file);
return(Format(man_globals, entry));
}
static FILE *
Uncompress(ManpageGlobals * man_globals, char * filename)
{
char tmp_file[BUFSIZ], error_buf[BUFSIZ];
FILE * file;
#ifndef HAS_MKSTEMP
if ( !UncompressNamed(man_globals, filename, tmp_file) )
return(NULL);
else if ((file = fopen(tmp_file, "r")) == NULL) {
sprintf(error_buf, "Something went wrong in retrieving the %s",
"uncompressed manual page try cleaning up /tmp.");
PopupWarning(man_globals, error_buf);
}
#else
if (!UncompressNamed(man_globals, filename, tmp_file, &file)) {
sprintf(error_buf, "Something went wrong in retrieving the %s",
"uncompressed manual page try cleaning up /tmp.");
PopupWarning(man_globals, error_buf);
return(NULL);
}
#endif
unlink(tmp_file);
return(file);
}
#ifndef HAS_MKSTEMP
static Boolean
UncompressNamed(ManpageGlobals * man_globals, char * filename, char * output)
#else
static Boolean
UncompressNamed(ManpageGlobals * man_globals, char * filename, char * output,
FILE ** output_fd)
#endif
{
char tmp[BUFSIZ], cmdbuf[BUFSIZ], error_buf[BUFSIZ];
struct stat junk;
#ifdef HAS_MKSTEMP
int fd;
#endif
if (stat(filename, &junk) != 0) {
if (errno != ENOENT) {
snprintf(error_buf, sizeof(error_buf),
"Error while stating file %s, errno = %d", filename, errno);
PopupWarning(man_globals, error_buf);
}
return(FALSE);
}
strcpy(tmp, MANTEMP);
#ifndef HAS_MKSTEMP
(void) mktemp(tmp);
#else
fd = mkstemp(tmp);
if (fd < 0) {
PopupWarning(man_globals, "Error creating a temp file");
return FALSE;
}
*output_fd = fdopen(fd, "r");
#endif
strcpy(output, tmp);
#ifdef GZIP_EXTENSION
if (streq(filename + strlen(filename) - strlen(GZIP_EXTENSION),
GZIP_EXTENSION))
snprintf(cmdbuf, sizeof(cmdbuf), GUNZIP_FORMAT, filename, output);
else
#endif
#ifdef BZIP2_EXTENSION
if (streq(filename + strlen(filename) - strlen(BZIP2_EXTENSION),
BZIP2_EXTENSION))
sprintf(cmdbuf, BUNZIP2_FORMAT, filename, output);
else
#endif
#ifdef LZMA_EXTENSION
if (streq(filename + strlen(filename) - strlen(LZMA_EXTENSION),
LZMA_EXTENSION))
sprintf(cmdbuf, UNLZMA_FORMAT, filename, output);
else
#endif
snprintf(cmdbuf, sizeof(cmdbuf), UNCOMPRESS_FORMAT, filename, output);
if(system(cmdbuf) == 0)
return(TRUE);
snprintf(error_buf, sizeof(error_buf),
"Error while uncompressing, command was: %s", cmdbuf);
PopupWarning(man_globals, error_buf);
return(FALSE);
}
#if defined(SMAN) && defined(SFORMAT)
#ifndef HAS_MKSTEMP
static Boolean
SgmlToRoffNamed(ManpageGlobals * man_globals, char * filename, char * output)
#else
static Boolean
SgmlToRoffNamed(ManpageGlobals * man_globals, char * filename, char * output,
FILE ** output_fd)
#endif
{
char tmp[BUFSIZ], cmdbuf[BUFSIZ], error_buf[BUFSIZ];
struct stat junk;
#ifdef HAS_MKSTEMP
int fd;
#endif
if (stat(filename, &junk) != 0) {
if (errno != ENOENT) {
snprintf(error_buf, sizeof(error_buf),
"Error while stating file %s, errno = %d", filename, errno);
PopupWarning(man_globals, error_buf);
}
return(FALSE);
}
strcpy(tmp, MANTEMP);
#ifndef HAS_MKSTEMP
(void) mktemp(tmp);
#else
fd = mkstemp(tmp);
if (fd < 0) {
PopupWarning(man_globals, "Error creating a temp file");
return FALSE;
}
*output_fd = fdopen(fd, "r");
#endif
strcpy(output, tmp);
snprintf(cmdbuf, sizeof(cmdbuf), "%s %s > %s", SFORMAT, filename, output);
if(system(cmdbuf) == 0)
return(TRUE);
snprintf(error_buf, sizeof(error_buf),
"Error while converting from sgml, command was: %s", cmdbuf);
PopupWarning(man_globals, error_buf);
return(FALSE);
}
#endif
FILE *
Format(ManpageGlobals * man_globals, char * entry)
{
FILE * file = NULL;
#ifdef HAS_MKSTEMP
int fd;
#endif
Widget manpage = man_globals->manpagewidgets.manpage;
char cmdbuf[BUFSIZ], tmp[BUFSIZ], filename[BUFSIZ], error_buf[BUFSIZ];
char path[BUFSIZ], sect[BUFSIZ];
XEvent event;
Position x,y;
#ifndef HAS_MKSTEMP
if ( !UncompressUnformatted(man_globals, entry, filename) ) {
#else
if ( !UncompressUnformatted(man_globals, entry, filename, &file) ) {
#endif
snprintf(error_buf, sizeof(error_buf),
"Could not open manual page, %s", entry);
PopupWarning(man_globals, error_buf);
XtPopdown( XtParent(man_globals->standby) );
return(NULL);
}
#ifndef HAS_MKSTEMP
if ((file = fopen(filename, "r")) != NULL) {
#else
if (file != NULL) {
#endif
char line[BUFSIZ];
if (fgets(line, sizeof(line), file) != NULL) {
if (strncmp(line, ".so ", 4) == 0) {
line[strlen(line) - 1] = '\0';
fclose(file);
unlink(filename);
if (line[4] != '/') {
char *ptr = NULL;
strcpy(tmp, entry);
if ((ptr = rindex(tmp, '/')) != NULL) {
*ptr = '\0';
if ((ptr = rindex(tmp, '/')) != NULL)
ptr[1] = '\0';
}
}
else
*tmp = '\0';
snprintf(filename, sizeof(filename), "%s%s", tmp, line + 4);
return (Format(man_globals, filename));
}
}
fclose(file);
}
Popup(XtParent(man_globals->standby), XtGrabExclusive);
while ( !XCheckTypedWindowEvent(XtDisplay(man_globals->standby),
XtWindow(man_globals->standby),
Expose, &event) );
XtDispatchEvent( &event );
XFlush(XtDisplay(man_globals->standby));
strcpy(tmp,MANTEMP);
#ifndef HAS_MKSTEMP
(void) mktemp(tmp);
#else
fd = mkstemp(tmp);
file = fdopen(fd, "r");
#endif
strcpy(man_globals->tempfile, tmp);
ParseEntry(entry, path, sect, NULL);
#ifndef HANDLE_ROFFSEQ
#ifndef HAS_MKSTEMP
snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s > %s %s", path, TBL,
filename, FORMAT, man_globals->tempfile, "2> /dev/null");
#else
snprintf(cmdbuf, sizeof(cmdbuf), "cd %s ; %s %s %s >> %s %s", path, TBL,
filename, FORMAT, man_globals->tempfile, "2> /dev/null");
#endif
#else
if (! ConstructCommand(cmdbuf, path, filename, man_globals->tempfile)) {
sprintf(error_buf, "Constructed command was too long!");
PopupWarning(man_globals, error_buf);
file = NULL;
}
else
#endif
if(system(cmdbuf) != 0) {
snprintf(error_buf, sizeof(error_buf),
"Something went wrong trying to run the command: %s", cmdbuf);
PopupWarning(man_globals, error_buf);
file = NULL;
}
else {
#ifndef HAS_MKSTEMP
if ((file = fopen(man_globals->tempfile,"r")) == NULL) {
sprintf(error_buf, "Something went wrong in retrieving the %s",
"temp file, try cleaning up /tmp");
PopupWarning(man_globals, error_buf);
}
else {
#endif
XtPopdown( XtParent(man_globals->standby) );
if ( (man_globals->save == NULL) ||
(man_globals->manpagewidgets.manpage == NULL) )
unlink(man_globals->tempfile);
else {
char * ptr, catdir[BUFSIZ];
strcpy(catdir, man_globals->save_file);
if ( (ptr = rindex(catdir, '/')) != NULL) {
*ptr = '\0';
if ( access(catdir, W_OK) != 0 )
unlink(man_globals->tempfile);
else {
x = (Position) Width(man_globals->manpagewidgets.manpage)/2;
y = (Position) Height(man_globals->manpagewidgets.manpage)/2;
XtTranslateCoords(manpage, x, y, &x, &y);
PositionCenter( man_globals->save, (int) x, (int) y, 0, 0, 0, 0);
XtPopup( man_globals->save, XtGrabExclusive);
}
}
else
unlink(man_globals->tempfile);
}
#ifndef HAS_MKSTEMP
}
#endif
}
if (man_globals->deletetempfile)
unlink(filename);
return(file);
}
#ifdef HANDLE_ROFFSEQ
static Boolean
ConstructCommand(cmdbuf, path, filename, tempfile)
char *cmdbuf, *path, *filename, *tempfile;
{
char *c = cmdbuf;
int left = BUFSIZ;
int used;
char *fmt;
FILE *file;
char fmtbuf[128];
int gotfmt = 0;
char *fname = NULL;
#ifdef __UNIXOS2__
int i;
#endif
fmt = NULL;
if (!fmt) {
if (filename[0] == '/') {
fname = filename;
} else {
fname = malloc(strlen(path) + 1 + strlen(filename) + 1);
if (!fname)
return FALSE;
sprintf(fname, "%s/%s", path, filename);
}
if ((file = fopen(fname, "r")) &&
(fgets(fmtbuf, sizeof(fmtbuf), file)) &&
(!memcmp(fmtbuf, "'\\\" ", 4))) {
int len;
fmt = fmtbuf + 3;
len = strlen(fmt);
if (len && (fmt[len-1] == '\n')) {
fmt[len-1] = 0;
gotfmt++;
}
}
if (fname && fname != filename)
free(fname);
if (!gotfmt)
{
fmt = getenv("MANROFFSEQ");
}
}
if (!fmt)
{
fmt = DEFAULT_MANROFFSEQ;
}
#ifdef __UNIXOS2__
for (i = 0; i < strlen(path); i++) {
if (path[i] == '/')
path[i] = '\\';
}
used = snprintf(c, left, "cd %s & %s %s ", path, ZSOELIM, filename);
#else
used = snprintf(c, left, "cd %s; %s %s ", path, ZSOELIM, filename);
#endif
left -= used;
c += used;
if (left <= 1)
return (FALSE);
for ( ; *fmt; fmt++)
{
char *filter;
switch (*fmt)
{
case 'e':
filter = EQN;
break;
case 'g':
filter = GRAP;
break;
case 'p':
filter = PIC;
break;
case 't':
filter = TBL;
break;
case 'v':
filter = VGRIND;
break;
case 'r':
filter = REFER;
break;
default:
filter = NULL;
break;
}
if (filter)
{
used = snprintf(c, left, " | %s ", filter);
left -= used;
c += used;
if (left <= 1)
return (FALSE);
}
}
#ifdef __UNIXOS2__
used = snprintf(c, left, " | %s > %s 2>NUL", FORMAT, tempfile);
#else
#ifndef HAS_MKSTEMP
used = snprintf(c, left, " | %s > %s 2>/dev/null", FORMAT, tempfile);
#else
used = snprintf(c, left, " | %s >> %s 2>/dev/null", FORMAT, tempfile);
#endif
#endif
left -= used;
if (left <= 1)
return (FALSE);
return (TRUE);
}
#endif
static Boolean
#ifndef HAS_MKSTEMP
UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
char * filename)
#else
UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
char * filename, FILE **file)
#endif
{
char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], input[BUFSIZ];
int len_cat = strlen(CAT), len_man = strlen(MAN);
#if defined(SMAN) && defined(SFORMAT)
int len_sman = strlen(SMAN);
#endif
ParseEntry(entry, path, section, page);
man_globals->bzip2 = FALSE;
man_globals->lzma = FALSE;
#if defined(__OpenBSD__) || defined(__NetBSD__)
snprintf(filename, BUFSIZ, "%s/%s%s/%s/%s", path, MAN,
section + len_cat, MACHINE, page);
if ( access( filename, R_OK ) == 0 ) {
man_globals->compress = FALSE;
man_globals->gzip = FALSE;
man_globals->deletetempfile = FALSE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s/%s/%s", path, CAT, section + len_cat, MACHINE, page);
return(TRUE);
}
snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->deletetempfile = TRUE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
COMPRESSION_EXTENSION);
return(TRUE);
}
#ifdef GZIP_EXTENSION
else {
snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->gzip = TRUE;
man_globals->deletetempfile = TRUE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
GZIP_EXTENSION);
return(TRUE);
}
}
#endif
#endif
#ifdef BZIP2_EXTENSION
{
sprintf(input, "%s.%s", filename, BZIP2_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->gzip = FALSE;
man_globals->bzip2 = TRUE;
sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
CAT, section + len_cat, page, BZIP2_EXTENSION);
return(TRUE);
}
}
#endif
#ifdef LZMA_EXTENSION
{
sprintf(input, "%s.%s", filename, LZMA_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->gzip = FALSE;
man_globals->lzma = TRUE;
sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
CAT, section + len_cat, page, LZMA_EXTENSION);
return(TRUE);
}
}
#endif
snprintf(filename, BUFSIZ, "%s/%s%s/%s", path, MAN, section + len_man, page);
if ( access( filename, R_OK ) == 0 ) {
man_globals->compress = FALSE;
man_globals->gzip = FALSE;
man_globals->deletetempfile = FALSE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s/%s", path, CAT, section + len_cat, page);
return(TRUE);
}
#if defined(SMAN) && defined(SFORMAT)
snprintf(input, BUFSIZ, "%s/%s%s/%s", path, SMAN, section + len_sman, page);
#ifndef HAS_MKSTEMP
if ( SgmlToRoffNamed(man_globals, input, filename) ) {
#else
if ( SgmlToRoffNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = FALSE;
man_globals->gzip = FALSE;
man_globals->deletetempfile = TRUE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s/%s", path, CAT, section + len_cat, page);
return(TRUE);
}
#endif
snprintf(input, sizeof(input), "%s.%s", filename, COMPRESSION_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->deletetempfile = TRUE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
COMPRESSION_EXTENSION);
return(TRUE);
}
#ifdef GZIP_EXTENSION
else {
snprintf(input, sizeof(input), "%s.%s", filename, GZIP_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->gzip = TRUE;
man_globals->deletetempfile = TRUE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s/%s.%s", path, CAT, section + len_cat, page,
GZIP_EXTENSION);
return(TRUE);
}
}
#endif
#ifdef BZIP2_EXTENSION
{
sprintf(input, "%s.%s", filename, BZIP2_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->gzip = TRUE;
sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
CAT, section + len_cat, page, BZIP2_EXTENSION);
return(TRUE);
}
}
#endif
#ifdef LZMA_EXTENSION
{
sprintf(input, "%s.%s", filename, LZMA_EXTENSION);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->lzma = TRUE;
sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
CAT, section + len_cat, page, LZMA_EXTENSION);
return(TRUE);
}
}
#endif
snprintf(input, sizeof(input), "%s/%s%s.%s/%s", path,
MAN, section + len_man, COMPRESSION_EXTENSION, page);
#ifndef HAS_MKSTEMP
if ( UncompressNamed(man_globals, input, filename) ) {
#else
if ( UncompressNamed(man_globals, input, filename, file) ) {
#endif
man_globals->compress = TRUE;
man_globals->deletetempfile = TRUE;
snprintf(man_globals->save_file, sizeof(man_globals->save_file),
"%s/%s%s.%s/%s", path, CAT, section + len_cat,
COMPRESSION_EXTENSION, page);
return(TRUE);
}
return(FALSE);
}
void
AddCursor(Widget w, Cursor cursor)
{
XColor colors[2];
Arg args[10];
Cardinal num_args = 0;
Colormap c_map;
if (!XtIsRealized(w)) {
PopupWarning(NULL, "Widget is not realized, no cursor added.\n");
return;
}
XtSetArg( args[num_args], XtNcolormap, &c_map); num_args++;
XtGetValues( w, args, num_args);
colors[0].pixel = resources.cursors.fg_color;
colors[1].pixel = resources.cursors.bg_color;
XQueryColors (XtDisplay(w), c_map, colors, 2);
XRecolorCursor(XtDisplay(w), cursor, colors, colors+1);
XDefineCursor(XtDisplay(w),XtWindow(w),cursor);
}
void
ChangeLabel(Widget w, char * str)
{
Arg arglist[3];
if (w == NULL) return;
XtSetArg(arglist[0], XtNlabel, str);
XtSetArg(arglist[1], XtNwidth, 0);
XtSetArg(arglist[2], XtNheight, 0);
XtSetValues(w, arglist, (Cardinal) 1);
}
void
PositionCenter(Widget widget, int x, int y, int above, int left, int v_space, int h_space)
{
Arg wargs[2];
int x_temp,y_temp;
int parent_height,parent_width;
x_temp = x - left - Width(widget) / 2 + BorderWidth(widget);
y_temp = y - above - Height(widget) / 2 + BorderWidth(widget);
parent_height = HeightOfScreen(XtScreen(widget));
parent_width = WidthOfScreen(XtScreen(widget));
if (x_temp < h_space)
x_temp = v_space;
if (y_temp < v_space)
(y_temp = 2);
if ( y_temp + Height(widget) + v_space > parent_height )
y_temp = parent_height - Height(widget) - v_space;
if ( x_temp + Width(widget) + h_space > parent_width )
x_temp = parent_width - Width(widget) - h_space;
XtSetArg(wargs[0], XtNx, x_temp);
XtSetArg(wargs[1], XtNy, y_temp);
XtSetValues(widget, wargs, 2);
}
void
ParseEntry(char *entry, char *path, char *sect, char *page)
{
char *c, temp[BUFSIZ];
strcpy(temp, entry);
c = rindex(temp, '/');
if (c == NULL)
PrintError("index failure in ParseEntry.");
*c++ = '\0';
if (page != NULL)
strcpy(page, c);
c = rindex(temp, '/');
if (c == NULL)
PrintError("index failure in ParseEntry.");
*c++ = '\0';
#if defined(SFORMAT) && defined(SMAN)
if (strcmp(c, ".") == 0) {
c = rindex(temp, '/');
if (c == NULL)
PrintError("index failure in ParseEntry.");
*c++ = '\0';
}
#endif
#if defined(__OpenBSD__) || defined(__NetBSD__)
if (strcmp(c, MACHINE) == 0) {
c = rindex(temp, '/');
if (c == NULL)
PrintError("index failure in ParseEntry.");
*c++ = '\0';
}
#endif
if (sect != NULL)
strcpy(sect, c);
if (path != NULL)
strcpy(path, temp);
}
ManpageGlobals *
GetGlobals(Widget w)
{
Widget temp;
caddr_t data;
while ( (temp = XtParent(w)) != initial_widget && (temp != NULL))
w = temp;
if (temp == NULL)
XtAppError(XtWidgetToApplicationContext(w),
"Xman: Could not locate widget in tree, exiting");
if (XFindContext(XtDisplay(w), XtWindow(w),
manglobals_context, &data) != XCSUCCESS)
XtAppError(XtWidgetToApplicationContext(w),
"Xman: Could not find global data, exiting");
return( (ManpageGlobals *) data);
}
void
SaveGlobals(Widget w, ManpageGlobals * globals)
{
if (XSaveContext(XtDisplay(w), XtWindow(w), manglobals_context,
(caddr_t) globals) != XCSUCCESS)
XtAppError(XtWidgetToApplicationContext(w),
"Xman: Could not save global data, are you out of memory?");
}
void
RemoveGlobals(Widget w)
{
if (XDeleteContext(XtDisplay(w), XtWindow(w),
manglobals_context) != XCSUCCESS)
XtAppError(XtWidgetToApplicationContext(w),
"Xman: Could not remove global data?");
}