home *** CD-ROM | disk | FTP | other *** search
- /* 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_atari.c */
-
- /* Atari-specific routines for Ghostscript */
-
- #include "gp_atari.h"
-
- /* popen isn't POSIX-standard, so we declare it here. */
-
- extern FILE *popen();
- extern int pclose();
- extern char *getenv(P1(const char *));
-
- extern void gs_exit(P1(int exit_status)); /* from gsmain.c */
- extern stream *gs_stream_stdin; /* from zfiledev.c */
- extern stream *gs_stream_stdout; /* from zfiledev.c */
- extern stream *gs_stream_stderr; /* from zfiledev.c */
-
- extern int plot_x, plot_y, step_dx, step_dy; /* from gdevvdi.c */
- extern int width, height; /* from gdevvdi.c */
-
- /* Use a pseudo file device to get win_stdio_init called at the right time. */
- /* This is bad architecture; we'll fix it later. */
-
- private fdev_proc_init(win_std_init);
- private int win_std_read_buf();
- private int win_std_write_buf();
- private int cons_redraw(int, TEXTWIN *);
- private int objw_redraw(int, OBJECT *, WINDOW *);
- private int form_redraw(int, WINDOW *);
-
- const file_device gs_fdev_wstdio = {
- "wstdio", {
- win_std_init, fdev_no_open_device,
- fdev_no_open_file, fdev_no_fopen, fdev_no_fclose,
- fdev_no_delete_file, fdev_no_rename_file,
- fdev_no_enumerate_files }
- };
-
- WINDOW twin = {
- 0,
- T_GADGETS,
- 0,
- T_TITL,
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- cons_redraw
- };
-
- TEXTWIN cons = {
- &twin,
- {},
- 0,
- 0,
- 0, 0,
- 0, 0,
- 0,
- 0, 0,
- 0, 0,
- 0, 0,
- 0, LINES-1,
- 0, INITLINES-1,
- 0, 0,
- 0
- };
-
- WINDOW icon = {
- 0,
- I_GADGETS,
- 0,
- I_TITL,
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- objw_redraw
- };
-
- WINDOW dial = {
- 0,
- D_GADGETS,
- 0,
- D_TITL,
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- objw_redraw
- };
-
- WINDOW imag = {
- 0,
- W_GADGETS,
- 0,
- W_TITL,
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- {0, 0, 0, 0},
- form_redraw
- };
-
- void GetPalette(), SetPalette();
-
- short GSPalette=0;
- uint PaletteSize=0;
- int *Palette, *OldPalette;
- int *ColorReg;
-
- char command[MAXLEN]=""; /* GS command string */
- char infile[MAXLEN]=""; /* input file */
- char current_dir[MAXLEN]=""; /* current directory */
- char dir_spec[MAXLEN]=""; /* used for file selector */
- char file_sel[MAXLEN]=""; /* selected file */
- char *sptr; /* generic string pointer */
-
- gx_color_value MaxRGB;
- int ChangeX, ChangeY;
-
- /* GEM variables. */
-
- short TrueColor=0;
- short Chunky8=0;
- short Gdebug=0, Debug8=0, Debug16=0;
-
- ushort SendMsg[8];
-
- int ApId, ExitButton;
- int XRes, YRes, ColorBits;
- int msgbuff[8], pxy[8];
- int GemHandle, VdiHandle;
- int window=1;
-
- char prgname[] = " ST-GS"; /* CF */
- int MultiTOS = 0; /* true : AES-Version >=0x400 */
- #ifdef USE_RSC /* use resource-file */
- OBJECT *menu, *about, *noghost;
- #endif
-
- float AspectRatio;
-
- GRECT full;
-
- MFDB plane_image, image, screen;
-
- /* Do platform-dependent initialization. */
-
- void
- gp_init(void)
- {
- char *env;
-
- int i, j;
- int wchar, hchar, wbox, hbox;
- int work_out[57], rgb[3];
- int work_in[11] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2};
-
- /* Check the GS_WIN environment variable to decide what to
- * do about windows. Windows are used unless GS_WIN contains
- * the string "off".
- */
-
- if ((env = getenv("GS_WIN")) != NULL) {
- if (!strcmp(env, "off") || !strcmp(env, "OFF")) {
- window = 0;
- }
- }
-
- /* Check the GS_DISPLAY environment variable. Chunky8/16
- * tell the screen driver that the screen hardware uses chunky
- * pixel format (each pixel is one byte or one word). This
- * knowledge allows some image transformations to be skipped.
- */
-
- if ((env = getenv("GS_DISPLAY")) != NULL) {
- if (!strcmp(env, "chunky8") || !strcmp(env, "CHUNKY8")) {
- Chunky8 = 1;
- }
- }
-
- if ((env = getenv("GS_DEBUG")) != NULL) {
- if (!strcmp(env, "gdebug")) {
- Gdebug = 1;
- }
- else if (!strcmp(env, "debug8")) {
- Debug8 = 1;
- }
- else if (!strcmp(env, "debug16")) {
- Debug16 = 1;
- }
- }
-
- /* Find the current directory. */
-
- getcwd(current_dir, MAXLEN);
- while ((sptr = strchr(current_dir, '/')) != NULL) {
- *sptr = '\\'; /* change forward to backward slashes */
- }
- strcat(current_dir, "\\");
-
- /* Call appl_init() to initialize the aes before using any aes
- * functions.
- */
-
- if ((ApId = appl_init()) == -1) {
- eprintf("stvdi_open: appl_init() failed!\n");
- gs_exit(-1);
- }
-
- MultiTOS = (gl_ap_version >= 0x400); /* CF */
-
- /* Open a virtual workstation and get the screen resolution. */
-
- GemHandle = graf_handle(&wchar, &hchar, &wbox, &hbox);
- VdiHandle = GemHandle;
- v_opnvwk(work_in, &VdiHandle, work_out);
-
- if (VdiHandle == 0) {
- eprintf("stvdi_open: Could not open virtual screen workstation");
- gs_exit(-1);
- }
-
- /* Get the character size, screen resolution, aspect ratio, and
- * palette size.
- */
-
- cons.wc = wchar;
- cons.hc = hchar;
-
- XRes = work_out[0];
- YRes = work_out[1];
-
- AspectRatio = (float)(work_out[3])/(float)(work_out[4]);
-
- /* Get the number of color planes. */
-
- vq_extnd(VdiHandle, 1, work_out);
-
- if (Debug8) {
- ColorBits = 8;
- }
- else if (Debug16) {
- ColorBits = 16;
- }
- else {
- ColorBits = work_out[4];
- }
-
- TrueColor = (!work_out[5] || (ColorBits >= 16));
-
- if ((env = getenv("GS_DISPLAY")) != NULL) {
- if (!strcmp(env, "truecolor")) {
- TrueColor = 1;
- }
- }
-
- if (ColorBits != 1 && ColorBits != 2 &&
- ColorBits != 4 && ColorBits != 8 && ColorBits != 16) {
- eprintf1("stvdi_open: %d bit color is not supported.\n", ColorBits);
- gs_exit(-1);
- }
-
- MaxRGB = DITH_RGB(ColorBits) - 1;
-
- if ((ColorBits > 1) && !TrueColor) {
-
- int psize;
-
- psize = (int)(pow(2, ColorBits) + .5);
- PaletteSize = 3 * psize;
-
- /* Set up the palette--a sequence of rgb values. */
-
- if ((Palette = (int *)gs_malloc((uint)PaletteSize,
- sizeof(int), "Palette")) == NULL) {
- eprintf("stvdi_open: No memory for color palette!\n");
- gs_exit(-1);
- }
-
- if ((OldPalette = (int *)gs_malloc((uint)PaletteSize,
- sizeof(int), "OldPalette")) == NULL) {
- eprintf("stvdi_open: No memory for color palette!\n");
- gs_exit(-1);
- }
-
- if ((ColorReg = (int *)gs_malloc((uint)psize,
- sizeof(int), "ColorReg")) == NULL) {
- eprintf("stvdi_open: No memory for color map array!\n");
- gs_exit(-1);
- }
-
- if (Debug8) {
-
- Palette[0] = 0;
- Palette[1] = 0;
- Palette[2] = 0;
-
- for (i=3; i<PaletteSize; i++) {
- Palette[i] = 1;
- }
-
- }
- else {
-
- /* Fill the array ColorReg. The value of ColorReg[i]
- * will be the hardware color register which corresponds
- * to the ith vdi color index.
- */
-
- reg_to_index(ColorReg, ColorBits, psize);
-
- GetPalette(psize, Palette); /* Get the current palette. */
- GetPalette(psize, OldPalette); /* Save it for restoration. */
- GSPalette = 1;
-
- }
-
- }
-
- if (Gdebug) {
- eprintf1("Color Bits = %ld\n", ColorBits);
- eprintf1("True Color = %ld\n", TrueColor);
- eprintf1("Max RGB = %ld\n", MaxRGB);
- eprintf1("Palette Size = %ld\n", PaletteSize);
- }
-
- /* Window initialization. */
-
- if (window) {
-
- wind_get(0, WF_WORKXYWH,
- &full.g_x, &full.g_y,
- &full.g_w, &full.g_h);
-
- /* Set up the image window. */
-
- imag.handle = wind_create(imag.gadgets + (MultiTOS ? SMALLER : 0),
- full.g_x, full.g_y,
- full.g_w, full.g_h);
-
- if (imag.handle == -1) {
- form_alert(1,
- "[3][Fatal Error !|Window not available.][Abort]");
- gs_exit(-1);
- }
-
- wind_set(imag.handle, WF_NAME, imag.title, imag.title, 0, 0);
-
- wind_set(imag.handle, WF_CURRXYWH, /* CF */
- 5, 25, 100, 60); /* initial window-size !!*/
-
- wind_get(imag.handle, WF_WORKXYWH,
- &imag.canvas.g_x, &imag.canvas.g_y,
- &imag.canvas.g_w, &imag.canvas.g_h);
-
- /* Set up the console window. */
-
- wind_calc(0, cons.win->gadgets, full.g_x, full.g_y,
- (COLUMNS + 4)*cons.wc, (LINES + 1)*cons.hc,
- &cons.win->mframe.g_x, &cons.win->mframe.g_y,
- &cons.win->mframe.g_w, &cons.win->mframe.g_h);
-
- cons.win->handle = wind_create(
- cons.win->gadgets + (MultiTOS ? SMALLER : 0),
- cons.win->mframe.g_x, cons.win->mframe.g_y,
- MIN(cons.win->mframe.g_w, full.g_w),
- MIN(cons.win->mframe.g_h, full.g_h));
-
- if (cons.win->handle == -1) {
- form_alert(1,
- "[3][Fatal Error !|Window not available.][Abort]");
- gs_exit(-1);
- }
-
- wind_set(cons.win->handle, WF_NAME, cons.win->title,
- cons.win->title, 0, 0);
-
- /* Set up the icon window. */
-
- icon.handle = wind_create(icon.gadgets,
- full.g_x, full.g_y,
- full.g_w, full.g_h);
-
- if (icon.handle == -1) {
- form_alert(1,
- "[3][Fatal Error !|Window not available.][Abort]");
- gs_exit(-1);
- }
-
- wind_set(icon.handle, WF_NAME, icon.title, icon.title, 0, 0);
-
-
- #ifdef USE_RSC /* CF */
- {
- char name[255];
-
- (void) strcpy(name, current_dir);
- (void) strcat(name, rscname);
- if (rsrc_load(name))
- {
- rsrc_gaddr(R_TREE, MENUBAR, &menu);
- rsrc_gaddr(R_TREE, ABOUTBOX, &about);
- rsrc_gaddr(R_TREE, ICONBOX, &noghost);
- }
- else
- {
- (void) form_alert(1,
- "[3][Fatal Error !|Can't load resource.][Abort]");
- gs_exit(-1);
- }
- }
- #else
- /* Fix object sizes for current resolution. */
-
- objc_fix(menu);
- objc_fix(about);
- for(i=0; i<2; i++) rsrc_obfix(noghost, i);
- #endif
-
- icon.canvas.g_x = noghost[0].ob_x = full.g_w / 2;
- icon.canvas.g_y = noghost[0].ob_y = full.g_h / 2;
- icon.canvas.g_w = noghost[0].ob_width;
- icon.canvas.g_h = noghost[0].ob_height;
-
- wind_calc(0, icon.gadgets,
- icon.canvas.g_x, icon.canvas.g_y,
- icon.canvas.g_w, icon.canvas.g_h,
- &icon.frame.g_x, &icon.frame.g_y,
- &icon.frame.g_w, &icon.frame.g_h);
-
- icon.frame.g_x = full.g_w - icon.frame.g_w - 5;
- icon.frame.g_y = full.g_y + 5;
-
- wind_calc(1, icon.gadgets,
- icon.frame.g_x, icon.frame.g_y,
- icon.frame.g_w, icon.frame.g_h,
- &icon.canvas.g_x, &icon.canvas.g_y,
- &icon.canvas.g_w, &icon.canvas.g_h);
-
- noghost[0].ob_x = icon.canvas.g_x;
- noghost[0].ob_y = icon.canvas.g_y;
-
- /* Set up the dialog window. */
-
- dial.handle = wind_create(dial.gadgets,
- full.g_x, full.g_y,
- full.g_w, full.g_h);
-
- if (dial.handle == -1) {
- form_alert(1,
- "[3][Fatal Error !|Window not available.][Abort]");
- gs_exit(-1);
- }
-
- wind_set(dial.handle, WF_NAME, dial.title, dial.title, 0, 0);
-
- }
-
- /* Display the menu and open the console window. */
-
- if (window && !cons.win->opened) {
-
- int dummy;
-
- restore_bg();
- graf_mouse(M_OFF, 0L );
-
- menu_bar(menu, 1);
-
- if (MultiTOS) /* CF */
- {
- menu_register(gl_apid, prgname);
- menu_ienable(menu, ICON, 0); /* use iconifier! */
- }
-
- wind_calc(0, cons.win->gadgets, full.g_x, full.g_y,
- (COLUMNS + 4)*cons.wc, (INITLINES + 1)*cons.hc,
- &cons.win->frame.g_x, &cons.win->frame.g_y,
- &cons.win->frame.g_w, &cons.win->frame.g_h);
-
- cons.win->frame.g_x = full.g_x;
- cons.win->frame.g_y = full.g_y;
-
- wind_open(cons.win->handle,
- cons.win->frame.g_x, cons.win->frame.g_y,
- MIN(cons.win->frame.g_w, full.g_w),
- MIN(cons.win->frame.g_h, full.g_h));
- cons.win->opened = 1;
-
- wind_get(cons.win->handle, WF_CURRXYWH,
- &cons.win->oframe.g_x, &cons.win->oframe.g_y,
- &cons.win->oframe.g_w, &cons.win->oframe.g_h);
-
- wind_get(cons.win->handle, WF_WORKXYWH,
- &cons.win->canvas.g_x, &cons.win->canvas.g_y,
- &cons.win->canvas.g_w, &cons.win->canvas.g_h);
-
- cons.edge = cons.win->canvas.g_x;
- cons.top = cons.win->canvas.g_y;
-
- cons.xoff = cons.wc/2;
- cons.yoff = cons.hc/2;
-
- cons.lins = visible_lines();
- cons.cols = visible_cols();
- cons.ldl = cons.fdl + cons.lins - 1;
-
- cons.cx = align(cons.edge + cons.xoff);
- cons.cy = cons.top + cons.yoff;
-
- vst_alignment(VdiHandle, 0, 5, &dummy, &dummy);
-
- clear_win(&cons.win->canvas);
- update_scroll(cons.win->handle);
-
- graf_mouse(BUSY_BEE, 0L);
- graf_mouse(M_ON, 0L);
-
- }
-
- }
-
- void GetPalette(int DefinedColors, int *Palette)
- {
- int ColorIndex;
- int ColorEntry[3];
-
- for (ColorIndex = 0; ColorIndex < DefinedColors; ColorIndex++) {
- vq_color(VdiHandle, ColorIndex, DEFINED_INTENSITY, ColorEntry);
-
- Palette[3*ColorIndex] = ColorEntry[0];
- Palette[3*ColorIndex+1] = ColorEntry[1];
- Palette[3*ColorIndex+2] = ColorEntry[2];
-
- }
- }
-
- void SetPalette(int DefinedColors, int *Palette)
- {
-
- int ColorIndex;
- int ColorEntry[3];
-
- for (ColorIndex = 0; ColorIndex < DefinedColors; ColorIndex++) {
- ColorEntry[0] = Palette[3*ColorIndex];
- ColorEntry[1] = Palette[3*ColorIndex+1];
- ColorEntry[2] = Palette[3*ColorIndex+2];
-
- vs_color(VdiHandle, ColorIndex, ColorEntry);
- }
- }
-
- /* Do platform-dependent cleanup */
-
- void
- gp_exit(int exit_status, int code)
- {
- graf_mouse(ARROW, 0L);
-
- /* Restore the palette and free the allocated memory. */
-
- if (ColorBits > 1 && !TrueColor) {
- int psize = PaletteSize/3;
-
- if (GSPalette) {
- SetPalette(psize, OldPalette);
- GSPalette = 0;
- }
-
- gs_free((char *)Palette, PaletteSize, sizeof(int), "Palette");
- gs_free((char *)OldPalette, PaletteSize, sizeof(int), "OldPalette");
-
- }
-
- /* Free the resources used by the aes. */
-
- if (window) {
- menu_bar(menu, 0);
-
- if (imag.opened) wind_close(imag.handle);
- if (icon.opened) wind_close(icon.handle);
- if (dial.opened) wind_close(dial.handle);
- if (cons.win->opened) wind_close(cons.win->handle);
-
- wind_delete(imag.handle);
- wind_delete(icon.handle);
- wind_delete(dial.handle);
- wind_delete(cons.win->handle);
- }
-
- v_clsvwk(VdiHandle);
-
- #ifdef USE_RSC /* CF */
- rsrc_free();
- #endif
-
- if (appl_exit() == 0) {
- eprintf("stvdi_close: appl_exit() failed!\n");
- exit_status = -1;
- }
-
- }
-
- /* ------ Date and time ------ */
-
- /* Read the current date (in days since Jan. 1, 1980) */
- /* and time (in milliseconds since midnight). */
-
- void
- gp_get_clock(long *pdt)
- { long secs_since_1970, secs_since_1980;
- struct tm *tm, *localtime();
-
- if ( (secs_since_1970 = time(NULL)) == 0 )
- { perror("Ghostscript: gettimeofday failed:");
- exit(-1);
- }
-
- /* secs_since_1970 is #secs since Jan 1, 1970 */
-
- /* subtract off number of seconds in 10 years */
- /* leap seconds are not accounted for */
- secs_since_1980 = secs_since_1970 - (long)(60 * 60 * 24 * 365.25 * 10);
-
- /* there is no time zone adjustment for the atari st */
-
- /* adjust for daylight savings time - assume dst offset is 1 hour */
- tm = localtime(&(secs_since_1970));
- if ( tm->tm_isdst )
- secs_since_1980 += (60 * 60);
-
- /* divide secs by #secs/day to get #days (integer division truncates) */
- pdt[0] = secs_since_1980 / (60 * 60 * 24);
- /* modulo * 1000 gives number of millisecs since midnight */
- pdt[1] = (secs_since_1980 % (60 * 60 * 24)) * 1000;
- #ifdef DEBUG_CLOCK
- printf("secs_since_1970 = %d usecs_since_1970 = %d pdt[0] = %ld\
- pdt[1] = %ld\n", secs_since_1970, pdt[1], pdt[0], pdt[1]);
- #endif
- }
-
- /* ------ Screen management ------ */
-
- /* Write a string to the console. */
-
- void
- gp_console_puts(const char *str, uint size)
- {
- fwrite(str, 1, size, stdout);
- }
-
- /* Check whether a file is the console. */
-
- int
- gp_file_is_console(FILE *f)
- {
- if (!f) return 0;
- if (fileno(f) >= 0 && fileno(f) <= 2) return 1;
-
- return 0;
- }
-
- /* Make the console current on the screen. */
-
- int
- gp_make_console_current(struct gx_device_s *dev)
- {
- return 0;
- }
-
- /* Make the graphics current on the screen. */
-
- int
- gp_make_graphics_current(struct gx_device_s *dev)
- {
- return 0;
- }
-
- /* ====== Substitute for stdio ====== */
-
- /* This method for redirecting stdio to a window was stolen from the
- * Microsoft Windows driver.
- */
-
- /* reinitialize stdin/out/err to use windows */
- /* assume stream has already been initialized for the real stdin */
-
- #define win_stdin_buf_size 160
-
- int
- win_std_init(file_device *fdev)
- {
-
- if (window) {
-
- if ( gp_file_is_console(gs_stream_stdin->file) ) {
-
- /* Allocate a real buffer for stdin. */
- /* The size must not exceed the size of the */
- /* lineedit buffer. (This is a hack.) */
-
- static const stream_procs pin = {
- s_std_noavailable, s_std_noseek,
- s_std_read_flush, s_std_close,
- win_std_read_buf, NULL
- };
-
- byte *buf = (byte *)gs_malloc(win_stdin_buf_size, 1,
- "win_stdin_init");
-
- s_std_init(gs_stream_stdin, buf, win_stdin_buf_size,
- &pin, s_mode_read);
-
- gs_stream_stdin->file = NULL;
-
- }
-
- {
- static const stream_procs pout = {
- s_std_noavailable, s_std_noseek,
- s_std_write_flush, s_std_close,
- NULL, win_std_write_buf
- };
-
- if ( gp_file_is_console(gs_stream_stdout->file) ) {
- gs_stream_stdout->procs = pout;
- gs_stream_stdout->file = NULL;
- }
-
- if ( gp_file_is_console(gs_stream_stderr->file) ) {
- gs_stream_stderr->procs = pout;
- gs_stream_stderr->file = NULL;
- }
- }
- }
- }
-
- #define ERASELINE 21 /* ^U */
- #define ERASECHAR1 8 /* ^H */
- #define ERASECHAR2 127 /* DEL */
-
- /* Handle all user input. This contains the main event loop for
- * Atari windows.
- */
-
- private int
- win_std_read_buf(register stream *s)
- {
-
- byte *buf = s->cbuf;
-
- byte *dest = buf - 1;
- byte *limit = dest + s->bsize - 1; /* always leave room for \n */
-
- uint ch;
-
- int ret;
- int psize = PaletteSize/3;
- int event, obj_ind, loop_end=0, menuitem=0, scrollitem=-1;
- int wait_event, button_state, mx, my, mb, mk, key, clicks;
-
- TEXTWIN *cw = &cons;
-
- char *inf = infile, *curd = current_dir, *dspec = dir_spec;
- char *fs = file_sel;
-
- /* Copy the appropriate portion of the image to the screen. */
-
- if (window) {
- wait_event = MU_MESAG | MU_KEYBD | MU_BUTTON;
- button_state = 1;
- }
-
- while (!loop_end && window) {
-
- graf_mouse(ARROW, 0L);
-
- step_dx = .9 * imag.canvas.g_w;
- step_dy = .9 * imag.canvas.g_h;
-
- if (menuitem) { /* fake menu events for hot keys */
-
- event = MU_MESAG;
- msgbuff[0] = MN_SELECTED;
- msgbuff[3] = -1;
- msgbuff[4] = menuitem;
- menuitem = 0;
-
- }
- else if (scrollitem >= 0) {
-
- event = MU_MESAG;
- msgbuff[0] = WM_ARROWED;
- msgbuff[3] = imag.handle;
- msgbuff[4] = scrollitem;
- scrollitem = -1;
-
- }
- else {
-
- event = evnt_multi(wait_event, 2, 1, button_state,
- 1, mx, my, 1, 1, 0, 0, 0, 0, 0,
- msgbuff, 0L, &mx, &my, &mb, &mk,
- &key, &clicks);
-
- }
-
- if (event & MU_BUTTON) { /* button events */
-
- if ((obj_ind = objc_find(about, OK, 0, mx, my)) >= 0) {
-
- objc_change(about, OK, 0,
- dial.canvas.g_x, dial.canvas.g_y,
- dial.canvas.g_w, dial.canvas.g_h, 1, 1);
-
- wind_close(dial.handle);
-
- objc_change(about, OK, 0,
- dial.canvas.g_x, dial.canvas.g_y,
- dial.canvas.g_w, dial.canvas.g_h, 0, 0);
-
- dial.opened = 0;
-
- }
- }
-
- if (event & MU_KEYBD) { /* keyboard input */
-
- ch = (uint)( key & 255 );
-
- switch (key) {
-
- case 0x1300: /* alt-r */
- menuitem = RUN;
- break;
-
- case 0x3100: /* alt-n */
- menuitem = NEXT;
- break;
-
- case 0x1000: /* alt-q */
- menuitem = QUIT;
- break;
-
- case 0x1700: /* alt-i */
- menuitem = ICON;
- break;
-
- case 0x1400: /* alt-t */
- menuitem = TOGTOP;
- break;
-
- case 0x4800: /* up arrow */
- scrollitem = WA_UPPAGE;
- break;
-
- case 0x5000: /* down arrow */
- scrollitem = WA_DNPAGE;
- break;
-
- case 0x4b00: /* left arrow */
- scrollitem = WA_LFPAGE;
- break;
-
- case 0x4d00: /* right arrow */
- scrollitem = WA_RTPAGE;
- break;
-
- case 0x1c0d: /* return */
-
- /* Close dialog if opened. Otherwise exit
- * the event loop so the interpreter can
- * read the input buffer.
- */
-
- if (dial.opened) {
-
- objc_change(about, OK, 0,
- dial.canvas.g_x, dial.canvas.g_y,
- dial.canvas.g_w, dial.canvas.g_h, 1, 1);
-
- wind_close(dial.handle);
-
- objc_change(about, OK, 0,
- dial.canvas.g_x, dial.canvas.g_y,
- dial.canvas.g_w, dial.canvas.g_h, 0, 0);
-
- dial.opened = 0;
-
- }
- else {
-
- /* If return is pressed after a showpage,
- * send a message to redraw the image window.
- */
-
- int prevline = (cons.ln > 0) ? cons.ln-1 : LINES-1;
-
- if ((sptr = strstr(cons.text[prevline], ">>"))
- != NULL) {
-
- SendMsg[0] = WM_REDRAW;
- SendMsg[3] = imag.handle;
- SendMsg[4] = imag.canvas.g_x;
- SendMsg[5] = imag.canvas.g_y;
- SendMsg[6] = imag.canvas.g_w;
- SendMsg[7] = imag.canvas.g_h;
- appl_write(ApId, 16, SendMsg);
-
- }
-
- *++dest = '\n';
- gemputc(ch);
- s->cptr = buf - 1;
- s->end_status = 0;
- s->endptr = dest;
-
- graf_mouse(BUSY_BEE, 0L);
- loop_end = 1;
-
- }
- break;
-
- default: /* handle the input character. */
-
- switch (ch) {
-
- default: /* put char in the input buffer. */
- if ( dest == limit ) {
- ; /* MessageBeep(-1); */
- }
- else {
- *++dest = ch;
- gemputc(ch);
- }
- break;
-
- case ERASELINE:
- clear_line(dest - buf + 1);
- dest = buf - 1;
- break;
-
- case ERASECHAR1:
- case ERASECHAR2:
- if ( dest >= buf ) {
- gemputc('\b');
- gemputc(' ');
- gemputc('\b');
- dest--;
- }
- break;
-
- }
-
- }
-
- }
-
- if (event & MU_MESAG) { /* message events */
-
- switch (msgbuff[0]) {
-
- case MN_SELECTED:
-
- if (msgbuff[3] != -1) {
- menu_tnormal(menu, msgbuff[3], 1);
- }
-
- switch (msgbuff[4]) {
-
- case ABOUT:
-
- if (!dial.opened) {
-
- form_center(about,
- &dial.canvas.g_x, &dial.canvas.g_y,
- &dial.canvas.g_w, &dial.canvas.g_h);
-
- wind_calc(0, dial.gadgets,
- dial.canvas.g_x, dial.canvas.g_y,
- dial.canvas.g_w, dial.canvas.g_h,
- &dial.frame.g_x, &dial.frame.g_y,
- &dial.frame.g_w, &dial.frame.g_h);
-
- wind_open(dial.handle,
- dial.frame.g_x, dial.frame.g_y,
- dial.frame.g_w, dial.frame.g_h);
-
- dial.opened = 1;
- }
-
- break;
-
- case RUN:
-
- {
-
- /* If return was not pressed after a showpage,
- * then enter a return and send a message to
- * redraw the image window and run a new program
- * the next time through the event loop.
- */
-
- int prevline = (cons.ln > 0) ? cons.ln-1 : LINES-1;
-
- if ((sptr = strstr(cons.text[prevline], ">>"))
- != NULL) {
-
- *++dest = '\n';
- gemputc('\n');
- graf_mouse(BUSY_BEE, 0L);
- loop_end = 1;
-
- SendMsg[0] = WM_REDRAW;
- SendMsg[3] = imag.handle;
- SendMsg[4] = imag.canvas.g_x;
- SendMsg[5] = imag.canvas.g_y;
- SendMsg[6] = imag.canvas.g_w;
- SendMsg[7] = imag.canvas.g_h;
- appl_write(ApId, 16, SendMsg);
-
- SendMsg[0] = MN_SELECTED;
- SendMsg[3] = -1;
- SendMsg[4] = RUN;
- appl_write(ApId, 16, SendMsg);
-
- break;
- }
-
- sprintf(dir_spec, "%s%s", current_dir, "*.PS");
-
- /* If a single input file has been specified,
- * make it the default selection. If more than
- * one input file exists, or no input is selected,
- * use no default.
- */
-
- if (strlen(infile)) {
- strcpy(file_sel, infile);
- }
- else {
- strcpy(file_sel, "");
- }
-
- ret = fsel_input(dir_spec, file_sel, &ExitButton);
-
- if (ExitButton && strlen(file_sel)) {
-
- sptr = strrchr(dir_spec, '\\');
- *++sptr = '\0';
-
- strcpy(current_dir, dir_spec);
- strcpy(infile, file_sel);
-
- sprintf(command, "(%s%s) run\n",
- dir_spec, file_sel);
-
- /* change back slashes to forward */
-
- while ((sptr = strchr(command, '\\')) != NULL) {
- *sptr = '/';
- }
-
- for (sptr = command; *sptr; sptr++) {
- *++dest = *sptr;
- }
-
- s->cptr = buf - 1;
- s->end_status = 0;
- s->endptr = dest;
-
- /* Send a message to output the command after
- * all pending events have been dispatched.
- */
-
- SendMsg[0] = COMMAND;
- appl_write(ApId, 16, SendMsg);
-
- }
- }
-
- break;
-
- case NEXT:
- if (imag.opened) {
- wind_get(imag.handle, WF_CURRXYWH,
- &imag.oframe.g_x, &imag.oframe.g_y,
- &imag.oframe.g_w, &imag.oframe.g_h);
- }
-
- if (icon.opened) {
- wind_close(icon.handle);
- icon.opened = 0;
- }
-
- if (dial.opened) {
- wind_close(dial.handle);
- dial.opened = 0;
- }
-
- graf_mouse(BUSY_BEE, 0L);
-
- loop_end = 1;
- break;
-
- case QUIT:
- gs_exit(0);
- break;
-
- case ICON:
- if (!MultiTOS) /* CF */
- if (icon.opened) {
-
- wind_get(icon.handle, WF_CURRXYWH,
- &icon.frame.g_x, &icon.frame.g_y,
- &icon.frame.g_w, &icon.frame.g_h);
-
- wind_close(icon.handle);
-
- wind_open(imag.handle,
- imag.oframe.g_x, imag.oframe.g_y,
- imag.oframe.g_w, imag.oframe.g_h);
-
- wind_open(cons.win->handle,
- cons.win->frame.g_x, cons.win->frame.g_y,
- cons.win->frame.g_w, cons.win->frame.g_h);
-
- menu[ICON].ob_spec = UL" Iconify ❎i ";
-
- icon.opened = 0;
- imag.opened = 1;
- cons.win->opened = 1;
-
- }
- else {
-
- if (imag.opened) {
- wind_get(imag.handle, WF_CURRXYWH,
- &imag.oframe.g_x, &imag.oframe.g_y,
- &imag.oframe.g_w, &imag.oframe.g_h);
-
- wind_close(imag.handle);
- imag.opened = 0;
- }
-
- if (cons.win->opened) {
- wind_get(cons.win->handle, WF_CURRXYWH,
- &cons.win->frame.g_x, &cons.win->frame.g_y,
- &cons.win->frame.g_w, &cons.win->frame.g_h);
-
- wind_close(cons.win->handle);
- cons.win->opened = 0;
- }
-
- wind_open(icon.handle,
- icon.frame.g_x, icon.frame.g_y,
- icon.frame.g_w, icon.frame.g_h);
-
- menu[ICON].ob_spec = UL" DeIconify ❎i ";
-
- icon.opened = 1;
- }
- break;
-
- case TOGTOP:
- {
- int topwin, empty;
-
- wind_get(0, WF_TOP, &topwin, &empty,
- &empty, &empty);
-
- if (topwin == cons.win->handle && imag.opened) {
- wind_set(imag.handle, WF_TOP, 0, 0, 0, 0);
- }
- else if (cons.win->opened) {
- wind_set(cons.win->handle, WF_TOP, 0, 0, 0, 0);
- }
- }
-
- break;
-
- }
-
- break;
-
- case WM_REDRAW:
- cursor(OFF);
- gp_win_redraw(DIRT_RECT);
- cursor(ON);
- break;
-
- case WM_ARROWED:
-
- switch (msgbuff[4]) {
-
- case WA_UPLINE: /* up line or top of page */
- if (msgbuff[3] == imag.handle) {
- plot_y = 0;
- }
- else if (msgbuff[3] == cons.win->handle) {
- if (cons.fdl != cons.fl) {
- cons.top += cons.hc;
- cons.cy += cons.hc;
- if (--cons.fdl < 0) cons.fdl += LINES;
- if (--cons.ldl < 0) cons.fdl += LINES;
- }
- }
- break;
-
- case WA_DNLINE: /* down line or bottom of page */
- if (msgbuff[3] == imag.handle) {
- plot_y = (height-1) - imag.canvas.g_h;
- }
- else if (msgbuff[3] == cons.win->handle) {
- if (cons.ldl != cons.ll) {
- cons.top -= cons.hc;
- cons.cy -= cons.hc;
- if (++cons.fdl >= LINES) cons.fdl = 0;
- if (++cons.ldl >= LINES) cons.ldl = 0;
- }
- }
- break;
-
- case WA_LFLINE:
- if (msgbuff[3] == imag.handle) {
- plot_x = 0;
- }
- else if (msgbuff[3] == cons.win->handle) {
- if (cons.fdc > 0) {
- cons.edge += cons.wc;
- cons.cx += cons.wc;
- cons.fdc--;
- }
- }
- break;
-
- case WA_RTLINE:
- if (msgbuff[3] == imag.handle) {
- plot_x = (width-1) - imag.canvas.g_w;
- }
- else if (msgbuff[3] == cons.win->handle) {
- if ((cons.fdc + cons.cols) < CLIMIT) {
- cons.edge -= cons.wc;
- cons.cx -= cons.wc;
- cons.fdc++;
- }
- }
- break;
-
- case WA_UPPAGE:
- if (msgbuff[3] == imag.handle) {
- plot_y = MAX(plot_y - step_dy, 0);
- }
- else if (msgbuff[3] == cons.win->handle) {
- int to_top = cons.fdl - cons.fl;
- to_top = (to_top >= 0) ? to_top : to_top + LINES;
-
- if (to_top >= (cons.lins - 1)) {
- cons.top += (cons.lins - 1) * cons.hc;
- cons.cy += (cons.lins - 1) * cons.hc;
- cons.fdl -= (cons.lins - 1);
- cons.ldl -= (cons.lins - 1);
- if (cons.fdl < 0) cons.fdl += LINES;
- if (cons.ldl < 0) cons.ldl += LINES;
- }
- else {
- ChangeY = cons.win->canvas.g_y - cons.top;
- cons.top += ChangeY;
- cons.cy += ChangeY;
- cons.fdl = cons.fl;
- cons.ldl = cons.fl + cons.lins - 1;
- if (cons.ldl >= LINES) cons.ldl -= LINES;
- }
- }
- break;
-
- case WA_DNPAGE:
- if (msgbuff[3] == imag.handle) {
- plot_y = plot_y + step_dy;
- }
- else if (msgbuff[3] == cons.win->handle) {
- int to_bot = cons.ll - cons.ldl;
- to_bot = (to_bot >= 0) ? to_bot : to_bot + LINES;
-
- if (to_bot >= (cons.lins - 1)) {
- cons.top -= (cons.lins - 1) * cons.hc;
- cons.cy -= (cons.lins - 1) * cons.hc;
- cons.fdl += (cons.lins - 1);
- cons.ldl += (cons.lins - 1);
- if (cons.fdl >= LINES) cons.fdl -= LINES;
- if (cons.ldl >= LINES) cons.ldl -= LINES;
- }
- else {
- ChangeY = cons.win->canvas.g_y
- - (LINES - cons.lins) * cons.hc
- - cons.top;
- cons.top += ChangeY;
- cons.cy += ChangeY;
- cons.fdl = cons.ll - cons.lins + 1;
- cons.ldl = cons.ll;
- if (cons.fdl < 0) cons.fdl += LINES;
- }
- }
- break;
-
- case WA_LFPAGE:
- if (msgbuff[3] == imag.handle) {
- plot_x = MAX(plot_x - step_dx, 0);
- }
- else if (msgbuff[3] == cons.win->handle) {
- if (cons.fdc >= (cons.cols - 1)) {
- cons.edge += (cons.cols - 1) * cons.wc;
- cons.cx += (cons.cols - 1) * cons.wc;
- cons.fdc -= (cons.cols - 1);
- }
- else {
- ChangeX = cons.win->canvas.g_x - cons.edge;
- cons.edge += ChangeX;
- cons.cx += ChangeX;
- cons.fdc = 0;
- }
- }
- break;
-
- case WA_RTPAGE:
- if (msgbuff[3] == imag.handle) {
- plot_x = plot_x + step_dx;
- }
- else if (msgbuff[3] == cons.win->handle) {
- if (cons.fdc <= (CLIMIT - 2*cons.cols + 1)) {
- cons.edge -= (cons.cols - 1) * cons.wc;
- cons.cx -= (cons.cols - 1) * cons.wc;
- cons.fdc += (cons.cols - 1);
- }
- else {
- ChangeX = cons.win->canvas.g_x
- - (CLIMIT - cons.cols) * cons.wc
- - cons.edge;
- cons.edge += ChangeX;
- cons.cx += ChangeX;
- cons.fdc = (CLIMIT - cons.cols);
- }
- }
- break;
-
- }
- update_scroll(msgbuff[3]);
- cursor(OFF);
- gp_win_redraw(FULL_WIN);
- cursor(ON);
- break;
-
- case WM_HSLID:
- if (msgbuff[3] == imag.handle) {
- plot_x = (width - imag.canvas.g_w) * msgbuff[4]/1000;
- }
- else if (msgbuff[3] == cons.win->handle) {
- cons.fdc =
- (CLIMIT - cons.cols) * msgbuff[4]/1000;
- ChangeX = cons.win->canvas.g_x
- - cons.fdc * cons.wc
- - cons.edge;
- cons.edge += ChangeX;
- cons.cx += ChangeX;
-
- }
- update_scroll(msgbuff[3]);
- cursor(OFF);
- gp_win_redraw(FULL_WIN);
- cursor(ON);
- break;
-
- case WM_VSLID:
- if (msgbuff[3] == imag.handle) {
- plot_y = (height - imag.canvas.g_h) * msgbuff[4]/1000;
- }
- else if (msgbuff[3] == cons.win->handle) {
- int OldOffset = cons.fdl - cons.fl;
- int NewOffset = (LINES - cons.lins) * msgbuff[4]/1000;
-
- if (OldOffset < 0) OldOffset += LINES;
-
- cons.fdl = cons.fl + NewOffset;
- if (cons.fdl >= LINES) cons.fdl -= LINES;
-
- cons.ldl = cons.fdl + cons.lins - 1;
- if (cons.ldl >= LINES) cons.ldl -= LINES;
-
- ChangeY = (OldOffset - NewOffset) * cons.hc;
- cons.top += ChangeY;
- cons.cy += ChangeY;
- }
- update_scroll(msgbuff[3]);
- cursor(OFF);
- gp_win_redraw(FULL_WIN);
- cursor(ON);
- break;
-
- case WM_TOPPED:
- wind_set(msgbuff[3], WF_TOP, 0, 0, 0, 0);
- /* intentional fall-through */
-
- case WM_ONTOP:
- if (ColorBits > 1 && !GSPalette && !TrueColor) {
- SetPalette(psize, Palette); /* Restore GS palette. */
- GSPalette = 1;
- }
- break;
-
- case WM_UNTOPPED:
- {
- int topwin, empty;
-
- wind_get(0, WF_TOP, &topwin, &empty,
- &empty, &empty);
-
- if (GSPalette && /* Release palette. */
- topwin != cons.win->handle &&
- topwin != imag.handle &&
- topwin != icon.handle &&
- topwin != dial.handle) {
-
- SetPalette(psize, OldPalette);
- GSPalette = 0;
- }
-
- }
- break;
-
- case WM_CLOSED:
- if (msgbuff[3] == dial.handle) {
- dial.opened = 0;
- wind_close(msgbuff[3]);
- }
- else if (msgbuff[3] == imag.handle) {
- int prevline = (cons.ln > 0) ? cons.ln-1 : LINES-1;
-
- wind_get(imag.handle, WF_CURRXYWH,
- &imag.oframe.g_x, &imag.oframe.g_y,
- &imag.oframe.g_w, &imag.oframe.g_h);
- imag.opened = 0;
-
- wind_close(msgbuff[3]);
-
- /* If a return has not been entered after a
- * showpage, then enter one.
- */
-
- if ((sptr = strstr(cons.text[prevline], ">>"))
- != NULL) {
-
- *++dest = '\n';
- gemputc('\n');
- loop_end = 1;
- }
-
- }
- else {
- gs_exit(0);
- }
-
- break;
-
- case WM_FULLED:
- if (msgbuff[3] == icon.handle) {
- menuitem = ICON;
- }
- else {
-
- WINDOW *win;
-
- if (msgbuff[3] == imag.handle) {
- win = &imag;
- }
- else if (msgbuff[3] == cons.win->handle) {
- win = cons.win;
- }
-
- SendMsg[0] = WM_SIZED;
- SendMsg[3] = win->handle;
-
- wind_get(win->handle, WF_CURRXYWH,
- &win->frame.g_x, &win->frame.g_y,
- &win->frame.g_w, &win->frame.g_h);
-
- if (win->frame.g_x == full.g_x &&
- win->frame.g_y == full.g_y &&
- win->frame.g_w == MIN(win->mframe.g_w, full.g_w) &&
- win->frame.g_h == MIN(win->mframe.g_h, full.g_h)) {
-
- SendMsg[4] = win->oframe.g_x;
- SendMsg[5] = win->oframe.g_y;
- SendMsg[6] = win->oframe.g_w;
- SendMsg[7] = win->oframe.g_h;
-
- }
- else {
- win->oframe.g_x = win->frame.g_x;
- win->oframe.g_y = win->frame.g_y;
- win->oframe.g_w = win->frame.g_w;
- win->oframe.g_h = win->frame.g_h;
-
- SendMsg[4] = full.g_x;
- SendMsg[5] = full.g_y;
- SendMsg[6] = MIN(win->mframe.g_w, full.g_w);
- SendMsg[7] = MIN(win->mframe.g_h, full.g_h);
-
- }
-
- /* Send a message to handle the window resizing. */
-
- appl_write(ApId, 16, SendMsg);
-
- }
-
- break;
-
- case WM_MOVED:
-
- if (msgbuff[3] == icon.handle) {
-
- wind_set(icon.handle, WF_CURRXYWH,
- msgbuff[4], msgbuff[5],
- msgbuff[6], msgbuff[7]);
-
- wind_get(icon.handle, WF_WORKXYWH,
- &icon.canvas.g_x, &icon.canvas.g_y,
- &icon.canvas.g_w, &icon.canvas.g_h);
-
- noghost[0].ob_x = icon.canvas.g_x;
- noghost[0].ob_y = icon.canvas.g_y;
-
- }
- else if (msgbuff[3] == dial.handle) {
-
- wind_set(dial.handle, WF_CURRXYWH,
- msgbuff[4], msgbuff[5],
- msgbuff[6], msgbuff[7]);
-
- ChangeX = msgbuff[4] - dial.frame.g_x;
- ChangeY = msgbuff[5] - dial.frame.g_y;
-
- dial.canvas.g_x += ChangeX;
- dial.canvas.g_y += ChangeY;
-
- about[0].ob_x += ChangeX;
- about[0].ob_y += ChangeY;
-
- wind_get(dial.handle, WF_CURRXYWH,
- &dial.frame.g_x, &dial.frame.g_y,
- &dial.frame.g_w, &dial.frame.g_h);
- }
- else if (msgbuff[3] == imag.handle) {
-
- wind_set(imag.handle, WF_CURRXYWH,
- msgbuff[4], msgbuff[5],
- MIN(imag.mframe.g_w, msgbuff[6]),
- MIN(imag.mframe.g_h, msgbuff[7]));
-
- wind_get(imag.handle, WF_WORKXYWH,
- &imag.canvas.g_x, &imag.canvas.g_y,
- &imag.canvas.g_w, &imag.canvas.g_h);
-
- }
- else {
-
- int oldterm_x = cons.win->canvas.g_x;
- int oldterm_y = cons.win->canvas.g_y;
-
- wind_set(cons.win->handle, WF_CURRXYWH,
- align(msgbuff[4]), msgbuff[5],
- MIN(cons.win->mframe.g_w, msgbuff[6]),
- MIN(cons.win->mframe.g_w, msgbuff[7]));
-
- wind_get(cons.win->handle, WF_WORKXYWH,
- &cons.win->canvas.g_x, &cons.win->canvas.g_y,
- &cons.win->canvas.g_w, &cons.win->canvas.g_h);
-
- ChangeX = cons.win->canvas.g_x - oldterm_x;
- ChangeY = cons.win->canvas.g_y - oldterm_y;
-
- cons.edge += ChangeX;
- cons.top += ChangeY;
-
- cons.cx += ChangeX;
- cons.cy += ChangeY;
-
- }
-
- break;
-
- case WM_SIZED:
-
- if (msgbuff[3] == imag.handle) {
-
- wind_set(imag.handle, WF_CURRXYWH,
- msgbuff[4], msgbuff[5],
- MIN(imag.mframe.g_w, msgbuff[6]),
- MIN(imag.mframe.g_h, msgbuff[7]));
-
- wind_get(imag.handle, WF_WORKXYWH,
- &imag.canvas.g_x, &imag.canvas.g_y,
- &imag.canvas.g_w, &imag.canvas.g_h);
-
- }
- else if (msgbuff[3] == cons.win->handle) {
- int offset;
- int old_x = cons.win->canvas.g_x;
- int old_y = cons.win->canvas.g_y;
- int old_w = cons.win->canvas.g_w;
- int old_h = cons.win->canvas.g_h;
-
- wind_set(cons.win->handle, WF_CURRXYWH,
- msgbuff[4], msgbuff[5],
- MIN(cons.win->mframe.g_w, msgbuff[6]),
- MIN(cons.win->mframe.g_h, msgbuff[7]));
-
- wind_get(cons.win->handle, WF_WORKXYWH,
- &cons.win->canvas.g_x, &cons.win->canvas.g_y,
- &cons.win->canvas.g_w, &cons.win->canvas.g_h);
-
- cons.lins = visible_lines();
- cons.cols = visible_cols();
-
- cons.fdl = cons.ln - cons.lins + 1;
-
- if (cons.fdl > LINES) {
- cons.fdl -= LINES;
- }
- else if (cons.fdl < 0 && !cons.scrolled) {
- cons.fdl = 0;
- }
- else if (cons.fdl < 0 && cons.scrolled) {
- cons.fdl += LINES;
- }
-
- cons.ldl = cons.fdl + cons.lins - 1;
- if (cons.ldl >= LINES) cons.ldl -= LINES;
-
- offset = cons.ln - cons.fdl;
- if (offset < 0) offset += LINES;
- if (offset >= LINES) offset -= LINES;
- cons.cy = cons.win->canvas.g_y
- + cons.yoff + offset * cons.hc;
-
- offset = cons.fdl - cons.fl;
- if (offset < 0) offset += LINES;
- if (offset >= LINES) offset -= LINES;
- cons.top = cons.win->canvas.g_y - offset * cons.hc;
-
- /* Redraw the window if the OS won't. */
-
- if (old_x <= cons.win->canvas.g_x &&
- old_y <= cons.win->canvas.g_y &&
- old_w >= cons.win->canvas.g_w &&
- old_h >= cons.win->canvas.g_h) {
-
- cursor(OFF);
- gp_win_redraw(FULL_WIN);
- cursor(ON);
- }
- }
-
- update_scroll(msgbuff[3]);
- break;
-
- case WM_BOTTOM: /* CF */
- wind_set(msgbuff[3], WF_BOTTOM, 0, 0, 0, 0);
- break;
-
- case WM_ICONIFY:
- case WM_ALLICONIFY: /* CF */
- if (imag.opened)
- {
- wind_get(imag.handle, WF_CURRXYWH,
- &imag.oframe.g_x, &imag.oframe.g_y,
- &imag.oframe.g_w, &imag.oframe.g_h);
- wind_close(imag.handle);
- imag.opened = 0;
- }
-
- if (cons.win->opened)
- {
- wind_get(cons.win->handle, WF_CURRXYWH,
- &cons.win->frame.g_x, &cons.win->frame.g_y,
- &cons.win->frame.g_w, &cons.win->frame.g_h);
- wind_close(cons.win->handle);
- cons.win->opened = 0;
- }
-
- wind_set(icon.handle, WF_ICONIFY,
- msgbuff[4], msgbuff[5], msgbuff[6], msgbuff[7]);
-
- wind_get(icon.handle, WF_CURRXYWH,
- &icon.frame.g_x, &icon.frame.g_y,
- &icon.frame.g_w, &icon.frame.g_h);
-
- wind_open(icon.handle, icon.frame.g_x, icon.frame.g_y,
- icon.frame.g_w, icon.frame.g_h);
-
- wind_get(icon.handle, WF_WORKXYWH,
- &icon.canvas.g_x, &icon.canvas.g_y,
- &icon.canvas.g_w, &icon.canvas.g_h);
-
- noghost[0].ob_x = icon.canvas.g_x;
- noghost[0].ob_y = icon.canvas.g_y;
- icon.opened = 1;
- break;
-
- case WM_UNICONIFY: /* CF */
- wind_set(icon.handle, WF_UNICONIFY,
- icon.frame.g_x, icon.frame.g_y,
- icon.frame.g_w, icon.frame.g_h);
-
- wind_get(icon.handle, WF_CURRXYWH,
- &icon.frame.g_x, &icon.frame.g_y,
- &icon.frame.g_w, &icon.frame.g_h);
- wind_close(icon.handle);
-
- wind_open(imag.handle, imag.oframe.g_x,
- imag.oframe.g_y, imag.oframe.g_w, imag.oframe.g_h);
-
- wind_open(cons.win->handle, cons.win->frame.g_x, cons.win->frame.g_y,
- cons.win->frame.g_w, cons.win->frame.g_h);
-
- icon.opened = 0;
- imag.opened = 1;
- cons.win->opened = 1;
- break;
-
- case COMMAND:
- dprintf1("%s", command);
- graf_mouse(BUSY_BEE, 0L);
- loop_end = 1;
- break;
-
- }
-
- }
-
- }
-
- return 0;
- }
-
- private int
- win_std_write_buf(register stream *s)
- {
-
- char string[COLUMNS+1];
-
- char *ptr = s->cbuf;
-
- int i, j, tempcol;
-
- uint count = s->cptr + 1 - s->cbuf;
-
- cursor(OFF);
- msgbuff[3] = cons.win->handle;
-
- for (i=0, tempcol=0; i<count; i++) {
-
- switch(*ptr) {
-
- case '\r':
- case '\n':
- newline:
-
- string[tempcol] = '\0';
- strcat(cons.text[cons.ln], string);
- next_line();
-
- tempcol = 0;
-
- ptr++;
- break;
-
- case '\t':
-
- for(j=0; j<8; j++) {
- string[tempcol++] = ' ';
- cons.cn++;
- }
-
- ptr++;
- break;
-
- case '\b':
- --tempcol;
- if (--cons.cn < 0) cons.cn = 0;
- else --ptr;
- break;
-
- default:
-
- string[tempcol++] = *ptr;
- if (++cons.cn >= COLUMNS) goto newline;
-
- ptr++;
- break;
-
- }
-
- }
-
- if (tempcol) {
- int dirtw;
-
- string[tempcol] = '\0';
- strcat(cons.text[cons.ln], string);
-
- dirtw = strlen(string) * cons.wc;
- msgbuff[4] = cons.cx;
- msgbuff[5] = cons.cy;
- msgbuff[6] = dirtw;
- msgbuff[7] = cons.hc;
-
- gp_win_redraw(DIRT_RECT);
-
- cons.cx += dirtw;
-
- }
-
- cursor(ON);
- s->cptr = s->cbuf - 1;
- s->endptr = s->cptr + s->bsize;
-
- return 0;
- }
-
- int
- gemputc(uint ch)
- {
- char c[2];
-
- cursor(OFF);
- msgbuff[3] = cons.win->handle;
-
- switch (ch) {
-
- default:
-
- c[0] = ch;
- c[1] = '\0';
-
- strcat(cons.text[cons.ln], c);
-
- msgbuff[4] = cons.cx;
- msgbuff[5] = cons.cy;
- msgbuff[6] = cons.wc;
- msgbuff[7] = cons.hc;
-
- gp_win_redraw(DIRT_RECT);
-
- if (++cons.cn >= COLUMNS) goto newline;
- cons.cx += cons.wc;
- break;
-
- case '\r':
- case '\n':
- newline:
-
- cons.text[cons.ln][cons.cn] = '\0';
-
- if (++cons.ln >= LINES) {
- cons.ln = 0;
- cons.scrolled = 1;
- }
-
- *cons.text[cons.ln] = '\0';
-
- if (cons.scrolled) {
- if (++cons.fl >= LINES) cons.fl = 0;
- if (++cons.fdl >= LINES) cons.fdl = 0;
- if (++cons.ll >= LINES) cons.ll = 0;
- if (++cons.ldl >= LINES) cons.ldl = 0;
- gp_win_redraw(FULL_WIN);
- }
- else if (cons.ln == (cons.ldl + 1)) {
- cons.top -= cons.hc;
- cons.fdl++;
- cons.ldl++;
- gp_win_redraw(FULL_WIN);
- update_scroll(cons.win->handle);
- }
- else {
- cons.cy += cons.hc;
- }
-
- cons.cx = align(cons.edge + cons.xoff);
- cons.cn = 0;
-
- break;
-
- case '\b':
- cons.text[cons.ln][--cons.cn] = '\0';
- cons.cx -= cons.wc;
- break;
-
- }
-
- cursor(ON);
- }
-
- int clear_line(int cnt)
- {
- int x, w;
-
- cursor(OFF);
- msgbuff[3] = cons.win->handle;
-
- if (cnt < 0) {
- *cons.text[cons.ln] = '\0';
- x = cons.win->canvas.g_x;
- w = cons.win->canvas.g_w;
- cons.cx = align(cons.edge + cons.xoff);
- cons.cn = 0;
- }
- else {
- cons.cn = MAX(cons.cn - cnt, 0);
- cons.cx -= cnt * cons.wc;
- cons.text[cons.ln][cons.cn] = '\0';
- x = MAX(cons.cx, cons.win->canvas.g_x);
- w = MIN(cnt * cons.wc, cons.win->canvas.g_w);
- }
-
- msgbuff[4] = x;
- msgbuff[5] = cons.cy;
- msgbuff[6] = w;
- msgbuff[7] = cons.hc;
-
- gp_win_redraw(DIRT_RECT);
-
- cursor(ON);
-
- }
-
- int next_line(void)
- {
-
- if (++cons.ln >= LINES) {
- cons.ln = 0;
- cons.scrolled = 1;
- }
-
- *cons.text[cons.ln] = '\0';
-
- if (cons.scrolled) {
- if (++cons.fl >= LINES) cons.fl = 0;
- if (++cons.fdl >= LINES) cons.fdl = 0;
- if (++cons.ll >= LINES) cons.ll = 0;
- if (++cons.ldl >= LINES) cons.ldl = 0;
- gp_win_redraw(FULL_WIN);
- }
- else if (cons.ln == (cons.ldl + 1)) {
- cons.top -= cons.hc;
- cons.fdl++;
- cons.ldl++;
- gp_win_redraw(FULL_WIN);
- update_scroll(cons.win->handle);
- }
- else {
- msgbuff[4] = cons.cx;
- msgbuff[5] = cons.cy;
- msgbuff[6] = cons.win->canvas.g_x + cons.win->canvas.g_w - cons.cx;
- msgbuff[7] = cons.hc;
- gp_win_redraw(DIRT_RECT);
-
- cons.cy += cons.hc;
- }
-
- cons.cx = align(cons.edge + cons.xoff);
- cons.cn = 0;
-
- }
-
- /* ------ Printer accessing ------ */
-
- /* Open a file or a printing device. A null file name will cause
- * output to be sent to "PRN:". If gp_open_printer returns
- * a NULL, the file will be sent directly to the centronics port.
- * This happens if fname = "CEN:" or if gp_open_scratch_file()
- * fails. Usually, GS wants to interpret a NULL return value as
- * an error, so this is slightly incompatible.
- * "|command" opens an output pipe.
- */
-
- FILE *
- gp_open_printer(char *fname, int binary_mode)
- {
- if (!strcmp(fname, "CEN:")) { /* Direct Centronics printing. */
- return NULL;
- }
- else {
- return
- (strlen(fname) == 0 ?
- gp_open_scratch_file(gp_scratch_file_name_prefix, fname, "wb") :
- fname[0] == '|' ?
- popen(fname + 1, "wb") :
- fopen(fname, "wb"));
- }
- }
-
- /* Close the connection to the printer. */
- void
- gp_close_printer(FILE *pfile, const char *fname)
- { if ( fname[0] == '|' )
- pclose(pfile);
- else
- fclose(pfile);
- }
-
- /* ------ File name syntax ------ */
-
- /* Define the character used for separating file names in a list. */
- char gp_file_name_list_separator = ',';
-
- /* Define the default scratch file name prefix. */
- const char gp_scratch_file_name_prefix[] = "gs_pr.";
-
- /* Define the string to be concatenated with the file mode */
- /* for opening files without end-of-line conversion. */
- const char gp_fmode_binary_suffix[] = "b";
-
- /* Define the file modes for binary reading or writing. */
- const char gp_fmode_rb[] = "rb";
- const char gp_fmode_wb[] = "wb";
-
- /* Define whether case is insignificant in file names. */
- const int gp_file_names_ignore_case = 1;
-
- /* Create and open a scratch file with a given name prefix. */
- /* Write the actual file name at fname. */
-
- #if 0
-
- FILE *
- gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
- {
- strcpy(fname, prefix);
- strcat(fname, "XXX");
- mktemp(fname);
- return fopen(fname, mode);
- }
-
- #endif
-
- FILE *
- gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
- { char *temp;
-
- if ( (temp = getenv("TEMP")) != NULL )
- strcpy(fname, temp);
- else
- strcpy(fname, "");
-
- strcat(fname, prefix);
-
- /* Prevent trailing X's in path from being converted by mktemp. */
- if ( *fname != 0 && fname[strlen(fname) - 1] == 'X' )
- strcat(fname, "-");
-
- strcat(fname, "XXX");
- mktemp(fname);
- return fopen(fname, mode);
- }
-
- /* Answer whether a file name contains a directory/device specification, */
- /* i.e. is absolute (not directory- or device-relative). */
- int
- gp_file_name_is_absolute(const char *fname, uint len)
- { /* A file name is absolute if it contains a drive specification */
- /* (second character is a :) or if it start with / or \. */
- return ( len >= 1 && (*fname == '/' || *fname == '\\' ||
- (len >= 2 && fname[1] == ':')) );
- }
-
- /* Answer the string to be used for combining a directory/device prefix */
- /* with a base file name. The file name is known to not be absolute. */
- const char *
- gp_file_name_concat_string(const char *prefix, uint plen,
- const char *fname, uint len)
- { if ( plen > 0 )
- switch ( prefix[plen - 1] )
- { case ':': case '/': case '\\': return "";
- };
- return "\\";
- }
-
- /* ------ File operations ------ */
-
- /* If the file given by fname exists, fill in its status and return 1; */
- /* otherwise return 0. */
- int
- gp_file_status(const char *fname, file_status *pstatus)
- { struct stat sbuf;
- /* The RS/6000 prototype for stat doesn't include const, */
- /* so we have to explicitly remove the const modifier. */
- if ( stat((char *)fname, &sbuf) < 0 ) return 0;
- pstatus->size_pages = stat_blocks(&sbuf); /* st_blocks is */
- /* missing on some systems, */
- /* see stat_.h */
- pstatus->size_bytes = sbuf.st_size;
- pstatus->time_referenced = sbuf.st_mtime;
- pstatus->time_created = sbuf.st_ctime;
- return 1;
- }
-
- /* ------ File enumeration ------ */
-
- /****** THIS IS NOT SUPPORTED ON UNIX SYSTEMS. ******/
- /* Amazingly enough, there is no standard Unix library routine */
- /* for enumerating the files matching a pattern, */
- /* or even for enumerating (conveniently) the files in a directory. */
-
- struct file_enum_s {
- char *pattern;
- int first_time;
- const gs_memory_procs *mprocs;
- };
-
- /* Initialize an enumeration. NEEDS WORK ON HANDLING * ? \. */
-
- file_enum *
- gp_enumerate_files_init(const char *pat, uint patlen,
- const gs_memory_procs *mprocs)
- { file_enum *pfen = (file_enum *)(*mprocs->alloc)(1, sizeof(file_enum), "gp_enumerate_files");
- char *pattern;
- if ( pfen == 0 ) return 0;
- pattern = (*mprocs->alloc)(patlen + 1, 1,
- "gp_enumerate_files(pattern)");
- if ( pattern == 0 ) return 0;
- memcpy(pattern, pat, patlen);
- pattern[patlen] = 0;
- pfen->pattern = pattern;
- pfen->mprocs = mprocs;
- pfen->first_time = 1;
- return pfen;
- }
-
- /* Enumerate the next file. */
- /* PUNT: JUST RETURN THE PATTERN. */
-
- uint
- gp_enumerate_files_next(file_enum *pfen, char *ptr, uint maxlen)
- { if ( pfen->first_time )
- { char *pattern = pfen->pattern;
- uint len = strlen(pattern);
- pfen->first_time = 0;
- if ( len > maxlen )
- return maxlen + 1;
- strcpy(ptr, pattern);
- return len;
- }
- return -1;
- }
-
- /* Clean up the file enumeration. */
-
- void
- gp_enumerate_files_close(file_enum *pfen)
- { const gs_memory_procs *mprocs = pfen->mprocs;
- (*mprocs->free)(pfen->pattern, strlen(pfen->pattern) + 1, 1,
- "gp_enumerate_files_close(pattern)");
- (*mprocs->free)((char *)pfen, 1, sizeof(file_enum),
- "gp_enumerate_files_close");
- }
-
-
- int
- gp_win_redraw(int flag)
- {
-
- wind_update(BEG_UPDATE); /* lock the screen */
-
- if (msgbuff[3] == icon.handle) {
- (icon.redraw)(flag, noghost, &icon);
- }
- else if (msgbuff[3] == dial.handle) {
- (dial.redraw)(flag, about, &dial);
- }
- else if (msgbuff[3] == cons.win->handle) {
- (cons.win->redraw)(flag, &cons);
- }
- else {
- (imag.redraw)(flag, &imag);
- }
-
- wind_update(END_UPDATE); /* release screen */
-
- }
-
- int
- cons_redraw(int full_win, TEXTWIN *tw)
- {
-
- int i, cnt;
- int x = align(tw->win->canvas.g_x + tw->xoff);
- int fcol = tw->fdc;
- int y, ln, *tpxy = pxy;
-
- GRECT redraw, rect;
-
- graf_mouse(M_OFF, 0L );
-
- if (full_win) {
- redraw.g_x = tw->win->canvas.g_x;
- redraw.g_y = tw->win->canvas.g_y;
- redraw.g_w = tw->win->canvas.g_w;
- redraw.g_h = tw->win->canvas.g_h;
- }
- else {
- redraw.g_x = msgbuff[4];
- redraw.g_y = msgbuff[5];
- redraw.g_w = msgbuff[6];
- redraw.g_h = msgbuff[7];
- }
-
- cnt = tw->ln - tw->fdl + 1;
- cnt = (cnt > 0) ? cnt : cnt + LINES;
- cnt = MIN(cnt, tw->lins);
-
- wind_get(tw->win->handle, WF_FIRSTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
-
- while (rect.g_w && rect.g_h) {
-
- if (intersect(&redraw, &rect)) {
- if (intersect(&tw->win->canvas, &rect)) {
-
- grect_to_array(&rect, pxy);
- vs_clip(VdiHandle, 1, pxy);
-
- clear_win(&rect);
-
- y = tw->win->canvas.g_y + tw->yoff;
-
- for (ln=tw->fdl, i=cnt; i; i--, ln++, y+=cons.hc) {
- if (ln >= LINES) ln -= LINES;
- if (strlen(cons.text[ln]) > fcol)
- v_gtext(VdiHandle, x, y, cons.text[ln]+fcol);
- }
-
- vs_clip(VdiHandle, 0, pxy);
-
- }
- }
-
- wind_get(tw->win->handle, WF_NEXTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
- }
-
- graf_mouse(M_ON, 0L );
-
- }
-
- int
- objw_redraw(int full_win, OBJECT *object, WINDOW *w)
- {
-
- GRECT redraw, rect;
-
- graf_mouse(M_OFF, 0L );
-
- if (full_win) {
- redraw.g_x = w->canvas.g_x;
- redraw.g_y = w->canvas.g_y;
- redraw.g_w = w->canvas.g_w;
- redraw.g_h = w->canvas.g_h;
- }
- else {
- redraw.g_x = msgbuff[4];
- redraw.g_y = msgbuff[5];
- redraw.g_w = msgbuff[6];
- redraw.g_h = msgbuff[7];
- }
-
- wind_get(msgbuff[3], WF_FIRSTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
-
- while (rect.g_w && rect.g_h) {
-
- if (intersect(&redraw, &rect)) {
- if (intersect(&w->canvas, &rect)) {
- objc_draw(object, 0, 1,
- rect.g_x, rect.g_y,
- rect.g_w, rect.g_h);
- }
- }
-
- wind_get(msgbuff[3], WF_NEXTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
-
- }
-
- graf_mouse(M_ON, 0L );
-
- }
-
- int
- form_redraw(int full_win, WINDOW *w)
- {
-
- int tpxy[4];
-
- GRECT redraw, rect;
-
- graf_mouse(M_OFF, 0L );
-
- if (full_win) {
- redraw.g_x = w->canvas.g_x;
- redraw.g_y = w->canvas.g_y;
- redraw.g_w = w->canvas.g_w;
- redraw.g_h = w->canvas.g_h;
- }
- else {
- redraw.g_x = msgbuff[4];
- redraw.g_y = msgbuff[5];
- redraw.g_w = msgbuff[6];
- redraw.g_h = msgbuff[7];
- }
-
- if (plot_x >= width - w->canvas.g_w)
- plot_x = (width - 1) - w->canvas.g_w;
- if (plot_x < 0) plot_x = 0;
-
- if (plot_y >= height - w->canvas.g_h)
- plot_y = (height - 1) - w->canvas.g_h;
- if (plot_y < 0) plot_y = 0;
-
- wind_get(msgbuff[3], WF_FIRSTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
-
- while (rect.g_w && rect.g_h) {
- if (intersect(&redraw, &rect)) {
- if (intersect(&w->canvas, &rect)) {
-
- pxy[0] = plot_x + (rect.g_x - w->canvas.g_x);
- pxy[1] = plot_y + (rect.g_y - w->canvas.g_y);
- pxy[2] = pxy[0] + rect.g_w - 1;
- pxy[3] = pxy[1] + rect.g_h - 1;
-
- grect_to_array(&rect, &pxy[4]);
-
- vs_clip(VdiHandle, 1, &pxy[4]);
- vro_cpyfm(VdiHandle, 3, pxy, &image, &screen);
- vs_clip(VdiHandle, 0, &pxy[4]);
-
- }
- }
-
- wind_get(w->handle, WF_NEXTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
- }
-
- graf_mouse(M_ON, 0L );
-
- }
-
- int align(int x)
- {
- return ((x & 0xfffffff0) + ((x & 0xf) ? 0x10 : 0));
- /* return ((x & 0xfffffff8) + ((x & 0x07) ? 0x08 : 0)); */
- }
-
- int visible_lines(void)
- {
- return ((cons.win->canvas.g_h - cons.yoff) / cons.hc);
- }
-
- int visible_cols(void)
- {
- return ((cons.win->canvas.g_w - align(cons.xoff)) / cons.wc);
- }
-
- int cursor(int state)
- {
- int xy[4], txy[4];
- GRECT rect;
-
- if ((state == OFF && cons.cstate == ON) ||
- (state == ON && cons.cstate == OFF)) {
-
- vsf_interior(VdiHandle, 1); /* set fill mode to solid */
- vswr_mode(VdiHandle, 3); /* set write mode to XOR */
-
- xy[0] = cons.cx;
- xy[1] = cons.cy;
- xy[2] = xy[0] + cons.wc - 1;
- xy[3] = xy[1] + cons.hc - 1;
-
- wind_get(cons.win->handle, WF_FIRSTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
-
- while (rect.g_w && rect.g_h) {
-
- if (intersect(&cons.win->canvas, &rect)) {
-
- grect_to_array(&rect, txy);
- vs_clip(VdiHandle, 1, txy);
-
- vr_recfl(VdiHandle, xy); /* draw the cursor */
-
- vs_clip(VdiHandle, 0, txy);
-
- }
-
- wind_get(cons.win->handle, WF_NEXTXYWH,
- &rect.g_x, &rect.g_y,
- &rect.g_w, &rect.g_h);
-
- }
-
- vs_clip(VdiHandle, 0, xy);
- vswr_mode(VdiHandle, 1); /* restore replace mode */
- cons.cstate = !cons.cstate; /* toggle cursor state */
-
- }
- }
-
- int update_scroll(int handle)
- {
-
- int hslide_pos, hslide_siz, vslide_pos, vslide_siz;
-
- if (handle == imag.handle) {
-
- if (width != imag.canvas.g_w) {
- hslide_pos = 1000 * plot_x/(width - imag.canvas.g_w);
- }
- else {
- hslide_pos = 0;
- }
-
- if (height != imag.canvas.g_h) {
- vslide_pos = 1000 * plot_y/(height - imag.canvas.g_h);
- }
- else {
- vslide_pos = 0;
- }
-
- hslide_siz = 1000 * imag.canvas.g_w/width;
- vslide_siz = 1000 * imag.canvas.g_h/height;
-
-
- }
- else if (handle == cons.win->handle) {
- int offset = cons.fdl - cons.fl;
-
- if (offset < 0) offset += LINES;
-
- if (cons.cols != CLIMIT) {
- hslide_pos = 1000 * cons.fdc/(CLIMIT - cons.cols);
- }
- else {
- hslide_pos = 0;
- }
-
- if (cons.lins < LINES) {
- vslide_pos = 1000 * offset/(LINES - cons.lins);
- }
- else {
- vslide_pos = 0;
- }
-
- hslide_siz = 1000 * cons.cols/CLIMIT;
- vslide_siz = 1000 * cons.lins/LINES;
-
- }
-
- wind_set(handle, WF_HSLIDE, hslide_pos);
- wind_set(handle, WF_VSLIDE, vslide_pos);
- wind_set(handle, WF_HSLSIZE, hslide_siz);
- wind_set(handle, WF_VSLSIZE, vslide_siz);
-
- }
-
-
- int intersect(GRECT *rec1, GRECT *rec2)
- {
- GRECT temp;
-
- temp.g_x = MAX(rec1->g_x, rec2->g_x);
- temp.g_y = MAX(rec1->g_y, rec2->g_y);
- temp.g_w = MIN(rec1->g_x + rec1->g_w, rec2->g_x + rec2->g_w);
- temp.g_h = MIN(rec1->g_y + rec1->g_h, rec2->g_y + rec2->g_h);
-
- rec2->g_x = temp.g_x;
- rec2->g_y = temp.g_y;
- rec2->g_w = temp.g_w - temp.g_x;
- rec2->g_h = temp.g_h - temp.g_y;
-
- return ((temp.g_w > temp.g_x) && (temp.g_h > temp.g_y));
- }
-
- /* Adjust the size of an object for the current screen resolution. */
-
- int objc_fix(OBJECT *object)
- {
- int i=-1;
-
- do {
- i++;
-
- if (object[i].ob_x == 769) object[i].ob_x = full.g_y;
- else if (object[i].ob_x == 513) object[i].ob_x = full.g_y;
- else object[i].ob_x *= cons.wc;
-
- if (object[i].ob_y == 769) object[i].ob_y = full.g_y;
- else if (object[i].ob_y == 513) object[i].ob_y = full.g_y;
- else object[i].ob_y *= cons.hc;
-
- if (object[i].ob_width == 769) object[i].ob_width = full.g_y;
- else if (object[i].ob_width == 513) object[i].ob_width = full.g_y;
- else if (object[i].ob_width == 80) object[i].ob_width = full.g_w;
- else object[i].ob_width *= cons.wc;
-
- if (object[i].ob_height == 769) object[i].ob_height = full.g_y;
- else if (object[i].ob_height == 513) object[i].ob_height = full.g_y;
- else object[i].ob_height *= cons.hc;
-
- }
- while (!(object[i].ob_flags & LASTOB));
-
- }
-
- int clear_win(GRECT *area)
- {
- int xy[4];
-
- xy[0] = area->g_x;
- xy[1] = area->g_y;
- xy[2] = xy[0] + area->g_w - 1;
- xy[3] = xy[1] + area->g_h - 1;
-
- vsf_interior(VdiHandle, 0); /* set fill mode to hollow */
- vr_recfl(VdiHandle, xy); /* clear the window */
- }
-
- /*
- * The remainder of this file contains printer output routines, most of
- * which were contributed by Chris Strunk (some of them were written by me).
- * I made some modifications to the following code (with permission), and
- * may have introduced errors not in the original code.
- * Tim Gallivan, 3/92.
- */
-
- /*
- * This file is Copyright (C) 1990 Christoph Strunk.
- *
- * You are not allowed to copy or modify it.
- */
-
- #define ATARI_TOS (1)
- #define MAKE_VOID (void *)
- #define MAXLEN (256)
-
- void con_flush();
- int OutputIsAscii = 0, RTX_Found = 0;
- long *old_ssp = NULL;
- FILE *OutFile = NULL;
-
- #if PC_DOS || ATARI_TOS
- # define DIRECT 1 /* 1 = Direct Centronics port programming */
- #endif
-
- #if ATARI_TOS || ( PC_DOS && DIRECT )
- static short prn_out ( int );
- #endif
-
- #if ATARI_TOS && LATTICE
- #include <dos.h>
- #endif
-
- #ifdef __GNUC__
- #include <osbind.h>
- #endif
-
- #if PC_DOS && DIRECT
- #include <bios.h>
- #endif
-
- /* output one character */
-
- static int fatal_output_error = 0;
-
- void
- lputc(c)
- int c;
- {
- static short rc;
- static unsigned char global_count = 0; /* other processes every 256 chars */
- void l_stop(), fatal();
-
- if ( fatal_output_error ) return;
-
- global_count += 1;
-
- c &= 255; /* New in 2.9.44: avoid signed char problems */
-
- #if ATARI_TOS || PC_DOS
- if ( ( c == '\n' ) && OutputIsAscii ) {
- lputc ( '\r' ); /* recursion */
- }
- #endif
-
- if ( OutFile ) {
- rc = ( fputc ( c, OutFile ) == EOF );
- } else {
- #if ATARI_TOS || ( PC_DOS && DIRECT )
- rc = prn_out ( c );
- #else
- rc = -1;
- #endif
- }
-
- if ( rc ) {
- if ( OutFile ) {
- perror ( "\nlputc" );
- fprintf ( stderr, "\nOutput error -- %s ?\n",
- "Disk full or printer not ready" );
- fclose ( OutFile );
- OutFile = NULL;
- } else {
- fprintf ( stderr, "\nOutput error -- Printer not ready ?\n" );
- }
- l_stop();
- fatal_output_error = 1;
- fatal ( "Output error" );
- }
-
- #if ATARI_TOS
- if ( RTX_Found && ! global_count ) call_yield(); /* allow other processes */
- #endif
- }
-
- /* output a string */
-
- void
- lputs ( s )
- char *s;
- {
- while ( *s ) lputc ( *s++ );
- }
-
- void
- lflush()
- {
- if ( OutFile ) fflush ( OutFile );
- }
-
- /* start/stop lputc device */
-
- void
- l_start()
- {
- void l_stop(), fatal();
-
- #if ATARI_TOS && DIRECT
- volatile char *gpip = (char *) 0xFFFFFA01L;
- int cnt;
-
- if ( OutFile == NULL && old_ssp == NULL ) {
- old_ssp = (void *) call_super ( NULL );
- cnt = 0;
- /* for ( cnt=0; ( *gpip & 1 ) && ( ++cnt <= 10 ); ) {
- printf("cnt = %d\n", cnt); */
- Ongibit(0x20); /* set strobe bit */
- /* } */
- if ( cnt > 10 ) {
- l_stop();
- puts ( "\n" );
- fatal_output_error = 1;
- fatal ( "Printer not ready" );
- }
- }
- #endif
- #if ATARI_TOS && ! DIRECT
- int cnt;
-
- if ( OutFile == NULL && old_ssp == NULL ) {
- old_ssp = (void *) call_super ( NULL );
-
- for ( cnt=0; ( ! prt_ready(0) ) && ( ++cnt <= 10 ); ) {
- Ongibit(0x20); /* set strobe bit */
- }
- if ( cnt > 10 ) {
- l_stop();
- puts ( "\n" );
- fatal_output_error = 1;
- fatal ( "Printer not ready" );
- }
- }
- #endif
- #if PC_DOS && DIRECT
- if ( OutFile == NULL && ( biosprint ( 2, 0, BiosChannel ) & 0x29 ) ) {
- l_stop();
- puts ( "\n" );
- fatal_output_error = 1;
- fatal ( "Printer not ready" );
- }
- #endif
- }
-
- void l_stop()
- {
- lflush();
- #if ATARI_TOS
- if ( old_ssp != NULL ) {
- MAKE_VOID call_super ( old_ssp );
- old_ssp = NULL;
- }
- #endif
- }
-
- #if ATARI_TOS && DIRECT
-
- extern void int_off __PROTO( ( void ) );
-
- /* int_off: ori.w #$0700,sr
- * ret
- */
-
- extern void int_on __PROTO( ( void ) );
-
- /* int_on: andi.w #$F8FF,sr
- * ret
- */
-
- static short prn_out ( c )
- int c;
- {
- volatile unsigned long *hz_200;
- register unsigned long end_time;
- volatile char *gpip = (char *) 0xFFFFFA01L;
- register char g;
-
- #if OLD
- unsigned char loop_count = 0;
- #endif
-
- if ( old_ssp == NULL ) l_start();
-
- hz_200 = (unsigned long *) 0x04BAL;
- #if OLD
- end_time = *hz_200 + 200; /* check once per second */
- #else
- end_time = *hz_200 + 2; /* check 100 times per second */
- #endif
-
- while ( *gpip & 1 ) { /* wait */
- #if OLD
- /* Printer 1 sec. or more not ready ? */
- if ( ( end_time < *hz_200 ) ||
- ( ( ( ++loop_count & 7 ) == 0 ) && ( BatchMode || RTX_Found ) ) ) {
- con_flush(); /* allow Control_C, other Processes etc. */
- end_time = *hz_200 + 2; /* check 100 times per second */
- }
- #else
- if ( end_time <= *hz_200 ) {
- con_flush(); /* allow Control_C, other Processes etc. */
- end_time = *hz_200 + 1; /* check 200 times per second */
- }
- #endif
- }
-
- int_off(); /* disable interrupts */
-
- gpip = (char *) 0xFFFF8800L; /* load sound chip adress now */
-
- *gpip = 15; /* select port B */
- gpip[2] = (char) c; /* write out char */
- *gpip = 14; /* select port A */
- g = *gpip; /* get old value */
- #if OLD
- g &= 0xDF; /* clear strobe bit */
- #else
- g &= ~0x20; /* clear strobe bit */
- #endif
- gpip[2] = g;
- g |= 0x20; /* set strobe bit */
- g |= 0x20; /* short delay */
- gpip[2] = g;
-
- int_on(); /* enable interrupts */
-
- return 0;
- }
- #endif
-
- #if ATARI_TOS && ! DIRECT
- static short prn_out ( c )
- int c;
- {
- volatile unsigned long *hz_200 = (unsigned long *) 0x04BAL;
- register unsigned long end_time;
-
- if ( old_ssp == NULL ) l_start();
-
- end_time = *hz_200 + 2; /* check 200 times per second */
-
- while ( ! prt_ready(0) ) { /* wait */
- if ( end_time <= *hz_200 ) {
- con_flush(); /* allow Control_C, other Processes etc. */
- end_time = *hz_200 + 1; /* check 200 times per second */
- }
- }
-
- prt_out ( 0, c );
-
- return 0;
- }
- #endif
-
- #if PC_DOS && DIRECT
-
- static short prn_out ( c )
- int c;
- {
- while ( biosprint ( 0, c, BiosChannel ) & 0x29 ) {
- /* wait until Ok or Control-C pressed */
- con_flush();
- }
-
- return 0;
- }
-
- #endif
-
- void
- con_flush()
- {
- int chin;
- void fatal();
-
- chin = Crawio(0xFF);
- if ((chin & 0xFF) == 3) fatal("Keyboard Interrupt");
- }
-
- void
- fatal(char *message)
- {
- fprintf(stderr, "%s\n", message);
- l_stop();
- exit(-1);
- }
-
- /* The following routines are generic interfaces to Chris Strunk's
- * fast printing routines. Tim Gallivan 3/92.
- */
-
- int
- csputc(int c, FILE *stream)
- {
- if (gp_file_is_console(stream) && window) { /* console I/O to a window */
- gemputc(c);
- }
- else {
- OutFile = stream;
- l_start();
- lputc(c);
- l_stop();
- }
-
- return c;
- }
-
- int
- csputs(const char *s, FILE *stream)
- {
- if (gp_file_is_console(stream) && window) { /* console I/O to a window */
- gemprintf(stream, s);
- }
- else {
- OutFile = stream;
- l_start();
- lputs(s);
- l_stop();
- }
-
- return 1;
- }
-
- size_t
- cswrite(const void *ptr, size_t size, size_t nobj, FILE *stream)
- {
- int count;
-
- if (stream == NULL) {
- OutFile = stream;
- l_start();
- for (count=0; count < size*nobj; count++) {
- lputc(*(char *)(ptr++)); /* send the data */
- }
- l_stop();
- return count;
- }
- else {
- int ret;
- ret = fwrite(ptr, size, nobj, stream);
- con_flush();
- return ret;
- }
-
- }
-
- #if 0
- int
- csprintf(FILE *stream, char *format, ...)
- {
- va_list args;
- char line[MAXLEN];
-
- va_start(args, format);
-
- if (stream == NULL) {
- OutFile = stream;
- vsprintf(line, format, args);
- l_start();
- lputs(line);
- l_stop();
- va_end(args);
- return 0;
- }
- else {
- vfprintf(stream, format, args);
- va_end(args);
- con_flush();
- return 0;
- }
-
- }
- #endif
-
- int
- gemprintf(FILE *stream, const char *format, ...)
- {
- va_list args;
-
- char c, *lptr, *bptr;
- char buffer[1024], line[COLUMNS+1];
-
- int i, count;
-
- va_start(args, format);
-
- lptr = line;
- bptr = buffer;
-
- if (gp_file_is_console(stream) && window) { /* console I/O to a window */
-
- msgbuff[3] = cons.win->handle;
- cursor(OFF);
-
- count = vsprintf(buffer, format, args);
-
- for (; (c = *bptr) != '\0'; bptr++) {
- switch (c) {
-
- case '\r':
- case '\n':
- newline:
- *lptr = '\0';
- strcat(cons.text[cons.ln], line);
- next_line();
-
- lptr = line;
- break;
-
- default:
- *lptr++ = c;
- if (++cons.cn >= COLUMNS) goto newline;
-
- }
-
- }
-
- if (lptr != line) {
- int dirtw;
-
- *lptr = '\0';
- strcat(cons.text[cons.ln], line);
-
- dirtw = strlen(line) * cons.wc;
- msgbuff[4] = cons.cx;
- msgbuff[5] = cons.cy;
- msgbuff[6] = dirtw;
- msgbuff[7] = cons.hc;
-
- gp_win_redraw(DIRT_RECT);
-
- cons.cx += dirtw;
-
- }
-
- cursor(ON);
-
- }
- else if (stream == NULL) { /* output for the centronics port */
- OutFile = stream;
- count = vsprintf(buffer, format, args);
- l_start();
- lputs(buffer);
- l_stop();
- }
- else { /* print to other streams normally */
- count = vfprintf(stream, format, args);
- con_flush();
- }
-
- va_end(args);
- return count;
-
- }
-
- /* Restore the usual desktop background. */
-
- #undef puts
-
- int restore_bg()
- {
- puts("\033f");
- v_hide_c(VdiHandle);
- form_dial(FMD_FINISH, 0, 0, 8, 16, 0, 0, XRes, YRes);
- v_show_c(VdiHandle, 0);
- }
-
- /*
- #-----------------------------------------------------------------------------#
- #: Simple support routines for LATTICE C 5.04.01 and other C compilers
- #
- #: Lattice C Assembler
- #
- #: The parameter comes on the stack for functions starting with '_'.
- #
- #: void *call_super ( void * ); supervisor mode on/off
- #
- #: Original code by Chris Strunk. Modified for use with gcc in
- #: Ghostscript by Tim Gallivan, 3/92.
- #-----------------------------------------------------------------------------#
- */
- asm("\
-
- .text 0
-
- .globl _int_off
- .globl _int_on
- .globl _call_super
- .globl _call_yield
- .globl _call_nice
- .globl _user_trace
- .globl _prt_ready
- .globl _prt_out
-
- _get_la:
- moveml d2/a2,sp@-
- .byte 0xA0,0x00 | Adresse Line-A-Var nach A0 & D0
- moveml sp@+,d2/a2
- rts
-
- _int_off:
- oriw #0x0700,sr
- rts
-
- _int_on:
- andiw #0xF8FF,sr
- rts
-
- _call_super:
- movel a7@(4),a0
- moveml d2/a2-a3,sp@-
- movel a0,sp@-
- movew #0x20,sp@-
- movel a7,a3 | save current stack pointer
- trap #1
- movel a3,a7 | make bad stack pointer good again !!!!!!!
- addql #6,sp
- movel d0,a0 | return value in both: d0 and a0
- moveml sp@+,d2/a2-a3
- rts
-
- _call_yield:
- moveml d2/a2,sp@-
- movew #0x00ff,sp@- | MiNT Syield() -- TOS illegal (rc -32)
- trap #1
- addql #2,sp
- moveml sp@+,d2/a2
- rts
-
- _call_nice:
- movel a7@(4),d0
- moveml d2/a2,sp@-
- movew d0,sp@-
- movew #0x10A,sp@-
- trap #1
- addql #4,sp
- moveml sp@+,d2/a2
- rts
-
- _user_trace:
- moveml d1-d7/a0-a6,sp@-
- moveql #0,d0
- movel 0x3F0,a1 | TEMPLMON user trace vector
- cmpal #0,a1 | not installed ?
- beqs end_trace
- jsr a1@ | execute it !
- extl d0
-
- end_trace:
- moveml sp@+,d1-d7/a0-a6
- rts
-
- _prt_ready:
- moveml d3/a3/a5,a7@-
- subl a5,a5
- movew d0,a7@-
- movel 0x506,a0
- jsr a0@
- addql #2,a7
- moveml a7@+,d3/a3/a5
- rts
-
- _prt_out:
- moveml d3/a3/a5,a7@-
- subl a5,a5
- movew d1,a7@-
- movew d0,a7@-
- movel 0x50A,a0
- jsr a0@
- addql #4,a7
- moveml a7@+,d3/a3/a5
- rts
-
- ");
-