home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume10 / calctool24 / part04 < prev    next >
Encoding:
Text File  |  1990-01-15  |  44.1 KB  |  1,742 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v10i009: Calctool V2.4 - a simple calculator (Part 4 of 6).
  3. from: richb@Aus.Sun.COM (Rich Burridge)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 10, Issue 9
  7. Submitted-by: richb@Aus.Sun.COM (Rich Burridge)
  8. Archive-name: calctool24/part04
  9.  
  10. ---- Cut Here and unpack ----
  11. #!/bin/sh
  12. # this is part 4 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file news.c continued
  15. #
  16. CurArch=4
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. echo "x - Continuing file news.c"
  27. sed 's/^X//' << 'SHAR_EOF' >> news.c
  28. X  for (i = 0; i < MAXREGS; i++)
  29. X    {
  30. X      switch (mtype)
  31. X        {
  32. X          case M_ACC    :                              /* Accuracies. */
  33. X          case M_EXCH   :                              /* Register exchange. */
  34. X          case M_LSHIFT :                              /* Left shift. */
  35. X          case M_RCL    :                              /* Register recall. */
  36. X          case M_RSHIFT :                              /* Right shift. */
  37. X          case M_STO    :                              /* Register store. */
  38. X                          FPRINTF(PostScript, "(%s)", num_names[i]) ;
  39. X                          break ;
  40. X          case M_CON    :                              /* Constants. */
  41. X                          FPRINTF(PostScript, "(%s)", con_names[i]) ;
  42. X                          break ;
  43. X          case M_FUN    :                              /* Functions. */
  44. X                          FPRINTF(PostScript, "(%s)", fun_names[i]) ;
  45. X                          break ;
  46. X        }
  47. X      FPRINTF(PostScript, " { %1d typedprint }\n", (int) mtype) ;
  48. X    }
  49. X  FPRINTF(PostScript, "] /new DefaultMenu send def\n") ;
  50. X  FFLUSH(PostScript) ;
  51. X}
  52. X
  53. X
  54. Xdestroy_frame()
  55. X{
  56. X  exit(0) ;
  57. X}
  58. X
  59. X
  60. Xdo_menu(mtype)      /* Popup appropriate menu and get value. */
  61. Xenum menu_type mtype ;
  62. X{
  63. X  int mval ;
  64. X
  65. X  FPRINTF(PostScript, "{ /ParentMenu Menu%1d def } ClientMenu send\n",
  66. X                      (int) mtype) ;
  67. X  FFLUSH(PostScript) ;
  68. X  pscanf(PostScriptInput, "%d", &mval) ;
  69. X  return(mval) ;
  70. X}
  71. X
  72. X
  73. Xdrawline(x1, y1, x2, y2)
  74. Xint x1, y1, x2, y2 ;
  75. X{
  76. X  FPRINTF(PostScript, "%d %d %d %d PSDrawLine\n", x1, x2, y1, y2) ;
  77. X  FFLUSH(PostScript) ;
  78. X}
  79. X
  80. X
  81. Xdraw_regs()
  82. X{
  83. X  FPRINTF(PostScript, "PSDrawRegs\n") ;
  84. X  FFLUSH(PostScript) ;
  85. X}
  86. X
  87. X
  88. Xdrawtext(x, y, window, fontno, color, str)
  89. Xenum can_type window ;
  90. Xenum font_type fontno ;
  91. Xint x, y, color ;
  92. Xchar *str ;
  93. X{
  94. X  int i ;
  95. X  char font, fonttype[6], line[MAXLINE] ;
  96. X       if (fontno == SFONT) STRCPY(fonttype, "SFont") ;
  97. X  else if (fontno == NFONT) STRCPY(fonttype, "NFont") ;
  98. X  else if (fontno == BFONT) STRCPY(fonttype, "BFont") ;
  99. X       if (window == KEYCANVAS) font = 'K' ;
  100. X  else if (window == REGCANVAS) font = 'R' ;
  101. X  line[0] = '\0' ;
  102. X  for (i = 0; i < strlen(str); i++)
  103. X    switch (str[i])
  104. X      {
  105. X        case '\\' : STRCAT(line,"\\\\") ;
  106. X                    break ;
  107. X        case '('  : STRCAT(line,"\\(") ;
  108. X                    break ;
  109. X        case ')'  : STRCAT(line,"\\)") ;
  110. X                    break ;
  111. X        default   : STRNCAT(line, &str[i], 1) ;
  112. X      }
  113. X  FPRINTF(PostScript, "(%s) %d %cCHeight %d ", line, x, font, y) ;
  114. X  FPRINTF(PostScript, "%s %d %cC PSMakeText\n", fonttype, color, font) ;
  115. X  FFLUSH(PostScript) ;
  116. X}
  117. X
  118. X
  119. Xget_display()         /* GET function key was pressed. */
  120. X{
  121. X}
  122. X
  123. X
  124. Xget_next_event()
  125. X{
  126. X  int type ;
  127. X
  128. X  FFLUSH(PostScript) ;
  129. X  if (pscanf(PostScriptInput, "%d", &type) == EOF) destroy_frame() ;
  130. X  switch (type)
  131. X    {
  132. X      case KEYBOARD    : pscanf(PostScriptInput, "%d", &cur_ch) ;
  133. X      case LEFT_DOWN   :
  134. X      case MIDDLE_DOWN :
  135. X      case LEFT_UP     :
  136. X      case MIDDLE_UP   : pscanf(PostScriptInput, "%d%d", &curx, &cury) ;
  137. X    }
  138. X  return(type) ;
  139. X}
  140. X
  141. X
  142. Xhandle_selection()      /* Handle the GET function key being pressed. */
  143. X{
  144. X}
  145. X
  146. X
  147. Xinit_fonts()
  148. X{
  149. X  FPRINTF(PostScript, "PSInitFonts\n") ;
  150. X  FFLUSH(PostScript) ;
  151. X  nfont_width = 9 ;
  152. X}
  153. X
  154. X
  155. Xinit_ws_type()
  156. X{
  157. X  gtype = NEWS ;
  158. X  if (ps_open_PostScript() < 0) return -1 ;
  159. X  if (send_ps_file(NEWSFILE) == -1)
  160. X    {
  161. X      FCLOSE(PostScript) ;
  162. X      return(-1) ;
  163. X    }
  164. X  FFLUSH(PostScript) ;
  165. X  if (ferror(PostScript))
  166. X    {
  167. X      FCLOSE(PostScript) ;
  168. X      return(-1) ;
  169. X    }
  170. X  FPRINTF(PostScript, "PSIsColor\n") ;
  171. X  FFLUSH(PostScript) ;
  172. X  pscanf(PostScriptInput, "%d", &iscolor) ;
  173. X  FPRINTF(PostScript, "PSInitialise\n") ;
  174. X  FFLUSH(PostScript) ;
  175. X  return(0) ;
  176. X}
  177. X
  178. X
  179. Xload_colors()      /* Create and load calctool color map. */
  180. X{
  181. X  u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
  182. X  int i ;
  183. X
  184. X  calc_colorsetup(red, green, blue) ;
  185. X  FPRINTF(PostScript, "%d PSMakeColorTable\n", CALC_COLORSIZE) ;
  186. X  for (i = 0; i < CALC_COLORSIZE; i++)
  187. X    FPRINTF(PostScript, "%d %d %d %d PSLoadColor\n",
  188. X                         i, blue[i], green[i], red[i]) ;
  189. X  FFLUSH(PostScript) ;
  190. X}
  191. X
  192. X
  193. X/*ARGSUSED*/
  194. Xmake_frames(argc, argv)
  195. Xint argc ;
  196. Xchar *argv[] ;
  197. X{
  198. X  FPRINTF(PostScript, "%d %d %d %d %d %d %d PSMakeFrames\n",
  199. X                     wx, wy, TWIDTH, DISPLAY+THEIGHT,
  200. X                     ix, iy, iconic) ;
  201. X  FFLUSH(PostScript) ;
  202. X}
  203. X
  204. X
  205. Xmake_icon()
  206. X{
  207. X  int depth, i, j, k, n ;
  208. X  char line[MAXLINE], name[MAXLINE], v[16][5] ;
  209. X  FILE *fin ;
  210. X
  211. X  if (iscolor) STRCPY(name, "calctool.color.icon") ;
  212. X  else STRCPY(name, "calctool.icon") ;
  213. X  if ((fin = fopen(name, "r")) == NULL)
  214. X    {
  215. X      FPRINTF(stderr, "%s: can't open %s.\n", progname, name) ;
  216. X      exit(1) ;
  217. X    }
  218. X  depth = (iscolor) ? 8 : 1 ;
  219. X  FPRINTF(PostScript, "/calctoolIcon %d %d %1d { } { <\n",
  220. X                      ICONWIDTH, ICONHEIGHT, depth) ;
  221. X  FGETS(line, MAXLINE, fin) ;
  222. X  FGETS(line, MAXLINE, fin) ;
  223. X  if (iscolor)
  224. X    {
  225. X      for (i = 0; i < 64; i++)
  226. X        for (j = 0; j < 4; j++)
  227. X          {
  228. X            FGETS(line, MAXLINE, fin) ;
  229. X            for (k = 0; k < 16; k++)
  230. X              {
  231. X                if (!(k % 2)) STRNCPY(v[k], &line[(k/2)*7+3], 2) ;
  232. X                else STRNCPY(v[k], &line[(k/2)*7+5], 2) ;
  233. X                v[k][2] = '\0' ;
  234. X              }    
  235. X                 if (j == 0 || j == 1) n = 16 ;
  236. X            else if (j == 2) n = 10 ;
  237. X            if (j != 3)
  238. X              {
  239. X                for (k = 0; k < n; k++)
  240. X                  FPRINTF(PostScript, "%.2s ", v[k]) ;
  241. X                FPRINTF(PostScript, "\n") ;
  242. X              }
  243. X          }
  244. X    }
  245. X  else
  246. X    {
  247. X      for (i = 0; i < 32; i++)
  248. X        {
  249. X          FGETS(line, MAXLINE, fin) ;
  250. X          for (j = 0; j < 8; j++)
  251. X            {
  252. X              STRNCPY(v[j], &line[j*7+3], 4) ;
  253. X              v[j][4] = '\0' ;
  254. X            }
  255. X          FPRINTF(PostScript, "%.4s %.4s %.4s %.4s %.4s %.4s\n",
  256. X                              v[0], v[1], v[2], v[4], v[5], v[6]) ;
  257. X        }
  258. X    }
  259. X  FPRINTF(PostScript, "> } buildimage def\n") ;
  260. X  FFLUSH(PostScript) ;
  261. X  FCLOSE(fin) ;
  262. X}
  263. X
  264. X
  265. Xmake_items()       /* Null routine. */
  266. X{}
  267. X
  268. X
  269. Xmake_subframes()   /* Null routine. */
  270. X{}
  271. X
  272. X
  273. Xsend_ps_file(fname)
  274. Xchar *fname ;
  275. X{
  276. X  FILE *stream ;
  277. X  int c ;
  278. X  if ((stream = fopen(fname,"r")) == NULL) return -1 ;
  279. X  while ((c = getc(stream)) != EOF) PUTC(c, PostScript) ;
  280. X  FCLOSE(stream) ;
  281. X  return 0 ;
  282. X}
  283. X
  284. X
  285. Xset_cursor(type)
  286. Xint type ;
  287. X{
  288. X  FPRINTF(PostScript, "%d PSSetCursor\n", type) ;
  289. X  FFLUSH(PostScript) ;
  290. X}
  291. X
  292. X
  293. Xstart_tool()
  294. X{
  295. X  while (1)
  296. X    process_event(get_next_event()) ;
  297. X}
  298. X
  299. X
  300. Xtoggle_reg_canvas()
  301. X
  302. X{
  303. X  rstate = !rstate ;
  304. X  FPRINTF(PostScript, "%d PSToggleRegCanvas\n", rstate) ;
  305. X  FFLUSH(PostScript) ;
  306. X}
  307. SHAR_EOF
  308. echo "File news.c is complete"
  309. chmod 0444 news.c || echo "restore of news.c fails"
  310. set `wc -c news.c`;Sum=$1
  311. if test "$Sum" != "8102"
  312. then echo original size 8102, current size $Sum;fi
  313. echo "x - extracting sunview.c (Text)"
  314. sed 's/^X//' << 'SHAR_EOF' > sunview.c &&
  315. X
  316. X/*  @(#)sunview.c 1.13 89/12/21
  317. X *
  318. X *  These are the SunView dependent graphics routines used by calctool.
  319. X *
  320. X *  Copyright (c) Rich Burridge.
  321. X *                Sun Microsystems, Australia - All rights reserved.
  322. X *
  323. X *  Permission is given to distribute these sources, as long as the
  324. X *  copyright messages are not removed, and no monies are exchanged.
  325. X *
  326. X *  No responsibility is taken for any errors or inaccuracies inherent
  327. X *  either to the comments or the code of this program, but if
  328. X *  reported to me then an attempt will be made to fix them.
  329. X */
  330. X
  331. X#include "calctool.h"
  332. X#include "color.h"
  333. X#include "extern.h"
  334. X#include <suntool/sunview.h>
  335. X#include <suntool/canvas.h>
  336. X#include <suntool/selection_svc.h>
  337. X#include <suntool/selection_attributes.h>
  338. X
  339. X#define  ICON_SET                       (void) icon_set
  340. X#define  MENU_SET                       (void) menu_set
  341. X#define  NOTIFY_INTERPOSE_DESTROY_FUNC  (void) notify_interpose_destroy_func
  342. X#define  PW_SETCMSNAME                  (void) pw_setcmsname
  343. X#define  PW_PUTCOLORMAP                 (void) pw_putcolormap
  344. X#define  PW_TTEXT                       (void) pw_ttext
  345. X#define  PW_VECTOR                      (void) pw_vector
  346. X#define  PW_WRITEBACKGROUND             (void) pw_writebackground
  347. X#define  SELN_QUERY                     (void) seln_query
  348. X#define  WINDOW_DONE                    (void) window_done
  349. X#define  WINDOW_SET                     (void) window_set
  350. X
  351. X#define  SMALLFONT   "/usr/lib/fonts/fixedwidthfonts/screen.r.7"
  352. X#define  NORMALFONT  "/usr/lib/fonts/fixedwidthfonts/screen.b.14"
  353. X#define  BIGFONT     "/usr/lib/fonts/fixedwidthfonts/gallant.r.19"
  354. X
  355. Xvoid func_key_proc() ;
  356. X
  357. XCanvas kcanvas, rcanvas ;
  358. XCursor help_cursor, main_cursor ;
  359. XEvent *cur_event ;
  360. XFrame frame, rframe ;
  361. XIcon calctool_icon ;
  362. XMenu menus[MAXMENUS] ;
  363. XNotify_value destroy_proc() ;
  364. XPixfont *font, *sfont, *nfont, *bfont ;
  365. XPixwin *pw, *cpw, *rcpw ;
  366. XSeln_client sel_client ;
  367. XSeln_holder holder ;
  368. XSeln_rank rank = SELN_PRIMARY ;
  369. XSeln_result get_proc(), reply_proc() ;
  370. X
  371. Xshort help_cursor_array[16] = {
  372. X#include "help.cursor"
  373. X} ;
  374. Xmpr_static(help_cursor_pr, 16, 16, 1, help_cursor_array) ;
  375. X
  376. Xunsigned short icon_image[] = {
  377. X#include "calctool.icon"
  378. X} ;
  379. Xmpr_static(icon_pr, 64, 64, 1, icon_image) ;
  380. X
  381. Xshort cicon_image[] = {
  382. X#include "calctool.color.icon"
  383. X} ;
  384. Xmpr_static(cicon_pr, 64, 64, 8, cicon_image) ;
  385. X
  386. X
  387. X/*ARGSUSED*/
  388. Xvoid
  389. Xcanvas_proc(canvas, event, arg)
  390. XCanvas canvas ;
  391. XEvent *event ;
  392. Xcaddr_t arg ;
  393. X{
  394. X  cur_event = event ;
  395. X  process_event(get_next_event(event)) ;
  396. X}
  397. X
  398. X
  399. Xclear_canvas(window, color)
  400. Xenum can_type window ;
  401. Xint color ;
  402. X{
  403. X  int height, width ;
  404. X  Canvas ctype ;
  405. X
  406. X  if (window == KEYCANVAS)
  407. X    {
  408. X      pw = cpw ;
  409. X      ctype = frame ;
  410. X    }
  411. X  else if (window == REGCANVAS)
  412. X    {
  413. X      pw = rcpw ;
  414. X      ctype = rframe ;
  415. X    }
  416. X  height = (int) window_get(ctype, WIN_HEIGHT) ;
  417. X  width = (int) window_get(ctype, WIN_WIDTH) ;
  418. X  PW_WRITEBACKGROUND(pw, 0, 0, width, height, PIX_SRC | PIX_COLOR(color)) ;
  419. X}
  420. X
  421. X
  422. Xclose_frame()
  423. X{
  424. X  if ((int) window_get(rframe, WIN_SHOW) == TRUE)
  425. X    WINDOW_SET(rframe, WIN_SHOW, FALSE, 0) ;
  426. X  WINDOW_SET(frame, FRAME_CLOSED, TRUE, 0) ;
  427. X  rstate = 0 ;
  428. X}
  429. X
  430. X
  431. Xcolor_area(x, y, width, height, color)
  432. Xint x, y, width, height, color ;
  433. X{
  434. X  PW_WRITEBACKGROUND(cpw, x, y, width, height, PIX_SRC | PIX_COLOR(color)) ;
  435. X}
  436. X
  437. X
  438. Xcreate_menu(mtype)       /* Create popup menu for right button press. */
  439. Xenum menu_type mtype ;
  440. X{
  441. X  int i ;
  442. X
  443. X  menus[(int) mtype] = menu_create(MENU_FONT, nfont, 0) ;
  444. X  for (i = 0; i < MAXREGS; i++)
  445. X    {
  446. X      switch (mtype)
  447. X        {
  448. X          case M_ACC    :                              /* Accuracies. */
  449. X          case M_EXCH   :                              /* Register exchange. */
  450. X          case M_LSHIFT :                              /* Left shift. */
  451. X          case M_RCL    :                              /* Register recall. */
  452. X          case M_RSHIFT :                              /* Right shift. */
  453. X          case M_STO    : MENU_SET(menus[(int) mtype], /* Register store. */
  454. X                                   MENU_STRING_ITEM, num_names[i], i+1, 0) ;
  455. X                          break ;
  456. X          case M_CON    : if (strlen(con_names[i]))    /* Constants. */
  457. X                            MENU_SET(menus[(int) mtype],
  458. X                                     MENU_STRING_ITEM, con_names[i], i+1, 0) ;
  459. X                          break ;
  460. X          case M_FUN    : if (strlen(fun_names[i]))    /* Functions. */
  461. X                            MENU_SET(menus[(int) mtype],
  462. X                                     MENU_STRING_ITEM, fun_names[i], i+1, 0) ;
  463. X        }
  464. X    }
  465. X}
  466. X
  467. X
  468. Xdestroy_frame()
  469. X{
  470. X  WINDOW_DONE(frame) ;
  471. X  exit(0) ;
  472. X}
  473. X
  474. X
  475. Xdestroy_rframe(frame)
  476. XFrame frame ;
  477. X{
  478. X  rstate = 0 ;
  479. X  WINDOW_SET(frame, WIN_SHOW, FALSE, 0) ;
  480. X}
  481. X
  482. X
  483. X/*ARGSUSED*/
  484. XNotify_value
  485. Xdestroy_proc(client, status)
  486. XNotify_client client ;
  487. XDestroy_status status ;
  488. X{
  489. X  exit(0) ;
  490. X}
  491. X
  492. X
  493. Xdo_menu(mtype)          /* Popup appropriate menu and get value. */
  494. Xenum menu_type mtype ;
  495. X{
  496. X  return ((int) menu_show(menus[(int) mtype], kcanvas,
  497. X                          canvas_window_event(kcanvas, cur_event), 0)) ;
  498. X}
  499. X
  500. X
  501. Xdrawline(x1, y1, x2, y2)
  502. Xint x1, y1, x2, y2 ;
  503. X{
  504. X  PW_VECTOR(cpw, x1, y1, x2, y2, PIX_SET, 0) ;
  505. X}
  506. X
  507. X
  508. Xdraw_regs()
  509. X{
  510. X  make_registers() ;
  511. X  WINDOW_SET(rframe, WIN_SHOW, TRUE, 0) ;
  512. X}
  513. X
  514. X
  515. Xdrawtext(x, y, window, fontno, color, str)
  516. Xenum font_type fontno ;
  517. Xenum can_type window ;
  518. Xint x, y, color ;
  519. Xchar *str ;
  520. X{
  521. X       if (fontno == SFONT) font = sfont ;
  522. X  else if (fontno == NFONT) font = nfont ;
  523. X  else if (fontno == BFONT) font = bfont ;
  524. X       if (window == KEYCANVAS) pw = cpw ;
  525. X  else if (window == REGCANVAS) pw = rcpw ;
  526. X  PW_TTEXT(pw, x, y, PIX_SRC | PIX_COLOR(color), font, str) ;
  527. X}
  528. X
  529. X
  530. X/*ARGSUSED*/
  531. Xvoid
  532. Xfunc_key_proc(client_data, args)
  533. Xchar *client_data ;
  534. XSeln_function_buffer *args ;
  535. X{
  536. X  get_display() ;
  537. X}
  538. X
  539. X
  540. Xget_display()     /* The GET function key has been pressed. */
  541. X{
  542. X  if (seln_acquire(sel_client, SELN_SHELF) == SELN_SHELF)
  543. X    {
  544. X      if (shelf != NULL) free(shelf) ;
  545. X      shelf = malloc((unsigned) strlen(display)) ;
  546. X      STRCPY(shelf, display) ;         /* Safely keep copy of display. */
  547. X    }
  548. X}
  549. X
  550. X
  551. XPixfont *
  552. Xget_font(name)
  553. Xchar *name ;
  554. X{
  555. X  Pixfont *font ;
  556. X
  557. X  font = pf_open(name) ;
  558. X  if (font == NULL) font = pf_default() ;
  559. X  if (font == NULL)
  560. X    {
  561. X      perror("couldn't get the default font.") ;
  562. X      exit(1) ;
  563. X    }
  564. X  return font ;
  565. X}
  566. X
  567. X
  568. Xget_next_event(event)
  569. XEvent *event ;
  570. X{
  571. X  static char eb[4] ;      /* Event buffer. */
  572. X  int i ;
  573. X
  574. X#ifdef   SUN4_KEYBOARD
  575. X  char *rpad = "\000\000\000=/*789456123" ;
  576. X  char *akeys = "8264" ;
  577. X  char *sun4keys = "\000\000\000+-\000\0000\000." ;
  578. X#else
  579. X  char *rpad = "\000\000\00078945612301=" ;
  580. X  char *akeys = "5.31" ;
  581. X#endif /*SUN4_KEYBOARD*/
  582. X
  583. X  nextc = event_id(event) ;
  584. X  curx = event_x(event) ;
  585. X  cury = event_y(event) ;
  586. X
  587. X  if (event_is_button(event))
  588. X         if (event_is_down(event) && nextc == MS_LEFT) return(LEFT_DOWN) ;
  589. X    else if (event_is_down(event) && nextc == MS_MIDDLE) return(MIDDLE_DOWN) ;
  590. X    else if (event_is_down(event) && nextc == MS_RIGHT) return(RIGHT_DOWN) ;
  591. X    else if (event_is_up(event) && nextc == MS_LEFT) return(LEFT_UP) ;
  592. X    else if (event_is_up(event) && nextc == MS_MIDDLE) return(MIDDLE_UP) ;
  593. X    else if (event_is_up(event) && nextc == MS_RIGHT) return(RIGHT_UP) ;
  594. X
  595. X/*  The following code attempts to handle a numeric keypad using the right
  596. X *  function keys. This pad differs on the Sun3 and Sun4 keyboards. There
  597. X *  is a compile-time define which determines which keyboard setup is
  598. X *  looked for.
  599. X */
  600. X
  601. X  if (event_is_ascii(event))
  602. X    {
  603. X
  604. X/*  If the last two events were escape and left square bracket.. */
  605. X
  606. X      if (eb[0] && eb[1])
  607. X        {
  608. X          switch (nextc)
  609. X            {
  610. X
  611. X/*  Interpret the arrow keys (if they are set).
  612. X *  R8 = ^[A     R14 = ^[B     R12 = ^[C     R10 = ^[B
  613. X */
  614. X
  615. X              case 'A' :
  616. X              case 'B' :
  617. X              case 'C' :
  618. X              case 'D' : cur_ch = akeys[nextc - 'A'] ;
  619. X                         eb[0] = eb[1] = '\0' ;
  620. X                         return(KEYBOARD) ;
  621. X
  622. X/*  Interpret the extra keys found on Sun4 keyboards.
  623. X *  These have codes of the form: ^[<int>z where <int> is a number
  624. X *  between 247 and 255.  We're only interested in 4 of these keys.
  625. X *  These are:
  626. X *    ^[253z = +     ^[254z = -     ^[257z = 0     ^[259z = .
  627. X */
  628. X#ifdef SUN4_KEYBOARD
  629. X              case '2' : eb[2] = '2' ;
  630. X                         break ;
  631. X
  632. X              case '5' : if (eb[0] && eb[1] && eb[2])
  633. X                           {
  634. X                             eb[3] = '5' ;
  635. X                             break ;
  636. X                           }
  637. X                         else 
  638. X
  639. X/*  Clear event_buf and treat as normal ascii char. */
  640. X
  641. X                           {
  642. X                             eb[0] = eb[1] = '\0' ;
  643. X                             cur_ch = nextc ;
  644. X                             return(KEYBOARD) ;
  645. X                           }
  646. X
  647. X              case '3' :
  648. X              case '4' :
  649. X              case '7' :
  650. X              case '9' : if (eb[0] && eb[1] && eb[2] && eb[3])
  651. X                           {
  652. X                             cur_ch = sun4keys[nextc - '0'] ;
  653. X                             eb[0] = eb[1] = eb[2] = eb[3] = '\0' ;
  654. X                             return(KEYBOARD) ;
  655. X                           }
  656. X                         else if (eb[0] && eb[1] && eb[2] && nextc == '4')
  657. X                           {
  658. X                             eb[3] = nextc ;
  659. X                             break ;
  660. X                           }
  661. X                         else
  662. X
  663. X/*  Clear event_buf and treat as normal ascii char. */
  664. X
  665. X                           {
  666. X                             eb[0] = eb[1] = '\0' ;
  667. X                             cur_ch = nextc ;
  668. X                             return(KEYBOARD) ;
  669. X                           }
  670. X#endif /*SUN4_KEYBOARD*/
  671. X
  672. X               default : eb[0] = eb[1] = eb[2] = eb[3] = '\0' ;
  673. X            }
  674. X        }
  675. X
  676. X/*  If previous events are ^[[ : set buffer   */
  677. X
  678. X      else if (nextc == '[' && eb[0])    /* Check for left square bracket. */
  679. X        eb[1] = '[' ;
  680. X      else if (nextc == '\033')          /* Check for escape char. */
  681. X        eb[0] = '\033' ;
  682. X      else 
  683. X        {
  684. X
  685. X/*  All the rest of the ASCII characters. */
  686. X
  687. X          eb[0] = eb[1] = '\0' ;
  688. X          cur_ch = nextc ;
  689. X          return(KEYBOARD) ;
  690. X        }
  691. X    }
  692. X
  693. X  if (event_is_key_right(event) && event_is_up(event))
  694. X    {
  695. X      for (i = 1; i < 16; i++)
  696. X        if (nextc == KEY_RIGHT(i))
  697. X          {
  698. X            cur_ch = rpad[i-1] ;
  699. X            return(KEYBOARD) ;
  700. X          }
  701. X    }
  702. X  if (nextc == KBD_DONE && down) return(EXIT_WINDOW) ;
  703. X  if (nextc == LOC_WINEXIT || nextc == LOC_RGNEXIT) return(EXIT_WINDOW) ;
  704. X  if (nextc == LOC_WINENTER || nextc == LOC_RGNENTER) return(ENTER_WINDOW) ;
  705. X  if (nextc == WIN_REPAINT) return(CFRAME_REPAINT) ;
  706. X  if ((nextc == KEY_LEFT(6)) & event_is_up(event)) return(PUT_ON_SHELF) ;
  707. X  if ((nextc == KEY_LEFT(8)) && event_is_up(event)) return(TAKE_FROM_SHELF) ;
  708. X  return(LASTEVENTPLUSONE) ;
  709. X}
  710. X
  711. X
  712. XSeln_result
  713. Xget_proc(buffer)
  714. XSeln_request *buffer ;
  715. X{
  716. X  issel = 0 ;
  717. X  if (*buffer->requester.context == 0)
  718. X    {
  719. X      if (buffer == (Seln_request *) NULL ||
  720. X          *((Seln_attribute *) buffer->data) != SELN_REQ_CONTENTS_ASCII)
  721. X        return ;
  722. X      selection = buffer->data + sizeof(Seln_attribute) ;
  723. X      *buffer->requester.context = 1 ;
  724. X    }
  725. X  else selection = buffer->data ;
  726. X  issel = 1 ;
  727. X}
  728. X
  729. X
  730. Xhandle_selection()  /* Handle the GET function key being pressed. */
  731. X{
  732. X  char context = 0 ;
  733. X
  734. X  holder = seln_inquire(rank) ;
  735. X  if (holder.state == SELN_NONE) return ;
  736. X  SELN_QUERY(&holder, get_proc, &context, SELN_REQ_CONTENTS_ASCII, 0, 0) ;
  737. X}
  738. X
  739. X
  740. Xinit_fonts()
  741. X{
  742. X  bfont = get_font(BIGFONT) ;
  743. X  nfont = get_font(NORMALFONT) ;
  744. X  nfont_width = nfont->pf_defaultsize.x ;
  745. X  sfont = get_font(SMALLFONT) ;
  746. X}
  747. X
  748. X
  749. Xinit_ws_type()
  750. X{
  751. X  if (getenv("WINDOW_PARENT") == NULL)
  752. X    {
  753. X      FPRINTF(stderr,"%s: Not a native SunView window\n", progname) ;
  754. X      return -1 ;
  755. X    }
  756. X  gtype = SVIEW ;
  757. X  return 0 ;
  758. X}
  759. X
  760. X
  761. Xload_colors()      /* Create and load calctool color map. */
  762. X{
  763. X  Pixwin *frame_pw ;
  764. X  char colorname[CMS_NAMESIZE] ;
  765. X  u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
  766. X
  767. X  iscolor = (cpw->pw_pixrect->pr_depth == 8) ? 1 : 0 ;
  768. X  SPRINTF(colorname, "%s%D", CALC_COLOR, getpid()) ;
  769. X  PW_SETCMSNAME(cpw, colorname) ;
  770. X
  771. X  calc_colorsetup(red, green, blue) ;
  772. X  PW_PUTCOLORMAP(cpw, 0, CALC_COLORSIZE, red, green, blue) ;
  773. X  if (inv_video) pw_reversevideo(cpw, 0, CALC_COLORSIZE) ;
  774. X
  775. X  if (iscolor)
  776. X    {
  777. X      frame_pw = (Pixwin *) window_get(frame, WIN_PIXWIN, 0) ;
  778. X      PW_SETCMSNAME(frame_pw, colorname) ;
  779. X      PW_PUTCOLORMAP(frame_pw, 0, CALC_COLORSIZE, red, green, blue) ;
  780. X    }
  781. X}
  782. X
  783. X
  784. Xmake_frames(argc, argv)
  785. Xint argc ;
  786. Xchar *argv[] ;
  787. X{
  788. X  frame = window_create((Window) 0, FRAME,
  789. X                        FRAME_ICON,       calctool_icon,
  790. X                        FRAME_SHOW_LABEL, FALSE,
  791. X                        FRAME_NO_CONFIRM, TRUE,
  792. X                        FRAME_ARGS,       argc, argv,
  793. X                        0) ;
  794. X  sel_client = seln_create(func_key_proc, reply_proc, (char *) 0) ;
  795. X  NOTIFY_INTERPOSE_DESTROY_FUNC(frame, destroy_proc) ;
  796. X  rframe = window_create(frame, FRAME,
  797. X                         FRAME_SHOW_LABEL, FALSE,
  798. X                         FRAME_NO_CONFIRM, TRUE,
  799. X                         FRAME_DONE_PROC,  destroy_rframe,
  800. X                         WIN_X,            TWIDTH+15,
  801. X                         WIN_Y,            0,
  802. X                         WIN_SHOW,         FALSE,
  803. X                         WIN_WIDTH,        TWIDTH,
  804. X                         WIN_HEIGHT,       200,
  805. X                         WIN_FONT,         nfont,
  806. X                         0) ;
  807. X}
  808. X
  809. X
  810. Xmake_icon()
  811. X{
  812. X  calctool_icon = icon_create(ICON_WIDTH, ICONWIDTH,
  813. X                              ICON_IMAGE, &icon_pr,
  814. X                              0) ;
  815. X}
  816. X
  817. X
  818. Xmake_items()
  819. X{
  820. X  main_cursor = window_get(kcanvas, WIN_CURSOR) ;
  821. X
  822. X  if (iscolor)
  823. X    {
  824. X      calctool_icon = (Icon) window_get(frame, FRAME_ICON) ;
  825. X      ICON_SET(calctool_icon, ICON_IMAGE, &cicon_pr, 0) ;
  826. X      WINDOW_SET(frame, FRAME_ICON, calctool_icon, 0) ;
  827. X    }
  828. X
  829. X  help_cursor = cursor_create(CURSOR_XHOT,  0,
  830. X                              CURSOR_YHOT,  0,
  831. X                              CURSOR_OP,    PIX_SRC | PIX_DST,
  832. X                              CURSOR_IMAGE, &help_cursor_pr, 0) ;
  833. X  window_fit(frame) ;
  834. X}
  835. X
  836. X
  837. Xmake_subframes()
  838. X{
  839. X  rcanvas = window_create(rframe, CANVAS, 0) ;
  840. X  kcanvas = window_create(frame, CANVAS,
  841. X                          CANVAS_RETAINED,     FALSE,
  842. X                          WIN_EVENT_PROC,      canvas_proc,
  843. X                          WIN_WIDTH,           TWIDTH,
  844. X                          WIN_HEIGHT,          THEIGHT + DISPLAY,
  845. X                          WIN_FONT,            nfont,
  846. X                          0) ;
  847. X
  848. X  WINDOW_SET(kcanvas, WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS,
  849. X                      WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
  850. X                      WIN_UP_EVENTS, 0, 0) ;
  851. X  WINDOW_SET(kcanvas, WIN_IGNORE_PICK_EVENT, LOC_MOVE, 0) ;
  852. X  cpw = canvas_pixwin(kcanvas) ;
  853. X  rcpw = canvas_pixwin(rcanvas) ;
  854. X}
  855. X
  856. X
  857. X/*ARGSUSED*/
  858. XSeln_result
  859. Xreply_proc(item, context, length)
  860. XSeln_attribute item ;
  861. XSeln_replier_data *context ;
  862. Xint length ;
  863. X{
  864. X  int size ;
  865. X  char *destp ;
  866. X
  867. X  switch (item)
  868. X    {
  869. X      case SELN_REQ_CONTENTS_ASCII :
  870. X
  871. X             if (context->context == NULL)
  872. X               {
  873. X                 if (shelf == NULL) return(SELN_DIDNT_HAVE) ;
  874. X                 context->context = shelf ;
  875. X               }
  876. X             size = strlen(context->context) ;
  877. X             destp = (char *) context->response_pointer ;
  878. X             STRCPY(destp, context->context) ;
  879. X             destp += size ;
  880. X             while ((int) destp % 4 != 0) *destp++ = '\0' ;
  881. X             context->response_pointer = (char **) destp ;
  882. X             *context->response_pointer++ = 0 ;
  883. X             return(SELN_SUCCESS) ;
  884. X
  885. X      case SELN_REQ_YIELD :
  886. X
  887. X             *context->response_pointer++ = (char *) SELN_SUCCESS ;
  888. X             return(SELN_SUCCESS) ;
  889. X
  890. X      case SELN_REQ_BYTESIZE :
  891. X
  892. X             if (shelf == NULL) return(SELN_DIDNT_HAVE) ;
  893. X             *context->response_pointer++ = (char *) strlen(shelf) ;
  894. X             return(SELN_SUCCESS) ;
  895. X
  896. X      case SELN_REQ_END_REQUEST : return(SELN_SUCCESS) ;
  897. X
  898. X      default                   : return(SELN_UNRECOGNIZED) ;
  899. X    }
  900. X}
  901. X
  902. X
  903. Xset_cursor(type)
  904. Xint type ;
  905. X{
  906. X  switch (type)
  907. X    {
  908. X      case HELPCURSOR : WINDOW_SET(kcanvas, WIN_CURSOR, help_cursor, 0) ;
  909. X                        break ;
  910. X      case MAINCURSOR : WINDOW_SET(kcanvas, WIN_CURSOR, main_cursor, 0) ;
  911. X    }
  912. X}
  913. X
  914. X
  915. Xstart_tool()
  916. X{
  917. X  window_main_loop(frame) ;
  918. X}
  919. X
  920. X
  921. Xtoggle_reg_canvas()
  922. X{
  923. X  rstate = !rstate ;
  924. X  if (rstate) draw_regs() ;
  925. X  else WINDOW_SET(rframe, WIN_SHOW, FALSE, 0) ;
  926. X}
  927. SHAR_EOF
  928. chmod 0444 sunview.c || echo "restore of sunview.c fails"
  929. set `wc -c sunview.c`;Sum=$1
  930. if test "$Sum" != "16635"
  931. then echo original size 16635, current size $Sum;fi
  932. echo "x - extracting tty.c (Text)"
  933. sed 's/^X//' << 'SHAR_EOF' > tty.c &&
  934. X
  935. X/*  @(#)tty.c 1.12 89/12/21
  936. X *
  937. X *  These are the dumb tty dependent graphics routines used by calctool.
  938. X *
  939. X *  Copyright (c) Rich Burridge.
  940. X *                Sun Microsystems, Australia - All rights reserved.
  941. X *
  942. X *  Permission is given to distribute these sources, as long as the
  943. X *  copyright messages are not removed, and no monies are exchanged.
  944. X *
  945. X *  No responsibility is taken for any errors or inaccuracies inherent
  946. X *  either to the comments or the code of this program, but if
  947. X *  reported to me then an attempt will be made to fix them.
  948. X */
  949. X
  950. X#include "calctool.h"
  951. X#include "color.h"
  952. X#include "extern.h"
  953. X
  954. Xchar *CE, *CL, *CM, *SE, *SO ;
  955. X
  956. Xchar *getenv(), *tgetstr(), *tgoto() ;
  957. Xint destroy_frame(), outc() ;
  958. X
  959. X#ifdef NO_4_3SELECT
  960. Xint fullmask ;               /* Full mask of file descriptors to check on. */
  961. Xint readmask ;               /* Readmask used in select call. */
  962. X#else
  963. Xfd_set fullmask ;            /* Full mask of file descriptors to check on. */
  964. Xfd_set readmask ;            /* Read mask used in select call. */
  965. X#endif /*NO_4_3SELECT*/
  966. X
  967. Xstruct sgttyb in_new, in_old ;
  968. X
  969. X
  970. XSIGRET
  971. Xcleanup()
  972. X{
  973. X  destroy_frame() ;
  974. X}
  975. X
  976. X
  977. X/*ARGSUSED*/
  978. Xclear_canvas(canvas, color)
  979. Xenum can_type canvas ;
  980. Xint color ;
  981. X{
  982. X  int i,j ;
  983. X
  984. X  if (canvas == REGCANVAS)
  985. X    for (i = 0; i < 24; i++)
  986. X      {
  987. X        tputs(tgoto(CM, i, 43), 1, outc) ;
  988. X        do_move(43, i) ;
  989. X        do_clr_eol() ;
  990. X      }
  991. X  else for (i = 0; i < 24; i++)
  992. X    {
  993. X      do_move(0, i) ;
  994. X      for (j = 0; j < 42; j++) outc(' ') ;
  995. X    }
  996. X  do_move(41, 1) ;
  997. X}
  998. X
  999. X
  1000. Xclose_frame() {}     /* This option does nothing with termcap. */
  1001. X
  1002. X
  1003. X/*ARGSUSED*/
  1004. Xcolor_area(x, y, width, height, color)    /* Color an area - null routine. */
  1005. Xint x, y, width, height, color ;
  1006. X{}
  1007. X
  1008. X
  1009. X/*ARGSUSED*/
  1010. Xcreate_menu(mtype)     /* Create popup menu - null routine. */
  1011. Xenum menu_type mtype ;
  1012. X{}
  1013. X
  1014. X
  1015. Xdestroy_frame()
  1016. X{
  1017. X  int i ;
  1018. X
  1019. X  tputs(CL, 1, outc) ; 
  1020. X  for (i = 0; i < 24; i++)
  1021. X    {
  1022. X      do_move(0, i) ;
  1023. X      do_clr_eol() ;
  1024. X    }
  1025. X  do_move(0, 0) ;
  1026. X  SIGNAL(SIGINT, SIG_IGN) ;
  1027. X  IOCTL(0, TIOCSETP, &in_old) ;
  1028. X  exit(0) ;
  1029. X}
  1030. X
  1031. X
  1032. Xdo_clr_eol()                  /* Clear to the end of the line. */
  1033. X{
  1034. X  tputs(CE, 1, outc) ;
  1035. X}
  1036. X
  1037. X
  1038. X/*ARGSUSED*/
  1039. Xdo_menu(mtype)                /* Popup appropriate menu (null routine). */
  1040. Xenum menu_type mtype ;
  1041. X{}
  1042. X
  1043. X
  1044. Xdo_move(x, y)                 /* Move to character position (x, y). */
  1045. Xint x, y ;
  1046. X{
  1047. X  tputs(tgoto(CM, x, y), 1, outc) ;
  1048. X}
  1049. X
  1050. X
  1051. Xdo_standend()                 /* Finish inverted area. */
  1052. X{
  1053. X  tputs(SE, 1, outc) ;
  1054. X}
  1055. X
  1056. X
  1057. Xdo_standout()                 /* Start inverted area. */
  1058. X{
  1059. X  tputs(SO, 1, outc) ;
  1060. X}
  1061. X
  1062. X
  1063. Xdrawline(x1, y1, x2, y2)
  1064. Xint x1, y1, x2, y2 ;
  1065. X{
  1066. X  double dx ;
  1067. X  int i, offset, x, y ;
  1068. X
  1069. X  if (x1)
  1070. X    {
  1071. X      dx = (float) (x1 - BBORDER) / (BWIDTH + BGAP) ;
  1072. X      if (dx == (int) dx) offset = 1 ;
  1073. X      else offset = 6 ;
  1074. X
  1075. X      x = ((x1 - BBORDER) / (BWIDTH + BGAP) * 7) + offset ;
  1076. X      y = ((y1 - BBORDER) / (BHEIGHT + BGAP) * 3) + 5 ;
  1077. X      do_move(x, y) ;
  1078. X      if (x1 == x2)
  1079. X        {
  1080. X          if ((y2 - y1) != BHEIGHT) return ;
  1081. X          outc('+') ;
  1082. X          for (i = 0; i < 2; i++)
  1083. X            {
  1084. X              do_move(x, y+i+1) ;
  1085. X              outc('|') ;
  1086. X            }
  1087. X          do_move(x, y+3) ;
  1088. X          outc('+') ;
  1089. X        }
  1090. X      else
  1091. X        {
  1092. X          if ((x2 - x1) != BWIDTH) return ;
  1093. X          outc('+') ;
  1094. X          for (i = 0; i < 4; i++)
  1095. X            {
  1096. X              do_move(x+i+1, y) ;
  1097. X              outc('-') ;
  1098. X            }
  1099. X          do_move(x+5, y) ;
  1100. X          outc('+') ;
  1101. X        }
  1102. X    }
  1103. X  else
  1104. X    {
  1105. X      do_move(0, 4) ;
  1106. X      for (i = 0; i < 42; i++) outc('-') ;
  1107. X    }
  1108. X}
  1109. X
  1110. X
  1111. Xdraw_regs()
  1112. X{
  1113. X}
  1114. X
  1115. X
  1116. X/*ARGSUSED*/
  1117. Xdrawtext(tx, ty, window, fontno, color, str)
  1118. Xenum can_type window ;
  1119. Xenum font_type fontno ;
  1120. Xint tx, ty, color ;
  1121. Xchar *str ;
  1122. X{
  1123. X  char key[5] ;
  1124. X  int i, invert, sps ;
  1125. X
  1126. X  invert = 0 ;
  1127. X  if (window == REGCANVAS)                   /* Register window. */
  1128. X    {
  1129. X      tx = 45 ;
  1130. X      ty = ((ty / 15 - 1) * 2) + 1 ;
  1131. X    }
  1132. X  else if (window == KEYCANVAS && tx == 5)   /* Help screen. */
  1133. X    {
  1134. X      tx = 1 ;
  1135. X      ty = ty / 15 ;
  1136. X    }
  1137. X  else if (window == KEYCANVAS && ty < DISPLAY)
  1138. X    {
  1139. X      if (color == WHITE)
  1140. X        for (i = 0; i < strlen(str); i++) str[i] = ' ' ;
  1141. X
  1142. X      if (ty == (DISPLAY-3))              /* Base, trig and op items. */
  1143. X        {
  1144. X          tx = tx * 42 / (TWIDTH) + 1 ;
  1145. X          ty = 3 ;
  1146. X        }
  1147. X      else                                /* Display item. */
  1148. X        {
  1149. X          tx = 41 - strlen(str) ;
  1150. X          ty = 1 ;
  1151. X        }
  1152. X    }
  1153. X  else                                    /* Button values. */
  1154. X    {
  1155. X      tx = ((tx - BBORDER) / (BWIDTH + BGAP) * 7) + 2 ;
  1156. X      for (sps = 0, i = 0; i < 4; i++)
  1157. X        if (str[i] == ' ') sps++ ;
  1158. X      ty = (ty - 34) / 30 ;
  1159. X      ty = (ty - (ty % 2)) * 3 / 2 + 6 + (ty % 2) ;
  1160. X      switch (sps)
  1161. X        {
  1162. X          case 0 :
  1163. X          case 1 :
  1164. X          case 4 : STRCPY(key, str) ;
  1165. X                   break ;
  1166. X          case 2 :
  1167. X          case 3 : key[0] = ' ' ;
  1168. X                   STRNCPY(&key[1], str, 3) ;
  1169. X        }
  1170. X      key[5] = '\0' ;
  1171. X      STRCPY(str, key) ;
  1172. X      if (ty % 3) invert = 1 ;
  1173. X    }
  1174. X  do_move(tx, ty) ;
  1175. X  if (window == REGCANVAS) do_clr_eol() ;
  1176. X  if (invert) do_standout() ;
  1177. X  outstr(str) ;
  1178. X  if (invert) do_standend() ;
  1179. X  do_move(41, 1) ;
  1180. X}
  1181. X
  1182. X
  1183. Xget_display()            /* No GET key; null routine. */
  1184. X{}
  1185. X
  1186. X
  1187. Xget_next_event()         /* Only events possible are keyboard ones. */
  1188. X{
  1189. X  char c ;
  1190. X  int reply ;
  1191. X
  1192. X  for (;;)
  1193. X    {
  1194. X      readmask = fullmask ;
  1195. X#ifdef NO_4_3SELECT
  1196. X      reply = select(32, &readmask, 0, 0, (struct timeval *) 0) ;
  1197. X      if (reply == -1) /* do nothing. */
  1198. X      else if (readmask && (1 << 0))
  1199. X#else
  1200. X      reply = select(FD_SETSIZE, &readmask, (fd_set *) 0, (fd_set *) 0,
  1201. X                                            (struct timeval *) 0) ;
  1202. X      if (reply == -1) /* do nothing. */ ;
  1203. X      else if (FD_ISSET(0, &readmask))
  1204. X#endif /*NO_4_3SELECT*/
  1205. X        {
  1206. X          READ(0, &c, 1) ;
  1207. X          cur_ch = c ;
  1208. X          return(KEYBOARD) ;
  1209. X        }
  1210. X    }
  1211. X}
  1212. X
  1213. X
  1214. Xhandle_selection()       /* There is no PUT function key with termcap. */
  1215. X{}
  1216. X
  1217. X
  1218. Xinit_fonts()             /* No fonts with the termcap version. */
  1219. X{
  1220. X  nfont_width = 8 ;
  1221. X}
  1222. X
  1223. X
  1224. Xinit_ws_type()           /* Check if terminal capable of termcap output. */
  1225. X{
  1226. X  char bp[1024], termtype[MAXLINE] ;
  1227. X  int i ;
  1228. X  static char buf[100] ;
  1229. X  char *area = buf ;
  1230. X
  1231. X  if (getenv("TERM") != NULL) STRCPY(termtype, getenv("TERM")) ;
  1232. X  if (tgetent(bp, termtype) != 1) return 1 ;
  1233. X  if ((CL = tgetstr("cl", &area)) == (char *) 0) return 1 ;
  1234. X  if ((CM = tgetstr("cm", &area)) == (char *) 0) return 1 ;
  1235. X  if ((CE = tgetstr("ce", &area)) == (char *) 0) return 1 ;
  1236. X  if ((SO = tgetstr("so", &area)) == (char *) 0) return 1 ;
  1237. X  if ((SE = tgetstr("se", &area)) == (char *) 0) return 1 ;
  1238. X  for (i = 0; i < 24; i++)
  1239. X    {
  1240. X      do_move(0, i) ;
  1241. X      do_clr_eol() ;
  1242. X    }
  1243. X  gtype = TTY ;
  1244. X  return 0 ;
  1245. X}
  1246. X
  1247. X
  1248. Xload_colors()
  1249. X{
  1250. X  iscolor = 0 ;          /* No colors in the termcap implementation. */
  1251. X}
  1252. X
  1253. X
  1254. X/*ARGSUSED*/
  1255. Xmake_frames(argc, argv)
  1256. Xint argc ;
  1257. Xchar *argv[] ;
  1258. X{
  1259. X  int i ;
  1260. X
  1261. X  SIGNAL(SIGINT, cleanup) ;
  1262. X
  1263. X#ifdef NO_4_3SELECT
  1264. X  fullmask = 1 ;                       /* Set mask for fd #0. */
  1265. X#else
  1266. X  FD_ZERO(&fullmask) ;
  1267. X  FD_SET(0, &fullmask) ;
  1268. X#endif /*NO_4_3SELECT*/
  1269. X
  1270. X  IOCTL(0, TIOCGETP, &in_old) ;        /* Setup standard input. */
  1271. X  in_new = in_old ;
  1272. X  in_new.sg_flags |= RAW ;
  1273. X  in_new.sg_flags &= ~(ECHO | CRMOD) ;
  1274. X  IOCTL(0, TIOCSETP, &in_new) ;
  1275. X
  1276. X  setbuf(stdout, (char *) NULL) ;
  1277. X
  1278. X  tputs(CL, 1, outc) ;
  1279. X  do_move(0, 4) ;
  1280. X  for (i = 0; i < 41; i++) outc('-') ;
  1281. X  for (i = 0; i < 24; i++)
  1282. X    {
  1283. X      do_move(42, i) ;
  1284. X      if (i == 4) outc('+') ;
  1285. X      else outc('|') ;
  1286. X    }
  1287. X}
  1288. X
  1289. X
  1290. Xmake_icon() {}          /* There is no icon with termcap. */
  1291. X
  1292. X
  1293. Xmake_items()
  1294. X{
  1295. X  do_repaint() ;        /* Redraw the calctool canvas[es]. */
  1296. X}
  1297. X
  1298. X
  1299. Xmake_subframes() {}     /* There are no subframes with termcap. */
  1300. X
  1301. X
  1302. Xoutc(c)                 /* Output the next character to the screen. */
  1303. Xint c ;
  1304. X{
  1305. X  PUTC(c, stdout) ;
  1306. X}
  1307. X
  1308. X
  1309. Xoutstr(str)
  1310. Xchar *str ;
  1311. X{
  1312. X  int i ;
  1313. X
  1314. X  for (i = 0; i < strlen(str); i++) PUTC(str[i], stdout) ;
  1315. X}
  1316. X
  1317. X
  1318. X/*ARGSUSED*/
  1319. Xset_cursor(type)        /* There are no cursors with termcap. */
  1320. Xint type ;
  1321. X{}
  1322. X
  1323. X
  1324. Xstart_tool()
  1325. X{
  1326. X  while (1)
  1327. X    process_event(get_next_event()) ;
  1328. X}
  1329. X
  1330. X
  1331. Xtoggle_reg_canvas()      /* Show or clear memory register area. */
  1332. X{
  1333. X  rstate = !rstate ;
  1334. X  clear_canvas(REGCANVAS, WHITE) ;
  1335. X  if (rstate) make_registers() ;
  1336. X}
  1337. SHAR_EOF
  1338. chmod 0444 tty.c || echo "restore of tty.c fails"
  1339. set `wc -c tty.c`;Sum=$1
  1340. if test "$Sum" != "8330"
  1341. then echo original size 8330, current size $Sum;fi
  1342. echo "x - extracting x11.c (Text)"
  1343. sed 's/^X//' << 'SHAR_EOF' > x11.c &&
  1344. X
  1345. X/*  @(#)x11.c 1.14 89/12/21
  1346. X *
  1347. X *  These are the X11 dependent graphics routines used by calctool.
  1348. X *
  1349. X *  Copyright (c) Rich Burridge.
  1350. X *                Sun Microsystems, Australia - All rights reserved.
  1351. X *
  1352. X *  Permission is given to distribute these sources, as long as the
  1353. X *  copyright messages are not removed, and no monies are exchanged.
  1354. X *
  1355. X *  No responsibility is taken for any errors or inaccuracies inherent
  1356. X *  either to the comments or the code of this program, but if
  1357. X *  reported to me then an attempt will be made to fix them.
  1358. X */
  1359. X
  1360. X#include "calctool.h"
  1361. X#include "color.h"
  1362. X#include "extern.h"
  1363. X#include <X11/Xlib.h>
  1364. X#include <X11/Xutil.h>
  1365. X#include <X11/Xatom.h>
  1366. X#include <X11/cursorfont.h>
  1367. X
  1368. X#define  XGETSIZEHINTS  (void) XGetSizeHints
  1369. X
  1370. X#define  BIGFONT               "helvetica-bold-14"
  1371. X#define  DEFFONT               "fixed"
  1372. X#define  NORMALFONT            "fixed"
  1373. X#define  SMALLFONT             "6x10"
  1374. X
  1375. X#define  CALCTOOL_BORDER_WIDTH  2
  1376. X
  1377. X#define  FRAME_MASK  (ButtonPressMask | ButtonReleaseMask | KeyPressMask | \
  1378. X                      EnterWindowMask | LeaveWindowMask | ExposureMask)
  1379. X
  1380. Xshort help_cursor_array[16] = {
  1381. X#include "help.cursor"
  1382. X} ;
  1383. X
  1384. Xshort icon_image[] = {
  1385. X#include "calctool.icon"
  1386. X} ;
  1387. X
  1388. Xshort cicon_image[] = {
  1389. X#include "calctool.color.icon"
  1390. X} ;
  1391. X
  1392. XAtom protocol_atom, kill_atom ;
  1393. XCursor help_cursor, main_cursor ;
  1394. XDisplay *dpy ;
  1395. XGC gc ;
  1396. XPixmap calctool_icon, help_pixmap ;
  1397. XPixmap load_icon() ;
  1398. XWindow frame, rframe ;
  1399. XXColor BGcolor, FGcolor, current_col ;
  1400. XXEvent event ;
  1401. XXFontStruct *bfont, *font, *nfont, *sfont ;
  1402. XXGCValues gc_val ;
  1403. XXSizeHints size ;
  1404. XXWMHints wm_hints ;
  1405. X
  1406. Xunsigned long gc_mask ;
  1407. Xint screen ;
  1408. Xunsigned int scr_depth ;
  1409. Xunsigned long backgnd, foregnd ;
  1410. Xunsigned long palette[CALC_COLORSIZE] ;
  1411. X
  1412. X
  1413. Xclear_canvas(ctype, color)
  1414. Xenum can_type ctype ;
  1415. Xint color ;
  1416. X{
  1417. X  XSizeHints hints ;
  1418. X  Window window ;
  1419. X
  1420. X       if (ctype == KEYCANVAS) window = frame ;
  1421. X  else if (ctype == REGCANVAS) window = rframe ;
  1422. X  XGETSIZEHINTS(dpy, window, &hints, XA_WM_NORMAL_HINTS) ;
  1423. X  if (iscolor) gc_val.foreground = palette[color] ;
  1424. X  else
  1425. X    {
  1426. X      if (color == WHITE) gc_val.foreground = backgnd ;
  1427. X      else gc_val.foreground = foregnd ;
  1428. X    }
  1429. X  gc_val.function = GXcopy ;
  1430. X  XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
  1431. X  XFillRectangle(dpy, window, gc, 0, 0, hints.width, hints.height) ;
  1432. X}
  1433. X
  1434. X
  1435. Xclose_frame()
  1436. X{
  1437. X  iconic = 1 ;
  1438. X  rstate = 0 ;
  1439. X  XIconifyWindow(dpy, frame, screen) ;
  1440. X}
  1441. X
  1442. X
  1443. Xcolor_area(x, y, width, height, color)
  1444. Xint x, y, width, height, color ;
  1445. X{
  1446. X  if (iscolor) gc_val.foreground = palette[color] ;
  1447. X  else
  1448. X    {
  1449. X      if (color == WHITE) gc_val.foreground = backgnd ;
  1450. X      else gc_val.foreground = foregnd ;
  1451. X    }
  1452. X  gc_val.function = GXcopy ;
  1453. X  XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
  1454. X  XFillRectangle(dpy, frame, gc, x, y,
  1455. X                 (unsigned int) width, (unsigned int) height) ;
  1456. X}
  1457. X
  1458. X
  1459. Xcreate_menu(mtype)    /* Create popup menu for right button press. */
  1460. Xenum menu_type mtype ;
  1461. X{
  1462. X}
  1463. X
  1464. X
  1465. Xdestroy_frame()
  1466. X{
  1467. X  XDestroyWindow(dpy, frame) ;
  1468. X  XDestroyWindow(dpy, rframe) ;
  1469. X  exit(0) ;
  1470. X}
  1471. X
  1472. X
  1473. Xdo_menu(mtype)      /* Popup appropriate menu and get value. */
  1474. Xenum menu_type mtype ;
  1475. X{
  1476. X}
  1477. X
  1478. X
  1479. Xdrawline(x1, y1, x2, y2)
  1480. Xint x1, y1, x2, y2 ;
  1481. X{
  1482. X  if (iscolor) gc_val.foreground = palette[BLACK] ;
  1483. X  else gc_val.foreground = foregnd ;
  1484. X  gc_val.function = GXcopy ;
  1485. X  XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
  1486. X  XDrawLine(dpy, frame, gc, x1, y1, x2, y2) ;
  1487. X}
  1488. X
  1489. X
  1490. Xdraw_regs()
  1491. X{
  1492. X  XMapWindow(dpy, rframe) ;
  1493. X}
  1494. X
  1495. X
  1496. Xdrawtext(x, y, ctype, fontno, color, str)
  1497. Xenum font_type fontno ;
  1498. Xenum can_type ctype ;
  1499. Xint x, y, color ;
  1500. Xchar *str ;
  1501. X{
  1502. X  Window window ;
  1503. X
  1504. X       if (fontno == SFONT) font = sfont ;
  1505. X  else if (fontno == NFONT) font = nfont ;
  1506. X  else if (fontno == BFONT) font = bfont ;
  1507. X       if (ctype == KEYCANVAS) window = frame ;
  1508. X  else if (ctype == REGCANVAS) window = rframe ;
  1509. X
  1510. X  if (ctype == KEYCANVAS && y == items[DISPLAYITEM].y) x += 100 ;
  1511. X  if (iscolor) gc_val.foreground = palette[color] ;
  1512. X  else
  1513. X    {
  1514. X      if (color == WHITE) gc_val.foreground = backgnd ;
  1515. X      else gc_val.foreground = foregnd ;
  1516. X    }
  1517. X  gc_val.font = font->fid ;
  1518. X  gc_val.function = GXcopy ;
  1519. X  XChangeGC(dpy, gc, GCFont | GCForeground | GCFunction, &gc_val) ;
  1520. X  XDrawString(dpy, window, gc, x, y, str, strlen(str)) ;
  1521. X}
  1522. X
  1523. X
  1524. Xget_display()         /* GET function key was pressed. */
  1525. X{
  1526. X}
  1527. X
  1528. X
  1529. XXFontStruct *
  1530. Xget_font(name)
  1531. Xchar *name ;
  1532. X{
  1533. X  XFontStruct *font ;
  1534. X
  1535. X  if (!(font = XLoadQueryFont(dpy, name)))
  1536. X    if (!(font = XLoadQueryFont(dpy, DEFFONT)))
  1537. X      {
  1538. X        perror("couldn't get the default font.") ;
  1539. X        exit(1) ;
  1540. X      }
  1541. X  return(font) ;
  1542. X}
  1543. X
  1544. X
  1545. Xget_next_event()
  1546. X{
  1547. X  XClientMessageEvent *ev ;
  1548. X  XKeyPressedEvent *key_event ;
  1549. X  char chs[2] ;
  1550. X
  1551. X  if (!XCheckMaskEvent(dpy, ExposureMask, &event))
  1552. X    XNextEvent(dpy, &event) ;
  1553. X
  1554. X  switch (event.type)
  1555. X    {
  1556. X      case ClientMessage    : /* Catch ICCCM kill from WM. */
  1557. X
  1558. X                              ev = (XClientMessageEvent *) &event ;
  1559. X                              if (ev->message_type == protocol_atom &&
  1560. X                                  ev->data.l[0] == kill_atom)
  1561. X                                exit(0) ;
  1562. X                              return(LASTEVENTPLUSONE) ;
  1563. X
  1564. X      case Expose           : return(process_expose(&event)) ;
  1565. X
  1566. X      case EnterNotify      : return(ENTER_WINDOW) ;
  1567. X
  1568. X      case LeaveNotify      : return(EXIT_WINDOW) ;
  1569. X
  1570. X      case KeyPress         : key_event = (XKeyPressedEvent *) &event ;
  1571. X                              curx = key_event->x ;
  1572. X                              cury = key_event->y ;
  1573. X                              (void) XLookupString(key_event, chs, 1,
  1574. X                                                   (KeySym *)  NULL,
  1575. X                                                   (XComposeStatus *) NULL) ;
  1576. X                              cur_ch = chs[0] ;
  1577. X                              return(KEYBOARD) ;
  1578. X
  1579. X      case ButtonPress      : curx = event.xbutton.x ;
  1580. X                              cury = event.xbutton.y ;
  1581. X                              if (event.xbutton.button == Button1)
  1582. X                                return(LEFT_DOWN) ;
  1583. X                              else if (event.xbutton.button == Button2)
  1584. X                                return(MIDDLE_DOWN) ;
  1585. X                              else if (event.xbutton.button == Button3)
  1586. X                                return(RIGHT_DOWN) ;
  1587. X
  1588. X      case ButtonRelease    : curx = event.xbutton.x ;
  1589. X                              cury = event.xbutton.y ;
  1590. X                              if (event.xbutton.button == Button1)
  1591. X                                return(LEFT_UP) ;
  1592. X                              else if (event.xbutton.button == Button2)
  1593. X                                return(MIDDLE_UP) ;
  1594. X                              else if (event.xbutton.button == Button3)
  1595. X                                return(RIGHT_UP) ;
  1596. X
  1597. X      default               : return(LASTEVENTPLUSONE) ;
  1598. X   }
  1599. X/*NOTREACHED*/
  1600. X}
  1601. X
  1602. X
  1603. Xhandle_selection()
  1604. X{
  1605. X}
  1606. X
  1607. X
  1608. Xinit_fonts()
  1609. X{
  1610. X  bfont = get_font(BIGFONT) ;
  1611. X  nfont = get_font(NORMALFONT) ;
  1612. X  nfont_width = 6 ;
  1613. X  sfont = get_font(SMALLFONT) ;
  1614. X}
  1615. X
  1616. X
  1617. Xinit_ws_type()
  1618. X{
  1619. X  if ((dpy = XOpenDisplay(x11_display)) == NULL)
  1620. X    {
  1621. X      FPRINTF(stderr,"%s: Couldn't open display %s\n", progname,
  1622. X              (getenv ("DISPLAY") ? getenv("DISPLAY") : x11_display)) ;
  1623. X      exit(1) ;
  1624. X    }
  1625. X
  1626. X  screen = DefaultScreen(dpy) ;
  1627. X
  1628. X  if (!geometry)
  1629. X    STRCPY(geometry, XGetDefault(dpy, progname, "Geometry")) ;
  1630. X
  1631. X  foregnd = BlackPixel(dpy, screen) ;
  1632. X  backgnd = WhitePixel(dpy, screen) ;
  1633. X  scr_depth = DefaultDepth(dpy, screen) ;
  1634. X  gtype = X11 ;
  1635. X  return 0 ;
  1636. X}
  1637. X
  1638. X
  1639. Xload_colors()      /* Create and load calctool color map. */
  1640. X{
  1641. X  u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
  1642. X  int i, numcolors ;
  1643. X
  1644. X  iscolor = 0 ;
  1645. X  if (DisplayCells(dpy, screen) > 2)
  1646. X    {
  1647. X      calc_colorsetup(red, green, blue) ;
  1648. X      iscolor = 1 ;
  1649. X      numcolors = 0 ;
  1650. X      for (i = 0; i < CALC_COLORSIZE; i++)
  1651. X        {
  1652. X          current_col.flags = DoRed | DoGreen | DoBlue ;
  1653. X          current_col.red = (unsigned short) (red[i] << 8) ;
  1654. X          current_col.green = (unsigned short) (green[i] << 8) ;
  1655. X          current_col.blue = (unsigned short) (blue[i] << 8) ;
  1656. X          if (XAllocColor(dpy, DefaultColormap(dpy, screen), ¤t_col) == True)
  1657. X            palette[numcolors++] = current_col.pixel ;
  1658. X        }
  1659. X      if (numcolors < 2)
  1660. X        {
  1661. X          FPRINTF(stderr, "%s: cannot allocate colors.\n", progname) ;
  1662. X          exit(1) ;
  1663. X        }
  1664. X    }
  1665. X}
  1666. X
  1667. X
  1668. XCursor
  1669. Xload_cursor(sbuf)
  1670. Xshort sbuf[16] ;
  1671. X{
  1672. X  char cbuf[32] ;
  1673. X  int i ;
  1674. X
  1675. X  for (i = 0; i < 16; i++)
  1676. X    {
  1677. X      cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
  1678. X      cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
  1679. X    }
  1680. X  help_pixmap = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), cbuf,
  1681. X                                     16, 16, foregnd, backgnd, 1) ;
  1682. X  return(XCreatePixmapCursor(dpy, help_pixmap, help_pixmap,
  1683. X                                    &FGcolor, &BGcolor, 0, 0)) ;
  1684. X}
  1685. X
  1686. X
  1687. XPixmap
  1688. Xload_icon(sbuf)
  1689. Xshort sbuf[] ;
  1690. X{
  1691. X  GC pix_gc ;
  1692. X  Pixmap pixmap ;
  1693. X  XImage *image ;
  1694. X  char cbuf[512*8] ;
  1695. X  int i ;
  1696. X
  1697. X  if (iscolor)
  1698. X    {
  1699. X      for (i = 0; i < (256*8); i++)
  1700. X        {
  1701. X          cbuf[i*2+0] = palette[(sbuf[i] >> 8) & 0xFF] ;
  1702. X          cbuf[i*2+1] = palette[sbuf[i] & 0xFF] ;
  1703. X        }
  1704. X      pix_gc = DefaultGC(dpy, screen) ;
  1705. X      image = XCreateImage(dpy, DefaultVisual(dpy, screen),
  1706. X                           scr_depth, ZPixmap, 0, cbuf, 64, 64, 8, 64) ;
  1707. X      pixmap = XCreatePixmap(dpy, RootWindow(dpy, screen),
  1708. X                             ICONWIDTH, (unsigned) image->height, scr_depth) ;
  1709. X      XPutImage(dpy, pixmap, pix_gc, image, 0, 0, 0, 0,
  1710. X                ICONWIDTH, (unsigned) image->height) ;
  1711. X    }
  1712. X  else
  1713. X    {
  1714. X      for (i = 0; i < 256; i++)
  1715. X        {
  1716. X          cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
  1717. X          cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
  1718. X        }
  1719. X      pixmap = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), cbuf,
  1720. X                                     64, 64, foregnd, backgnd, scr_depth) ;
  1721. X    }
  1722. X  return(pixmap) ;
  1723. X}
  1724. X
  1725. X
  1726. Xmake_frames(argc, argv)
  1727. Xint argc ;
  1728. Xchar *argv[] ;
  1729. X{
  1730. X  unsigned int h, w ;       /* Window dimensions. */
  1731. X  int flags ;
  1732. X  int x, y ;                /* Window position. */
  1733. SHAR_EOF
  1734. echo "End of part 4"
  1735. echo "File x11.c is continued in part 5"
  1736. echo "5" > s2_seq_.tmp
  1737. exit 0
  1738.  
  1739.