home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume13 / faces-1.4.5 / part03 < prev    next >
Encoding:
Text File  |  1990-07-02  |  43.3 KB  |  1,350 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v13i072: Faces v1.4.5: a visual list monitor for mail etc.. (Part 3 of 7).
  3. from: rburridge@Sun.COM (Rich Burridge)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 72
  7. Submitted-by: rburridge@Sun.COM (Rich Burridge)
  8. Archive-name: faces-1.4.5/part03
  9.  
  10. ------CUT HERE------faces.part3------CUT HERE------
  11. #! /bin/sh
  12. # this is a shell archive, meaning:
  13. # 1. Remove everything above the #! /bin/sh line
  14. # 2. Save the resulting text in a file.
  15. # 3. Execute the file with /bin/sh to create the files:
  16. #    xview.c
  17. #    x11.c
  18. #    extern.h
  19. #    faces.h
  20. #    patchlevel.h
  21. # This archive created: Fri Jun 29 10:45:10 EST 1990
  22. #
  23. #
  24. export PATH; PATH=/bin:$PATH
  25. #
  26. if [ -f xview.c ]
  27. then
  28. echo shar: will not over-write existing file xview.c
  29. else
  30. echo shar: extracting 'xview.c',    12752 characters
  31. cat > xview.c <<'Funky_Stuff'
  32.  
  33. /*  @(#)xview.c 1.6 90/06/26
  34.  *
  35.  *  XView dependent graphics routines used by faces,
  36.  *  the visual mail and print job monitor.
  37.  * 
  38.  *  Copyright (c) Rich Burridge - Sun Microsystems Australia.
  39.  *                                All rights reserved.
  40.  *
  41.  *  Permission is given to distribute these sources, as long as the
  42.  *  copyright messages are not removed, and no monies are exchanged. 
  43.  * 
  44.  *  No responsibility is taken for any errors or inaccuracies inherent
  45.  *  either to the comments or the code of this program, but if reported
  46.  *  to me, then an attempt will be made to fix them.
  47.  */
  48.  
  49. #include <stdio.h>
  50. #include "faces.h"
  51. #include "extern.h"
  52. #include <xview/xview.h>
  53. #include <xview/canvas.h>
  54. #include <xview/icon.h>
  55. #include <X11/Xlib.h>
  56.  
  57. #define  DEF_FONT  "fixed"
  58. #define  F_ICON    0                  /* Icon index to frame array. */
  59. #define  F_WINDOW  1                  /* Window index to frame array. */
  60. #define  FONT      "times-roman-10"
  61.  
  62. #define  NOTIFY_INTERPOSE_EVENT_FUNC  (void) notify_interpose_event_func
  63. #define  NOTIFY_SET_ITIMER_FUNC       (void) notify_set_itimer_func
  64. #define  XV_DESTROY                   (void) xv_destroy
  65. #define  XV_SET                       (void) xv_set
  66.  
  67. #define  ITIMER_NULL             ((struct itimerval *) 0)
  68.  
  69. int repaint_proc() ;
  70.  
  71. Canvas canvas ;
  72. Canvas_paint_window pw ;
  73. Frame frame ;
  74. Icon faces_icon ;
  75.  
  76. Display *dpy ;
  77. Drawable xid[2] ;               /* Xlib pointers to the screen and the icon. */
  78. Pixmap pr[3] = { NULL, NULL, NULL } ;     /* Current memory pixmaps. */
  79. Pixmap old_pr[2] = { NULL, NULL } ;       /* Previous memory pixmaps. */
  80.  
  81. /* Array of the different icon images. */
  82. Pixmap images[MAXICONS] = {
  83.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  84. } ;
  85.  
  86. GC gc ;                       /* Main drawing graphics context. */
  87. GC tilegc ;                   /* Graphics context for tiling background. */
  88. Window root ;
  89. XFontStruct *sfont ;
  90. XGCValues gc_val ;            /* Used to setup graphics context values. */
  91. int screen ;                  /* Default graphics display screen. */
  92. int toclear ;                 /* Set if faces icon needs clearing. */
  93. unsigned int depth ;
  94. unsigned long backgnd ;       /* Default background color. */
  95. unsigned long foregnd ;       /* Default foreground color. */
  96. unsigned long gc_mask ;       /* Mask for setting graphic context values. */
  97.  
  98.  
  99. adjust_image(dtype, itype, row, column)  /* Put new face in memory pixrect. */
  100. enum disp_type dtype ;
  101. enum icon_type itype ;
  102. int row, column ;
  103. {
  104.   if (mtype == MONNEW)
  105.     XCopyArea(dpy, pr[(int) dtype], pr[(int) dtype], gc, 0, 0,
  106.               (maxcols-1)*imagewidth, imageheight, imagewidth, 0) ;
  107.  
  108.   XCopyArea(dpy, images[(int) itype], pr[(int) dtype], gc, 0, 0,
  109.             imagewidth, imageheight, column*imagewidth, row*imageheight) ;
  110. }
  111.  
  112.  
  113. /*ARGSUSED*/
  114. beep_flash(beeps, flashes)    /* Perform visual feedback. */
  115. int beeps, flashes ;
  116. {
  117.   int i ;
  118.  
  119.   for (i = 0; i < beeps; i++) window_bell(frame) ;
  120. }
  121.  
  122.  
  123. /*ARGSUSED*/
  124. void
  125. canvas_proc(canvas, event, arg)
  126. Canvas canvas ;
  127. Event *event ;
  128. caddr_t arg ;
  129. {
  130.   int nextc ;
  131.  
  132.   nextc = event_id(event) ;
  133.   if (event_is_down(event) && nextc == MS_LEFT)
  134.     {
  135.       wdtype = (wdtype == DISP_NAME) ? DISP_OTHER : DISP_NAME ;
  136.       XCopyArea(dpy, pr[(int) wdtype], xid[F_WINDOW], gc, 0, 0,
  137.                 width, height, 0, 0) ;
  138.     }
  139.   else if (mtype == MONNEW && event_is_ascii(event) && nextc == DEL)
  140.     {
  141.       repl_image(DISP_NAME,  CUROFF, width, height) ;
  142.       repl_image(DISP_OTHER, CUROFF, width, height) ;
  143.       toclear = 1 ;
  144.       do_check() ;
  145.     }
  146. }
  147.  
  148.  
  149. Notify_value
  150. check_mail()
  151. {
  152.   do_check() ;
  153. }
  154.  
  155.  
  156. create_pixrects(width, height)   /* Create pixrects for the face images. */
  157. int width, height ;
  158. {
  159.   old_pr[(int) DISP_NAME]  = pr[(int) DISP_NAME] ;
  160.   old_pr[(int) DISP_OTHER] = pr[(int) DISP_OTHER] ;
  161.  
  162.   make_area(DISP_NAME, width, height) ;
  163.   repl_image(DISP_NAME, CUROFF, width, height) ;
  164.  
  165.   if (toclear && mtype == MONNEW)
  166.     {
  167.       repl_image(DISP_OTHER, OLDOFF, width, height) ;
  168.       toclear = 0 ;
  169.     }
  170.  
  171.   make_area(DISP_OTHER, width, height) ;
  172.   repl_image(DISP_OTHER, CUROFF, width, height) ;
  173.  
  174.   if (mtype == MONNEW && old_pr[(int) DISP_NAME] != NULL)
  175.     XCopyArea(dpy, old_pr[(int) DISP_NAME], pr[(int) DISP_NAME], gc, 0, 0,
  176.               (unsigned int) width, (unsigned int) height, 0, 0) ;
  177.   if (mtype == MONNEW && old_pr[(int) DISP_OTHER] != NULL)
  178.     XCopyArea(dpy, old_pr[(int) DISP_OTHER], pr[(int) DISP_OTHER], gc, 0, 0,
  179.               (unsigned int) width, (unsigned int) height, 0, 0) ;
  180. }
  181.  
  182.  
  183. destroy_image(itype)
  184. enum icon_type itype ;
  185. {
  186.   if (images[(int) itype] != NULL)
  187.     {
  188.       XFreePixmap(dpy, images[(int) itype]) ;
  189.       images[(int) itype] = NULL ;
  190.     }
  191. }
  192.  
  193.  
  194. static Notify_value
  195. frame_interpose(frame, event, arg, type)
  196. Frame frame ;
  197. Event *event ;
  198. Notify_arg arg ;
  199. Notify_event_type type ;
  200. {
  201.   Notify_value rc ;
  202.  
  203.   rc = notify_next_event_func(frame, event, arg, type) ;
  204.   if (event_action(event) == ACTION_CLOSE)
  205.     {
  206.       XCopyArea(dpy, pr[(int) DISP_ICON], xid[F_ICON], gc, 0, 0, 
  207.                 imagewidth, imageheight, 0, 0) ; 
  208.     }
  209.   return(rc) ;
  210. }
  211.  
  212.  
  213. init_font()
  214. {
  215.   if (!(sfont = XLoadQueryFont(dpy, FONT)))
  216.     if (!(sfont = XLoadQueryFont(dpy, DEF_FONT)))
  217.       {
  218.         perror("couldn't get the default font.") ;
  219.         exit(1) ;
  220.       }
  221. }
  222.  
  223.  
  224. init_ws_type(argc, argv)
  225. int argc ;
  226. char *argv[] ;
  227. {
  228.   int i, j ;
  229.   unsigned short buf[256] ;
  230.  
  231.   xv_init(XV_INIT_ARGS, argc, argv, 0) ;
  232.   frame = xv_create(XV_NULL, FRAME, 0) ;   /* Needed to get Xlib handles now.*/
  233.  
  234.   faces_icon = xv_create(XV_NULL,   ICON,
  235.                          XV_WIDTH,  imagewidth,
  236.                          XV_HEIGHT, imageheight,
  237.                          0) ;
  238.   xid[F_ICON] = (Drawable) xv_get(faces_icon, XV_XID) ;
  239.  
  240.   dpy  = (Display *) xv_get(frame, XV_DISPLAY) ;
  241.   screen  = DefaultScreen(dpy) ;
  242.   root = RootWindow(dpy, screen) ;
  243.   foregnd = BlackPixel(dpy, screen) ;
  244.   backgnd = WhitePixel(dpy, screen) ;
  245.   depth = DefaultDepth(dpy, screen) ;
  246.  
  247.   init_font() ;
  248.  
  249.   gc_mask = GCFont | GCForeground | GCBackground | GCGraphicsExposures ;
  250.   gc_val.font = sfont->fid ;
  251.   gc_val.foreground = foregnd ;
  252.   gc_val.background = backgnd ;
  253.   gc_val.graphics_exposures = False ;
  254.   gc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  255.  
  256.   tilegc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  257.   if (depth == 1) XSetFillStyle(dpy, tilegc, FillOpaqueStippled) ;
  258.   else            XSetFillStyle(dpy, tilegc, FillTiled) ;
  259.  
  260.   for (i = 0; i < 16; i++)    /* Load default gray background. */
  261.     {
  262.       for (j = 0; j < 4; j++) buf[i * 16      + j] = 0x7777 ;
  263.       for (j = 0; j < 4; j++) buf[i * 16 +  4 + j] = 0xDDDD ;
  264.       for (j = 0; j < 4; j++) buf[i * 16 +  8 + j] = 0xBBBB ;
  265.       for (j = 0; j < 4; j++) buf[i * 16 + 12 + j] = 0xEEEE ;
  266.     }
  267.  
  268.   if (strlen(bgicon)) GET_SUN_ICON(bgicon, buf) ;
  269.   load_icon(BACKGROUND, buf) ;
  270.  
  271.   STRCPY(fname[0], "sun.icon") ;
  272.   STRCPY(fname[1], "48x48x1") ;
  273.   STRCPY(fname[2], "face.xbm") ;
  274.   maxtypes = 3 ;
  275.   gtype = XVIEW ;
  276.   pr[(int) DISP_NAME] = pr[(int) DISP_OTHER] = NULL ;
  277.   old_pr[(int) DISP_NAME] = old_pr[(int) DISP_OTHER] = NULL ;
  278.   toclear = 0 ;
  279.   return 0 ;
  280. }
  281.  
  282.  
  283. /* Create a server image from given image data. */
  284.  
  285. /*ARGSUSED*/
  286. load_icon(itype, sbuf, not_flipped)
  287. enum icon_type itype ;
  288. unsigned short sbuf[256] ;
  289. int not_flipped ;
  290. {
  291.   char cbuf[512] ;
  292.   int i ;
  293.  
  294.   for (i = 0; i < 256; i++)
  295.     {
  296.       cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
  297.       cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
  298.     }
  299.   images[(int) itype] = XCreatePixmapFromBitmapData(dpy, root,
  300.                                            cbuf, iconwidth, iconheight,
  301.                                            foregnd, backgnd, depth) ;
  302. }
  303.  
  304.  
  305. make_area(dtype, width, height)
  306. enum disp_type dtype ;
  307. int width, height ;
  308. {
  309.   pr[(int) dtype] = XCreatePixmap(dpy, root, (unsigned int) width,
  310.                                   (unsigned int) height, depth) ;
  311.   XSetFunction(dpy, gc, GXandInverted) ;
  312.   XFillRectangle(dpy, pr[(int) dtype], gc, 0, 0, width, height) ;
  313.   XSetFunction(dpy, gc, GXcopy) ;
  314. }
  315.  
  316.  
  317. /*ARGSUSED*/
  318. make_frame(argc, argv)
  319. int argc ;
  320. char *argv[] ;
  321. {
  322.   XV_SET(frame,
  323.          FRAME_ICON,                  faces_icon,
  324.          FRAME_LABEL,                 "faces",
  325.          FRAME_NO_CONFIRM,            TRUE,
  326.          FRAME_SHOW_FOOTER,           FALSE,
  327.          XV_WIDTH,                    maxcols * imagewidth,
  328.          XV_HEIGHT,                   imageheight * 10,
  329.          0) ;
  330.   NOTIFY_INTERPOSE_EVENT_FUNC(frame, frame_interpose, 0) ;
  331.  
  332.   canvas = xv_create(frame,               CANVAS,
  333.                      CANVAS_REPAINT_PROC, repaint_proc,
  334.                      CANVAS_RETAINED,     FALSE,
  335.                      CANVAS_PAINTWINDOW_ATTRS,
  336.                      WIN_CONSUME_EVENTS,
  337.                        MS_LEFT, WIN_ASCII_EVENTS,
  338.                        WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
  339.                        0,
  340.                      WIN_IGNORE_EVENTS,
  341.                        LOC_MOVE, LOC_DRAG,
  342.                        0,
  343.                      WIN_EVENT_PROC, canvas_proc,
  344.                        0,
  345.                      0) ;
  346.  
  347.   pw = canvas_paint_window(canvas) ;
  348.   xid[F_WINDOW] = (Drawable) xv_get(pw, XV_XID) ;
  349.  
  350.   width = maxcols * imagewidth ;
  351.   height = imageheight ;
  352. }
  353.  
  354.  
  355. make_icon()
  356. {
  357.   if (mtype == MONPRINTER) adjust_image(DISP_ICON, NOPRINT, 0, 0) ;
  358.   else                     adjust_image(DISP_ICON, NOMAIL,  0, 0) ;
  359. }
  360.  
  361.  
  362. /*ARGSUSED*/
  363. repaint_proc(canvas, window, repaint_area)
  364. Canvas canvas ;
  365. Xv_Window window ;
  366. Rectlist *repaint_area ;
  367. {
  368.   XCopyArea(dpy, pr[(int) wdtype], xid[F_WINDOW], gc, 0, 0,
  369.             (unsigned int) width, (unsigned int) height, 0, 0) ;
  370. }
  371.  
  372.  
  373. repl_image(dtype, dest, width, height)
  374. enum disp_type dtype ;
  375. enum image_type dest ;
  376. int width, height ;
  377. {
  378.   Pixmap dpm ;
  379.  
  380.   if (dest == CUROFF) dpm = pr[(int) dtype] ;
  381.   else dpm = old_pr[(int) dtype] ;
  382.   if (depth == 1) XSetStipple(dpy, tilegc, images[(int) BACKGROUND]) ;
  383.   else XSetTile(dpy, tilegc, images[(int) BACKGROUND]) ;
  384.   XFillRectangle(dpy, dpm, tilegc, 0, 0, width, height) ;
  385. }
  386.  
  387.  
  388. show_display()    /* Show the latest set of mail icon faces. */
  389. {
  390.   Rect *temprect ;
  391.  
  392.   if (invert)     /* Invert the memory pixrects before displaying. */
  393.     {
  394.       XSetFunction(dpy, gc, GXcopyInverted) ;
  395.       XCopyArea(dpy, pr[(int) DISP_NAME], pr[(int) DISP_NAME], gc, 0, 0,
  396.                 (unsigned int) width, (unsigned int) height, 0, 0) ;
  397.       XCopyArea(dpy, pr[(int) DISP_OTHER], pr[(int) DISP_OTHER], gc, 0, 0,
  398.                 (unsigned int)  width, (unsigned int) height, 0, 0) ;
  399.     }
  400.  
  401.   XCopyArea(dpy, pr[(int) DISP_ICON], xid[F_ICON], gc, 0, 0,
  402.             (unsigned int) width, (unsigned int) height, 0, 0) ;
  403.  
  404.   temprect = (Rect *) xv_get(frame, FRAME_OPEN_RECT) ;
  405.   temprect->r_height = height ;
  406.   temprect->r_width = width ;
  407.   XV_SET(frame, FRAME_OPEN_RECT, temprect, 0) ;
  408.  
  409.   XCopyArea(dpy, pr[(int) wdtype], xid[F_WINDOW], gc, 0, 0,
  410.             (unsigned int) width, (unsigned int) height, 0, 0) ;
  411.  
  412.   if (newmail) beep_flash(beeps, flashes) ;
  413.   if (old_pr[(int) DISP_NAME])  XFreePixmap(dpy, old_pr[(int) DISP_NAME]) ;
  414.   if (old_pr[(int) DISP_OTHER]) XFreePixmap(dpy, old_pr[(int) DISP_OTHER]) ;
  415.   old_pr[(int) DISP_NAME] = NULL ;
  416.   old_pr[(int) DISP_OTHER] = NULL ;
  417.   XSync(dpy, 0) ;
  418. }
  419.  
  420.  
  421. start_tool()
  422. {
  423.   struct itimerval tval ;
  424.  
  425.   tval.it_interval.tv_usec = 0 ;
  426.   tval.it_interval.tv_sec = period ;
  427.   tval.it_value.tv_usec = 0 ;
  428.   tval.it_value.tv_sec = period ;
  429.   NOTIFY_SET_ITIMER_FUNC(frame, check_mail,
  430.                          ITIMER_REAL, &tval, ITIMER_NULL) ;
  431.   xv_main_loop(frame) ;
  432. }
  433.  
  434.  
  435. text(dtype, jtype, str)
  436. enum disp_type dtype ;
  437. enum just_type jtype ;
  438. char *str ;
  439. {
  440.   int len ;
  441.   int c, r ;         /* Column and row position for this face. */
  442.   int x, y ;         /* Position of start of this text string. */
  443.  
  444.   c = column ;
  445.   r = row ;
  446.   switch (dtype)
  447.     {
  448.       case DISP_ALL    : text(DISP_ICON,  jtype, str) ;
  449.       case DISP_BOTH   : text(DISP_NAME,  jtype, str) ;
  450.                          text(DISP_OTHER, jtype, str) ;
  451.                          return ;
  452.       case DISP_ICON   : c = r = 0 ;
  453.     }
  454.  
  455.   if ((len = strlen(str)) > 10)      /* Character length of text. */
  456.     {
  457.       len = 10 ;
  458.       str[10] = '\0' ;               /* Maximum of 10 characters. */
  459.     }
  460.   switch (jtype)
  461.     {
  462.       case LEFT  : x =  c      * imagewidth + 2 ;
  463.                    y = (r + 1) * imageheight - 5 ;
  464.                    break ;
  465.       case RIGHT : x = (c + 1) * imagewidth - (len * 6) - 2 ;
  466.                    y = (r + 1) * imageheight - 5 ;
  467.     }
  468.   XSetFunction(dpy, gc, GXandInverted) ;
  469.   XFillRectangle(dpy, pr[(int) dtype], gc, x, y-9, (unsigned int) len*6+2, 13) ;
  470.   XSetFunction(dpy, gc, GXxor) ;
  471.   XDrawImageString(dpy, pr[(int) dtype], gc, x, y, str, strlen(str)) ;
  472.   XSetFunction(dpy, gc, GXcopy) ;
  473. }
  474. Funky_Stuff
  475. len=`wc -c < xview.c`
  476. if [ $len !=    12752 ] ; then
  477. echo error: xview.c was $len bytes long, should have been    12752
  478. fi
  479. fi # end of overwriting check
  480. if [ -f x11.c ]
  481. then
  482. echo shar: will not over-write existing file x11.c
  483. else
  484. echo shar: extracting 'x11.c',    16665 characters
  485. cat > x11.c <<'Funky_Stuff'
  486.  
  487. /*  @(#)x11.c 1.12 90/06/26
  488.  *
  489.  *  X11 dependent graphics routines used by faces,
  490.  *  the visual mail and print job monitor.
  491.  * 
  492.  *  Copyright (c) Rich Burridge - Sun Microsystems Australia.
  493.  *                                All rights reserved.
  494.  *
  495.  *  Permission is given to distribute these sources, as long as the
  496.  *  copyright messages are not removed, and no monies are exchanged. 
  497.  * 
  498.  *  No responsibility is taken for any errors or inaccuracies inherent
  499.  *  either to the comments or the code of this program, but if reported
  500.  *  to me, then an attempt will be made to fix them.
  501.  *
  502.  */
  503.  
  504. #include <stdio.h>
  505. #include <sys/time.h>
  506. #include "faces.h"
  507. #include "extern.h"
  508. #include <X11/Xlib.h>
  509. #include <X11/Xutil.h>
  510. #include <X11/Xatom.h>
  511.  
  512. #define  DEF_FONT            "fixed"
  513. #define  F_ICON              0         /* Icon index to frame array. */
  514. #define  F_WINDOW            1         /* Window index to frame array. */
  515. #define  FACES_BORDER_WIDTH  2
  516. #define  FONT                "times-roman-10"
  517. #define  FRAME_MASK          (ButtonPressMask  | ExposureMask | \
  518.                               ButtonMotionMask | KeyPressMask)
  519.  
  520. Atom protocol_atom, kill_atom ;
  521. Display *dpy ;
  522. GC gc ;
  523. GC tilegc ;
  524. Pixmap faces_icon ;
  525.  
  526. /* Array of the different icon images. */
  527. Pixmap images[MAXICONS] = {
  528.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  529. } ;
  530.  
  531. Pixmap pr[3] = { NULL, NULL, NULL } ;    /* Current memory Pixmaps. */
  532. Pixmap old_pr[2] = { NULL, NULL } ;      /* Previous memory Pixmaps. */
  533. Window frame[2] ;
  534. Window root ;
  535. XFontStruct *sfont ;
  536. XGCValues gc_val ;
  537. XSizeHints size ;
  538. XWMHints wm_hints ;
  539.  
  540. #ifdef NO_43SELECT
  541. int fullmask ;               /* Full mask of file descriptors to check on. */
  542. int readmask ;               /* Readmask used in select call. */
  543. #else
  544. fd_set fullmask ;            /* Full mask of file descriptors to check on. */
  545. fd_set readmask ;            /* Readmask used in select call. */
  546. #endif /*NO_43SELECT*/
  547.  
  548. unsigned long gc_mask ;
  549. int screen ;
  550. int toclear ;                /* Set if faces icon needs clearing. */
  551. int xfd ;                    /* File descriptor for X11 server connection. */
  552. unsigned int depth ;
  553. long backgnd, foregnd ;
  554.  
  555.  
  556. adjust_image(dtype, itype, row, column)  /* Put new face in memory pixrect. */
  557. enum disp_type dtype ;
  558. enum icon_type itype ;
  559. int row, column ;
  560. {
  561.   if (mtype == MONNEW)
  562.     XCopyArea(dpy, pr[(int) dtype], pr[(int) dtype], gc, 0, 0,
  563.               (maxcols-1)*imagewidth, imageheight, imagewidth, 0) ;
  564.   XCopyArea(dpy, images[(int) itype], pr[(int) dtype], gc, 0, 0,
  565.             imagewidth, imageheight, column*imagewidth, row*imageheight) ;
  566. }
  567.  
  568.  
  569. beep_flash(beeps, flashes)    /* Perform visual feedback. */
  570. int beeps, flashes ;
  571. {
  572.   static struct timeval btime = { 0, 250000 } ;   /* Beep timer. */
  573.  
  574.   while (beeps > 0)
  575.     {
  576.       XBell(dpy, 56) ;
  577.       SELECT(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &btime) ;
  578.       beeps-- ;
  579.     }
  580.   while (flashes > 0)
  581.     {
  582.       XSetFunction(dpy, gc, GXcopyInverted) ;
  583.       XCopyArea(dpy, frame[F_WINDOW], frame[F_WINDOW], gc, 0, 0,
  584.                 (unsigned int) width, (unsigned int) height, 0, 0) ;
  585.       XCopyArea(dpy, frame[F_WINDOW], frame[F_WINDOW], gc, 0, 0,
  586.                 (unsigned int) width, (unsigned int) height, 0, 0) ;
  587.  
  588.       XCopyArea(dpy, frame[F_ICON], frame[F_ICON], gc, 0, 0,
  589.                 (unsigned int) width, (unsigned int) height, 0, 0) ;
  590.       XCopyArea(dpy, frame[F_ICON], frame[F_ICON], gc, 0, 0,
  591.                 (unsigned int) width, (unsigned int) height, 0, 0) ;
  592.       flashes-- ;
  593.     }
  594.   XSetFunction(dpy, gc, GXcopy) ;
  595. }
  596.  
  597.  
  598. create_pixrects(width, height)   /* Create pixrects for the face images. */
  599. int width, height ;
  600. {
  601.   old_pr[(int) DISP_NAME]  = pr[(int) DISP_NAME] ;
  602.   old_pr[(int) DISP_OTHER] = pr[(int) DISP_OTHER] ;
  603.  
  604.   make_area(DISP_NAME, width, height) ;
  605.   repl_image(DISP_NAME, CUROFF, width, height) ;
  606.  
  607.   if (toclear && mtype == MONNEW)
  608.     {
  609.       repl_image(DISP_OTHER, OLDOFF, width, height) ;
  610.       toclear = 0 ;
  611.     }
  612.     
  613.   make_area(DISP_OTHER, width, height) ;
  614.   repl_image(DISP_OTHER, CUROFF, width, height) ;
  615.  
  616.   if (mtype == MONNEW && old_pr[(int) DISP_NAME] != NULL)
  617.     XCopyArea(dpy, old_pr[(int) DISP_NAME], pr[(int) DISP_NAME], gc, 0, 0,
  618.               (unsigned int) width, (unsigned int) height, 0, 0) ;
  619.   if (mtype == MONNEW && old_pr[(int) DISP_OTHER] != NULL)
  620.     XCopyArea(dpy, old_pr[(int) DISP_OTHER], pr[(int) DISP_OTHER], gc, 0, 0,
  621.               (unsigned int) width, (unsigned int) height, 0, 0) ;
  622. }
  623.  
  624.  
  625. destroy_image(itype)
  626. enum icon_type itype ;
  627. {
  628.   if (images[(int) itype] != NULL)
  629.     {
  630.       XFreePixmap(dpy, images[(int) itype]) ;
  631.       images[(int) itype] = NULL ;
  632.     }
  633. }
  634.  
  635.  
  636. init_font()
  637. {
  638.   if ((sfont = XLoadQueryFont(dpy, FONT)) == NULL)
  639.     if ((sfont = XLoadQueryFont(dpy, DEF_FONT)) == NULL)
  640.       {
  641.         perror("couldn't get the default font.") ;
  642.         exit(1) ;
  643.       }
  644. }
  645.  
  646.  
  647. /*ARGSUSED*/
  648. init_ws_type(argc, argv)
  649. int argc ;
  650. char *argv[] ;
  651. {
  652.   int i, j ;
  653.   unsigned short buf[256] ;
  654.  
  655.   if ((dpy = XOpenDisplay(display)) == NULL)
  656.     {
  657.       FPRINTF(stderr,"%s: Couldn't open display %s\n", progname,
  658.               (getenv ("DISPLAY") ? getenv("DISPLAY") : display)) ;
  659.       exit(1) ;
  660.     }
  661.   xfd = ConnectionNumber(dpy) ;
  662.  
  663. #ifdef NO_43SELECT
  664.   fullmask = 1 << xfd ;
  665. #else
  666.   FD_ZERO(&fullmask) ;
  667.   FD_SET(xfd, &fullmask) ;
  668. #endif /*NO_43SELECT*/
  669.  
  670.   screen = DefaultScreen(dpy) ;
  671.   root = RootWindow(dpy, screen) ;
  672.   if (geometry[0] != '\0')
  673.     STRCPY(geometry, XGetDefault(dpy, progname, "Geometry")) ;
  674.  
  675.   foregnd = BlackPixel(dpy, screen) ;
  676.   backgnd = WhitePixel(dpy, screen) ;
  677.   depth = DefaultDepth(dpy, screen) ;
  678.  
  679.   init_font() ;
  680.  
  681.   gc_mask = GCFont | GCForeground | GCBackground | GCGraphicsExposures ;
  682.   gc_val.font = sfont->fid ;
  683.   gc_val.foreground = foregnd ;
  684.   gc_val.background = backgnd ;
  685.   gc_val.graphics_exposures = False ;
  686.   gc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  687.     
  688.   tilegc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  689.   if (depth == 1) XSetFillStyle(dpy, tilegc, FillOpaqueStippled) ;
  690.   else            XSetFillStyle(dpy, tilegc, FillTiled) ;
  691.  
  692.   for (i = 0; i < 16; i++)    /* Load default gray background. */
  693.     {
  694.       for (j = 0; j < 4; j++) buf[i * 16      + j] = 0x7777 ;
  695.       for (j = 0; j < 4; j++) buf[i * 16 +  4 + j] = 0xDDDD ;
  696.       for (j = 0; j < 4; j++) buf[i * 16 +  8 + j] = 0xBBBB ;
  697.       for (j = 0; j < 4; j++) buf[i * 16 + 12 + j] = 0xEEEE ;
  698.     }
  699.  
  700.   if (strlen(bgicon)) GET_SUN_ICON(bgicon, buf) ;
  701.   load_icon(BACKGROUND, buf) ;
  702.  
  703.   STRCPY(fname[0], "face.xbm") ;
  704.   STRCPY(fname[1], "sun.icon") ;
  705.   STRCPY(fname[2], "48x48x1") ;
  706.   maxtypes = 3 ;
  707.   gtype = X11 ;
  708.   pr[(int) DISP_NAME] = pr[(int) DISP_OTHER] = NULL ;
  709.   old_pr[(int) DISP_NAME] = old_pr[(int) DISP_OTHER] = NULL ;
  710.   toclear = 0 ;
  711.   return(0) ;
  712. }
  713.  
  714.  
  715. /*ARGSUSED*/
  716. static Bool
  717. is_exposed(dpy, ev, window)   /* Return True if window is being exposed */
  718. Display *dpy ;
  719. XEvent *ev ;
  720. char *window ;
  721. {
  722.   if (ev->type == Expose && *((Window *) window) == ev->xkey.window)
  723.     return True ;
  724.   return False ;
  725. }
  726.  
  727.  
  728. /*ARGSUSED*/
  729. load_icon(itype, sbuf, not_flipped)
  730. enum icon_type itype ;
  731. unsigned short sbuf[256] ;
  732. int not_flipped ;
  733. {
  734.   char cbuf[512] ;
  735.   int i ;
  736.  
  737.   for (i = 0; i < 256; i++)
  738.     {
  739.       cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
  740.       cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
  741.     }
  742.   images[(int) itype] = XCreatePixmapFromBitmapData(dpy, root,
  743.                                            cbuf, iconwidth, iconheight,
  744.                                            foregnd, backgnd, depth) ;
  745. }
  746.  
  747.  
  748. make_area(dtype, width, height)
  749. enum disp_type dtype ;
  750. int width, height ;
  751. {
  752.   pr[(int) dtype] = XCreatePixmap(dpy, root,
  753.                       (unsigned int) width, (unsigned int) height, depth) ;
  754.   XSetFunction(dpy, gc, GXandInverted) ;
  755.   XFillRectangle(dpy, pr[(int) dtype], gc, 0, 0, width, height) ;
  756.   XSetFunction(dpy, gc, GXcopy) ;
  757. }
  758.  
  759.  
  760. /*ARGSUSED*/
  761. make_frame(argc, argv)
  762. int argc ;
  763. char *argv[] ;
  764. {
  765.   unsigned int h, w ;                /* Window dimensions. */
  766.   int flags ;
  767.   int x, y ;                         /* Window position. */
  768.   XSetWindowAttributes winattrs ;
  769.  
  770.   w = width = maxcols * imagewidth ;
  771.   h = height = imageheight ;
  772.  
  773.   size.flags = PMinSize | PMaxSize | PPosition | PSize ;
  774.   size.x = 0 ;
  775.   size.y = 0 ;
  776.   size.min_width = imagewidth ;
  777.   size.min_height = imageheight ;
  778.   size.max_width = size.width = width ;
  779.   if (mtype == MONNEW) size.max_height = imageheight ;
  780.   else                 size.max_height = 900 ;
  781.   size.height = height ;
  782.  
  783.   if (strlen(geometry))
  784.     {
  785.       flags = XParseGeometry(geometry, &x, &y, &w, &h) ;
  786.       if (XValue & flags)
  787.         {
  788.           if (XNegative & flags)
  789.             x = DisplayWidth(dpy, screen) + x - size.width ;
  790.             size.flags |= USPosition ;
  791.             size.x = x ;
  792.         }
  793.       if (YValue & flags)
  794.         {
  795.           if (YNegative & flags)
  796.             y = DisplayHeight(dpy, screen) + y - size.height ;
  797.             size.flags |= USPosition ;
  798.             size.y = y ;
  799.         }
  800.     }
  801.  
  802. #ifdef WANTED
  803.   frame[F_WINDOW] = XCreateSimpleWindow(dpy, root,
  804.                                         size.x, size.y, size.width, size.height,
  805.                                         FACES_BORDER_WIDTH, foregnd, backgnd) ;
  806.  
  807.   frame[F_ICON] = XCreateSimpleWindow(dpy, root,
  808.                                       ix, iy, imagewidth, imageheight,
  809.                                       FACES_BORDER_WIDTH, foregnd, backgnd) ;
  810. #endif /*WANTED*/
  811.  
  812.   winattrs.background_pixel = backgnd ;
  813.   winattrs.border_pixel = foregnd ;
  814.   winattrs.event_mask = FRAME_MASK ;
  815.  
  816.   frame[F_WINDOW] = XCreateWindow(dpy, root, size.x, size.y,
  817.                         size.width, size.height, FACES_BORDER_WIDTH,
  818.                         CopyFromParent, InputOutput, CopyFromParent,
  819.                         CWBackPixel | CWBorderPixel | CWEventMask, &winattrs) ;
  820.  
  821.   frame[F_ICON] = XCreateWindow(dpy, root,
  822.                         ix, iy, imagewidth, imageheight, FACES_BORDER_WIDTH,
  823.                         CopyFromParent, InputOutput, CopyFromParent, 
  824.                         CWBackPixel | CWBorderPixel | CWEventMask, &winattrs) ;
  825.  
  826.   protocol_atom = XInternAtom(dpy, "WM_PROTOCOLS", False) ;
  827.   kill_atom = XInternAtom(dpy, "WM_DELETE_WINDOW", False) ;
  828.   XSetWMProtocols(dpy, frame[F_WINDOW], &kill_atom, 1) ;
  829.  
  830.   XSetStandardProperties(dpy, frame[F_WINDOW], "faces", "faces", None,
  831.                          argv, argc, &size) ;
  832.  
  833.   wm_hints.icon_x = ix ;
  834.   wm_hints.icon_y = iy ;
  835.   wm_hints.input = True ;
  836.   wm_hints.icon_window = frame[F_ICON] ;
  837.   wm_hints.flags = IconPositionHint | InputHint | IconWindowHint ;
  838.   if (iconic)
  839.     {    
  840.       wm_hints.initial_state = IconicState ;
  841.       wm_hints.flags |= StateHint ;
  842.     }    
  843.   XSetWMHints(dpy, frame[F_WINDOW], &wm_hints) ;
  844. /**  XSetWMHints(dpy, frame[F_ICON],   &wm_hints) ; **/
  845.  
  846. /* Equivalent of make_icon. */
  847.  
  848.   if (mtype == MONPRINTER) adjust_image(DISP_ICON, NOPRINT, 0, 0) ;
  849.   else                     adjust_image(DISP_ICON, NOMAIL,  0, 0) ;
  850. }
  851.  
  852.  
  853. make_icon()         /* Null routine. */
  854. {}
  855.  
  856.  
  857. repl_image(dtype, dest, width, height)
  858. enum disp_type dtype ;
  859. enum image_type dest ;
  860. int width, height ;
  861. {
  862.   Pixmap dpm ;
  863.  
  864.   if (dest == CUROFF) dpm = pr[(int) dtype] ;
  865.   else dpm = old_pr[(int) dtype] ;
  866.   if (depth == 1) XSetStipple(dpy, tilegc, images[(int) BACKGROUND]) ;
  867.   else XSetTile(dpy, tilegc, images[(int) BACKGROUND]) ;
  868.   XFillRectangle(dpy, dpm, tilegc, 0, 0, width, height) ;
  869. }
  870.  
  871.  
  872. show_display()    /* Show the latest set of mail icon faces. */
  873. {
  874.   XEvent ev ;
  875.   static int first_time = 1 ;
  876.  
  877.   if (invert)     /* Invert the memory pixrects before displaying. */
  878.     {
  879.       XSetFunction(dpy, gc, GXcopyInverted) ;
  880.       XCopyArea(dpy, pr[(int) DISP_NAME], pr[(int) DISP_NAME], gc, 0, 0,
  881.                 (unsigned int) width, (unsigned int) height, 0, 0) ;
  882.       XCopyArea(dpy, pr[(int) DISP_OTHER], pr[(int) DISP_OTHER], gc, 0, 0,
  883.                 (unsigned int)  width, (unsigned int) height, 0, 0) ;
  884.     }
  885.   if (first_time)
  886.     {
  887.       XSelectInput(dpy, frame[F_WINDOW], FRAME_MASK) ;
  888.       XMapWindow(dpy, frame[F_WINDOW]) ;
  889.       XSync(dpy, 0) ;
  890.       XPeekIfEvent(dpy, &ev, is_exposed, (char *) &frame[F_WINDOW]) ;
  891.       first_time = 0 ;
  892.     }
  893.  
  894.   XCopyArea(dpy, pr[(int) DISP_ICON], frame[F_ICON], gc, 0, 0,
  895.             (unsigned int) width, (unsigned int) height, 0, 0) ;
  896.  
  897.   XResizeWindow(dpy, frame[F_WINDOW],
  898.                 (unsigned int) width, (unsigned int) height) ;
  899.   XCopyArea(dpy, pr[(int) wdtype], frame[F_WINDOW], gc, 0, 0,
  900.             (unsigned int) width, (unsigned int) height, 0, 0) ;
  901.  
  902.   if (newmail) beep_flash(beeps, flashes) ;
  903.   if (old_pr[(int) DISP_NAME])  XFreePixmap(dpy, old_pr[(int) DISP_NAME]) ;
  904.   if (old_pr[(int) DISP_OTHER]) XFreePixmap(dpy, old_pr[(int) DISP_OTHER]) ;
  905.   old_pr[(int) DISP_NAME] = NULL ;
  906.   old_pr[(int) DISP_OTHER] = NULL ;
  907.   XSync(dpy, 0) ;
  908. }
  909.  
  910.  
  911. start_tool()
  912. {
  913.   struct timeval tval ;          /* To set checking period. */
  914.   XEvent event ;                 /* For events received. */
  915.   XClientMessageEvent *ev ;
  916.   XKeyPressedEvent *key_event ;
  917.   char chs[2] ;
  918.  
  919.   tval.tv_usec = 0 ;
  920.   tval.tv_sec = period ;
  921.  
  922.   for (;;)
  923.     {
  924.       readmask = fullmask ;
  925. #ifdef NO_43SELECT
  926.       SELECT(32, &readmask, 0, 0, &tval) ;
  927.       if (readmask && (1 << xfd))
  928. #else
  929.       SELECT(FD_SETSIZE, &readmask, (fd_set *) 0, (fd_set *) 0, &tval) ;
  930.       if (FD_ISSET(xfd, &readmask))
  931. #endif /*NO_43SELECT*/
  932.         do
  933.           {
  934.             XNextEvent(dpy, &event) ;
  935.  
  936. /* ClientMessage: (catch ICCCM kill from WM). */
  937.  
  938.             if (event.type == ClientMessage)
  939.               {
  940.                 ev = (XClientMessageEvent *) &event ;
  941.                 if (ev->message_type == protocol_atom &&
  942.                   ev->data.l[0] == kill_atom)
  943.                 exit(0) ;
  944.               }
  945.  
  946. /* Expose. */
  947.  
  948.             else if (event.type == Expose && event.xexpose.count == 0)
  949.               {
  950.                 while (XCheckTypedEvent(dpy, Expose, &event)) /* do nothing. */ ;
  951.                 XCopyArea(dpy, pr[(int) wdtype],
  952.                           frame[F_WINDOW], gc, 0, 0,
  953.                           (unsigned int) width, (unsigned int) height, 0, 0) ;
  954.                 XCopyArea(dpy, pr[(int) DISP_ICON],
  955.                           frame[F_ICON], gc, 0, 0,
  956.                           (unsigned int) width, (unsigned int) height, 0, 0) ;
  957.               }
  958.  
  959. /* ButtonPress. */
  960.  
  961.             else if (event.type == ButtonPress        &&
  962.                      event.xbutton.button == Button1)
  963.               {
  964.                 wdtype = (wdtype == DISP_NAME) ? DISP_OTHER : DISP_NAME ;
  965.                 XCopyArea(dpy, pr[(int) wdtype],
  966.                           frame[F_WINDOW], gc, 0, 0,
  967.                           (unsigned int) width, (unsigned int) height, 0, 0) ;
  968.               }
  969.  
  970. /* KeyPress. */
  971.  
  972.             else if (mtype == MONNEW && event.type == KeyPress)
  973.               {
  974.                 key_event = (XKeyPressedEvent *) &event ;
  975.                 (void) XLookupString(key_event, chs, 1, (KeySym *) NULL,
  976.                                      (XComposeStatus *) NULL) ;
  977.                 if (chs[0] == DEL)
  978.                   {
  979.                     repl_image(DISP_NAME,  CUROFF, width, height) ;
  980.                     repl_image(DISP_OTHER, CUROFF, width, height) ;
  981.                     toclear = 1 ;
  982.                     do_check() ;
  983.                   }
  984.               }
  985.           }
  986.         while (XPending(dpy)) ;
  987.       else do_check() ;     /* Check the mail/printer/user queue again. */
  988.     }
  989. }
  990.  
  991.  
  992. text(dtype, jtype, str)
  993. enum disp_type dtype ;
  994. enum just_type jtype ;
  995. char *str ;
  996. {
  997.   int len ;
  998.   int c, r ;         /* Column and row position for this face. */
  999.   int x, y ;         /* Position of start of this text string. */
  1000.  
  1001.   c = column ;
  1002.   r = row ;
  1003.   switch (dtype)
  1004.     {
  1005.       case DISP_ALL    : text(DISP_ICON,  jtype, str) ;
  1006.       case DISP_BOTH   : text(DISP_NAME,  jtype, str) ;
  1007.                          text(DISP_OTHER, jtype, str) ;
  1008.                          return ;
  1009.       case DISP_ICON   : c = r = 0 ;
  1010.     }
  1011.  
  1012.   if ((len = strlen(str)) > 10)     /* Character length of text. */
  1013.     {
  1014.       len = 10 ;
  1015.       str[10] = '\0' ;              /* Maximum of 10 characters. */
  1016.     }
  1017.   switch (jtype)
  1018.     {
  1019.       case LEFT  : x =  c      * imagewidth + 2 ;
  1020.                    y = (r + 1) * imageheight - 5 ;
  1021.                    break ;
  1022.       case RIGHT : x = (c + 1) * imagewidth - (len * 6) - 2 ;
  1023.                    y = (r + 1) * imageheight - 5 ;
  1024.     }
  1025.   XSetFunction(dpy, gc, GXandInverted) ;
  1026.   XFillRectangle(dpy, pr[(int) dtype], gc, x, y-9, (unsigned int) len*6+2, 13) ;
  1027.   XSetFunction(dpy, gc, GXxor) ;
  1028.   XDrawImageString(dpy, pr[(int) dtype], gc, x, y, str, strlen(str)) ;
  1029.   XSetFunction(dpy, gc, GXcopy) ;
  1030. }
  1031. Funky_Stuff
  1032. len=`wc -c < x11.c`
  1033. if [ $len !=    16665 ] ; then
  1034. echo error: x11.c was $len bytes long, should have been    16665
  1035. fi
  1036. fi # end of overwriting check
  1037. if [ -f extern.h ]
  1038. then
  1039. echo shar: will not over-write existing file extern.h
  1040. else
  1041. echo shar: extracting 'extern.h',     5702 characters
  1042. cat > extern.h <<'Funky_Stuff'
  1043.  
  1044. /*  @(#)extern.h 1.13 90/06/26
  1045.  *
  1046.  *  Contains the external variable definitions used by faces.
  1047.  *
  1048.  *  Copyright (c) Rich Burridge.
  1049.  *                Sun Microsystems, Australia - All rights reserved.
  1050.  *
  1051.  *  Permission is given to distribute these sources, as long as the
  1052.  *  copyright messages are not removed, and no monies are exchanged. 
  1053.  *
  1054.  *  No responsibility is taken for any errors or inaccuracies inherent
  1055.  *  either to the comments or the code of this program, but if
  1056.  *  reported to me then an attempt will be made to fix them.
  1057.  */
  1058.  
  1059. extern char *getname(), *strlower() ;
  1060. extern int do_check() ;
  1061. struct recinfo *rec_exists() ;
  1062.  
  1063. extern struct comminfo *communities ;  /* Community alias/username chain. */
  1064. extern struct comminfo *clast ;        /* End of chain of community records. */
  1065. extern struct machinfo *machines ;     /* Known machine/communities. */
  1066. extern struct machinfo *mlast ;        /* End of chain of machine records. */
  1067. extern struct psinfo *psrecs ;   /* List of news.ps animation files. */
  1068. extern struct psinfo *plast ;    /* End of chain of NeWS animation files. */
  1069. extern struct recinfo *recs ;    /* Mail messages being monitored. */
  1070. extern struct recinfo *last ;    /* End of the chain of mail records. */
  1071. extern struct stat buf ;         /* Buffer for stat call for file existence. */
  1072. extern long lastsize ;           /* Last known size of the mail folder. */
  1073.  
  1074. extern enum disp_type wdtype ;   /* Current window display option. */
  1075. extern enum gr_type gtype ;  /* Indicates what graphics system is being used. */
  1076. extern enum mon_type mtype ; /* What type of monitoring we should do. */
  1077.  
  1078. extern char bgicon[] ;     /* Alternate background pattern. */
  1079. extern char community[] ;  /* Community name ("real" host name). */
  1080. extern char defdir[] ;     /* The default face directory. */
  1081. extern char display[] ;    /* X11 display information. */
  1082. extern char face_buf[] ;   /* Buffer for "X-Face" face images. */
  1083. extern char face_host[] ;  /* Pointer to host name from the "From" line. */
  1084. extern char face_ts[] ;    /* Pointer to time stamp from the "From" line. */
  1085. extern char face_user[] ;  /* Pointer to user name from the "From" line. */
  1086. extern char facedir[] ;    /* Alternate face image directory. */
  1087. extern char fname[MAXTYPES][MAXLINE] ;  /* Array of various face name types. */
  1088. extern char geometry[] ;   /* X11 geometry information. */
  1089. extern char hostname[] ;   /* Machine name to monitor. */
  1090. extern char iconname[] ;   /* Name of the icon file for this person. */
  1091. extern char line[] ;       /* Next line from users mail spool file. */
  1092. extern char machfile[] ;   /* Name of the machine/community file. */
  1093. extern char nextline[] ;   /* Input/conversion buffer for various routines. */
  1094. extern char peopfile[] ;   /* Name of the people/username file. */
  1095. extern char printer[] ;    /* Printer name to monitor. */
  1096. extern char progname[] ;   /* Name of this program. */
  1097. extern char realname[] ;   /* Real username for this user. */
  1098. extern char revtable[] ;   /* Table for reversing the bits in a byte. */
  1099. extern char spoolfile[] ;  /* Full pathname of users current mail. */
  1100. extern char update_alias[] ;   /* Name of mail alias for database updates. */
  1101. extern char userprog[] ;   /* User supplied program to run. */
  1102.  
  1103. extern int beeps ;         /* Number of beeps for arrival of new mail. */
  1104. extern int column ;        /* Column number for next icon. */
  1105. extern int doing_xface ;   /* Set if we've started to process an X-Face: */
  1106. extern int dontshowno ;    /* Set if no. of messages shouldn't  be shown. */
  1107. extern int dontshowtime ;  /* Set if timestamp shouldn't be shown. */
  1108. extern int dontshowuser ;  /* Set if username shouldn't be shown. */
  1109. extern int facetype ;      /* Type of face file found. */
  1110. extern int firsttime ;     /* Zeroised after first mail/printer check. */
  1111. extern int flashes ;       /* Number of flashes for arrival of new mail. */
  1112. extern int found ;         /* Set if iconname found under username directory. */
  1113. extern int fromc_found ;   /* Set if "From:" line found during processing. */
  1114. extern int froms_found ;   /* Set if "From " line found during processing. */
  1115. extern int height ;        /* Height in pixels of faces display. */
  1116. extern int iconheight ;    /* Height of an individual icon. */
  1117. extern int iconwidth ;     /* Width of an individual icon. */
  1118. extern int iconic ;        /* Start as an icon if set. */
  1119. extern int imageheight ;   /* Height of an individual face image. */
  1120. extern int imagewidth ;    /* Width of an individual face image. */
  1121. extern int invert ;        /* Set if to use reverse video. */
  1122. extern int ix ;            /* Initial X position of the icon. */
  1123. extern int iy ;            /* Initial Y position of the icon. */
  1124. extern int maxcols ;       /* Maximum number of columns to display. */
  1125. extern int maxtypes ;      /* Max. no. of icon types for graphics target. */
  1126. extern int mhflag ;        /* Set if this user uses MH to read mail. */
  1127. extern int newmail ;       /* Set if there is new mail this time around. */
  1128. extern int noicons ;       /* Number of faces this time around. */
  1129. extern int old_style ;     /* Set when "old" style face ikon is found. */
  1130. extern int period ;        /* Period in seconds for checking new mail. */
  1131. extern int posspec ;       /* Set if -Wp or -g option is present (for X11) */
  1132. extern int row ;           /* Row number for next icon. */
  1133. extern int update ;        /* If set, send mail to update faces database. */
  1134. extern int width ;         /* Width in pixels of faces display. */
  1135. extern int wx ;            /* Initial X position of the window. */
  1136. extern int wy ;            /* Initial Y position of the window. */
  1137. extern int x_face ;        /* Set if we've extracted an "on-the-fly" face. */
  1138. Funky_Stuff
  1139. len=`wc -c < extern.h`
  1140. if [ $len !=     5702 ] ; then
  1141. echo error: extern.h was $len bytes long, should have been     5702
  1142. fi
  1143. fi # end of overwriting check
  1144. if [ -f faces.h ]
  1145. then
  1146. echo shar: will not over-write existing file faces.h
  1147. else
  1148. echo shar: extracting 'faces.h',     6241 characters
  1149. cat > faces.h <<'Funky_Stuff'
  1150.  
  1151. /*  @(#)faces.h 1.14 90/06/26
  1152.  *
  1153.  *  Contains all the global definitions used by faces.
  1154.  *
  1155.  *  Copyright (c) Rich Burridge - Sun Microsystems Australia.
  1156.  *                                All rights reserved.
  1157.  *
  1158.  *  Permission is given to distribute these sources, as long as the
  1159.  *  copyright messages are not removed, and no monies are exchanged. 
  1160.  *
  1161.  *  No responsibility is taken for any errors or inaccuracies inherent
  1162.  *  either to the comments or the code of this program, but if
  1163.  *  reported to me then an attempt will be made to fix them.
  1164.  */
  1165.  
  1166. #define  FCLOSE        (void) fclose      /* To make lint happy. */
  1167. #define  FFLUSH        (void) fflush
  1168. #define  FGETS         (void) fgets
  1169. #define  FPRINTF       (void) fprintf
  1170. #define  FPUTS         (void) fputs
  1171. #define  FSEEK         (void) fseek
  1172. #define  GETHOSTNAME   (void) gethostname
  1173. #define  GET_SUN_ICON  (void) get_sun_icon
  1174. #define  IOCTL         (void) ioctl
  1175. #define  PCLOSE        (void) pclose
  1176. #define  PUTC          (void) putc
  1177. #define  SELECT        (void) select
  1178. #define  SSCANF        (void) sscanf
  1179. #define  SPRINTF       (void) sprintf
  1180. #define  STRCAT        (void) strcat
  1181. #define  STRCPY        (void) strcpy
  1182. #define  STRNCAT       (void) strncat
  1183. #define  STRNCPY       (void) strncpy
  1184. #define  UTIME         (void) utime
  1185. #define  WRITE         (void) write
  1186.  
  1187. /* Window display types. */
  1188. enum disp_type { DISP_NAME,      /* Window type 1. */
  1189.                  DISP_OTHER,     /* Window type 2. */
  1190.                  DISP_ICON,      /* Icon display. */
  1191.                  DISP_BOTH,      /* Both window types. */
  1192.                  DISP_ALL,       /* Both window types and the icon. */
  1193. } ;
  1194.  
  1195. /* Different types of possible face images. */
  1196. enum icon_type { BACKGROUND, NOFACE, NOMAIL, NOPAPER,
  1197.                  NOPRINT, NOUSERS, ORDINARY, XFACE } ;
  1198.  
  1199. enum image_type { ONSCREEN, OLDOFF, CUROFF } ;   /* Image types. */
  1200.  
  1201. enum just_type { LEFT, RIGHT } ;                 /* Text justification. */
  1202.  
  1203. /* Different types of file monitoring performed by this program. */
  1204. enum mon_type { MONALL, MONNEW, MONPRINTER, MONPROG, MONUSERS } ;
  1205.  
  1206. /* Different graphics systems. Appropriate one set in gtype. */
  1207. enum gr_type { NEWS, SVIEW, X11, XVIEW } ;
  1208.  
  1209. /* Determine order for face type lookup. */
  1210. #define  NEWSTYPE        0
  1211. #define  SUNTYPE         1
  1212. #define  BLITTYPE        2
  1213. #define  X11TYPE         3
  1214.  
  1215. /* NeWS return event values. */
  1216. #define  DIED            100  /* Faces has been zapped. */
  1217. #define  PAINTED         101  /* Canvas/Icon needs repainting. */
  1218. #define  LEFTDOWN        102  /* Left mouse button has been pressed. */
  1219.  
  1220. #define  BLITHEIGHT      48       /* Maximum number of lines in a blit icon. */
  1221. #define  DEL             '\177'   /* Clear faces display. */
  1222. #define  EQUAL(str,val)  !strncmp(str,val,strlen(val))
  1223. #define  ICONHEIGHT      64   /* Default height of individual face icons. */
  1224. #define  ICONWIDTH       64   /* Default width of individual face icons. */
  1225. #define  INC             argc-- ; argv++ ;
  1226.  
  1227. #ifndef  LINT_CAST
  1228. #ifdef   lint
  1229. #define  LINT_CAST(arg)  (arg ? 0 : 0)
  1230. #else
  1231. #define  LINT_CAST(arg)  (arg)
  1232. #endif /*lint*/
  1233. #endif /*LINT_CAST*/
  1234.  
  1235. #define  MAXICONS        8    /* Maximum number of different icon types. */
  1236. #define  MAXITYPES       3    /* Maximum number of image types. */
  1237.  
  1238. #ifndef  MAXLINE
  1239. #define  MAXLINE         200  /* Maximum length for character strings. */
  1240. #endif   MAXLINE
  1241.  
  1242. #define  MAXTYPES        4    /* Maximum number of different face types. */
  1243. #define  NO_PER_ROW      10   /* Default number of faces per row. */
  1244.  
  1245. #ifdef  NOINDEX
  1246. #define  index        strchr
  1247. #define  rindex       strrchr
  1248. #endif /*NOINDEX*/
  1249.  
  1250. char *getenv(), *malloc(), *sprintf() ;
  1251. void endpwent() ;
  1252. FILE *popen() ;
  1253.  
  1254. /*  Various programs that are used by faces.
  1255.  *  You might need to change these on some machines.
  1256.  */
  1257.  
  1258. /* Monitoring the printer:        %s replaced by printer name. */
  1259. #define  PRINTDEF   "lpq -P %s"
  1260.  
  1261. /* Updating the faces database:   %s replaced with mail update alias name. */
  1262. #define  UPDATEDEF  "/usr/lib/sendmail -oeq -oi %s"
  1263.  
  1264. /* Monitoring users on a machine: %s replaced with hostname. */
  1265. #define  USERSDEF   "rusers -l %s"
  1266.  
  1267. /* Default definitions used by faces. They can be globally changed here. */
  1268.  
  1269. #define  MACHINETAB    "machine.tab"   /* Machine aliases table. */
  1270. #define  PEOPLETAB     "people.tab"    /* Username aliases table. */
  1271. #define  UPDATE_ALIAS  "facemaker"     /* Faces database update alias. */
  1272.  
  1273. struct machinfo                 /* Machine/community record. */
  1274.   {
  1275.     char *machine ;             /* Machine name. */
  1276.     char *community ;           /* Community it belongs to. */
  1277.     struct machinfo *next ;     /* Pointer to next record. */
  1278.   } ;
  1279.  
  1280. struct comminfo                 /* Community alias/username records. */
  1281.   {
  1282.     char *community ;           /* Community name. */
  1283.     struct peopinfo *people ;   /* Chain of alias/usernames. */
  1284.     struct comminfo *next ;     /* Pointer to next record. */
  1285.   } ;
  1286.  
  1287. struct peopinfo                 /* Username/alias record. */
  1288.   {
  1289.     char *alias ;               /* Alias for this user. */
  1290.     char *username ;            /* Real username. */
  1291.     struct peopinfo *next ;     /* Pointer to next record. */
  1292.   } ;
  1293.  
  1294. struct psinfo                   /* News.ps animation records. */
  1295.   {
  1296.     char *name ;                /* Full pathname of news.ps file. */
  1297.     int row ;                   /* Row number where animation will occur. */
  1298.     int column ;                /* Column number where animation will occur. */
  1299.     struct psinfo *next ;       /* Pointer to next record. */
  1300.   } ;
  1301.  
  1302. struct recinfo                  /* Mail/print information record. */
  1303.   {
  1304.     char *community ;           /* Community name for this person. */
  1305.     unsigned char *faceimage ;  /* X-Face image or NULL. */
  1306.     char *iconname ;            /* Name of iconfile for this person. */
  1307.     char *username ;            /* User name for this person. */
  1308.     int total ;                 /* Total number of messages/print jobs. */
  1309.     int size ;                  /* Total size in bytes of print job. */
  1310.     int update ;                /* If set, the database has been updated. */
  1311.     char ts[6] ;                /* Latest timestamp for this user. */
  1312.     struct recinfo *next ;      /* Pointer to next record. */
  1313.   } ;
  1314. Funky_Stuff
  1315. len=`wc -c < faces.h`
  1316. if [ $len !=     6241 ] ; then
  1317. echo error: faces.h was $len bytes long, should have been     6241
  1318. fi
  1319. fi # end of overwriting check
  1320. if [ -f patchlevel.h ]
  1321. then
  1322. echo shar: will not over-write existing file patchlevel.h
  1323. else
  1324. echo shar: extracting 'patchlevel.h',      561 characters
  1325. cat > patchlevel.h <<'Funky_Stuff'
  1326.  
  1327. /*  @(#)patchlevel.h 1.20 90/06/29
  1328.  *
  1329.  *  This is the current patch level for this version of faces.
  1330.  *
  1331.  *  Copyright (c) Rich Burridge.
  1332.  *        Sun Microsystems, Australia - All rights reserved.
  1333.  *
  1334.  *  Permission is given to distribute these sources, as long as the
  1335.  *  copyright messages are not removed, and no monies are exchanged. 
  1336.  *
  1337.  *  No responsibility is taken for any errors or inaccuracies inherent
  1338.  *  either to the comments or the code of this program, but if
  1339.  *  reported to me then an attempt will be made to fix them.
  1340.  */
  1341.  
  1342. #define  PATCHLEVEL  5
  1343. Funky_Stuff
  1344. len=`wc -c < patchlevel.h`
  1345. if [ $len !=      561 ] ; then
  1346. echo error: patchlevel.h was $len bytes long, should have been      561
  1347. fi
  1348. fi # end of overwriting check
  1349.  
  1350.