richb@sunaus.sun.oz.AU (Rich Burridge) (12/13/89)
Posting-number: Volume 9, Issue 49 Submitted-by: Rich Burridge <richb@sunaus.sun.oz.AU> Archive-name: popi/part03 ---- Cut Here and unpack ---- #!/bin/sh # this is part 3 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file mgr.c continued # CurArch=3 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 mgr.c" sed 's/^X//' << 'Funky_Stuff' >> mgr.c X m_bitwrite(x, y, width, height) ; X} X X Xdrawline(x1, y1, x2, y2) Xint x1, y1, x2, y2 ; X{ X m_func(B_COPY) ; X m_line(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) m_font(N_FONT) ; X else if (fontno == BFONT) m_font(B_FONT) ; X m_func(B_XOR) ; X if (str[strlen(str)-1] == '\n') str[strlen(str)-1] = '\0' ; X m_stringto(0, x, y+4, str) ; X m_movecursor(2500, 2500) ; X} X X Xget_next_char(c) /* Process events, and return when character typed. */ Xchar *c ; X{ X int chr ; X static struct timeval tval = { 0, 0 } ; X X m_flush() ; X for (;;) X { X readmask = fullmask ; X#ifdef NO_43SELECT X SELECT(32, &readmask, 0, 0, &tval) ; X if (readmask && (1 << mgr_infd)) X#else X SELECT(FD_SETSIZE, &readmask, (fd_set *) 0, (fd_set *) 0, &tval) ; X if (FD_ISSET(mgr_infd, &readmask)) X#endif /* NO_4.3SELECT */ X { X if ((chr = m_getchar()) == EOF) X { X clearerr(m_termin) ; X continue ; X } X switch (chr) X { X case '\032' : X case '\033' : close_frame() ; /* Turn window iconic. */ X break ; X case '\034' : clean(1) ; /* Window destroyed. */ X case '\035' : if (iconic) iconic = 0 ; X case '\036' : reshape(OPEN) ; X case '\037' : paint_canvas() ; /* Repaint popi canvas. */ X break ; X default : *c = chr ; X return ; X } X } X } X} X X Xinit_fonts() X{ X char path[MAXLINE] ; /* Directory path for font files. */ X X#ifdef MGRHOME X STRCPY(path, MGRHOME) ; X#else X STRCPY(path, "/usr/mgr") ; X#endif X X SPRINTF(fontname, "%s/font/%s", path, NORMAL_FONT) ; X m_loadfont(NFONT, fontname) ; X nfont_width = 7 ; X X SPRINTF(fontname, "%s/font/%s", path, BOLD_FONT) ; X m_loadfont(BFONT, fontname) ; X} X X Xinit_ws_type() X{ X m_setup(M_FLUSH) ; /* Setup I/O; turn on flushing. */ X m_push(P_BITMAP | P_MENU | P_EVENT | P_FONT | P_FLAGS | P_POSITION) ; X mgr_infd = fileno(m_termin) ; X mgr_outfd = fileno(m_termout) ; X X SIGNAL(SIGHUP, clean) ; X SIGNAL(SIGINT, clean) ; X SIGNAL(SIGTERM, clean) ; X m_ttyset() ; X m_setraw() ; X m_setmode(M_NOWRAP) ; X m_setmode(M_ABS) ; X m_setmode(ACTIVATE) ; X m_clearmode(M_NOINPUT) ; X m_func(B_COPY) ; X X mptr = (unsigned char *) malloc((unsigned) Xsize) ; X ops[(int) GCLR] = B_CLEAR ; X ops[(int) GSET] = B_SET ; X return 0 ; X} X X Xload_colors() /* Hardwired to a monochrome version. */ X{ X iscolor = 0 ; X} X X Xload_icon(pixrect, ibuf) Xint pixrect ; Xshort ibuf[256] ; X{ X int size ; X X IOCTL(mgr_outfd, TIOCLGET, &local_mode) ; X local_mode |= LLITOUT ; X IOCTL(mgr_outfd, TIOCLSET, &local_mode) ; X X size = ICONHEIGHT * (((64 + 15) &~ 15) >> 3) ; X m_bitldto(ICONWIDTH, ICONHEIGHT, 0, 0, pixrect, size) ; X m_flush() ; X WRITE(mgr_outfd, (char *) ibuf, size) ; X X local_mode &= ~LLITOUT ; X IOCTL(mgr_outfd, TIOCLSET, &local_mode) ; X} X X Xmake_items(argc, argv) /* Create icon, frame, canvas etc.. */ Xint argc ; Xchar *argv[] ; X{ X X#ifdef NO_43SELECT X fullmask = 1 << mgr_infd ; X#else X FD_ZERO(&fullmask) ; X FD_SET(mgr_infd, &fullmask) ; X#endif /* NO_4.3SELECT */ X X m_setevent(BUTTON_2U, "\032") ; /* Middle mouse button released. */ X m_setevent(BUTTON_1U, "\033") ; /* Right mouse button released. */ X m_setevent(DESTROY, "\034") ; /* Window has been destroyed. */ X m_setevent(ACTIVATE, "\035") ; /* Window has been activated. */ X m_setevent(RESHAPE, "\036") ; /* Check for window being reshaped. */ X m_setevent(REDRAW, "\037") ; /* Check for window being redrawn. */ X X m_movecursor(2500, 2500) ; /* Move character cursor offscreen. */ X m_font(N_FONT) ; /* Default is the normal font. */ X load_icon(PR_ICON, icon_image) ; X reshape(OPEN) ; X m_clear() ; /* Clear popi window. */ X load_colors() ; /* Hardwired to monochrome. */ X} X X Xreshape(type) Xint type ; X{ X int x, y, w, h ; /* Position and size of calctool window. */ X X get_size(&x, &y, &w, &h) ; X switch (type) X { X case ICONIC : m_shapewindow(x, y, ICONWIDTH+10, ICONHEIGHT+10) ; X m_clear() ; X m_bitcopyto(0, 0, ICONWIDTH, ICONHEIGHT, X 0, 0, 0, PR_ICON) ; X break ; X case OPEN : m_shapewindow(x, y, TWIDTH+10, THEIGHT+10) ; X } X m_movecursor(2500, 2500) ; X} X X X/*ARGUSED*/ Xset_cursor(type) /* Doesn't appear to be any way to set the cursor. */ Xenum cur_type type ; X{ X} X X Xstart_tool() /* Null routine. */ X{ X} Funky_Stuff echo "File mgr.c is complete" chmod 0444 mgr.c || echo "restore of mgr.c fails" set `wc -c mgr.c`;Sum=$1 if test "$Sum" != "7681" then echo original size 7681, current size $Sum;fi echo "x - extracting graphics.h (Text)" sed 's/^X//' << 'Funky_Stuff' > graphics.h && X X/* @(#)graphics.h 1.1 89/12/12 X * X * External variable definitions used by the popi program X * optional graphics module. 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/* External declarations for the variables declared in graphics.c. */ X Xextern char geometry[] ; /* X11 geometry information. */ Xextern char nextline[] ; /* Next input line to be parsed. */ Xextern char x11_display[] ; /* X11 display information. */ X Xextern unsigned char *mptr ; /* Pointer to scanline data. */ X Xextern int iconic ; /* Set if the window is in an iconic state. */ Xextern int iscolor ; /* Set if this is a color screen. */ Xextern int ix ; /* Initial X position of the icon. */ Xextern int iy ; /* Initial Y position of the icon. */ Xextern int nfont_width ; /* Width of normal font characters. */ Xextern int ops[] ; /* Rasterop functions. */ Xextern int posspec ; /* Set if -Wp or -g option is present (for X11) */ Xextern int tptr ; /* Input buffer pointer. */ X Xextern int wx ; /* Initial X position of the open window. */ Xextern int wy ; /* Initial Y position of the open window. */ Funky_Stuff chmod 0444 graphics.h || echo "restore of graphics.h fails" set `wc -c graphics.h`;Sum=$1 if test "$Sum" != "1762" then echo original size 1762, current size $Sum;fi echo "x - extracting news.c (Text)" sed 's/^X//' << 'Funky_Stuff' > news.c && X/*LINTLIBRARY*/ X X/* @(#)news.c 1.8 89/12/11 X * X * C wrappers for News dependent graphics routines used by popi. X * written by Rich Burridge - Sun Microsystems Australia. 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 <sys/types.h> X X/* Various pseudo events generated by the popi program. */ X#define KEYBOARD 100 /* Keyboard character was pressed. */ X#define REPAINT 101 /* Popi canvas needs repainting. */ X Xextern FILE *PostScript ; Xextern FILE *PostScriptInput ; X Xunsigned short icon_image[] = { X#include "popi.icon" X} ; X X Xcleanup() /* Null routine for the NeWS version. */ X{ X FPRINTF(PostScript, "/destroy Frame send\n") ; X FFLUSH(PostScript) ; X} X X Xdraw_scanline(line, y) /* Display image scanline on the screen. */ Xunsigned char *line ; Xint y ; X{ X int depth, i ; X X depth = (iscolor) ? 8 : 1 ; X FPRINTF(PostScript, "/ScanLine %1d 1 %1d { } { < \n", Xsize, depth) ; X if (iscolor) X { X for (i = 0; i < Xsize; i++) X FPRINTF(PostScript, "%.2X ", line[i]) ; 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++) X FPRINTF(PostScript, "%.2X ", 255 - mptr[i]) ; X } X FPRINTF(PostScript, "> } buildimage def\n") ; X FPRINTF(PostScript, "%1d PSDrawScanLine\n", y) ; X FFLUSH(PostScript) ; X} X X Xdrawarea(x, y, width, height, op) Xint x, y, width, height ; Xenum op_type op ; X{ X FPRINTF(PostScript, "%d %d %d %d %d PSDrawArea\n", X x, y, width, height, (int) op) ; X FFLUSH(PostScript) ; X} X X Xdrawline(x1, y1, x2, y2) Xint x1, y1, x2, y2 ; X{ X FPRINTF(PostScript, "%d %d %d %d PSDrawLine\n", x1, y1, x2, y2) ; X} X X Xdrawtext(x, y, fontno, str) Xenum font_type fontno ; Xint x, y ; Xchar *str ; X{ X int i ; X char font, fonttype[6], line[MAXLINE] ; X X if (fontno == NFONT) STRCPY(fonttype, "NFont") ; X else if (fontno == BFONT) STRCPY(fonttype, "BFont") ; X line[0] = '\0' ; X for (i = 0; i < strlen(str); i++) X switch (str[i]) X { X case '\\' : STRCAT(line,"\\\\") ; X break ; X case '(' : STRCAT(line,"\\(") ; X break ; X case ')' : STRCAT(line,"\\)") ; X break ; X default : STRNCAT(line, &str[i], 1) ; X } X FPRINTF(PostScript, "%s %d %d (%s) PSDrawText\n", fonttype, x, y, line) ; X} X X Xget_next_char(c) /* Process events, and return when character is typed. */ Xchar *c ; X{ X int ch, type ; X X for (;;) X { X FFLUSH(PostScript) ; X if (pscanf(PostScriptInput, "%d", &type) == EOF) exit(0) ; X switch (type) X { X case KEYBOARD : pscanf(PostScriptInput, "%d", &ch) ; X *c = ch ; X return ; X case REPAINT : paint_canvas() ; X } X } X/*NOTREACHED*/ X} X X Xinit_fonts() X{ X FPRINTF(PostScript, "PSInitFonts\n") ; X nfont_width = 9 ; X} X X Xinit_ws_type() X{ X if (ps_open_PostScript() < 0) return -1 ; X if (send_ps_file(NEWSFILE) == -1) X { X FCLOSE(PostScript) ; X return(-1) ; X } X FFLUSH(PostScript) ; X if (ferror(PostScript)) X { X FCLOSE(PostScript) ; X return(-1) ; X } X FPRINTF(PostScript, "PSIsColor\n") ; X pscanf(PostScriptInput, "%d", &iscolor) ; X FPRINTF(PostScript, "PSInitialise\n") ; X return(0) ; X} X X Xload_colors() /* Create and load popi color map. */ X{ X int i ; X u_char red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN] ; X X for (i = 0; i < CMAPLEN; i++) X red[i] = green[i] = blue[i] = 255 - i ; X X FPRINTF(PostScript, "%d PSMakeColorTable\n", 256) ; X for (i = 0; i < 256; i++) X FPRINTF(PostScript, "%d %d %d %d PSLoadColor\n", X red[i], green[i], blue[i], i) ; X} X X Xmake_icon() X{ X int i, j ; X X FPRINTF(PostScript,"/PopiIcon 64 64 1 { } { <\n") ; X for (i = 0; i < 32; i++) X { X for (j = 0; j < 8; j++) FPRINTF(PostScript,"%.4X ", icon_image[i*8+j]) ; X FPRINTF(PostScript,"\n") ; X } X FPRINTF(PostScript,"> } buildimage def\n") ; X} X X Xmake_items(argc, argv) /* Create icon, frame, canvas etc.. */ Xint argc ; Xchar *argv[] ; X{ X make_icon() ; X FPRINTF(PostScript, "%d %d %d %d %d %d %d PSMakeItems\n", X wx, wy, TWIDTH, THEIGHT, X ix, iy, iconic) ; X load_colors() ; X} X X Xsend_ps_file(fname) Xchar *fname ; X{ X FILE *stream ; X int c ; X X if ((stream = fopen(fname,"r")) == NULL) return -1 ; X while ((c = getc(stream)) != EOF) PUTC(c, PostScript) ; X FCLOSE(stream) ; X return 0 ; X} X X Xset_cursor(type) Xenum cur_type type ; X{ X FPRINTF(PostScript, "%d PSSetCursor\n", (int) type) ; X} X X Xstart_tool() /* Null routine in the NeWS version. */ X{ X} Funky_Stuff chmod 0444 news.c || echo "restore of news.c fails" set `wc -c news.c`;Sum=$1 if test "$Sum" != "5267" then echo original size 5267, current size $Sum;fi echo "x - extracting nulldev.c (Text)" sed 's/^X//' << 'Funky_Stuff' > nulldev.c && X/*LINTLIBRARY*/ X X/* @(#)nulldev.c 1.7 89/12/11 X * X * Popi device driver for a null device. X * written by Stephen Frede, Softway Pty Ltd. 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 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) - display error message. X * disp_percentdone(n) - display percentage value of conversion. X */ X X/*ARGSUSED*/ Xvoid Xdisp_init(argc,argv) /* called from main at the atart. */ Xint argc; Xchar *argv[]; X{ X} X X Xvoid Xdisp_finish() /* called from main prior to exit. */ X{ 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) /* called to draw image scanline y. */ Xpixel_t *line; Xint y; X{ X} X X Xdisp_getchar() /* get next user typed character. */ X{ X return(getchar()); X} X X X/*ARGSUSED*/ Xvoid Xdisp_ungetc(c) /* put back the last character typed. */ Xchar c; X{ X UNGETC(c, stdin); X} X X Xdisp_prompt() /* display popi prompt. */ X{ X char *prompt = "-> "; X X PRINTF(prompt); X return sizeof prompt - 1; X} X X Xvoid Xdisp_error(errtype, pos) /* display error message. */ Xint errtype, X pos; X{ X extern int errno; X extern char *sys_errlist[]; X X if (errtype & ERR_PARSE) X { X int i; X X for (i=1; i < pos; ++i) X PUTC('-', stderr); X PUTC('^', stderr); X PUTC('\n', stderr); X } X X FPRINTF(stderr, "%s\n", ErrBuf); X /* we assume errno hasn't been reset by the preceding output */ X if (errtype & ERR_SYS) X FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]); X} X Xvoid Xdisp_percentdone(percent) Xint percent; X{ X static int lastpercent = 100; X X if (!Verbose) X return; X if (percent == 100) X { X printf("\r \n"); X return; X } X if (percent != lastpercent && percent % 5 == 0) X { X printf("\r%2d%% ", percent); X fflush(stdout); X lastpercent = percent; X } X} Funky_Stuff chmod 0444 nulldev.c || echo "restore of nulldev.c fails" set `wc -c nulldev.c`;Sum=$1 if test "$Sum" != "3179" then echo original size 3179, current size $Sum;fi echo "x - extracting patchlevel.h (Text)" sed 's/^X//' << 'Funky_Stuff' > patchlevel.h && X X/* @(#)patchlevel.h 1.11 89/12/11 X * X * This is the current patchlevel for this version of popi. 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#define PATCHLEVEL 2 Funky_Stuff chmod 0444 patchlevel.h || echo "restore of patchlevel.h fails" set `wc -c patchlevel.h`;Sum=$1 if test "$Sum" != "764" then echo original size 764, current size $Sum;fi echo "x - extracting polar.c (Text)" sed 's/^X//' << 'Funky_Stuff' > polar.c && X X/* @(#)polar.c 1.6 89/12/11 X * X * Polar coordinate handling 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 "popi.h" X Xshort X *avals = 0, X *rvals = 0; X X/* X * +y X * ^ X * 2 | 1 X * -x <----+----> +x X * 3 | 4 X * v X * -y X */ X X#ifdef AMIGA Xdouble Xhypot(x, y) Xdouble x, y; X{ X return(sqrt(x*x + y*y)); X} X#endif /* AMIGA */ X Xvoid XMakePolar() X{ X short *ap, /* pointer to angle array */ X *rp, /* pointer into radius array */ X *a1, /* tmp pointer to angle array */ X *r1; /* tmp pointer to radius array */ X int x, X y, X xmin, X xmax, X ymin, X ymax; X X if (avals) X return; /* previously calculated */ X X avals = (short *) LINT_CAST(Emalloc((unsigned)Xsize * Ysize * sizeof(short))); X rvals = (short *) LINT_CAST(Emalloc((unsigned)Xsize * Ysize * sizeof(short))); X X ymax = Ysize / 2; X ymin = -(Ysize - 1) / 2; X xmin = -Xsize / 2; X xmax = (Xsize - 1) / 2; X X rp = rvals; X ap = avals; X X for (y = ymax; y >= 0; --y) X { X /* Quadrant 2 */ X for (x = xmin; x < 0; ++x) X { X *ap++ = (short) (RtoD(atan2((double) y, (double) x)) + 0.5); X *rp++ = (short) hypot((double) y, (double) x); X } X /* x == 0 */ X if (y == 0) X { X *ap++ = 0; /* prevent a domain error calling atan2() */ X *rp++ = 0; X } X else X { X *ap++ = (short) (RtoD(atan2((double) y, (double) x)) + 0.5); X *rp++ = (short) hypot((double) y, (double) x); X } X ++x; X /* remember location just before the 0 value */ X r1 = rp -2; X a1 = ap - 2; X /* Quadrant 1 */ X for (; x <= xmax; ++x) X { X *ap++ = 180 - *a1--; X *rp++ = *r1--; X } X } X r1 = rp - Xsize - 1; X a1 = ap - Xsize - 1; X for (; y >= ymin; --y) X { X /* Quadrant 3, 4 */ X for (x = xmin; x <= xmax; ++x) X { X *rp++ = *r1--; X *ap++ = *a1-- + 180; X } X } X} Funky_Stuff chmod 0444 polar.c || echo "restore of polar.c fails" set `wc -c polar.c`;Sum=$1 if test "$Sum" != "2418" then echo original size 2418, current size $Sum;fi echo "x - extracting popi.h (Text)" sed 's/^X//' << 'Funky_Stuff' > popi.h && X/* @(#)popi.h 1.10 89/12/11 X * X * Definitions and constants 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#ifndef POPI_DEFINED X#define POPI_DEFINED X X#if defined(MSDOS) && defined(M_I86) X/* Assume we are Microsoft C */ X# define __MSC__ 1 X#endif /* MSC */ X X/* X * Some compilers are near enough to ANSI for our purposes. X * In some situations the compiler has a true ANSI mode which X * we should set if possible. But sometimes we can't because X * we need non-standard features of the compiler (eg far pointers X * under DOS). We can't just set __STDC__ ourselves in these cases X * because their include files need to know the truth. So we X * set the token STDC which means that as far as we're concerned X * we are ANSI. X */ X X#if defined(__STDC__) || defined(__TURBOC__) || defined(__MSC__) X# define STDC 1 X#endif /* __STDC__ || __TURBOC__ || __MSC__ */ X X#if defined(STDC) && ! defined(apollo) X X# include <stdlib.h> X X#else /* ! STDC || apollo */ X X/* No <stdlib.h> */ X/* We can't define these as well as including <stdlib.h> because X * some compilers (eg Turbo C) use silly nonstandard keywords (which X * we can't #define away) as part of the type. X */ Xextern char X *malloc(), X *getenv(), X# ifdef BSD X *sprintf(); X# endif /* BSD */ X#endif /* STDC && !apollo */ X X#if defined(STDC) || ! defined(BSD) X# include <string.h> X#else X# include <strings.h> X#endif /* STDC || ! BSD */ X X/* X * For all function declarations, if ANSI then use a prototype. X */ X#if defined(STDC) X# define P(args) args X#else /* ! STDC */ X# define P(args) () X#endif /* STDC */ X X#ifndef FILE X# include <stdio.h> X#endif /* FILE */ X#ifndef assert X# include <assert.h> X#endif /* assert */ X X/* X * The assumption we make here is that not all versions of <math.h> X * define M_PI, but they all define HUGE. X */ X#ifndef M_PI X# ifndef HUGE X# include <math.h> X# endif /* HUGE */ X X# ifndef M_PI X# define M_PI 3.14159265358979323846 X# endif /* M_PI */ X#endif /* M_PI */ Xextern double X pow P((double, double)), X sin P((double)), X cos P((double)), X atan2 P((double, double)), X hypot P((double, double)), X log P((double)), X sqrt P((double)); X X#define NELS(arr) (sizeof (arr) / sizeof (*(arr))) X X#define DtoR(degrees) ((degrees) * M_PI * 2.0 / 360.0) X#define RtoD(radians) ((radians) / (M_PI * 2.0 / 360.0)) X X#define BITSINBYTE 8 X X/* X * define RANDOM to be an expression which returns a value X * between 0 and some large number (like maxint or maxlong). X */ X#if defined(BSD) X# define RANDOM random() Xextern long random P((void)); X#else /* ! BSD */ X# if defined(SYSV) X# define RANDOM lrand48() Xextern long lrand48 P((void)); X# else /* ! SYSV */ X# define RANDOM rand() Xextern int rand P((void)); X# endif /* SYSV */ X#endif /* BSD */ X Xtypedef long stack_t; Xtypedef long parse_t; Xtypedef unsigned char pixel_t; Xtypedef int bool; X X#ifndef FALSE X# define FALSE 0 X# define TRUE 1 X#endif /* FALSE */ X X X/* To make lint happy. */ X X#define FCLOSE (void) fclose X#define FFLUSH (void) fflush X#define FPRINTF (void) fprintf X#define FPUTS (void) fputs X#define FREAD (void) fread X#define FWRITE (void) fwrite X#define IOCTL (void) ioctl X#define PCLOSE (void) pclose X#define PRINTF (void) printf X#define PUTC (void) putc X#define SELECT (void) select X#define SIGNAL (void) signal X#define SPRINTF (void) sprintf X#define STRCAT (void) strcat X#define STRCPY (void) strcpy X#define STRNCAT (void) strncat X#define STRNCPY (void) strncpy X#define UNGETC (void) ungetc X#define WRITE (void) write X X#ifndef LINT_CAST X#ifdef lint X#define LINT_CAST(arg) (arg ? 0 : 0) X#else X#define LINT_CAST(arg) (arg) X#endif /* lint */ X#endif /* LINT_CAST */ X X#define PUTCHAR(ch) (void) putc(ch, stderr) X X#define BACKSPACE 8 /* for input line parsing. */ X#define DEL 127 X#define LINEFEED 13 X#define RETURN 10 X X#define BITSPERPIXEL 8 X#define BOXH 40 /* height of input dialog box. */ X#define BOXW (TWIDTH-40) /* width of input dialog box. */ X#define BOXX 20 /* x position of input dialog box. */ X#define BOXY 10 /* y position of input dialog box. */ X#define CMAPLEN 256 /* length of the color map. */ X#define DEF_X 512 /* image width */ X#define DEF_Y 512 /* image height */ X#define DEF_ZSIZE (1 << BITSPERPIXEL) X#define MAXIMG 128 X X#ifndef MAXLINE X#define MAXLINE 80 /* length of character strings. */ X#endif /*MAXLINE*/ X X#define MAXOPS 2 /* number of pseudo rasterop functions. */ X#define MAXTOKENS 128 X X#ifndef SIGRET X#define SIGRET int X#endif /* SIGRET */ X X#define THEIGHT 612 /* total height of the popi window. */ X#define TWIDTH 512 /* total width of the popi canvas. */ X X#define ERR_NONE 0 X#define ERR_SYS (1<<0) /* system error (errno set) */ X#define ERR_PARSE (1<<1) /* syntax error while parsing input */ X#define ERR_SNARK (1<<2) /* internal program error */ X#define ERR_WARN (1<<3) /* just a warning */ X X/* larger than any char token. */ X#define CRVAL 257 /* cartesian image coordinate rval */ X#define CLVAL 258 /* cartesian image coordinate lval */ X#define INAME 259 /* image name */ X#define VALUE 260 X#define NAME 261 X#define NEW 262 X#define AND 264 /* && */ X#define OR 265 /* || */ X#define EQ 266 /* == */ X#define NE 267 /* != */ X#define GE 268 /* >= */ X#define LE 269 /* <= */ X#define UMIN 270 /* unary minus */ X#define POW 271 /* ** */ X#define LSHIFT 272 /* << */ X#define RSHIFT 273 /* >> */ X#define SPECIAL 274 X#define INUM 275 /* integer number */ X#define FNUM 276 /* floating point number */ X#define PLVAL 277 /* polar image coordinate lval */ X#define PRVAL 278 /* polar image coordinate rval */ X#define FNAME 279 /* Filename */ X#define SIN 300 /* sine() * Z */ X#define COS 301 /* cosine() * Z */ X#define ATAN 302 /* atan2(y, x) */ X#define ABS 303 /* abs() */ X#define LOG 304 /* natural log */ X#define SQRT 305 X#define RAND 306 /* RANDOM() as defined above */ X#define HYPOT 307 /* hypot(x, y) == sqrt(x*x + y*y) */ X X#ifdef NDEBUG X# define DEBUG(stuff) X#else /* ! NDEBUG */ X# define DEBUG(stuff) if (Debug) FPRINTF stuff X#endif /* ! NDEBUG */ X Xenum cur_type { BUSY_CUR, NORMAL_CUR } ; /* cursor types. */ X Xenum font_type { BFONT, NFONT } ; /* fonts used by popi. */ X Xenum op_type { GCLR, GSET } ; /* pseudo rasterop functions. */ X Xstruct SRC X{ X pixel_t **pix; /* pix[y][x] */ X char *str; X}; X X/* An element of the execution string. X * Each such item will perform some operation on the X * evaluation stack. X */ Xtypedef Xstruct exec X{ X int op; X union X { X long i; /* integer */ X float f; /* floating point */ X } value; X} exec_t; X X#if SEQPAR X#ifndef sequent X#include "Sorry, this will only work on a sequent" X#endif /* sequent */ X#define malloc shmalloc X#endif /* SEQPAR */ X X/* External declarations */ X X/* main.c */ Xextern char *Emalloc P((unsigned int)); Xextern void PrStrs P((char **)); Xextern void version P((void)); X X/* io.c */ Xextern pixel_t **ImgAlloc P((void)); Xextern void ImgFree P((struct SRC *)); Xextern void Efclose P((FILE *)); Xextern FILE *EfopenR P((char *)), X *EfopenW P((char *)); Xextern void getpix P((char *, char *)); Xextern void putpix P((struct SRC *, char *)); Xextern void showfiles P((void)); X X/* lex.c */ Xextern void Skip P((void)); Xextern void lex P((void)); Xextern void error P((int)); Xextern void pushback P((int)); X X/* expr.c */ Xextern void transform P((void)); X X/* special.c */ Xextern void help P((void)); Xextern void OpenLog P((void)); Xextern void special P((void)); X X/* run.c */ Xextern void SwapOldNew P((void)); Xextern void run P((void)); X X/* polar.c */ Xextern void MakePolar P((void)); X X/* driver routines */ Xvoid disp_init P((int, char**)); Xvoid disp_finish P((void)); Xvoid disp_imgstart P((void)); Xvoid disp_imgend P((void)); Xvoid disp_putline P((pixel_t *, int)); Xvoid disp_error P((int, int)); Xvoid disp_ungetc P((int)); Xvoid disp_percentdone P((int)); Xint disp_prompt P((void)); Xint disp_getchar P((void)); X X/* External variable declarations */ X Xextern char ErrBuf[] ; Xextern char *ProgName ; /* Name of this program. */ Xextern char nextline[] ; /* Next input line to be parsed. */ Xextern char text[] ; Xextern char *LogFile ; /* Name of file for logging commands */ X Xextern FILE *Debug ; /* Debugging stream */ Xextern FILE *LogStr ; /* command logging stream */ X Xextern double lexfract ; X Xextern short CUROLD ; Xextern short CURNEW ; X Xextern long parsed[] ; X Xextern int CharPos ; /* Position in input line. */ Xextern int OldPos ; Xextern int RangeCheck ; Xextern int Xsize ; Xextern int Ysize ; Xextern int Zsize ; Xextern pixel_t Zmax ; Xextern short *avals ; Xextern int lat ; /* Lookahead token. */ Xextern int lexval ; Xextern int noerr ; /* Indicates if an error has occured. */ Xextern int nsrc ; Xextern int prs ; Xextern short *rvals ; Xextern int Verbose ; Xextern void Skip() ; Xextern int Truncate ; X Xextern struct SRC src[MAXIMG] ; X Xextern int disp_active ; /* Display results after each operation. */ X X#if SEQPAR Xextern int ncpus; /* No. cpus to use in parallel */ X#endif /* SEQPAR */ X X#endif /* POPI_DEFINED */ Funky_Stuff chmod 0444 popi.h || echo "restore of popi.h fails" set `wc -c popi.h`;Sum=$1 if test "$Sum" != "9927" then echo original size 9927, current size $Sum;fi echo "x - extracting popi.icon (Text)" sed 's/^X//' << 'Funky_Stuff' > popi.icon && X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 X */ X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8000,0x0000,0x0001,0x0001, X 0x8000,0x0000,0x0001,0x7F81,0x8000,0x0000,0x0001,0x30C1, X 0x8000,0x0000,0x0001,0x3061,0x8000,0x0000,0x0001,0x3061, X 0x8000,0x0000,0x0001,0x3061,0x8000,0x0000,0x0001,0x30C1, X 0x8000,0x7600,0x0001,0x3781,0x8000,0xDF80,0x0001,0x3001, X 0x8001,0x76E8,0x0001,0x3001,0x8001,0xFF00,0x0001,0x3001, X 0x8002,0x7BFC,0x0001,0x3001,0x8002,0xDE03,0x0001,0x3001, X 0x800A,0xD5F8,0x0001,0x3001,0x804A,0xBF45,0xC001,0x7801, X 0x801A,0xE97C,0x0001,0x0001,0x81D3,0xAFEB,0x6001,0x0001, X 0x823F,0xFBBE,0x1001,0x0F81,0x82EF,0xEAFF,0xF401,0x11C1, X 0x857F,0xABFF,0x8401,0x20E1,0x857F,0xE87F,0xF801,0x6061, X 0x87FF,0x007F,0xFE01,0x6061,0x8BFF,0x000F,0xF801,0x6061, X 0x8FFC,0x0005,0xFE01,0x6061,0x87FE,0x01FF,0xFF01,0x7041, X 0x8FFB,0xF37F,0xFE01,0x3881,0x87EF,0xF1E0,0xFF81,0x1F01, X 0x8FF8,0xF1FE,0xFF81,0x0001,0x8FFF,0xB110,0x5D01,0x0001, X 0x87E2,0xD0C4,0x5FC1,0x0001,0x8FEA,0x0010,0x3FC1,0x77C1, X 0x87A0,0xA045,0x1FC1,0x38E1,0x87F4,0xA030,0x5F81,0x3071, X 0x87D2,0x8001,0x3F81,0x3031,0x85D6,0xC014,0xBF81,0x3031, X 0x87F0,0x39C5,0xBF01,0x3031,0x87DE,0x8F85,0xFE01,0x3031, X 0x83EA,0x3FF4,0x3E01,0x3021,0x83FC,0xA85D,0xF801,0x3841, X 0x81F7,0xFFE5,0xB801,0x3F81,0x81FE,0xA005,0xF801,0x3001, X 0x807E,0x9007,0xF001,0x3001,0x807F,0x96C3,0xF801,0x3001, X 0x80FE,0x8A8F,0xFC01,0x3001,0x80FF,0xCBA2,0xFE01,0x7801, X 0x80FF,0xD69F,0xFF01,0x0001,0x807F,0xD5D7,0xFC01,0x0001, X 0x81FF,0xF77F,0xFC01,0x0601,0x80FF,0xFDDF,0xFE01,0x0601, X 0x80FF,0xEFFE,0xFE01,0x0001,0x81FE,0xFFFD,0xFF81,0x0001, X 0x87FE,0xFFFD,0xFFC1,0x1E01,0x9FEF,0xBFF5,0xABF1,0x0601, X 0xBFFB,0x7FDF,0xFFFD,0x0601,0xFFCF,0xD7F3,0xC7FF,0x0601, X 0xFFFF,0xFFDF,0xFFFF,0x0601,0xFFFF,0x6FF7,0xFFFF,0x0601, X 0xFFFF,0xFFFF,0xFFFF,0x0601,0xFFFF,0xEFCF,0xFFFF,0x0601, X 0xFFFF,0xFFFF,0xFFFF,0x0601,0xFFFF,0xFFFF,0xFFFF,0x1F81, X 0xFFFF,0xFFFF,0xFFFF,0x0001,0xFFFF,0xFFFF,0xFFFF,0xFFFF Funky_Stuff chmod 0444 popi.icon || echo "restore of popi.icon fails" set `wc -c popi.icon`;Sum=$1 if test "$Sum" != "1933" then echo original size 1933, current size $Sum;fi echo "x - extracting popi.ps (Text)" sed 's/^X//' << 'Funky_Stuff' > popi.ps && X X% @(#)popi.ps 1.5 89/12/04 X% X% NeWS dependent graphics routines used by the popi program. X% written by Rich Burridge - Sun Microsystems Australia. 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 on inaccuracies inherent X% either to the comments or the code of this program, but if reported X% to me, then an attempt will be made to fix them. X X/edef { exch def } def X X/PSDrawArea % x y width height op => - X{ X 5 dict begin X /Op edef X /Height edef X /Width edef X /Y edef X /Y CanvasHeight Y sub Height sub def X /X edef X X Canvas setcanvas X newpath X X Y moveto X Width Height rect X Op [ X GSET { 0 setgray } X GCLR { 1 setgray } X ] case X fill X end X} def X X X/PSDrawLine % x1 y1 x2 y2 => - X{ X 4 dict begin X /Y2 edef X /Y2 CanvasHeight Y2 sub def X /X2 edef X /Y1 edef X /Y1 CanvasHeight Y1 sub def X /X1 edef X X Canvas setcanvas X 0 setgray X X2 Y2 moveto X1 Y1 lineto stroke X end X} def X X X/PSDrawScanLine % y => - X{ X /Y edef X /Y CanvasHeight Y sub 100 sub def X X gsave X Canvas setcanvas X 0 Y translate X 512 1 scale X ScanLine imagecanvas X grestore X} def X X X/PSDrawText % font x y text => - X{ X 4 dict begin X /Text edef X /Y edef X /Y CanvasHeight Y sub def X /X edef X /Font edef X X Canvas setcanvas X Font setfont X 0 setgray X X Y moveto Text show X end X} def X X X/PSInitFonts % - => - X{ X /NFont /Courier findfont 14 scalefont def X /BFont /Courier-Bold findfont 14 scalefont def X} def X X X/PSInitialise % - => - X{ X /GCLR 0 def X /GSET 1 def X /KEYBOARD 100 def X /REPAINT 101 def X /BUSY_CUR 0 def X /NORMAL_CUR 1 def X} def X X X/PSIsColor % - => iscolorscreen X{ X /Color? framebuffer /Color get def X Color? {1} {0} ifelse typedprint X} def X X X/PSLoadColor % red green blue index => - X{ X 4 dict begin X /ColorIndex edef X /BlueValue edef X /GreenValue edef X /RedValue edef X X /CColor RedValue 255 div GreenValue 255 div BlueValue 255 div rgbcolor def X ColorTable ColorIndex CColor put X end X} def X X X/PSMakeColorTable % size => - X{ X /TableSize edef X X /ColorTable TableSize array def X} def X X X/PSMakeItems % wx wy width height ix iy iconic => - X{ X [ /IsIcon /IconY /IconX /FrameHeight /FrameWidth /FrameY /FrameX ] X { exch def } forall X X clippath pathbbox /ScreenHeight edef pop pop pop X /Frame framebuffer /new DefaultWindow send def X FrameX FrameY IconX IconY X { X [ /IconY /IconX /FrameY /FrameX ] { exch def } forall X /BorderTop 5 def X /BorderLeft 5 def X /BorderBottom 5 def X /BorderRight 5 def X /ControlSize 0 def X /PaintClient X { X REPAINT typedprint X } def X /PaintIcon X { X gsave X IconCanvas setcanvas X 1 fillcanvas X clippath pathbbox X scale pop pop X 0 setgray X true PopiIcon imagemaskcanvas X grestore X } def X } Frame send X FrameX X ScreenHeight FrameHeight sub FrameY sub X FrameWidth 10 add FrameHeight /reshape Frame send X /map Frame send X X /Canvas Frame /ClientCanvas get def X Canvas X begin X /Transparent false def X /Mapped true def X /Retained true def X end X /CanvasHeight FrameHeight def X X /KbdEvent X { X begin X Action /DownTransition eq X { X KEYBOARD typedprint Name typedprint X } if X end X } def X X /EventMgrKbdInterest X { X [3 1 roll] { MakeEventMgrKbdInterest} append cvx X } def X X /MakeEventMgrKbdInterest X { X addkbdinterests X { /ClientData 10 dict dup /CallBack 5 index put put } forall X pop X } def X X /EventMgr X [ X { KbdEvent } Canvas EventMgrKbdInterest X ] forkeventmgr def X} def X X X/PSSetCursor % type => - X{ X [ X BUSY_CUR { /hourg /hourg_m } X NORMAL_CUR { /ptr /ptr_m } X ] case X Canvas setstandardcursor X} def Funky_Stuff chmod 0444 popi.ps || echo "restore of popi.ps fails" set `wc -c popi.ps`;Sum=$1 if test "$Sum" != "4365" then echo original size 4365, current size $Sum;fi echo "x - extracting run.c (Text)" sed 's/^X//' << 'Funky_Stuff' > run.c && X/* @(#)run.c 1.9 89/12/11 X * X * Run time interpreter 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 <ctype.h> X#include "popi.h" X#if SEQPAR X#include <parallel/microtask.h> X#endif /* SEQPAR */ X X#define STACKSIZE 128 X X#define dop(OP) a = *--sp ; tp = sp-1 ; *tp = (*tp OP (stack_t) a) X X/* local function prototypes */ Xvoid prun P((void)); X Xvoid XSwapOldNew() X{ X CUROLD = CURNEW; X CURNEW = 1 - CUROLD; X} X Xstatic void Xprun() X{ X long *ParseEnd; /* after end of parse string */ X int x, X y; /* coordinates */ X int nrange = 0; /* no. range errors */ X X ParseEnd = &parsed[prs]; X X if (Debug) X { X register long X *CurrParse; /* pointer to current item in parse string */ X FPRINTF(Debug, "Parse string\n"); X for (CurrParse = parsed; CurrParse != ParseEnd; ++CurrParse) X FPRINTF(Debug, "'%c' (%ld)\n", (char) *CurrParse, *CurrParse); X FPRINTF(Debug, "---\n"); X } X X /* X * Warning: Microsoft Quick C generates incorrect code X * for the following loop when optimisation is turned on. X */ X#ifndef SEQPAR X for (y = 0; y < Ysize; ++y) X#else /* ! SEQPAR */ X for (y = m_myid; y < Ysize; y += m_numprocs) X#endif /* ! SEQPAR */ X { X short *ap, /* precalculated polar angles */ X *rp; /* precalculated polar radius */ X register pixel_t X *p; /* default destination */ X X ap = &avals[y * Xsize]; X rp = &rvals[y * Xsize]; X X p = src[CURNEW].pix[y]; X X DEBUG((Debug, "y = %d\n", y)); X for (x = 0; x < Xsize; ++x, ++p) X { X stack_t X Stack[STACKSIZE]; /* the stack */ X register stack_t X *sp, /* stack pointer (top of stack) */ X *tp; /* temp stack pointer */ X stack_t X a, X b; X int X c; /* scratch */ X register pixel_t X *u; /* explicit destination */ X register long X *CurrParse; /* pointer to current item in parse string */ X X for (CurrParse = parsed, sp = Stack; CurrParse != ParseEnd; ++CurrParse) X { X if (*CurrParse == VALUE) X { X *sp++ = (stack_t) *++CurrParse; X continue; X } X if (*CurrParse == '@') X { X --sp; X if (Truncate) X { X if (*sp > Zmax) X *sp = Zmax; X else if (*sp < 0) X *sp = 0; X } X *p = (pixel_t) *sp; X continue; X } X switch ((int) *CurrParse) X { X case '+': X dop(+); X break; X case '-': X dop(-); X break; X case '*': X dop(*); X break; X case '/': X a = *--sp; X tp = sp-1; X if (a == 0) X *tp = Zmax; X else X *tp = (*tp / (stack_t) a); X break; X case '%': X a = *--sp; X tp = sp-1; X if (a == 0) X *tp = 0; X else X *tp = (*tp % (stack_t) a); X break; X case '>': X dop(>); X break; X case '<': X dop(<); X break; X case GE: X dop(>=); X break; X case LE: X dop(<=); X break; X case EQ: X dop(==); X break; X case NE: X dop(!=); X break; X case AND: X dop(&&); X break; X case OR: X dop(||); X break; X case '^': X dop(^); X break; X case '|': X dop(|); X break; X case '&': X dop(&); X break; X case 'x': X *sp++ = (stack_t) x; X break; X case 'y': X *sp++ = (stack_t) y; X break; X case UMIN: X tp = sp-1; X *tp = -(*tp); X break; X case '!': X tp = sp-1; X *tp = !(*tp); X break; X case '=': X a = *--sp; X u = (pixel_t *) *--sp; X if (Truncate) X { X if (a > Zmax) X a = Zmax; X else if (a < 0) X a = 0; X } X *u = (pixel_t) a; X break; X case CRVAL: X a = *--sp; /* y */ X b = *--sp; /* x */ X tp = sp-1; X c = (int) *tp; X *tp = (stack_t) src[c].pix[a][b]; X break; X case CLVAL: X a = *--sp; /* y */ X b = *--sp; /* x */ X tp = sp-1; X c = (int) *tp; X if X ( X RangeCheck && X ( X a > Xsize - 1 || a < 0 X || X b > Ysize - 1 || b < 0 X ) X ) X { X if (nrange++ == 0) X FPRINTF(stderr, X "Range err at (%d,%d) => %s[%d, %d]\n", X x, y, src[c].str, b, a); X } X if (a >= Ysize) X a = Ysize - 1; X if (a < 0) X a = 0; X if (b >= Xsize) X b = Xsize - 1; X if (b < 0) X b = 0; X *tp = (stack_t) &(src[c].pix[a][b]); X break; X case PRVAL: X { X int xval, X yval; X X a = *--sp; /* angle */ X b = *--sp; /* radius */ X X xval = (int) (b * cos((double) DtoR(a)) + Xsize / 2.0); X yval = (int) (- b * sin((double) DtoR(a)) + Ysize / 2.0); X X tp = sp - 1; X c = (int) *tp; X X if (RangeCheck && X (xval < 0 || xval >= Xsize || X yval < 0 || yval >= Ysize)) X { X if (nrange++ == 0) X FPRINTF(stderr, X "Range err at (%d,%d) => %s{%d,%d} [%d,%d]\n", X x, y, src[c].str, b, a, xval, yval); X } X X if (xval < 0) X xval = 0; X if (xval >= Xsize) X xval = Xsize - 1; X if (yval < 0) X yval = 0; X if (yval >= Ysize) X yval = Ysize - 1; X X *tp = (stack_t) src[c].pix[yval][xval]; X } X break; X X case PLVAL: X { X int xval, X yval; X X a = *--sp; /* angle */ X b = *--sp; /* radius */ X X xval = (int) (b * cos((double) DtoR(a)) + Xsize / 2.0); X yval = (int) (- b * sin((double) DtoR(a)) + Ysize / 2.0); X X tp = sp - 1; X c = (int) *tp; X X if (RangeCheck && X (xval < 0 || xval >= Xsize || X yval < 0 || yval >= Ysize)) X { X if (nrange++ == 0) X FPRINTF(stderr, X "Range err at (%d,%d) => %s{%d,%d} [%d,%d]\n", X x, y, src[c].str, b, a, xval, yval); X } X X if (xval < 0) X xval = 0; X if (xval >= Xsize) X xval = Xsize - 1; X if (yval < 0) X yval = 0; X if (yval >= Ysize) X yval = Ysize - 1; X X *tp = (stack_t) &(src[c].pix[yval][xval]); X } X break; X X case POW: X a = *--sp; /* exponent */ X tp = sp-1; X *tp = (stack_t) pow((double) *tp, (double) a); X break; X case 'a': X#if NOMEM X *sp++ = (stack_t) X RtoD(atan2((double) y, (double) x)) + 0.5; X#else /* !NOMEM */ X *sp++ = (stack_t) *ap; X#endif /* !NOMEM */ X break; X case 'r': X *sp++ = (stack_t) *rp; X break; X case SIN: X tp = sp-1; X *tp = (stack_t) (sin((double) DtoR(*tp)) * (double)Zmax); X break; X case COS: X tp = sp-1; X *tp = (stack_t) (cos((double) DtoR(*tp)) * (double)Zmax); X break; X case ATAN: X a = *--sp; X tp = sp-1; X *tp = (stack_t) RtoD(atan2((double) *tp, (double) a)); X break; X case HYPOT: X a = *--sp; X tp = sp - 1; X *tp = (stack_t) hypot((double) *tp, (double) a); X break; X case ABS: X tp = sp-1; X *tp = *tp < 0 ? - *tp : *tp; X break; X case LOG: X tp = sp-1; X *tp = (stack_t) log((double) *tp); X break; X case SQRT: X tp = sp-1; X *tp = (stack_t) sqrt((double) *tp); X break; X case RAND: X#if 0 X tp = sp -1; X *tp = (stack_t) RANDOM % *tp; X#else X *sp++ = (stack_t) RANDOM; X#endif X break; X case LSHIFT: X dop(<<); X break; X case RSHIFT: X dop(>>); X break; X case '?': X a = *--sp; X CurrParse++; X if (!a) X CurrParse = &parsed[*CurrParse]; X break; X case ':': X CurrParse = &parsed[CurrParse[1]]; X break; X X default: X if (*CurrParse < 127 && isprint(*CurrParse)) X SPRINTF(ErrBuf, "run: unknown operator '%c' (%d)", X *CurrParse, *CurrParse); X else X SPRINTF(ErrBuf, "run: unknown operator %d", *CurrParse); X error(ERR_SNARK); X return; X } X } X ++ap; Funky_Stuff echo "End of part 3" echo "File run.c is continued in part 4" echo "4" > s2_seq_.tmp exit 0