v10i009: Calctool V2.4 - a simple calculator (Part 4 of 6).
Rich Burridge
richb at Aus.Sun.COM
Tue Jan 16 11:03:14 AEST 1990
Posting-number: Volume 10, Issue 9
Submitted-by: richb at Aus.Sun.COM (Rich Burridge)
Archive-name: calctool24/part04
---- Cut Here and unpack ----
#!/bin/sh
# this is part 4 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file news.c continued
#
CurArch=4
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 news.c"
sed 's/^X//' << 'SHAR_EOF' >> news.c
X for (i = 0; i < MAXREGS; i++)
X {
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 FPRINTF(PostScript, "(%s)", num_names[i]) ;
X break ;
X case M_CON : /* Constants. */
X FPRINTF(PostScript, "(%s)", con_names[i]) ;
X break ;
X case M_FUN : /* Functions. */
X FPRINTF(PostScript, "(%s)", fun_names[i]) ;
X break ;
X }
X FPRINTF(PostScript, " { %1d typedprint }\n", (int) mtype) ;
X }
X FPRINTF(PostScript, "] /new DefaultMenu send def\n") ;
X FFLUSH(PostScript) ;
X}
X
X
Xdestroy_frame()
X{
X exit(0) ;
X}
X
X
Xdo_menu(mtype) /* Popup appropriate menu and get value. */
Xenum menu_type mtype ;
X{
X int mval ;
X
X FPRINTF(PostScript, "{ /ParentMenu Menu%1d def } ClientMenu send\n",
X (int) mtype) ;
X FFLUSH(PostScript) ;
X pscanf(PostScriptInput, "%d", &mval) ;
X return(mval) ;
X}
X
X
Xdrawline(x1, y1, x2, y2)
Xint x1, y1, x2, y2 ;
X{
X FPRINTF(PostScript, "%d %d %d %d PSDrawLine\n", x1, x2, y1, y2) ;
X FFLUSH(PostScript) ;
X}
X
X
Xdraw_regs()
X{
X FPRINTF(PostScript, "PSDrawRegs\n") ;
X FFLUSH(PostScript) ;
X}
X
X
Xdrawtext(x, y, window, fontno, color, str)
Xenum can_type window ;
Xenum font_type fontno ;
Xint x, y, color ;
Xchar *str ;
X{
X int i ;
X char font, fonttype[6], line[MAXLINE] ;
X
X if (fontno == SFONT) STRCPY(fonttype, "SFont") ;
X else if (fontno == NFONT) STRCPY(fonttype, "NFont") ;
X else if (fontno == BFONT) STRCPY(fonttype, "BFont") ;
X if (window == KEYCANVAS) font = 'K' ;
X else if (window == REGCANVAS) font = 'R' ;
X line[0] = '\0' ;
X for (i = 0; i < strlen(str); i++)
X switch (str[i])
X {
X case '\\' : STRCAT(line,"\\\\") ;
X break ;
X case '(' : STRCAT(line,"\\(") ;
X break ;
X case ')' : STRCAT(line,"\\)") ;
X break ;
X default : STRNCAT(line, &str[i], 1) ;
X }
X FPRINTF(PostScript, "(%s) %d %cCHeight %d ", line, x, font, y) ;
X FPRINTF(PostScript, "%s %d %cC PSMakeText\n", fonttype, color, font) ;
X FFLUSH(PostScript) ;
X}
X
X
Xget_display() /* GET function key was pressed. */
X{
X}
X
X
Xget_next_event()
X{
X int type ;
X
X FFLUSH(PostScript) ;
X if (pscanf(PostScriptInput, "%d", &type) == EOF) destroy_frame() ;
X switch (type)
X {
X case KEYBOARD : pscanf(PostScriptInput, "%d", &cur_ch) ;
X case LEFT_DOWN :
X case MIDDLE_DOWN :
X case LEFT_UP :
X case MIDDLE_UP : pscanf(PostScriptInput, "%d%d", &curx, &cury) ;
X }
X return(type) ;
X}
X
X
Xhandle_selection() /* Handle the GET function key being pressed. */
X{
X}
X
X
Xinit_fonts()
X{
X FPRINTF(PostScript, "PSInitFonts\n") ;
X FFLUSH(PostScript) ;
X nfont_width = 9 ;
X}
X
X
Xinit_ws_type()
X{
X gtype = NEWS ;
X if (ps_open_PostScript() < 0) return -1 ;
X if (send_ps_file(NEWSFILE) == -1)
X {
X FCLOSE(PostScript) ;
X return(-1) ;
X }
X FFLUSH(PostScript) ;
X if (ferror(PostScript))
X {
X FCLOSE(PostScript) ;
X return(-1) ;
X }
X FPRINTF(PostScript, "PSIsColor\n") ;
X FFLUSH(PostScript) ;
X pscanf(PostScriptInput, "%d", &iscolor) ;
X FPRINTF(PostScript, "PSInitialise\n") ;
X FFLUSH(PostScript) ;
X return(0) ;
X}
X
X
Xload_colors() /* Create and load calctool color map. */
X{
X u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
X int i ;
X
X calc_colorsetup(red, green, blue) ;
X FPRINTF(PostScript, "%d PSMakeColorTable\n", CALC_COLORSIZE) ;
X for (i = 0; i < CALC_COLORSIZE; i++)
X FPRINTF(PostScript, "%d %d %d %d PSLoadColor\n",
X i, blue[i], green[i], red[i]) ;
X FFLUSH(PostScript) ;
X}
X
X
X/*ARGSUSED*/
Xmake_frames(argc, argv)
Xint argc ;
Xchar *argv[] ;
X{
X FPRINTF(PostScript, "%d %d %d %d %d %d %d PSMakeFrames\n",
X wx, wy, TWIDTH, DISPLAY+THEIGHT,
X ix, iy, iconic) ;
X FFLUSH(PostScript) ;
X}
X
X
Xmake_icon()
X{
X int depth, i, j, k, n ;
X char line[MAXLINE], name[MAXLINE], v[16][5] ;
X FILE *fin ;
X
X if (iscolor) STRCPY(name, "calctool.color.icon") ;
X else STRCPY(name, "calctool.icon") ;
X if ((fin = fopen(name, "r")) == NULL)
X {
X FPRINTF(stderr, "%s: can't open %s.\n", progname, name) ;
X exit(1) ;
X }
X depth = (iscolor) ? 8 : 1 ;
X FPRINTF(PostScript, "/calctoolIcon %d %d %1d { } { <\n",
X ICONWIDTH, ICONHEIGHT, depth) ;
X FGETS(line, MAXLINE, fin) ;
X FGETS(line, MAXLINE, fin) ;
X if (iscolor)
X {
X for (i = 0; i < 64; i++)
X for (j = 0; j < 4; j++)
X {
X FGETS(line, MAXLINE, fin) ;
X for (k = 0; k < 16; k++)
X {
X if (!(k % 2)) STRNCPY(v[k], &line[(k/2)*7+3], 2) ;
X else STRNCPY(v[k], &line[(k/2)*7+5], 2) ;
X v[k][2] = '\0' ;
X }
X if (j == 0 || j == 1) n = 16 ;
X else if (j == 2) n = 10 ;
X if (j != 3)
X {
X for (k = 0; k < n; k++)
X FPRINTF(PostScript, "%.2s ", v[k]) ;
X FPRINTF(PostScript, "\n") ;
X }
X }
X }
X else
X {
X for (i = 0; i < 32; i++)
X {
X FGETS(line, MAXLINE, fin) ;
X for (j = 0; j < 8; j++)
X {
X STRNCPY(v[j], &line[j*7+3], 4) ;
X v[j][4] = '\0' ;
X }
X FPRINTF(PostScript, "%.4s %.4s %.4s %.4s %.4s %.4s\n",
X v[0], v[1], v[2], v[4], v[5], v[6]) ;
X }
X }
X FPRINTF(PostScript, "> } buildimage def\n") ;
X FFLUSH(PostScript) ;
X FCLOSE(fin) ;
X}
X
X
Xmake_items() /* Null routine. */
X{}
X
X
Xmake_subframes() /* Null routine. */
X{}
X
X
Xsend_ps_file(fname)
Xchar *fname ;
X{
X FILE *stream ;
X int c ;
X
X if ((stream = fopen(fname,"r")) == NULL) return -1 ;
X while ((c = getc(stream)) != EOF) PUTC(c, PostScript) ;
X FCLOSE(stream) ;
X return 0 ;
X}
X
X
Xset_cursor(type)
Xint type ;
X{
X FPRINTF(PostScript, "%d PSSetCursor\n", type) ;
X FFLUSH(PostScript) ;
X}
X
X
Xstart_tool()
X{
X while (1)
X process_event(get_next_event()) ;
X}
X
X
Xtoggle_reg_canvas()
X
X{
X rstate = !rstate ;
X FPRINTF(PostScript, "%d PSToggleRegCanvas\n", rstate) ;
X FFLUSH(PostScript) ;
X}
SHAR_EOF
echo "File news.c is complete"
chmod 0444 news.c || echo "restore of news.c fails"
set `wc -c news.c`;Sum=$1
if test "$Sum" != "8102"
then echo original size 8102, current size $Sum;fi
echo "x - extracting sunview.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > sunview.c &&
X
X/* @(#)sunview.c 1.13 89/12/21
X *
X * These are the SunView 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 <suntool/sunview.h>
X#include <suntool/canvas.h>
X#include <suntool/selection_svc.h>
X#include <suntool/selection_attributes.h>
X
X#define ICON_SET (void) icon_set
X#define MENU_SET (void) menu_set
X#define NOTIFY_INTERPOSE_DESTROY_FUNC (void) notify_interpose_destroy_func
X#define PW_SETCMSNAME (void) pw_setcmsname
X#define PW_PUTCOLORMAP (void) pw_putcolormap
X#define PW_TTEXT (void) pw_ttext
X#define PW_VECTOR (void) pw_vector
X#define PW_WRITEBACKGROUND (void) pw_writebackground
X#define SELN_QUERY (void) seln_query
X#define WINDOW_DONE (void) window_done
X#define WINDOW_SET (void) window_set
X
X#define SMALLFONT "/usr/lib/fonts/fixedwidthfonts/screen.r.7"
X#define NORMALFONT "/usr/lib/fonts/fixedwidthfonts/screen.b.14"
X#define BIGFONT "/usr/lib/fonts/fixedwidthfonts/gallant.r.19"
X
Xvoid func_key_proc() ;
X
XCanvas kcanvas, rcanvas ;
XCursor help_cursor, main_cursor ;
XEvent *cur_event ;
XFrame frame, rframe ;
XIcon calctool_icon ;
XMenu menus[MAXMENUS] ;
XNotify_value destroy_proc() ;
XPixfont *font, *sfont, *nfont, *bfont ;
XPixwin *pw, *cpw, *rcpw ;
XSeln_client sel_client ;
XSeln_holder holder ;
XSeln_rank rank = SELN_PRIMARY ;
XSeln_result get_proc(), reply_proc() ;
X
Xshort help_cursor_array[16] = {
X#include "help.cursor"
X} ;
Xmpr_static(help_cursor_pr, 16, 16, 1, help_cursor_array) ;
X
Xunsigned short icon_image[] = {
X#include "calctool.icon"
X} ;
Xmpr_static(icon_pr, 64, 64, 1, icon_image) ;
X
Xshort cicon_image[] = {
X#include "calctool.color.icon"
X} ;
Xmpr_static(cicon_pr, 64, 64, 8, cicon_image) ;
X
X
X/*ARGSUSED*/
Xvoid
Xcanvas_proc(canvas, event, arg)
XCanvas canvas ;
XEvent *event ;
Xcaddr_t arg ;
X{
X cur_event = event ;
X process_event(get_next_event(event)) ;
X}
X
X
Xclear_canvas(window, color)
Xenum can_type window ;
Xint color ;
X{
X int height, width ;
X Canvas ctype ;
X
X if (window == KEYCANVAS)
X {
X pw = cpw ;
X ctype = frame ;
X }
X else if (window == REGCANVAS)
X {
X pw = rcpw ;
X ctype = rframe ;
X }
X height = (int) window_get(ctype, WIN_HEIGHT) ;
X width = (int) window_get(ctype, WIN_WIDTH) ;
X PW_WRITEBACKGROUND(pw, 0, 0, width, height, PIX_SRC | PIX_COLOR(color)) ;
X}
X
X
Xclose_frame()
X{
X if ((int) window_get(rframe, WIN_SHOW) == TRUE)
X WINDOW_SET(rframe, WIN_SHOW, FALSE, 0) ;
X WINDOW_SET(frame, FRAME_CLOSED, TRUE, 0) ;
X rstate = 0 ;
X}
X
X
Xcolor_area(x, y, width, height, color)
Xint x, y, width, height, color ;
X{
X PW_WRITEBACKGROUND(cpw, x, y, width, height, PIX_SRC | PIX_COLOR(color)) ;
X}
X
X
Xcreate_menu(mtype) /* Create popup menu for right button press. */
Xenum menu_type mtype ;
X{
X int i ;
X
X menus[(int) mtype] = menu_create(MENU_FONT, nfont, 0) ;
X for (i = 0; i < MAXREGS; i++)
X {
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 : MENU_SET(menus[(int) mtype], /* Register store. */
X MENU_STRING_ITEM, num_names[i], i+1, 0) ;
X break ;
X case M_CON : if (strlen(con_names[i])) /* Constants. */
X MENU_SET(menus[(int) mtype],
X MENU_STRING_ITEM, con_names[i], i+1, 0) ;
X break ;
X case M_FUN : if (strlen(fun_names[i])) /* Functions. */
X MENU_SET(menus[(int) mtype],
X MENU_STRING_ITEM, fun_names[i], i+1, 0) ;
X }
X }
X}
X
X
Xdestroy_frame()
X{
X WINDOW_DONE(frame) ;
X exit(0) ;
X}
X
X
Xdestroy_rframe(frame)
XFrame frame ;
X{
X rstate = 0 ;
X WINDOW_SET(frame, WIN_SHOW, FALSE, 0) ;
X}
X
X
X/*ARGSUSED*/
XNotify_value
Xdestroy_proc(client, status)
XNotify_client client ;
XDestroy_status status ;
X{
X exit(0) ;
X}
X
X
Xdo_menu(mtype) /* Popup appropriate menu and get value. */
Xenum menu_type mtype ;
X{
X return ((int) menu_show(menus[(int) mtype], kcanvas,
X canvas_window_event(kcanvas, cur_event), 0)) ;
X}
X
X
Xdrawline(x1, y1, x2, y2)
Xint x1, y1, x2, y2 ;
X{
X PW_VECTOR(cpw, x1, y1, x2, y2, PIX_SET, 0) ;
X}
X
X
Xdraw_regs()
X{
X make_registers() ;
X WINDOW_SET(rframe, WIN_SHOW, TRUE, 0) ;
X}
X
X
Xdrawtext(x, y, window, fontno, color, str)
Xenum font_type fontno ;
Xenum can_type window ;
Xint x, y, color ;
Xchar *str ;
X{
X if (fontno == SFONT) font = sfont ;
X else if (fontno == NFONT) font = nfont ;
X else if (fontno == BFONT) font = bfont ;
X if (window == KEYCANVAS) pw = cpw ;
X else if (window == REGCANVAS) pw = rcpw ;
X PW_TTEXT(pw, x, y, PIX_SRC | PIX_COLOR(color), font, str) ;
X}
X
X
X/*ARGSUSED*/
Xvoid
Xfunc_key_proc(client_data, args)
Xchar *client_data ;
XSeln_function_buffer *args ;
X{
X get_display() ;
X}
X
X
Xget_display() /* The GET function key has been pressed. */
X{
X if (seln_acquire(sel_client, SELN_SHELF) == SELN_SHELF)
X {
X if (shelf != NULL) free(shelf) ;
X shelf = malloc((unsigned) strlen(display)) ;
X STRCPY(shelf, display) ; /* Safely keep copy of display. */
X }
X}
X
X
XPixfont *
Xget_font(name)
Xchar *name ;
X{
X Pixfont *font ;
X
X font = pf_open(name) ;
X if (font == NULL) font = pf_default() ;
X if (font == NULL)
X {
X perror("couldn't get the default font.") ;
X exit(1) ;
X }
X return font ;
X}
X
X
Xget_next_event(event)
XEvent *event ;
X{
X static char eb[4] ; /* Event buffer. */
X int i ;
X
X#ifdef SUN4_KEYBOARD
X char *rpad = "\000\000\000=/*789456123" ;
X char *akeys = "8264" ;
X char *sun4keys = "\000\000\000+-\000\0000\000." ;
X#else
X char *rpad = "\000\000\00078945612301=" ;
X char *akeys = "5.31" ;
X#endif /*SUN4_KEYBOARD*/
X
X nextc = event_id(event) ;
X curx = event_x(event) ;
X cury = event_y(event) ;
X
X if (event_is_button(event))
X if (event_is_down(event) && nextc == MS_LEFT) return(LEFT_DOWN) ;
X else if (event_is_down(event) && nextc == MS_MIDDLE) return(MIDDLE_DOWN) ;
X else if (event_is_down(event) && nextc == MS_RIGHT) return(RIGHT_DOWN) ;
X else if (event_is_up(event) && nextc == MS_LEFT) return(LEFT_UP) ;
X else if (event_is_up(event) && nextc == MS_MIDDLE) return(MIDDLE_UP) ;
X else if (event_is_up(event) && nextc == MS_RIGHT) return(RIGHT_UP) ;
X
X/* The following code attempts to handle a numeric keypad using the right
X * function keys. This pad differs on the Sun3 and Sun4 keyboards. There
X * is a compile-time define which determines which keyboard setup is
X * looked for.
X */
X
X if (event_is_ascii(event))
X {
X
X/* If the last two events were escape and left square bracket.. */
X
X if (eb[0] && eb[1])
X {
X switch (nextc)
X {
X
X/* Interpret the arrow keys (if they are set).
X * R8 = ^[A R14 = ^[B R12 = ^[C R10 = ^[B
X */
X
X case 'A' :
X case 'B' :
X case 'C' :
X case 'D' : cur_ch = akeys[nextc - 'A'] ;
X eb[0] = eb[1] = '\0' ;
X return(KEYBOARD) ;
X
X/* Interpret the extra keys found on Sun4 keyboards.
X * These have codes of the form: ^[<int>z where <int> is a number
X * between 247 and 255. We're only interested in 4 of these keys.
X * These are:
X * ^[253z = + ^[254z = - ^[257z = 0 ^[259z = .
X */
X#ifdef SUN4_KEYBOARD
X case '2' : eb[2] = '2' ;
X break ;
X
X case '5' : if (eb[0] && eb[1] && eb[2])
X {
X eb[3] = '5' ;
X break ;
X }
X else
X
X/* Clear event_buf and treat as normal ascii char. */
X
X {
X eb[0] = eb[1] = '\0' ;
X cur_ch = nextc ;
X return(KEYBOARD) ;
X }
X
X case '3' :
X case '4' :
X case '7' :
X case '9' : if (eb[0] && eb[1] && eb[2] && eb[3])
X {
X cur_ch = sun4keys[nextc - '0'] ;
X eb[0] = eb[1] = eb[2] = eb[3] = '\0' ;
X return(KEYBOARD) ;
X }
X else if (eb[0] && eb[1] && eb[2] && nextc == '4')
X {
X eb[3] = nextc ;
X break ;
X }
X else
X
X/* Clear event_buf and treat as normal ascii char. */
X
X {
X eb[0] = eb[1] = '\0' ;
X cur_ch = nextc ;
X return(KEYBOARD) ;
X }
X#endif /*SUN4_KEYBOARD*/
X
X default : eb[0] = eb[1] = eb[2] = eb[3] = '\0' ;
X }
X }
X
X/* If previous events are ^[[ : set buffer */
X
X else if (nextc == '[' && eb[0]) /* Check for left square bracket. */
X eb[1] = '[' ;
X else if (nextc == '\033') /* Check for escape char. */
X eb[0] = '\033' ;
X else
X {
X
X/* All the rest of the ASCII characters. */
X
X eb[0] = eb[1] = '\0' ;
X cur_ch = nextc ;
X return(KEYBOARD) ;
X }
X }
X
X if (event_is_key_right(event) && event_is_up(event))
X {
X for (i = 1; i < 16; i++)
X if (nextc == KEY_RIGHT(i))
X {
X cur_ch = rpad[i-1] ;
X return(KEYBOARD) ;
X }
X }
X if (nextc == KBD_DONE && down) return(EXIT_WINDOW) ;
X if (nextc == LOC_WINEXIT || nextc == LOC_RGNEXIT) return(EXIT_WINDOW) ;
X if (nextc == LOC_WINENTER || nextc == LOC_RGNENTER) return(ENTER_WINDOW) ;
X if (nextc == WIN_REPAINT) return(CFRAME_REPAINT) ;
X if ((nextc == KEY_LEFT(6)) & event_is_up(event)) return(PUT_ON_SHELF) ;
X if ((nextc == KEY_LEFT(8)) && event_is_up(event)) return(TAKE_FROM_SHELF) ;
X return(LASTEVENTPLUSONE) ;
X}
X
X
XSeln_result
Xget_proc(buffer)
XSeln_request *buffer ;
X{
X issel = 0 ;
X if (*buffer->requester.context == 0)
X {
X if (buffer == (Seln_request *) NULL ||
X *((Seln_attribute *) buffer->data) != SELN_REQ_CONTENTS_ASCII)
X return ;
X selection = buffer->data + sizeof(Seln_attribute) ;
X *buffer->requester.context = 1 ;
X }
X else selection = buffer->data ;
X issel = 1 ;
X}
X
X
Xhandle_selection() /* Handle the GET function key being pressed. */
X{
X char context = 0 ;
X
X holder = seln_inquire(rank) ;
X if (holder.state == SELN_NONE) return ;
X SELN_QUERY(&holder, get_proc, &context, SELN_REQ_CONTENTS_ASCII, 0, 0) ;
X}
X
X
Xinit_fonts()
X{
X bfont = get_font(BIGFONT) ;
X nfont = get_font(NORMALFONT) ;
X nfont_width = nfont->pf_defaultsize.x ;
X sfont = get_font(SMALLFONT) ;
X}
X
X
Xinit_ws_type()
X{
X if (getenv("WINDOW_PARENT") == NULL)
X {
X FPRINTF(stderr,"%s: Not a native SunView window\n", progname) ;
X return -1 ;
X }
X gtype = SVIEW ;
X return 0 ;
X}
X
X
Xload_colors() /* Create and load calctool color map. */
X{
X Pixwin *frame_pw ;
X char colorname[CMS_NAMESIZE] ;
X u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
X
X iscolor = (cpw->pw_pixrect->pr_depth == 8) ? 1 : 0 ;
X SPRINTF(colorname, "%s%D", CALC_COLOR, getpid()) ;
X PW_SETCMSNAME(cpw, colorname) ;
X
X calc_colorsetup(red, green, blue) ;
X PW_PUTCOLORMAP(cpw, 0, CALC_COLORSIZE, red, green, blue) ;
X if (inv_video) pw_reversevideo(cpw, 0, CALC_COLORSIZE) ;
X
X if (iscolor)
X {
X frame_pw = (Pixwin *) window_get(frame, WIN_PIXWIN, 0) ;
X PW_SETCMSNAME(frame_pw, colorname) ;
X PW_PUTCOLORMAP(frame_pw, 0, CALC_COLORSIZE, red, green, blue) ;
X }
X}
X
X
Xmake_frames(argc, argv)
Xint argc ;
Xchar *argv[] ;
X{
X frame = window_create((Window) 0, FRAME,
X FRAME_ICON, calctool_icon,
X FRAME_SHOW_LABEL, FALSE,
X FRAME_NO_CONFIRM, TRUE,
X FRAME_ARGS, argc, argv,
X 0) ;
X sel_client = seln_create(func_key_proc, reply_proc, (char *) 0) ;
X NOTIFY_INTERPOSE_DESTROY_FUNC(frame, destroy_proc) ;
X rframe = window_create(frame, FRAME,
X FRAME_SHOW_LABEL, FALSE,
X FRAME_NO_CONFIRM, TRUE,
X FRAME_DONE_PROC, destroy_rframe,
X WIN_X, TWIDTH+15,
X WIN_Y, 0,
X WIN_SHOW, FALSE,
X WIN_WIDTH, TWIDTH,
X WIN_HEIGHT, 200,
X WIN_FONT, nfont,
X 0) ;
X
X}
X
X
Xmake_icon()
X{
X calctool_icon = icon_create(ICON_WIDTH, ICONWIDTH,
X ICON_IMAGE, &icon_pr,
X 0) ;
X}
X
X
Xmake_items()
X{
X main_cursor = window_get(kcanvas, WIN_CURSOR) ;
X
X if (iscolor)
X {
X calctool_icon = (Icon) window_get(frame, FRAME_ICON) ;
X ICON_SET(calctool_icon, ICON_IMAGE, &cicon_pr, 0) ;
X WINDOW_SET(frame, FRAME_ICON, calctool_icon, 0) ;
X }
X
X help_cursor = cursor_create(CURSOR_XHOT, 0,
X CURSOR_YHOT, 0,
X CURSOR_OP, PIX_SRC | PIX_DST,
X CURSOR_IMAGE, &help_cursor_pr, 0) ;
X window_fit(frame) ;
X}
X
X
Xmake_subframes()
X{
X rcanvas = window_create(rframe, CANVAS, 0) ;
X kcanvas = window_create(frame, CANVAS,
X CANVAS_RETAINED, FALSE,
X WIN_EVENT_PROC, canvas_proc,
X WIN_WIDTH, TWIDTH,
X WIN_HEIGHT, THEIGHT + DISPLAY,
X WIN_FONT, nfont,
X 0) ;
X
X WINDOW_SET(kcanvas, WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS,
X WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
X WIN_UP_EVENTS, 0, 0) ;
X WINDOW_SET(kcanvas, WIN_IGNORE_PICK_EVENT, LOC_MOVE, 0) ;
X cpw = canvas_pixwin(kcanvas) ;
X rcpw = canvas_pixwin(rcanvas) ;
X}
X
X
X/*ARGSUSED*/
XSeln_result
Xreply_proc(item, context, length)
XSeln_attribute item ;
XSeln_replier_data *context ;
Xint length ;
X{
X int size ;
X char *destp ;
X
X switch (item)
X {
X case SELN_REQ_CONTENTS_ASCII :
X
X if (context->context == NULL)
X {
X if (shelf == NULL) return(SELN_DIDNT_HAVE) ;
X context->context = shelf ;
X }
X size = strlen(context->context) ;
X destp = (char *) context->response_pointer ;
X STRCPY(destp, context->context) ;
X destp += size ;
X while ((int) destp % 4 != 0) *destp++ = '\0' ;
X context->response_pointer = (char **) destp ;
X *context->response_pointer++ = 0 ;
X return(SELN_SUCCESS) ;
X
X case SELN_REQ_YIELD :
X
X *context->response_pointer++ = (char *) SELN_SUCCESS ;
X return(SELN_SUCCESS) ;
X
X case SELN_REQ_BYTESIZE :
X
X if (shelf == NULL) return(SELN_DIDNT_HAVE) ;
X *context->response_pointer++ = (char *) strlen(shelf) ;
X return(SELN_SUCCESS) ;
X
X case SELN_REQ_END_REQUEST : return(SELN_SUCCESS) ;
X
X default : return(SELN_UNRECOGNIZED) ;
X }
X}
X
X
Xset_cursor(type)
Xint type ;
X{
X switch (type)
X {
X case HELPCURSOR : WINDOW_SET(kcanvas, WIN_CURSOR, help_cursor, 0) ;
X break ;
X case MAINCURSOR : WINDOW_SET(kcanvas, WIN_CURSOR, main_cursor, 0) ;
X }
X}
X
X
Xstart_tool()
X{
X window_main_loop(frame) ;
X}
X
X
Xtoggle_reg_canvas()
X{
X rstate = !rstate ;
X if (rstate) draw_regs() ;
X else WINDOW_SET(rframe, WIN_SHOW, FALSE, 0) ;
X}
SHAR_EOF
chmod 0444 sunview.c || echo "restore of sunview.c fails"
set `wc -c sunview.c`;Sum=$1
if test "$Sum" != "16635"
then echo original size 16635, current size $Sum;fi
echo "x - extracting tty.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > tty.c &&
X
X/* @(#)tty.c 1.12 89/12/21
X *
X * These are the dumb tty 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
Xchar *CE, *CL, *CM, *SE, *SO ;
X
Xchar *getenv(), *tgetstr(), *tgoto() ;
Xint destroy_frame(), outc() ;
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 ; /* Read mask used in select call. */
X#endif /*NO_4_3SELECT*/
X
Xstruct sgttyb in_new, in_old ;
X
X
XSIGRET
Xcleanup()
X{
X destroy_frame() ;
X}
X
X
X/*ARGSUSED*/
Xclear_canvas(canvas, color)
Xenum can_type canvas ;
Xint color ;
X{
X int i,j ;
X
X if (canvas == REGCANVAS)
X for (i = 0; i < 24; i++)
X {
X tputs(tgoto(CM, i, 43), 1, outc) ;
X do_move(43, i) ;
X do_clr_eol() ;
X }
X else for (i = 0; i < 24; i++)
X {
X do_move(0, i) ;
X for (j = 0; j < 42; j++) outc(' ') ;
X }
X do_move(41, 1) ;
X}
X
X
Xclose_frame() {} /* This option does nothing with termcap. */
X
X
X/*ARGSUSED*/
Xcolor_area(x, y, width, height, color) /* Color an area - null routine. */
Xint x, y, width, height, color ;
X{}
X
X
X/*ARGSUSED*/
Xcreate_menu(mtype) /* Create popup menu - null routine. */
Xenum menu_type mtype ;
X{}
X
X
Xdestroy_frame()
X{
X int i ;
X
X tputs(CL, 1, outc) ;
X for (i = 0; i < 24; i++)
X {
X do_move(0, i) ;
X do_clr_eol() ;
X }
X do_move(0, 0) ;
X SIGNAL(SIGINT, SIG_IGN) ;
X IOCTL(0, TIOCSETP, &in_old) ;
X exit(0) ;
X}
X
X
Xdo_clr_eol() /* Clear to the end of the line. */
X{
X tputs(CE, 1, outc) ;
X}
X
X
X/*ARGSUSED*/
Xdo_menu(mtype) /* Popup appropriate menu (null routine). */
Xenum menu_type mtype ;
X{}
X
X
Xdo_move(x, y) /* Move to character position (x, y). */
Xint x, y ;
X{
X tputs(tgoto(CM, x, y), 1, outc) ;
X}
X
X
Xdo_standend() /* Finish inverted area. */
X{
X tputs(SE, 1, outc) ;
X}
X
X
Xdo_standout() /* Start inverted area. */
X{
X tputs(SO, 1, outc) ;
X}
X
X
Xdrawline(x1, y1, x2, y2)
Xint x1, y1, x2, y2 ;
X{
X double dx ;
X int i, offset, x, y ;
X
X if (x1)
X {
X dx = (float) (x1 - BBORDER) / (BWIDTH + BGAP) ;
X if (dx == (int) dx) offset = 1 ;
X else offset = 6 ;
X
X x = ((x1 - BBORDER) / (BWIDTH + BGAP) * 7) + offset ;
X y = ((y1 - BBORDER) / (BHEIGHT + BGAP) * 3) + 5 ;
X do_move(x, y) ;
X if (x1 == x2)
X {
X if ((y2 - y1) != BHEIGHT) return ;
X outc('+') ;
X for (i = 0; i < 2; i++)
X {
X do_move(x, y+i+1) ;
X outc('|') ;
X }
X do_move(x, y+3) ;
X outc('+') ;
X }
X else
X {
X if ((x2 - x1) != BWIDTH) return ;
X outc('+') ;
X for (i = 0; i < 4; i++)
X {
X do_move(x+i+1, y) ;
X outc('-') ;
X }
X do_move(x+5, y) ;
X outc('+') ;
X }
X }
X else
X {
X do_move(0, 4) ;
X for (i = 0; i < 42; i++) outc('-') ;
X }
X}
X
X
Xdraw_regs()
X{
X}
X
X
X/*ARGSUSED*/
Xdrawtext(tx, ty, window, fontno, color, str)
Xenum can_type window ;
Xenum font_type fontno ;
Xint tx, ty, color ;
Xchar *str ;
X{
X char key[5] ;
X int i, invert, sps ;
X
X invert = 0 ;
X if (window == REGCANVAS) /* Register window. */
X {
X tx = 45 ;
X ty = ((ty / 15 - 1) * 2) + 1 ;
X }
X else if (window == KEYCANVAS && tx == 5) /* Help screen. */
X {
X tx = 1 ;
X ty = ty / 15 ;
X }
X else if (window == KEYCANVAS && ty < DISPLAY)
X {
X if (color == WHITE)
X for (i = 0; i < strlen(str); i++) str[i] = ' ' ;
X
X if (ty == (DISPLAY-3)) /* Base, trig and op items. */
X {
X tx = tx * 42 / (TWIDTH) + 1 ;
X ty = 3 ;
X }
X else /* Display item. */
X {
X tx = 41 - strlen(str) ;
X ty = 1 ;
X }
X }
X else /* Button values. */
X {
X tx = ((tx - BBORDER) / (BWIDTH + BGAP) * 7) + 2 ;
X for (sps = 0, i = 0; i < 4; i++)
X if (str[i] == ' ') sps++ ;
X ty = (ty - 34) / 30 ;
X ty = (ty - (ty % 2)) * 3 / 2 + 6 + (ty % 2) ;
X switch (sps)
X {
X case 0 :
X case 1 :
X case 4 : STRCPY(key, str) ;
X break ;
X case 2 :
X case 3 : key[0] = ' ' ;
X STRNCPY(&key[1], str, 3) ;
X }
X key[5] = '\0' ;
X STRCPY(str, key) ;
X if (ty % 3) invert = 1 ;
X }
X do_move(tx, ty) ;
X if (window == REGCANVAS) do_clr_eol() ;
X if (invert) do_standout() ;
X outstr(str) ;
X if (invert) do_standend() ;
X do_move(41, 1) ;
X}
X
X
Xget_display() /* No GET key; null routine. */
X{}
X
X
Xget_next_event() /* Only events possible are keyboard ones. */
X{
X char c ;
X int reply ;
X
X for (;;)
X {
X readmask = fullmask ;
X#ifdef NO_4_3SELECT
X reply = select(32, &readmask, 0, 0, (struct timeval *) 0) ;
X if (reply == -1) /* do nothing. */
X else if (readmask && (1 << 0))
X#else
X reply = select(FD_SETSIZE, &readmask, (fd_set *) 0, (fd_set *) 0,
X (struct timeval *) 0) ;
X if (reply == -1) /* do nothing. */ ;
X else if (FD_ISSET(0, &readmask))
X#endif /*NO_4_3SELECT*/
X {
X READ(0, &c, 1) ;
X cur_ch = c ;
X return(KEYBOARD) ;
X }
X }
X}
X
X
Xhandle_selection() /* There is no PUT function key with termcap. */
X{}
X
X
Xinit_fonts() /* No fonts with the termcap version. */
X{
X nfont_width = 8 ;
X}
X
X
Xinit_ws_type() /* Check if terminal capable of termcap output. */
X{
X char bp[1024], termtype[MAXLINE] ;
X int i ;
X static char buf[100] ;
X char *area = buf ;
X
X if (getenv("TERM") != NULL) STRCPY(termtype, getenv("TERM")) ;
X if (tgetent(bp, termtype) != 1) return 1 ;
X if ((CL = tgetstr("cl", &area)) == (char *) 0) return 1 ;
X if ((CM = tgetstr("cm", &area)) == (char *) 0) return 1 ;
X if ((CE = tgetstr("ce", &area)) == (char *) 0) return 1 ;
X if ((SO = tgetstr("so", &area)) == (char *) 0) return 1 ;
X if ((SE = tgetstr("se", &area)) == (char *) 0) return 1 ;
X for (i = 0; i < 24; i++)
X {
X do_move(0, i) ;
X do_clr_eol() ;
X }
X gtype = TTY ;
X return 0 ;
X}
X
X
Xload_colors()
X{
X iscolor = 0 ; /* No colors in the termcap implementation. */
X}
X
X
X/*ARGSUSED*/
Xmake_frames(argc, argv)
Xint argc ;
Xchar *argv[] ;
X{
X int i ;
X
X SIGNAL(SIGINT, cleanup) ;
X
X#ifdef NO_4_3SELECT
X fullmask = 1 ; /* Set mask for fd #0. */
X#else
X FD_ZERO(&fullmask) ;
X FD_SET(0, &fullmask) ;
X#endif /*NO_4_3SELECT*/
X
X IOCTL(0, TIOCGETP, &in_old) ; /* Setup standard input. */
X in_new = in_old ;
X in_new.sg_flags |= RAW ;
X in_new.sg_flags &= ~(ECHO | CRMOD) ;
X IOCTL(0, TIOCSETP, &in_new) ;
X
X setbuf(stdout, (char *) NULL) ;
X
X tputs(CL, 1, outc) ;
X do_move(0, 4) ;
X for (i = 0; i < 41; i++) outc('-') ;
X for (i = 0; i < 24; i++)
X {
X do_move(42, i) ;
X if (i == 4) outc('+') ;
X else outc('|') ;
X }
X}
X
X
Xmake_icon() {} /* There is no icon with termcap. */
X
X
Xmake_items()
X{
X do_repaint() ; /* Redraw the calctool canvas[es]. */
X}
X
X
Xmake_subframes() {} /* There are no subframes with termcap. */
X
X
Xoutc(c) /* Output the next character to the screen. */
Xint c ;
X{
X PUTC(c, stdout) ;
X}
X
X
Xoutstr(str)
Xchar *str ;
X{
X int i ;
X
X for (i = 0; i < strlen(str); i++) PUTC(str[i], stdout) ;
X}
X
X
X/*ARGSUSED*/
Xset_cursor(type) /* There are no cursors with termcap. */
Xint type ;
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 clear_canvas(REGCANVAS, WHITE) ;
X if (rstate) make_registers() ;
X}
SHAR_EOF
chmod 0444 tty.c || echo "restore of tty.c fails"
set `wc -c tty.c`;Sum=$1
if test "$Sum" != "8330"
then echo original size 8330, current size $Sum;fi
echo "x - extracting x11.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > x11.c &&
X
X/* @(#)x11.c 1.14 89/12/21
X *
X * These are the X11 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 <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X
X#define XGETSIZEHINTS (void) XGetSizeHints
X
X#define BIGFONT "helvetica-bold-14"
X#define DEFFONT "fixed"
X#define NORMALFONT "fixed"
X#define SMALLFONT "6x10"
X
X#define CALCTOOL_BORDER_WIDTH 2
X
X#define FRAME_MASK (ButtonPressMask | ButtonReleaseMask | KeyPressMask | \
X EnterWindowMask | LeaveWindowMask | ExposureMask)
X
Xshort help_cursor_array[16] = {
X#include "help.cursor"
X} ;
X
Xshort icon_image[] = {
X#include "calctool.icon"
X} ;
X
Xshort cicon_image[] = {
X#include "calctool.color.icon"
X} ;
X
XAtom protocol_atom, kill_atom ;
XCursor help_cursor, main_cursor ;
XDisplay *dpy ;
XGC gc ;
XPixmap calctool_icon, help_pixmap ;
XPixmap load_icon() ;
XWindow frame, rframe ;
XXColor BGcolor, FGcolor, current_col ;
XXEvent event ;
XXFontStruct *bfont, *font, *nfont, *sfont ;
XXGCValues gc_val ;
XXSizeHints size ;
XXWMHints wm_hints ;
X
Xunsigned long gc_mask ;
Xint screen ;
Xunsigned int scr_depth ;
Xunsigned long backgnd, foregnd ;
Xunsigned long palette[CALC_COLORSIZE] ;
X
X
Xclear_canvas(ctype, color)
Xenum can_type ctype ;
Xint color ;
X{
X XSizeHints hints ;
X Window window ;
X
X if (ctype == KEYCANVAS) window = frame ;
X else if (ctype == REGCANVAS) window = rframe ;
X XGETSIZEHINTS(dpy, window, &hints, XA_WM_NORMAL_HINTS) ;
X if (iscolor) gc_val.foreground = palette[color] ;
X else
X {
X if (color == WHITE) gc_val.foreground = backgnd ;
X else gc_val.foreground = foregnd ;
X }
X gc_val.function = GXcopy ;
X XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
X XFillRectangle(dpy, window, gc, 0, 0, hints.width, hints.height) ;
X}
X
X
Xclose_frame()
X{
X iconic = 1 ;
X rstate = 0 ;
X XIconifyWindow(dpy, frame, screen) ;
X}
X
X
Xcolor_area(x, y, width, height, color)
Xint x, y, width, height, color ;
X{
X if (iscolor) gc_val.foreground = palette[color] ;
X else
X {
X if (color == WHITE) gc_val.foreground = backgnd ;
X else gc_val.foreground = foregnd ;
X }
X gc_val.function = GXcopy ;
X XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
X XFillRectangle(dpy, frame, gc, x, y,
X (unsigned int) width, (unsigned int) height) ;
X}
X
X
Xcreate_menu(mtype) /* Create popup menu for right button press. */
Xenum menu_type mtype ;
X{
X}
X
X
Xdestroy_frame()
X{
X XDestroyWindow(dpy, frame) ;
X XDestroyWindow(dpy, rframe) ;
X exit(0) ;
X}
X
X
Xdo_menu(mtype) /* Popup appropriate menu and get value. */
Xenum menu_type mtype ;
X{
X}
X
X
Xdrawline(x1, y1, x2, y2)
Xint x1, y1, x2, y2 ;
X{
X if (iscolor) gc_val.foreground = palette[BLACK] ;
X else gc_val.foreground = foregnd ;
X gc_val.function = GXcopy ;
X XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
X XDrawLine(dpy, frame, gc, x1, y1, x2, y2) ;
X}
X
X
Xdraw_regs()
X{
X XMapWindow(dpy, rframe) ;
X}
X
X
Xdrawtext(x, y, ctype, fontno, color, str)
Xenum font_type fontno ;
Xenum can_type ctype ;
Xint x, y, color ;
Xchar *str ;
X{
X Window window ;
X
X if (fontno == SFONT) font = sfont ;
X else if (fontno == NFONT) font = nfont ;
X else if (fontno == BFONT) font = bfont ;
X if (ctype == KEYCANVAS) window = frame ;
X else if (ctype == REGCANVAS) window = rframe ;
X
X if (ctype == KEYCANVAS && y == items[DISPLAYITEM].y) x += 100 ;
X if (iscolor) gc_val.foreground = palette[color] ;
X else
X {
X if (color == WHITE) gc_val.foreground = backgnd ;
X else gc_val.foreground = foregnd ;
X }
X gc_val.font = font->fid ;
X gc_val.function = GXcopy ;
X XChangeGC(dpy, gc, GCFont | GCForeground | GCFunction, &gc_val) ;
X XDrawString(dpy, window, gc, x, y, str, strlen(str)) ;
X}
X
X
Xget_display() /* GET function key was pressed. */
X{
X}
X
X
XXFontStruct *
Xget_font(name)
Xchar *name ;
X{
X XFontStruct *font ;
X
X if (!(font = XLoadQueryFont(dpy, name)))
X if (!(font = XLoadQueryFont(dpy, DEFFONT)))
X {
X perror("couldn't get the default font.") ;
X exit(1) ;
X }
X return(font) ;
X}
X
X
Xget_next_event()
X{
X XClientMessageEvent *ev ;
X XKeyPressedEvent *key_event ;
X char chs[2] ;
X
X if (!XCheckMaskEvent(dpy, ExposureMask, &event))
X XNextEvent(dpy, &event) ;
X
X switch (event.type)
X {
X case ClientMessage : /* Catch ICCCM kill from WM. */
X
X ev = (XClientMessageEvent *) &event ;
X if (ev->message_type == protocol_atom &&
X ev->data.l[0] == kill_atom)
X exit(0) ;
X return(LASTEVENTPLUSONE) ;
X
X case Expose : return(process_expose(&event)) ;
X
X case EnterNotify : return(ENTER_WINDOW) ;
X
X case LeaveNotify : return(EXIT_WINDOW) ;
X
X case KeyPress : key_event = (XKeyPressedEvent *) &event ;
X curx = key_event->x ;
X cury = key_event->y ;
X (void) XLookupString(key_event, chs, 1,
X (KeySym *) NULL,
X (XComposeStatus *) NULL) ;
X cur_ch = chs[0] ;
X return(KEYBOARD) ;
X
X case ButtonPress : curx = event.xbutton.x ;
X cury = event.xbutton.y ;
X if (event.xbutton.button == Button1)
X return(LEFT_DOWN) ;
X else if (event.xbutton.button == Button2)
X return(MIDDLE_DOWN) ;
X else if (event.xbutton.button == Button3)
X return(RIGHT_DOWN) ;
X
X case ButtonRelease : curx = event.xbutton.x ;
X cury = event.xbutton.y ;
X if (event.xbutton.button == Button1)
X return(LEFT_UP) ;
X else if (event.xbutton.button == Button2)
X return(MIDDLE_UP) ;
X else if (event.xbutton.button == Button3)
X return(RIGHT_UP) ;
X
X default : return(LASTEVENTPLUSONE) ;
X }
X/*NOTREACHED*/
X}
X
X
Xhandle_selection()
X{
X}
X
X
Xinit_fonts()
X{
X bfont = get_font(BIGFONT) ;
X nfont = get_font(NORMALFONT) ;
X nfont_width = 6 ;
X sfont = get_font(SMALLFONT) ;
X}
X
X
Xinit_ws_type()
X{
X if ((dpy = XOpenDisplay(x11_display)) == NULL)
X {
X FPRINTF(stderr,"%s: Couldn't open display %s\n", progname,
X (getenv ("DISPLAY") ? getenv("DISPLAY") : x11_display)) ;
X exit(1) ;
X }
X
X screen = DefaultScreen(dpy) ;
X
X if (!geometry)
X STRCPY(geometry, XGetDefault(dpy, progname, "Geometry")) ;
X
X foregnd = BlackPixel(dpy, screen) ;
X backgnd = WhitePixel(dpy, screen) ;
X scr_depth = DefaultDepth(dpy, screen) ;
X gtype = X11 ;
X return 0 ;
X}
X
X
Xload_colors() /* Create and load calctool color map. */
X{
X u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
X int i, numcolors ;
X
X iscolor = 0 ;
X if (DisplayCells(dpy, screen) > 2)
X {
X calc_colorsetup(red, green, blue) ;
X iscolor = 1 ;
X numcolors = 0 ;
X for (i = 0; i < CALC_COLORSIZE; i++)
X {
X current_col.flags = DoRed | DoGreen | DoBlue ;
X current_col.red = (unsigned short) (red[i] << 8) ;
X current_col.green = (unsigned short) (green[i] << 8) ;
X current_col.blue = (unsigned short) (blue[i] << 8) ;
X if (XAllocColor(dpy, DefaultColormap(dpy, screen), ¤t_col) == True)
X palette[numcolors++] = current_col.pixel ;
X }
X if (numcolors < 2)
X {
X FPRINTF(stderr, "%s: cannot allocate colors.\n", progname) ;
X exit(1) ;
X }
X }
X}
X
X
XCursor
Xload_cursor(sbuf)
Xshort sbuf[16] ;
X{
X char cbuf[32] ;
X int i ;
X
X for (i = 0; i < 16; i++)
X {
X cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
X cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
X }
X help_pixmap = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), cbuf,
X 16, 16, foregnd, backgnd, 1) ;
X return(XCreatePixmapCursor(dpy, help_pixmap, help_pixmap,
X &FGcolor, &BGcolor, 0, 0)) ;
X}
X
X
XPixmap
Xload_icon(sbuf)
Xshort sbuf[] ;
X{
X GC pix_gc ;
X Pixmap pixmap ;
X XImage *image ;
X char cbuf[512*8] ;
X int i ;
X
X if (iscolor)
X {
X for (i = 0; i < (256*8); i++)
X {
X cbuf[i*2+0] = palette[(sbuf[i] >> 8) & 0xFF] ;
X cbuf[i*2+1] = palette[sbuf[i] & 0xFF] ;
X }
X pix_gc = DefaultGC(dpy, screen) ;
X image = XCreateImage(dpy, DefaultVisual(dpy, screen),
X scr_depth, ZPixmap, 0, cbuf, 64, 64, 8, 64) ;
X pixmap = XCreatePixmap(dpy, RootWindow(dpy, screen),
X ICONWIDTH, (unsigned) image->height, scr_depth) ;
X XPutImage(dpy, pixmap, pix_gc, image, 0, 0, 0, 0,
X ICONWIDTH, (unsigned) image->height) ;
X }
X else
X {
X for (i = 0; i < 256; i++)
X {
X cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
X cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
X }
X pixmap = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), cbuf,
X 64, 64, foregnd, backgnd, scr_depth) ;
X }
X return(pixmap) ;
X}
X
X
Xmake_frames(argc, argv)
Xint argc ;
Xchar *argv[] ;
X{
X unsigned int h, w ; /* Window dimensions. */
X int flags ;
X int x, y ; /* Window position. */
SHAR_EOF
echo "End of part 4"
echo "File x11.c is continued in part 5"
echo "5" > s2_seq_.tmp
exit 0
More information about the Comp.sources.misc
mailing list