home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume10
/
calctool24
/
part03
< prev
next >
Wrap
Text File
|
1990-01-15
|
46KB
|
1,275 lines
Newsgroups: comp.sources.misc
subject: v10i008: Calctool V2.4 - a simple calculator (Part 3 of 6).
from: richb@Aus.Sun.COM (Rich Burridge)
Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
Posting-number: Volume 10, Issue 8
Submitted-by: richb@Aus.Sun.COM (Rich Burridge)
Archive-name: calctool24/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 functions.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 functions.c"
sed 's/^X//' << 'SHAR_EOF' >> functions.c
X break ;
X case CCTRL('t') : disp_val = atan(disp_val) ; /* atan */
X }
X else
X switch (current)
X {
X case CCTRL('c') : disp_val = acosh(disp_val) ; /* acosh */
X break ;
X case CCTRL('s') : disp_val = asinh(disp_val) ; /* asinh */
X break ;
X case CCTRL('t') : disp_val = atanh(disp_val) ; /* atanh */
X }
X
X tresults[(int) DEG] = disp_val * 180.0 / M_PI ;
X tresults[(int) GRAD] = disp_val * 200.0 / M_PI ;
X tresults[(int) RAD] = disp_val ;
X }
X
X cur_op = current ;
X show_display(tresults[(int) ttype]) ;
X disp_val = tresults[(int) ttype] ;
X}
X
X
Xdo_trigtype() /* Change the current trigonometric type. */
X{
X switch (current)
X {
X case CCTRL('d') : ttype = DEG ;
X break ;
X case CCTRL('g') : ttype = GRAD ;
X break ;
X case CCTRL('r') : ttype = RAD ;
X }
X if (cur_op == CCTRL('c') || cur_op == CCTRL('s') || cur_op == CCTRL('t'))
X {
X disp_val = tresults[(int) ttype] ;
X show_display(tresults[(int) ttype]) ;
X }
X set_item(TTYPEITEM, ttype_str[(int) ttype]) ;
X}
X
X
XBOOLEAN
Xibool(x)
Xdouble x ;
X{
X BOOLEAN p ;
X
X if (x > 68719476736.00) return(0) ;
X else if (x < -68719476736.00) return(0) ;
X else
X {
X while(x < 0.0) x += 4294967296.00 ;
X while(x > 4294967296.00) x -= 4294967296.00 ;
X p = x ;
X return (p) ;
X }
X}
X
X
Xdouble
Xsetbool(p)
XBOOLEAN p ;
X{
X BOOLEAN q ;
X double val ;
X
X q = p & 0x80000000 ;
X p &= 0x7fffffff ;
X val = p ;
X if (q) val += 2147483648.0 ;
X return(val) ;
X}
SHAR_EOF
echo "File functions.c is complete"
chmod 0444 functions.c || echo "restore of functions.c fails"
set `wc -c functions.c`;Sum=$1
if test "$Sum" != "18212"
then echo original size 18212, current size $Sum;fi
echo "x - extracting get.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > get.c &&
X
X/* @(#)get.c 1.8 89/12/13
X *
X * Command line and help file routines.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright 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
X * reported to me then an attempt will be made to fix them.
X */
X
X#include "patchlevel.h"
X#include "calctool.h"
X#include "color.h"
X#include "extern.h"
X
X
Xchar *
Xconvert(line) /* Convert .calctoolrc line to ascii values. */
Xchar *line ; /* Input line to be converted. */
X{
X char output[MAXLINE] ; /* Converted output record. */
X int ctrl = 0 ; /* Set if we are processing a control character. */
X int i ; /* Position within input line. */
X int n = 0 ; /* Position within output line. */
X
X for (i = 0; i < strlen(line)-1; i++)
X {
X if (line[i] == ' ') continue ;
X else if (line[i] == '\\') ctrl = 1 ;
X else if (ctrl)
X {
X output[n++] = CCTRL(line[i]) ;
X ctrl = 0 ;
X }
X else output[n++] = line[i] ;
X }
X output[n] = '\0' ;
X return(output) ;
X}
X
X
Xget_options(argc, argv) /* Extract command line options. */
Xint argc ;
Xchar *argv[] ;
X{
X char next[MAXLINE] ; /* The next command line parameter. */
X
X STRCPY(helpname, HELPNAME) ; /* Default help filename. */
X STRCPY(x11_display, "") ; /* Initially no X11 display value. */
X STRCPY(geometry, "") ; /* Initialy no X11 geometry value. */
X accuracy = 2 ; /* Initial accuracy. */
X inv_video = 0 ; /* Default is normal video. */
X INC ;
X while (argc > 0)
X {
X if (argv[0][0] == '-')
X switch (argv[0][1])
X {
X case 'a' : INC ;
X getparam(next, argv, "-a needs accuracy value") ;
X accuracy = atoi(next) ;
X if (accuracy < 0 || accuracy > 9)
X {
X FPRINTF(stderr,
X "%s: accuracy should be in the range 0-9\n",
X progname) ;
X accuracy = 2 ;
X }
X break ;
X case 'd' : INC ; /* X11 display information. */
X getparam(x11_display, argv, "-d needs display information") ; break ;
X case 'g' : INC ; /* X11 geometry information. */
X getparam(geometry, argv, "-g needs geometry information") ;
X break ;
X case 'h' : INC ;
X getparam(helpname, argv, "-h needs helpfile name") ;
X break ;
X case 'i' : inv_video = 1 ;
X break ;
X case 'v' : FPRINTF(stderr, "%s version 2.4.%1d\n", progname, PATCHLEVEL) ;
X break ;
X/* SunView windowing arguments. -Wp, -WP and -Wi are used in the NeWS
X * implementation to initially position the window and icon.
X */
X
X case 'W' : switch (argv[0][2])
X {
X case 'H' : break ; /* -WH, no sub-args follow */
X case 'i' : iconic = 1 ;
X break ; /* -Wi, start as an icon. */
X case 'g' : /* -Wg, set default color. */
X case 'n' : break ; /* -Wn, no label at all */
X case 'h' : /* -Wh, height */
X case 'I' : /* -WI "icon filename" */
X case 'l' : /* -Wl "some window label" */
X case 'L' : /* -Wl "some icon label" */
X case 't' : /* Font filename */
X case 'T' : /* Icon font filename */
X case 'w' : INC ; /* Width, in columns. */
X break ;
X case 'p' : INC ; /* -Wp xnum ynum */
X getparam(next, argv,
X "-Wp needs x coordinate") ;
X wx = atoi(next) ;
X INC ;
X getparam(next, argv,
X "-Wp needs y coordinate") ;
X wy = atoi(next) ;
X posspec = 1 ;
X break ;
X case 'P' : INC ; /* -WP xnum ynum */
X getparam(next, argv,
X "-WP needs x coordinate") ;
X ix = atoi(next) ;
X INC ;
X getparam(next, argv,
X "-WP needs y coordinate") ;
X iy = atoi(next) ;
X break ;
X case 's' : INC ; INC ; /* -Ws xnum ynum */
X break ;
X case 'b' : /* -Wb r g b (bg color spec)
X*/
X case 'f' : INC ; INC ; INC ; /* Same, fg color */
X break ;
X default : FPRINTF(stderr,"%s: -W%c unknown argument\n",
X progname, argv[0][2]) ;
X break ;
X }
X break ;
X default : usage() ;
X }
X INC ;
X }
X}
X
X
Xgetparam(s, argv, errmes)
Xchar *s, *argv[], *errmes ;
X{
X if (*argv != NULL && argv[0][0] != '-') STRCPY(s, *argv) ;
X else
X {
X FPRINTF(stderr,"%s: %s as next argument.\n", progname, errmes) ;
X exit(1) ;
X }
X}
X
X
Xget_helpfile(helpname) /* Open helpfile if present. */
Xchar *helpname ;
X{
X char *getenv(), name[MAXLINE], *paths, *ptr ;
X int i ;
X
X i = 0 ;
X ishelp = 1 ;
X if ((hfd = fopen(helpname,"r")) == NULL)
X {
X paths = getenv("PATH") ;
X if ((ptr = paths) && helpname[0] != '/')
X for (;;)
X if (*ptr == ':' || *ptr == 0)
X {
X if (*ptr == 0) break ;
X name[i++] = '/' ;
X name[i] = 0 ;
X STRCAT(name, helpname) ;
X if ((hfd = fopen(name, "r")) != NULL) return ;
X *ptr++ ;
X i = 0 ;
X }
X else name[i++] = *ptr++ ;
X FPRINTF(stderr, "%s: Help file: %s not found\r\n", progname, helpname) ;
X ishelp = 0 ;
X }
X}
X
X
Xget_rcfile(name) /* Read .calctoolrc file. */
Xchar *name ;
X{
X char line[MAXLINE] ; /* Current line from the .calctoolrc file. */
X char tmp[MAXLINE] ; /* Used to extract function definitions. */
X double const ; /* Current constant value being conveted. */
X int i ; /* Index to constant or function array. */
X int isval ; /* Set to 'c' or 'f' for convertable line. */
X int n ;
X FILE *rcfd ; /* File descriptor for calctool rc file. */
X
X if ((rcfd = fopen(name, "r")) == NULL) return ;
X
X/* Process the .calctoolrc file. There are currently four types of
X * records to look for:
X *
X * 1) Those starting with a hash in the first column are comments.
X *
X * 2) Lines starting with 'c' or 'C' in the first column are
X * definitions for constants. The cC is followed by a digit in
X * the range 0-9, then a space. This is followed by a number
X * in fixed or scientific notation. Following this is an optional
X * comment, which if found, will be used in the popup menu for
X * the constants. If the comment is present, there must be at
X * least one space between this and the preceding number.
X *
X * 3) Those starting with a 'f' or a 'F' in the first column are
X * definitions for functions. The fF is followed by a digit in
X * the range 0-9, then a space. This is followed by a function
X * definition. Following this is an optional comment, which if
X * found, will be used in the popup menu for the functions.
X * If the comment is present, there must be at least one space
X * between this and the preceding function definition.
X *
X * 4) Lines starting with a 'r' or a 'R' in the first column are
X * definitions for the initial contents of the calculators
X * memory registers. The rR is followed by a digit in the
X * range 0-9, then a space. This is followed by a number in
X * fixed or scientific notation. The rest of the line is ignored.
X *
X * All other lines are ignored.
X *
X * Two other things to note. There should be no embedded spaces in
X * the function definitions, and whenever a backslash is found, that
X * and the following character signify a control character, for
X * example \g would be ascii 7.
X */
X
X while (fgets(line, MAXLINE, rcfd) != NULL)
X {
X isval = 0 ;
X if (line[0] == 'c' || line[0] == 'C') isval = 'c' ;
X else if (line[0] == 'f' || line[0] == 'F') isval = 'f' ;
X else if (line[0] == 'r' || line[0] == 'R') isval = 'r' ;
X if (isval)
X if (line[1] >= '0' && line[1] <= '9' && line[2] == ' ')
X {
X i = char_val(line[1]) ;
X if (isval == 'c')
X {
X n = sscanf(&line[3], "%lf", &const) ;
X if (n == 1) con_vals[i] = const ;
X }
X else if (isval == 'f')
X {
X SSCANF(&line[3], "%s", tmp) ;
X STRCPY(fun_vals[i], convert(tmp)) ;
X }
X else if (isval == 'r')
X {
X n = sscanf(&line[3], "%lf", &const) ;
X if (n == 1) mem_vals[i] = const ;
X continue ;
X }
X for (n = 3; n < strlen(line); n++)
X if (line[n] == ' ')
X {
X while (line[n] == ' ') n++ ;
X line[strlen(line)-1] = '\0' ;
X if (isval == 'c')
X SPRINTF(con_names[i], "%1d: %g [%s]",
X i, con_vals[i], &line[n]) ;
X else
X SPRINTF(fun_names[i], "%1d: %s [%s]",
X i, fun_vals[i], &line[n]) ;
X break ;
X }
X }
X }
X FCLOSE(rcfd) ;
X}
X
X
Xread_rcfiles() /* Read .calctoolrc's from home and current directories. */
X{
X char *home ; /* Pathname for users home directory. */
X char name[MAXLINE] ; /* Full name of users .calctoolrc file. */
X int n ;
X struct passwd *entry ;
X
X for (n = 0; n < MAXREGS; n++)
X {
X SPRINTF(name, "%1d: %g [%s]", n, con_vals[n], con_names[n]) ;
X STRCPY(con_names[n], name) ;
X STRCPY(fun_vals[n], "") ; /* Initially empty function strings. */
X }
X
X if ((home = getenv("HOME")) == NULL)
X {
X if ((entry = getpwuid(getuid())) == NULL) return ;
X home = entry->pw_dir ;
X }
X SPRINTF(name, "%s/%s", home, RCNAME) ;
X get_rcfile(name) ; /* Read .calctoolrc from users home directory. */
X
X SPRINTF(name, "%s/%s", getcwd((char *) NULL, MAXLINE), RCNAME) ;
X get_rcfile(name) ; /* Read .calctoolrc file from current directory. */
X}
X
X
Xusage()
X{
X FPRINTF(stderr, "Usage: %s: [-d display] [-g geometry] ", progname) ;
X FPRINTF(stderr, "[-h helpfile] [-i] [-v] [-Wi] [-Wp x y] [-WP x y]\n") ;
X exit(0) ;
X}
SHAR_EOF
chmod 0444 get.c || echo "restore of get.c fails"
set `wc -c get.c`;Sum=$1
if test "$Sum" != "11877"
then echo original size 11877, current size $Sum;fi
echo "x - extracting calctool.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > calctool.c &&
X
X/* @(#)calctool.c 1.12 89/12/07
X *
X * A simple calculator program.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Basic algorithms, copyright (c) Ed Falk.
X * Sun Microsystems, Mountain View.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright 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
X * reported to me then an attempt will be made to fix them.
X */
X
X#include "patchlevel.h"
X#include "color.h"
X#include "calctool.h"
X
Xdouble powers[11][4] = {
X { 1.0, 1.0, 1.0, 1.0 },
X { 2.0, 8.0, 10.0, 16.0 },
X { 4.0, 64.0, 100.0, 256.0 },
X { 8.0, 512.0, 1000.0, 4096.0 },
X { 16.0, 4096.0, 10000.0, 65536.0 },
X { 32.0, 32768.0, 100000.0, 1048576.0 },
X { 64.0, 262144.0, 1000000.0, 16777216.0 },
X { 128.0, 2097152.0, 10000000.0, 268435456.0 },
X { 256.0, 16777216.0, 100000000.0, 4294967296.0 },
X { 512.0, 134217728.0, 1000000000.0, 68719476736.0 },
X { 1024.0, 1073741824.0, 10000000000.0, 1099511627776.0 }
X} ;
X
Xdouble exp_p1[10][4] = {
X { 1.0, 1.0, 1.0, 1.0 },
X { 1.0, 1.0, 1.0, 1.0 },
X { 0.5, 0.125, 0.1, 0.0625 },
X { 0.25, 0.015625, 0.01, 3.90625e-03 },
X { 0.125, 1.953125e-03, 0.001, 2.44140625e-04 },
X { 0.0625, 2.44140625e-04, 1.0e-4, 1.525878906e-05 },
X { 0.03125, 3.051757813e-05, 1.0e-5, 9.536743164e-07 },
X { 0.015625, 3.814697266e-06, 1.0e-6, 5.960464478e-08 },
X { 0.0078125, 4.768371582e-07, 1.0e-7, 3.725290298e-09 },
X { 3.90625e-03, 5.960464478e-08, 1.0e-8, 2.328306437e-10 }
X} ;
X
Xdouble max_fix[4] = {
X 6.871947674e+10, 3.245185537e+32,
X 1.000000000e+36, 2.230074520e+43
X} ;
X
X/* Selectable constants - these are the default selections. */
X
Xdouble con_vals[MAXREGS] = {
X 0.621, /* kilometres per hour <=> miles per hour. */
X 1.41421356237309504880, /* square root of 2. */
X 2.7182818284590452354, /* e */
X 3.14159265358979323846, /* pi */
X 2.54, /* centimetres <=> inch. */
X 57.29577951308232, /* degrees in a radian. */
X 1048576.0, /* 2 ^ 20. */
X 0.0353, /* grams <=> ounce. */
X 0.948, /* kilojoules <=> British thermal units. */
X 0.0610, /* cubic cms <=> cubic inches. */
X} ;
X
Xchar con_names[MAXREGS][MAXLINE] = {
X "kilometres per hour <=> miles per hour.",
X "square root of 2.",
X "e.",
X "pi.",
X "centimetres <=> inch.",
X "degrees in a radian.",
X "2 ^ 20.",
X "grams <=> ounce.",
X "kilojoules <=> British thermal units.",
X "cubic cms <=> cubic inches.",
X} ;
X
Xchar num_names[MAXREGS][2] = { /* Used by the popup menus. */
X "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
X} ;
X
Xchar base_str[4][4] = { "BIN", "OCT", "DEC", "HEX" } ;
Xchar dtype_str[2][4] = { "FIX", "SCI" } ;
Xchar ttype_str[3][5] = { "DEG", "GRAD", "RAD" } ;
X
Xchar digits[] = "0123456789abcdef" ;
Xint basevals[4] = {2, 8, 10, 16} ;
X
X/* Length of display in characters for each base. */
Xint disp_length[4] = {32, 15, 12, 12} ;
X
X/* X offset in pixels for various length button strings. */
Xint chxoff[5] = { 5, 9, 14, 16, 5 } ;
X
X/* Valid keys when an error condition has occured. */
X/* MEM KEYS HELP clr QUIT OFF REDRAW */
Xchar validkeys[MAXVKEYS] = { 'M', 'K', '?', '\177', 'q', 'o', '\f' } ;
X
X/* Valid keys for which the right mouse button will get a popup menu. */
Xchar validmenu[MAXMENUS] = {
X/* ACC CON EXCH FUN < > RCL STO */
X 'A', '#', CCTRL('e'), CCTRL('f'), '<', '>', 'r', 's'
X} ;
X
Xdouble disp_val ; /* Value of the current display. */
Xdouble last_input ; /* Previous number input by user. */
Xdouble mem_vals[MAXREGS] ; /* Memory register values. */
Xdouble result ; /* Current calculator total value. */
Xdouble tresults[3] ; /* Current trigonometric results. */
X
Xenum base_type base ; /* Current base: BIN, OCT, DEC or HEX. */
Xenum gr_type gtype ; /* What graphics system is being used. */
Xenum num_type dtype ; /* Number display mode. */
Xenum trig_type ttype ; /* Trigonometric type (deg, grad or rad). */
X
XFILE *hfd ; /* File descriptor for help information. */
X
Xint accuracy ; /* Number of digits precision (Max 9). */
Xint color ; /* Color being used for current raster operation. */
Xint column ; /* Column number of current key/mouse press. */
Xint cur_ch ; /* Current character if keyboard event. */
Xint curx ; /* Current mouse X position. */
Xint cury ; /* Current mouse Y position. */
Xint down ; /* Indicates is a mouse button is down. */
Xint error ; /* Indicates some kind of display error. */
Xint hyperbolic ; /* If set, trig functions will be hyperbolic. */
Xint iconic ; /* Set if window is currently iconic. */
Xint inv_video ; /* Set if user wants inverse video mode. */
Xint inverse ; /* If set, trig and log functions will be inversed. */
Xint iscolor ; /* Set if this is a color screen. */
Xint ishelp ; /* Set if there is a help file. */
Xint issel ; /* Set if valid [Get] selection. */
Xint ix ; /* Initial X position of the icon. */
Xint iy ; /* Initial Y position of the icon. */
Xint key_exp ; /* Set if entering exponent number. */
Xint new_input ; /* New number input since last op. */
Xint nextc ; /* Current event identifier. */
Xint nfont_width ; /* Width of the normal font characters. */
Xint pending ; /* Indicates command depending on multiple presses. */
Xint pending_op ; /* Arithmetic operation for pending command. */
Xint pointed ; /* Whether a decimal point has been given. */
Xint portion ; /* Portion of button on current key/mouse press. */
Xint posspec ; /* Set if -Wp or -g option is present (for X11) */
Xint row ; /* Row number of current key/mouse press. */
Xint rstate ; /* Indicates if memory register frame is displayed. */
Xint spaces ; /* Number of spaces in current button string. */
Xint toclear ; /* Indicates if display should be cleared. */
Xint tstate ; /* Indicates current button set being displayed. */
Xint wx ; /* Initial X position of the window. */
Xint wy ; /* Initial Y position of the window. */
Xint x ; /* X offset for text for button. */
Xint y ; /* Y offset for text for button. */
X
X/* Routines obeyed by mouse button or character presses. */
Xint close_frame(), destroy_frame(), do_base() ;
Xint do_calculation(), do_clear(), do_constant(), do_delete() ;
Xint do_expno(), do_immediate(), do_keys(), do_number() ;
Xint do_pending(), do_point(), do_portion(), do_repaint() ;
Xint do_set_mode(), do_trig(), do_trigtype(), toggle_reg_canvas() ;
X
Xchar cur_op ; /* Current arithmetic operation. */
Xchar current ; /* Current button or character pressed. */
Xchar *exp_posn ; /* Position of the exponent sign. */
Xchar fnum[MAX_DIGITS+1] ; /* Scratch area for fixed point numbers. */
Xchar fun_names[MAXREGS][MAXLINE] ; /* Function defs from .calctoolrc. */
Xchar fun_vals[MAXREGS][MAXLINE] ; /* Function names from .calctoolrc. */
Xchar geometry[MAXLINE] ; /* X11 geometry information. */
Xchar old_cal_value ; /* Previous calculation operator. */
Xchar pstr[5] ; /* Current button text string. */
Xchar *selection ; /* Current [Get] selection. */
Xchar *shelf ; /* PUT selection shelf contents. */
Xchar snum[MAX_DIGITS+1] ; /* Scratch are for scientific numbers. */
Xchar x11_display[MAXLINE] ; /* X11 display information. */
X
Xstruct iteminfo items[MAXITEMS] = { /* Panel items. */
X { SFONT, BBORDER, DISPLAY-3, "" }, /* BASEITEM. */
X { NFONT, 0, DISPLAY-15, "" }, /* DISPLAYITEM. */
X { SFONT, BBORDER+1*(BWIDTH+BGAP), DISPLAY-3, "" }, /* TTYPEITEM. */
X { SFONT, BBORDER+2*(BWIDTH+BGAP), DISPLAY-3, "" }, /* NUMITEM. */
X { SFONT, BBORDER+3*(BWIDTH+BGAP), DISPLAY-3, "" }, /* HYPITEM. */
X { SFONT, BBORDER+4*(BWIDTH+BGAP), DISPLAY-3, "" }, /* INVITEM. */
X { SFONT, BBORDER+5*(BWIDTH+BGAP), DISPLAY-3, "" }, /* OPITEM. */
X} ;
X
X/* Calculator button values. */
X
Xstruct button buttons[TITEMS] = {
X { "EXCH", CCTRL('e'), OP_SET, MAUVE, do_pending }, /* Row 1. */
X { "CON ", '#', OP_SET, BLUE, do_pending },
X { "BIN ", 'B', OP_CLEAR, YELLOW, do_base },
X { "MEM ", 'M', OP_CLEAR, BLUE, toggle_reg_canvas },
X { "OCT ", 'O', OP_CLEAR, YELLOW, do_base },
X { "D ", 'd', OP_NOP, PINK, do_number },
X { "DEC ", 'D', OP_CLEAR, YELLOW, do_base },
X { "E ", 'e', OP_NOP, PINK, do_number },
X { "HEX ", 'H', OP_CLEAR, YELLOW, do_base },
X { "F ", 'f', OP_NOP, PINK, do_number },
X { "SCI ", CCTRL('n'), OP_CLEAR, BLUE, do_set_mode },
X { "FUN ", CCTRL('f'), OP_SET, BLUE, do_pending },
X
X { "&32 ", '[', OP_CLEAR, LGREY, do_immediate }, /* Row 2. */
X { "STO ", 's', OP_SET, MAUVE, do_pending },
X { "&16 ", ']', OP_CLEAR, LGREY, do_immediate },
X { "RCL ", 'r', OP_SET, MAUVE, do_pending },
X { "< ", '<', OP_SET, LGREY, do_pending },
X { "A ", 'a', OP_NOP, PINK, do_number },
X { "> ", '>', OP_SET, LGREY, do_pending },
X { "B ", 'b', OP_NOP, PINK, do_number },
X { "% ", '%', OP_SET, LPURPLE, do_calculation },
X { "C ", 'c', OP_NOP, PINK, do_number },
X { "clr ", '\177', OP_CLEAR, BLUE, do_clear },
X { "bsp ", CCTRL('h'), OP_NOP, BLUE, do_delete },
X
X { "OR ", '|', OP_SET, GREEN, do_calculation }, /* Row 3. */
X { "AND ", '&', OP_SET, GREEN, do_calculation },
X { "HYP ", 'h', OP_CLEAR, BLUE, do_set_mode },
X { "SIN ", CCTRL('s'), OP_CLEAR, LGREEN, do_trig },
X { "e^x ", '{', OP_CLEAR, ORANGE, do_immediate },
X { "7 ", '7', OP_NOP, LBLUE, do_number },
X { "10^x", '}', OP_CLEAR, ORANGE, do_immediate },
X { "8 ", '8', OP_NOP, LBLUE, do_number },
X { "y^x ", 'Y', OP_SET, ORANGE, do_calculation },
X { "9 ", '9', OP_NOP, LBLUE, do_number },
X { "INT ", 'I', OP_CLEAR, LGREY, do_portion },
X { "X ", 'x', OP_SET, LPURPLE, do_calculation },
X
X { "XNOR", 'n', OP_SET, GREEN, do_calculation }, /* Row 4. */
X { "XOR ", '^', OP_SET, GREEN, do_calculation },
X { "INV ", 'i', OP_CLEAR, BLUE, do_set_mode },
X { "COS ", CCTRL('c'), OP_CLEAR, LGREEN, do_trig },
X { "ln ", 'N', OP_CLEAR, ORANGE, do_immediate },
X { "4 ", '4', OP_NOP, LBLUE, do_number },
X { "log ", 'G', OP_CLEAR, ORANGE, do_immediate },
X { "5 ", '5', OP_NOP, LBLUE, do_number },
X { "SQRT", 'S', OP_CLEAR, ORANGE, do_immediate },
X { "6 ", '6', OP_NOP, LBLUE, do_number },
X { "FRAC", 'F', OP_CLEAR, LGREY, do_portion },
X { "/ ", '/', OP_SET, LPURPLE, do_calculation },
X
X { "NOT ", '~', OP_CLEAR, GREEN, do_immediate }, /* Row 5. */
X { "ACC ", 'A', OP_SET, BLUE, do_pending },
X { "EXP ", 'E', OP_SET, BLUE, do_expno },
X { "TAN ", CCTRL('t'), OP_CLEAR, LGREEN, do_trig },
X { "1/x ", 'R', OP_CLEAR, ORANGE, do_immediate },
X { "1 ", '1', OP_NOP, LBLUE, do_number },
X { "x! ", '!', OP_CLEAR, ORANGE, do_immediate },
X { "2 ", '2', OP_NOP, LBLUE, do_number },
X { "x^2 ", '@', OP_CLEAR, ORANGE, do_immediate },
X { "3 ", '3', OP_NOP, LBLUE, do_number },
X { "CHS ", 'C', OP_CLEAR, LGREY, do_immediate },
X { "- ", '-', OP_SET, LPURPLE, do_calculation },
X
X { "QUIT", 'q', OP_CLEAR, BLUE, destroy_frame }, /* Row 6. */
X { "OFF ", 'o', OP_CLEAR, BLUE, close_frame },
X { "KEYS", 'K', OP_CLEAR, BLUE, do_keys },
X { "? ", '?', OP_SET, BLUE, do_pending },
X { "DEG ", CCTRL('d'), OP_CLEAR, RED, do_trigtype },
X { "0 ", '0', OP_NOP, LBLUE, do_number },
X { "RAD ", CCTRL('r'), OP_CLEAR, RED, do_trigtype },
X { ". ", '.', OP_NOP, LPURPLE, do_point },
X { "GRAD", CCTRL('g'), OP_CLEAR, RED, do_trigtype },
X { "= ", '=', OP_CLEAR, LPURPLE, do_calculation },
X { "ABS ", 'U', OP_CLEAR, LGREY, do_portion },
X { "+ ", '+', OP_SET, LPURPLE, do_calculation },
X
X/* Extra definitions. */
X
X { "X ", 'X', OP_SET, WHITE, do_calculation },
X { "X ", '*', OP_SET, WHITE, do_calculation },
X { " ", CCTRL('m'), OP_CLEAR, WHITE, do_calculation },
X { "QUIT", 'Q', OP_CLEAR, WHITE, destroy_frame },
X { " ", '\f', OP_NOP, WHITE, do_repaint },
X} ;
X
X/* 256-byte table for quickly reversing the bits in an unsigned 8-bit char,
X * used to convert between MSBFirst and LSBFirst image formats.
X */
X
Xchar revtable[256] = {
X 0, -128, 64, -64, 32, -96, 96, -32,
X 16, -112, 80, -48, 48, -80, 112, -16,
X 8, -120, 72, -56, 40, -88, 104, -24,
X 24, -104, 88, -40, 56, -72, 120, -8,
X 4, -124, 68, -60, 36, -92, 100, -28,
X 20, -108, 84, -44, 52, -76, 116, -12,
X 12, -116, 76, -52, 44, -84, 108, -20,
X 28, -100, 92, -36, 60, -68, 124, -4,
X 2, -126, 66, -62, 34, -94, 98, -30,
X 18, -110, 82, -46, 50, -78, 114, -14,
X 10, -118, 74, -54, 42, -86, 106, -22,
X 26, -102, 90, -38, 58, -70, 122, -6,
X 6, -122, 70, -58, 38, -90, 102, -26,
X 22, -106, 86, -42, 54, -74, 118, -10,
X 14, -114, 78, -50, 46, -82, 110, -18,
X 30, -98, 94, -34, 62, -66, 126, -2,
X 1, -127, 65, -63, 33, -95, 97, -31,
X 17, -111, 81, -47, 49, -79, 113, -15,
X 9, -119, 73, -55, 41, -87, 105, -23,
X 25, -103, 89, -39, 57, -71, 121, -7,
X 5, -123, 69, -59, 37, -91, 101, -27,
X 21, -107, 85, -43, 53, -75, 117, -11,
X 13, -115, 77, -51, 45, -83, 109, -19,
X 29, -99, 93, -35, 61, -67, 125, -3,
X 3, -125, 67, -61, 35, -93, 99, -29,
X 19, -109, 83, -45, 51, -77, 115, -13,
X 11, -117, 75, -53, 43, -85, 107, -21,
X 27, -101, 91, -37, 59, -69, 123, -5,
X 7, -121, 71, -57, 39, -89, 103, -25,
X 23, -105, 87, -41, 55, -73, 119, -9,
X 15, -113, 79, -49, 47, -81, 111, -17,
X 31, -97, 95, -33, 63, -65, 127, -1,
X} ;
X
Xchar display[MAXLINE] ; /* Current calculator display. */
Xchar helpname[MAXLINE] ; /* Filename for help file. */
Xchar progname[MAXLINE] ; /* Name of this program. */
X
X
Xmain(argc,argv)
Xint argc ;
Xchar *argv[] ;
X{
X STRCPY(progname, argv[0]) ; /* Save this programs name. */
X get_options(argc, argv) ; /* Get command line arguments. */
X get_helpfile(helpname) ; /* Open helpfile if present. */
X read_rcfiles() ; /* Read .calctoolrc's files. */
X if (init_ws_type()) /* Determine window system type. */
X {
X FPRINTF(stderr,"Error initialising window system.\n") ;
X exit(1) ;
X }
X init_fonts() ; /* Open required fonts. */
X make_icon() ; /* Set up the calctool window icon. */
X make_frames(argc, argv) ; /* Create calctool window frames. */
X make_subframes() ; /* Create panels and canvases. */
X make_menus() ; /* Create menus for graphics versions. */
X if (gtype != X11) load_colors() ; /* Load the initial calctool colormap. */
X
X shelf = NULL ; /* No selection for shelf initially. */
X pending = 0 ; /* No initial pending command. */
X rstate = 0 ; /* No memory register frame display initially. */
X tstate = 0 ; /* Button values displayed first. */
X hyperbolic = 0 ; /* Normal trig functions initially. */
X inverse = 0 ; /* No inverse functions initially. */
X base = DEC ; /* Initial base. */
X ttype = DEG ; /* Initial trigonometric type. */
X dtype = FIX ; /* Initial number display mode. */
X down = 0 ; /* No mouse presses initially. */
X
X make_items() ; /* Create panel items and cursors. */
X do_clear() ; /* Initialise and clear display. */
X set_cursor(MAINCURSOR) ; /* Initially display the arrow cursor. */
X start_tool() ; /* Display the calculator. */
X exit(0) ;
X}
X
X
Xmatherr(x) /* Calctools' math library error-handling routine. */
Xstruct exception *x ;
X{
X SPRINTF(display, "Error in %s", x->name) ;
X set_item(DISPLAYITEM, display) ;
X error = 1 ;
X set_item(OPITEM, "CLR") ;
X return(1) ;
X}
SHAR_EOF
chmod 0444 calctool.c || echo "restore of calctool.c fails"
set `wc -c calctool.c`;Sum=$1
if test "$Sum" != "17879"
then echo original size 17879, current size $Sum;fi
echo "x - extracting mgr.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > mgr.c &&
X
X/* @(#)mgr.c 1.11 89/12/21
X *
X * These are the MGR dependent graphics routines used by calctool.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright 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
X * reported to me then an attempt will be made to fix them.
X */
X
X#include "dump.h"
X#include "term.h"
X#include "calctool.h"
X#include "color.h"
X#include "extern.h"
X
X#define S_FONT 1 /* Font descriptors. */
X#define N_FONT 2
X#define B_FONT 3
X
X#define ICONIC 0 /* States that the calctool display can be in. */
X#define JUST_KEYS 1
X#define SHOW_ALL 2
X
X#define PR_ICON 1 /* Descriptor for closed icon image. */
X
X#define SMALLFONT "sail6x8r"
X#define NORMALFONT "cour7x14b"
X#define BIGFONT "gal12x20r"
X
X#define MENU_COUNT (sizeof(menus) / (sizeof(struct menu_entry) * MAXMENUS))
X
Xstruct menu_entry menus[MAXMENUS][MAXREGS] ;
X
Xchar fontname[MAXLINE] ; /* Full pathname of the small font. */
X
Xint local_mode ; /* Used by load_icon for correct line mode. */
Xint mgr_infd ; /* MGR input connection file descriptor. */
Xint mgr_outfd ; /* MGR output connection file descriptor. */
X
Xshort icon_image[] = {
X#include "calctool.icon"
X} ;
X
X#ifdef NO_4_3SELECT
Xint fullmask ; /* Full mask of file descriptors to check on. */
Xint readmask ; /* Readmask used in select call. */
X#else
Xfd_set fullmask ; /* Full mask of file descriptors to check on. */
Xfd_set readmask ; /* Readmask used in select call. */
X#endif /*NO_4_3SELECT */
X
X
XSIGRET
Xclean(code)
Xint code ;
X{
X m_bitdestroy(1) ;
X m_pop() ;
X m_ttyreset() ;
X m_clear() ;
X exit(code) ;
X}
X
X
X/*ARGSUSED*/
Xclear_canvas(canvas, color)
Xenum can_type canvas ;
Xint color ;
X{
X m_func(B_CLEAR) ;
X if (canvas == KEYCANVAS)
X m_bitwrite(0, 0, TWIDTH+10, THEIGHT+DISPLAY+10) ;
X else if (canvas == REGCANVAS)
X m_bitwrite(TWIDTH+15, 0, TWIDTH+10, THEIGHT+DISPLAY+10) ;
X}
X
X
Xclose_frame()
X{
X reshape(ICONIC) ;
X m_clearmode(M_ACTIVATE) ;
X}
X
X
Xcolor_area(x, y, width, height, color)
Xint x, y, width, height, color ;
X{
X if (color == BLACK)
X {
X m_func(B_COPY) ;
X m_bitwrite(x, y, width, height) ;
X }
X}
X
X
Xcreate_menu(mtype) /* Create popup menu for right button press. */
Xenum menu_type mtype ;
X{
X int i ;
X char istr[3] ; /* String representation for action value. */
X
X for (i = 0; i < MAXREGS; i++)
X {
X SPRINTF(istr, "%1d\r", i) ;
X switch (mtype)
X {
X case M_ACC : /* Accuracies. */
X case M_EXCH : /* Register exchange. */
X case M_LSHIFT : /* Left shift. */
X case M_RCL : /* Register recall. */
X case M_RSHIFT : /* Right shift. */
X case M_STO : /* Register store. */
X menus[(int) mtype][i].value = num_names[i] ;
X break ;
X case M_CON : /* Constants. */
X menus[(int) mtype][i].value = con_names[i] ;
X break ;
X case M_FUN : /* Functions. */
X menus[(int) mtype][i].value = fun_names[i] ;
X }
X menus[(int) mtype][i].action = num_names[i] ;
X }
X menu_load((int) mtype, MENU_COUNT, menus[(int) mtype]) ;
X}
X
X
Xdestroy_frame()
X{
X clean(0) ;
X}
X
X
Xdo_menu(mtype) /* Popup appropriate menu and get value. */
Xenum menu_type mtype ;
X{
X m_selectmenu2((int) mtype) ;
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
Xdraw_regs()
X{
X reshape(SHOW_ALL) ;
X clear_canvas(REGCANVAS, WHITE) ;
X drawline(TWIDTH, 0, TWIDTH, THEIGHT+DISPLAY+10) ;
X make_registers() ;
X}
X
X
X/*ARGSUSED*/
Xdrawtext(x, y, window, fontno, color, str)
Xenum font_type fontno ;
Xenum can_type window ;
Xint x, y, color ;
Xchar *str ;
X{
X int i ;
X
X if (fontno == SFONT) m_font(S_FONT) ;
X else if (fontno == NFONT) m_font(N_FONT) ;
X else if (fontno == BFONT) m_font(B_FONT) ;
X if (window == REGCANVAS) x += TWIDTH + 15 ;
X m_func(B_XOR) ;
X i = strlen(str)-1 ;
X while (str[i] == ' ' && i) str[i--] = '\0' ;
X m_stringto(0, x, y+4, str) ;
X m_movecursor(2500, 2500) ;
X}
X
X
Xget_display()
X{
X}
X
X
Xget_next_event()
X{
X int c ;
X static struct timeval tval = { 0, 0 } ;
X
X m_flush() ;
X for (;;)
X {
X readmask = fullmask ;
X#ifdef NO_4_3SELECT
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 ((c = m_getchar()) == EOF)
X {
X clearerr(m_termin) ;
X continue ;
X }
X get_mouse(&curx, &cury) ;
X switch (c)
X {
X case '\030' : return(MIDDLE_DOWN) ;
X case '\031' : return(MIDDLE_UP) ;
X case '\032' : return(LEFT_DOWN) ;
X case '\033' : return(LEFT_UP) ;
X case '\034' : return(DIED) ; /* Window destroyed. */
X case '\035' : if (iconic) iconic = 0 ;
X case '\036' : if (rstate) reshape(SHOW_ALL) ;
X else reshape(JUST_KEYS) ;
X case '\037' : return(CFRAME_REPAINT) ; /* Window redrawn. */
X default : cur_ch = c ;
X return(KEYBOARD) ;
X }
X }
X }
X}
X
X
Xhandle_selection()
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 /*MGRHOME*/
X
X SPRINTF(fontname, "%s/font/%s", path, SMALLFONT) ;
X m_loadfont(SFONT, fontname) ;
X
X SPRINTF(fontname, "%s/font/%s", path, NORMALFONT) ;
X m_loadfont(NFONT, fontname) ;
X nfont_width = 9 ;
X
X SPRINTF(fontname, "%s/font/%s", path, BIGFONT) ;
X m_loadfont(BFONT, fontname) ;
X
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 gtype = MGR ;
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
X/*ARGSUSED*/
Xmake_frames(argc, argv)
Xint argc ;
Xchar *argv[] ;
X{
X#ifdef NO_4_3SELECT
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_1, "\030") ; /* Right mouse button depressed. */
X m_setevent(BUTTON_1U, "\031") ; /* Right mouse button released. */
X
X m_setevent(BUTTON_2, "\032") ; /* Middle mouse button depressed. */
X m_setevent(BUTTON_2U, "\033") ; /* Middle mouse button released. */
X
X m_setevent(ACTIVATE, "\034") ; /* Window has been activated. */
X m_setevent(DESTROY, "\035") ; /* Check for window being destroyed. */
X m_setevent(RESHAPE, "\036") ; /* Check for window being reshaped. */
X m_setevent(REDRAW, "\037") ; /* Check for window being redrawn. */
X}
X
X
Xmake_icon()
X{
X load_icon(PR_ICON, icon_image) ;
X}
X
X
Xmake_items()
X{
X do_repaint() ; /* Redraw the calctool canvas[es]. */
X m_movecursor(2500, 2500) ; /* Move character cursor offscreen. */
X}
X
X
Xmake_subframes()
X{
X m_font(N_FONT) ; /* Use the default font. */
X reshape(JUST_KEYS) ;
X m_clear() ; /* Clear calctool window. */
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 JUST_KEYS : m_shapewindow(x, y, TWIDTH+10, THEIGHT+DISPLAY+10) ;
X break ;
X case SHOW_ALL : m_shapewindow(x, y, 2*TWIDTH+25, THEIGHT+DISPLAY+10) ;
X }
X m_movecursor(2500, 2500) ;
X}
X
X
X/*ARGSUSED*/
Xset_cursor(type) /* Doesn't appear to be any way to set the cursor. */
Xint type ;
X{
X}
X
X
Xstart_tool()
X{
X while (1)
X process_event(get_next_event()) ;
X}
X
X
Xtoggle_reg_canvas() /* Show or clear memory register area. */
X{
X rstate = !rstate ;
X if (rstate) draw_regs() ;
X else reshape (JUST_KEYS) ;
X}
SHAR_EOF
chmod 0444 mgr.c || echo "restore of mgr.c fails"
set `wc -c mgr.c`;Sum=$1
if test "$Sum" != "9469"
then echo original size 9469, current size $Sum;fi
echo "x - extracting news.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > news.c &&
X
X/* @(#)news.c 1.9 89/12/21
X *
X * These are the NeWS dependent graphics routines used by calctool.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright 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
X * reported to me then an attempt will be made to fix them.
X */
X
X#include "calctool.h"
X#include "color.h"
X#include "extern.h"
X#include <sys/types.h>
X
Xextern FILE *PostScript ;
Xextern FILE *PostScriptInput ;
X
X
Xclear_canvas(canvas, color)
Xenum can_type canvas ;
Xint color ;
X{
X char cantype ;
X
X if (canvas == KEYCANVAS) cantype = 'K' ;
X else if (canvas == REGCANVAS) cantype = 'R' ;
X FPRINTF(PostScript,"%d %cC PSClearCanvas\n", color, cantype) ;
X FFLUSH(PostScript) ;
X}
X
X
Xclose_frame()
X{
X FPRINTF(PostScript, "PSCloseFrame\n") ;
X FFLUSH(PostScript) ;
X}
X
X
Xcolor_area(x, y, width, height, color)
Xint x, y, width, height, color ;
X{
X FPRINTF(PostScript, "%d %d %d %d %d PSColorArea\n",
X color, x, width, height, y) ;
X FFLUSH(PostScript) ;
X}
X
X
Xcreate_menu(mtype) /* Create popup menu for right button press. */
Xenum menu_type mtype ;
X{
X int i ;
X
X FPRINTF(PostScript, "/Menu%1d [\n", (int) mtype) ;
SHAR_EOF
echo "End of part 3"
echo "File news.c is continued in part 4"
echo "4" > s2_seq_.tmp
exit 0