home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2055 / xlpr.c < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.1 KB  |  61 lines

  1. #include <X11/Intrinsic.h>
  2. #include <X11/StringDefs.h>
  3. #include <X11/Xatom.h>
  4. #include <stdio.h>
  5. #include "copyright.h"
  6.  
  7. static Widget toplevel;
  8.  
  9. main (argc, argv)
  10. int    argc;
  11. char    *argv[];
  12. {
  13.     void clipboard();
  14.     Window window;
  15.     Arg args[10];
  16.     int i;
  17.  
  18.     toplevel = XtInitialize(NULL, "xlpr", NULL, 0, &argc, argv);
  19.     XtSetMappedWhenManaged(toplevel, False);
  20.  
  21.     i = 0;
  22.     XtSetArg(args[i], XtNwidth, 100); i++;
  23.     XtSetArg(args[i], XtNheight, 100); i++;
  24.     XtSetValues(toplevel, args, i);
  25.  
  26.     XtRealizeWidget(toplevel);
  27.  
  28.     XtGetSelectionValue(toplevel,
  29.         XInternAtom(XtDisplay(toplevel), "CLIPBOARD", False),
  30.         XA_STRING, clipboard, NULL, CurrentTime);
  31.  
  32.     XtMainLoop();
  33. }
  34.  
  35. void clipboard(w, client_data, selection, type, buf, length, format)
  36. Widget w;
  37. XtPointer client_data;
  38. Atom *selection;
  39. Atom *type;
  40. XtPointer buf;
  41. unsigned long *length;
  42. int *format;
  43. {
  44.     FILE *fp;
  45.  
  46.     if (*type == XT_CONVERT_FAIL || *length <= 0)
  47.         return;
  48.  
  49.     fp = popen("/usr/ucb/lpr", "w");
  50.     if (fp == NULL) {
  51.         perror("xlpr: could not open pipe to /usr/ucb/lpr");
  52.     } else {
  53.         fputs (buf, fp);
  54.         pclose(fp);
  55.     }
  56.  
  57.     XtFree (buf);
  58.     XtDestroyApplicationContext(XtWidgetToApplicationContext(toplevel));
  59.     exit (0);
  60. }
  61.