Article View: vmsnet.sources
Article #21Ghostview for VMS 11/14
From: Terry Poot
Date: Thu, 29 Oct 1992 18:50
Date: Thu, 29 Oct 1992 18:50
1592 lines
48932 bytes
48932 bytes
Submitted-by: Terry Poot <tp@mccall.com>
Posting-number: Volume 3, Issue 229
Archive-name: ghostview/part11
-+-+-+-+-+-+-+-+ START OF PART 11 -+-+-+-+-+-+-+-+
X if (olddoc->nummedia != doc->nummedia) return False;
X for (i = 0; i < doc->nummedia; i++)
X`09if (strcmp(olddoc->media`5Bi`5D.name, doc->media`5Bi`5D.name)) return Fal
Vse;
X return True;
X`7D
X
Xvoid
Xbuild_pagemedia_menu()
X`7B
X Arg args`5B20`5D;
X Cardinal num_args;
X Widget w;
X int i;
X
X if (pagemediamenu && same_document_media()) return;
X if (pagemediamenu) XtDestroyWidget(pagemediamenu);
X force_document_media = False;
X
X`09`09`09`09`09`09`09num_args = 0;
X XtSetArg(args`5Bnum_args`5D, XtNcolormap, cmap);`09num_args++;
X if (special_cmap) `7B
X`09XtSetArg(args`5Bnum_args`5D, XtNbackground, white);`09num_args++;
X `7D
X pagemediamenu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
X`09`09`09`09 pagemediabutton, args, num_args);
X
X /* Build the Page Media menu */
X /* the Page media menu has two parts.
X * - the document defined page medias
X * - the standard page media defined from Adobe's PPD
X */
X base_papersize = 0;
X if (doc) base_papersize = doc->nummedia;
X for (i = 0; papersizes`5Bi`5D.name; i++) `7B`7D`09/* Count the standard
V entries */
X i += base_papersize;
X pagemediaentry = (Widget *) XtMalloc(i * sizeof(Widget));
X
X if (doc && doc->nummedia) `7B
X`09for (i = 0; i < doc->nummedia; i++) `7B
X`09`09`09`09`09`09`09`09num_args = 0;
X`09 if (special_cmap) `7B
X`09`09XtSetArg(args`5Bnum_args`5D, XtNforeground, black);`09num_args++;
X`09`09XtSetArg(args`5Bnum_args`5D, XtNbackground, white);`09num_args++;
X`09 `7D
X`09 XtSetArg(args`5Bnum_args`5D, XtNleftMargin, 20);`09num_args++;
X`09 pagemediaentry`5Bi`5D = XtCreateManagedWidget(doc->media`5Bi`5D.name,
X`09`09`09`09smeBSBObjectClass, pagemediamenu,
X`09`09`09`09args, num_args);
X`09 XtAddCallback(pagemediaentry`5Bi`5D, XtNcallback,
X`09`09`09 set_pagemedia, (XtPointer)i);
X`09`7D
X
X`09`09`09`09`09`09`09num_args = 0;
X`09if (special_cmap) `7B
X`09 XtSetArg(args`5Bnum_args`5D, XtNforeground, black);`09num_args++;
X`09 XtSetArg(args`5Bnum_args`5D, XtNbackground, white);`09num_args++;
X`09`7D
X`09w = XtCreateManagedWidget("line", smeLineObjectClass, pagemediamenu,
X`09`09`09`09 args, num_args);
X `7D
X
X for (i = 0; papersizes`5Bi`5D.name; i++) `7B
X`09pagemediaentry`5Bi+base_papersize`5D = NULL;
X`09if (i > 0) `7B
X`09 /* Skip over same paper size with small imageable area */
X`09 if ((papersizes`5Bi`5D.width == papersizes`5Bi-1`5D.width) &&
X`09`09(papersizes`5Bi`5D.height == papersizes`5Bi-1`5D.height)) `7B
X`09`09continue;
X`09 `7D
X`09`7D
X`09`09`09`09`09`09`09num_args = 0;
X`09if (special_cmap) `7B
X`09 XtSetArg(args`5Bnum_args`5D, XtNforeground, black);`09num_args++;
X`09 XtSetArg(args`5Bnum_args`5D, XtNbackground, white);`09num_args++;
X`09`7D
X`09XtSetArg(args`5Bnum_args`5D, XtNleftMargin, 20);`09num_args++;
X`09pagemediaentry`5Bi+base_papersize`5D = XtCreateManagedWidget(
X`09`09`09`09`09 papersizes`5Bi`5D.name,
X`09`09`09`09`09 smeBSBObjectClass, pagemediamenu,
X`09`09`09`09`09 args, num_args);
X`09XtAddCallback(pagemediaentry`5Bi+base_papersize`5D, XtNcallback,
X`09`09 set_pagemedia, (XtPointer)(i+base_papersize));
X `7D
X`7D
X
XWidget
Xbuild_label_menu(parent, name, label, bitmap)
X Widget parent;
X String name, label;
X Pixmap bitmap;
X`7B
X Arg args`5B20`5D;
X Cardinal num_args;
X Widget menu, entry;
X`09`09`09`09`09`09`09`09num_args = 0;
X`09XtSetArg(args`5Bnum_args`5D, XtNcolormap, cmap);`09`09num_args++;
X`09if (special_cmap) `7B
X`09 XtSetArg(args`5Bnum_args`5D, XtNbackground, white);`09num_args++;
X`09`7D
X`09menu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
X`09`09`09`09 parent, args, num_args);
X
X`09`09`09`09`09`09`09`09num_args = 0;
X`09if (special_cmap) `7B
X`09 XtSetArg(args`5Bnum_args`5D, XtNforeground, black);`09num_args++;
X`09 XtSetArg(args`5Bnum_args`5D, XtNbackground, white);`09num_args++;
X`09`7D
X`09XtSetArg(args`5Bnum_args`5D, XtNlabel, label);`09`09num_args++;
X`09if (bitmap) `7B
X`09 XtSetArg(args`5Bnum_args`5D, XtNleftMargin, 20);`09num_args++;
X`09 XtSetArg(args`5Bnum_args`5D, XtNleftBitmap, bitmap);`09num_args++;
X`09`7D
X`09entry = XtCreateManagedWidget(name, smeBSBObjectClass,
X`09`09`09`09 menu, args, num_args);
X`09return menu;
X`7D
X
Xvoid
Xnew_file(number)
X int number;
X`7B
X Boolean layout_changed = False;
X
X if (setup_ghostview()) layout_changed = True;
X
X /* Coerce page number to fall in range */
X if (toc_text) `7B
X`09if (number >= doc->numpages) number = doc->numpages - 1;
X`09if (number < 0) number = 0;
X `7D
X
X if (set_new_orientation(number)) layout_changed = True;
X if (set_new_pagemedia(number)) layout_changed = True;
X if (layout_changed) layout_ghostview();
X`7D
X
X/* Catch X errors die gracefully if one occurs */
Xint
Xcatch_Xerror(dpy, err)
X Display *dpy;
X XErrorEvent *err;
X`7B
X if (err->error_code == BadImplementation) `7B
X`09old_Xerror(dpy, err);
X`09return 0;
X `7D
X if (dying) return 0;
X dying = True;
X bomb = *err;
X XtDestroyWidget(toplevel);
X return 0;
X`7D
$ CALL UNPACK MISC.C;1 944026782
$ create 'f'
X/*
X * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation, and that the name of Software Research Associates not be u
Vsed
X * in advertising or publicity pertaining to distribution of the software
X * without specific, written prior permission. Software Research Associates
X * makes no representations about the suitability of this software for any
X * purpose. It is provided "as is" without express or implied warranty.
X *
X * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
X * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
V,
X * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
X * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FRO
VM
X * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENC
VE
X * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
X * PERFORMANCE OF THIS SOFTWARE.
X *
X * Author: Erik M. van der Poel
X * Software Research Associates, Inc., Tokyo, Japan
X * erik@sra.co.jp
X */
X
X#include <stdio.h>
X
X#ifdef SEL_FILE_IGNORE_CASE
X#include <ctype.h>
X#endif /* def SEL_FILE_IGNORE_CASE */
X
X#include <X11/Xos.h>
X#include <pwd.h>
X#include "SFinternal.h"
X#include "xstat.h"
X#include <X11/Xaw/Scrollbar.h>
X
X#if defined(SVR4) `7C`7C defined(SYSV) `7C`7C defined(USG)
Xextern uid_t getuid();
Xextern void qsort();
X#endif /* defined(SVR4) `7C`7C defined(SYSV) `7C`7C defined(USG) */
X
Xtypedef struct `7B
X`09char`09*name;
X`09char`09*dir;
X`7D SFLogin;
X
XSFDir *SFdirs = NULL;
X
Xint SFdirEnd;
X
Xint SFdirPtr;
X
Xint SFbuttonPressed = 0;
X
Xstatic int SFdoNotTouchDirPtr = 0;
X
Xstatic int SFdoNotTouchVorigin = 0;
X
Xstatic SFDir SFrootDir, SFhomeDir;
X
Xstatic SFLogin *SFlogins;
X
Xstatic int SFtwiddle = 0;
X
Xint
XSFchdir(path)
X`09char`09*path;
X`7B
X`09int`09result;
X
X`09result = 0;
X
X`09if (strcmp(path, SFcurrentDir)) `7B
X`09`09result = chdir(path);
X`09`09if (!result) `7B
X`09`09`09(void) strcpy(SFcurrentDir, path);
X`09`09`7D
X`09`7D
X
X`09return result;
X`7D
X
Xstatic
XSFfree(i)
X`09int`09i;
X`7B
X`09register SFDir`09*dir;
X`09register int`09j;
X
X`09dir = &(SFdirs`5Bi`5D);
X
X`09for (j = dir->nEntries - 1; j >= 0; j--) `7B
X`09`09if (dir->entries`5Bj`5D.shown != dir->entries`5Bj`5D.real) `7B
X`09`09`09XtFree(dir->entries`5Bj`5D.shown);
X`09`09`7D
X`09`09XtFree(dir->entries`5Bj`5D.real);
X`09`7D
X
X`09XtFree((char *) dir->entries);
X
X`09XtFree(dir->dir);
X
X`09dir->dir = NULL;
X`7D
X
Xstatic
XSFunreadableDir(dir)
X`09SFDir`09*dir;
X`7B
X`09char`09*cannotOpen = "<cannot open> ";
X
X`09dir->entries = (SFEntry *) XtMalloc(sizeof(SFEntry));
X`09dir->entries`5B0`5D.statDone = 1;
X`09dir->entries`5B0`5D.real = XtMalloc((unsigned) (strlen(cannotOpen) + 1));
X`09(void) strcpy(dir->entries`5B0`5D.real, cannotOpen);
X`09dir->entries`5B0`5D.shown = dir->entries`5B0`5D.real;
X`09dir->nEntries = 1;
X`09dir->nChars = strlen(cannotOpen);
X`7D
X
X#ifdef SEL_FILE_IGNORE_CASE
Xstatic
XSFstrncmp(p, q, n)
X`09register char`09*p, *q;
X`09register int`09n;
X`7B
X`09register char`09c1, c2;
X`09char`09`09*psave, *qsave;
X`09int`09`09nsave;
X
X`09psave = p;
X`09qsave = q;
X`09nsave = n;
X
X`09c1 = *p++;
X`09if (islower(c1)) `7B
X`09`09c1 = toupper(c1);
X`09`7D
X`09c2 = *q++;
X`09if (islower(c2)) `7B
X`09`09c2 = toupper(c2);
X`09`7D
X
X`09while ((--n >= 0) && (c1 == c2)) `7B
X`09`09if (!c1) `7B
X`09`09`09return strncmp(psave, qsave, nsave);
X`09`09`7D
X`09`09c1 = *p++;
X`09`09if (islower(c1)) `7B
X`09`09`09c1 = toupper(c1);
X`09`09`7D
X`09`09c2 = *q++;
X`09`09if (islower(c2)) `7B
X`09`09`09c2 = toupper(c2);
X`09`09`7D
X`09`7D
X
X`09if (n < 0) `7B
X`09`09return strncmp(psave, qsave, nsave);
X`09`7D
X
X`09return c1 - c2;
X`7D
X#endif /* def SEL_FILE_IGNORE_CASE */
X
Xstatic
XSFreplaceText(dir, str)
X`09SFDir`09*dir;
X`09char`09*str;
X`7B
X`09int`09len;
X
X`09*(dir->path) = 0;
X`09len = strlen(str);
X`09if (str`5Blen - 1`5D == '/') `7B
X`09`09(void) strcat(SFcurrentPath, str);
X`09`7D else `7B
X`09`09(void) strncat(SFcurrentPath, str, len - 1);
X`09`7D
X`09if (strncmp(SFcurrentPath, SFstartDir, strlen(SFstartDir))) `7B
X`09`09SFsetText(SFcurrentPath);
X`09`7D else `7B
X`09`09SFsetText(&(SFcurrentPath`5Bstrlen(SFstartDir)`5D));
X`09`7D
X
X`09SFtextChanged();
X`7D
X
Xstatic void
XSFexpand(str)
X`09char`09*str;
X`7B
X`09int`09len;
X`09int`09cmp;
X`09char`09*name, *growing;
X`09SFDir`09*dir;
X`09SFEntry`09*entry, *max;
X
X`09len = strlen(str);
X
X`09dir = &(SFdirs`5BSFdirEnd - 1`5D);
X
X`09if (dir->beginSelection == -1) `7B
X`09`09str = strcpy(XtMalloc((unsigned) (strlen(str) + 1)), str);
X`09`09SFreplaceText(dir, str);
X`09`09XtFree(str);
X`09`09return;
X`09`7D else if (dir->beginSelection == dir->endSelection) `7B
X`09`09SFreplaceText(dir, dir->entries`5Bdir->beginSelection`5D.shown);
X`09`09return;
X`09`7D
X
X`09max = &(dir->entries`5Bdir->endSelection + 1`5D);
X
X`09name = dir->entries`5Bdir->beginSelection`5D.shown;
X`09(void) strcpy((growing = XtMalloc((unsigned) (strlen(name) + 1))),
X`09`09name);
X
X`09cmp = 0;
X`09while (!cmp) `7B
X`09`09entry = &(dir->entries`5Bdir->beginSelection`5D);
X`09`09while (entry < max) `7B
X`09`09`09if (cmp = strncmp(growing, entry->shown, len)) `7B
X`09`09`09`09break;
X`09`09`09`7D
X`09`09`09entry++;
X`09`09`7D
X`09`09len++;
X`09`7D
X
X`09/*
X`09 * SFreplaceText() expects filename
X`09 */
X`09growing`5Blen - 2`5D = ' ';
X
X`09growing`5Blen - 1`5D = 0;
X`09SFreplaceText(dir, growing);
X`09XtFree(growing);
X`7D
X
Xstatic int
XSFfindFile(dir, str)
X`09SFDir`09`09*dir;
X`09register char`09*str;
X`7B
X`09register int`09i, last, max;
X`09register char`09*name, save;
X`09SFEntry`09`09*entries;
X`09int`09`09len;
X`09int`09`09begin, end;
X`09int`09`09result;
X
X`09len = strlen(str);
X
X`09if (str`5Blen - 1`5D == ' ') `7B
X`09`09SFexpand(str);
X`09`09return 1;
X`09`7D else if (str`5Blen - 1`5D == '/') `7B
X`09`09len--;
X`09`7D
X
X`09max = dir->nEntries;
X
X`09entries = dir->entries;
X
X`09i = 0;
X`09while (i < max) `7B
X`09`09name = entries`5Bi`5D.shown;
X`09`09last = strlen(name) - 1;
X`09`09save = name`5Blast`5D;
X`09`09name`5Blast`5D = 0;
X
X#ifdef SEL_FILE_IGNORE_CASE
X`09`09result = SFstrncmp(str, name, len);
X#else /* def SEL_FILE_IGNORE_CASE */
X`09`09result = strncmp(str, name, len);
X#endif /* def SEL_FILE_IGNORE_CASE */
X
X`09`09name`5Blast`5D = save;
X`09`09if (result <= 0) `7B
X`09`09`09break;
X`09`09`7D
X`09`09i++;
X`09`7D
X`09begin = i;
X`09while (i < max) `7B
X`09`09name = entries`5Bi`5D.shown;
X`09`09last = strlen(name) - 1;
X`09`09save = name`5Blast`5D;
X`09`09name`5Blast`5D = 0;
X
X#ifdef SEL_FILE_IGNORE_CASE
X`09`09result = SFstrncmp(str, name, len);
X#else /* def SEL_FILE_IGNORE_CASE */
X`09`09result = strncmp(str, name, len);
X#endif /* def SEL_FILE_IGNORE_CASE */
X
X`09`09name`5Blast`5D = save;
X`09`09if (result) `7B
X`09`09`09break;
X`09`09`7D
X`09`09i++;
X`09`7D
X`09end = i;
X
X`09if (begin != end) `7B
X`09`09if (
X`09`09`09(dir->beginSelection != begin) `7C`7C
X`09`09`09(dir->endSelection != end - 1)
X`09`09) `7B
X`09`09`09dir->changed = 1;
X`09`09`09dir->beginSelection = begin;
X`09`09`09if (str`5Bstrlen(str) - 1`5D == '/') `7B
X`09`09`09`09dir->endSelection = begin;
X`09`09`09`7D else `7B
X`09`09`09`09dir->endSelection = end - 1;
X`09`09`09`7D
X`09`09`7D
X`09`7D else `7B
X`09`09if (dir->beginSelection != -1) `7B
X`09`09`09dir->changed = 1;
X`09`09`09dir->beginSelection = -1;
X`09`09`09dir->endSelection = -1;
X`09`09`7D
X`09`7D
X
X`09if (
X`09`09SFdoNotTouchVorigin `7C`7C
X`09`09((begin > dir->vOrigin) && (end < dir->vOrigin + SFlistSize))
X`09) `7B
X`09`09SFdoNotTouchVorigin = 0;
X`09`09return 0;
X`09`7D
X
X`09i = begin - 1;
X`09if (i > max - SFlistSize) `7B
X`09`09i = max - SFlistSize;
X`09`7D
X`09if (i < 0) `7B
X`09`09i = 0;
X`09`7D
X
X`09if (dir->vOrigin != i) `7B
X`09`09dir->vOrigin = i;
X`09`09dir->changed = 1;
X`09`7D
X
X`09return 0;
X`7D
X
Xstatic
XSFunselect()
X`7B
X`09SFDir`09*dir;
X
X`09dir = &(SFdirs`5BSFdirEnd - 1`5D);
X`09if (dir->beginSelection != -1) `7B
X`09`09dir->changed = 1;
X`09`7D
X`09dir->beginSelection = -1;
X`09dir->endSelection = -1;
X`7D
X
Xstatic int
XSFcompareLogins(p, q)
X`09SFLogin`09*p, *q;
X`7B
X`09return strcmp(p->name, q->name);
X`7D
X
Xstatic
XSFgetHomeDirs()
X`7B
X`09struct passwd`09*pw;
X`09struct stat`09statBuf;
X`09int`09`09alloc;
X`09int`09`09i;
X`09SFEntry`09`09*entries = NULL;
X#ifndef`09HOME_ON_DEMAND /* by Y.Kawabe */
X`09int`09`09len;
X#endif`09/* HOME_ON_DEMAND */
X`09int`09`09maxChars;
X
X`09alloc = 0;
X`09i = 0;
X
X`09maxChars = -1;
X
X`09if (pw = getpwuid((int) getuid())) `7B
X`09`09if (
X`09`09`09(!stat(pw->pw_dir, &statBuf)) &&
X`09`09`09(S_ISDIR (statBuf.st_mode))
X`09`09) `7B
X`09`09`09alloc = 1;
X`09`09`09i = 1;
X`09`09`09entries = (SFEntry *) XtMalloc(sizeof(SFEntry));
X`09`09`09SFlogins = (SFLogin *) XtMalloc(sizeof(SFLogin));
X`09`09`09entries`5B0`5D.real = XtMalloc(3);
X`09`09`09(void) strcpy(entries`5B0`5D.real, "`7E");
X`09`09`09entries`5B0`5D.shown = entries`5B0`5D.real;
X`09`09`09entries`5B0`5D.statDone = 1;
X`09`09`09SFlogins`5B0`5D.name = "";
X`09`09`09SFlogins`5B0`5D.dir = XtMalloc((unsigned)
X`09`09`09`09(strlen(pw->pw_dir) + 1));
X`09`09`09(void) strcpy(SFlogins`5B0`5D.dir, pw->pw_dir);
X`09`09`09maxChars = 1;
X`09`09`7D
X`09`7D
X
X#ifndef`09HOME_ON_DEMAND /* by Y.Kawabe */
X
X`09(void) setpwent();
X
X`09while ((pw = getpwent()) && (*(pw->pw_name))) `7B
X`09`09if (
X`09`09`09(!stat(pw->pw_dir, &statBuf)) &&
X`09`09`09(S_ISDIR (statBuf.st_mode))
X`09`09) `7B
X`09`09`09if (i >= alloc) `7B
X`09`09`09`09alloc *= 2;
X`09`09`09`09entries = (SFEntry *) XtRealloc(
X`09`09`09`09`09(char *) entries,
X`09`09`09`09`09(unsigned) (alloc * sizeof(SFEntry))
X`09`09`09`09);
X`09`09`09`09SFlogins = (SFLogin *) XtRealloc(
X`09`09`09`09`09(char *) SFlogins,
X`09`09`09`09`09(unsigned) (alloc * sizeof(SFLogin))
X`09`09`09`09);
X`09`09`09`7D
X`09`09`09len = strlen(pw->pw_name);
X`09`09`09entries`5Bi`5D.real = XtMalloc((unsigned) (len + 3));
X`09`09`09(void) strcat(strcpy(entries`5Bi`5D.real, "`7E"),
X`09`09`09`09pw->pw_name);
X`09`09`09entries`5Bi`5D.shown = entries`5Bi`5D.real;
X`09`09`09entries`5Bi`5D.statDone = 1;
X`09`09`09if (len > maxChars) `7B
X`09`09`09`09maxChars = len;
X`09`09`09`7D
X`09`09`09SFlogins`5Bi`5D.name = XtMalloc((unsigned)
X`09`09`09`09(strlen(pw->pw_name) + 1));
X`09`09`09(void) strcpy(SFlogins`5Bi`5D.name, pw->pw_name);
X`09`09`09SFlogins`5Bi`5D.dir = XtMalloc((unsigned)
X`09`09`09`09(strlen(pw->pw_dir) + 1));
X`09`09`09(void) strcpy(SFlogins`5Bi`5D.dir, pw->pw_dir);
X`09`09`09i++;
X`09`09`7D
X`09`7D
X
X#endif`09/* HOME_ON_DEMAND */
X
X`09SFhomeDir.dir`09`09`09= XtMalloc(1)`09;
X`09SFhomeDir.dir`5B0`5D`09`09= 0`09`09;
X`09SFhomeDir.path`09`09`09= SFcurrentPath`09;
X`09SFhomeDir.entries`09`09= entries`09;
X`09SFhomeDir.nEntries`09`09= i`09`09;
X`09SFhomeDir.vOrigin`09`09= 0`09`09;`09/* :-) */
X`09SFhomeDir.nChars`09`09= maxChars + 2`09;
X`09SFhomeDir.hOrigin`09`09= 0`09`09;
X`09SFhomeDir.changed`09`09= 1`09`09;
X`09SFhomeDir.beginSelection`09= -1`09`09;
X`09SFhomeDir.endSelection`09`09= -1`09`09;
X
X#if defined(SVR4) `7C`7C defined(SYSV) `7C`7C defined(USG)
X`09qsort((char *) entries, (unsigned)i, sizeof(SFEntry), SFcompareEntries);
X`09qsort((char *) SFlogins, (unsigned)i, sizeof(SFLogin), SFcompareLogins);
X#else /* defined(SVR4) `7C`7C defined(SYSV) `7C`7C defined(USG) */
X`09qsort((char *) entries, i, sizeof(SFEntry), SFcompareEntries);
X`09qsort((char *) SFlogins, i, sizeof(SFLogin), SFcompareLogins);
X#endif /* defined(SVR4) `7C`7C defined(SYSV) `7C`7C defined(USG) */
X
X`09for (i--; i >= 0; i--) `7B
X`09`09(void) strcat(entries`5Bi`5D.real, "/");
X`09`7D
X`7D
X
X
Xstatic int
XSFfindHomeDir(begin, end)
X`09char`09*begin, *end;
X`7B
X`09char`09save;
X`09char`09*theRest;
X`09int`09i;
X
X`09save = *end;
X`09*end = 0;
X
X`09for (i = SFhomeDir.nEntries - 1; i >= 0; i--) `7B
X`09`09if (!strcmp(SFhomeDir.entries`5Bi`5D.real, begin)) `7B
X`09`09`09*end = save;
X`09`09`09theRest = XtMalloc((unsigned) (strlen(end) + 1));
X`09`09`09(void) strcpy(theRest, end);
X`09`09`09(void) strcat(strcat(strcpy(SFcurrentPath,
X`09`09`09`09SFlogins`5Bi`5D.dir), "/"), theRest);
X`09`09`09XtFree(theRest);
X`09`09`09SFsetText(SFcurrentPath);
X`09`09`09SFtextChanged();
X`09`09`09return 1;
X`09`09`7D
X`09`7D
X
X#ifdef`09HOME_ON_DEMAND /* by Y.Kawabe */
X`09if (*(++begin)) `7B
X`09`09struct passwd *pwd;
X`09`09char user`5B256`5D;
X`09`09int i = 0;
X
X`09`09while (*begin && *begin != '/' && i < sizeof(user))
X`09`09`09user`5Bi++`5D = *begin++;
X`09`09user`5Bi`5D = '\0';
X
X`09`09if (pwd = getpwnam(user)) `7B
X`09`09`09theRest = XtMalloc((unsigned) (strlen(end) + 1));
X`09`09`09(void) strcpy(theRest, end);
X`09`09`09(void) strcat(strcat(strcpy(SFcurrentPath,
X`09`09`09`09pwd->pw_dir), "/"), theRest);
X`09`09`09XtFree(theRest);
X`09`09`09SFsetText(SFcurrentPath);
X`09`09`09SFtextChanged();
X`09`09`09return 1;
X`09`09`7D
X`09`7D
X#endif`09/* HOME_ON_DEMAND */
X
X`09*end = save;
X
X`09return 0;
X`7D
X
XSFupdatePath()
X`7B
X`09static int`09alloc;
X`09static int`09wasTwiddle = 0;
X`09char`09`09*begin, *end;
X`09int`09`09i, j;
X`09int`09`09len;
X`09int`09`09prevChange;
X`09int`09`09SFdirPtrSave, SFdirEndSave;
X`09SFDir`09`09*dir;
X
X`09if (!SFdirs) `7B
X`09`09SFdirs = (SFDir *) XtMalloc((alloc = 10) * sizeof(SFDir));
X`09`09dir = &(SFdirs`5B0`5D);
X`09`09dir->dir = XtMalloc(2);
X`09`09(void) strcpy(dir->dir, "/");
X`09`09(void) SFchdir("/");
X`09`09(void) SFgetDir(dir);
X`09`09for (j = 1; j < alloc; j++) `7B
X`09`09`09SFdirs`5Bj`5D.dir = NULL;
X`09`09`7D
X`09`09dir->path = SFcurrentPath + 1;
X`09`09dir->vOrigin = 0;
X`09`09dir->hOrigin = 0;
X`09`09dir->changed = 1;
X`09`09dir->beginSelection = -1;
X`09`09dir->endSelection = -1;
X`09`09SFgetHomeDirs();
X`09`7D
X
X`09SFdirEndSave = SFdirEnd;
X`09SFdirEnd = 1;
X
X`09SFdirPtrSave = SFdirPtr;
X`09SFdirPtr = 0;
X
X`09begin = NULL;
X
X`09if (SFcurrentPath`5B0`5D == '`7E') `7B
X`09`09if (!SFtwiddle) `7B
X`09`09`09SFtwiddle = 1;
X`09`09`09dir = &(SFdirs`5B0`5D);
X`09`09`09SFrootDir = *dir;
X`09`09`09*dir = SFhomeDir;
X`09`09`09dir->changed = 1;
X`09`09`7D
X`09`09end = SFcurrentPath;
X`09`09SFdoNotTouchDirPtr = 1;
X`09`09wasTwiddle = 1;
X`09`7D else `7B
X`09`09if (SFtwiddle) `7B
X`09`09`09SFtwiddle = 0;
X`09`09`09dir = &(SFdirs`5B0`5D);
X`09`09`09*dir = SFrootDir;
X`09`09`09dir->changed = 1;
X`09`09`7D
X`09`09end = SFcurrentPath + 1;
X`09`7D
X
X`09i = 0;
X
X`09prevChange = 0;
X
X`09while (*end) `7B
X`09`09while (*end++ == '/') `7B
X`09`09`09;
X`09`09`7D
X`09`09end--;
X`09`09begin = end;
X`09`09while ((*end) && (*end++ != '/')) `7B
X`09`09`09;
X`09`09`7D
X`09`09if ((end - SFcurrentPath <= SFtextPos) && (*(end - 1) == '/')) `7B
X`09`09`09SFdirPtr = i - 1;
X`09`09`09if (SFdirPtr < 0) `7B
X`09`09`09`09SFdirPtr = 0;
X`09`09`09`7D
X`09`09`7D
X`09`09if (*begin) `7B
X`09`09`09if (*(end - 1) == '/') `7B
X`09`09`09`09char save = *end;
X
X`09`09`09`09if (SFtwiddle) `7B
X`09`09`09`09`09if (SFfindHomeDir(begin, end)) `7B
X`09`09`09`09`09`09return;
X`09`09`09`09`09`7D
X`09`09`09`09`7D
X`09`09`09`09*end = 0;
X`09`09`09`09i++;
X`09`09`09`09SFdirEnd++;
X`09`09`09`09if (i >= alloc) `7B
X`09`09`09`09`09SFdirs = (SFDir *) XtRealloc(
X`09`09`09`09`09`09(char *) SFdirs,
X`09`09`09`09`09`09(unsigned) ((alloc *= 2) *
X`09`09`09`09`09`09`09sizeof(SFDir))
X`09`09`09`09`09);
X`09`09`09`09`09for (j = alloc / 2; j < alloc; j++) `7B
X`09`09`09`09`09`09SFdirs`5Bj`5D.dir = NULL;
X`09`09`09`09`09`7D
X`09`09`09`09`7D
X`09`09`09`09dir = &(SFdirs`5Bi`5D);
X`09`09`09`09if (
X`09`09`09`09`09(!(dir->dir)) `7C`7C
X`09`09`09`09`09prevChange `7C`7C
X`09`09`09`09`09strcmp(dir->dir, begin)
X`09`09`09`09) `7B
X`09`09`09`09`09if (dir->dir) `7B
X`09`09`09`09`09`09SFfree(i);
X`09`09`09`09`09`7D
X`09`09`09`09`09prevChange = 1;
X`09`09`09`09`09len = strlen(begin) + 1;
X`09`09`09`09`09dir->dir = XtMalloc((unsigned) len);
X`09`09`09`09`09(void) strcpy(dir->dir, begin);
X`09`09`09`09`09dir->path = end;
X`09`09`09`09`09dir->vOrigin = 0;
X`09`09`09`09`09dir->hOrigin = 0;
X`09`09`09`09`09dir->changed = 1;
X`09`09`09`09`09dir->beginSelection = -1;
X`09`09`09`09`09dir->endSelection = -1;
X`09`09`09`09`09(void) SFfindFile(dir - 1, begin);
X`09`09`09`09`09if (
X`09`09`09`09`09`09SFchdir(SFcurrentPath) `7C`7C
X`09`09`09`09`09`09SFgetDir(dir)
X`09`09`09`09`09) `7B
X`09`09`09`09`09`09SFunreadableDir(dir);
X`09`09`09`09`09`09break;
X`09`09`09`09`09`7D
X`09`09`09`09`7D
X`09`09`09`09*end = save;
X`09`09`09`09if (!save) `7B
X`09`09`09`09`09SFunselect();
X`09`09`09`09`7D
X`09`09`09`7D else `7B
X`09`09`09`09if (SFfindFile(&(SFdirs`5BSFdirEnd-1`5D), begin)) `7B
X`09`09`09`09`09return;
X`09`09`09`09`7D
X`09`09`09`7D
X`09`09`7D else `7B
X`09`09`09SFunselect();
X`09`09`7D
X`09`7D
X
X`09if ((end == SFcurrentPath + 1) && (!SFtwiddle)) `7B
X`09`09SFunselect();
X`09`7D
X
X`09for (i = SFdirEnd; i < alloc; i++) `7B
X`09`09if (SFdirs`5Bi`5D.dir) `7B
X`09`09`09SFfree(i);
X`09`09`7D
X`09`7D
X
X`09if (SFdoNotTouchDirPtr) `7B
X`09`09if (wasTwiddle) `7B
X`09`09`09wasTwiddle = 0;
X`09`09`09SFdirPtr = SFdirEnd - 2;
X`09`09`09if (SFdirPtr < 0) `7B
X`09`09`09`09SFdirPtr = 0;
X`09`09`09`7D
X`09`09`7D else `7B
X`09`09`09SFdirPtr = SFdirPtrSave;
X`09`09`7D
X`09`09SFdoNotTouchDirPtr = 0;
X`09`7D
X
X`09if ((SFdirPtr != SFdirPtrSave) `7C`7C (SFdirEnd != SFdirEndSave)) `7B
X`09`09XawScrollbarSetThumb(
X`09`09`09selFileHScroll,
X`09`09`09(float) (((double) SFdirPtr) / SFdirEnd),
X`09`09`09(float) (((double) ((SFdirEnd < 3) ? SFdirEnd : 3)) /
X`09`09`09`09SFdirEnd)
X`09`09);
X`09`7D
X
X`09if (SFdirPtr != SFdirPtrSave) `7B
X`09`09SFdrawLists(SF_DO_SCROLL);
X`09`7D else `7B
X`09`09for (i = 0; i < 3; i++) `7B
X`09`09`09if (SFdirPtr + i < SFdirEnd) `7B
X`09`09`09`09if (SFdirs`5BSFdirPtr + i`5D.changed) `7B
X`09`09`09`09`09SFdirs`5BSFdirPtr + i`5D.changed = 0;
X`09`09`09`09`09SFdrawList(i, SF_DO_SCROLL);
X`09`09`09`09`7D
X`09`09`09`7D else `7B
X`09`09`09`09SFclearList(i, SF_DO_SCROLL);
X`09`09`09`7D
X`09`09`7D
X`09`7D
X`7D
X
XSFsetText(path)
X`09char`09*path;
X`7B
X`09XawTextBlock`09text;
X
X`09text.firstPos = 0;
X`09text.length = strlen(path);
X`09text.ptr = path;
X`09text.format = FMT8BIT;
X
X`09XawTextReplace(selFileField, 0, strlen(SFtextBuffer), &text);
X`09XawTextSetInsertionPoint(selFileField, strlen(SFtextBuffer));
X`7D
X
X/* ARGSUSED */
Xvoid
XSFbuttonPressList(w, n, event)
X`09Widget`09`09`09w;
X`09int`09`09`09n;
X`09XButtonPressedEvent`09*event;
X`7B
X`09SFbuttonPressed = 1;
X`7D
X
X/* ARGSUSED */
Xvoid
XSFbuttonReleaseList(w, n, event)
X`09Widget`09`09`09w;
X`09int`09`09`09n;
X`09XButtonReleasedEvent`09*event;
X`7B
X`09SFDir`09*dir;
X
X`09SFbuttonPressed = 0;
X
X`09if (SFcurrentInvert`5Bn`5D != -1) `7B
X`09`09if (n < 2) `7B
X`09`09`09SFdoNotTouchDirPtr = 1;
X`09`09`7D
X`09`09SFdoNotTouchVorigin = 1;
X`09`09dir = &(SFdirs`5BSFdirPtr + n`5D);
X`09`09SFreplaceText(
X`09`09`09dir,
X`09`09`09dir->entries`5Bdir->vOrigin + SFcurrentInvert`5Bn`5D`5D.shown
X`09`09);
X`09`09SFmotionList(w, n, event);
X`09`7D
X`7D
X
Xstatic int
XSFcheckDir(n, dir)
X`09int`09`09n;
X`09SFDir`09`09*dir;
X`7B
X`09struct stat`09statBuf;
X`09int`09`09i;
X
X`09if (
X`09`09(!stat(".", &statBuf)) &&
X`09`09(statBuf.st_mtime != dir->mtime)
X`09) `7B
X
X`09`09/*
X`09`09 * If the pointer is currently in the window that we are about
X`09`09 * to update, we must warp it to prevent the user from
X`09`09 * accidentally selecting the wrong file.
X`09`09 */
X`09`09if (SFcurrentInvert`5Bn`5D != -1) `7B
X`09`09`09XWarpPointer(
X`09`09`09`09SFdisplay,
X`09`09`09`09None,
X`09`09`09`09XtWindow(selFileLists`5Bn`5D),
X`09`09`09`090,
X`09`09`09`090,
X`09`09`09`090,
X`09`09`09`090,
X`09`09`09`090,
X`09`09`09`090
X`09`09`09);
X`09`09`7D
X
X`09`09for (i = dir->nEntries - 1; i >= 0; i--) `7B
X`09`09`09if (dir->entries`5Bi`5D.shown != dir->entries`5Bi`5D.real) `7B
X`09`09`09`09XtFree(dir->entries`5Bi`5D.shown);
X`09`09`09`7D
X`09`09`09XtFree(dir->entries`5Bi`5D.real);
X`09`09`7D
X`09`09XtFree((char *) dir->entries);
X`09`09if (SFgetDir(dir)) `7B
X`09`09`09SFunreadableDir(dir);
X`09`09`7D
X`09`09if (dir->vOrigin > dir->nEntries - SFlistSize) `7B
X`09`09`09dir->vOrigin = dir->nEntries - SFlistSize;
X`09`09`7D
X`09`09if (dir->vOrigin < 0) `7B
X`09`09`09dir->vOrigin = 0;
X`09`09`7D
X`09`09if (dir->hOrigin > dir->nChars - SFcharsPerEntry) `7B
X`09`09`09dir->hOrigin = dir->nChars - SFcharsPerEntry;
X`09`09`7D
X`09`09if (dir->hOrigin < 0) `7B
X`09`09`09dir->hOrigin = 0;
X`09`09`7D
X`09`09dir->beginSelection = -1;
X`09`09dir->endSelection = -1;
X`09`09SFdoNotTouchVorigin = 1;
X`09`09if ((dir + 1)->dir) `7B
X`09`09`09(void) SFfindFile(dir, (dir + 1)->dir);
X`09`09`7D else `7B
X`09`09`09(void) SFfindFile(dir, dir->path);
X`09`09`7D
X
X`09`09if (!SFworkProcAdded) `7B
X`09`09`09(void) XtAppAddWorkProc(SFapp, SFworkProc, NULL);
X`09`09`09SFworkProcAdded = 1;
X`09`09`7D
X
X`09`09return 1;
X`09`7D
X
X`09return 0;
X`7D
X
Xstatic int
XSFcheckFiles(dir)
X`09SFDir`09*dir;
X`7B
X`09int`09`09from, to;
X`09int`09`09result;
X`09char`09`09old, new;
X`09int`09`09i;
X`09char`09`09*str;
X`09int`09`09last;
X`09struct stat`09statBuf;
X
X`09result = 0;
X
X`09from = dir->vOrigin;
X`09to = dir->vOrigin + SFlistSize;
X`09if (to > dir->nEntries) `7B
X`09`09to = dir->nEntries;
X`09`7D
X
X`09for (i = from; i < to; i++) `7B
X`09`09str = dir->entries`5Bi`5D.real;
X`09`09last = strlen(str) - 1;
X`09`09old = str`5Blast`5D;
X`09`09str`5Blast`5D = 0;
X`09`09if (stat(str, &statBuf)) `7B
X`09`09`09new = ' ';
X`09`09`7D else `7B
X`09`09`09new = SFstatChar(&statBuf);
X`09`09`7D
X`09`09str`5Blast`5D = new;
X`09`09if (new != old) `7B
X`09`09`09result = 1;
X`09`09`7D
X`09`7D
X
X`09return result;
X`7D
X
Xvoid
XSFdirModTimer()
X`7B
X`09static int`09n = -1;
X`09static int`09f = 0;
X`09char`09`09save;
X`09SFDir`09`09*dir;
X
X`09if ((!SFtwiddle) && (SFdirPtr < SFdirEnd)) `7B
X`09`09n++;
X`09`09if ((n > 2) `7C`7C (SFdirPtr + n >= SFdirEnd)) `7B
X`09`09`09n = 0;
X`09`09`09f++;
X`09`09`09if ((f > 2) `7C`7C (SFdirPtr + f >= SFdirEnd)) `7B
X`09`09`09`09f = 0;
X`09`09`09`7D
X`09`09`7D
X`09`09dir = &(SFdirs`5BSFdirPtr + n`5D);
X`09`09save = *(dir->path);
X`09`09*(dir->path) = 0;
X`09`09if (SFchdir(SFcurrentPath)) `7B
X`09`09`09*(dir->path) = save;
X
X`09`09`09/*
X`09`09`09 * force a re-read
X`09`09`09 */
X`09`09`09*(dir->dir) = 0;
X
X`09`09`09SFupdatePath();
X`09`09`7D else `7B
X`09`09`09*(dir->path) = save;
X`09`09`09if (
X`09`09`09`09SFcheckDir(n, dir) `7C`7C
X`09`09`09`09((f == n) && SFcheckFiles(dir))
X`09`09`09) `7B
X`09`09`09`09SFdrawList(n, SF_DO_SCROLL);
X`09`09`09`7D
X`09`09`7D
X`09`7D
X
X`09SFdirModTimerId = XtAppAddTimeOut(SFapp, (unsigned long) 1000,
X`09`09SFdirModTimer, (XtPointer) NULL);
X`7D
X
X/* Return a single character describing what kind of file STATBUF is. */
X
Xchar
XSFstatChar (statBuf)
X`09struct stat *statBuf;
X`7B
X`09if (S_ISDIR (statBuf->st_mode)) `7B
X`09`09return '/';
X`09`7D else if (S_ISREG (statBuf->st_mode)) `7B
X`09 return S_ISXXX (statBuf->st_mode) ? '*' : ' ';
X#ifdef S_ISSOCK
X`09`7D else if (S_ISSOCK (statBuf->st_mode)) `7B
X`09`09return '=';
X#endif /* S_ISSOCK */
X`09`7D else `7B
X`09`09return ' ';
X`09`7D
X`7D
$ CALL UNPACK PATH.C;1 1982034148
$ create 'f'
X/*
X * ps.c -- Postscript scanning and copying routines.
X * Copyright (C) 1992 Timothy O. Theisen
X *
X * This program is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 2 of the License, or
X * (at your option) any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X *
X * Author: Tim Theisen Systems Programmer
X * Internet: tim@cs.wisc.edu Department of Computer Sciences
X * UUCP: uwvax!tim University of Wisconsin-Madison
X * Phone: (608)262-0438 1210 West Dayton Street
X * FAX: (608)262-9777 Madison, WI 53706
X */
X
X#include <stdio.h>
X#ifndef SEEK_SET
X#define SEEK_SET 0
X#endif
X#ifndef BUFSIZ
X#define BUFSIZ 1024
X#endif
X#include <ctype.h>
X#include <X11/Xos.h>`09`09/* #includes the appropriate <string.h> */
X#include "ps.h"
X
X#ifdef BSD4_2
X#define memset(a,b,c) bzero(a,c)
X#endif
X
X/* length calculates string length at compile time */
X/* can only be used with character constants */
X#define length(a) (sizeof(a)-1)
X#define iscomment(a, b)`09(strncmp(a, b, length(b)) == 0)
X
X`09/* list of standard paper sizes from Adobe's PPD. */
X
Xstruct documentmedia papersizes`5B`5D = `7B
X "Letter",`09`09 612, 792,
X "LetterSmall",`09 612, 792,
X "Tabloid",`09`09 792, 1224,
X "Ledger",`09`091224, 792,
X "Legal",`09`09 612, 1008,
X "Statement",`09 396, 612,
X "Executive",`09 540, 720,
X "A3",`09`09 842, 1190,
X "A4",`09`09 595, 842,
X "A4Small",`09`09 595, 842,
X "A5",`09`09 420, 595,
X "B4",`09`09 729, 1032,
X "B5",`09`09 516, 729,
X "Folio",`09`09 612, 936,
X "Quarto",`09`09 610, 780,
X "10x14",`09`09 720, 1008,
X NULL,`09`09 0, 0
X`7D;
X
X
Xstatic char *readline();
Xstatic char *gettextline();
Xstatic char *gettext();
Xstatic int isblank();
X
X/*
X *`09psscan -- scan the PostScript file for document structuring comments.
X *
X *`09This scanner is designed to retrieve the information necessary for
X *`09the ghostview previewer. It will scan files that conform to any
X *`09version (1.0, 2.0, 2.1, or 3.0) of the document structuring conventions
V.
X *`09It does not really care which version of comments the file contains.
X *`09(The comments are largely upward compatible.) It will scan a number
X *`09of non-conforming documents. (You could have part of the document
X *`09conform to V2.0 and the rest conform to V3.0. It would be similar
X *`09to the DC-2 1/2+, it would look funny but it can still fly.)
X *
X *`09This routine returns a pointer to the document structure.
X *`09The structure contains the information relevant to previewing.
X * These include EPSF flag (to tell if the file is a encapsulated figur
Ve),
X * Page Media (for the Page Size), Bounding Box (to minimize backing
X * pixmap size or determine window size for encapsulated PostScript),`2
V0
X * Orientation of Paper (for default transformation matrix), and
X * Page Order. The title and CreationDate are also retrieved to
X * help identify the document.
X *
X * The following comments are examined:
X *
X * Header section:`20
X * Must start with %!PS-Adobe-. Version numbers ignored.
X *
X * %!PS-Adobe-* `5BEPSF-*`5D
X * %%BoundingBox: <int> <int> <int> <int>`7C(atend)
X * %%CreationDate: <textline>
X * %%Orientation: Portrait`7CLandscape`7C(atend)
X * %%Pages: <uint> `5B<int>`5D`7C(atend)
X * %%PageOrder: Ascend`7CDescend`7CSpecial`7C(atend)
X * %%Title: <textline>
X * %%DocumentMedia: <text> <real> <real> <real> <text> <text>
X * %%DocumentPageSizes: <text>
X * %%EndComments
X *
X * Note: Either the 3.0 or 2.0 syntax for %%Pages is accepted.
X * Also either the 2.0 %%DocumentPageSizes or the 3.0
X * %%DocumentMedia comments are accepted as well.
X *
X * The header section ends either explicitly with %%EndComments or
X * implicitly with any line that does not begin with %X where X is
X * a not whitespace character.
X *
X * If the file is encapsulated PostScript the optional Preview section
X * is next:
X *
X * %%BeginPreview
X * %%EndPreview
X *
X * This section explicitly begins and ends with the above comments.
X *
X * Next the Defaults section for version 3 page defaults:
X *
X * %%BeginDefaults
X * %%PageBoundingBox: <int> <int> <int> <int>
X * %%PageOrientation: Portrait`7CLandscape
X * %%PageMedia: <text>
X * %%EndDefaults
X *
X * This section explicitly begins and ends with the above comments.
X *
X * The prolog section either explicitly starts with %%BeginProlog or
X * implicitly with any nonblank line.
X *
X * %%BeginProlog
X * %%EndProlog
X *
X * The Prolog should end with %%EndProlog, however the proglog implicit
Vly
X * ends when %%BeginSetup, %%Page, %%Trailer or %%EOF are encountered.
X *
X * The Setup section is where the version 2 page defaults are found.
X * This section either explicitly begins with %%BeginSetup or implicitl
Vy
X * with any noblank line after the Prolog.
X *
X * %%BeginSetup
X * %%PageBoundingBox: <int> <int> <int> <int>
X * %%PageOrientation: Portrait`7CLandscape
X * %%PaperSize: <text>
X * %%EndSetup
X *
X * The Setup should end with %%EndSetup, however the setup implicitly
X * ends when %%Page, %%Trailer or %%EOF are encountered.
X *
X * Next each page starts explicitly with %%Page and ends implicitly wit
Vh
X * %%Page or %%Trailer or %%EOF. The following comments are recognized
V:
X *
X * %%Page: <text> <uint>
X * %%PageBoundingBox: <int> <int> <int> <int>`7C(atend)
X * %%PageOrientation: Portrait`7CLandscape
X * %%PageMedia: <text>
X * %%PaperSize: <text>
X *
X * The tralier section start explicitly with %%Trailer and end with %%E
VOF.
X * The following comment are examined with the proper (atend) notation
X * was used in the header:
X *
X * %%Trailer
X * %%BoundingBox: <int> <int> <int> <int>`7C(atend)
X * %%Orientation: Portrait`7CLandscape`7C(atend)
X * %%Pages: <uint> `5B<int>`5D`7C(atend)
X * %%PageOrder: Ascend`7CDescend`7CSpecial`7C(atend)
X * %%EOF
X *
X *
X * + A DC-3 received severe damage to one of its wings. The wing was a tot
Val
X * loss. There was no replacement readily available, so the mechanic
X * installed a wing from a DC-2.
X */
X
Xstruct document *
Xpsscan(file)
X FILE *file;
X`7B
X struct document *doc;
X int bb_set = NONE;
X int pages_set = NONE;
X int page_order_set = NONE;
X int orientation_set = NONE;
X int page_bb_set = NONE;
X int page_media_set = NONE;
X int preread;`09`09/* flag which tells the readline isn't needed */
X int i;
X unsigned int maxpages = 0;
X unsigned int nextpage = 1;`09/* Next expected page */
X unsigned int thispage;
X int ignore = 0;`09`09/* whether to ignore page ordinals */
X char *label;
X char line`5BPSLINELENGTH`5D;`09/* 255 characters + 1 newline + 1 NULL */
X char text`5BPSLINELENGTH`5D;`09/* Temporary storage for text */
X long position;`09`09/* Position of the current line */
X unsigned int line_len; `09/* Length of the current line */
X unsigned int section_len;`09/* Place to accumulate the section length */
X char *next_char;`09`09/* 1st char after text returned by gettext() */
X char *cp;
X struct documentmedia *dmp;
X
X rewind(file);
X if (readline(line, sizeof line, file, &position, &line_len) == NULL) `7B
X`09fprintf(stderr, "Warning: empty file.\n");
X`09return(NULL);
X `7D
X
X /* Header comments */
X
X if (iscomment(line,"%!PS-Adobe-")) `7B
X`09doc = (struct document *) malloc(sizeof(struct document));
X`09if (doc == NULL) `7B
X`09 fprintf(stderr, "Fatal Error: Dynamic memory exhausted.\n");
X`09 exit(-1);
X`09`7D
X`09memset(doc, 0, sizeof(struct document));
X`09sscanf(line, "%*s %s", text);
X`09doc->epsf = iscomment(text, "EPSF-");
X`09doc->beginheader = position;
X`09section_len = line_len;
X `7D else `7B
X`09return(NULL);
X `7D
X
X preread = 0;
X while (preread `7C`7C readline(line, sizeof line, file, &position, &line
V_len)) `7B
X`09if (!preread) section_len += line_len;
X`09preread = 0;
X`09if (iscomment(line, "%%EndComments") `7C`7C
X`09 line`5B0`5D != '%' `7C`7C
X`09 (!isprint(line`5B1`5D) `7C`7C line`5B1`5D == ' ' `7C`7C
X`09 line`5B1`5D == '\t' `7C`7C line`5B1`5D == '\n')) `7B
X`09 break;
X`09`7D else if (!iscomment(line, "%%")) `7B
X`09 /* Do nothing */
X`09`7D else if (doc->title == NULL && iscomment(line+2, "Title:")) `7B
X`09 doc->title = gettextline(line+length("%%Title:"));
X`09`7D else if (doc->date == NULL && iscomment(line+2, "CreationDate:")) `7B
X`09 doc->date = gettextline(line+length("%%CreationDate:"));
X`09`7D else if (bb_set == NONE && iscomment(line+2, "BoundingBox:")) `7B
X`09 sscanf(line+length("%%BoundingBox:"), "%s", text);
X`09 if (strcmp(text, "(atend)") == 0) `7B
X`09`09bb_set = ATEND;
X`09 `7D else `7B
X`09`09if (sscanf(line+length("%%BoundingBox:"), "%d %d %d %d",
X`09`09`09 &(doc->boundingbox`5BLLX`5D),
X`09`09`09 &(doc->boundingbox`5BLLY`5D),
X`09`09`09 &(doc->boundingbox`5BURX`5D),
X`09`09`09 &(doc->boundingbox`5BURY`5D)) == 4)
X`09`09 bb_set = 1;
X`09`09else `7B
X`09`09 float fllx, flly, furx, fury;
X`09`09 if (sscanf(line+length("%%BoundingBox:"), "%f %f %f %f",
X`09`09`09 &fllx, &flly, &furx, &fury) == 4) `7B
X`09`09`09bb_set = 1;
X`09`09`09doc->boundingbox`5BLLX`5D = fllx;
X`09`09`09doc->boundingbox`5BLLY`5D = flly;
X`09`09`09doc->boundingbox`5BURX`5D = furx;
X`09`09`09doc->boundingbox`5BURY`5D = fury;
X`09`09`09if (fllx < doc->boundingbox`5BLLX`5D)
X`09`09`09 doc->boundingbox`5BLLX`5D--;
X`09`09`09if (flly < doc->boundingbox`5BLLY`5D)
X`09`09`09 doc->boundingbox`5BLLY`5D--;
X`09`09`09if (furx > doc->boundingbox`5BURX`5D)
X`09`09`09 doc->boundingbox`5BURX`5D++;
X`09`09`09if (fury > doc->boundingbox`5BURY`5D)
X`09`09`09 doc->boundingbox`5BURY`5D++;
X`09`09 `7D
X`09`09`7D
X`09 `7D
X`09`7D else if (orientation_set == NONE &&
X`09`09 iscomment(line+2, "Orientation:")) `7B
X`09 sscanf(line+length("%%Orientation:"), "%s", text);
X`09 if (strcmp(text, "(atend)") == 0) `7B
X`09`09orientation_set = ATEND;
X`09 `7D else if (strcmp(text, "Portrait") == 0) `7B
X`09`09doc->orientation = PORTRAIT;
X`09`09orientation_set = 1;
X`09 `7D else if (strcmp(text, "Landscape") == 0) `7B
X`09`09doc->orientation = LANDSCAPE;
X`09`09orientation_set = 1;
X`09 `7D
X`09`7D else if (page_order_set == NONE && iscomment(line+2, "PageOrder:")) `
V7B
X`09 sscanf(line+length("%%PageOrder:"), "%s", text);
X`09 if (strcmp(text, "(atend)") == 0) `7B
X`09`09page_order_set = ATEND;
X`09 `7D else if (strcmp(text, "Ascend") == 0) `7B
X`09`09doc->pageorder = ASCEND;
X`09`09page_order_set = 1;
X`09 `7D else if (strcmp(text, "Descend") == 0) `7B
X`09`09doc->pageorder = DESCEND;
X`09`09page_order_set = 1;
X`09 `7D else if (strcmp(text, "Special") == 0) `7B
X`09`09doc->pageorder = SPECIAL;
X`09`09page_order_set = 1;
X`09 `7D
X`09`7D else if (pages_set == NONE && iscomment(line+2, "Pages:")) `7B
X`09 sscanf(line+length("%%Pages:"), "%s", text);
X`09 if (strcmp(text, "(atend)") == 0) `7B
X`09`09pages_set = ATEND;
X`09 `7D else `7B
X`09`09switch (sscanf(line+length("%%Pages:"), "%d %d",
X`09`09`09 &maxpages, &i)) `7B
X`09`09 case 2:
X`09`09`09if (page_order_set == NONE) `7B
X`09`09`09 if (i == -1) `7B
X`09`09`09`09doc->pageorder = DESCEND;
X`09`09`09`09page_order_set = 1;
X`09`09`09 `7D else if (i == 0) `7B
X`09`09`09`09doc->pageorder = SPECIAL;
X`09`09`09`09page_order_set = 1;
X`09`09`09 `7D else if (i == 1) `7B
X`09`09`09`09doc->pageorder = ASCEND;
X`09`09`09`09page_order_set = 1;
X`09`09`09 `7D
X`09`09`09`7D
X`09`09 case 1:
X`09`09`09doc->pages = (struct page *) calloc(maxpages,
X`09`09`09`09`09`09`09sizeof(struct page));
X`09`09`09if (doc->pages == NULL) `7B
X`09`09`09 fprintf(stderr,
X`09`09`09`09 "Fatal Error: Dynamic memory exhausted.\n");
X`09`09`09 exit(-1);
X`09`09`09`7D
X`09`09`7D
X`09 `7D
X`09`7D else if (doc->nummedia == NONE &&
X`09`09 iscomment(line+2, "DocumentMedia:")) `7B
X`09 float w, h;
X`09 doc->media = (struct documentmedia *)
X`09`09`09 malloc(sizeof (struct documentmedia));
X`09 if (doc->media == NULL) `7B
X`09`09fprintf(stderr, "Fatal Error: Dynamic memory exhausted.\n");
X`09`09exit(-1);
X`09 `7D
X`09 doc->media`5B0`5D.name = gettext(line+length("%%DocumentMedia:"),
X`09`09`09`09`09 &next_char);
X`09 if (doc->media`5B0`5D.name != NULL) `7B
X`09`09if (sscanf(next_char, "%f %f", &w, &h) == 2) `7B
X`09`09 doc->media`5B0`5D.width = w + 0.5;
X`09`09 doc->media`5B0`5D.height = h + 0.5;
X`09`09`7D
X`09`09if (doc->media`5B0`5D.width != 0 && doc->media`5B0`5D.height != 0)
X`09`09 doc->nummedia = 1;
X`09`09else
X`09`09 free(doc->media`5B0`5D.name);
X`09 `7D
X`09 preread=1;
X`09 while (readline(line, sizeof line, file, &position, &line_len) &&
X`09`09 iscomment(line, "%%+")) `7B
X`09`09section_len += line_len;
X`09`09doc->media = (struct documentmedia *)
X`09`09`09 realloc(doc->media,
X`09`09`09`09 (doc->nummedia+1)*
X`09`09`09`09 sizeof (struct documentmedia));
X`09`09if (doc->media == NULL) `7B
X`09`09 fprintf(stderr, "Fatal Error: Dynamic memory exhausted.\n");
X`09`09 exit(-1);
X`09`09`7D
X`09`09doc->media`5Bdoc->nummedia`5D.name = gettext(line+length("%%+"),
X`09`09`09`09`09`09`09 &next_char);
X`09`09if (doc->media`5Bdoc->nummedia`5D.name != NULL) `7B
X`09`09 if (sscanf(next_char, "%f %f", &w, &h) == 2) `7B
X`09`09`09doc->media`5Bdoc->nummedia`5D.width = w + 0.5;
X`09`09`09doc->media`5Bdoc->nummedia`5D.height = h + 0.5;
X`09`09 `7D
X`09`09 if (doc->media`5Bdoc->nummedia`5D.width != 0 &&
X`09`09`09doc->media`5Bdoc->nummedia`5D.height != 0) doc->nummedia++;
X`09`09 else
X`09`09`09free(doc->media`5Bdoc->nummedia`5D.name);
X`09`09`7D
X`09 `7D
X`09 section_len += line_len;
X`09 if (doc->nummedia != 0) doc->default_page_media = doc->media;
X`09`7D else if (doc->nummedia == NONE &&
X`09`09 iscomment(line+2, "DocumentPaperSizes:")) `7B
X
X`09 doc->media = (struct documentmedia *)
X`09`09`09 malloc(sizeof (struct documentmedia));
X`09 if (doc->media == NULL) `7B
X`09`09fprintf(stderr, "Fatal Error: Dynamic memory exhausted.\n");
X`09`09exit(-1);
X`09 `7D
X`09 doc->media`5B0`5D.name = gettext(line+length("%%DocumentPaperSizes:")
V,
X`09`09`09`09`09 &next_char);
X`09 if (doc->media`5B0`5D.name != NULL) `7B
X`09`09doc->media`5B0`5D.width = 0;
X`09`09doc->media`5B0`5D.height = 0;
X`09`09for (dmp=papersizes; dmp->name != NULL; dmp++) `7B
X`09`09 /* Note: Paper size comment uses down cased paper size
X`09`09 * name. Case insensitive compares are only used for
X`09`09 * PaperSize comments.
X`09`09 */
X`09`09 if (strcasecmp(doc->media`5B0`5D.name, dmp->name) == 0) `7B
X`09`09`09free(doc->media`5B0`5D.name);
X`09`09`09doc->media`5B0`5D.name =
X`09`09`09`09(char *)malloc(strlen(dmp->name)+1);
X`09`09`09if (doc->media`5B0`5D.name == NULL) `7B
X`09`09`09 fprintf(stderr,
X`09`09`09`09 "Fatal Error: Dynamic memory exhausted.\n");
X`09`09`09 exit(-1);
X`09`09`09`7D
X`09`09`09strcpy(doc->media`5B0`5D.name, dmp->name);
X`09`09`09doc->media`5B0`5D.width = dmp->width;
X`09`09`09doc->media`5B0`5D.height = dmp->height;
X`09`09`09break;
X`09`09 `7D
X`09`09`7D
X`09`09if (doc->media`5B0`5D.width != 0 && doc->media`5B0`5D.height != 0)
X`09`09 doc->nummedia = 1;
X`09`09else
X`09`09 free(doc->media`5B0`5D.name);
X`09 `7D
X`09 while (cp = gettext(next_char, &next_char)) `7B
X`09`09doc->media = (struct documentmedia *)
X`09`09`09 realloc(doc->media,
X`09`09`09`09 (doc->nummedia+1)*
X`09`09`09`09 sizeof (struct documentmedia));
X`09`09if (doc->media == NULL) `7B
X`09`09 fprintf(stderr, "Fatal Error: Dynamic memory exhausted.\n");
X`09`09 exit(-1);
X`09`09`7D
X`09`09doc->media`5Bdoc->nummedia`5D.name = cp;
X`09`09doc->media`5Bdoc->nummedia`5D.width = 0;
X`09`09doc->media`5Bdoc->nummedia`5D.height = 0;
X`09`09for (dmp=papersizes; dmp->name != NULL; dmp++) `7B
X`09`09 /* Note: Paper size comment uses down cased paper size
X`09`09 * name. Case insensitive compares are only used for
X`09`09 * PaperSize comments.
X`09`09 */
X`09`09 if (strcasecmp(doc->media`5Bdoc->nummedia`5D.name,
X`09`09`09 dmp->name) == 0) `7B
X`09`09`09free(doc->media`5Bdoc->nummedia`5D.name);
X`09`09`09doc->media`5Bdoc->nummedia`5D.name =
X`09`09`09`09(char *)malloc(strlen(dmp->name)+1);
X`09`09`09if (doc->media`5Bdoc->nummedia`5D.name == NULL) `7B
X`09`09`09 fprintf(stderr,
X`09`09`09`09 "Fatal Error: Dynamic memory exhausted.\n");
X`09`09`09 exit(-1);
X`09`09`09`7D
X`09`09`09strcpy(doc->media`5Bdoc->nummedia`5D.name, dmp->name);
X`09`09`09doc->media`5Bdoc->nummedia`5D.name = dmp->name;
X`09`09`09doc->media`5Bdoc->nummedia`5D.width = dmp->width;
X`09`09`09doc->media`5Bdoc->nummedia`5D.height = dmp->height;
X`09`09`09break;
X`09`09 `7D
X`09`09`7D
X`09`09if (doc->media`5Bdoc->nummedia`5D.width != 0 &&
X`09`09 doc->media`5Bdoc->nummedia`5D.height != 0) doc->nummedia++;
X`09`09else
X`09`09 free(doc->media`5Bdoc->nummedia`5D.name);
X`09 `7D
X`09 preread=1;
X`09 while (readline(line, sizeof line, file, &position, &line_len) &&
X`09`09 iscomment(line, "%%+")) `7B
X`09`09section_len += line_len;
X`09`09next_char = line + length("%%+");
+-+-+-+-+-+-+-+- END OF PART 11 +-+-+-+-+-+-+-+-
Technical Details
Message-ID:
<8881767@MVB.SAIC.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!usc!news.service.uci.edu!unogate!mvb.saic.com!vmsnet-sourcesShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!usc!news.service.uci.edu!unogate!mvb.saic.com!vmsnet-sources Newsgroups: vmsnet.sources From: Terry Poot <tp@mccall.com> Subject: Ghostview for VMS 11/14 Message-ID: <8881767@MVB.SAIC.COM> Date: Thu, 29 Oct 1992 18:50:03 GMT Lines: 1592 Approved: Mark.Berryman@Mvb.Saic.Com