message.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* This file contains code for X-CHESS.
  2. Copyright (C) 1986 Free Software Foundation, Inc.
  3. This file is part of X-CHESS.
  4. X-CHESS is distributed in the hope that it will be useful,
  5. but WITHOUT ANY WARRANTY. No author or distributor
  6. accepts responsibility to anyone for the consequences of using it
  7. or for whether it serves any particular purpose or works at all,
  8. unless he says so in writing. Refer to the X-CHESS General Public
  9. License for full details.
  10. Everyone is granted permission to copy, modify and redistribute
  11. X-CHESS, but only under the conditions described in the
  12. X-CHESS General Public License. A copy of this license is
  13. supposed to have been given to you along with X-CHESS so you
  14. can know your rights and responsibilities. It should be in a
  15. file named COPYING. Among other things, the copyright notice
  16. and this notice must be preserved on all copies. */
  17. /* RCS Info: $Revision: 1.4 $ on $Date: 86/11/26 12:10:22 $
  18. * $Source: /users/faustus/xchess/RCS/message.c,v $
  19. * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
  20. * Permission is granted to do anything with this code except sell it
  21. * or remove this message.
  22. *
  23. * Do stuff with the message window. Font 0 is the normal font, font 1
  24. * is large, and font 3 is normal red.
  25. */
  26. #include "xchess.h"
  27. #define MESSAGE_HEADER "1 XChess Messages0\n\n"
  28. void
  29. message_init(win)
  30. windata *win;
  31. {
  32. TxtGrab(win->messagewin, "xchess", win->medium,
  33. win->textback.pixel, win->textcolor.pixel,
  34. win->cursorcolor.pixel);
  35. TxtAddFont(win->messagewin, 1, win->large, win->textcolor.pixel);
  36. TxtAddFont(win->messagewin, 2, win->medium, win->errortext.pixel);
  37. TxtAddFont(win->messagewin, 3, win->medium, win->playertext.pixel);
  38. TxtWriteStr(win->messagewin, MESSAGE_HEADER);
  39. return;
  40. }
  41. void
  42. message_add(win, string, err)
  43. windata *win;
  44. char *string;
  45. bool err;
  46. {
  47. XSetDisplay(win->display);
  48. if (err) {
  49. TxtWriteStr(win->messagewin, "2");
  50. TxtWriteStr(win->messagewin, string);
  51. TxtWriteStr(win->messagewin, "0");
  52. XFeep(0);
  53. } else
  54. TxtWriteStr(win->messagewin, string);
  55. return;
  56. }
  57. void
  58. message_send(win, event)
  59. windata *win;
  60. XEvent *event;
  61. {
  62. XKeyOrButtonEvent *ev = (XKeyOrButtonEvent *) event;
  63. windata *ow = (win == win1) ? win2 : win1;
  64. char buf[BSIZE], *s;
  65. int i;
  66. s = XLookupMapping(ev, &i);
  67. strncpy(buf, s, i);
  68. buf[i] = '\0';
  69. for (s = buf; *s; s++)
  70. if (*s == '\r')
  71. *s = '\n';
  72. else if (*s == '\177')
  73. *s = '';
  74. XSetDisplay(win->display);
  75. TxtWriteStr(win->messagewin, "3");
  76. TxtWriteStr(win->messagewin, buf);
  77. TxtWriteStr(win->messagewin, "0");
  78. if (ow) {
  79. XSetDisplay(ow->display);
  80. TxtWriteStr(ow->messagewin, "3");
  81. TxtWriteStr(ow->messagewin, buf);
  82. TxtWriteStr(ow->messagewin, "0");
  83. }
  84. return;
  85. }