From decwrl!ogicse!ucsd!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew Sat Feb 3 15:03:42 PST 1990 Article 107 of comp.sources.sun: Path: decwrl!ogicse!ucsd!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew) Newsgroups: comp.sources.sun Subject: v02i009: Sunplot - a UNIX plot backend for sunview Message-ID: Date: 27 Jan 90 05:18:58 GMT Organization: Rutgers Univ., New Brunswick, N.J. Lines: 1409 Approved: mcgrew@aramis.rutgers.edu Posted: Fri Jan 26 21:18:58 1990 Submitted-by: sjoerd@piring.cwi.nl (Sjoerd Mullender) Posting-number: Volume 2, Issue 9 Archive-name: sunplot The subject says it all, really. Sjoerd Mullender e-mail: sjoerd@cwi.nl Centre for Mathematics and Computer Science, Amsterdam #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'MANIFEST' <<'END_OF_FILE' X File Name Archive # Description X----------------------------------------------------------- X MANIFEST 1 This shipping list X Makefile 1 Guess X README 1 Read this for instructions X sunplot.1 1 The manual X sunplot.c 1 The source X sunplot.icon 1 An icon END_OF_FILE if test 358 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(364 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# The names of the installed binary and manual page. X# Feel free to change. XBINARY = /usr/local/sunplot XMANUAL = /usr/man/manl/sunplot.l X XCFLAGS = -O X Xsunplot: sunplot.o X $(CC) -o sunplot sunplot.o -lsuntool -lsunwindow -lpixrect X Xinstall: sunplot X cp sunplot $(BINARY) X cp sunplot.1 $(MANUAL) X Xclean: X rm -f sunplot *.o core make.out X Xsunplot.o: sunplot.icon END_OF_FILE if test 364 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(616 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' XThis program was written on a Sun 3/50 running SunOS 3.2. XIt also compiles and runs on a Sun 3/50 running SunOS 3.5 and a XSPARCstation 1 running SunOS 4.0.3c. X XTo make simply type ``make.'' XTo install, check the Makefile to see if all the names are correct. Then Xtype ``make install.'' X XIf you find any bugs or if you have any suggestions or improvements, please Xdrop me a note at the address below. X XYou might try the command X echo 0 0 1 1 2 4 3 9 4 16 | spline | graph | sunplot Xafter which a window pops up. X XSjoerd Mullender XCentre for Mathematics & Computer Science XAmsterdam XNetherlands X XEmail: sjoerd@cwi.nl END_OF_FILE if test 616 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'sunplot.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'sunplot.1'\" else echo shar: Extracting \"'sunplot.1'\" \(5037 characters\) sed "s/^X//" >'sunplot.1' <<'END_OF_FILE' X.TH SUNPLOT 1 X.SH NAME Xsunplot \- plotter backend for Sun workstation X.SH SYNOPSIS X.B sunplot X[ X.B \-c X.I canvas_size X] [ X.B \-h X.I horizontal_size X] [ X.B \-v X.I vertical_size X] [ X.B \-f X.I font_name X] [ X.B \-r X] [ X.B \-x X] [ X.B \-y X] [ X.B \-l X] [ X.B \-s X] [ X.B \-R X] X.SH DESCRIPTION X.I Sunplot Xreads UNIX plotter code (see X.IR plot (5)) Xfrom standard input and displays it in a Sun window. XThe window consists of two subwindows. XAt the top is a control panel with a number of buttons and below it is Xa window with a canvas on which X.I sunplot Xdraws and a horizontal and a vertical scrollbar with which you can select Xwhich part of the canvas you want to see in the window. XThe buttons in the control panel have the following functions: X.TP X.B "Next Page" XDraw the next page. XPages are separated by an X.B e X(the X.I erase Xfunction in the X.IR plot (3X) Xlibrary). XThis button is not displayed while X.I sunplot Xis still reading a page or when the end of the input has been reached. X.TP X.B Redraw XRedraw the current page. X.TP X.B Zoom XZoom the current page. X.I Sunplot Xfinds the most extreme x- and y-coordinates in the current page and uses Xthose values in stead of the values given by the X.B s Xcommand (the X.I space Xfunction) for scaling. X.TP X.B Options X.I Sunplot Xdisplays a window where you can set certain options. XSee the description below. X.TP X.B Dump X.I Sunplot Xdisplays a window with four items. XYou should type a file name after the string X.B Dump to file: Xand then press the X.B Dump Xbutton. X.I Sunplot Xwill then dump the plot into the named file in the format chosen with the X.B Dump format Xitem. XThe dump can be in X.IR rasterfile (5), X.IR icon , Xor X.I UNIX X.IR plot (5) Xformat. XIf the file name is empty, X.I sunplot Xwill do nothing. XThe dump subwindow will continue to be displayed until the X.B Done Xbutton is selected. X.TP X.B "Fit Screen" XResize the window so that the canvas fits. X.TP X.B Quit XExit X.I sunplot Xwithout asking for user confirmation. X.SH OPTIONS XWhen the X.B Options Xbutton is pressed X.I sunplot Xwill display a window with the following items. X.TP X.B Done XDone setting options. XThe window disappears and the page is redrawn with the new settings. X.TP X.B Apply XApply the selected options. X.I Sunplot Xwill automatically do a redraw of the page with the new settings. X.TP X.B Rotate XRotate the plot by 90 degrees counter-clockwise. X.TP X.B "X Mirror" XMirror the plot in the x-axis. X.TP X.B "Y Mirror" XMirror the plot in the y-axis. X.TP X.B Label XIf on, display labels. X.TP X.B Square XIf on, the canvas is square, otherwise you can set the horizontal and vertical Xsizes of the canvas separately. X.TP X.B Reverse XDisplay the canvas in reverse video. X.TP X.B "Font name" XThe name of the font to be used for the labels. XIf the name is not absolute it is taken to be relative to the system's fonts Xdirectory /usr/lib/fonts/fixedwidthfonts. XIf no name is given or the named file does not contain a font, the default Xfont is used. X.TP X.B "Canvas size" XThe size of the canvas. XThe size of the canvas is measured in pixels. XThis is only displayed when the X.B Square Xtoggle is on. X.TP X.B "Horizontal size" XThe horizontal size of the canvas. XThis is only displayed when the X.B Square Xtoggle is off. X.TP X.B "Vertical size" XThe vertical size of the canvas. XThis is only displayed when the X.B Square Xtoggle is off. X.PP XThe following command line options are recognized. X.IP "\f3\-c\fP \f2canvas_size\fP" XSet the canvas size. X.I Canvas_size Xmust be between 64 and 2048. XThis also switches on the X.B Square Xtoggle. X.IP "\f3\-h\fP \f2horizontal_size\fP" XSet the horizontal size. X.I Horizontal_size Xmust be between 64 and 2048. XThis also switches off the X.B Square Xtoggle. X.IP "\f3\-v\fP \f2vertical_size\fP" XSet the vertical size. X.I Vertical_size Xmust be between 64 and 2048. XThis also switches off the X.B Square Xtoggle. X.IP "\f3\-f\fP \f2font_name\fP" XSet the font to be used for labels. XThis is independent from the font that is used for the text in the control Xpanel and the options and dump windows. XA name not starting with ``/'' is taken to be relative to the system's font Xdirectory /usr/lib/fonts/fixedwidthfonts. X.IP \f3\-r\fP XRotate the plot by 90 degrees counter-clockwise. X.IP \f3\-x\fP XMirror the plot in the x-axis. X.IP \f3\-y\fP XMirror the plot in the y-axis. X.IP \f3\-l\fP XToggle labeling. X.IP \f3\-s\fP XToggle square mode. X.IP \f3\-R\fP XDisplay in reverse video (white on black). X.PP XThe X.BR \-r , X.B \-x Xand X.B \-y Xoptions are evaluated left to right and can be repeated to get cumulative Xeffect. X.I Sunplot Xalso recognizes the generic tool arguments; see X.IR suntools (1) Xfor a list of these arguments. X.PP XThe defaults are: labels printed, square canvas, canvas size is 512 Xby 512 pixels, the point X.I "(0,\ 0)" Xis in the lower left-hand corner. X.SH BUGS XThe X.I linemod Xfunction is not implemented. X.PP XThe X.B zoom Xcommand doesn't take the height and width of labels into account. X.SH "SEE ALSO" X.IR plot (3X), X.IR plot (5), Xand X.IR rasterfile (5). X.SH AUTHOR XSjoerd Mullender, Free University, Amsterdam END_OF_FILE if test 5037 -ne `wc -c <'sunplot.1'`; then echo shar: \"'sunplot.1'\" unpacked with wrong size! fi # end of 'sunplot.1' fi if test -f 'sunplot.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'sunplot.c'\" else echo shar: Extracting \"'sunplot.c'\" \(22427 characters\) sed "s/^X//" >'sunplot.c' <<'END_OF_FILE' X/* X * Sunplot - plotter backend for Sun workstation X * X * Copyright (c) 1987 by Sjoerd Mullender, Vrije Universiteit, Amsterdam. X * X * This program may be redistributed without fee as long as this copyright X * notice is in tact. X * Any commercial use is strictly prohibited. X */ X X#ifndef lint Xstatic char rcsid[] = "$Header: /tmp_mnt/tuintje/ufs1/cl/sjoerd/src/sunplot/RCS/sunplot.c,v 1.5 89/12/08 10:53:15 sjoerd Exp $"; X#endif X X#include X#include X#include X#include X#include X X/* X * Configurable definitions X */ X#define INIT_CANVAS_SIZE 512 X#define DEFAULT_SPACE 4096 X#define MAX_NAME_LENGTH 128 X X/* X * Unconfigurable definitions X */ X#define BIG 0x7FFFFFFF X X#define FORMAT_RASTER 0 X#define FORMAT_ICON 1 X#define FORMAT_PLOT 2 X X#define LABEL 0 X#define SQUARE 1 X#define REVERSE 2 X Xint client_object; /* used for notifier */ Xint *me = &client_object; /* idem */ X Xint curx, cury; /* current position on plot */ Xint lox, loy, hix = DEFAULT_SPACE, hiy = DEFAULT_SPACE; /* current space */ Xint slox, shix, sloy, shiy; /* saved space settings for zooming */ Xint minx, maxx, miny, maxy; /* minimum and maximum values encountered */ Xint hor_size, ver_size; /* canvas size */ Xint turned, xmirror, ymirror; /* orientation of plot */ Xint zooming; Xint make_label = TRUE; /* print labels */ Xint square = TRUE; /* canvas is square */ Xint reverse = FALSE; /* reverse video */ Xint dirty; XFrame frame, dump_frame, options_frame; XPanel panel, dump_panel, options_panel; XPanel_item next_page_item; XPanel_item hor_size_item, ver_size_item, toggle_item, font_item; XPanel_item dump_format, dump_file_item; XCanvas canvas; XPixwin *pw; XPixfont *font; Xchar font_name[MAX_NAME_LENGTH]; Xchar font_dir[] = "/usr/lib/fonts/fixedwidthfonts/"; XPr_texture texture; XPr_brush brush = {1}; X Xshort sunplot_icon_image[] = { X#include "sunplot.icon" X}; Xmpr_static(sunplot_icon, 64, 64, 1, sunplot_icon_image); X Xchar *malloc(), *realloc(); X X/* X * input module X */ X Xstatic char *plotcommands, *plptr; Xstatic int plotlength; Xstatic int maxplotlength; Xstatic int eof_seen; X Xgetchr() X{ X register c; X X if (plptr < plotcommands + plotlength) X return *plptr++ & 0xFF; X if (eof_seen || (c = getchar()) == EOF) { X eof_seen = 1; X return EOF; X } X if (plotlength >= maxplotlength) { X plotcommands = realloc(plotcommands, maxplotlength *= 2); X plptr = plotcommands + plotlength; X } X *plptr++ = c; X plotlength++; X return c; X} X Xgetint() X{ X register n; X X n = getchr(); X n = n | getchr() << 8; X if (n & 0x8000) /* sign extend */ X n |= ~0x7FFF; X return n; X} X Xchar *getstr() X{ X register i = plptr - plotcommands; X register c; X X while ((c = getchr()) != EOF && c != '\0' && c != '\n') X ; X plptr[-1] = 0; X return plotcommands + i; X} X X/* X * plot module X */ X X#define point(x,y) pw_put(pw, plotx(x, y), ploty(x, y), !reverse) X X#if 0 X#define line(x0,y0,x1,y1) pw_vector(pw,plotx(x0,y0),ploty(x0,y0),plotx(x1,y1),ploty(x1,y1),PIX_SRC,!reverse) X#else X#define line(x0,y0,x1,y1) pw_line(pw,plotx(x0,y0),ploty(x0,y0),plotx(x1,y1),ploty(x1,y1),&brush,&texture,reverse?PIX_CLR:PIX_SET) X#endif X X#define convx(x,s) (((x) - lox) * (s) / (hix - lox)) X#define convy(y,s) (((y) - loy) * (s) / (hiy - loy)) X Xinitplot() X{ X plptr = plotcommands = malloc(maxplotlength = 1024); X plotlength = 0; X} X Xplotx(x, y) X{ X register a; X X switch (turned) { X case 0: a = convx(x, hor_size); break; X case 1: a = hor_size - 1 - convy(y, hor_size); break; X case 2: a = hor_size - 1 - convx(x, hor_size); break; X case 3: a = convy(y, hor_size); break; X } X return xmirror ? hor_size - 1 - a : a; X} X Xploty(x, y) X{ X register a; X X switch (turned) { X case 0: a = ver_size - 1 - convy(y, ver_size); break; X case 1: a = ver_size - 1 - convx(x, ver_size); break; X case 2: a = convy(y, ver_size); break; X case 3: a = convx(x, ver_size); break; X } X a = ymirror ? ver_size - 1 - a : a; X return zooming ? a+1 : a; X} X Xlabel(s) Xchar *s; X{ X struct pr_size pr_size; X X if (!make_label) X return 0; X pw_text(pw, plotx(curx, cury), ploty(curx, cury), reverse ? PIX_NOT(PIX_SRC)&PIX_DST : PIX_SRC|PIX_DST, font, s); X pr_size = pf_textwidth(strlen(s), font, s); X return pr_size.x * (hix - lox) / hor_size; X} X Xlinemod(s) Xchar *s; X{ X static short dotted[] = {1,5,0}; X static short solid[] = {1,0}; X static short longdashed[] = {10,6,0}; X static short shortdashed[] = {5,3,0}; X static short dotdashed[] = {7,3,1,3,0}; X X if (strcmp(s, "dotted") == 0) { X texture.pattern = dotted; X } else if (strcmp(s, "solid") == 0) { X texture.pattern = solid; X } else if (strcmp(s, "longdashed") == 0) { X texture.pattern = longdashed; X } else if (strcmp(s, "shortdashed") == 0) { X texture.pattern = shortdashed; X } else if (strcmp(s, "dotdashed") == 0) { X texture.pattern = dotdashed; X } X} X Xisqrt(n) X{ X int a, b, c; X X a = n; X b = n; X if (n > 1) { X while (a > 0) { X a = a >> 2; X b = b >> 1; X } X do { X a = b; X c = n / b; X b = (c + a) >> 1; X } while ((a - c) < -1 || (a - c) > 1); X } X return b; X} X Xstatic setcir(x, y, a1, b1, c1, a2, b2, c2) X{ X if (a1 * y - b1 * x >= c1 && a2 * y - b2 * x <= c2) X point(x, y); X} X Xarc(x, y, x1, y1, x2, y2) X{ X register a1 = x1 - x, b1 = y1 - y, a2 = x2 - x, b2 = y2 - y; X register c1 = a1 * y - b1 * x, c2 = a2 * y - b2 * x; X register r2 = a1 * a1 + b1 * b1; X register i, di, sqrt, dx, dy; X X dx = (hix - lox) / hor_size; X dy = (hiy - loy) / ver_size; X di = dx < dy ? dx : dy; X if (di <= 0) X di = 1; X for (i = isqrt(r2 >> 1); i >= 0; i -= di) { X sqrt = isqrt(r2 - i * i); X setcir(x + i, y + sqrt, a1, b1, c1, a2, b2, c2); X setcir(x + i, y - sqrt, a1, b1, c1, a2, b2, c2); X setcir(x - i, y + sqrt, a1, b1, c1, a2, b2, c2); X setcir(x - i, y - sqrt, a1, b1, c1, a2, b2, c2); X setcir(x + sqrt, y + i, a1, b1, c1, a2, b2, c2); X setcir(x + sqrt, y - i, a1, b1, c1, a2, b2, c2); X setcir(x - sqrt, y + i, a1, b1, c1, a2, b2, c2); X setcir(x - sqrt, y - i, a1, b1, c1, a2, b2, c2); X } X} X Xcircle(x, y, r) X{ X arc(x, y, x + r, y, x - r, y); X arc(x, y, x - r, y, x + r, y); X} X XNotify_value input_reader(me, fd) Xint *me; Xint fd; X{ X int newx, newy, x, y, r; X register char *p; X X do { X switch (getchr()) { X case 'm': /* move */ X dirty = 1; X curx = getint(); X cury = getint(); X if (curx < minx) minx = curx; X if (curx > maxx) maxx = curx; X if (cury < miny) miny = cury; X if (cury > maxy) maxy = cury; X break; X case 'n': /* cont */ X dirty = 1; X newx = getint(); X newy = getint(); X line(curx, cury, newx, newy); X curx = newx; X cury = newy; X if (curx < minx) minx = curx; X if (curx > maxx) maxx = curx; X if (cury < miny) miny = cury; X if (cury > maxy) maxy = cury; X break; X case 'p': /* point */ X dirty = 1; X curx = getint(); X cury = getint(); X point(curx, cury); X if (curx < minx) minx = curx; X if (curx > maxx) maxx = curx; X if (cury < miny) miny = cury; X if (cury > maxy) maxy = cury; X break; X case 'l': /* line */ X dirty = 1; X newx = getint(); X newy = getint(); X curx = getint(); X cury = getint(); X line(newx, newy, curx, cury); X if (newx < minx) minx = newx; X if (newx > maxx) maxx = newx; X if (newy < miny) miny = newy; X if (newy > maxy) maxy = newy; X if (curx < minx) minx = curx; X if (curx > maxx) maxx = curx; X if (cury < miny) miny = cury; X if (cury > maxy) maxy = cury; X break; X case 't': /* label */ X dirty = 1; X p = getstr(); X curx += label(p); X plptr[-1] = '\n'; X if (curx < minx) minx = curx; X if (curx > maxx) maxx = curx; X break; X case 'a': /* arc */ X dirty = 1; X x = getint(); X y = getint(); X newx = getint(); X newy = getint(); X curx = getint(); X cury = getint(); X arc(x, y, newx, newy, curx, cury); X if (x < minx) minx = x; X if (x > maxx) maxx = x; X if (y < miny) miny = y; X if (y > maxy) maxy = y; X if (newx < minx) minx = newx; X if (newx > maxx) maxx = newx; X if (newy < miny) miny = newy; X if (newy > maxy) maxy = newy; X if (curx < minx) minx = curx; X if (curx > maxx) maxx = curx; X if (cury < miny) miny = cury; X if (cury > maxy) maxy = cury; X break; X case 'c': /* circle */ X dirty = 1; X curx = getint(); X cury = getint(); X r = getint(); X circle(curx, cury, r); X if (curx - r < minx) minx = curx - r; X if (curx + r > maxx) maxx = curx + r; X if (cury - r < miny) miny = cury - r; X if (cury + r > maxy) maxy = cury + r; X break; X case 'e': /* erase */ X if (!dirty) X break; X panel_set(next_page_item, PANEL_SHOW_ITEM, TRUE, 0); X /* fall through */ X case EOF: X notify_set_input_func(me, NOTIFY_FUNC_NULL, fd); X if (zooming) { X lox = slox; X hix = shix; X loy = sloy; X hiy = shiy; X zooming = 0; X } X return NOTIFY_DONE; X case 'f': /* linemod */ X dirty = 1; X p = getstr(); X linemod(p); X plptr[-1] = '\n'; X break; X case 's': /* space */ X if (zooming) { X slox = getint(); X sloy = getint(); X shix = getint(); X shiy = getint(); X } else { X lox = getint(); X loy = getint(); X hix = getint(); X hiy = getint(); X } X break; X } X } while (plptr < plotcommands + plotlength || stdin->_cnt > 0); X return NOTIFY_DONE; X} X X/* X * button routines X */ X Xrestartplot() X{ X dirty = 0; X minx = BIG; X maxx = -BIG; X miny = BIG; X maxy = -BIG; X plptr = plotcommands; X X /* clear the canvas */ X pw_writebackground(pw, 0, 0, (int) window_get(canvas, CANVAS_WIDTH), X (int) window_get(canvas, CANVAS_HEIGHT), X reverse ? PIX_SET : PIX_CLR); X} X Xresetplot() X{ X restartplot(); X plotlength = 0; X} X Xvoid redraw() X{ X if (zooming) { X lox = slox; X hix = shix; X loy = sloy; X hiy = shiy; X zooming = 0; X } X restartplot(); X input_reader(me, fileno(stdin)); X} X Xvoid nextpage() X{ X resetplot(); X panel_set(next_page_item, PANEL_SHOW_ITEM, FALSE, 0); X notify_set_input_func(me, input_reader, fileno(stdin)); X if (stdin->_cnt > 0) X input_reader(me, fileno(stdin)); X} X Xvoid zoom() X{ X int a; X X if (!zooming) { X slox = lox; X shix = hix; X sloy = loy; X shiy = hiy; X zooming = 1; X } X if (maxx == minx) { X maxx++; X minx--; X } X if (maxy == miny) { X maxy++; X miny--; X } X if ((a = (maxx-minx) * (shiy-sloy) / (shix-slox)) >= maxy-miny) { X loy = miny - (a - maxy + miny) / 2; X hiy = loy + a; X lox = minx; X hix = maxx; X } else { X a = (maxy - miny) * (shix - slox) / (shiy - sloy); X lox = minx - (a - maxx + minx) / 2; X hix = lox + a; X loy = miny; X hiy = maxy; X } X hix++; X hiy++; X restartplot(); X input_reader(me, fileno(stdin)); X} X Xvoid quit() X{ X /* don't ask for confirmation */ X if (font) X pf_close(font); X window_set(frame, FRAME_NO_CONFIRM, TRUE, 0); X window_destroy(frame); X} X Xvoid turn() X{ X int tmp; X X turned = (turned + 1) & 3; X tmp = xmirror; X xmirror = ymirror; X ymirror = tmp; X} X Xvoid mirrorx() X{ X xmirror ^= 1; X} X Xvoid mirrory() X{ X ymirror ^= 1; X} X Xvoid canvas_fit() X{ X register int w, h; X X w = (int) window_get(canvas, WIN_WIDTH) - (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_VERTICAL_SCROLLBAR), SCROLL_THICKNESS); X h = (int) window_get(canvas, WIN_HEIGHT) - (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_HORIZONTAL_SCROLLBAR), SCROLL_THICKNESS); X if ((int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE)) { X if (w < h) X h = w; X else X w = h; X } X panel_set(hor_size_item, PANEL_VALUE, w, 0); X panel_set(ver_size_item, PANEL_VALUE, h, 0); X} X X/* X * initialization X */ X Xvoid toggle_proc() X{ X if ((int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE)) { X panel_set(ver_size_item, X PANEL_SHOW_ITEM, FALSE, X 0); X panel_set(hor_size_item, X PANEL_LABEL_STRING, "Canvas size: ", X 0); X } else { X panel_set(ver_size_item, X PANEL_SHOW_ITEM, TRUE, X 0); X panel_set(hor_size_item, X PANEL_LABEL_STRING, "Horizontal size: ", X 0); X } X} X Xvoid options() X{ X window_set(options_frame, WIN_SHOW, TRUE, 0); X} X Xvoid apply_options() X{ X register int r; X char *f; X Cursor cursor; X X square = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE); X r = (int) panel_get(hor_size_item, PANEL_VALUE); X if (r != hor_size) { X window_set(canvas, CANVAS_WIDTH, r, 0); X hor_size = r; X } X if (square) X r = hor_size; X else X r = (int) panel_get(ver_size_item, PANEL_VALUE); X if (r != ver_size) { X window_set(canvas, CANVAS_HEIGHT, r, 0); X ver_size = r; X } X f = (char *) panel_get_value(font_item); X if (f == 0 || *f == 0) { X if (font_name[0] != 0) { X font_name[0] = 0; X if (font) X pf_close(font); X font = pf_default(); X } X } else { X if (font_name[0] == 0 || strcmp(f, font_name) != 0) { X strcpy(font_name, f); X f = font_name; X if (*f != '/') { X f = malloc(strlen(font_dir)+strlen(font_name)+1); X strcpy(f, font_dir); X strcat(f, font_name); X } X if (font) X pf_close(font); X font = pf_open(f); X if (f != font_name) X free(f); X } X } X if (font == 0) { X font_name[0] = 0; X font = pf_default(); X } X make_label = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, LABEL); X reverse = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, REVERSE); X cursor = (Cursor) window_get(canvas, WIN_CURSOR); X cursor_set(cursor, X CURSOR_OP, reverse ? PIX_SRC^PIX_DST : PIX_SRC|PIX_DST, X 0); X window_set(canvas, WIN_CURSOR, cursor, 0); X redraw(); X} X Xvoid options_done() X{ X window_set(options_frame, WIN_SHOW, FALSE, 0); X apply_options(); X} X Xvoid dump() X{ X window_set(dump_frame, WIN_SHOW, TRUE, 0); X} X Xvoid do_dump() X{ X char *file; X int width, height; X register int x, y; X register char *s; X register short *p; X FILE *f; X X /* we use the fact that the canvas is retained */ X file = (char *) panel_get_value(dump_file_item); X if (file != 0 && *file != 0 && (f = fopen(file, "w")) != 0) { X width = (int) window_get(canvas, CANVAS_WIDTH); X height = (int) window_get(canvas, CANVAS_HEIGHT); X switch ((int) panel_get_value(dump_format)) { X case FORMAT_RASTER: X pr_dump(pw->pw_prretained, f, (colormap_t *) 0, X RT_STANDARD, 0); X break; X case FORMAT_ICON: X p = mpr_d(pw->pw_prretained)->md_image; X fprintf(f, "\ X/* Format_version=1, Width=%d, Height=%d, Depth=1, Valid_bits_per_item=16\n\ X */\n", (width+15) & ~15, height); X for (y = 0; y < height; y++) { X s = "\t"; X for (x = 0; x < width; x += 16) { X fprintf(f, "%s0x%04x,", s, *p & 0xFFFF); X p++; X s = ""; X } X fprintf(f, "\n"); X } X break; X case FORMAT_PLOT: X fwrite(plotcommands, 1, plotlength, f); X break; X } X fclose(f); X } X} X Xvoid dump_done() X{ X window_set(dump_frame, WIN_SHOW, FALSE, 0); X} X Xvoid fit_screen() X{ X register int w, h; X X w = hor_size + (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_VERTICAL_SCROLLBAR), SCROLL_THICKNESS); X h = ver_size + (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_HORIZONTAL_SCROLLBAR), SCROLL_THICKNESS); X window_set(canvas, WIN_WIDTH, w, WIN_HEIGHT, h, 0); X window_set(canvas, CANVAS_WIDTH, hor_size, CANVAS_HEIGHT, ver_size, 0); X window_set(panel, WIN_WIDTH, w, 0); X window_fit(frame); X} X X/* X * initialization X */ X Xvoid dump_init() X{ X register Pixrect *pr; X X dump_frame = window_create(frame, FRAME, X FRAME_DONE_PROC, dump_done, X 0); X dump_panel = window_create(dump_frame, PANEL, 0); X pr = panel_button_image(dump_panel, "Done", 0, (Pixfont *) 0); X (void) panel_create_item(dump_panel, PANEL_BUTTON, X PANEL_LABEL_IMAGE, pr, X PANEL_NOTIFY_PROC, dump_done, X 0); X pr = panel_button_image(dump_panel, "Dump", 0, (Pixfont *) 0); X (void) panel_create_item(dump_panel, PANEL_BUTTON, X PANEL_LABEL_IMAGE, pr, X PANEL_NOTIFY_PROC, do_dump, X 0); X /* order of strings is important (see definitions of FORMAT_*) */ X dump_format = panel_create_item(dump_panel, PANEL_CYCLE, X PANEL_LABEL_STRING, "Dump format:", X PANEL_CHOICE_STRINGS, "Rasterfile format", X "Icon format", X "Plot format", X (char *) 0, X 0); X dump_file_item = panel_create_item(dump_panel, PANEL_TEXT, X PANEL_LABEL_X, ATTR_COL(0), X PANEL_LABEL_Y, ATTR_ROW(1), X PANEL_VALUE_DISPLAY_LENGTH, 30, X PANEL_LABEL_STRING, "Dump to file:", X 0); X window_fit(dump_panel); X window_fit(dump_frame); X} X Xvoid options_init() X{ X register Pixrect *pr; X X options_frame = window_create(frame, FRAME, X FRAME_DONE_PROC, options_done, X 0); X options_panel = window_create(options_frame, PANEL, 0); X X pr = panel_button_image(options_panel, "Done", 0, (Pixfont *) 0); X (void) panel_create_item(options_panel, PANEL_BUTTON, X PANEL_LABEL_IMAGE, pr, X PANEL_NOTIFY_PROC, options_done, X 0); X pr = panel_button_image(options_panel, "Apply", 0, (Pixfont *) 0); X (void) panel_create_item(options_panel, PANEL_BUTTON, X PANEL_LABEL_IMAGE, pr, X PANEL_NOTIFY_PROC, apply_options, X 0); X pr = panel_button_image(options_panel, "Rotate", 0, (Pixfont*) 0); X (void) panel_create_item(options_panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, turn, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(options_panel, "X Mirror", 0, (Pixfont*) 0); X (void) panel_create_item(options_panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, mirrorx, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(options_panel, "Y Mirror", 0, (Pixfont*) 0); X (void) panel_create_item(options_panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, mirrory, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(options_panel, "Fit Canvas", 0, (Pixfont*) 0); X (void) panel_create_item(options_panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, canvas_fit, X PANEL_LABEL_IMAGE, pr, X 0); X toggle_item = panel_create_item(options_panel, PANEL_TOGGLE, X PANEL_LAYOUT, PANEL_HORIZONTAL, X PANEL_CHOICE_STRINGS, "Label", X "Square", X "Reverse", X (char *) 0, X PANEL_TOGGLE_VALUE, LABEL, make_label, X PANEL_TOGGLE_VALUE, SQUARE, square, X PANEL_TOGGLE_VALUE, REVERSE, reverse, X PANEL_NOTIFY_PROC, toggle_proc, X 0); X font_item = panel_create_item(options_panel, PANEL_TEXT, X PANEL_VALUE_DISPLAY_LENGTH, 51, X PANEL_VALUE_STORED_LENGTH, MAX_NAME_LENGTH, X PANEL_LABEL_STRING, "Font name:", X PANEL_VALUE, font_name, X 0); X hor_size_item = panel_create_item(options_panel, PANEL_SLIDER, X PANEL_LABEL_STRING, "Horizontal size: ", X PANEL_VALUE, hor_size, X PANEL_MIN_VALUE, 64, X PANEL_MAX_VALUE, 2048, X PANEL_SLIDER_WIDTH, 225, X 0); X ver_size_item = panel_create_item(options_panel, PANEL_SLIDER, X PANEL_LABEL_STRING, "Vertical size: ", X PANEL_VALUE, ver_size, X PANEL_MIN_VALUE, 64, X PANEL_MAX_VALUE, 2048, X PANEL_SLIDER_WIDTH, 225, X 0); X window_fit(options_panel); X window_fit(options_frame); X if (square) { X panel_set(ver_size_item, X PANEL_SHOW_ITEM, FALSE, X 0); X panel_set(hor_size_item, X PANEL_LABEL_STRING, "Canvas size: ", X 0); X } X} X Xvoid panel_init() X{ X register Pixrect *pr; X X panel = window_create(frame, PANEL, 0); X pr = panel_button_image(panel, "Next Page", 0, (Pixfont *) 0); X next_page_item = panel_create_item(panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, nextpage, X PANEL_LABEL_IMAGE, pr, X PANEL_SHOW_ITEM, FALSE, X 0); X pr = panel_button_image(panel, "Redraw", 0, (Pixfont *) 0); X (void) panel_create_item(panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, redraw, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(panel, "Zoom", 0, (Pixfont *) 0); X (void) panel_create_item(panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, zoom, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(panel, "Options", 0, (Pixfont *) 0); X (void) panel_create_item(panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, options, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(panel, "Dump", 0, (Pixfont *) 0); X (void) panel_create_item(panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, dump, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(panel, "Fit Screen", 0, (Pixfont *) 0); X (void) panel_create_item(panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, fit_screen, X PANEL_LABEL_IMAGE, pr, X 0); X pr = panel_button_image(panel, "Quit", 0, (Pixfont *) 0); X (void) panel_create_item(panel, PANEL_BUTTON, X PANEL_NOTIFY_PROC, quit, X PANEL_LABEL_IMAGE, pr, X 0); X window_fit_height(panel); X} X Xcanvas_init() X{ X canvas = window_create(frame, CANVAS, X CANVAS_AUTO_SHRINK, FALSE, X CANVAS_WIDTH, hor_size, X CANVAS_HEIGHT, ver_size, X CANVAS_RETAINED, TRUE, X WIN_VERTICAL_SCROLLBAR, scrollbar_create(0), X WIN_HORIZONTAL_SCROLLBAR, scrollbar_create(0), X 0); X pw = canvas_pixwin(canvas); X} X Xusage(cmd) Xchar *cmd; X{ X fprintf(stderr, "\ X%s recognizes the following options:\n\ X\t-c canvas-size\t\t(set size of canvas)\n\ X\t-h horizontal-size\t(set horizontal size of canvas)\n\ X\t-v vertical-size\t(set vertical size of canvas)\n\ X\t-f font-name\t\t(use specified font for labels)\n\ X\t-r\t\t\t(rotate 90 degrees)\n\ X\t-x\t\t\t(mirror in x axis)\n\ X\t-y\t\t\t(mirror in y axis)\n\ X\t-l\t\t\t(don't print labels)\n\ X\t-s\t\t\t(don't force canvas to be square)\n\ X\t-R\t\t\t(display in reverse video)\n\ X", cmd); X exit(1); X} X Xmain(argc, argv) Xchar **argv; X{ X Cursor cursor; X register c; X extern char *optarg; X X initplot(); X X hor_size = ver_size = INIT_CANVAS_SIZE; X frame = window_create(NULL, FRAME, X FRAME_LABEL, "Sunplot", X FRAME_SUBWINDOWS_ADJUSTABLE, FALSE, X FRAME_ICON, icon_create(ICON_IMAGE, &sunplot_icon, 0), X FRAME_ARGC_PTR_ARGV, &argc, argv, X 0); X while ((c = getopt(argc, argv, "c:h:v:lsRrxyf:")) != EOF) { X switch (c) { X case 'c': X hor_size = atoi(optarg); X if (hor_size < 64) X hor_size = 64; X ver_size = hor_size; X square = TRUE; X break; X case 'h': X hor_size = atoi(optarg); X if (hor_size < 64) X hor_size = 64; X square = FALSE; X break; X case 'v': X ver_size = atoi(optarg); X if (ver_size < 64) X ver_size = 64; X square = FALSE; X break; X case 'l': X make_label = !make_label; X break; X case 's': X square = !square; X break; X case 'R': X reverse = !reverse; X break; X case 'r': X turn(); X break; X case 'x': X mirrorx(); X break; X case 'y': X mirrory(); X break; X case 'f': X strcpy(font_name, optarg); X break; X default: X usage(argv[0]); X /*NOTREACHED*/ X } X } X dump_init(); X options_init(); X panel_init(); X canvas_init(); X if (font_name[0]) { X register char *f = font_name; X X if (*f != '/') { X f = malloc(strlen(font_dir)+strlen(font_name)+1); X strcpy(f, font_dir); X strcat(f, font_name); X } X font = pf_open(f); X if (f != font_name) X free(f); X } X if (font == 0) { X font = pf_default(); X font_name[0] = 0; X } X X fit_screen(); X X notify_set_input_func(me, input_reader, fileno(stdin)); X X linemod("solid"); X restartplot(); X cursor = (Cursor) window_get(canvas, WIN_CURSOR); X cursor_set(cursor, X CURSOR_OP, reverse ? PIX_SRC^PIX_DST : PIX_SRC|PIX_DST, X 0); X window_set(canvas, WIN_CURSOR, cursor, 0); X X window_main_loop(frame); X X exit(0); X} END_OF_FILE if test 22427 -ne `wc -c <'sunplot.c'`; then echo shar: \"'sunplot.c'\" unpacked with wrong size! fi # end of 'sunplot.c' fi if test -f 'sunplot.icon' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'sunplot.icon'\" else echo shar: Extracting \"'sunplot.icon'\" \(1933 characters\) sed "s/^X//" >'sunplot.icon' <<'END_OF_FILE' X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 X */ X 0x0000,0x0000,0x0000,0x0400,0x0000,0x0000,0x0000,0x0400, X 0x0000,0x0000,0x0000,0x0800,0x0000,0x0000,0x0000,0x0800, X 0x0000,0x0000,0x0000,0x1000,0x0000,0x0000,0x7FF0,0x1000, X 0x0000,0x0007,0x800F,0x1000,0x0000,0x0038,0x0000,0xE000, X 0x0000,0x00C0,0x0000,0x3800,0x2000,0x0300,0x0000,0x4600, X 0x1800,0x0400,0x0000,0x4100,0x07FF,0x0800,0x0000,0x8080, X 0x03FF,0xFFFC,0x0000,0x8060,0x01C1,0xFFFF,0xFFF0,0x8010, X 0x00E0,0x8037,0xFFFF,0xF008,0x0071,0x0030,0x001F,0xFE04, X 0x003A,0x0030,0x0002,0x0002,0x001E,0x0060,0x0002,0x0002, X 0x000F,0x0060,0x0002,0x0001,0x000F,0x8060,0x0004,0x0000, X 0x0011,0xC0C0,0x0004,0x0000,0x0010,0xE0C0,0x0008,0x0000, X 0x0020,0x7180,0x0008,0x0000,0x0020,0x3B80,0x0008,0x0000, X 0x0040,0x1F00,0x0010,0x0000,0x0040,0x0E00,0x0010,0x0000, X 0x0040,0x1F80,0x0020,0x0000,0x0080,0x3BC0,0x0020,0x0000, X 0x0080,0x70E0,0x0040,0x0000,0x0081,0xE070,0x0040,0x0000, X 0x0081,0xC038,0x0040,0x0000,0x0100,0x001C,0x0080,0x0000, X 0x0100,0x000E,0x0080,0x0000,0x0100,0x0007,0x0100,0x0000, X 0x0100,0x0003,0x8100,0x0000,0x0100,0x0001,0xE100,0x0000, X 0x0100,0x0000,0xF200,0x0000,0x0100,0x0000,0x3A00,0x0000, X 0x0100,0x0000,0x1C00,0x0000,0x0100,0x0000,0x0E00,0x0000, X 0x0100,0x0000,0x0F00,0x0000,0x0100,0x0000,0x0B80,0x0000, X 0x0080,0x0000,0x0980,0x0000,0x0080,0x0000,0x1040,0x0000, X 0x0080,0x0000,0x1020,0x0000,0x0080,0x0000,0x2000,0x0000, X 0x0040,0x0000,0x2000,0x0000,0x0040,0x0000,0x2000,0x0000, X 0x0FFF,0xFFFF,0xFFFF,0xFFE0,0x0924,0x9249,0x2492,0x4920, X 0x0924,0x9249,0x2492,0x4920,0x0924,0x9249,0x2492,0x4920, X 0x0800,0x0000,0x0000,0x0020,0x0800,0x0000,0x0000,0x0020, X 0x0800,0x0000,0x0000,0x0021,0x0800,0x0000,0x0000,0x0022, X 0x0800,0x0000,0x0000,0x0022,0x0800,0x0000,0x0000,0x0024, X 0x0FFF,0xFFFF,0xFFFF,0xFFE8,0x0000,0x4004,0x0000,0x0010, X 0x0000,0x3008,0x0000,0x0060,0x0000,0x0808,0x0000,0x0080, X 0x0000,0x0410,0x0000,0x0100,0x0000,0x0310,0x0000,0x0600 END_OF_FILE if test 1933 -ne `wc -c <'sunplot.icon'`; then echo shar: \"'sunplot.icon'\" unpacked with wrong size! fi # end of 'sunplot.icon' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Sjoerd Mullender e-mail: sjoerd@cwi.nl Centre for Mathematics and Computer Science, Amsterdam