File: mgr.c

package info (click to toggle)
calctool 2.4.9-10
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 432 kB
  • ctags: 1,165
  • sloc: ansic: 5,130; makefile: 613; sh: 22
file content (400 lines) | stat: -rw-r--r-- 9,576 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400

/*  @(#)mgr.c 1.11 89/12/21
 *
 *  These are the MGR dependent graphics routines used by calctool.
 *
 *  Copyright (c) Rich Burridge.
 *                Sun Microsystems, Australia - All rights reserved.
 *
 *  Permission is given to distribute these sources, as long as the
 *  copyright messages are not removed, and no monies are exchanged.
 *
 *  No responsibility is taken for any errors or inaccuracies inherent
 *  either to the comments or the code of this program, but if
 *  reported to me then an attempt will be made to fix them.
 */

#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include "dump.h"
#include "term.h"
#include "calctool.h"
#include "color.h"
#include "extern.h"

#define  S_FONT      1     /* Font descriptors. */
#define  N_FONT      2
#define  B_FONT      3

#define  ICONIC      0     /* States that the calctool display can be in. */
#define  JUST_KEYS   1
#define  SHOW_ALL    2

#define  PR_ICON     1     /* Descriptor for closed icon image. */

#define  SMALLFONT   "sail6x8r"
#define  NORMALFONT  "cour7x14b"
#define  BIGFONT     "gal12x20r"

#define  MENU_COUNT  (sizeof(menus) / (sizeof(struct menu_entry) * MAXMENUS))

struct menu_entry menus[MAXMENUS][MAXREGS] ;

char fontname[MAXLINE] ;      /* Full pathname of the small font. */

int local_mode ;         /* Used by load_icon for correct line mode. */
int mgr_infd ;           /* MGR input connection file descriptor. */
int mgr_outfd ;          /* MGR output connection file descriptor. */

short icon_image[] = {
#include "calctool.icon"
} ;

#ifdef NO_4_3SELECT
int fullmask ;               /* Full mask of file descriptors to check on. */ 
int readmask ;               /* Readmask used in select call. */ 
#else 
fd_set fullmask ;            /* Full mask of file descriptors to check on. */
fd_set readmask ;            /* Readmask used in select call. */
#endif /*NO_4_3SELECT */
 

SIGRET
clean(code)
int code ;
{
  m_bitdestroy(1) ;
  m_pop() ;
  m_ttyreset() ;
  m_clear() ;
  exit(code) ;
}


/*ARGSUSED*/
clear_canvas(canvas, color)
enum can_type canvas ;
int color ;
{
  m_func(B_CLEAR) ;
  if (canvas == KEYCANVAS)
    m_bitwrite(0, 0, TWIDTH+10, THEIGHT+DISPLAY+10) ;
  else if (canvas == REGCANVAS)
    m_bitwrite(TWIDTH+15, 0, TWIDTH+10, THEIGHT+DISPLAY+10) ;
}


close_frame()
{
  reshape(ICONIC) ;
  m_clearmode(M_ACTIVATE) ;
}


color_area(x, y, width, height, color)
int x, y, width, height, color ;
{
  if (color == BLACK)
    {
      m_func(B_COPY) ;
      m_bitwrite(x, y, width, height) ;
    }
}


create_menu(mtype)     /* Create popup menu for right button press. */
enum menu_type mtype ;
{
  int i ;
  char istr[3] ;       /* String representation for action value. */

  for (i = 0; i < MAXREGS; i++)
    {
      SPRINTF(istr, "%1d\r", i) ;
      switch (mtype)
        {
          case M_ACC    :                              /* Accuracies. */
          case M_EXCH   :                              /* Register exchange. */
          case M_LSHIFT :                              /* Left shift. */
          case M_RCL    :                              /* Register recall. */
          case M_RSHIFT :                              /* Right shift. */
          case M_STO    :                              /* Register store. */
                          menus[(int) mtype][i].value = num_names[i] ;
                          break ;
          case M_CON    :                              /* Constants. */
                          menus[(int) mtype][i].value = con_names[i] ;
                          break ;
          case M_FUN    :                              /* Functions. */
                          menus[(int) mtype][i].value = fun_names[i] ;
        }
      menus[(int) mtype][i].action = num_names[i] ;
    }
  menu_load((int) mtype, MENU_COUNT, menus[(int) mtype]) ;
}


destroy_frame()
{
  clean(0) ;
}


do_menu(mtype)      /* Popup appropriate menu and get value. */
enum menu_type mtype ;
{
  m_selectmenu2((int) mtype) ;
}


drawline(x1, y1, x2, y2)
int x1, y1, x2, y2 ;
{
  m_func(B_COPY) ;
  m_line(x1, y1, x2, y2) ;
}


draw_regs()
{
  reshape(SHOW_ALL) ;
  clear_canvas(REGCANVAS, WHITE) ;
  drawline(TWIDTH, 0, TWIDTH, THEIGHT+DISPLAY+10) ;
  make_registers() ;
}


/*ARGSUSED*/
drawtext(x, y, window, fontno, color, str)
enum font_type fontno ;
enum can_type window ;
int x, y, color ;
char *str ;
{
  int i ;

       if (fontno == SFONT) m_font(S_FONT) ;
  else if (fontno == NFONT) m_font(N_FONT) ;
  else if (fontno == BFONT) m_font(B_FONT) ;
       if (window == REGCANVAS) x += TWIDTH + 15 ;
  m_func(B_XOR) ;
  i = strlen(str)-1 ;
  while (str[i] == ' ' && i) str[i--] = '\0' ;
  m_stringto(0, x, y+4, str) ;
  m_movecursor(2500, 2500) ;
}


get_display()
{
}


get_next_event()
{
  int c ;
  static struct timeval tval = { 0, 0 } ;

  m_flush() ;
  for (;;)
    {
      readmask = fullmask ;
#ifdef NO_4_3SELECT
      SELECT(32, &readmask, 0, 0, &tval) ;
      if (readmask && (1 << mgr_infd))
#else
      SELECT(FD_SETSIZE, &readmask, (fd_set *) 0, (fd_set *) 0, &tval) ;
      if (FD_ISSET(mgr_infd, &readmask))
#endif /*NO_4_3SELECT*/
        {
          if ((c = m_getchar()) == EOF)
            {
              clearerr(m_termin) ;
              continue ;
            }
          get_mouse(&curx, &cury) ;
          switch (c)
            {
              case '\030' : return(MIDDLE_DOWN) ;
              case '\031' : return(MIDDLE_UP) ;
              case '\032' : return(LEFT_DOWN) ;
              case '\033' : return(LEFT_UP) ;
              case '\034' : return(DIED) ;           /* Window destroyed. */
              case '\035' : if (iconic) iconic = 0 ;
              case '\036' : if (rstate) reshape(SHOW_ALL) ;
                            else reshape(JUST_KEYS) ;
              case '\037' : return(CFRAME_REPAINT) ; /* Window redrawn. */
              default     : cur_ch = c ;
                            return(KEYBOARD) ;
            }
        }
    }    
}


handle_selection()
{
}


init_fonts()
{
  char path[MAXLINE] ;     /* Directory path for font files. */

#ifdef MGRHOME
  STRCPY(path, MGRHOME) ;
#else
  STRCPY(path, "/usr/mgr") ;
#endif /*MGRHOME*/

  SPRINTF(fontname, "%s/font/%s", path, SMALLFONT) ;
  m_loadfont(SFONT, fontname) ;

  SPRINTF(fontname, "%s/font/%s", path, NORMALFONT) ; 
  m_loadfont(NFONT, fontname) ;
  nfont_width = 9 ;

  SPRINTF(fontname, "%s/font/%s", path, BIGFONT) ; 
  m_loadfont(BFONT, fontname) ;

}


init_ws_type()
{
  m_setup(M_FLUSH) ;     /* Setup I/O; turn on flushing. */
  m_push(P_BITMAP | P_MENU | P_EVENT | P_FONT | P_FLAGS | P_POSITION) ;
  mgr_infd = fileno(m_termin) ;
  mgr_outfd = fileno(m_termout) ;

  SIGNAL(SIGHUP, clean) ;
  SIGNAL(SIGINT, clean) ;
  SIGNAL(SIGTERM, clean) ;
  m_ttyset() ;
  m_setraw() ;
  m_setmode(M_NOWRAP) ;
  m_setmode(M_ABS) ;
  m_setmode(ACTIVATE) ;
  m_clearmode(M_NOINPUT) ;
  m_func(B_COPY) ;

  gtype = MGR ;
  return 0 ;
}


load_colors()      /* Hardwired to a monochrome version. */
{
  iscolor = 0 ;
}


load_icon(pixrect, ibuf)
int pixrect ;
short ibuf[256] ;
{
  int size ;

  IOCTL(mgr_outfd, TIOCLGET, &local_mode) ;
  local_mode |= LLITOUT ;
  IOCTL(mgr_outfd, TIOCLSET, &local_mode) ;

  size = ICONHEIGHT * (((64 + 15) &~ 15) >> 3) ;
  m_bitldto(ICONWIDTH, ICONHEIGHT, 0, 0, pixrect, size) ;
  m_flush() ;
  WRITE(mgr_outfd, (char *) ibuf, size) ;

  local_mode &= ~LLITOUT ;
  IOCTL(mgr_outfd, TIOCLSET, &local_mode) ;
}


/*ARGSUSED*/
make_frames(argc, argv)
int argc ;
char *argv[] ;
{
#ifdef NO_4_3SELECT
  fullmask = 1 << mgr_infd ;
#else
  FD_ZERO(&fullmask) ;
  FD_SET(mgr_infd, &fullmask) ;
#endif /*NO_4_3SELECT*/

  m_setevent(BUTTON_1, "\030") ;    /* Right mouse button depressed. */
  m_setevent(BUTTON_1U, "\031") ;   /* Right mouse button released. */

  m_setevent(BUTTON_2, "\032") ;    /* Middle mouse button depressed. */
  m_setevent(BUTTON_2U, "\033") ;   /* Middle mouse button released. */

  m_setevent(ACTIVATE, "\034") ;    /* Window has been activated. */
  m_setevent(DESTROY, "\035") ;     /* Check for window being destroyed. */
  m_setevent(RESHAPE, "\036") ;     /* Check for window being reshaped. */
  m_setevent(REDRAW, "\037") ;      /* Check for window being redrawn. */
}


make_icon()
{
  load_icon(PR_ICON, icon_image) ;
}


make_items()
{
  do_repaint() ;               /* Redraw the calctool canvas[es]. */
  m_movecursor(2500, 2500) ;   /* Move character cursor offscreen. */
}


make_subframes()
{
  m_font(N_FONT) ;          /* Use the default font. */
  reshape(JUST_KEYS) ;
  m_clear() ;               /* Clear calctool window. */
}


reshape(type)
int type ;
{
  int x, y, w, h ;      /* Position and size of calctool window. */

  get_size(&x, &y, &w, &h) ;
  switch (type)
    {
      case ICONIC    : m_shapewindow(x, y, ICONWIDTH+10, ICONHEIGHT+10) ;
                       m_clear() ;
                       m_bitcopyto(0, 0, ICONWIDTH, ICONHEIGHT,
                                   0, 0, 0, PR_ICON) ;
                       break ;
      case JUST_KEYS : m_shapewindow(x, y, TWIDTH+10, THEIGHT+DISPLAY+10) ;
                       break ;
      case SHOW_ALL  : m_shapewindow(x, y, 2*TWIDTH+25, THEIGHT+DISPLAY+10) ;
    }
  m_movecursor(2500, 2500) ;
}


/*ARGSUSED*/
set_cursor(type)   /* Doesn't appear to be any way to set the cursor. */
int type ;
{
}


start_tool()
{
  while (1)
    process_event(get_next_event()) ;
}


toggle_reg_canvas()      /* Show or clear memory register area. */
{
  rstate = !rstate ;
  if (rstate) draw_regs() ;
  else reshape (JUST_KEYS) ;
}