/* get-pixmap --- given a pixmap ID, show its contents as an XPM. Copyright © 1998, 2000 Jamie Zawinski Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. cc -o get-pixmap get-pixmap.c -lXpm -lX11 */ #include #include #include #include #include #define USAGE "usage: %s -id pixmap_id\n" void main (argc, argv) int argc; char **argv; { Display *dpy; XpmAttributes attrs; char *buffer = 0; Pixmap pixmap = 0; int result; int i; for (i = 1; i < argc; i++) { if (!strcmp (argv[i], "-id") && i != argc-1) { unsigned int n; char c; i++; if ((1 != sscanf (argv[i], " %d %c", &n, &c)) && (1 != sscanf (argv[i], " 0x%x %c", &n, &c))) { fprintf (stderr, "%s: pixmap id %s unparsable\n", argv[0], argv[i]); exit (1); } pixmap = (Pixmap) n; } else { fprintf (stderr, USAGE, argv[0]); exit (1); } } if (! pixmap) { fprintf (stderr, USAGE, argv[0]); exit (1); } dpy = XOpenDisplay (0); memset (&attrs, 0, sizeof (attrs)); result = XpmCreateBufferFromPixmap (dpy, &buffer, pixmap, 0, /* shapemask */ &attrs); switch (result) { case XpmSuccess: fprintf (stdout, "%s\n", buffer); break; default: fprintf (stderr, "%s: xpm error %d\n", argv[0], result); exit (-1); break; } exit (0); }