home *** CD-ROM | disk | FTP | other *** search
- From: richb@sunaus.sun.oz.AU (Rich Burridge)
- Newsgroups: comp.sources.misc
- Subject: v09i051: popi, The Digital Darkroom, Part05/09
- Message-ID: <2785@basser.oz>
- Date: 12 Dec 89 23:47:32 GMT
- Approved: john@cs.su.oz.AU (John Mackin - comp.sources.misc)
-
- Posting-number: Volume 9, Issue 51
- Submitted-by: Rich Burridge <richb@sunaus.sun.oz.AU>
- Archive-name: popi/part05
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # this is part 5 of a multipart archive
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file special.c continued
- #
- CurArch=5
- if test ! -r s2_seq_.tmp
- then echo "Please unpack part 1 first!"
- exit 1; fi
- ( read Scheck
- if test "$Scheck" != $CurArch
- then echo "Please unpack part $Scheck next!"
- exit 1;
- else exit 0; fi
- ) < s2_seq_.tmp || exit 1
- echo "x - Continuing file special.c"
- sed 's/^X//' << 'Funky_Stuff' >> special.c
- X { "write", writeimg },
- X { "genps", genps },
- X { "genepson", genepson },
- X { "list", list },
- X { "display", displayimg },
- X { "debug", debug },
- X { "version", version },
- X { "verbose", verbose },
- X { "truncate", trunc },
- X { "undo", undo },
- X { "help", help },
- X { "free", freeimg },
- X { "logfile", dolog },
- X { (char *) 0, (void (*) P((void)) ) 0 }
- X};
- X
- Xvoid
- Xspecial()
- X{
- X struct SpecialOp *sp;
- X
- X DEBUG((Debug, "special\n"));
- X lex();
- X if (! (lat == NAME || isalpha(lat)))
- X {
- X SPRINTF(ErrBuf, "Expected name of special operation");
- X error(ERR_PARSE);
- X return;
- X }
- X
- X sp = SpecialOps;
- X for (sp = SpecialOps; sp->name && strcmp(text, sp->name) != 0; ++sp)
- X ;
- X
- X if (! sp->name)
- X {
- X SPRINTF(ErrBuf,
- X "Special operation '%s' unrecognised",
- X text);
- X error(ERR_PARSE);
- X return;
- X }
- X
- X DEBUG((Debug, "calling func '%s'\n", sp->name));
- X (*(sp->func))();
- X
- X if (lat != '\n')
- X lex();
- X
- X if (lat != '\n')
- X {
- X SPRINTF(ErrBuf, "Tokens after special command ignored");
- X error(ERR_WARN);
- X }
- X
- X assert(lat == '\n');
- X}
- Funky_Stuff
- echo "File special.c is complete"
- chmod 0444 special.c || echo "restore of special.c fails"
- set `wc -c special.c`;Sum=$1
- if test "$Sum" != "18870"
- then echo original size 18870, current size $Sum;fi
- echo "x - extracting graphics.c (Text)"
- sed 's/^X//' << 'Funky_Stuff' > graphics.c &&
- X
- X/* @(#)graphics.c 1.10 89/12/11
- X *
- X * Independent graphics routines associated with the popi program.
- X *
- X * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- X * This version is based on the code in his Prentice Hall book,
- X * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- X * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- X *
- X * Permission is given to distribute these extensions, as long as these
- X * introductory messages are not removed, and no monies are exchanged.
- X *
- X * No responsibility is taken for any errors or inaccuracies inherent
- X * either to the comments or the code of this program, but if reported
- X * (see README file) then an attempt will be made to fix them.
- X */
- X
- X#include "popi.h"
- X#include "graphics.h"
- X
- X#define RES 8
- X
- Xchar nextline[MAXLINE] ; /* Next input line to be parsed. */
- X
- Xunsigned char *mptr ; /* Pointer to scanline data. */
- X
- Xint errpos = -1 ; /* Character position error occured at. */
- Xint iscolor ; /* Set if this is a color screen. */
- Xint ix = 0 ; /* Initial X position of the icon. */
- Xint iy = 0 ; /* Initial Y position of the icon. */
- Xint nfont_width ; /* Width of normal font characters. */
- Xint ops[MAXOPS] ; /* Rasterop functions. */
- Xint posspec = 0 ; /* Set if -g option is present (for X11) */
- Xint started = 0 ; /* Set if we've drawn the percent dialog box. */
- Xint tptr = 0 ; /* Input buffer pointer. */
- Xint wx = 0 ; /* Initial X position of the open window. */
- Xint wy = 0 ; /* Initial Y position of the open window. */
- X
- Xint thresh[RES][RES] = { /* Array containing threshold values. */
- X { 0, 128, 32, 160, 8, 136, 40, 168, },
- X { 192, 64, 224, 96, 200, 72, 232, 104, },
- X { 48, 176, 16, 144, 56, 184, 24, 152, },
- X { 240, 112, 208, 80, 248, 120, 216, 88, },
- X { 12, 140, 44, 172, 4, 132, 36, 164, },
- X { 204, 76, 236, 108, 196, 68, 228, 100, },
- X { 60, 188, 28, 156, 52, 180, 20, 148, },
- X { 252, 124, 220, 92, 244, 116, 212, 84, },
- X} ;
- X
- Xextern int errno ;
- Xextern char *sys_errlist[] ;
- X
- X
- X/* There are ten exportable routines used by the popi program.
- X *
- X * These are:
- X *
- X * disp_init(argc, argv) - called from main at the start.
- X * disp_finish() - called from main prior to exit.
- X * disp_imgstart() - called prior to drawing an image.
- X * disp_imgend() - called after drawing an image.
- X * disp_putline(line, y) - to draw an image scanline.
- X * disp_getchar() - to get the next character typed.
- X * disp_ungetc(c) - put back the last character typed.
- X * disp_prompt() - display popi prompt and clear input buffer.
- X * disp_error(errtype, pos) - display error message.
- X * disp_percentdone(n) - display percentage value of conversion.
- X */
- X
- X
- Xvoid
- Xdisp_init(argc, argv) /* Called from main at the start. */
- Xint argc ;
- Xchar *argv[] ;
- X{
- X if (init_ws_type()) /* Determine window system type. */
- X {
- X FPRINTF(stderr, "Error initialising window system.\n") ;
- X exit(1) ;
- X }
- X init_fonts() ; /* Open required fonts. */
- X make_items(argc, argv) ; /* Create icon, frame, canvas etc.. */
- X paint_canvas() ; /* Draw dialog boxes. */
- X start_tool() ;
- X}
- X
- X
- Xvoid
- Xdisp_finish() /* Called from main prior to exit. */
- X{
- X cleanup() ;
- X}
- X
- X
- Xvoid
- Xdisp_imgstart() /* Called prior to drawing an image. */
- X{
- X}
- X
- X
- Xvoid
- Xdisp_imgend() /* Called after drawing an image. */
- X{
- X}
- X
- X
- Xvoid
- Xdisp_putline(line, y) /* Draw an image scanline. */
- Xunsigned char *line ;
- Xint y ;
- X{
- X draw_scanline(line, y) ;
- X}
- X
- X
- Xdisp_getchar() /* Get next user typed character. */
- X{
- X char c ;
- X int finished = 0 ;
- X
- X if (tptr >= strlen(nextline))
- X {
- X while (!finished)
- X {
- X get_next_char(&c) ; /* Get next character typed. */
- X if (c == '\0') continue ;
- X if (errpos != -1)
- X {
- X drawarea(BOXX+100+errpos*nfont_width, BOXY+BOXH-9,
- X nfont_width, 4, GCLR) ;
- X drawarea(BOXX+91, BOXY+51, BOXW-102, BOXH-22, GCLR) ;
- X errpos = -1 ;
- X }
- X if (c == BACKSPACE || c == DEL)
- X nextline[strlen(nextline)-1] = '\0' ;
- X else if (c == RETURN || c == LINEFEED)
- X {
- X set_cursor(BUSY_CUR) ; /* We will now get busy! */
- X c = '\n' ;
- X STRNCAT(nextline, &c, 1) ;
- X finished = 1 ;
- X }
- X else if (c >= 32) STRNCAT(nextline, &c, 1) ;
- X drawarea(BOXX+91, BOXY+11, BOXW-102, BOXH-22, GCLR) ;
- X put_text(BOXX, BOXY, BOXW, BOXH, nextline, 1) ;
- X }
- X tptr = 0 ;
- X }
- X return(nextline[tptr++]) ;
- X}
- X
- X
- X/*ARGSUSED*/
- Xvoid
- Xdisp_ungetc(c) /* Put back the last character typed. */
- Xchar c ;
- X{
- X tptr-- ;
- X}
- X
- X
- Xdisp_prompt() /* Display popi prompt and clear input line. */
- X{
- X set_cursor(NORMAL_CUR) ;
- X if (errpos == -1) drawarea(BOXX+91, BOXY+11, BOXW-102, BOXH-22, GCLR) ;
- X STRCPY(nextline, "") ;
- X tptr = 0 ;
- X return 0 ;
- X}
- X
- X
- Xvoid
- Xdisp_error(errtype, pos) /* Display error message. */
- Xint errtype ;
- Xint pos ;
- X{
- X errpos = pos ;
- X if (errtype & ERR_PARSE)
- X drawarea(BOXX+100+errpos*nfont_width, BOXY+BOXH-9,
- X nfont_width, 4, GSET) ;
- X
- X put_text(BOXX, BOXY+40, BOXW, BOXH, ErrBuf, 0) ;
- X
- X/* We assume errno hasn't been reset by the preceding output */
- X
- X if (errtype & ERR_SYS)
- X {
- X sleep(2) ;
- X SPRINTF(ErrBuf, "\t(%s)\n", sys_errlist[errno]) ;
- X drawarea(BOXX+91, BOXY+51, BOXW-102, BOXH-22, GCLR) ;
- X put_text(BOXX, BOXY+40, BOXW, BOXH, ErrBuf, 0) ;
- X }
- X}
- X
- X/* These are other independent graphics routines used by popi. */
- X
- Xdraw_frame(x, y, width, height)
- Xint x, y, width, height ;
- X{
- X drawarea(x, y, width, height, GSET) ;
- X drawarea(x+1, y+1, width-2, height-2, GCLR) ;
- X drawarea(x+3, y+3, width-6, height-6, GSET) ;
- X drawarea(x+5, y+5, width-10, height-10, GCLR) ;
- X}
- X
- X
- X/* Display a text box of given width and height with top left corner at
- X * the given x,y location, displaying a title and the given text value.
- X */
- X
- Xdraw_textbox(x, y, w, h, title, str, showcur)
- Xint x, y, w, h, showcur ;
- Xchar *title, *str ;
- X{
- X draw_frame(x, y, w, h) ;
- X drawtext(x+10, y+h-15, BFONT, title) ;
- X draw_rect(x+90, y+10, x+w-10, y+h-10) ;
- X put_text(x, y, w, h, str, showcur) ;
- X}
- X
- X
- Xdraw_rect(x1, y1, x2, y2)
- Xint x1, y1, x2, y2 ;
- X{
- X drawline(x1, y1, x2, y1) ;
- X drawline(x1, y1, x1, y2) ;
- X drawline(x2, y1, x2, y2) ;
- X drawline(x1, y2, x2, y2) ;
- X}
- X
- X
- Xhalftone(line, y) /* Halftone 8bit scanline image. */
- Xunsigned char *line ;
- Xint y ;
- X{
- X int x ;
- X
- X for (x = 0; x < Xsize; x++)
- X if (line[x] < thresh[y % RES][x % RES])
- X mptr[x / 8] |= (1 << (7 - (x % 8))) ; /* Set pixel black. */
- X else mptr[x / 8] &= ~(1 << (7 - (x % 8))) ; /* Set pixel white. */
- X}
- X
- X
- X/* Paint the contents of the popi canvas. This consists of first clearing
- X * the whole canvas, then drawing a line to distinguish between the image
- X * drawing area and the command feedback area. Two text boxes are then
- X * drawn, one for user input and the other to shown any error messages.
- X */
- X
- Xpaint_canvas()
- X{
- X drawarea(0, 0, TWIDTH, THEIGHT, GCLR) ;
- X drawline(0, 99, TWIDTH, 99) ;
- X draw_textbox(BOXX, BOXY, BOXW, BOXH, "Command:", nextline, 1) ;
- X draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "Error:", "", 0) ;
- X}
- X
- X
- X/* With the screen based window systems, display the character string
- X * str at the given x,y location. The width of the dialog box is given,
- X * so that if the text exceeds the displayable area, it is scrolled to
- X * the left. A soft cursor in the form of a vertical line is shown if
- X * so requested.
- X */
- X
- Xput_text(x, y, w, h, str, showcur)
- Xint x, y, w, h ;
- Xchar *str ;
- X{
- X char dummy[MAXLINE] ;
- X int limit, nochars ;
- X
- X limit = ((w - 100) / nfont_width) - 1 ;
- X nochars = (strlen(str) <= limit) ? strlen(str) : limit ;
- X STRNCPY(dummy, &str[strlen(str) - nochars], nochars) ;
- X
- X dummy[nochars] = '\0' ;
- X drawtext(x+100, y+h-17, NFONT, dummy) ;
- X if (showcur)
- X drawline(x+100+strlen(dummy)*nfont_width, y+15,
- X x+100+strlen(dummy)*nfont_width, y+h-15) ;
- X}
- X
- X
- X/* Show the percentage of the image converted as a graphical slider using
- X * the error dialog box. If the percentage is zero, then we are just starting,
- X * so the box is relabeled (to % done:). If the percentage is 100, then we
- X * are just finishing, and the box is relabel back (to Error:), and cleared.
- X * Otherwise we show an intermediate percentage value.
- X */
- X
- Xvoid
- Xdisp_percentdone(percent)
- Xint percent ;
- X{
- X if (!percent)
- X {
- X if (!started)
- X draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "% done:", "", 0) ;
- X started = 1 ;
- X }
- X else if (percent == 100)
- X {
- X if (started)
- X draw_textbox(BOXX, BOXY+40, BOXW, BOXH, "Error:", "", 0) ;
- X started = 0 ;
- X }
- X else
- X drawarea(BOXX+91, BOXY+51,
- X (int) ((double) (BOXW-102) / 100 * percent), BOXH-20, GSET) ;
- X}
- Funky_Stuff
- chmod 0444 graphics.c || echo "restore of graphics.c fails"
- set `wc -c graphics.c`;Sum=$1
- if test "$Sum" != "9099"
- then echo original size 9099, current size $Sum;fi
- echo "x - extracting lex.c (Text)"
- sed 's/^X//' << 'Funky_Stuff' > lex.c &&
- X/* @(#)lex.c 1.9 89/12/11
- X *
- X * Lexical routines used by the popi program.
- X *
- X * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- X * This version is based on the code in his Prentice Hall book,
- X * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- X * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- X *
- X * Permission is given to distribute these extensions, as long as these
- X * introductory messages are not removed, and no monies are exchanged.
- X *
- X * No responsibility is taken for any errors or inaccuracies inherent
- X * either to the comments or the code of this program, but if reported
- X * (see README file) then an attempt will be made to fix them.
- X */
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <math.h>
- X#include "popi.h"
- X
- X/* prototypes for local functions */
- Xint Getch P((void));
- Xint getnumber P((int));
- Xint getstring P((int));
- Xint follow P((int, int, int));
- X
- Xint CharPos = 0, /* Current character pos on input line */
- X OldPos = 0, /* previous character pos on input line */
- X TokPos = 0; /* position of the beginning of the current token */
- Xchar ErrBuf[256];
- Xdouble lexfract;
- Xdouble hypot();
- X
- Xstatic int
- XGetch()
- X{
- X int c;
- X
- X c = disp_getchar();
- X
- X OldPos = CharPos;
- X
- X if (c == '\t')
- X CharPos = (CharPos - 1) % 8 + 8;
- X else if (c == '\n')
- X CharPos = 0;
- X else
- X ++CharPos;
- X
- X DEBUG((Debug, "Getch() => '%c'\n", c));
- X
- X if (LogStr)
- X PUTC(c, LogStr);
- X
- X return c;
- X}
- X
- X/* Skip to the end of the line */
- Xvoid
- XSkip()
- X{
- X while (lat != '\n' && lat != EOF)
- X lat = Getch();
- X lat = '\n';
- X}
- X
- Xvoid
- Xerror(errtype)
- Xint errtype;
- X{
- X DEBUG((Debug, "error: type %d, pos %d msg '%s'\n", errtype, TokPos, ErrBuf));
- X if (!noerr) /* Already printed a message */
- X return;
- X disp_error(errtype, TokPos);
- X Skip();
- X noerr = FALSE; /* an error has occurred */
- X
- X if (LogStr)
- X FPRINTF(LogStr, "Error: %s\n", ErrBuf);
- X}
- X
- Xstatic int
- Xgetnumber(first)
- Xint first;
- X{
- X int c;
- X
- X lexval = first - '0';
- X lexfract = 0.0;
- X while (isdigit(c = Getch()))
- X lexval = 10 * lexval + c - '0';
- X
- X /* Some of the special routines use floating values */
- X if (c == '.')
- X {
- X double div = 10.0;
- X
- X while (isdigit(c = Getch()))
- X {
- X lexfract += (c - '0') / div;
- X div *= 10.0;
- X }
- X }
- X pushback(c);
- X return VALUE;
- X}
- X
- Xstatic int
- Xgetstring(first)
- Xint first;
- X{
- X int c = first;
- X char *str = text;
- X
- X do
- X {
- X *str++ = (char) c;
- X c = Getch();
- X }
- X while (isalpha(c) || c == '_' || isdigit(c));
- X *str = '\0';
- X pushback(c);
- X
- X if (strcmp(text, "new") == 0) return NEW;
- X else if (strcmp(text, "sin") == 0) return SIN;
- X else if (strcmp(text, "cos") == 0) return COS;
- X else if (strcmp(text, "atan") == 0) return ATAN;
- X else if (strcmp(text, "hypot") == 0) return HYPOT;
- X else if (strcmp(text, "abs") == 0) return ABS;
- X else if (strcmp(text, "log") == 0) return LOG;
- X else if (strcmp(text, "sqrt") == 0) return SQRT;
- X else if (strcmp(text, "rand") == 0) return RAND;
- X
- X for (c = 0; c < nsrc; c++)
- X if (src[c].str && strcmp(src[c].str, text) == 0)
- X {
- X lexval = c - 1;
- X return INAME;
- X }
- X
- X if (strlen(text) > 1)
- X return NAME;
- X return first;
- X}
- X
- Xstatic int
- Xfollow(tok, ifyes, ifno)
- Xint tok, ifyes, ifno;
- X{
- X int c;
- X
- X if ((c = Getch()) == tok)
- X return ifyes;
- X pushback(c);
- X return ifno;
- X}
- X
- X/*
- X * Set the global lookahead token "lat".
- X */
- Xvoid
- Xlex()
- X{
- X DEBUG((Debug, "lex():\n"));
- X
- X do /* ignore white space */
- X lat = Getch();
- X while (lat == ' ' || lat == '\t');
- X
- X TokPos = CharPos;
- X
- X if (isdigit(lat))
- X lat = getnumber(lat);
- X else if (isalpha(lat) || lat == '_')
- X lat = getstring(lat);
- X
- X switch (lat)
- X {
- X case EOF:
- X lat = 'q';
- X break;
- X
- X case '*':
- X lat = follow('*', POW, lat);
- X break;
- X
- X case '>':
- X lat = follow('=', GE, lat);
- X lat = follow('>', RSHIFT, lat);
- X break;
- X
- X case '<':
- X lat = follow('=', LE, lat);
- X lat = follow('<', LSHIFT, lat);
- X break;
- X
- X case '!':
- X lat = follow('=', NE, lat);
- X break;
- X
- X case '=':
- X lat = follow('=', EQ, lat);
- X break;
- X
- X case '|':
- X lat = follow('|', OR, lat);
- X break;
- X
- X case '&':
- X lat = follow('&', AND, lat);
- X break;
- X
- X case 'Z':
- X lat = VALUE;
- X lexval = Zmax;
- X break;
- X
- X case 'Y':
- X lat = VALUE;
- X lexval = Ysize - 1;
- X break;
- X
- X case 'X':
- X lat = VALUE;
- X lexval = Xsize - 1;
- X break;
- X
- X case 'R':
- X lat = VALUE;
- X lexval = (int) hypot(Xsize / 2.0, Ysize / 2.0);
- X break;
- X
- X case 'A':
- X lat = VALUE;
- X lexval = 360;
- X break;
- X
- X case '"':
- X {
- X char *str;
- X
- X str = text;
- X while ((lat = Getch()) != EOF && lat != '\n' && lat != '"')
- X *str++ = (char) lat;
- X *str = '\0';
- X if (lat != '"')
- X {
- X SPRINTF(ErrBuf, "Expected matching '\"'");
- X error(ERR_PARSE);
- X return;
- X }
- X }
- X lat = FNAME;
- X break;
- X
- X case ';': /* comment to end of line */
- X Skip();
- X lat = '\n';
- X break;
- X
- X default:
- X break;
- X }
- X
- X if (Debug)
- X {
- X if (lat < 127 && isprint(lat))
- X DEBUG((Debug, "lex() => '%c' (%d)\n", lat, lat));
- X else
- X DEBUG((Debug, "lex() => (%d)\n", lat));
- X }
- X}
- X
- Xvoid
- Xpushback(c)
- Xint c;
- X{
- X DEBUG((Debug, "pushback('%c')\n", c));
- X disp_ungetc(c);
- X CharPos = OldPos;
- X}
- Funky_Stuff
- chmod 0444 lex.c || echo "restore of lex.c fails"
- set `wc -c lex.c`;Sum=$1
- if test "$Sum" != "5493"
- then echo original size 5493, current size $Sum;fi
- echo "x - extracting sunview.c (Text)"
- sed 's/^X//' << 'Funky_Stuff' > sunview.c &&
- X/*LINTLIBRARY*/
- X
- X/* @(#)sunview.c 1.10 89/12/11
- X *
- X * SunView dependent graphics routines used by popi.
- X * written by Rich Burridge - Sun Microsystems.
- X *
- X * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- X * This version is based on the code in his Prentice Hall book,
- X * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- X * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- X *
- X * Permission is given to distribute these extensions, as long as these
- X * introductory messages are not removed, and no monies are exchanged.
- X *
- X * No responsibility is taken for any errors or inaccuracies inherent
- X * either to the comments or the code of this program, but if reported
- X * (see README file) then an attempt will be made to fix them.
- X */
- X
- X#include "popi.h"
- X#include "graphics.h"
- X#include <suntool/sunview.h>
- X#include <suntool/canvas.h>
- X
- X#define ICON_SET (void) icon_set
- X#define NOTIFY_DISPATCH (void) notify_dispatch
- X#define NOTIFY_DO_DISPATCH (void) notify_do_dispatch
- X#define NOTIFY_INTERPOSE_DESTROY_FUNC (void) notify_interpose_destroy_func
- X#define PR_GETCOLORMAP (void) pr_getcolormap
- X#define PW_PUTCOLORMAP (void) pw_putcolormap
- X#define PW_ROP (void) pw_rop
- X#define PW_SETCMSNAME (void) pw_setcmsname
- X#define PW_TEXT (void) pw_text
- X#define PW_VECTOR (void) pw_vector
- X#define PW_WRITEBACKGROUND (void) pw_writebackground
- X#define WINDOW_DONE (void) window_done
- X#define WINDOW_SET (void) window_set
- X
- X#define BOLD_FONT "/usr/lib/fonts/fixedwidthfonts/screen.b.14"
- X#define NORMAL_FONT "/usr/lib/fonts/fixedwidthfonts/screen.r.14"
- X
- XCanvas canvas ;
- XCursor busy_cursor, main_cursor ;
- XEvent event ;
- XFrame frame ;
- XIcon popi_icon ;
- XNotify_value destroy_proc() ;
- XPixfont *font, *nfont, *bfont ;
- XPixrect *pr ; /* Offscreen image area. */
- XPixwin *cpw ;
- X
- Xshort busy_cursor_array[] = {
- X#include <images/hglass.cursor>
- X} ;
- Xmpr_static(busy_cursor_pr, 16, 16, 1, busy_cursor_array) ;
- X
- Xunsigned short icon_image[] = {
- X#include "popi.icon"
- X} ;
- Xmpr_static(icon_pr, 64, 64, 1, icon_image) ;
- X
- Xint blocking ; /* Set if in event blocking mode. */
- Xint gotevent ; /* Set if we have an event to handle. */
- Xint nonblocking ; /* Set if in event non-blocking mode. */
- Xint oktoshow ; /* Set just before window is displayed. */
- X
- X
- X/*ARGSUSED*/
- Xvoid
- Xcanvas_proc(canvas, e)
- XCanvas canvas ;
- XEvent *e ;
- X{
- X if (!oktoshow) return ;
- X event = *e ;
- X gotevent = 1 ;
- X if (blocking) notify_stop() ;
- X}
- X
- X
- Xcleanup() /* Null routine for the SunView version. */
- X{
- X}
- X
- X
- X/*ARGSUSED*/
- XNotify_value
- Xdestroy_proc(client, status)
- XNotify_client client ;
- XDestroy_status status ;
- X{
- X exit(0) ;
- X}
- X
- X
- Xdraw_scanline(line, y) /* Display image scanline on the screen. */
- Xunsigned char *line ;
- Xint y ;
- X{
- X int i ;
- X
- X mptr = (unsigned char *) ((struct mpr_data *) pr->pr_data)->md_image ;
- X if (iscolor)
- X for (i = 0; i < Xsize; i++) mptr[i] = 255 - line[i] ;
- X else halftone(line, y) ;
- X PW_ROP(cpw, 0, y+100, Xsize, 1, PIX_SRC, pr, 0, 0) ;
- X}
- X
- X
- Xdrawarea(x, y, width, height, op)
- Xint x, y, width, height ;
- Xenum op_type op ;
- X{
- X PW_WRITEBACKGROUND(cpw, x, y, width, height, ops[(int) op]) ;
- X}
- X
- X
- Xdrawline(x1, y1, x2, y2)
- Xint x1, y1, x2, y2 ;
- X{
- X PW_VECTOR(cpw, x1, y1, x2, y2, PIX_SET, 0) ;
- X}
- X
- X
- Xdrawtext(x, y, fontno, str)
- Xenum font_type fontno ;
- Xint x, y ;
- Xchar *str ;
- X{
- X if (fontno == NFONT) font = nfont ;
- X else if (fontno == BFONT) font = bfont ;
- X PW_TEXT(cpw, x, y, PIX_SRC, font, str) ;
- X}
- X
- X
- XPixfont *
- Xget_font(name)
- Xchar *name ;
- X{
- X Pixfont *font ;
- X
- X font = pf_open(name) ;
- X if (font == NULL) font = pf_default() ;
- X if (font == NULL)
- X {
- X perror("couldn't get the default font.") ;
- X exit(1) ;
- X }
- X return font ;
- X}
- X
- X
- Xget_event() /* Get the next SunView event. */
- X{
- X if (!gotevent) notify_start() ; /* This blocks until notify_stop. */
- X gotevent = 0 ;
- X}
- X
- X
- Xget_next_char(c) /* Process events, and return when character typed. */
- Xchar *c ;
- X{
- X for (;;)
- X {
- X get_event() ;
- X if (event_is_ascii(&event)) /* Keyboard character? */
- X {
- X *c = event_id(&event) ;
- X return ;
- X }
- X else window_default_event_proc(canvas, &event, (char *) 0) ;
- X }
- X}
- X
- X
- Xinit_fonts()
- X{
- X bfont = get_font(BOLD_FONT) ;
- X nfont = get_font(NORMAL_FONT) ;
- X nfont_width = nfont->pf_defaultsize.x ;
- X}
- X
- X
- Xinit_ws_type()
- X{
- X if (getenv("WINDOW_PARENT") == NULL)
- X {
- X FPRINTF(stderr,"%s: Not a native SunView window\n", ProgName) ;
- X return -1 ;
- X }
- X ops[(int) GCLR] = PIX_CLR ;
- X ops[(int) GSET] = PIX_SET ;
- X oktoshow = 0 ; /* Kludge to correctly handle repaints. */
- X blocking = 1 ;
- X return 0 ;
- X}
- X
- X
- Xload_colors() /* Create and load popi color map. */
- X{
- X int i ;
- X char cmsname[MAXLINE] ;
- X u_char red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN] ;
- X
- X iscolor = (cpw->pw_pixrect->pr_depth == 8) ? 1 : 0 ;
- X
- X if (iscolor)
- X {
- X for (i = 0; i < CMAPLEN; i++)
- X red[i] = green[i] = blue[i] = 255 - i ;
- X
- X SPRINTF(cmsname, "popi%10ld", getpid()) ;
- X PW_SETCMSNAME(cpw, cmsname) ;
- X PW_PUTCOLORMAP(cpw, 0, CMAPLEN, red, green, blue) ;
- X
- X pr = mem_create(Xsize, 1, 8) ;
- X }
- X else pr = mem_create(Xsize, 1, 1) ;
- X}
- X
- X
- Xmake_items(argc, argv) /* Create icon, frame, canvas etc.. */
- Xint argc ;
- Xchar *argv[] ;
- X{
- X popi_icon = icon_create(ICON_IMAGE, &icon_pr, 0) ;
- X frame = window_create((Window) 0, FRAME,
- X FRAME_ICON, popi_icon,
- X FRAME_SHOW_LABEL, FALSE,
- X FRAME_NO_CONFIRM, TRUE,
- X FRAME_ARGS, argc, argv,
- X 0) ;
- X canvas = window_create(frame, CANVAS,
- X WIN_WIDTH, TWIDTH,
- X WIN_HEIGHT, THEIGHT,
- X WIN_EVENT_PROC, canvas_proc,
- X 0) ;
- X
- X WINDOW_SET(canvas, WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS,
- X WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
- X WIN_UP_EVENTS, 0, 0) ;
- X WINDOW_SET(canvas, WIN_IGNORE_PICK_EVENT, LOC_MOVE, 0) ;
- X cpw = canvas_pixwin(canvas) ;
- X
- X main_cursor = window_get(canvas, WIN_CURSOR) ;
- X busy_cursor = cursor_create(CURSOR_IMAGE, &busy_cursor_pr, 0) ;
- X load_colors() ; /* Load the popi grayscale colormap. */
- X}
- X
- X
- Xset_cursor(type)
- Xenum cur_type type ;
- X{
- X switch (type)
- X {
- X case BUSY_CUR : WINDOW_SET(canvas, WIN_CURSOR, busy_cursor, 0) ;
- X break ;
- X case NORMAL_CUR : WINDOW_SET(canvas, WIN_CURSOR, main_cursor, 0) ;
- X }
- X}
- X
- X
- Xstart_tool()
- X{
- X window_fit(frame) ;
- X NOTIFY_INTERPOSE_DESTROY_FUNC(frame, destroy_proc) ;
- X oktoshow = 1 ;
- X WINDOW_SET(frame, WIN_SHOW, TRUE, 0) ;
- X NOTIFY_DISPATCH() ; /* Make the window appear. */
- X NOTIFY_DO_DISPATCH() ;
- X}
- Funky_Stuff
- chmod 0444 sunview.c || echo "restore of sunview.c fails"
- set `wc -c sunview.c`;Sum=$1
- if test "$Sum" != "7006"
- then echo original size 7006, current size $Sum;fi
- echo "x - extracting x11.c (Text)"
- sed 's/^X//' << 'Funky_Stuff' > x11.c &&
- X/*LINTLIBRARY*/
- X
- X/* @(#)x11.c 1.9 89/12/11
- X *
- X * X11 dependent graphics routines used by popi.
- X * written by Rich Burridge - Sun Microsystems.
- X *
- X * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- X * This version is based on the code in his Prentice Hall book,
- X * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- X * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- X *
- X * Permission is given to distribute these extensions, as long as these
- X * introductory messages are not removed, and no monies are exchanged.
- X *
- X * No responsibility is taken for any errors or inaccuracies inherent
- X * either to the comments or the code of this program, but if reported
- X * (see README file) then an attempt will be made to fix them.
- X */
- X
- X#include "popi.h"
- X#include "graphics.h"
- X#include <X11/Xlib.h>
- X#include <X11/Xutil.h>
- X#include <X11/cursorfont.h>
- X#include <X11/keysym.h>
- X
- X#define BOLD_FONT "helvetica-bold-14"
- X#define DEFFONT "fixed"
- X#define NORMAL_FONT "8x13"
- X
- X#define POPI_BORDER_WIDTH 2
- X
- X#define FRAME_MASK (KeyPressMask | KeyReleaseMask | ExposureMask)
- X
- Xshort icon_image[] = {
- X#include "popi.icon"
- X} ;
- X
- XAtom protocol_atom, kill_atom ;
- XCursor busy_cursor, main_cursor ;
- XDisplay *dpy ;
- XGC gc, pix_gc ;
- XPixmap mpr, popi_icon, load_icon() ;
- XVisual *visual ;
- XWindow frame, frame_icon ;
- XXColor current_col ;
- XXEvent event ;
- XXFontStruct *bfont, *font, *nfont ;
- XXGCValues gc_val ;
- XXSetWindowAttributes attributes ;
- XXSizeHints size ;
- XXVisualInfo vinfo ;
- XXWMHints wm_hints ;
- X
- Xunsigned long gc_mask ;
- Xint screen ;
- Xunsigned int scr_depth ;
- Xunsigned long backgnd, foregnd ;
- Xunsigned long palette[CMAPLEN] ;
- X
- X/* 256-byte table for quickly reversing the bits in an unsigned 8-bit char,
- X * used to convert between MSBFirst and LSBFirst image formats.
- X */
- X
- Xchar revtable[256] = {
- X 0, -128, 64, -64, 32, -96, 96, -32,
- X 16, -112, 80, -48, 48, -80, 112, -16,
- X 8, -120, 72, -56, 40, -88, 104, -24,
- X 24, -104, 88, -40, 56, -72, 120, -8,
- X 4, -124, 68, -60, 36, -92, 100, -28,
- X 20, -108, 84, -44, 52, -76, 116, -12,
- X 12, -116, 76, -52, 44, -84, 108, -20,
- X 28, -100, 92, -36, 60, -68, 124, -4,
- X 2, -126, 66, -62, 34, -94, 98, -30,
- X 18, -110, 82, -46, 50, -78, 114, -14,
- X 10, -118, 74, -54, 42, -86, 106, -22,
- X 26, -102, 90, -38, 58, -70, 122, -6,
- X 6, -122, 70, -58, 38, -90, 102, -26,
- X 22, -106, 86, -42, 54, -74, 118, -10,
- X 14, -114, 78, -50, 46, -82, 110, -18,
- X 30, -98, 94, -34, 62, -66, 126, -2,
- X 1, -127, 65, -63, 33, -95, 97, -31,
- X 17, -111, 81, -47, 49, -79, 113, -15,
- X 9, -119, 73, -55, 41, -87, 105, -23,
- X 25, -103, 89, -39, 57, -71, 121, -7,
- X 5, -123, 69, -59, 37, -91, 101, -27,
- X 21, -107, 85, -43, 53, -75, 117, -11,
- X 13, -115, 77, -51, 45, -83, 109, -19,
- X 29, -99, 93, -35, 61, -67, 125, -3,
- X 3, -125, 67, -61, 35, -93, 99, -29,
- X 19, -109, 83, -45, 51, -77, 115, -13,
- X 11, -117, 75, -53, 43, -85, 107, -21,
- X 27, -101, 91, -37, 59, -69, 123, -5,
- X 7, -121, 71, -57, 39, -89, 103, -25,
- X 23, -105, 87, -41, 55, -73, 119, -9,
- X 15, -113, 79, -49, 47, -81, 111, -17,
- X 31, -97, 95, -33, 63, -65, 127, -1,
- X} ;
- X
- Xcleanup() /* Null routine for the X11 version. */
- X{
- X}
- X
- X
- X/* This routine needs to be dramatically improved. It should be possible
- X * to avoid copying the data to a separate buffer and creating a pixmap,
- X * and send it direct to the popi frame.
- X */
- X
- Xdraw_scanline(line, y) /* Display image scanline on the screen. */
- Xunsigned char *line ;
- Xint y ;
- X{
- X XImage *image ;
- X int i ;
- X
- X if (iscolor)
- X {
- X mptr = (unsigned char *) Emalloc(Xsize) ;
- X for (i = 0; i < Xsize; i++) mptr[i] = palette[255 - line[i]] ;
- X image = XCreateImage(dpy, DefaultVisual(dpy, screen),
- X scr_depth, ZPixmap, 0, mptr, Xsize, 1, 8, Xsize) ;
- X mpr = XCreatePixmap(dpy, RootWindow(dpy, screen),
- X (unsigned) image->width,
- X (unsigned) image->height, scr_depth) ;
- X XPutImage(dpy, mpr, pix_gc, image, 0, 0, 0, 0,
- X (unsigned) image->width, (unsigned) image->height) ;
- X XDestroyImage(image) ;
- X }
- X else
- X {
- X mptr = (unsigned char *) Emalloc((Xsize / 8) + 1) ;
- X halftone(line, y) ;
- X for (i = 0; i < (Xsize / 8) + 1; i++) mptr[i] = revtable[mptr[i]] ;
- X mpr = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), mptr,
- X Xsize, 1, foregnd, backgnd, scr_depth) ; free(mptr) ;
- X }
- X XCopyArea(dpy, mpr, frame, gc, 0, 0, Xsize, 1, 0, y+100) ;
- X XFreePixmap(dpy, mpr) ;
- X}
- X
- X
- Xdrawarea(x, y, width, height, op)
- Xint x, y, width, height ;
- Xenum op_type op ;
- X{
- X gc_val.function = ops[(int) op] ;
- X XChangeGC(dpy, gc, GCFunction, &gc_val) ;
- X XFillRectangle(dpy, frame, gc, x, y,
- X (unsigned int) width, (unsigned int) height) ;
- X XSync(dpy, 0) ;
- X}
- X
- X
- Xdrawline(x1, y1, x2, y2)
- Xint x1, y1, x2, y2 ;
- X{
- X gc_val.foreground = foregnd ;
- X gc_val.function = GXcopy ;
- X XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
- X XDrawLine(dpy, frame, gc, x1, y1, x2, y2) ;
- X}
- X
- X
- Xdrawtext(x, y, fontno, str)
- Xenum font_type fontno ;
- Xint x, y ;
- Xchar *str ;
- X{
- X if (fontno == NFONT) font = nfont ;
- X else if (fontno == BFONT) font = bfont ;
- X gc_val.font = font->fid ;
- X gc_val.function = GXcopy ;
- X XChangeGC(dpy, gc, GCFont | GCFunction, &gc_val) ;
- X XDrawString(dpy, frame, gc, x, y, str, strlen(str)) ;
- X}
- X
- X
- XXFontStruct *
- Xget_font(name)
- Xchar *name ;
- X{
- X XFontStruct *font ;
- X
- X if (!(font = XLoadQueryFont(dpy, name)))
- X if (!(font = XLoadQueryFont(dpy, DEFFONT)))
- X {
- X perror("couldn't get the default font.") ;
- X exit(1) ;
- X }
- X return(font) ;
- X}
- X
- X
- Xget_next_char(c)
- Xchar *c ;
- X{
- X XClientMessageEvent *ev ;
- X XKeyPressedEvent *key_event ;
- X KeySym keysym ;
- X char chs[2] ;
- X
- X for (;;)
- X {
- X if (!XCheckMaskEvent(dpy, ExposureMask, &event))
- X XNextEvent(dpy, &event) ;
- X
- X switch (event.type)
- X {
- X case ClientMessage : /* Catch ICCCM kill from WM. */
- X
- X ev = (XClientMessageEvent *) &event ;
- X if (ev->message_type == protocol_atom &&
- X ev->data.l[0] == kill_atom)
- X exit(0) ;
- X break ;
- X
- X case Expose : process_expose(&event) ;
- X break ;
- X
- X case KeyPress : key_event = (XKeyPressedEvent *) &event ;
- X (void) XLookupString(key_event, chs, 1,
- X &keysym,
- X (XComposeStatus *) NULL) ;
- X if (keysym == XK_Shift_L ||
- X keysym == XK_Shift_R) break ;
- X *c = chs[0] ;
- X return ;
- X }
- X }
- X/*NOTREACHED*/
- X}
- X
- X
- Xinit_fonts()
- X{
- X bfont = get_font(BOLD_FONT) ;
- X nfont = get_font(NORMAL_FONT) ;
- X nfont_width = 8 ;
- X}
- X
- X
- Xinit_ws_type()
- X{
- X if ((dpy = XOpenDisplay(x11_display)) == NULL)
- X {
- X FPRINTF(stderr,"%s: Couldn't open display %s\n", ProgName,
- X (getenv ("DISPLAY") ? getenv("DISPLAY") : x11_display)) ;
- X exit(1) ;
- X }
- X
- X screen = DefaultScreen(dpy) ;
- X
- X if (!geometry)
- X STRCPY(geometry, XGetDefault(dpy, ProgName, "Geometry")) ;
- X
- X foregnd = BlackPixel(dpy, screen) ;
- X backgnd = WhitePixel(dpy, screen) ;
- X scr_depth = DefaultDepth(dpy, screen) ;
- X
- X ops[(int) GCLR] = GXclear ;
- X ops[(int) GSET] = GXset ;
- X return 0 ;
- X}
- X
- X
- X/*ARGSUSED*/
- Xstatic Bool
- Xis_exposed(dpy, ev, window) /* Return True if window is being exposed */
- XDisplay *dpy ;
- XXEvent *ev ;
- Xchar *window ;
- X{
- X if (ev->type == Expose && *((Window *) window) == ev->xkey.window)
- X return True ;
- X return False ;
- X}
- X
- X
- Xload_colors() /* Create and load popi color map. */
- X{
- X u_char red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN] ;
- X int i, numcolors ;
- X
- X iscolor = 0 ;
- X if (DisplayCells(dpy, screen) > 2)
- X {
- X iscolor = 1 ;
- X numcolors = 0 ;
- X for (i = 0; i < CMAPLEN; i++)
- X {
- X current_col.flags = DoRed | DoGreen | DoBlue ;
- X current_col.red = current_col.green =
- X current_col.blue = (unsigned short) ((255 - i) << 8) ;
- X if (XAllocColor(dpy, DefaultColormap(dpy, screen), ¤t_col) == True)
- X palette[numcolors++] = current_col.pixel ;
- X }
- X if (numcolors < 2)
- X {
- X FPRINTF(stderr, "%s: cannot allocate colors.\n", ProgName) ;
- X exit(1) ;
- X }
- X }
- X}
- X
- X
- XPixmap
- Xload_icon(sbuf)
- Xshort sbuf[] ;
- X{
- X char cbuf[512] ;
- X int i ;
- X
- X for (i = 0; i < 256; i++)
- X {
- X cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
- X cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
- X }
- X return(XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), cbuf,
- X 64, 64, foregnd, backgnd, scr_depth)) ;
- X}
- X
- X
- Xmake_items(argc, argv) /* Create icon, frame, canvas etc.. */
- Xint argc ;
- Xchar *argv[] ;
- X{
- X unsigned int h, w ; /* Window dimensions. */
- X int flags ;
- X int x, y ; /* Window position. */
- X
- X load_colors() ;
- X popi_icon = load_icon(icon_image) ;
- X
- X size.flags = PMinSize | PMaxSize | PPosition | PSize ;
- X size.x = 0 ;
- X size.y = 0 ;
- X size.max_width = size.min_width = size.width = TWIDTH ;
- X size.max_height = size.min_height = size.height = THEIGHT ;
- X
- X if (strlen(geometry))
- X {
- X flags = XParseGeometry(geometry, &x, &y, &w, &h) ;
- X if (XValue & flags)
- X {
- X if (XNegative & flags)
- X x = DisplayWidth(dpy, screen) + x - size.width ;
- X size.flags |= USPosition ;
- X size.x = x ;
- X }
- X if (YValue & flags)
- X {
- X if (YNegative & flags)
- X y = DisplayHeight(dpy, screen) + y - size.height ;
- X size.flags |= USPosition ;
- X size.y = y ;
- X }
- X }
- X
- X frame = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
- X size.x, size.y, size.width, size.height,
- X POPI_BORDER_WIDTH, foregnd, backgnd) ;
- X
- X protocol_atom = XInternAtom(dpy, "WM_PROTOCOLS", False) ;
- X kill_atom = XInternAtom(dpy, "WM_DELETE_WINDOW", False) ;
- X
- X XSetStandardProperties(dpy, frame, "popi", NULL, popi_icon,
- X argv, argc, &size) ;
- X
- X wm_hints.icon_x = ix ;
- X wm_hints.icon_y = iy ;
- X wm_hints.input = True ;
- X wm_hints.icon_pixmap = popi_icon ;
- X wm_hints.flags = IconPositionHint | InputHint | IconPixmapHint ;
- X if (iconic)
- X {
- X wm_hints.initial_state = IconicState ;
- X wm_hints.flags |= StateHint ;
- X }
- X XSetWMHints(dpy, frame, &wm_hints) ;
- X
- X gc_mask = GCFont | GCForeground | GCBackground | GCGraphicsExposures ;
- X gc_val.font = nfont->fid ;
- X gc_val.foreground = foregnd ;
- X gc_val.background = backgnd ;
- X gc_val.graphics_exposures = False ;
- X gc = XCreateGC(dpy, RootWindow(dpy, screen), gc_mask, &gc_val) ;
- X XSetFunction(dpy, gc, GXcopy) ;
- X pix_gc = DefaultGC(dpy, screen) ;
- X
- X main_cursor = XCreateFontCursor(dpy, XC_top_left_arrow) ;
- X busy_cursor = XCreateFontCursor(dpy, XC_coffee_mug) ;
- X}
- X
- X
- Xprocess_expose(event)
- XXExposeEvent *event ;
- X{
- X int doframe ;
- X
- X doframe = 0 ;
- X do
- X {
- X if (event->count == 0)
- X if (event->window == frame) doframe++ ;
- X }
- X while (XCheckMaskEvent(dpy, ExposureMask, event)) ;
- X
- X if (doframe) paint_canvas() ;
- X}
- X
- X
- Xset_cursor(type)
- Xenum cur_type type ;
- X{
- X switch (type)
- X {
- X case BUSY_CUR : XDefineCursor(dpy, frame, busy_cursor) ;
- X break ;
- X case NORMAL_CUR : XDefineCursor(dpy, frame, main_cursor) ;
- X }
- X}
- X
- X
- Xstart_tool()
- X{
- X XSelectInput(dpy, frame, FRAME_MASK) ;
- X XMapWindow(dpy, frame) ;
- X}
- Funky_Stuff
- chmod 0444 x11.c || echo "restore of x11.c fails"
- set `wc -c x11.c`;Sum=$1
- if test "$Sum" != "12178"
- then echo original size 12178, current size $Sum;fi
- echo "x - extracting xview.c (Text)"
- sed 's/^X//' << 'Funky_Stuff' > xview.c &&
- X/*LINTLIBRARY*/
- X
- X/* @(#)xview.c 1.8 89/12/11
- X *
- X * XView dependent graphics routines used by popi.
- X * written by Rich Burridge - Sun Microsystems.
- X *
- X * Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
- X * This version is based on the code in his Prentice Hall book,
- X * "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
- X * which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
- X *
- X * Permission is given to distribute these extensions, as long as these
- X * introductory messages are not removed, and no monies are exchanged.
- X *
- X * No responsibility is taken for any errors or inaccuracies inherent
- X * either to the comments or the code of this program, but if reported
- X * (see README file) then an attempt will be made to fix them.
- X */
- X
- X#include "popi.h"
- X#include "graphics.h"
- X#include <xview/xview.h>
- X#include <xview/canvas.h>
- X#include <xview/cms.h>
- X#include <xview/cursor.h>
- X#include <X11/Xlib.h>
- X
- X#define NOTIFY_DISPATCH (void) notify_dispatch
- X#define NOTIFY_INTERPOSE_DESTROY_FUNC (void) notify_interpose_destroy_func
- X#define PW_WRITEBACKGROUND (void) pw_writebackground
- X#define WINDOW_DONE (void) window_done
- X#define XV_SET (void) xv_set
- X
- X#define BOLD_FONT "/usr/lib/fonts/fixedwidthfonts/screen.b.14"
- X#define NORMAL_FONT "/usr/lib/fonts/fixedwidthfonts/screen.r.14"
- X
- Xvoid repaint_canvas() ;
- X
- XCanvas canvas ;
- XCanvas_paint_window cpw ;
- XDisplay *dpy ;
- XEvent event ;
- XFrame frame ;
- XIcon popi_icon ;
- XNotify_value destroy_proc() ;
- XPixfont *bfont, *font, *nfont, *xv_pf_default(), *xv_pf_open() ;
- XPixrect *pr, *xv_mem_create() ; /* Offscreen image area. */
- XXv_cmsdata cms_data ;
- XXv_Cursor busy_cursor, main_cursor ;
- X
- Xunsigned short busy_cursor_array[] = {
- X#include <images/hglass.cursor>
- X} ;
- Xmpr_static(busy_cursor_pr, 16, 16, 1, busy_cursor_array) ;
- X
- Xunsigned short icon_image[] = {
- X#include "popi.icon"
- X} ;
- Xmpr_static(icon_pr, 64, 64, 1, icon_image) ;
- X
- Xint blocking ; /* Set if in event blocking mode. */
- Xint gotevent ; /* Set if we have an event to handle. */
- Xint nonblocking ; /* Set if in event non-blocking mode. */
- Xint oktoshow ; /* Set just before window is displayed. */
- Xint win_depth ; /* Depth in pixels of this display. */
- X
- X
- X/*ARGSUSED*/
- Xvoid
- Xcanvas_proc(canvas, e, arg)
- XCanvas canvas ;
- XEvent *e ;
- Xcaddr_t arg ;
- X{
- X if (!oktoshow) return ;
- X event = *e ;
- X gotevent = 1 ;
- X if (blocking) (void) notify_stop() ;
- X}
- X
- X
- Xcleanup() /* Null routine for the XView version. */
- X{
- X}
- X
- X
- X/*ARGSUSED*/
- XNotify_value
- Xdestroy_proc(client, status)
- XNotify_client client ;
- XDestroy_status status ;
- X{
- X exit(0) ;
- X}
- X
- X
- Xdraw_scanline(line, y) /* Display image scanline on the screen. */
- Xunsigned char *line ;
- Xint y ;
- X{
- X int i ;
- X
- X mptr = (unsigned char *) ((struct mpr_data *) pr->pr_data)->md_image ;
- X if (iscolor)
- X for (i = 0; i < Xsize; i++) mptr[i] = 255 - line[i] ;
- X else halftone(line, y) ;
- X (void) pw_rop(cpw, 0, y+100, Xsize, 1, PIX_SRC, pr, 0, 0) ;
- X}
- X
- X
- Xdrawarea(x, y, width, height, op)
- Xint x, y, width, height ;
- Xenum op_type op ;
- X{
- X PW_WRITEBACKGROUND(cpw, x, y, width, height, ops[(int) op]) ;
- X XSync(dpy, 0) ;
- X}
- X
- X
- Xdrawline(x1, y1, x2, y2)
- Xint x1, y1, x2, y2 ;
- X{
- X (void) pw_vector(cpw, x1, y1, x2, y2, PIX_SET, 0) ;
- X}
- X
- X
- Xdrawtext(x, y, fontno, str)
- Xenum font_type fontno ;
- Xint x, y ;
- Xchar *str ;
- X{
- X if (fontno == NFONT) font = nfont ;
- X else if (fontno == BFONT) font = bfont ;
- X (void) pw_text(cpw, x, y, PIX_SRC, font, str) ;
- X}
- X
- X
- XPixfont *
- Xget_font(name)
- Xchar *name ;
- X{
- X Pixfont *font ;
- X
- X font = xv_pf_open(name) ;
- X if (font == NULL) font = xv_pf_default() ;
- X if (font == NULL)
- X {
- X perror("couldn't get the default font.") ;
- X exit(1) ;
- X }
- X return font ;
- X}
- X
- X
- Xget_event() /* Get the next XView event. */
- X{
- X if (!gotevent)
- X {
- X XSync(dpy, 0) ;
- X notify_start() ; /* This blocks until notify_stop. */
- X }
- X gotevent = 0 ;
- X}
- X
- X
- Xget_next_char(c) /* Process events, and return when character typed. */
- Xchar *c ;
- X{
- X for (;;)
- X {
- X get_event() ;
- X if (event_is_ascii(&event) && event_is_up(&event)) /* Keyboard char? */
- X {
- X *c = event_id(&event) ;
- X return ;
- X }
- X else if (event_id(&event) == WIN_REPAINT) paint_canvas() ;
- X }
- X}
- X
- X
- Xinit_fonts()
- X{
- X bfont = get_font(BOLD_FONT) ;
- X nfont = get_font(NORMAL_FONT) ;
- X nfont_width = nfont->pf_defaultsize.x ;
- X}
- X
- X
- Xinit_ws_type()
- X{
- X ops[(int) GCLR] = PIX_CLR ;
- X ops[(int) GSET] = PIX_SET ;
- X oktoshow = 0 ; /* Kludge to correctly handle repaints. */
- X blocking = 1 ;
- X return 0 ;
- X}
- X
- X
- Xmake_items(argc, argv) /* Create icon, frame, canvas etc.. */
- Xint argc ;
- Xchar *argv[] ;
- X{
- X int i ;
- X char cmsname[MAXLINE] ;
- X u_char red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN] ;
- X
- X xv_init(XV_INIT_ARGS, argc, argv, 0);
- X popi_icon = xv_create(0, ICON,
- X ICON_IMAGE, &icon_pr,
- X 0) ;
- X frame = xv_create(0, FRAME,
- X FRAME_ICON, popi_icon,
- X FRAME_SHOW_LABEL, FALSE,
- X FRAME_NO_CONFIRM, TRUE,
- X XV_HEIGHT, THEIGHT,
- X XV_WIDTH, TWIDTH,
- X 0) ;
- X iscolor = ((win_depth = (int) xv_get(frame, WIN_DEPTH)) > 1) ? 1 : 0 ;
- X
- X pr = xv_mem_create(Xsize, 1, win_depth) ;
- X
- X SPRINTF(cmsname, "popi%10ld", getpid()) ;
- X for (i = 0; i < CMAPLEN; i++)
- X red[i] = green[i] = blue[i] = 255 - i ;
- X
- X cms_data.type = XV_DYNAMIC_CMS ;
- X cms_data.size = 256 ;
- X cms_data.rgb_count = 256 ;
- X cms_data.index = 0 ;
- X cms_data.red = red ;
- X cms_data.green = green ;
- X cms_data.blue = blue ;
- X
- X canvas = xv_create(frame, CANVAS,
- X OPENWIN_AUTO_CLEAR, FALSE,
- X CANVAS_RETAINED, TRUE,
- X XV_WIDTH, TWIDTH,
- X XV_HEIGHT, THEIGHT,
- X CANVAS_PAINTWINDOW_ATTRS,
- X WIN_DYNAMIC_VISUAL, TRUE,
- X WIN_CONSUME_EVENTS,
- X WIN_ASCII_EVENTS,
- X WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
- X 0,
- X WIN_IGNORE_EVENTS,
- X LOC_MOVE, LOC_DRAG,
- X 0,
- X WIN_EVENT_PROC, canvas_proc,
- X 0,
- X 0) ;
- X
- X cpw = canvas_paint_window(canvas) ;
- X XV_SET(/**canvas_pixwin(canvas),**/cpw,
- X WIN_CMS_NAME, cmsname,
- X WIN_CMS_DATA, &cms_data,
- X 0) ;
- X dpy = (Display *) xv_get(cpw, XV_DISPLAY) ;
- X
- X main_cursor = xv_get(canvas, WIN_CURSOR) ;
- X busy_cursor = xv_create(NULL, CURSOR,
- X CURSOR_IMAGE, &busy_cursor_pr,
- X 0) ;
- X}
- X
- X
- Xset_cursor(type)
- Xenum cur_type type ;
- X{
- X switch (type)
- X {
- X case BUSY_CUR : XV_SET(canvas, WIN_CURSOR, busy_cursor, 0) ;
- X break ;
- X case NORMAL_CUR : XV_SET(canvas, WIN_CURSOR, main_cursor, 0) ;
- X }
- X XSync(dpy, 0) ;
- X}
- X
- X
- Xstart_tool()
- X{
- X window_fit(frame) ;
- X NOTIFY_INTERPOSE_DESTROY_FUNC(frame, destroy_proc) ;
- X XV_SET(frame, WIN_SHOW, TRUE, 0) ;
- X oktoshow = 1 ;
- X (void) xv_set(xv_default_server, SERVER_SYNC_AND_PROCESS_EVENTS) ;
- X NOTIFY_DISPATCH() ;
- X}
- Funky_Stuff
- chmod 0444 xview.c || echo "restore of xview.c fails"
- set `wc -c xview.c`;Sum=$1
- if test "$Sum" != "7343"
- then echo original size 7343, current size $Sum;fi
- echo "x - extracting popi.msc (Text)"
- sed 's/^X//' << 'Funky_Stuff' > popi.msc &&
- X#
- X# Program: Popi
- X#
- X# Make file for Microsoft braindamaged make.
- X# In the Quick C environment, select
- X# File/Set Program List
- X# and set to the name of this file (popi.qcl).
- X# From the command line, use "make popi.qcl"
- X# Quick C has fought hard against generating correct code,
- X# but I believe the current version doesn't trigger any of
- X# its many bugs. Do not enable run-time pointer checking or
- X# it will wrongly complain about some valid pointer assignments.
- X# Also, do not enable optimisation as incorrect code will be
- X# generated in a loop inside run.c.
- X#
- X
- XCC = qcl
- X
- X.c.obj:
- X $(CC) -c -W3 -AS $*.c
- X
- Xmain.obj : main.c
- X
- Xexpr.obj : expr.c
- X
- Xio.obj : io.c
- X
- Xlex.obj : lex.c
- X
- Xpolar.obj : polar.c
- X
- Xrun.obj : run.c
- X
- Xspecial.obj : special.c
- X
- Xibmpc.obj : ibmpc.c
- X
- XPopi.exe : expr.obj ibmpc.obj io.obj lex.obj main.obj polar.obj run.obj \
- X special.obj
- X del Popi.lnk
- X echo expr.obj+ >>Popi.lnk
- X echo ibmpc.obj+ >>Popi.lnk
- X echo io.obj+ >>Popi.lnk
- X echo lex.obj+ >>Popi.lnk
- X echo main.obj+ >>Popi.lnk
- X echo polar.obj+ >>Popi.lnk
- X echo run.obj+ >>Popi.lnk
- X echo special.obj >>Popi.lnk
- X echo Popi.exe >>Popi.lnk
- X echo Popi.map >>Popi.lnk
- X link @Popi.lnk /NOI $(LDFLAGS);
- Funky_Stuff
- chmod 0444 popi.msc || echo "restore of popi.msc fails"
- set `wc -c popi.msc`;Sum=$1
- if test "$Sum" != "1163"
- then echo original size 1163, current size $Sum;fi
- echo "x - extracting dmr.Z (Binary)"
- sed 's/^X//' << 'Funky_Stuff' > s2_temp_.tmp &&
- Xbegin 600 dmr.Z
- Funky_Stuff
- echo "End of part 5"
- echo "File dmr.Z is continued in part 6"
- echo "6" > s2_seq_.tmp
- exit 0
-
-