home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Crawly Crypt Collection 2
/
crawlyvol2.bin
/
apps
/
dtp
/
ghost
/
gs301src
/
atari
/
gp_atar4.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-17
|
25KB
|
1,068 lines
/* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises. All rights reserved.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* gp_atar4.c */
/*
* This file contains callback functions for the user interface of
* the Atari platform.
*/
#include "gp_atar4.h"
extern VWRK VWork; /* from gp_atar1.h */
extern PSTATE State; /* from gp_atar1.h */
extern OBJECT menuobj[], aboutobj[], iconobj[]; /* from gp_atar1.h */
extern OBJECT resobj[], devobj[], sizobj[]; /* from gp_atar1.h */
extern OBJECT printobj[]; /* from gp_atar1.h */
extern WINLIST *WinListDelete(); /* from gp_atar3.c */
extern WINLIST *WList; /* from gp_atar2.c */
extern WINDOW conswin, printwin; /* from gp_atar2.c */
extern WINDOW aboutwin, reswin, pagewin; /* from gp_atar2.c */
extern WINDOW iconwin, devwin, sizwin; /* from gp_atar2.c */
extern EVENT Event; /* from gp_atar2.c */
extern char devices[DEVICES][DNAMELEN]; /* gp_atar1.h */
int LastPrnOutButton=0;
int
res_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
char *sptr, nl[2]="";
byte cone, cten, chun;
short cindex=0, done=0, redraw=1;
static short applied=0;
int Resolution, Width, Height;
static unsigned long oldone=0x30FF1100L;
static unsigned long oldten=0x38FF1100L;
static unsigned long oldhun=0x30FF1100L;
WINTEXT *text = conswin.obj;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
strcpy(nl, "\n");
}
switch (index) {
case RES_OUP:
if (!cindex) cindex = RES_ONE;
case RES_TUP:
if (!cindex) cindex = RES_TEN;
case RES_HUP:
if (!cindex) cindex = RES_HUN;
if (object[cindex].ob_spec < 0x39000000L) {
object[cindex].ob_spec += 0x01000000L;
}
else {
object[cindex].ob_spec -= 0x09000000L;
}
objc_draw(object, cindex, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h);
applied = 0;
break;
case RES_ODN:
if (!cindex) cindex = RES_ONE;
case RES_TDN:
if (!cindex) cindex = RES_TEN;
case RES_HDN:
if (!cindex) cindex = RES_HUN;
if (object[cindex].ob_spec > 0x31000000L) {
object[cindex].ob_spec -= 0x01000000L;
}
else {
object[cindex].ob_spec += 0x09000000L;
}
objc_draw(object, cindex, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h);
applied = 0;
break;
case RES_DEF:
object[RES_ONE].ob_spec = 0x30FF1100L;
object[RES_TEN].ob_spec = 0x38FF1100L;
object[RES_HUN].ob_spec = 0x30FF1100L;
objc_draw(object, RES_HUN, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h);
objc_draw(object, RES_TEN, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h);
objc_draw(object, RES_ONE, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h);
applied = 0;
break;
case RES_CAN:
object[RES_ONE].ob_spec = oldone;
object[RES_TEN].ob_spec = oldten;
object[RES_HUN].ob_spec = oldhun;
WinClose(owin);
WList = WinListDelete(WList, owin);
redraw = 0;
break;
case RES_DONE:
if (applied) {
WinClose(owin);
WList = WinListDelete(WList, owin);
redraw = 0;
break;
}
done = 1;
case RES_APP:
if (done) {
WinClose(owin);
WList = WinListDelete(WList, owin);
redraw = 0;
}
oldone = object[RES_ONE].ob_spec;
oldten = object[RES_TEN].ob_spec;
oldhun = object[RES_HUN].ob_spec;
cone = *(byte *)(&object[RES_ONE].ob_spec);
cten = *(byte *)(&object[RES_TEN].ob_spec);
chun = *(byte *)(&object[RES_HUN].ob_spec);
Resolution = 100 * (chun-'0') + 10 * (cten-'0') + (cone-'0');
Width = nint(((float)Resolution * gr->Width) / gr->XRes);
Height = nint((Resolution * vw->AspectRatio * gr->Height) / gr->YRes);
gr->XRes = Resolution;
gr->YRes = nint(Resolution * vw->AspectRatio);
sprintf(st->Command,
"%smark /HWResolution [%d %d] /HWSize [%d %d] currentdevice putdeviceprops pop\n",
nl, gr->XRes, gr->YRes, Width, Height);
SendCommand(st, pw, dest);
applied = 1;
break;
}
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), redraw);
return 0;
}
int
abo_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
short redraw=1;
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), redraw);
switch (index) {
case ABO_GEN:
HandleHelp(GENHELP, vw, st, pw, dest);
break;
case ABO_FONT:
HandleHelp(FONTHELP, vw, st, pw, dest);
break;
case ABO_ERR:
HandleHelp(ERRHELP, vw, st, pw, dest);
break;
case ABO_FEAT:
HandleHelp(FEATHELP, vw, st, pw, dest);
break;
}
return 0;
}
int
dev_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
char *sptr, nl[2]="";
short done=0, redraw=1;
static short applied=0;
unsigned short state, screendev;
WINTEXT *text = conswin.obj;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
strcpy(nl, "\n");
}
switch (index) {
case DEV_DEF:
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
index = FIRSTDEV;
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
/* Intentional fall through. */
default:
objc_change(object, st->Device, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[st->Device].ob_state ^ SELECTED), 1);
st->Device = index;
applied = 0;
break;
case DEV_CAN:
objc_change(object, st->Device, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[st->Device].ob_state ^ SELECTED), 1);
objc_change(object, st->LastDevice, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[st->LastDevice].ob_state ^ SELECTED), 1);
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 0);
WinClose(owin);
WList = WinListDelete(WList, owin);
st->Device = st->LastDevice;
break;
case DEV_DONE:
if (applied) {
WinClose(owin);
WList = WinListDelete(WList, owin);
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 0);
break;
}
done = 1;
/* Intentional fall-through. */
case DEV_APP:
/* Close the window if we are done. */
if (done) {
WinClose(owin);
WList = WinListDelete(WList, owin);
redraw = 0;
}
/* Update the print dialog and redraw if it is open. */
strcpy(st->DevString, (char *)object[st->Device].ob_spec);
if (printwin.opened) {
st->Event->Message[3] = printwin.handle;
objc_offset(printobj, PR_DSTR,
&st->Event->Message[4], &st->Event->Message[5]);
st->Event->Message[6] = printobj[PR_DSTR].ob_width;
st->Event->Message[7] = printobj[PR_DSTR].ob_height;
objw_redraw(0, st);
}
if (LastPrnOutButton) {
objc_change(printobj, LastPrnOutButton, 0,
printwin.canvas.g_x, printwin.canvas.g_y,
printwin.canvas.g_w, printwin.canvas.g_h,
(printobj[LastPrnOutButton].ob_state ^ SELECTED),
printwin.opened);
}
screendev = !strcmp(st->DevString, "stvdi");
state = printobj[PR_PRN].ob_state;
objc_change(printobj, PR_PRN, 0,
printwin.canvas.g_x, printwin.canvas.g_y,
printwin.canvas.g_w, printwin.canvas.g_h,
((screendev) ? state | DISABLED : state & ~ DISABLED),
printwin.opened);
state = printobj[PR_CEN].ob_state;
objc_change(printobj, PR_CEN, 0,
printwin.canvas.g_x, printwin.canvas.g_y,
printwin.canvas.g_w, printwin.canvas.g_h,
((screendev) ? state | DISABLED : state & ~ DISABLED),
printwin.opened);
state = printobj[PR_OFILE].ob_state;
objc_change(printobj, PR_OFILE, 0,
printwin.canvas.g_x, printwin.canvas.g_y,
printwin.canvas.g_w, printwin.canvas.g_h,
((screendev) ? state | DISABLED : state & ~ DISABLED),
printwin.opened);
LastPrnOutButton = 0;
/* Send the command to change the device to the interpreter. */
sprintf(st->Command, "%s(%s) selectdevice\n",
nl, (char *)object[st->Device].ob_spec);
SendCommand(st, pw, dest);
redraw = 1;
applied = 1;
st->LastDevice = st->Device;
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), redraw);
break;
}
return 0;
}
int
siz_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
char *sptr, nl[2]="";
short done=0, redraw=1;
static short applied=0, select=6, oldselect=6;
WINTEXT *text = conswin.obj;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
strcpy(nl, "\n");
}
switch (index) {
case SIZ_DEF:
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
index = 6;
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
default:
objc_change(object, select, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[select].ob_state ^ SELECTED), 1);
select = index;
applied = 0;
break;
case SIZ_CAN:
objc_change(object, select, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[select].ob_state ^ SELECTED), 1);
objc_change(object, oldselect, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[oldselect].ob_state ^ SELECTED), 1);
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 0);
WinClose(owin);
WList = WinListDelete(WList, owin);
select = oldselect;
break;
case SIZ_DONE:
if (applied) {
WinClose(owin);
WList = WinListDelete(WList, owin);
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 0);
break;
}
done = 1;
case SIZ_APP:
if (done) {
WinClose(owin);
WList = WinListDelete(WList, owin);
redraw = 0;
}
sprintf(st->Command, "%s%s\n",
nl, (char *)object[select].ob_spec);
SendCommand(st, pw, dest);
redraw = 1;
applied = 1;
oldselect = select;
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), redraw);
break;
}
return 0;
}
int
prn_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
char *sptr, nl[2]="";
unsigned short state, screendev;
int Select=1, Deselect=0;
WINTEXT *text = conswin.obj;
int prevline = (text->ln > 0) ? text->ln-1 : text->bh-1;
if ((sptr = strstr(text->buff[prevline], ">>")) != NULL) {
strcpy(nl, "\n");
}
switch (index) {
case PR_DEF:
*st->Command = '\0';
if (st->Device != FIRSTDEV + 1) {
st->Device = FIRSTDEV + 1;
strcpy(st->DevString, devices[1]);
sprintf(st->Command, "%s(%s) selectdevice\n", nl, devices[1]);
}
if (printwin.opened) {
st->Event->Message[3] = printwin.handle;
objc_offset(printobj, PR_DSTR,
&st->Event->Message[4], &st->Event->Message[5]);
st->Event->Message[6] = printobj[PR_DSTR].ob_width;
st->Event->Message[7] = printobj[PR_DSTR].ob_height;
objw_redraw(0, st);
}
if (printobj[PR_PRN].ob_state & DISABLED) {
objc_change(printobj, PR_PRN, 0,
printwin.canvas.g_x, printwin.canvas.g_y,
printwin.canvas.g_w, printwin.canvas.g_h,
(printobj[PR_PRN].ob_state & ~ DISABLED),
printwin.opened);
objc_change(printobj, PR_CEN, 0,
printwin.canvas.g_x, printwin.canvas.g_y,
printwin.canvas.g_w, printwin.canvas.g_h,
(printobj[PR_CEN].ob_state & ~ DISABLED),
printwin.opened);
objc_change(printobj, PR_OFILE, 0,
printwin.canvas.g_x, printwin.canvas.g_y,
printwin.canvas.g_w, printwin.canvas.g_h,
(printobj[PR_OFILE].ob_state & ~ DISABLED),
printwin.opened);
}
if (LastPrnOutButton != PR_CEN) {
if (LastPrnOutButton) {
objc_change(object, LastPrnOutButton, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[LastPrnOutButton].ob_state ^ SELECTED), 1);
}
objc_change(object, PR_CEN, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[PR_CEN].ob_state ^ SELECTED), 1);
LastPrnOutButton = PR_CEN;
strcpy(st->Outfile, "CEN:");
strcat(st->Command,
"mark /OutputFile (CEN:) currentdevice putdeviceprops pop\n");
}
if (strlen(st->Command)) {
SendCommand(st, pw, dest);
}
DevObjUpdate(st);
Deselect = 1;
break;
case PR_CAN:
WinClose(owin);
WList = WinListDelete(WList, owin);
Deselect = 1;
break;
case PR_PR:
sprintf(st->Command, "%s(%s%s) run\n", nl, st->DirSpec, st->Infile);
SendCommand(st, pw, dest);
Deselect = 1;
break;
case PR_DEV:
WinListAdd(WList, &devwin);
ObjWinOpen(devobj, &devwin, vw, st);
Deselect = 1;
break;
case PR_IFILE:
/* Use any previously selected input file as the default. */
if (strlen(st->Infile)) {
strcpy(st->FileSel, st->Infile);
}
else {
strcpy(st->FileSel, "");
}
if ((Select = GetFile(st, "*.*")) != 0) {
strcpy(st->Infile, st->FileSel);
}
if (printwin.opened) {
st->Event->Message[3] = printwin.handle;
objc_offset(printobj, PR_FSTR,
&st->Event->Message[4], &st->Event->Message[5]);
st->Event->Message[6] = printobj[PR_FSTR].ob_width;
st->Event->Message[7] = printobj[PR_FSTR].ob_height;
objw_redraw(0, st);
}
Deselect = 1;
break;
case PR_CEN: /* directly to centronics hardware */
if (LastPrnOutButton != PR_CEN) {
if (LastPrnOutButton) {
objc_change(object, LastPrnOutButton, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
}
LastPrnOutButton = PR_CEN;
}
else {
objc_change(object, PR_CEN, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
}
if (strcmp(st->Outfile, "CEN:")) {
strcpy(st->Outfile, "CEN:");
sprintf(st->Command,
"%smark /OutputFile (CEN:) currentdevice putdeviceprops pop\n",nl);
SendCommand(st, pw, dest);
}
break;
case PR_PRN: /* centronics port via gemdos */
if (LastPrnOutButton != PR_PRN) {
if (LastPrnOutButton) {
objc_change(object, LastPrnOutButton, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
}
LastPrnOutButton = PR_PRN;
}
else {
objc_change(object, PR_PRN, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
}
if (strcmp(st->Outfile, "PRN:")) {
strcpy(st->Outfile, "PRN:");
sprintf(st->Command,
"%smark /OutputFile (PRN:) currentdevice putdeviceprops pop\n",nl);
SendCommand(st, pw, dest);
}
break;
case PR_OFILE: /* output to 'Outfile' */
if (LastPrnOutButton != PR_OFILE) {
if (LastPrnOutButton) {
objc_change(object, LastPrnOutButton, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
}
LastPrnOutButton = PR_OFILE;
}
else {
objc_change(object, PR_OFILE, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
}
/* Use any previously selected output file as the default. */
if (strlen(st->Outfile)) {
strcpy(st->FileSel, st->Outfile);
}
else {
strcpy(st->FileSel, "");
}
if ((Select = GetFile(st, "*.*")) != 0) {
strcpy(st->Outfile, st->FileSel);
sprintf(st->Command,
"%smark /OutputFile (%s%s) currentdevice putdeviceprops pop\n",
nl, st->DirSpec, st->Outfile);
SendCommand(st, pw, dest);
}
break;
}
if (Deselect) {
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
}
return 0;
}
int
pag_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
graf_mouse(BUSY_BEE, 0L);
HandlePageSelect(vw, st, pw, dest, index);
graf_mouse(ARROW, 0L);
return 0;
}
int
ign_button(OBJECT object[], int index, WINDOW *owin, VWRK *vw,
PSTATE *st, GRAPHIC *gr, stream_cursor_write *pw, byte **dest)
{
objc_change(object, index, 0,
owin->canvas.g_x, owin->canvas.g_y,
owin->canvas.g_w, owin->canvas.g_h,
(object[index].ob_state ^ SELECTED), 1);
return 0;
}
OBJECT *
CreatePageObj(int pages)
{
char (*str)[4], *itoa();
int i, j, count, rows, cols, prod;
OBJECT *pobj;
TEDINFO *tinf;
rows = cols = (int)(pow(pages, .5) + .1);
while (rows*cols < pages) {
++cols;
}
prod = rows * cols;
/* Put some error checks here! */
pobj = (OBJECT *)gs_malloc((uint)(prod+1), sizeof(OBJECT), "page object");
tinf = (TEDINFO *)gs_malloc((uint)pages, sizeof(TEDINFO), "page tedinfo");
str = (char (*)[4])gs_malloc((uint)pages, 4, "page strings");
AssignObj(&pobj[0], -1, 1, prod, G_BOX, HIDETREE, OUTLINED, 0x11100L,
0, 0, 4*cols, 2*rows);
for (j=0, count=0; j<rows; ++j) {
for (i=0; i<cols; ++i) {
if (++count <= pages) {
itoa(count, str[count-1]);
AssignTinf(&tinf[count-1], str[count-1] , "", "",
3, 6, 2, 0x1100, 0x0, 1, 2, 1);
AssignObj(&pobj[count], count+1, -1, -1, G_BOXTEXT, SELECTABLE,
NORMAL, &tinf[count-1], 4*i, 2*j, 4, 2);
}
else {
AssignObj(&pobj[count], count+1, -1, -1, G_BOX, NONE,
NORMAL, 0x11131L, 4*i, 2*j, 4, 2);
}
}
}
pobj[prod].ob_next = 0;
pobj[prod].ob_flags |= LASTOB;
i=-1;
do {
++i;
rsrc_obfix(pobj, i);
} while (!(pobj[i].ob_flags & LASTOB));
return pobj;
}
int
DeletePageObj(PSTATE *st, WINDOW *pwin)
{
int rows, cols, prod;
OBJECT *pobj = (OBJECT *)pwin->obj;
TEDINFO *tinf = (TEDINFO *)pobj[1].ob_spec;
rows = cols = (int)(pow(st->Doc->numpages, .5) + .1);
while (rows*cols < st->Doc->numpages) {
++cols;
}
prod = rows * cols;
if (pwin->opened || pwin->iconified) {
WinClose(pwin);
WList = WinListDelete(WList, pwin);
}
gs_free((char *)tinf->te_ptext, st->Doc->numpages, 4, "page strings");
gs_free((char *)tinf, st->Doc->numpages, sizeof(TEDINFO), "page tedinfo");
gs_free((char *)pobj, prod+1, sizeof(OBJECT), "page object");
pwin->obj = NULL;
pwin->frame.g_x = 0;
pwin->frame.g_y = 0;
pwin->frame.g_w = 0;
pwin->frame.g_h = 0;
st->Doc->name[0] = '\0';
st->Doc->maxpages = 0;
st->Doc->numpages = 0;
st->Doc->currentpage = 0;
return 0;
}
int
AssignObj(OBJECT *obj, int next, int head, int tail, int type, int flags,
int state, unsigned long spec, int x, int y, int width, int height)
{
obj->ob_next = (short)next;
obj->ob_head = (short)head;
obj->ob_tail = (short)tail;
obj->ob_type = (unsigned short)type;
obj->ob_flags = (unsigned short)flags;
obj->ob_state = (unsigned short)state;
obj->ob_spec = spec;
obj->ob_x = (short)x;
obj->ob_y = (short)y;
obj->ob_width = (short)width;
obj->ob_height = (short)height;
return 0;
}
int
AssignTinf(TEDINFO *inf, char *ptext, char *ptmplt, char *pvalid,
int font, int junk1, int just, int color, int junk2,
int thickness, int txtlen, int tmplen)
{
inf->te_ptext = ptext;
inf->te_ptmplt = ptmplt;
inf->te_pvalid = pvalid;
inf->te_font = (short)font;
inf->te_junk1 = (short)junk1;
inf->te_just = (short)just;
inf->te_color = (short)color;
inf->te_junk2 = (short)junk2;
inf->te_thickness = (short)thickness;
inf->te_txtlen = (short)txtlen;
inf->te_tmplen = (short)tmplen;
return 0;
}
int
PageFilter(char* InputName, DOCUMENT *doc)
{
char *sptr, line[MAXLEN];
int PageCount=0, length=0, maxpages=20;
fpos_t EndPosition;
FILE *InFile;
PAGEINFO *temp;
if ((InFile = fopen(InputName, "r")) == NULL) {
return -1;
}
strcpy((char *)doc->name, InputName);
doc->maxpages = maxpages;
if (doc->pageinf == NULL) {
doc->pageinf = (PAGEINFO *)gs_malloc(maxpages, sizeof(PAGEINFO),
"page info");
memset(doc->pageinf, 0, maxpages*sizeof(PAGEINFO));
}
fgetpos(InFile, &doc->pageinf[PageCount].start);
while (fgets(line, MAXLEN, InFile) != NULL) {
length += strlen(line);
if (strncmp(line, "%%", 2) == 0) {
if (strncmp(line, "%%Page:", 7) == 0 ||
strncmp(line, "%%Trailer", 9) == 0) {
if (doc->pageinf[PageCount].extracted == 1) {
doc->pageinf[PageCount].extracted = -1;
}
doc->pageinf[PageCount].length = length;
length = 0;
if (++PageCount > maxpages) {
int oldsize = maxpages;
maxpages += 20;
/* Allocate a larger buffer. */
temp = (PAGEINFO *)gs_malloc(maxpages, sizeof(PAGEINFO),
"page info");
memset(doc->pageinf, 0, maxpages*sizeof(PAGEINFO));
/* Copy the old buffer to the new one. */
memcpy(temp, doc->pageinf,
(MIN(oldsize, maxpages))*sizeof(PAGEINFO));
/* Free the old buffer. */
gs_free((char *)doc->pageinf, oldsize, sizeof(PAGEINFO),
"page info");
doc->pageinf = temp;
doc->maxpages = maxpages;
}
fgetpos(InFile, &doc->pageinf[PageCount].start);
}
}
}
doc->pageinf[PageCount].length = length;
doc->numpages = PageCount-1;
fclose(InFile);
return PageCount-1;
}
int PageCopy(int page, char *OutName, DOCUMENT *doc)
{
char *itoa(), temp[MAXLEN], *buffer;
int count, ch, ret;
FILE *InFile, *OutFile;
if (doc->numpages <= 1) {
return -1;
}
if (page != 0) {
itoa(page, temp);
strcat(OutName, temp);
}
strcat(OutName, ".ps");
if (doc->pageinf[page].extracted == 1) {
return 0;
}
if ((InFile = fopen(doc->name, "r")) == NULL) {
return -1;
}
if ((OutFile = fopen(OutName, "wb")) == NULL) {
return -1;
}
fsetpos(InFile, &doc->pageinf[page].start);
count = doc->pageinf[page].length;
if ((buffer = (char *)gs_malloc(count, 1, "copy buffer")) != NULL) {
if ((ret = fread(buffer, 1, count, InFile)) != count)
eprintf("PageCopy: Read Error!");
if ((ret = fwrite(buffer, 1, count, OutFile)) != count)
eprintf("PageCopy: Write Error!");
gs_free(buffer, count, 1, "copy buffer");
}
else {
while (count--) {
ch = fgetc(InFile);
fputc(ch, OutFile);
}
}
doc->pageinf[page].extracted = 1;
fclose(InFile);
fclose(OutFile);
}