STDWIN 0.9.5, Part 16/19
Guido van Rossum
guido at cwi.nl
Mon Mar 4 21:58:28 AEST 1991
Archive-name: stdwin/part16
#! /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 <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 16 (of 19)."
# Contents: Appls/bed/file.c Appls/bed/fmenu.c Appls/dpv/dpvdoc.h
# Appls/dpv/dpvmachine.c Appls/dpv/dpvmachine.h Appls/test/bike.c
# Appls/test/bits.c Appls/test/charset.c Appls/test/dklok.c
# H/lists.h H/patchlevel.h H/winreq.h Packs/vt/vtresize.c
# Packs/vt/vtvtrm.c Ports/mac/caret.c Ports/vtrm/DIST/pag.c
# Ports/x11/scroll.c
# Wrapped by guido at voorn.cwi.nl on Mon Mar 4 12:37:34 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Appls/bed/file.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/bed/file.c'\"
else
echo shar: Extracting \"'Appls/bed/file.c'\" \(2953 characters\)
sed "s/^X//" >'Appls/bed/file.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include "bed.h"
X
Xextern char *rindex () ;
X
Xextern int sqrsize ;
X
Xextern int map_width ;
Xextern int map_height ;
X
Xextern char *raster ;
Xextern int raster_lenght ;
Xextern int stride ;
X
Xextern char *fname ;
Xextern char *title ;
X
Xextern WINDOW *win ;
X
Xextern bool changed ;
X
Xchar
X*strip (fname)
X char *fname ;
X{
X char *p ;
X
X if ((p = rindex (fname, '/')) == NULL && /* UNIX */
X (p = rindex (fname, '\\')) == NULL && /* GEMDOS & MSDOS */
X (p = rindex (fname, ':')) == NULL)
X return (fname) ;
X return (p + 1) ;
X}
X
Xbool
Xinput(fp)
X FILE *fp;
X{
X int value ;
X char ibuf[81] ;
X char *id ;
X char *p ;
X char *type ;
X int i ;
X
X for (;;) {
X if (fgets (ibuf, 81, fp) == NULL)
X /*
X ** EOF
X */
X break ;
X
X if (strlen (ibuf) == 80) {
X /*
X ** Line too long, not a bitmap file
X */
X fclose (fp) ;
X return (FALSE) ;
X }
X
X if (strncmp (ibuf, "#define ", 8) == 0) {
X id = ibuf + 8 ;
X if ((type = rindex (id, '_')) == NULL)
X type = id ;
X else
X type++ ;
X
X if (!strncmp (type, "width", 5)) {
X map_width = atoi (type + 5) ;
X }
X
X if (!strncmp (type, "height", 6)) {
X map_height = atoi (type + 6) ;
X }
X
X continue ;
X }
X
X if (strncmp (ibuf, "static unsigned char ", 21) == 0)
X id = ibuf + 21 ;
X else if (strncmp (ibuf, "static char ", 12) == 0)
X id = ibuf + 12 ;
X else
X continue ;
X
X if ((type = rindex (id, '_')) == NULL)
X type = id ;
X else
X type++ ;
X
X if (strncmp (type, "bits[]", 6) != 0)
X continue ;
X
X newraster () ;
X
X for (i = 0, p = raster ; i < raster_lenght ; ++i, ++p) {
X if (fscanf (fp, " 0x%2x%*[,}]%*[ \n]", &value) != 1) {
X free (raster) ;
X raster = NULL ;
X fclose (fp) ;
X return (FALSE) ;
X }
X *p = value ;
X }
X }
X
X fclose (fp) ;
X return (TRUE) ;
X}
X
Xbool
Xreadbitmap ()
X{
X FILE *fp ;
X char namebuf[256] ;
X
X if (fname == NULL) {
X namebuf[0] = 0 ;
X
X if (!waskfile ("Read file", namebuf, sizeof (namebuf), FALSE))
X return (FALSE) ;
X
X fname = strdup (namebuf) ;
X title = strip (fname) ;
X
X wsettitle (win, title) ;
X }
X
X fp = fopen (fname, "r") ;
X if (fp == NULL) {
X perror(fname);
X return (FALSE) ;
X }
X
X return (input(fp)) ;
X}
X
Xvoid
Xoutput(fp)
X FILE *fp ;
X{
X int i ;
X
X fprintf (fp, "#define %s_width\t%d\n", title, map_width) ;
X fprintf (fp, "#define %s_height\t%d\n", title, map_height) ;
X fprintf (fp, "static char %s_bits[] {\n 0x%02x", title,
X raster[0] & 0xFF) ;
X
X for (i = 1 ; i < raster_lenght ; ++i) {
X fprintf (fp, i % 12 ? ", " : ",\n ") ;
X fprintf (fp, "0x%02x", raster[i] & 0xFF) ;
X }
X fprintf (fp, "};\n") ;
X}
X
Xbool
Xwritebitmap()
X{
X FILE *fp;
X char namebuf[256];
X
X namebuf[0] = '\0' ;
X if (fname == NULL) {
X if (!waskfile ("Save as", namebuf, sizeof (namebuf), TRUE))
X return (FALSE) ;
X fname = strdup (namebuf) ;
X title = strip (namebuf) ;
X wsettitle (win, title) ;
X }
X
X fp = fopen (fname, "w") ;
X if (fp == NULL) {
X wperror (fname) ;
X return (FALSE) ;
X }
X
X output (fp) ;
X fclose (fp) ;
X return (TRUE) ;
X}
X
END_OF_FILE
if test 2953 -ne `wc -c <'Appls/bed/file.c'`; then
echo shar: \"'Appls/bed/file.c'\" unpacked with wrong size!
fi
# end of 'Appls/bed/file.c'
fi
if test -f 'Appls/bed/fmenu.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/bed/fmenu.c'\"
else
echo shar: Extracting \"'Appls/bed/fmenu.c'\" \(2781 characters\)
sed "s/^X//" >'Appls/bed/fmenu.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include "bed.h"
X#include "menu.h"
X
Xextern char *strip () ;
X
Xextern int sqrsize ;
X
Xextern int map_width ;
Xextern int map_height ;
X
Xextern char *fname ;
Xextern char *title ;
X
Xextern WINDOW *win ;
X
Xextern char *raster ;
X
Xextern bool changed ;
X
Xvoid
Xdo_open_file ()
X{
X if (changed) {
X switch (waskync ("Save changes ?", 1)) {
X case 1:
X if (!writebitmap ())
X return ;
X break ;
X case -1 :
X return ;
X }
X
X changed = FALSE ;
X }
X if (fname != NULL) {
X free (fname) ;
X fname = title = NULL ;
X }
X
X if (!readbitmap ()) {
X if (fname != NULL) {
X free (fname) ;
X fname = title = NULL ;
X wsettitle (win, "Untitled") ;
X }
X
X newraster () ;
X }
X}
X
Xvoid
Xdo_new_map ()
X{
X char str[20] ;
X
X if (changed) {
X switch (waskync ("Save changes ?", 1)) {
X case 1 :
X if (!writebitmap ())
X return ;
X break ;
X case -1 :
X return ;
X }
X
X changed = FALSE ;
X }
X
X if (fname != NULL) {
X free (fname) ;
X fname = title = NULL ;
X wsettitle (win, "Untitled") ;
X }
X
X *str = 0 ;
X
X if (waskstr ("Enter width of new raster", str, 20)) {
X while ((map_width = atoi (str)) <= 0) {
X *str = 0 ;
X if (!waskstr ("Please enter a number greater 0",
X str, 20)) {
X map_width = -1 ;
X break ;
X }
X }
X
X if (waskstr ("Enter height of new raster", str, 20)) {
X while ((map_height = atoi (str)) <= 0) {
X *str = 0 ;
X if (!waskstr ("Please enter a number greater 0",
X str, 20))
X break ;
X }
X }
X else
X map_width = -1 ;
X }
X
X if (map_width == -1) {
X map_width = DEF_COLS ;
X map_height = DEF_ROWS ;
X }
X
X newraster () ;
X}
X
Xbool
Xdo_quit ()
X{
X if (changed) {
X switch (waskync ("Save changes ?", 1)) {
X case 1 :
X if (!writebitmap ())
X return (FALSE) ;
X break ;
X case -1 :
X return (FALSE) ;
X }
X
X changed = FALSE ;
X }
X wclose (win) ;
X free (raster) ;
X raster = NULL ;
X return (TRUE) ;
X}
X
Xbool
Xdo_file_menu (ep)
X EVENT *ep ;
X{
X switch (ep->u.m.item) {
X case OPEN_ITEM:
X do_open_file () ;
X setsqrsize () ;
X wchange (win, 0, 0, map_width * sqrsize,
X map_height * sqrsize) ;
X wsetdocsize (win, map_width * sqrsize, map_height * sqrsize) ;
X break ;
X case NEW_ITEM:
X do_new_map () ;
X setsqrsize () ;
X wchange (win, 0, 0, map_width * sqrsize,
X map_height * sqrsize) ;
X wsetdocsize (win, map_width * sqrsize, map_height * sqrsize) ;
X break ;
X case SAVE_ITEM:
X if (changed) {
X if (writebitmap ())
X changed = FALSE ;
X }
X break ;
X case SAVE_AS_ITEM: {
X char namebuf[256] ;
X
X strcpy (namebuf, fname) ;
X if (waskstr ("Save as ?", namebuf, 256, FALSE)) {
X char *savedname = fname ;
X
X fname = strdup (namebuf) ;
X title = strip (fname) ;
X (void) writebitmap () ;
X free (fname) ;
X fname = savedname ;
X title = strip (fname) ;
X }
X break ;
X }
X case QUIT_ITEM:
X return (do_quit ()) ;
X }
X
X return (FALSE) ;
X}
END_OF_FILE
if test 2781 -ne `wc -c <'Appls/bed/fmenu.c'`; then
echo shar: \"'Appls/bed/fmenu.c'\" unpacked with wrong size!
fi
# end of 'Appls/bed/fmenu.c'
fi
if test -f 'Appls/dpv/dpvdoc.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/dpv/dpvdoc.h'\"
else
echo shar: Extracting \"'Appls/dpv/dpvdoc.h'\" \(2487 characters\)
sed "s/^X//" >'Appls/dpv/dpvdoc.h' <<'END_OF_FILE'
X/* dpv -- ditroff previewer. Description of input language. */
X
X/* This isn't really a source file but disguised as one it is
X more likely to be distributed with the rest of the source */
X
X/******************************************************************************
X
X output language from ditroff:
X all numbers are character strings
X
X (These comments should suffice to write my own ditroff output
X filter, but I'm lazy... Note that the parser expects its input to
X be error-free -- it contains unchecked fscanf calls all over.
X Also it is not clear whether relative motions may have negative
X numbers as parameters. For filters descending from BWK's prototype
X this works for 'v' but not for 'h', as 'v' uses fscan but 'h'
X reads characters until it finds a non-digit... GvR)
X
X{ push environment (font, size, position)
X} pop environment
X#..\n comment
Xsn size in points
Xfn font as number from 1 to n
Xcx ascii character x
XCxyz funny char \(xyz. terminated by white space
XHn go to absolute horizontal position n
XVn go to absolute vertical position n (down is positive)
Xhn go n units horizontally (relative)
Xvn ditto vertically
Xnnc move right nn, then print c (exactly 2 digits!)
X (this wart is an optimization that shrinks output file size
X about 35% and run-time about 15% while preserving ascii-ness)
Xpn new page begins (number n) -- set v to 0
XP spread ends -- output it. (Put in by vsort).
Xnb a end of line (information only -- no action needed)
X b = space before line, a = after
Xw paddable word space -- no action needed
X
XDt ..\n draw operation 't':
X Dl x y line from here by x,y (drawing char .)
X (affects position by x, y -- GvR)
X Dc d circle of diameter d with left side here
X De x y ellipse of axes x,y with left side here
X Da x y x1 y1 arc; see drawarc in dpvoutput.c for description
X D~ x y x y ... B-spline curve by x,y then x,y ...
X
Xx ..\n device control functions:
X x i init
X x T s name of device is s
X x r n h v resolution is n/inch h = min horizontal motion, v = min vert
X x p pause (can restart)
X x s stop -- done for ever
X x t generate trailer
X x f n s font position n contains font s
X (there appears to be some disagreement whether this also
X selects s as the current font -- GvR)
X x H n set character height to n
X x S n set slant to N
X
X Subcommands like "i" are often spelled out like "init".
X
X******************************************************************************/
END_OF_FILE
if test 2487 -ne `wc -c <'Appls/dpv/dpvdoc.h'`; then
echo shar: \"'Appls/dpv/dpvdoc.h'\" unpacked with wrong size!
fi
# end of 'Appls/dpv/dpvdoc.h'
fi
if test -f 'Appls/dpv/dpvmachine.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/dpv/dpvmachine.c'\"
else
echo shar: Extracting \"'Appls/dpv/dpvmachine.c'\" \(2989 characters\)
sed "s/^X//" >'Appls/dpv/dpvmachine.c' <<'END_OF_FILE'
X/* dpv -- ditroff previewer. Ditroff virtual machine. */
X
X#include "dpv.h"
X#include "dpvmachine.h"
X#include "dpvoutput.h"
X
X/* Basic state */
X
Xint size; /* current point size */
Xint font; /* current font */
Xint hpos; /* horizontal position we are to be at next; left=0 */
Xint vpos; /* current vertical position (down positive) */
X
X/* Environment */
X
X
Xstruct state state[MAXSTATE];
Xstruct state *statep = state;
X
X/* Mounted font table */
X
Xfontinfo fonts;
Xint nfonts = 0; /* start with no fonts mounted */
X
X/* Page info */
X
Xint ipage; /* internal page number */
X
X/* Global info */
X
Xint res = 432; /* resolution for which input was prepared */
X /* default is old troff resolution */
X
X/* Load font info for font s on position n; optional file name s1 */
X
Xloadfont(n, s, s1)
X int n;
X char *s, *s1;
X{
X if (n < 0 || n > NFONTS)
X error(FATAL, "can't load font %d", n);
X fonts.name[n]= strdup(s);
X}
X
X/* Initialize device */
X
Xt_init()
X{
X /* Start somewhere */
X hpos = vpos = 0;
X size= 10;
X font= 1;
X usefont();
X}
X
X/* Begin a new block */
X
Xt_push()
X{
X if (statep >= state+MAXSTATE)
X error(FATAL, "{ nested too deep");
X statep->ssize = size;
X statep->sfont = font;
X statep->shpos = hpos;
X statep->svpos = vpos;
X ++statep;
X}
X
X/* Pop to previous state */
X
Xt_pop()
X{
X if (--statep < state)
X error(FATAL, "extra }");
X size = statep->ssize;
X font = statep->sfont;
X hpos = statep->shpos;
X vpos = statep->svpos;
X usefont();
X}
X
X/* Called at the start of a new page.
X Returns < 0 if it is time to stop. */
X
Xint
Xt_page(n)
X int n;
X{
X if (nextpage(n) < 0)
X return -1;
X vpos = hpos = 0;
X usefont();
X return 0;
X}
X
X/* Do whatever for the end of a line */
X
Xt_newline()
X{
X hpos = 0; /* because we're now back at the left margin */
X}
X
X/* Convert integer to internal size number */
X
Xt_size(n)
X int n;
X{
X return n;
X}
X
X/* Set character height to n */
X
X/*ARGSUSED*/
Xt_charht(n)
X int n;
X{
X static bool warned;
X if (!warned) {
X error(WARNING, "Setting character height not implemented");
X warned= TRUE;
X }
X}
X
X/* Set slant to n */
X
X/*ARGSUSED*/
Xt_slant(n)
X int n;
X{
X static bool warned;
X if (!warned) {
X error(WARNING, "Setting slant not implemented");
X warned= TRUE;
X }
X}
X
X/* Convert string to font number */
X
Xt_font(s)
X char *s;
X{
X return atoi(s);
X}
X
X/* Print string s as text */
X
Xt_text(s)
X char *s;
X{
X int c;
X char str[100];
X
X /* XXX This function doesn't work any more since lastw is not set */
X
X while (c = *s++) {
X if (c == '\\') {
X switch (c = *s++) {
X case '\\':
X case 'e':
X put1('\\');
X break;
X case '(':
X str[0] = *s++;
X str[1] = *s++;
X str[2] = EOS;
X put1s(str);
X break;
X }
X } else {
X put1(c);
X }
X /*hmot(lastw);*/
X }
X}
X
X/* Reset; argument is 'p' for pause, 's' for start */
X
Xt_reset(c)
X int c;
X{
X if (c == 's')
X lastpage();
X}
X
X/* Absolute vertical motion to position n */
X
Xvgoto(n)
X int n;
X{
X vpos = n;
X recheck();
X}
X
X/* Set point size to n */
X
Xsetsize(n)
Xint n;
X{
X size = n;
X usefont();
X}
X
X/* Set font to n */
X
Xsetfont(n)
Xint n;
X{
X font = n;
X usefont();
X}
END_OF_FILE
if test 2989 -ne `wc -c <'Appls/dpv/dpvmachine.c'`; then
echo shar: \"'Appls/dpv/dpvmachine.c'\" unpacked with wrong size!
fi
# end of 'Appls/dpv/dpvmachine.c'
fi
if test -f 'Appls/dpv/dpvmachine.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/dpv/dpvmachine.h'\"
else
echo shar: Extracting \"'Appls/dpv/dpvmachine.h'\" \(2383 characters\)
sed "s/^X//" >'Appls/dpv/dpvmachine.h' <<'END_OF_FILE'
X/* dpv -- ditroff previewer. Definitions for ditroff virtual machine. */
X
X/* The ditroff machine has the following state information:
X
X Basic state:
X - hpos, vpos print head position on current page
X - size current point size
X - font current font number (range 0..NFONTS-1)
X
X Environment:
X - a stack containing up to MAXSTATE copies of the basic state
X
X Mounted font table:
X - a mapping from font number to (ditroff) font names
X (i.e., which font is mounted on which logical position)
X
X Page info:
X - current page number
X
X Global info (not used much):
X - typesetter name
X - resolution assumed when preparing
X - page dimensions
X - etc.?
X
X To restart the machine at a given page, we need to save and restore
X the basic state, environment and mounted font table.
X It could be argued that at page boundaries the environment stack
X should be empty, and that the mounted font table should be initialized
X once and for ever.
X The latter isn't the case in practice; ".fp" requests can be and are
X used anywhere in ditroff source files.
X Because the environment pushes the (page-relative) position, it is
X unlikely that restoring an environment on a different page makes any
X sense, so we could assume this (and check that the input conforms).
X*/
X
X/* Array dimensions */
X
X#define NFONTS 65 /* total number of fonts usable */
X#define MAXSTATE 6 /* number of environments rememberable */
X
X/* Basic state */
X
Xextern int hpos; /* horizontal position we are to be at next; left=0 */
Xextern int vpos; /* current vertical position (down positive) */
Xextern int size; /* current point size */
Xextern int font; /* current font */
X
X#define hmot(n) hpos += n
X#define hgoto(n) hpos = n
X#define vmot(n) vgoto(vpos + (n))
Xextern vgoto();
X
X/* Environment */
X
Xstruct state {
X int ssize;
X int sfont;
X int shpos;
X int svpos;
X};
X
Xextern struct state state[MAXSTATE];
Xextern struct state *statep;
X
Xextern t_push();
Xextern t_pop();
X
X/* Mounted font table */
X
Xtypedef struct _fontinfo {
X char *name[NFONTS];
X} fontinfo;
X
Xextern fontinfo fonts; /* current mounted font table */
Xextern int nfonts; /* number of used entries (0..nfonts-1) */
X
X/* Page info */
X
Xextern int ipage; /* internal page number */
X
X/* Global typesetter info */
X
Xextern int res; /* resolution for which input was prepared */
X /* default is old troff resolution */
END_OF_FILE
if test 2383 -ne `wc -c <'Appls/dpv/dpvmachine.h'`; then
echo shar: \"'Appls/dpv/dpvmachine.h'\" unpacked with wrong size!
fi
# end of 'Appls/dpv/dpvmachine.h'
fi
if test -f 'Appls/test/bike.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/test/bike.c'\"
else
echo shar: Extracting \"'Appls/test/bike.c'\" \(2785 characters\)
sed "s/^X//" >'Appls/test/bike.c' <<'END_OF_FILE'
X#include "stdwin.h"
X#include "tilist.h"
X
X#define NFRONT 3
X#define NBACK 6
X
X#define VSTEP 50
X#define HSCALE 470
X
X#define TIPWIDTH 40
X
Xint front[NFRONT] = {28, 38, 48};
Xint back[NBACK] = {28, 24, 20, 17, 15, 13};
X
Xdouble verzet[NFRONT][NBACK];
Xdouble lowest, highest;
X
XWINDOW *win;
X
XTILIST *til;
X
XTEXTITEM *fronttips[NFRONT];
XTEXTITEM *backtips[NBACK];
X
Xcalculate()
X{
X int f, b;
X double v;
X
X lowest = 1e10;
X highest = 0.0;
X for (f = 0; f < NFRONT; ++f) {
X for (b = 0; b < NBACK; ++b) {
X v = (double)front[f] / (double)back[b];
X verzet[f][b] = v;
X if (v < lowest)
X lowest = v;
X if (v > highest)
X highest = v;
X }
X }
X}
X
Xsetuptil()
X{
X int f, b;
X int h, v;
X
X til = tilcreate(win);
X
X h = 0;
X v = 2;
X for (b = 0; b < NBACK; ++b) {
X backtips[b] = tiladd(til, h, v, h+TIPWIDTH-2, 0, 1);
X h += TIPWIDTH;
X }
X
X h = 0;
X v = 0;
X for (f = 0; f < NFRONT; ++f) {
X v += VSTEP;
X fronttips[f] = tiladd(til, h, v, h+TIPWIDTH-2, 0, 1);
X }
X
X settilvalues();
X}
X
Xsettilvalues()
X{
X int f, b;
X char buf[100];
X
X for (f = 0; f < NFRONT; ++f) {
X sprintf(buf, "%d", front[f]);
X tilsettext(fronttips[f], buf);
X }
X for (b = 0; b < NBACK; ++b) {
X sprintf(buf, "%d", back[b]);
X tilsettext(backtips[b], buf);
X }
X}
X
Xgettilvalues()
X{
X int f, b;
X char *text;
X
X for (f = 0; f < NFRONT; ++f) {
X text = tilgettext(fronttips[f]);
X sscanf(text, "%d", &front[f]);
X }
X for (b = 0; b < NBACK; ++b) {
X text = tilgettext(backtips[b]);
X sscanf(text, "%d", &back[b]);
X }
X settilvalues();
X calculate();
X wchange(win, 0, 0, 30000, 30000);
X}
X
Xvoid
Xdrawproc(win, left, top, right, bottom)
X WINDOW *win;
X int left, top, right, bottom;
X{
X int f, b;
X int h, v;
X int lasth;
X
X tildraw(til, left, top, right, bottom);
X
X v = VSTEP;
X for (f = 0; f < NFRONT; ++f) {
X for (b = 0; b < NBACK; ++b) {
X h = (verzet[f][b] - lowest) *
X (HSCALE - 2*TIPWIDTH) / (highest - lowest);
X h += 2*TIPWIDTH;
X wcprintf(50, h, v-2-wlineheight(), "%d", back[b]);
X wdrawbox(h-2, v-2, h+2, v+2);
X wcprintf(50, h, v+2, "%.2f", verzet[f][b]);
X if (b > 0) {
X wpaint(lasth+2, v-1, h-2, v+1);
X }
X lasth = h;
X }
X v += VSTEP;
X }
X}
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X winitargs(&argc, &argv);
X calculate();
X wsetdefwinsize(HSCALE + 4*wcharwidth('0'), (NFRONT+1) * VSTEP);
X win = wopen("Bike", drawproc);
X wsetdocsize(win, HSCALE + 4*wcharwidth('0'), (NFRONT+1) * VSTEP);
X setuptil();
X for (;;) {
X EVENT e;
X wgetevent(&e);
X if (tilevent(til, &e))
X continue;
X switch (e.type) {
X case WE_COMMAND:
X switch (e.u.command) {
X case WC_CLOSE:
X quit();
X /*NOTREACHED*/
X case WC_CANCEL:
X settilvalues();
X break;
X case WC_RETURN:
X gettilvalues();
X break;
X }
X break;
X case WE_CLOSE:
X quit();
X /*NOTREACHED*/
X }
X }
X}
X
Xquit()
X{
X wclose(win);
X wdone();
X exit(0);
X /*NOTREACHED*/
X}
END_OF_FILE
if test 2785 -ne `wc -c <'Appls/test/bike.c'`; then
echo shar: \"'Appls/test/bike.c'\" unpacked with wrong size!
fi
# end of 'Appls/test/bike.c'
fi
if test -f 'Appls/test/bits.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/test/bits.c'\"
else
echo shar: Extracting \"'Appls/test/bits.c'\" \(2694 characters\)
sed "s/^X//" >'Appls/test/bits.c' <<'END_OF_FILE'
X/* Here's a very simple bitmap editor.
X A window shows a magnified 64x64 bitmap
X which you can edit by clicking the mouse.
X Clicking on a bit that's off turns it on,
X clicking on one that's on turns it off.
X Drag the mouse to set or clear more bits.
X Additional facilities like saving to a file
X are left as exercises for the reader. */
X
X#include "stdwin.h"
X
X/* Bitmap dimensions */
X
X#define WIDTH 64
X#define HEIGHT 64
X
X/* The bitmap */
X
Xchar bit[WIDTH][HEIGHT];
X
X/* Magnification factors.
X (Should really be calculated from screen dimensions). */
X
Xint xscale= 5;
Xint yscale= 5;
X
X/* The window */
X
XWINDOW *win;
X
X/* Main program */
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X winitargs(&argc, &argv);
X setup();
X mainloop();
X wdone();
X exit(0);
X}
X
X/* Create the window */
X
Xsetup()
X{
X extern void drawproc(); /* Forward */
X
X wsetdefwinsize(WIDTH*xscale, HEIGHT*yscale);
X win= wopen("Bitmap Editor Demo", drawproc);
X wsetdocsize(win, WIDTH*xscale, HEIGHT*yscale);
X}
X
X/* Main event loop */
X
Xmainloop()
X{
X int value= 0;
X
X for (;;) {
X EVENT e;
X
X wgetevent(&e);
X
X switch (e.type) {
X
X case WE_MOUSE_DOWN:
X value= !getbit(e.u.where.h/xscale, e.u.where.v/yscale);
X /* Fall through to next cases */
X case WE_MOUSE_MOVE:
X case WE_MOUSE_UP:
X setbit(e.u.where.h/xscale, e.u.where.v/yscale, value);
X break;
X
X case WE_COMMAND:
X switch (e.u.command) {
X case WC_CLOSE:
X case WC_CANCEL:
X return;
X }
X
X case WE_CLOSE:
X return;
X
X }
X }
X}
X
X/* Draw procedure */
X
Xvoid
Xdrawproc(win, left, top, right, bottom)
X WINDOW *win;
X{
X#ifdef UNOPTIMIZED
X int h, v;
X
X for (v= top/yscale; v*yscale < bottom; ++v) {
X for (h= left/xscale; h*xscale < right; ++h) {
X if (getbit(h, v))
X wpaint(h*xscale, v*yscale,
X (h+1)*xscale, (v+1)*yscale);
X }
X }
X#else
X int h, v;
X int start;
X
X for (v= top/yscale; v*yscale < bottom; ++v) {
X start = -1;
X for (h= left/xscale; h*xscale < right; ++h) {
X if (getbit(h, v)) {
X if (start == -1)
X start = h;
X } else {
X if (start != -1) {
X wpaint(start*xscale, v*yscale,
X h*xscale, (v+1)*yscale);
X start = -1;
X }
X }
X }
X if (start != -1)
X wpaint(start*xscale, v*yscale, h*xscale, (v+1)*yscale);
X }
X#endif
X}
X
X/* Macro to test for bit coordinates in range */
X
X#define INRANGE(h, v) ((v) >= 0 && (v) < HEIGHT && (h) >= 0 && (h) < WIDTH)
X
X/* Return a bit's value; return 0 if outside range */
X
Xint
Xgetbit(h, v)
X{
X if (INRANGE(h, v))
X return bit[h][v];
X else
X return 0;
X}
X
X/* Change a bit's value (if in range) and arrange for it to be drawn. */
X
Xsetbit(h, v, value)
X{
X if (INRANGE(h, v) && bit[h][v] != value) {
X bit[h][v]= value;
X wchange(win, h*xscale, v*yscale, (h+1)*xscale, (v+1)*yscale);
X }
X}
END_OF_FILE
if test 2694 -ne `wc -c <'Appls/test/bits.c'`; then
echo shar: \"'Appls/test/bits.c'\" unpacked with wrong size!
fi
# end of 'Appls/test/bits.c'
fi
if test -f 'Appls/test/charset.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/test/charset.c'\"
else
echo shar: Extracting \"'Appls/test/charset.c'\" \(2954 characters\)
sed "s/^X//" >'Appls/test/charset.c' <<'END_OF_FILE'
X/* Display character set.
X usage: charset [-font font] [minchar [maxchar]] */
X
X#include "tools.h"
X#include "stdwin.h"
X
Xint minchar= 0; /* First char to draw */
Xint maxchar= 255;
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X int *which= &minchar;
X int i;
X
X winitargs(&argc, &argv);
X
X for (i= 1; i < argc; ++i) {
X if (isnumeric(argv[i])) {
X *which= atoi(argv[i]);
X which= &maxchar;
X }
X else
X break;
X }
X if (i < argc) {
X wdone();
X fprintf(stderr, "usage: %s [minchar [maxchar]]\n", argv[0]);
X exit(2);
X }
X
X if (maxchar < minchar) {
X wdone();
X fprintf(stderr, "%s: maxchar < minchar\n", argv[0]);
X exit(2);
X }
X
X setup();
X mainloop();
X wdone();
X exit(0);
X}
X
Xbool
Xisnumeric(str)
X char *str;
X{
X while (*str != EOS) {
X if (!isdigit(*str))
X return FALSE;
X ++str;
X }
X return TRUE;
X}
X
XWINDOW *win;
Xint ncols, nrows;
Xint colwidth, rowheight;
X
Xvoid drawproc(win, l, t, r, b)
X WINDOW *win;
X{
X int lineheight= wlineheight();
X int i= (t/rowheight) * ncols;
X for (; i <= maxchar-minchar; ++i) {
X int c= minchar+i;
X int col= i%ncols;
X int row= i/ncols;
X int h= col*colwidth;
X int v= row*rowheight;
X int charwidth= wcharwidth(c);
X if (v >= b)
X break;
X wdrawchar(h + (colwidth - charwidth) / 2,
X v + (rowheight - lineheight) / 2,
X c);
X }
X}
X
Xsetup()
X{
X int scrwidth, scrheight;
X int maxwidth= 1;
X int i;
X
X wgetscrsize(&scrwidth, &scrheight);
X while (minchar <= maxchar && wcharwidth(minchar) == 0)
X ++minchar;
X while (maxchar >= minchar && wcharwidth(maxchar) == 0)
X --maxchar;
X if (minchar > maxchar) {
X wdone();
X fprintf(stderr, "no chars in given range\n");
X exit(1);
X }
X for (i= minchar; i <= maxchar; i++) {
X int w= wcharwidth(i);
X if (w > maxwidth)
X maxwidth= w;
X }
X colwidth= maxwidth * 2;
X rowheight= wlineheight() * 3 / 2;
X ncols= 16;
X if ((ncols+2) * colwidth > scrwidth) {
X ncols= scrwidth/colwidth - 2;
X if (ncols < 1)
X ncols= 1;
X }
X nrows= (maxchar - minchar + ncols) / ncols;
X if (nrows < 1)
X nrows= 1;
X wsetdefwinsize(ncols*colwidth, nrows*rowheight);
X wsetmaxwinsize(ncols*colwidth, nrows*rowheight);
X win= wopen("Character Set", drawproc);
X if (win == NULL) {
X wdone();
X fprintf(stderr, "can't open window\n");
X exit(1);
X }
X (void) wmenucreate(1, "Press q to quit");
X}
X
Xmainloop()
X{
X for (;;) {
X EVENT e;
X wgetevent(&e);
X switch (e.type) {
X case WE_CHAR:
X switch (e.u.character) {
X case 'q':
X case 'Q':
X return;
X }
X break;
X case WE_COMMAND:
X switch (e.u.command) {
X case WC_CANCEL:
X case WC_CLOSE:
X wclose(win);
X return;
X }
X break;
X case WE_CLOSE:
X wclose(win);
X return;
X case WE_MOUSE_DOWN:
X charinfo(e.u.where.h, e.u.where.v);
X break;
X }
X }
X}
X
Xcharinfo(h, v)
X int h, v;
X{
X int row= v/rowheight;
X int col= h/colwidth;
X int i= minchar + row*ncols + col;
X if (i >= minchar && i <= maxchar) {
X char buf[256];
X sprintf(buf, "Char '%c' (%d. 0x%x), width %d",
X i>=' ' && i<0x7f ? i : '?', i, i, wcharwidth(i));
X wmessage(buf);
X }
X else
X wfleep();
X}
END_OF_FILE
if test 2954 -ne `wc -c <'Appls/test/charset.c'`; then
echo shar: \"'Appls/test/charset.c'\" unpacked with wrong size!
fi
# end of 'Appls/test/charset.c'
fi
if test -f 'Appls/test/dklok.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Appls/test/dklok.c'\"
else
echo shar: Extracting \"'Appls/test/dklok.c'\" \(2557 characters\)
sed "s/^X//" >'Appls/test/dklok.c' <<'END_OF_FILE'
X/* Digital clock */
X
X#ifdef ns32000
X#define void int
X#endif
X
X#include <ctype.h>
X#include <stdio.h>
X#include <time.h>
X
X#include "stdwin.h"
X
X#include "sevenseg.h"
X
Xextern long time();
X
Xint text_only; /* Non-zero on text-only device */
X
XWINDOW *win; /* Our window */
X
X#define NIMAGE 5 /* Number of chars in image */
Xchar image[NIMAGE+1]; /* Text to draw, plus trailing \0 */
X
Xint aleft, atop, aright, abottom; /* Rect in which to draw */
X
Xgetinfo()
X{
X wgetwinsize(win, &aright, &abottom);
X wsetdocsize(win, aright, abottom);
X newtime();
X}
X
Xnewtime()
X{
X unsigned long now;
X struct tm *tp;
X
X wchange(win, aleft, atop, aright, abottom);
X time(&now);
X tp= localtime(&now);
X wsettimer(win, 10 * (60 - now%60));
X sprintf(image, "%02d:%02d", tp->tm_hour, tp->tm_min);
X
X}
X
Xvoid
Xdrawdigit(digit, left, top, right, bottom, dh, dv)
X int digit;
X int left, top, right, bottom;
X int dh, dv; /* Segment thickness */
X{
X int bits= sevenseg[digit];
X int mid= (top + bottom) / 2;
X void (*func)();
X
X if (text_only)
X func= winvert;
X else
X func= wpaint;
X
X if (bits & (1<<6))
X func(left, top, right, top+dv);
X if (bits & (1<<5))
X func(left, top, left+dh, mid);
X if (bits & (1<<4))
X func(right-dh, top, right, mid);
X if (bits & (1<<3))
X func(left, mid-dv/2, right, mid+dv-dv/2);
X if (bits & (1<<2))
X func(left, mid, left+dh, bottom);
X if (bits & (1<<1))
X func(right-dh, mid, right, bottom);
X if (bits & (1<<0))
X func(left, bottom-dv, right, bottom);
X}
X
Xvoid
Xdrawproc(win, left, top, right, bottom)
X WINDOW *win;
X int left, top, right, bottom;
X{
X int width= aright - aleft;
X int height= abottom - atop;
X int dh= width / (NIMAGE*6 + 1);
X int dv= height / 9;
X int spacing;
X int i;
X
X if (dh < 1)
X dh= 1;
X if (dv < 1)
X dv= 1;
X
X spacing= dh*6;
X
X for (i= 0; i < NIMAGE && image[i] != '\0'; ++i) {
X if (isdigit(image[i])) {
X drawdigit(image[i] - '0',
X aleft + dh + i*spacing, atop + dv,
X aleft + dh + (i+1)*spacing - dh, abottom - dv,
X dh, dv);
X }
X }
X}
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X winitargs(&argc, &argv);
X setup();
X mainloop();
X wdone();
X exit(0);
X}
X
Xsetup()
X{
X if (wlineheight() == 1) {
X text_only= 1;
X wmessage("Text-only version");
X }
X win= wopen("DIGITAL CLOCK", drawproc);
X getinfo();
X}
X
Xmainloop()
X{
X for (;;) {
X EVENT e;
X wgetevent(&e);
X switch (e.type) {
X case WE_COMMAND:
X switch (e.u.command) {
X case WC_CLOSE:
X case WC_CANCEL:
X wclose(win);
X return 0;
X }
X break;
X case WE_CLOSE:
X wclose(win);
X return 0;
X case WE_SIZE:
X getinfo();
X break;
X case WE_TIMER:
X newtime();
X break;
X }
X }
X}
END_OF_FILE
if test 2557 -ne `wc -c <'Appls/test/dklok.c'`; then
echo shar: \"'Appls/test/dklok.c'\" unpacked with wrong size!
fi
# end of 'Appls/test/dklok.c'
fi
if test -f 'H/lists.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'H/lists.h'\"
else
echo shar: Extracting \"'H/lists.h'\" \(3065 characters\)
sed "s/^X//" >'H/lists.h' <<'END_OF_FILE'
X/* Package to manipulate dynamic arrays represented like
X argc/argv (but not necessarily containing character pointers).
X Operations provided are macros that expand to groups of statements;
X their arguments should be side-effect-free. The arguments argc and
X argv should be single identifiers, since they are assigned to.
X (L_DECLARE expands to a series of declarations.)
X
X This code was written because I found myself writing code very
X similar to it times and times over, or, worse, using fixed-length
X arrays out of laziness. It's slow for large arrays (although this
X could be improved easily by rounding up the sizes passed to
X malloc/realloc), but this shouldn't be a problem for the applications
X I am currently using it for. It sure helped me write some array
X processing code faster.
X
X Operations:
X
X L_DECLARE(argc, argv, type) declare a list with element type 'type'
X L_INIT(argc, argv) initialize a list
X L_DEALLOC(argc, argv) deallocate a list
X L_SETSIZE(argc, argv, type, size) set list to size 'size'
X L_EXTEND(argc, argv, type, count) append 'count' unitinialized elements
X L_APPEND(argc, argv, type, elem) append a given element
X L_REMOVE(argc, argv, type, index) remove element number 'index'
X L_INSERT(argc, argv, type, index, elem) insert 'elem' at 'index'
X L_SORT(argc, argv, type, compare) sort the list ('compare' is a function)
X
X (There should also be operations to insert in the middle and to
X remove elements.)
X
X NB: the 'type' argument could be discarded (except for L_DECLARE)
X if we could live with warnings about assignments from malloc/realloc
X to other pointer types.
X
X*/
X
X/* This file only works when included by "stdwtools.h" !!! */
X
X/* You could define GOOD_REALLOC if your realloc() calls malloc() when
X passed a NULL pointer */
X
X#ifdef GOOD_REALLOC
X#define _REALLOC(p, size) realloc(p, size)
X#else
X#define _REALLOC(p, size) ((p) ? realloc(p, size) : malloc(size))
X#endif
X
X#define L_DECLARE(argc, argv, type) int argc = 0; type *argv = 0
X
X#define L_INIT(argc, argv) argc = 0; argv = 0
X
X#define L_DEALLOC(argc, argv) argc = 0; FREE(argv)
X
X#define L_SETSIZE(argc, argv, type, size) \
X argv = (type *) _REALLOC((UNIVPTR) argv, \
X (unsigned) (size) * sizeof(type)); \
X argc = (argv == 0) ? 0 : size
X
X#define L_EXTEND(argc, argv, type, count) \
X L_SETSIZE(argc, argv, type, argc+count)
X
X#define L_APPEND(argc, argv, type, elem) \
X argv = (type *) _REALLOC((UNIVPTR) argv, \
X (unsigned) (argc+1) * sizeof(type)); \
X if (argv == 0) \
X argc = 0; \
X else \
X argv[argc++] = elem
X
X#define L_REMOVE(argc, argv, type, index) \
X { \
X int k_; \
X for (k_ = index+1; k_ < argc; ++k_) \
X argv[k_-1] = argv[k_]; \
X L_SETSIZE(argc, argv, type, argc-1); \
X }
X
X#define L_INSERT(argc, argv, type, index, item) \
X { \
X int k_; \
X L_SETSIZE(argc, argv, type, argc+1); \
X for (k_ = argc-1; k_ > index; --k_) \
X argv[k_] = argv[k_-1]; \
X argv[index] = item; \
X }
X
X#define L_SORT(argc, argv, type, compare) \
X qsort((UNIVPTR)argv, argc, sizeof(type), compare)
END_OF_FILE
if test 3065 -ne `wc -c <'H/lists.h'`; then
echo shar: \"'H/lists.h'\" unpacked with wrong size!
fi
# end of 'H/lists.h'
fi
if test -f 'H/patchlevel.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'H/patchlevel.h'\"
else
echo shar: Extracting \"'H/patchlevel.h'\" \(21 characters\)
sed "s/^X//" >'H/patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL 5
END_OF_FILE
if test 21 -ne `wc -c <'H/patchlevel.h'`; then
echo shar: \"'H/patchlevel.h'\" unpacked with wrong size!
fi
# end of 'H/patchlevel.h'
fi
if test -f 'H/winreq.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'H/winreq.h'\"
else
echo shar: Extracting \"'H/winreq.h'\" \(3052 characters\)
sed "s/^X//" >'H/winreq.h' <<'END_OF_FILE'
X/* STDWIN Server -- Window (Manager) Requests. */
X
X/* Command codes in transaction header. */
X
X#define WIN_FIRST 1100
X
X#define WIN_HELLO (WIN_FIRST+1) /* Say hello to server */
X#define WIN_DROPDEAD (WIN_FIRST+2) /* Die, if idle */
X#define WIN_OPEN (WIN_FIRST+3) /* Open new window */
X#define WIN_CLOSE (WIN_FIRST+4) /* Close window */
X#define WIN_DRAW (WIN_FIRST+5) /* Drawing commands; see subcodes */
X#define WIN_GETEVENT (WIN_FIRST+6) /* Get event */
X#define WIN_FLEEP (WIN_FIRST+7) /* Flash or beep */
X#define WIN_ACTIVATE (WIN_FIRST+8) /* Make window active */
X#define WIN_SETDOCSIZE (WIN_FIRST+9) /* Set document size */
X#define WIN_SETTITLE (WIN_FIRST+10) /* Set window title */
X#define WIN_SHOW (WIN_FIRST+11) /* Show part of document */
X#define WIN_SETORIGIN (WIN_FIRST+12) /* Set window origin in document */
X#define WIN_CHANGE (WIN_FIRST+13) /* Change part of document */
X#define WIN_SCROLL (WIN_FIRST+14) /* Scroll part of document */
X#define WIN_MESSAGE (WIN_FIRST+15) /* Output message */
X#define WIN_ASKSTR (WIN_FIRST+16) /* Ask string */
X#define WIN_ASKYNC (WIN_FIRST+17) /* Ask yes/no/cancel question */
X#define WIN_SETCARET (WIN_FIRST+18) /* Set caret position */
X#define WIN_STATUS (WIN_FIRST+19) /* Get window status */
X#define WIN_GETFONTTAB (WIN_FIRST+20) /* Get font width table */
X#define WIN_SETTIMER (WIN_FIRST+21) /* Set window timer */
X#define WIN_SETCLIP (WIN_FIRST+22) /* Set clipboard string */
X#define WIN_GETCLIP (WIN_FIRST+23) /* Get clipboard string */
X#define WIN_POLLEVENT (WIN_FIRST+24) /* Poll for event */
X
X#define MENU_FIRST (WIN_FIRST+50)
X
X#define MENU_CREATE (MENU_FIRST+1)
X#define MENU_DELETE (MENU_FIRST+2)
X#define MENU_ADDITEM (MENU_FIRST+3)
X#define MENU_SETITEM (MENU_FIRST+4)
X#define MENU_ATTACH (MENU_FIRST+5)
X#define MENU_DETACH (MENU_FIRST+6)
X#define MENU_ENABLE (MENU_FIRST+7)
X#define MENU_CHECK (MENU_FIRST+8)
X
X
X/* Subcodes in data buffer for WIN_DRAW. */
X
X#define DRW_LINE 1
X#define DRW_BOX 2
X#define DRW_CIRCLE 3
X#define DRW_ERASE 4
X#define DRW_PAINT 5
X#define DRW_SHADE 6
X#define DRW_INVERT 7
X#define DRW_TEXT 8
X#define DRW_FONT 9
X#define DRW_STYLE 10
X#define DRW_ELARC 11
X#define DRW_XORLINE 12
X
X/* Error codes for h_status. */
X
X#define WER_OK 0 /* ok */
X#define WER_FAIL -101 /* don't know why it failed */
X#define WER_COMBAD -102 /* bad command */
X#define WER_CAPBAD -103 /* bad capability */
X#define WER_NOSPACE -104 /* no space left */
X#define WER_ABORT -105 /* call aborted */
X#define WER_NODATA -106 /* No or insufficient data provided */
X
X/* Event packing parameters.
X (This is a kludge! Should be variable-length and have a length byte
X in the data!) */
X
X#define EVSHORTS 7
X#define EVPACKSIZE (EVSHORTS * sizeof(short))
X
X/* Server's buffer size. */
X
X#define SVRBUFSIZE 4096
X /* I suppose this should really be negotiated between server and
X client, e.g., WIN_HELLO should return the server's buffer
X size. */
X
X/* Font width table length. */
X
X#define FONTTABLEN 256 /* Number of chars in a font */
X
X/* Pseudo-event sent when SIGAMOEBA received */
X
X#define WE_ALERT 22
END_OF_FILE
if test 3052 -ne `wc -c <'H/winreq.h'`; then
echo shar: \"'H/winreq.h'\" unpacked with wrong size!
fi
# end of 'H/winreq.h'
fi
if test -f 'Packs/vt/vtresize.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Packs/vt/vtresize.c'\"
else
echo shar: Extracting \"'Packs/vt/vtresize.c'\" \(3023 characters\)
sed "s/^X//" >'Packs/vt/vtresize.c' <<'END_OF_FILE'
X/* Resize function */
X
X#include "vtimpl.h"
X
X/* Resize the screen.
X When growing, blanks are added to the right and/or at the top (!);
X when shrinking, characters are lost at those edges.
X It is really a disaster if we run out of memory halfway
X (much more so than in vtopen);
X in this case the caller should immediately call vtclose,
X and expect some memory leaks... */
X
Xbool
Xvtresize(vt, rows, cols, save)
X VT *vt;
X int rows, cols;
X int save;
X{
X int rowdiff;
X int i;
X
X rows += save;
X rowdiff = rows - vt->rows;
X if (cols != vt->cols) {
X if (cols < vt->cols) {
X /* Clear the corresponding screen area */
X vtchange(vt, 0, cols, vt->rows, vt->cols);
X vt->cols = cols;
X }
X i = vt->rows;
X if (rows < i)
X i = rows;
X while (--i >= 0) {
X if (!RESIZE(vt->data[i], char, cols))
X return FALSE;
X if (!RESIZE(vt->flags[i], unsigned char, cols))
X return FALSE;
X if (vt->llen[i] > cols)
X vt->llen[i] = cols;
X }
X if (cols > vt->cols) {
X /* Clear the corresponding screen area */
X vtchange(vt, 0, vt->cols, rows, cols);
X vt->cols = cols;
X }
X }
X
X if (rowdiff != 0) {
X if (rowdiff < 0) {
X /* Get the last line into its new position */
X vtscrollup(vt, 0, vt->rows, -rowdiff);
X /* Free the excess lines */
X for (i = rows; i < vt->rows; ++i) {
X FREE(vt->data[i]);
X FREE(vt->flags[i]);
X }
X /* Clear the corresponding screen area */
X vtchange(vt, rows, 0, vt->rows, cols);
X vt->rows = rows;
X }
X
X if (!RESIZE(vt->data, char *, rows))
X return FALSE;
X if (!RESIZE(vt->flags, unsigned char *, rows))
X return FALSE;
X if (!RESIZE(vt->llen, short, rows))
X return FALSE;
X
X if (rowdiff > 0) {
X /* Add new lines */
X for (i = vt->rows; i < rows; ++i) {
X if ((vt->data[i] = NALLOC(char, cols)) == NULL)
X return FALSE;
X if ((vt->flags[i] = NALLOC(unsigned char, cols)) == NULL)
X return FALSE;
X vt->llen[i] = 0;
X }
X /* Clear the corresponding screen area */
X vtchange(vt, vt->rows, 0, rows, cols);
X vt->rows = rows;
X /* Get the last line into its new position */
X vtscrolldown(vt, 0, rows, rowdiff);
X }
X }
X
X if (rowdiff != 0 || save != vt->topterm) {
X vt->topterm = save;
X vtsetscroll(vt, 0, 0); /* Reset scrolling region */
X }
X
X wsetdocsize(vt->win,
X vt->cols * vt->cwidth, vt->rows * vt->cheight);
X
X i = vt->cur_row + rowdiff;
X CLIPMIN(i, save);
X vtsetcursor(vt, i, vt->cur_col);
X
X return TRUE;
X}
X
X/* Adapt the screen size to the new window dimensions.
X The 'save' parameter is computed so as to keep the total amount
X of rows the same (if possible).
X Return value as for vtresize (i.e., FALSE is a disaster). */
X
Xbool
Xvtautosize(vt)
X VT *vt;
X{
X int width, height;
X int newrows, newcols, newsave;
X wgetwinsize(vt->win, &width, &height);
X newrows = height / vt->cheight;
X newcols = width / vt->cwidth;
X newsave = vt->rows - newrows;
X D( printf("vtautosize: size now %dx%d (char = %dx%d) => %dx%d\n",
X width,height, vt->cwidth,vt->cheight, newrows,newcols) );
X CLIPMIN(newsave, 0);
X return vtresize(vt, newrows, newcols, newsave);
X}
END_OF_FILE
if test 3023 -ne `wc -c <'Packs/vt/vtresize.c'`; then
echo shar: \"'Packs/vt/vtresize.c'\" unpacked with wrong size!
fi
# end of 'Packs/vt/vtresize.c'
fi
if test -f 'Packs/vt/vtvtrm.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Packs/vt/vtvtrm.c'\"
else
echo shar: Extracting \"'Packs/vt/vtvtrm.c'\" \(2629 characters\)
sed "s/^X//" >'Packs/vt/vtvtrm.c' <<'END_OF_FILE'
X/* VTRM implementation using VT as lower layer.
X Unfortunately, this isn't too useful on the input part:
X you'll really want to use wgetevent directly to get access
X to mouse clicks, menu events etc.
X Another problem is that there is no portable way to direct normal
X output (e.g., from printf and putchar) to the VTRM window.
X One other thing: you'll have to call wdone() when you really exit. */
X
X/* XXX This has never been tested... */
X
X#include "vtimpl.h"
X#include "vtrm.h"
X
Xstatic VT *vt;
Xstatic bool active;
X
Xint
Xtrmstart(rows_return, cols_return, flags_return)
X int *rows_return, *cols_return, *flags_return;
X{
X if (active)
X return TE_TWICE; /* Already started */
X if (vt == NULL) {
X winit();
X wsetdefwinsize(24*wcharwidth('0'), 80*wlineheight());
X vt= vtopen("VTRM", 24, 80, 0);
X if (vt == NULL)
X return TE_NOMEM; /* Failure */
X }
X *rows_return= 24;
X *cols_return= 80;
X *flags_return=
X HAS_STANDOUT | CAN_SCROLL | CAN_SENSE;
X return TE_OK;
X}
X
Xtrmend()
X{
X active= FALSE;
X}
X
Xtrmputdata(row, col, data)
X int row, col;
X char *data;
X{
X char *start= data;
X int mask= 0;
X vtsetcursor(vt, row, col);
X do {
X if ((*data & 0x80) != mask) {
X if (data > start) {
X if (mask) {
X char *p;
X for (p= start; p < data; ++p)
X *p &= 0x7f;
X vt->gflags= VT_INVERSE;
X }
X vtputstring(vt, start, data-start);
X if (mask) {
X char *p;
X for (p= start; p < data; ++p)
X *p |= 0x80;
X vt->gflags= 0;
X }
X start= data;
X }
X mask= *data & 0x80;
X }
X } while (*data++ != EOS);
X /* XXX This is likely to omit the final data? */
X vteolclear(vt, vt->cur_row, vt->cur_col);
X}
X
Xtrmscrollup(r1, r2, n)
X int r1, r2;
X int n;
X{
X if (n > 0)
X vtscrollup(vt, r1, r2+1, n);
X else if (n < 0)
X vtscrolldown(vt, r1, r2+1, -n);
X}
X
Xtrmsync(row, col)
X int row, col;
X{
X vtsetcursor(vt, row, col);
X}
X
Xstatic lasth, lastv;
X
Xint
Xtrminput()
X{
X EVENT e;
X for (;;) {
X switch (e.type) {
X case WE_COMMAND:
X switch (e.type) {
X case WC_CANCEL:
X return '\003';
X case WC_RETURN:
X return '\r';
X case WC_TAB:
X return '\t';
X case WC_BACKSPACE:
X return '\b';
X case WC_LEFT:
X return '\034';
X case WC_RIGHT:
X return '\035';
X case WC_UP:
X return '\036';
X case WC_DOWN:
X return '\037';
X }
X break;
X case WE_CHAR:
X return e.u.character;
X break;
X case WE_MOUSE_DOWN:
X case WE_MOUSE_MOVE:
X case WE_MOUSE_UP:
X lasth= e.u.where.h;
X lastv= e.u.where.v;
X if (e.type == WE_MOUSE_UP)
X return '\007';
X break;
X }
X }
X}
X
Xint
Xtrmsense(row_return, col_return)
X int *row_return, *col_return;
X{
X *row_return= lastv / vtcheight(vt);
X *col_return= lasth / vtcwidth(vt);
X}
END_OF_FILE
if test 2629 -ne `wc -c <'Packs/vt/vtvtrm.c'`; then
echo shar: \"'Packs/vt/vtvtrm.c'\" unpacked with wrong size!
fi
# end of 'Packs/vt/vtvtrm.c'
fi
if test -f 'Ports/mac/caret.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/mac/caret.c'\"
else
echo shar: Extracting \"'Ports/mac/caret.c'\" \(2827 characters\)
sed "s/^X//" >'Ports/mac/caret.c' <<'END_OF_FILE'
X/* MAC STDWIN -- TEXT CARET HANDLING. */
X
X/* The 'caret' is a blinking vertical bar indicating the text insertion point.
X Each window has its own caret position (hcaret, vcaret) telling where the
X insertion point is; if either is negative no caret is shown.
X Only the caret of the active window is actually visible.
X The blinking is done by repeatedly calling (in the event loop when idling)
X blinkcaret(), which flips the caret's state if it's been stable long enough.
X The file-static variable lastflip records when the caret has last changed
X state.
X A struct member caret_on indicates per window whether the caret is
X currently drawn or not. (A file-static variable would really suffice.)
X
X NB: all routines except w{set,no}caret assume win->w is the current GrafPort.
X*/
X
X#include "macwin.h"
X
X#ifdef MPW
X#include <Events.h>
X#endif
X
X/* Function prototypes */
XSTATIC void invertcaret _ARGS((WINDOW *win));
XSTATIC void flipcaret _ARGS((WINDOW *win));
X
Xstatic long lastflip = 0; /* Time when the caret last blinked */
X
X/* Invert the caret's pixels. */
X
Xstatic void
Xinvertcaret(win)
X WINDOW *win;
X{
X Rect r;
X FontInfo finfo;
X
X if (win->hcaret < 0 || win->vcaret < 0)
X return;
X GetFontInfo(&finfo);
X makerect(win, &r,
X win->hcaret-1,
X win->vcaret,
X win->hcaret,
X win->vcaret + finfo.leading + finfo.ascent + finfo.descent);
X InvertRect(&r);
X}
X
X/* Flip the caret state, if the window has a caret.
X Also set lastflip, so blinkcaret() below knows when to flip it again. */
X
Xstatic void
Xflipcaret(win)
X WINDOW *win;
X{
X if (win->hcaret < 0 || win->vcaret < 0)
X return;
X invertcaret(win);
X win->caret_on = !win->caret_on;
X lastflip= TickCount();
X}
X
X/* Make sure the caret is invisible.
X This is necessary before operations like handling mouse clicks,
X bringing up dialog boxes, or when the window goes inactive. */
X
Xvoid
Xrmcaret(win)
X WINDOW *win;
X{
X if (win->caret_on)
X flipcaret(win);
X}
X
X/* Blink the caret, if there is one.
X This should be called sufficiently often from the main event loop.
X We only blink if enough ticks have passed since the last flip,
X whether caused by us or by an explicit call to rmcaret(). */
X
Xvoid
Xblinkcaret(win)
X WINDOW *win;
X{
X if (win->hcaret < 0 || win->vcaret < 0)
X return;
X if (TickCount() >= lastflip + GetCaretTime())
X flipcaret(win);
X}
X
X/* User-callable routine to specify the caret position.
X The caret is not drawn now, but when the next blink is due. */
X
Xvoid
Xwsetcaret(win, h, v)
X WINDOW *win;
X int h, v;
X{
X SetPort(win->w);
X rmcaret(win);
X win->hcaret = h;
X win->vcaret = v;
X}
X
X/* User-callable routine to specify that the window has no caret.
X This is indicated by setting (hcaret, vcaret) to (-1, -1). */
X
Xvoid
Xwnocaret(win)
X WINDOW *win;
X{
X SetPort(win->w);
X rmcaret(win); /* See remark in wsetcaret() */
X win->hcaret = win->vcaret= -1;
X}
END_OF_FILE
if test 2827 -ne `wc -c <'Ports/mac/caret.c'`; then
echo shar: \"'Ports/mac/caret.c'\" unpacked with wrong size!
fi
# end of 'Ports/mac/caret.c'
fi
if test -f 'Ports/vtrm/DIST/pag.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/vtrm/DIST/pag.c'\"
else
echo shar: Extracting \"'Ports/vtrm/DIST/pag.c'\" \(2582 characters\)
sed "s/^X//" >'Ports/vtrm/DIST/pag.c' <<'END_OF_FILE'
X/* VTRM example -- a trivial pager.
X There are zillions of things this pager doesn't do, or would
X crash on, but it is a nice demonstration of the use of VTRM. */
X
X#include <stdio.h>
X
Xchar *index();
X
X#define CTRL(c) ((c)&0x1F)
X
X#include "trm.h"
X
Xint lines, columns, flags;
XFILE *fp;
X
X/* Main program -- scan arguments, open file, set-up VTRM, main loop. */
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X int n, c;
X
X if (argc != 2) {
X fprintf(stderr, "usage: %s file\n", argv[0]);
X exit(2);
X }
X
X if ((fp= fopen(argv[1], "r")) == NULL) {
X perror(argv[1]);
X exit(1);
X }
X
X if ((n= trmstart(&lines, &columns, &flags)) != 0) {
X fprintf(stderr, "trmstart error %d\n", n);
X exit(3);
X }
X
X page();
X
X for (;;) {
X prompt();
X c= trminput();
X
X switch (c) {
X
X case ' ': /* Display one more page */
X page();
X break;
X
X case '\n': /* Display one more line */
X case '\r':
X line();
X break;
X
X case 'q': /* Quit */
X case CTRL('C'): /* or Interrupt */
X trmputdata(lines-1, lines-1, 0, "");
X trmsync(lines-1, 0);
X trmend();
X exit(2);
X
X case CTRL('Z'): /* Suspend */
X trmputdata(lines-1, lines-1, 0, "");
X trmsync(lines-1, 0);
X trmend();
X trmsuspend();
X if (trmstart(&lines, &columns, &flags))
X exit(3);
X page();
X break;
X
X default: /* Error */
X trmbell();
X break;
X
X }
X }
X}
X
Xint left; /* Lines left on current page */
X
X/* Output one page, using line() as a subroutine.
X BUG: if the last line takes up more space than available, it is
X displayed in its entirety, scrolling up more than a page in total. */
X
Xpage()
X{
X left= lines-1;
X do {
X line();
X } while (left > 0);
X}
X
X/* Output one line. The line is displayed at the bottom,
X assuming the botom line of the screen is free.
X Update count of lines left on display. Exit if EOF hit. */
X
Xline()
X{
X char linebuf[BUFSIZ];
X char *p;
X int n;
X
X if (fgets(linebuf, sizeof linebuf, fp) == NULL) {
X trmend();
X exit(0);
X }
X if (p= index(linebuf, '\n'))
X *p= '\0';
X n= need(linebuf);
X trmscrollup(0, lines-1, n);
X trmputdata(lines-n-1, lines-2, 0, linebuf);
X left -= n;
X}
X
X/* Compute the number of screen lines required.
X Assumes only printing characters. */
X
Xneed(buf)
X char *buf;
X{
X int len= strlen(buf);
X
X if (len == 0)
X return 1;
X else
X return (len+columns-1) / columns;
X}
X
X/* Issue a prompt on the bottom line.
X Assumes this line is already free. */
X
Xprompt()
X{
X static int beenhere= 0;
X static char pr[]= "--More--";
X
X if (!beenhere++) {
X char *p;
X
X for (p= pr; *p; ++p)
X *p |= 0x80;
X }
X trmputdata(lines-1, lines-1, 0, pr);
X trmsync(lines-1, strlen(pr));
X}
END_OF_FILE
if test 2582 -ne `wc -c <'Ports/vtrm/DIST/pag.c'`; then
echo shar: \"'Ports/vtrm/DIST/pag.c'\" unpacked with wrong size!
fi
# end of 'Ports/vtrm/DIST/pag.c'
fi
if test -f 'Ports/x11/scroll.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Ports/x11/scroll.c'\"
else
echo shar: Extracting \"'Ports/x11/scroll.c'\" \(2894 characters\)
sed "s/^X//" >'Ports/x11/scroll.c' <<'END_OF_FILE'
X/* X11 STDWIN -- Scroll bars */
X
X#include "x11.h"
X
X#define IMARGIN 2 /* See window.c */
X
X/* Macro to compute the thumb position and size.
X Don't call when docwidth (docheight) is zero. */
X
X/* dir is x or y; dim is width or height; bar is hbar or vbar */
X#define BARCOMPUTE(dir, dim, bar) { \
X range= win->bar.dim; \
X start= range * (-win->wa.dir) / win->doc.dim; \
X size= range * win->wi.dim / win->doc.dim; \
X _wdebug(4, "BARCOMPUTE: start=%d, size=%d", start, size); \
X }
X
X/* Functions to draw the scroll bars.
X Currently, the thumb is a rectangle separated by the scroll bar's
X borders by a one-pixel wide space */
X
X_wdrawhbar(win)
X WINDOW *win;
X{
X _wdebug(3, "draw hbar");
X XClearWindow(_wd, win->hbar.wid);
X if (win->doc.width > win->wi.width) {
X int start, size, range;
X BARCOMPUTE(x, width, hbar);
X XSetTile(_wd, win->gc, _w_gray());
X XSetFillStyle(_wd, win->gc, FillTiled);
X XFillRectangle(_wd, win->hbar.wid, win->gc,
X start + 1, 1, size - 1, win->hbar.height - 2);
X XSetFillStyle(_wd, win->gc, FillSolid);
X }
X}
X
X_wdrawvbar(win)
X WINDOW *win;
X{
X _wdebug(3, "draw vbar");
X XClearWindow(_wd, win->vbar.wid);
X if (win->doc.height > win->wi.height) {
X int start, size, range;
X BARCOMPUTE(y, height, vbar);
X XSetTile(_wd, win->gc, _w_gray());
X XSetFillStyle(_wd, win->gc, FillTiled);
X XFillRectangle(_wd, win->vbar.wid, win->gc,
X 1, start + 1, win->vbar.width - 2, size - 1);
X XSetFillStyle(_wd, win->gc, FillSolid);
X }
X}
X
X/* Functions to interpret scroll bar hits.
X Matching the Toolkit scroll bars, we should implement:
X - button 1: scroll forward, amount determined by position
X - button 2: position scroll bar begin at pointer
X - buttom 3: scroll back, amount determined by position
X*/
X
X/* dir is x or y; dim is width or height; bar is hbar or vbar;
X drawcall is _wdraw{h,v}bar; imargin is IMARGIN or 0. */
X#define HITCODE(dir, dim, bar, drawcall, imargin) { \
X WINDOW *win= bsp->win; \
X int start, size, range, nstart; \
X if (win->doc.dim <= win->wi.dim - imargin) \
X return; \
X BARCOMPUTE(dir, dim, bar); \
X switch (bsp->button) { \
X case 1: \
X if (bsp->down) return; \
X nstart= start + \
X (bsp->dir * win->wi.dim + win->doc.dim/2) \
X / win->doc.dim; \
X break; \
X default: \
X nstart= bsp->dir; \
X break; \
X case 3: \
X if (bsp->down) return; \
X nstart= start - \
X (bsp->dir * win->wi.dim + win->doc.dim/2) \
X / win->doc.dim; \
X break; \
X } \
X CLIPMAX(nstart, range-size); \
X CLIPMIN(nstart, 0); \
X if (nstart != start) { \
X win->wa.dir= \
X -(nstart * win->doc.dim / win->bar.dim); \
X _wmove(&win->wa); \
X drawcall(win); \
X } \
X }
X
X_whithbar(bsp, ep)
X struct button_state *bsp;
X EVENT *ep;
X{
X _wdebug(3, "hit hbar");
X HITCODE(x, width, hbar, _wdrawhbar, IMARGIN);
X}
X
X_whitvbar(bsp, ep)
X struct button_state *bsp;
X EVENT *ep;
X{
X _wdebug(3, "hit vbar");
X HITCODE(y, height, vbar, _wdrawvbar, 0);
X}
END_OF_FILE
if test 2894 -ne `wc -c <'Ports/x11/scroll.c'`; then
echo shar: \"'Ports/x11/scroll.c'\" unpacked with wrong size!
fi
# end of 'Ports/x11/scroll.c'
fi
echo shar: End of archive 16 \(of 19\).
cp /dev/null ark16isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 19 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
More information about the Alt.sources
mailing list