home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1715 < prev    next >
Encoding:
Text File  |  1990-12-28  |  82.6 KB  |  2,680 lines

  1. Newsgroups: alt.sources
  2. From: lehors@modja.inria.fr (Arnaud Le Hors)
  3. Subject: [xpert] XPM2 The new XPM version (source files).
  4. Message-ID: <1990Aug25.221607.11150@math.lsa.umich.edu>
  5. Date: Sat, 25 Aug 90 22:16:07 GMT
  6.  
  7. Archive-name: xpm2/25-Aug-90
  8. Original-posting-by: lehors@modja.inria.fr (Arnaud Le Hors)
  9. Original-subject: XPM2 The new XPM version (source files).
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.windows.x.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. Here goes the first  distribution of the new version of XPM.
  16.  
  17. XPM (X PixMap) is a format for storing/retrieving X pixmaps to/from ascii 
  18. files. 
  19.  
  20. Here is provided a library containing a set of three functions, similar to the
  21. X bitmap functions as defined in the Xlib: XCreatePixmapFromData,
  22. XReadPixmapFile and XWritePixmapFile for respectively including, reading and
  23. writing this format.
  24.  
  25. This new version provides different types of format: a natural one which will
  26. be preferably used for manual editing (with emacs, vi, ...), a C includable
  27. format and a Lisp includable format. It provides defaults for different types
  28. of display: monochrome/color/grayscale, and symbol names for colors for
  29. overriding default colors when creating the pixmap. Finally it provides a
  30. structure for storing information while reading a file which is re-used while
  31. writing. This way comments, default colors and symbol names aren't lost.
  32.  
  33. Follows the shar file containing all the source files needed for building the 
  34. XPM2 library, the manual (xpm.tex file), and a demo.
  35.  
  36. I hope this will be useful to you. Please let me know your feelings.
  37.  
  38. --
  39.    Arnaud LE HORS
  40.    BULL Research FRANCE -- Koala Project   |    Email : lehors@mirsa.inria.fr
  41.          Inria - Sophia Antipolis          |    Phone : (33) 93 65 77 71
  42.          2004, Route des Lucioles          |    Telex :      97 00 50 F
  43.          06565 Valbonne CEDEX  France      |    Fax   : (33) 93 65 77 66
  44.  
  45. --
  46. #!/bin/sh
  47. # This is a shell archive. To unpack its contents, do "sh <this-file>"
  48. cat > COPYRIGHT << \END_OF_SHAR_FOR_COPYRIGHT
  49. /*
  50.  * Copyright 1990 GROUPE BULL
  51.  *
  52.  * Permission to use, copy, modify, and distribute this software and its
  53.  * documentation for any purpose and without fee is hereby granted, provided
  54.  * that the above copyright notice appear in all copies and that both that
  55.  * copyright notice and this permission notice appear in supporting
  56.  * documentation, and that the name of GROUPE BULL not be used in advertising
  57.  * or publicity pertaining to distribution of the software without specific,
  58.  * written prior permission.  GROUPE BULL makes no representations about the
  59.  * suitability of this software for any purpose.  It is provided "as is"
  60.  * without express or implied warranty.
  61.  *
  62.  * GROUPE BULL disclaims all warranties with regard to this software,
  63.  * including all implied warranties of merchantability and fitness,
  64.  * in no event shall GROUPE BULL be liable for any special,
  65.  * indirect or consequential damages or any damages
  66.  * whatsoever resulting from loss of use, data or profits,
  67.  * whether in an action of contract, negligence or other tortious
  68.  * action, arising out of or in connection with the use 
  69.  * or performance of this software.
  70.  *
  71.  */
  72.  
  73. Arnaud LE HORS      BULL Research FRANCE -- Koala Project 
  74.                     (XPM2 - X PixMap format version 2)
  75.     Internet:       lehors@mirsa.inria.fr
  76. Surface Mail:       Arnaud LE HORS, INRIA - Sophia Antipolis, 
  77.                     2004, route des Lucioles, 06565 Valbonne Cedex -- FRANCE
  78.  Voice phone:       (33) 93.65.77.71, Fax: (33) 93 65 77 66, Telex: 97 00 50 F
  79. END_OF_SHAR_FOR_COPYRIGHT
  80. cat > Makefile << \END_OF_SHAR_FOR_Makefile
  81. # Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT
  82. #
  83. # XPM Makefile - Arnaud LE HORS
  84. # $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  85. #
  86.  
  87. AR = ar r
  88. CC = cc
  89. RANLIB = ranlib
  90. RM = rm -f
  91.  
  92. CFLAGS=
  93.  
  94. LIBDIRS= -L/usr/lib/X11 -L.
  95. LIBS= -lXPM2 -lX11
  96. OBJS= mio.o value.o create.o visual.o free.o XWrPixF.o XRdPixF.o XCrPFData.o
  97.  
  98. all: demo
  99.  
  100. clean: 
  101.     $(RM) *.o demo libXPM2.a
  102.  
  103. demo: libXPM2.a demo.o
  104.     $(CC) $(CFLAGS) demo.o $(LIBDIRS) $(LIBS) -o demo
  105.  
  106. libXPM2.a: $(OBJS)
  107.     $(AR) libXPM2.a $(OBJS)
  108.     $(RANLIB) libXPM2.a
  109. END_OF_SHAR_FOR_Makefile
  110. cat > README << \END_OF_SHAR_FOR_README
  111. $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  112.  
  113.                 XPM Version 2
  114.  
  115. WHAT IS XPM?
  116. ============
  117.  
  118. XPM (X PixMap) is a format for storing/retrieving X pixmaps to/from ascii
  119. files.
  120.  
  121. Here is provided a library containing a set of three functions, similar to the
  122. X bitmap functions as defined in the Xlib: XCreatePixmapFromData,
  123. XReadPixmapFile and XWritePixmapFile for respectively including, reading and
  124. writing this format.
  125.  
  126. This new version provides different types of format: a natural one which will
  127. be preferably used for manual editing (with emacs, vi, ...), a C includable
  128. format and a Lisp includable format. It provides defaults for different types
  129. of display: monochrome/color/grayscale, and symbol names for colors for
  130. overriding default colors when creating the pixmap. Finally it provides a
  131. structure for storing information while reading a file which is re-used while
  132. writing. This way comments, default colors and symbol names aren't lost.
  133.  
  134. See the XPM Manual for more details.
  135.  
  136. INSTALLATION:
  137. ============
  138.  
  139. To obtain the XPM library, first execute the shell archive file in an
  140. approriate directory. Then just do:
  141.  
  142.               make all 
  143.        or          make libxpm.a
  144.  
  145. NOTE:   if you compile  with gcc, use "gcc -traditional", otherwise you will
  146.         have compilation warnings (but the code will work Ok)
  147.  
  148. DEMO:
  149. ====
  150.  
  151. In addition to the library a demo is provided. If you have previously done 
  152. 'make all' you should have it yet, otherwise just do:
  153.  
  154.               make demo
  155.  
  156. This demo shows you all the features of XPM and the three provided functions.
  157.  
  158. By executing 'demo' without any option you will see a demo of the 
  159. XCreatePixmapFromData function. The pixmap is created from the static variable
  160. plaid defined in the demo.c file. Demo will end when you click in the created
  161. window.
  162.  
  163. Executing 'demo -s lines_in_mix blue' will show the feature of color symbols.
  164.  
  165. Then you should try 'demo -o output' to get an output file using the
  166. XWritePixmapFile function. This is a natural type format file, other types can
  167. be obtained by adding the option '-t C' or '-t Lisp'.
  168.  
  169. To end you should try 'demo -i plaid' or 'demo -i plaid_c' or 
  170. 'demo -i plaid_ll' to use the XReadPixmapFile function.
  171.  
  172. Of course, other combinations are allowed and should be tried. Thus, 
  173. 'demo -i plaid -o output -t C' will show you how a natural type format is
  174. translated to a C type format.
  175.  
  176. The XCreatePixmapFromData function is on purpose called without any Xpminfo 
  177. pointer to show the utility of this one. Indeed, compare the color section of
  178. the two files foo and bar obtained from 'demo -o foo' and 
  179. 'demo -i plaid -o bar'.
  180.  
  181. KNOWN BUG:
  182. =========
  183.  
  184. XWritePixmapFile:
  185. Writing out multilines comment to a single line comment is not handled. Thus,
  186. translating a C multilines comment to Lisp will result to an invalid file.
  187.  
  188. DISCUSSION:
  189. ==========
  190.  
  191. Any discussion should be made on the comp.windows.x newsgroup. The subject
  192. line will preferably begin by the word XPM.
  193.  
  194. COPYRIGHT:
  195. ==========
  196.  
  197.   Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT
  198.   See the COPYRIGHT file in the XPM distribution
  199.  
  200. Please mail any bug reports or modifications done, comments, suggestions,
  201. requests for updates or patches to port on another machine to:
  202.  
  203. lehors@mirsa.inria.fr        (INTERNET)
  204.  
  205. 33 (FRANCE) 93.65.77.71        (VOICE PHONE)
  206.  
  207. Arnaud Le Hors            (SURFACE MAIL)
  208. INRIA
  209. 2004, Route des lucioles
  210. Sophia Antipolis
  211. 06565 VALBONNE
  212. FRANCE
  213. END_OF_SHAR_FOR_README
  214. cat > XCrPFData.c << \END_OF_SHAR_FOR_XCrPFData.c
  215. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  216. /* XCrPFData.c:
  217.  *
  218.  *  XPM2
  219.  *  Create from Data utility for XPM2 file format
  220.  *  Developped by Arnaud Le Hors
  221.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  222.  */
  223.  
  224. #include "xpmP.h"
  225.  
  226. int XCreatePixmapFromData(display, visual, d, colormap, data, depth,
  227.               pixmap_return, width_return, height_return, 
  228.               pixels_return, npixels_return,
  229.               colorsymbols, numsymbols, infos)
  230.      Display *display;
  231.      Visual *visual;
  232.      Drawable d;
  233.      Colormap colormap;
  234.      char **data;
  235.      unsigned int depth;
  236.      Pixmap *pixmap_return;
  237.      unsigned int *width_return, *height_return, *npixels_return;
  238.      Pixel **pixels_return;
  239.      ColorSymbol colorsymbols[];
  240.      unsigned int numsymbols;
  241.      XpmInfo *infos;
  242.  
  243. { MData *mdata;
  244.  
  245.   *width_return = *height_return = 0;
  246.   if (! (mdata = (MData *)malloc(sizeof(MData)))) { 
  247.       XpmErrorStatus = PixmapNoMemory;
  248.       return(NULL);
  249.   }
  250.   mdata->type = MARRAY;
  251.   mdata->stream = (void*) data;
  252.   mdata->cptr = *data;
  253.   mdata->line = 0;
  254.   XpmErrorStatus = PixmapSuccess;
  255.   *pixmap_return = CreatePixmap(display, visual, d, colormap, mdata, depth,
  256.                 width_return, height_return, 
  257.                 pixels_return, npixels_return,
  258.                 colorsymbols, numsymbols, infos);
  259.   free(mdata);
  260.   return(XpmErrorStatus);
  261. }
  262. END_OF_SHAR_FOR_XCrPFData.c
  263. cat > XRdPixF.c << \END_OF_SHAR_FOR_XRdPixF.c
  264. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  265. /* XRdPixF.c:
  266.  *
  267.  *  XPM2
  268.  *  Read utility for XPM2 file format
  269.  *  Developped by Arnaud Le Hors
  270.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  271.  */
  272.  
  273. #include "xpmP.h"
  274.  
  275. int XReadPixmapFile(display, visual, d, colormap, filename, depth, 
  276.             pixmap_return, width_return, height_return, 
  277.             pixels_return, npixels_return,
  278.             colorsymbols, numsymbols, infos)
  279.      Display *display;
  280.      Visual *visual;
  281.      Drawable d;
  282.      Colormap colormap;
  283.      char *filename;
  284.      unsigned int depth;
  285.      Pixmap *pixmap_return;
  286.      unsigned int *width_return, *height_return, *npixels_return;
  287.      Pixel **pixels_return;
  288.      ColorSymbol colorsymbols[];
  289.      unsigned int numsymbols;
  290.      XpmInfo *infos;
  291.  
  292. { MData *mdata;
  293.   char buf[BUFSIZ];
  294.   int l, n = 0;
  295.  
  296.   *pixmap_return = NULL;
  297.   *width_return = *height_return = 0;
  298.   XpmErrorStatus = PixmapSuccess;
  299.  
  300.   if (! (mdata = (MData *)malloc(sizeof(MData)))) {
  301.       return(XpmErrorStatus = PixmapNoMemory);
  302.   }
  303.   mdata->type = MFILE;
  304.   if (! (mdata->stream = (void*) fopen(filename, "r"))) {
  305.       free(mdata);
  306.       return(XpmErrorStatus = PixmapOpenFailed);
  307.   }
  308.   mdata->cptr = NULL;
  309.   mdata->line = 0;
  310.  
  311.   /* parse the header file
  312.    */
  313.   BOS = '\0';
  314.   EOS = '\n';
  315.   BCMT = ECMT = NULL;
  316.   l = mnextw(mdata, buf);    /* skip the first word */
  317.   l = mnextw(mdata, buf);    /* then get the second word */
  318.   if (l == 4 && !strncmp("XPM2", buf, 4)) {
  319.       l = mnextw(mdata, buf);    /* get the type key word */
  320.  
  321.      /* get infos about this type
  322.        */
  323.       while (DataTypes[n].type && strncmp(DataTypes[n].type, buf, l)) n++;
  324.       if (DataTypes[n].type) {
  325.       if (infos) {
  326.           infos->type = (char *) malloc(l+1);
  327.           strncpy(infos->type, buf, l);
  328.           infos->type[l] = '\0';
  329.       }
  330.       if (n == 0) {        /* natural type */
  331.           BCMT = DataTypes[n].Bcmt;
  332.           ECMT = DataTypes[n].Ecmt;
  333.           mnextstring(mdata);    /* skip the end of headerline */
  334.           BOS = DataTypes[n].Bos;
  335.       } else {
  336.           mnextstring(mdata);    /* skip the end of headerline */
  337.           BCMT = DataTypes[n].Bcmt;
  338.           ECMT = DataTypes[n].Ecmt;
  339.           BOS = DataTypes[n].Bos;
  340.           mnextstring(mdata);    /* skip the assignment line */
  341.       }
  342.       EOS = DataTypes[n].Eos;
  343.  
  344.       *pixmap_return = CreatePixmap(display, visual, d, colormap, mdata,
  345.                     depth, width_return, height_return,
  346.                     pixels_return, npixels_return,
  347.                     colorsymbols, numsymbols, infos);
  348.       } else {
  349.       XpmErrorStatus = PixmapFileInvalid;
  350.       }
  351.   } else {
  352.       XpmErrorStatus = PixmapFileInvalid;
  353.   }
  354.   fclose((FILE *) mdata->stream);
  355.   free(mdata);
  356.   return(XpmErrorStatus);
  357. }
  358. END_OF_SHAR_FOR_XRdPixF.c
  359. cat > XWrPixF.c << \END_OF_SHAR_FOR_XWrPixF.c
  360. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  361. /*
  362.  *  XPM2
  363.  *  Write utility for XPM2 file format
  364.  *  Developped by Arnaud Le Hors
  365.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  366.  */
  367.  
  368. #include "xpmP.h"
  369. #include <strings.h>
  370.  
  371. #undef RETURN
  372. #define RETURN(status) \
  373.   { if (index) free(index); \
  374.     if (colorStrings) { \
  375.     for (a = 0; a < ncolors; a++) \
  376.         if (*(colorStrings + a)) \
  377.         free(*(colorStrings + a)); \
  378.     free(colorStrings); \
  379.     } \
  380.     fclose(stream); \
  381.     return(XpmErrorStatus = status); }
  382.  
  383. int XWritePixmapFile(display, colormap, filename, pixmap, width, 
  384.              height, type, cppm, infos)
  385.      Display *display;
  386.      Colormap colormap;
  387.      char *filename;
  388.      Pixmap *pixmap;
  389.      unsigned int width, height;
  390.      char *type;
  391.      unsigned int cppm;
  392.      XpmInfo *infos;
  393.  
  394. { FILE *stream;
  395.   XImage *ximage = NULL;
  396.   unsigned int pixlen;        /* length of pixels */
  397.   unsigned int pixgap;        /* length of pixels gap */
  398.   byte *dptr;
  399.   Pixel *index = NULL;        /* index of different pixels */
  400.   unsigned int indexsize = 256;    /* should be enough most of the time */
  401.   XColor *xcolors;        /* used colors */
  402.   char **colorStrings = NULL;    /* character strings associated to colors */
  403.   unsigned int ncolors = 0;    /* number of colors */
  404.   unsigned int cpp;             /* chars per pixel */
  405.   char *name;
  406.   unsigned int a, b, c, x, y, n = 0, key;
  407.   Pixel pixel;
  408.  
  409.   if (! (stream = fopen(filename, "w"))) {
  410.       return(XpmErrorStatus = PixmapOpenFailed);
  411.   }
  412.   XpmErrorStatus = PixmapSuccess;
  413.  
  414.   if (!(name = rindex(filename, '/')))
  415.     name = filename;
  416.   else
  417.     name++;
  418.  
  419.   if (!type)
  420.       if (infos && infos->type)
  421.       type = infos->type;
  422.       else
  423.       n = 0;        /* natural type */
  424.   if (n == 0 && type) {
  425.       while (DataTypes[n].type && strcmp(DataTypes[n].type, type)) n++;
  426.       if (! DataTypes[n].type)
  427.       return(XpmErrorStatus = PixmapFileInvalid);
  428.   }
  429.  
  430.  
  431.   /*
  432.    * read the image data
  433.    */
  434.  
  435.   ximage = XGetImage(display, pixmap, 0, 0, width, height, AllPlanes,
  436. ZPixmap);
  437.   pixlen = (ximage->bits_per_pixel / 8) + (ximage->bits_per_pixel % 8 ? 1 :
  438. 0);
  439.   pixgap = ximage->bytes_per_line - width;
  440.  
  441.   /* index the different pixels
  442.    */
  443.   if (! (index = (Pixel *)malloc(sizeof(Pixel) * indexsize)))
  444.       return(XpmErrorStatus = PixmapNoMemory);
  445.   dptr = (byte *)ximage->data;
  446.   for (y = 0; y < height; y++) {
  447.       for (x = 0; x < width; x++) {
  448.       pixel = memToVal(dptr, pixlen);
  449.       for (a = 0; a < ncolors; a++)
  450.           if (*(index + a) == pixel) break;
  451.       if (a == ncolors) {
  452.           if (ncolors > indexsize) {
  453.           indexsize *= 2;
  454.           if (! (index = (Pixel *)malloc(sizeof(Pixel) * indexsize)))
  455.               RETURN(PixmapNoMemory);
  456.           }
  457.           *(index + ncolors) = pixel;
  458.           ncolors++;
  459.       }
  460.       valToMem((unsigned long)a, dptr, pixlen);
  461.       dptr += pixlen;
  462.       }
  463.       for (b = 0; b < pixgap; b++) dptr += pixlen; /* skip extra pixels */
  464.   }
  465.  
  466.   /* get rgb values and a string of char for each color
  467.    */
  468.   if (! (xcolors = (XColor *) malloc(sizeof(XColor) * ncolors)))
  469.       RETURN(PixmapNoMemory);
  470.   if (! (colorStrings = (char **) calloc(ncolors, sizeof(char *))))
  471.       RETURN(PixmapNoMemory);
  472.  
  473.   for (cpp = 1, c = MAXPRINTABLE; ncolors > c; cpp++) c *= MAXPRINTABLE;
  474.   if (cpp < cppm) cpp = cppm;
  475.  
  476.   for (a = 0; a < ncolors; a++) {
  477.       if (! (*(colorStrings + a) = (char *)malloc(cpp)))
  478.       RETURN(PixmapNoMemory);
  479.       **(colorStrings + a) = printable[c = a % MAXPRINTABLE];
  480.       for (b = 1; b < cpp; b++)
  481.       *(*(colorStrings + a) + b) = 
  482.           printable[c = ((a - c) / MAXPRINTABLE) % MAXPRINTABLE];
  483.       (xcolors + a)->pixel = *(index + a);
  484.   }
  485.   XQueryColors(display, colormap, xcolors, ncolors);
  486.  
  487.  
  488.   /*
  489.    * print the pixmap file
  490.    */
  491.  
  492.   /* print the header line 
  493.    */
  494.   fprintf(stream, "%s XPM2 %s %s", DataTypes[n].Bcmt, DataTypes[n].type, 
  495.       DataTypes[n].Ecmt);
  496.   if (n != 0)            /* print the assignment line */
  497.       fprintf(stream, "%s %s %s", DataTypes[n].Dec, name, 
  498.           DataTypes[n].Boa);
  499.  
  500.   /* print the hints 
  501.    */
  502.   if (infos && infos->hints_cmt) /* print hints comment line */
  503.       fprintf(stream, "%s%s%s", DataTypes[n].Bcmt, 
  504.           infos->hints_cmt, DataTypes[n].Ecmt);
  505.  
  506.   if (DataTypes[n].Bos) fprintf(stream, "%c", DataTypes[n].Bos);
  507.   fprintf(stream, "%d %d %d %d", width, height, ncolors, cpp);
  508.   if (DataTypes[n].Eos) fprintf(stream, "%c", DataTypes[n].Eos);
  509.   fprintf(stream, DataTypes[n].Strs);
  510.  
  511.   /* print colors 
  512.    */
  513.   if (infos && infos->colors_cmt) /* print colors comment line */
  514.       fprintf(stream, "%s%s%s", DataTypes[n].Bcmt, 
  515.           infos->colors_cmt, DataTypes[n].Ecmt);
  516.  
  517.   for (a = 0; a < ncolors; a++) {
  518.       if (DataTypes[n].Bos) fprintf(stream, "%c", DataTypes[n].Bos);
  519.       for (b = 0; b < cpp; b++)
  520.       fprintf(stream, "%c", *(*(colorStrings + a) + b));
  521.       c = 1;
  522.       if (infos && infos->pixels) {
  523.       for (b = 0; b < infos->ncolors; b++)
  524.           if (*(infos->pixels + b) == (xcolors + a)->pixel)
  525.           break;
  526.       if (b != infos->ncolors) {
  527.           c = 0;
  528.           for (key = 1; key < NKEYS + 1; key++) {
  529.           if (*(*(infos->colorTable + b) + key))
  530.               fprintf(stream, "  %s %s", ColorKeys[key - 1], 
  531.                   *(*(infos->colorTable + b) + key));
  532.           }
  533.       }
  534.       }
  535.       if (c)
  536.           fprintf(stream, " c #%04X%04X%04X", (xcolors + a)->red, 
  537.               (xcolors + a)->green, (xcolors + a)->blue);
  538.       if (DataTypes[n].Eos) fprintf(stream, "%c", DataTypes[n].Eos);
  539.       fprintf(stream, DataTypes[n].Strs);
  540.   }
  541.  
  542.   /* print pixels
  543.    */
  544.   if (infos && infos->pixels_cmt) /* print pixels comment line */
  545.       fprintf(stream,  "%s%s%s", DataTypes[n].Bcmt, 
  546.           infos->pixels_cmt, DataTypes[n].Ecmt);
  547.  
  548.   dptr = (byte *)ximage->data;
  549.   for (y = 0; y < height; y++) {
  550.       if (DataTypes[n].Bos) fprintf(stream, "%c", DataTypes[n].Bos);
  551.       for (x = 0; x < width; x++) {
  552.       for (b = 0; b < cpp; b++) {
  553.           fprintf(stream, "%c", 
  554.               *(*(colorStrings + memToVal(dptr, pixlen)) + b));
  555.       }
  556.       dptr += pixlen;
  557.       }
  558.       if (DataTypes[n].Eos) fprintf(stream, "%c", DataTypes[n].Eos);
  559.       if (y < height - 1) 
  560.       fprintf(stream, DataTypes[n].Strs);
  561.       for (c = 0; c < pixgap; c++) dptr += pixlen; /* skip extra pixels */
  562.   }
  563.   fprintf(stream, DataTypes[n].Eoa);
  564.  
  565.   fclose(stream);
  566.   free(index);
  567.   for (a = 0; a < ncolors; a++)
  568.       free(*(colorStrings + a));
  569.   free(colorStrings);
  570.   free(xcolors);
  571.   return(XpmErrorStatus);
  572. }
  573. END_OF_SHAR_FOR_XWrPixF.c
  574. cat > colas.sty << \END_OF_SHAR_FOR_colas.sty
  575. % my add-on LaTeX macros
  576. % to be used like in:
  577. % \documentstyle[12pt,gwm]{report}
  578.  
  579. % postscript inclusion:
  580. \def\texpsfig#1#2#3
  581. {\vbox{\kern #3pt\hbox{\special{psfile=#1}\kern #2pt}}\typeout{(#1)}}
  582.  
  583. % RCS version stripping
  584. \def\RCSRevNum#1Revision: #2 ${#2}
  585. \def\RCSRevVersion#1Version: #2 ${#2}
  586.  
  587. \newlength{\colaslength}
  588. \newlength{\colaslengthh}
  589. \newlength{\colasmargin}
  590.  
  591. \def\exemplefont{\footnotesize}
  592. \def\usagefont{\large}
  593. \def\usageupspace{\vspace{0.1mm}}
  594. \newcommand{\Description}
  595.     {\list{}{\leftmargin 4cm \labelsep 0.1cm \labelwidth 3.9cm}}
  596.  
  597. \def\descriptionlabel#1{\bf #1\hspace\labelsep\hfil}
  598. \def\description
  599.     {\list{}{\leftmargin 2.4cm \labelsep 0.1cm \labelwidth 2.3cm
  600.     \let\makelabel\descriptionlabel}}
  601.  
  602. \def\upspace{\vspace{-2mm}}
  603. \def\undertablespace{\vspace{-3mm}}
  604.  
  605. \def\Item#1#2{\upspace\pagebreak[1]\section*{\hspace{-7pt}
  606.     {\large\tt#1}{\normalsize\sf\quad ---\quad #2}}\vspace{-0.3cm}}
  607.  
  608. \def\ITEMa#1#2{
  609.  \Item{#1}{#2}\markright{#1}
  610.  \label{#1}}
  611. \def\ITEMb#1#2#3{
  612.  \Item{\vbox{\hbox{#1}\hbox{#2}}}{#3}\markright{#1}
  613.  \label{#1} \label{#2}}
  614. \def\ITEMbi#1#2#3{
  615.  \Item{\vbox{\hbox{#1}\hbox{#2}}}{#3}\markright{#1}
  616.  \label{#2}}
  617. \def\ITEMc#1#2#3#4{
  618.  \Item{\vbox{\hbox{#1}\hbox{#2}\hbox{#3}}}{#4}\markright{#1}
  619.  \label{#1}\label{#2} \label{#3}}
  620. \def\ITEMci#1#2#3#4{
  621.  \Item{\vbox{\hbox{#1}\hbox{#2}\hbox{#3}}}{#4}\markright{#1}
  622.  \label{#2}\label{#3}}
  623. \def\ITEMd#1#2#3#4#5{
  624.  \Item{\vbox{\hbox{#1}\hbox{#2}\hbox{#3}\hbox{#4}}}{#5}\markright{#1}
  625.  \label{#1}\label{#2}\label{#3}\label{#4}}
  626. \def\ITEMe#1#2#3#4#5#6{
  627.  \Item{
  628.   \vbox{\hbox{#1}\hbox{#2}\hbox{#3}\hbox{#4}\hbox{#5}}}{#6}\markright{#1}
  629.  \label{#1}\label{#2}\label{#3}\label{#4}\label{#5}}
  630. \def\ITEMf#1#2#3#4#5#6#7{
  631.  \Item{
  632.     \vbox{\hbox{#1}\hbox{#2}\hbox{#3}\hbox{#4}\hbox{#5}\hbox{#6}}}{#7}
  633.     \markright{#1}
  634.  \label{#1}\label{#2}\label{#3}\label{#4}\label{#5}\label{#6}}
  635.  
  636. \newcommand{\context}[1]{
  637.   Context used:
  638.     \begin{center}\begin{tabular}{@{\tt}l@{\hspace{1cm}}@{\rm}p{7cm}}
  639.     \multicolumn{1}{c}{\bf Variable}&\multicolumn{1}{c}{\bf used for}\\ 
  640.     \hline \multicolumn{2}{l}{\undertablespace}\\
  641.     #1
  642.     \end{tabular}\end{center}}
  643.  
  644. \newcommand{\contextdim}[2]{
  645.   \setlength{\colaslength}{7cm}
  646.   \addtolength{\colaslength}{#1}
  647.   Context used:
  648.     \begin{center}\begin{tabular}{@{\tt}l@{\hspace{1cm}}@{\rm}p{\colaslength}}
  649.     \multicolumn{1}{c}{\bf Variable}&\multicolumn{1}{c}{\bf used for}\\ 
  650.     \hline  \multicolumn{2}{l}{\undertablespace}\\
  651.     #2
  652.     \end{tabular}\end{center}}
  653.  
  654. \newcommand{\desctable}[3]{
  655.     \begin{center}\begin{tabular}{@{\bf}l@{\hspace{1cm}}@{\rm}p{7cm}}
  656.     \multicolumn{1}{c}{\bf #1}&\multicolumn{1}{c}{\bf #2}\\ 
  657.     \hline \multicolumn{2}{l}{\undertablespace}\\
  658.     #3
  659.     \end{tabular}\end{center}}
  660.  
  661. \newcommand{\desctabledim}[4]{
  662.   \setlength{\colaslength}{7cm}
  663.   \addtolength{\colaslength}{#1}
  664.     \begin{center}\begin{tabular}{@{\bf}l@{\hspace{1cm}}@{\rm}p{\colaslength}}
  665.     \multicolumn{1}{c}{\bf #2}&\multicolumn{1}{c}{\bf #3}\\ 
  666.     \hline  \multicolumn{2}{l}{\undertablespace}\\
  667.     #4
  668.     \end{tabular}\end{center}}
  669.  
  670. \newcommand{\exemples}[2]{
  671.   #1{\exemplefont 
  672.     \begin{center}\begin{tabular}{@{\tt}l@{\hspace{1cm}}@{\rm}p{5cm}}
  673.     #2
  674.     \end{tabular}\end{center}}}
  675.  
  676. \newcommand{\exemplesdim}[3]{
  677.   \setlength{\colaslength}{5cm}
  678.   \addtolength{\colaslength}{#1}
  679.   #2{\exemplefont 
  680.     \begin{center}\begin{tabular}{@{\tt}l@{\hspace{1cm}}@{\rm}p{\colaslength}}
  681.     #3
  682.     \end{tabular}\end{center}}}
  683.  
  684. \newcommand{\usagetype}[1]{{\sl #1}\vspace{0.2cm}}
  685. \newcommand{\usagetyped}[2]{{\sl #1}\quad{\it (#2)}\vspace{0.2cm}}
  686. \newcommand{\see}[1]{{\tt #1}}
  687. \newcommand{\seep}[1]{{\tt #1}, p~\pageref{#1}}
  688. \newcommand{\seensp}[1]{{\tt #1} (see p~\pageref{#1})}
  689. \newcommand{\seesnp}[1]{(see {\tt #1}, p~\pageref{#1})}
  690. \newcommand{\seeref}[1]{{\tt #1} (see \ref{#1}, p~\pageref{#1})}
  691. \newcommand{\seesp}[1]{(see \ref{#1}, p~\pageref{#1})}
  692.  
  693. \def\smalldesc#1#2#3{#1\\}
  694. \newcommand{\bigdesc}[2]{
  695.   \setlength{\colaslength}{300pt}
  696.   \settowidth{\colaslengthh}{{\tt #1}}
  697.   \addtolength{\colaslength}{-\colaslengthh}
  698.     \begin{center}\begin{tabular}
  699.     {@{\tt}l@{\hspace{0.5cm}}@{\sf}p{\colaslength}@{\hspace{0.4cm}}@{\bf}r}
  700.    \multicolumn{1}{c}{\bf Object}&\multicolumn{1}{c}{\bf Description}&{\bf
  701. p}\\
  702.     \hline \multicolumn{3}{l}{\undertablespace}\\
  703.     #2
  704.     \end{tabular}\end{center}}
  705.  
  706. \newcommand{\desc}[4]{
  707.   \setlength{\colaslength}{250pt}
  708.   \settowidth{\colaslengthh}{{\tt #1}}
  709.   \addtolength{\colaslength}{-\colaslengthh}
  710.     \begin{center}\begin{tabular}
  711. {@{\tt}l@{\hspace{0.5cm}}@{\sf}p{\colaslength}}
  712.     \multicolumn{1}{c}{\bf #2}&\multicolumn{1}{c}{\bf #3}\\
  713.     \hline \multicolumn{2}{l}{\undertablespace}\\
  714.     #4
  715.     \end{tabular}\end{center}}
  716.  
  717. \newcommand{\contextdimtt}[2]{
  718.   \setlength{\colaslength}{250pt}
  719.   \settowidth{\colaslengthh}{{\tt #1}}
  720.   \addtolength{\colaslength}{-\colaslengthh}
  721.   Context used:
  722.     \begin{center}\begin{tabular}{@{\tt}l@{\hspace{1cm}}@{\rm}p{\colaslength}}
  723.     \multicolumn{1}{c}{\bf Variable}&\multicolumn{1}{c}{\bf used for}\\ 
  724.     \hline \multicolumn{2}{l}{\undertablespace}\\
  725.     #2
  726.     \end{tabular}\end{center}}
  727.  
  728. \def\itemtt#1{\item[{\tt #1}]}
  729. \def\itemit#1{\item[{\it #1}]}
  730.  
  731.  
  732. % SIZE of page
  733. %=============
  734.  
  735. \def\fullpage{\if@twoside \oddsidemargin 35pt \evensidemargin -8pt 
  736. \marginparsep 10pt \marginparpush 10pt \marginparwidth 10pt
  737. \else \oddsidemargin 0pt \evensidemargin 0pt 
  738. \marginparwidth 30pt\fi
  739. \textwidth 450pt \setlength{\colasmargin}{0pt}
  740. \def\colaspm{\hspace{0pt}}\def\colasmm{\hspace{0pt}}
  741. \def\colassmm{\hspace{0pt}}\def\colastitledisp{\hspace{0pt}}
  742. }
  743. \def\mediumpage{\if@twoside \oddsidemargin 75pt \evensidemargin 32pt 
  744. \marginparsep 10pt \marginparpush 10pt \marginparwidth 40pt
  745. \else \oddsidemargin 43pt \evensidemargin 63pt 
  746. \marginparwidth 30pt\fi
  747. \textwidth 410pt \setlength{\colasmargin}{0pt}
  748. \def\colaspm{\hspace{40pt}}\def\colasmm{\hspace{-40pt}}
  749. \def\colassmm{\hspace{-20pt}}\def\colastitledisp{\hspace{-45pt}}
  750. }
  751. \def\smallpage{\if@twoside \oddsidemargin 135pt \evensidemargin 92pt 
  752. \marginparsep 10pt \marginparpush 10pt \marginparwidth 80pt
  753. \else \oddsidemargin 123pt \evensidemargin 123pt
  754. \marginparwidth 30pt \fi
  755. \textwidth 350pt 
  756. \setlength{\colasmargin}{100pt}
  757. \def\colaspm{\hspace{100pt}}\def\colasmm{\hspace{-100pt}}
  758. \def\colassmm{\hspace{-60pt}}\def\colastitledisp{\hspace{-75pt}}
  759. }
  760.  
  761. \smallpage
  762. \topmargin -30pt \headheight 12pt \headsep 25pt \footheight 12pt \footskip
  763. 30pt 
  764. \textheight 680pt \columnsep 10pt \columnseprule 0pt 
  765. \footnotesep 12pt \skip\footins 6pt plus 2pt minus 2pt 
  766. \floatsep 12pt plus 2pt minus 2pt \textfloatsep 20pt plus 2pt minus 4pt
  767. \intextsep 12pt plus 2pt minus 2pt \@maxsep 20pt \dblfloatsep 12pt plus 2pt
  768. minus 2pt \dbltextfloatsep 20pt plus 2pt minus 4pt \@dblmaxsep 20pt 
  769. \@fptop 0pt plus 1fil \@fpsep 8pt plus 2fil \@fpbot 0pt plus 1fil 
  770. \@dblfptop 0pt plus 1fil \@dblfpsep 8pt plus 2fil \@dblfpbot 0pt plus 1fil
  771.  
  772. \parskip 5pt plus 1pt \parindent 0pt \topsep 2pt plus 1pt minus 1pt
  773. \partopsep 0pt plus 1pt minus 1pt \itemsep 2pt plus 1pt minus 1pt 
  774.  
  775. \reversemarginpar
  776. \@mparswitchfalse
  777.  
  778. %% abbrevs
  779.  
  780. \def\GWM{\sc Gwm}
  781. \def\WOOL{\sc Wool}
  782.  
  783. %% fonts
  784. \def\Huge{\@setsize\Huge{30pt}\xxvpt\@xxvpt}
  785.  
  786. %% chapter
  787.  
  788. \def\@makechapterhead#1{ \vspace*{1pt} { \parindent 0pt \raggedright 
  789.  \Huge\bf \colasmm
  790.  \ifnum \c@secnumdepth >\m@ne \thechapter \quad \fi
  791.  #1\par 
  792.  \nobreak \vskip 20pt
  793.  \colasmm{\vbox{\hbox{\vrule height 5pt width450pt depth -3pt}
  794.              \vspace*{-1.1cm}
  795.                 \hbox{\vrule height 0.0pt width450pt depth 0.4pt}}}
  796.  \nobreak \vskip 50pt \nobreak } }
  797.  
  798. \def\@makeschapterhead#1{ \vspace*{1pt} { \parindent 0pt \raggedright 
  799.  \Huge \bf \colasmm #1\par 
  800.  \nobreak \vskip 80pt } }
  801.  
  802. \def\chapter{\clearpage \thispagestyle{pagenum} \global\@topnum\z@
  803. \@afterindentfalse \secdef\@chapter\@schapter} 
  804. \def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
  805.  \refstepcounter{chapter}
  806.  \typeout{\@chapapp\space\thechapter.}
  807.  \addcontentsline{toc}{chapter}{\protect
  808.  \numberline{\thechapter}#1}\else
  809.  \addcontentsline{toc}{chapter}{#1}\fi
  810.  \chaptermark{#1}
  811.  \addtocontents{lof}{\protect\addvspace{10pt}}
  812. \addtocontents{lot}{\protect\addvspace{10pt}} \if@twocolumn
  813. \@topnewpage[\@makechapterhead{#2}] 
  814.  \else \@makechapterhead{#2}
  815.  \@afterheading \fi} 
  816. \def\@schapter#1{\if@twocolumn \@topnewpage[\@makeschapterhead{#1}]
  817.  \else \@makeschapterhead{#1} 
  818.  \@afterheading\fi}
  819.  
  820. %% sections
  821.  
  822. \def\section{\@startsection {section}{1}{\z@}{-3.5ex plus -1ex minus 
  823.  -.2ex}{2.3ex plus .2ex}{\Large\bf\colasmm}}
  824. \def\subsection{\@startsection{subsection}{2}{\z@}{-3.25ex plus -1ex minus 
  825.  -.2ex}{1.5ex plus .2ex}{\large\bf\colassmm}}
  826. \def\subsubsection{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus
  827. -1ex minus -.2ex}{1.5ex plus .2ex}{\normalsize\bf}}
  828. \def\paragraph{\@startsection
  829.  {paragraph}{4}{\z@}{3.25ex plus 1ex minus .2ex}{-1em}{\normalsize\bf}}
  830. \def\subparagraph{\@startsection
  831.  {subparagraph}{4}{\parindent}{3.25ex plus 1ex minus 
  832.  .2ex}{-1em}{\normalsize\bf}}
  833.  
  834. %% headings
  835.  
  836. \if@twoside \def\ps@headings{\def\@oddfoot{}
  837. \def\@evenfoot{}\def\@evenhead{
  838. \colasmm\makebox[0pt][l]{\vrule height-4pt width450pt depth4.3pt}
  839. \bf\thepage\hfill \sl \leftmark}
  840. \def\@oddhead{
  841. \colasmm\makebox[0pt][l]{\vrule height-4pt width450pt depth4.3pt}
  842. \sl \rightmark \hfill\bf\thepage}
  843. \def\chaptermark##1{\markboth {\uppercase{\ifnum \c@secnumdepth
  844. >\m@ne
  845.  \@chapapp\ \thechapter. \ \fi ##1}}{}}\def\sectionmark##1{\markright
  846. {\uppercase{\ifnum \c@secnumdepth >\z@
  847.  \thesection. \ \fi ##1}}}}
  848. \else \def\ps@headings{\def\@oddfoot{}\def\@evenfoot{}\def\@oddhead{\hbox
  849. {}\sl \rightmark \hfill \rm\thepage}\def\chaptermark##1{\markright
  850. {\uppercase{\ifnum \c@secnumdepth >\m@ne
  851.  \@chapapp\ \thechapter. \ \fi ##1}}}}
  852. \fi
  853.  
  854. \if@twoside \def\ps@pagenum{\def\@oddfoot{}
  855. \def\@evenfoot{}\def\@evenhead{
  856. \colasmm\bf\thepage\hfill}
  857. \def\@oddhead{
  858. \colasmm\hfill\bf\thepage}
  859. \def\chaptermark##1{\markboth {\uppercase{\ifnum \c@secnumdepth
  860. >\m@ne
  861.  \@chapapp\ \thechapter. \ \fi ##1}}{}}\def\sectionmark##1{\markright
  862. {\uppercase{\ifnum \c@secnumdepth >\z@
  863.  \thesection. \ \fi ##1}}}}
  864. \else \def\ps@pagenum{\def\@oddfoot{}\def\@evenfoot{}\def\@oddhead{\hbox
  865. {}\hfil \bf\thepage}\def\chaptermark##1{\markright
  866. {\uppercase{\ifnum \c@secnumdepth >\m@ne
  867.  \@chapapp\ \thechapter. \ \fi ##1}}}}
  868. \fi
  869.  
  870. END_OF_SHAR_FOR_colas.sty
  871. cat > create.c << \END_OF_SHAR_FOR_create.c
  872. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  873. /* create.c:
  874.  *
  875.  *  XPM2
  876.  *  Create utility for XPM2 file format
  877.  *  Developped by Arnaud Le Hors
  878.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  879.  */
  880.  
  881. #include "xpmP.h"
  882.  
  883. #define RETURN(status) \
  884.   { freeColorTable(colorTable, ncolors); \
  885.     XpmErrorStatus = status; \
  886.     return(NULL); }
  887.  
  888. Pixmap CreatePixmap(display, visual, d, colormap, data, depth, 
  889.             width_return, height_return, 
  890.             pixels_return, npixels_return,
  891.             colorsymbols, numsymbols, infos)
  892.      Display *display;
  893.      Visual *visual;
  894.      Drawable d;
  895.      Colormap colormap;
  896.      MData *data;
  897.      unsigned int depth;
  898.      unsigned int *width_return, *height_return, *npixels_return;
  899.      Pixel **pixels_return;
  900.      ColorSymbol colorsymbols[];
  901.      unsigned int numsymbols;
  902.      XpmInfo *infos;
  903.  
  904. { Pixmap       pixmap;
  905.   unsigned int cpp;             /* chars per pixel */
  906.   unsigned int ncolors;         /* number of colors */
  907.   char       ***colorTable;     /* color table */
  908.   unsigned int key;        /* color key */
  909.   unsigned int pixlen;        /* length of pixels */
  910.   Pixel        *pixels;        /* pixels colors */
  911.   unsigned int width, height;
  912.   char         *chars, buf[BUFSIZ], *colorname;
  913.   byte         *dptr, *bptr;
  914.   XColor       xcolor;
  915.   XGCValues    gcv;
  916.   GC           gc;
  917.   XImage       *ximage;
  918.   unsigned int a, b, x, y, l = 0;
  919.  
  920.   /* Initialize return values
  921.    */
  922.   *width_return = *height_return = *npixels_return = 0;
  923.   *pixels_return = NULL;
  924.  
  925.   /*
  926.    * parse the data
  927.    */
  928.  
  929.   /* read hints: width, height, ncolors, chars_per_pixel
  930.    */
  931.   if (! ((width = mnextui(data)) && (height = mnextui(data))
  932.      && (ncolors = mnextui(data)) && (cpp =  mnextui(data)))) {
  933.       XpmErrorStatus = PixmapFileInvalid;
  934.       return(NULL);
  935.   }
  936.  
  937.   /* store the hints comment line
  938.    */
  939.   if (infos) mgetcmt(data, &infos->hints_cmt);
  940.  
  941.   for (a = 1, b = 2; b < ncolors; b <<= 1, a++);
  942.   pixlen = (a / 8) + (a % 8 ? 1 : 0);
  943.  
  944.   /* read colors
  945.    */
  946.   if (! (colorTable = (char ***)calloc(ncolors, sizeof(char **)))) {
  947.       XpmErrorStatus = PixmapNoMemory;
  948.       return(NULL);
  949.   }
  950.   for(a = 0; a < ncolors; a++) {
  951.       mnextstring(data);        /* skip the line */
  952.       if (! (*(colorTable + a) = (char **)calloc((NKEYS + 1), sizeof(char
  953. *))))
  954.       RETURN(PixmapNoMemory);
  955.       /* read pixel value
  956.        */
  957.       if (! (**(colorTable + a) = (char *)malloc(cpp)))
  958.       RETURN(PixmapNoMemory);
  959.       for (b = 0; b < cpp; b++)
  960.       *(**(colorTable + a) + b)= mgetc(data);
  961.  
  962.       /* read color keys and values
  963.        */
  964.       while (l = mnextw(data, buf)) {
  965.       for (key = 1; key < NKEYS + 1; key++)
  966.           if (! strncmp(ColorKeys[key - 1], buf, l))
  967.           break;
  968.       if (l = mnextw(data, buf)) {
  969.           if (! (*(*(colorTable + a) + key) = (char *)malloc(l + 1)))
  970.           RETURN(PixmapNoMemory);
  971.           strncpy(*(*(colorTable + a) + key), buf, l);
  972.           *(*(*(colorTable + a) + key) + l) = '\0';
  973.       } else {
  974.           RETURN(PixmapFileInvalid); /* key without value */
  975.       }
  976.       }      
  977.   }
  978.  
  979.   /* store the colors comment line
  980.    */
  981.   if (infos) mgetcmt(data, &infos->colors_cmt);
  982.  
  983.   /* read pixels and index them on color number
  984.    */
  985.   if (! (dptr = bptr = (unsigned char *)
  986.      malloc(width * height * pixlen)))
  987.       RETURN(PixmapNoMemory);
  988.   if (! (chars = (char *)malloc(cpp)))
  989.       RETURN(PixmapNoMemory);
  990.   for (y = 0; y < height; y++) {
  991.       mnextstring(data);
  992.       for (x = 0; x < width; x++) {
  993.       for (a = 0; a < cpp; a++) {
  994.           chars[a] = mgetc(data);
  995.       }
  996.       for (a = 0; a < ncolors; a++)
  997.           if (!strncmp(**(colorTable + a), chars, cpp))
  998.           break;
  999.       if (a == ncolors) {    /* no color matches */
  1000.           RETURN(PixmapFileInvalid);
  1001.       }
  1002.       valToMem((unsigned long)a, dptr, pixlen);
  1003.       dptr += pixlen;
  1004.       }
  1005.   }
  1006.  
  1007.   /* store the pixels comment line
  1008.    */
  1009.   if (infos) mgetcmt(data, &infos->pixels_cmt);
  1010.  
  1011.   /* 
  1012.    * build the image data
  1013.    */
  1014.  
  1015.   key = visualType(visual);
  1016.  
  1017.   if (! (pixels = (Pixel *)malloc(sizeof(Pixel) * ncolors)))
  1018.       RETURN(PixmapNoMemory);
  1019.  
  1020.   /* get pixel colors and index them
  1021.    */
  1022.   for (a = 0; a < ncolors; a++) {
  1023.       colorname = NULL;
  1024.  
  1025.       /* look for a defined symbol
  1026.        */
  1027.       if (numsymbols && *(*(colorTable + a) + 1)) {
  1028.       for (l = 0; l < numsymbols; l++)
  1029.           if (!strcmp(colorsymbols[l].name, *(*(colorTable + a) + 1)))
  1030.           break;
  1031.       if (l != numsymbols && colorsymbols[l].value)
  1032.           colorname = colorsymbols[l].value;
  1033.       }
  1034.       if (! colorname) {
  1035.       if (*(*(colorTable + a) + key)) {
  1036.           b = key;
  1037.       } else {
  1038.           for (b = key - 1; b > 1; b--)
  1039.           if (*(*(colorTable + a) + b))
  1040.               break;
  1041.           if (b == 1) {
  1042.           for (b = key + 1; b < NKEYS + 1; b++)
  1043.               if (*(*(colorTable + a) + b))
  1044.               break;
  1045.           if (b == NKEYS + 1)
  1046.               RETURN(PixmapFileInvalid);
  1047.           }
  1048.       }
  1049.       colorname = *(*(colorTable + a) + b);
  1050.       }
  1051.       if (! XParseColor(display, colormap, colorname, &xcolor))
  1052.       RETURN(PixmapParseColorFailed);
  1053.       if (XAllocColor(display, colormap, &xcolor)) {
  1054.       if (infos) {
  1055.           for (b = 0; b < a; b++)
  1056.           if (*(pixels + b) == xcolor.pixel)
  1057.               break;
  1058.           if (b != a) {
  1059.           if (! XAllocColorCells(display, colormap, False, NULL, 0,
  1060.                      pixels + a, 1))
  1061.               RETURN(PixmapAllocColorFailed);
  1062.           XFreeColors(display, colormap, &(xcolor.pixel), 1, 0);
  1063.           xcolor.pixel = *(pixels + a);
  1064.           XStoreColor(display, colormap, &xcolor);
  1065.           }
  1066.       }
  1067.       } else
  1068.       RETURN(PixmapAllocColorFailed);
  1069.  
  1070.       *(pixels + a) = xcolor.pixel;
  1071.   }
  1072.  
  1073.   /* set data pixels to the indexed color pixel
  1074.    */
  1075.   dptr = bptr;
  1076.   for (y = 0; y < height; y++) {
  1077.       for (x = 0; x < width; x++) {
  1078.       valToMem(*(pixels + memToVal(dptr, pixlen)), dptr, pixlen);
  1079.       dptr += pixlen;
  1080.       }
  1081.   }
  1082.  
  1083.   /*
  1084.    * send the image to the server
  1085.    */
  1086.  
  1087.   pixmap = XCreatePixmap(display, d, width, 
  1088.              height, depth);
  1089.   gcv.function= GXcopy;
  1090.   gc = XCreateGC(display, pixmap, GCFunction, &gcv);
  1091.   ximage = XCreateImage(display, visual, depth, ZPixmap, 0, (char *)bptr, 
  1092.             width, height, 8, 0);
  1093.   ximage->byte_order= MSBFirst; /* trust him, Jim Frost knows what he's */
  1094.                 /* talking about */
  1095.   XPutImage(display, pixmap, gc, ximage, 0, 0, 0, 0, 
  1096.         width, height);
  1097.  
  1098.   ximage->data = NULL;
  1099.   XDestroyImage(ximage);    /* waste not want not */
  1100.   XFreeGC(display, gc);
  1101.   free(dptr);
  1102.   free(chars);
  1103.  
  1104.   *width_return = width;
  1105.   *height_return = height;
  1106.   *pixels_return = pixels;
  1107.   *npixels_return = ncolors;
  1108.  
  1109.   /* store color table infos
  1110.    */
  1111.   if (infos) {
  1112.       infos->ncolors = ncolors;
  1113.       infos->colorTable = colorTable;
  1114.       infos->pixels = pixels;
  1115.   } else {
  1116.       freeColorTable(colorTable, ncolors);
  1117.   }
  1118.  
  1119.   return(pixmap);
  1120. }
  1121. END_OF_SHAR_FOR_create.c
  1122. cat > demo.c << \END_OF_SHAR_FOR_demo.c
  1123. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  1124. /* demo.c:
  1125.  *
  1126.  *  XPM2
  1127.  *  Demo File
  1128.  *  Developped by Arnaud Le Hors
  1129.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  1130.  */
  1131.  
  1132. #include "xpm.h"
  1133.  
  1134. /* XPM2 C */
  1135. /* plaid pixmap */
  1136. static char * plaid[] = {
  1137. /* width height ncolors chars_per_pixel */ 
  1138. "22 22 4 2",
  1139. /* colors */
  1140. "   c red     m white  s light_color",
  1141. "Y  c yellow    m black  s lines_in_mix",
  1142. "+  c yellow    m white  s lines_in_dark",
  1143. "x         m black  s dark_color",
  1144. /* pixels */
  1145. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1146. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1147. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1148. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1149. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1150. "Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + ", 
  1151. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1152. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1153. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1154. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1155. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1156. "          x           x   x   x Y x   x   x ", 
  1157. "          x             x   x   Y   x   x   ",
  1158. "          x           x   x   x Y x   x   x ", 
  1159. "          x             x   x   Y   x   x   ", 
  1160. "          x           x   x   x Y x   x   x ", 
  1161. "x x x x x x x x x x x x x x x x x x x x x x ", 
  1162. "          x           x   x   x Y x   x   x ", 
  1163. "          x             x   x   Y   x   x   ", 
  1164. "          x           x   x   x Y x   x   x ", 
  1165. "          x             x   x   Y   x   x   ", 
  1166. "          x           x   x   x Y x   x   x "
  1167. } ;
  1168.  
  1169. static Display *dpy;
  1170. static XEvent e ;
  1171. static Window root, win ;
  1172. static int depth,screen ;
  1173. static XSetWindowAttributes xswa;
  1174. static char **command ;
  1175. static Pixmap pix ;
  1176. static Colormap cmp;
  1177. static unsigned long *pixels;
  1178. static unsigned int npixels;
  1179. static XpmInfo infos;
  1180. static Visual *v;
  1181.  
  1182. main(argc, argv)
  1183. int    argc;
  1184. char    *argv[];
  1185. {
  1186.  
  1187.     unsigned int w, h;
  1188.     int winx, winy, winw, winh;
  1189.     char *display = NULL ;
  1190.     char *geom = NULL;
  1191.     char *type = NULL;
  1192.     char *input = NULL;
  1193.     char *output = NULL;
  1194.     int numsymbols = 0;
  1195.     ColorSymbol symbols[4];
  1196.     int ErrorStatus, notend = 1;
  1197.  
  1198.     command = argv ;
  1199.     while (*++argv) {
  1200.     if (index(*argv,':')) display = *argv ; else
  1201.     if (!strcmp(*argv,"-d")) 
  1202.         if (*++argv)  display = *argv ; else Usage(); else
  1203.     if (!strcmp(*argv,"-display")) 
  1204.         if (*++argv)  display = *argv ; else Usage(); else
  1205.     if (index(*argv,'=')) geom = *argv ; else
  1206.     if (!strcmp(*argv,"-g")) 
  1207.         if (*++argv)  geom = *argv ; else Usage(); else
  1208.     if (!strcmp(*argv,"-geometry")) 
  1209.         if (*++argv)  geom = *argv ; else Usage(); else
  1210.     if (!strcmp(*argv,"-geom")) 
  1211.         if (*++argv)  geom = *argv ; else Usage(); else
  1212.     if (!strcmp(*argv,"-t")) 
  1213.         if (*++argv)  type = *argv ; else Usage(); else
  1214.     if (!strcmp(*argv,"-i")) 
  1215.         if (*++argv)  input = *argv ; else Usage(); else
  1216.     if (!strcmp(*argv,"-o")) 
  1217.         if (*++argv)  output = *argv ; else Usage(); else
  1218.     if (!strcmp(*argv,"-s")) {
  1219.         if (numsymbols < 4) {
  1220.         if (*++argv) symbols[numsymbols].name = *argv ; else Usage();
  1221.         if (*++argv) symbols[numsymbols++].value = *argv ; else Usage();
  1222.         }
  1223.     } else
  1224.          Usage() ;
  1225.     }
  1226.  
  1227.  
  1228.     if ((dpy = XOpenDisplay(display)) == NULL) {
  1229.     fprintf(stderr,"Cannot open display : %s\n",
  1230.             XDisplayName(display));
  1231.     exit(0);
  1232.     }
  1233.  
  1234.     winx = 100;        winy = 100;
  1235.     winw = 100;        winh = 100;
  1236.     if (geom)  {
  1237.        XParseGeometry(geom, &winx, &winy, &winw, &winh) ;
  1238.     }
  1239.      
  1240.     root = DefaultRootWindow(dpy);
  1241.     screen = DefaultScreen(dpy) ;
  1242.     depth = DefaultDepth(dpy,screen) ;
  1243.     cmp = DefaultColormap(dpy, screen);
  1244.     v = DefaultVisual(dpy, screen);
  1245.  
  1246.     xswa.background_pixel = WhitePixel(dpy,DefaultScreen(dpy)) ;
  1247.     xswa.event_mask = ButtonPressMask;
  1248.     xswa.save_under = True ;
  1249.     xswa.override_redirect = True ;
  1250.     win = XCreateWindow(dpy,root,
  1251.             winx, winy, winw, winh, 1, 
  1252.             depth, InputOutput,CopyFromParent,
  1253.             CWEventMask|CWBackPixel|
  1254.             CWOverrideRedirect|CWSaveUnder, &xswa);
  1255.  
  1256.     if (input) {
  1257.     if ((ErrorStatus = XReadPixmapFile(dpy, v, win, cmp, input, depth,
  1258.                        &pix, &w, &h, &pixels, &npixels,
  1259.                        symbols, numsymbols, &infos))
  1260.         != PixmapSuccess) {
  1261.         printf("Pixmap Error %d\n", ErrorStatus);
  1262.         exit(1);
  1263.     }
  1264.     } else {
  1265.     if ((ErrorStatus = XCreatePixmapFromData(dpy, v, win, cmp, plaid, depth,
  1266.                         &pix, &w, &h, &pixels, &npixels,
  1267.                          symbols, numsymbols, NULL))
  1268.         != PixmapSuccess) {
  1269.         printf("Pixmap Error %d\n", ErrorStatus);
  1270.         exit(1);
  1271.     }
  1272.     }
  1273.     XSetWindowBackgroundPixmap(dpy, win, pix);
  1274.     XMapWindow(dpy, win);
  1275.  
  1276.     if (output)
  1277.     if ((ErrorStatus = XWritePixmapFile(dpy, cmp, output, pix, w, h, type, 
  1278.                         2, &infos))
  1279.         != PixmapSuccess) {
  1280.         printf("Pixmap Error %d\n", ErrorStatus);
  1281.         exit(1);
  1282.     }
  1283.  
  1284.     do {
  1285.       XNextEvent(dpy, &e) ;
  1286.       if (e.type == ButtonPress)
  1287.        notend = 0;
  1288.     } while (notend) ;
  1289.  
  1290.     XFreePixmap(dpy, pix);
  1291.     XFreeColors(dpy, cmp, pixels, npixels, 0);
  1292.     XFreeXpmInfo(&infos);
  1293. }
  1294.  
  1295.  
  1296. Usage()
  1297. {
  1298.     fprintf(stderr,"%s %s %s%s", command[0],
  1299.         "[-g wxh+x+y] [-d host:display.screen]",
  1300.         "[-s symbol_name symbol_value]\n", 
  1301.         "\t[-t type] [-i inputfile] [-o outputfile]\n");
  1302.     exit(0);
  1303. }
  1304. END_OF_SHAR_FOR_demo.c
  1305. cat > free.c << \END_OF_SHAR_FOR_free.c
  1306. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  1307. /* free.c:
  1308.  *
  1309.  *  XPM2
  1310.  *  Free utility for XPM2 file format
  1311.  *  Developped by Arnaud Le Hors
  1312.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  1313.  */
  1314.  
  1315. #include "xpmP.h"
  1316.  
  1317. freeColorTable(colorTable, ncolors)
  1318. char ***colorTable;
  1319. int ncolors;
  1320. { int a, b;
  1321.     if (colorTable) {
  1322.     for (a = 0; a < ncolors; a++)
  1323.         if (*(colorTable +a)) {
  1324.         for (b = 0; b < (NKEYS + 1); b++)
  1325.             if (*(*(colorTable +a) + b))
  1326.             free(*(*(colorTable +a) + b));
  1327.         free(*(colorTable +a));
  1328.         }
  1329.     free(colorTable);
  1330.     }
  1331. }
  1332.  
  1333. XFreeXpmInfo(infos)
  1334. XpmInfo *infos;
  1335. {
  1336.     if (infos) {
  1337.     if (infos->type) free(infos->type);
  1338.     freeColorTable(infos->colorTable, infos->ncolors);
  1339.     if (infos->hints_cmt) free(infos->hints_cmt);
  1340.     if (infos->colors_cmt) free(infos->colors_cmt);
  1341.     if (infos->pixels_cmt) free(infos->pixels_cmt);
  1342.     }
  1343. }
  1344. END_OF_SHAR_FOR_free.c
  1345. cat > mio.c << \END_OF_SHAR_FOR_mio.c
  1346. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  1347. /* mio.c:
  1348.  *
  1349.  *  XPM2
  1350.  *  I/O utility for XPM2 file format
  1351.  *  Developped by Arnaud Le Hors
  1352.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  1353.  */
  1354.  
  1355. #include "xpmP.h"
  1356.  
  1357. static int CommentLength = 0;
  1358. static char Comment[BUFSIZ];
  1359. LFUNC(atoui, unsigned int, (char *p));
  1360.  
  1361. static unsigned int atoui(p)
  1362. char *p;
  1363. {
  1364.         register int n;
  1365.  
  1366.         n = 0;
  1367.         while(*p >= '0' && *p <= '9')
  1368.                 n = n*10 + *p++ - '0';
  1369.         return(n);
  1370. }
  1371.  
  1372. mnextstring(mdata)        /* skip to the end of the current string */
  1373. MData *mdata;            /* and the beginning of the next one */
  1374. { char  c;
  1375.     switch(mdata->type) {
  1376.     case MARRAY:
  1377.     mdata->cptr = ((char **)mdata->stream)[++mdata->line];
  1378.     break;
  1379.     case MFILE:
  1380.     while ((c = mgetc(mdata)) != EOS && c != EOF);
  1381.     if (BOS)
  1382.         while ((c = mgetc(mdata)) != BOS && c != EOF);
  1383.     break;
  1384.     }
  1385. }
  1386.  
  1387. unsigned int mnextui(mdata)    /* skip whitespace and return the following */
  1388. MData *mdata;            /* unsigned int                 */
  1389. { char buf[BUFSIZ];
  1390.  
  1391.   mnextw(mdata, buf);
  1392.   return(atoui(buf));
  1393. }
  1394.  
  1395. char mgetc(mdata)        /* return the current character */
  1396. MData *mdata;
  1397. { char c;
  1398.   register unsigned int n = 1, a;
  1399.   unsigned int notend;
  1400.  
  1401.     switch(mdata->type) {
  1402.     case MARRAY:
  1403.     return(*mdata->cptr++);
  1404.     case MFILE:
  1405.     c = getc((FILE *)mdata->stream);
  1406.     if (BCMT && c == BCMT[0]) {
  1407.         Comment[0] = c;
  1408.         /* skip the string begining comment
  1409.          */
  1410.         while ((Comment[n] = getc((FILE *)mdata->stream)) == BCMT[n]
  1411.            && BCMT[n] != '\0' && Comment[n] != EOF) n++;
  1412.         if (BCMT[n] != '\0') { /* this wasn't the begining of a comment */
  1413.         for (a = 1; a < n; a++)
  1414.             mungetc(Comment[a], mdata);
  1415.         return(c);
  1416.         }
  1417.         /* store comment 
  1418.          */
  1419.         Comment[0] = Comment[n];
  1420.         n = notend = 1;
  1421.         while (notend) {
  1422.         while ((Comment[n] = getc((FILE *)mdata->stream)) != ECMT[0] 
  1423.                && Comment[n] != EOF) n++;
  1424.         CommentLength = n++;
  1425.         a = 1;
  1426.         while ((Comment[n] = getc((FILE *)mdata->stream)) == ECMT[a]
  1427.                && ECMT[a] != '\0' && Comment[n] != EOF) { a++; n++; }
  1428.         if (ECMT[a] == '\0') { /* this is the end of the comment */
  1429.             notend = 0;
  1430.             mungetc(Comment[n], mdata);
  1431.         } else {
  1432.             n++;
  1433.         }
  1434.         }
  1435.         c = mgetc(mdata);
  1436.     }
  1437.     return(c);
  1438.     }
  1439. }
  1440.  
  1441.  
  1442. char mungetc(c, mdata)        /* push the given character back */
  1443. int c;
  1444. MData *mdata;
  1445.     switch(mdata->type) {
  1446.     case MARRAY:
  1447.     return(*--mdata->cptr = c);
  1448.     case MFILE:
  1449.     return(ungetc(c, (FILE *)mdata->stream));
  1450.     }
  1451. }
  1452.  
  1453.  
  1454. mskipwhite(mdata)        /* skip whitespace */
  1455. MData *mdata;
  1456. { char c;
  1457.  
  1458.     switch(mdata->type) {
  1459.     case MARRAY:
  1460.     while (*mdata->cptr == SPC || *mdata->cptr == TAB) 
  1461.         mdata->cptr++;
  1462.     break;
  1463.     case MFILE:
  1464.     while ((c = mgetc(mdata)) == SPC || c == TAB);
  1465.     mungetc(c, mdata);
  1466.     break;
  1467.     }
  1468. }
  1469.  
  1470.  
  1471. unsigned int mnextw(mdata, buf)    /* skip whitespace and return the following */
  1472. MData *mdata;            /* word                        */
  1473. char *buf;
  1474. { register unsigned int n = 0;
  1475.  
  1476.     mskipwhite(mdata);
  1477.     switch(mdata->type) {
  1478.     case MARRAY:
  1479.     while ((buf[n] = *mdata->cptr++) != SPC 
  1480.            && buf[n] != TAB && buf[n] != EOS && buf[n] != EOF) n++;
  1481.     mdata->cptr--;
  1482.     break;
  1483.     case MFILE:
  1484.     while ((buf[n] = mgetc(mdata)) != SPC 
  1485.            && buf[n] != TAB && buf[n] != EOS && buf[n] != EOF) n++;
  1486.     ungetc(buf[n],(FILE *)mdata->stream); 
  1487.     break;
  1488.     }
  1489.   return(n);
  1490. }
  1491.  
  1492. mgetcmt(mdata, cmt)        /* get the current comment line */
  1493. MData *mdata;
  1494. char **cmt;
  1495. {
  1496.     switch(mdata->type) {
  1497.     case MARRAY:
  1498.     break;
  1499.     case MFILE:
  1500.     *cmt = (char *) malloc(CommentLength + 1);
  1501.     strncpy(*cmt, Comment, CommentLength);
  1502.     (*cmt)[CommentLength] = '\0';
  1503.     CommentLength = 0;
  1504.     break;
  1505.     }
  1506. }
  1507. END_OF_SHAR_FOR_mio.c
  1508. cat > plaid << \END_OF_SHAR_FOR_plaid
  1509. ! XPM2
  1510. ! width height ncolors chars_per_pixel
  1511. 22 22 4 2
  1512. ! colors
  1513.    c red     m white  s light_color
  1514. Y  c yellow    m black  s lines_in_mix
  1515. +  c yellow    m white  s lines_in_dark
  1516. x         m black  s dark_color
  1517. ! pixels
  1518. x   x   x x x   x   x x x x x x + x x x x x 
  1519.   x   x   x   x   x   x x x x x x x x x x x 
  1520. x   x   x x x   x   x x x x x x + x x x x x 
  1521.   x   x   x   x   x   x x x x x x x x x x x 
  1522. x   x   x x x   x   x x x x x x + x x x x x 
  1523. Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + 
  1524. x   x   x x x   x   x x x x x x + x x x x x 
  1525.   x   x   x   x   x   x x x x x x x x x x x 
  1526. x   x   x x x   x   x x x x x x + x x x x x 
  1527.   x   x   x   x   x   x x x x x x x x x x x 
  1528. x   x   x x x   x   x x x x x x + x x x x x 
  1529.           x           x   x   x Y x   x   x 
  1530.           x             x   x   Y   x   x   
  1531.           x           x   x   x Y x   x   x 
  1532.           x             x   x   Y   x   x   
  1533.           x           x   x   x Y x   x   x 
  1534. x x x x x x x x x x x x x x x x x x x x x x 
  1535.           x           x   x   x Y x   x   x 
  1536.           x             x   x   Y   x   x   
  1537.           x           x   x   x Y x   x   x 
  1538.           x             x   x   Y   x   x   
  1539.           x           x   x   x Y x   x   x 
  1540. END_OF_SHAR_FOR_plaid
  1541. cat > plaid_c << \END_OF_SHAR_FOR_plaid_c
  1542. /* XPM2 C */
  1543. static char * plaid[] = {
  1544. /* plaid pixmap 
  1545.  * width height ncolors chars_per_pixel */
  1546. "22 22 4 2 ",
  1547. /* colors 
  1548.  */
  1549. "   c red     m white  s light_color ",
  1550. "Y  c yellow    m black  s lines_in_mix ",
  1551. "+  c yellow    m white  s lines_in_dark ",
  1552. "x         m black  s dark_color ",
  1553. /* pixels */
  1554. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1555. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1556. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1557. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1558. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1559. "Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + ", 
  1560. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1561. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1562. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1563. "  x   x   x   x   x   x x x x x x x x x x x ", 
  1564. "x   x   x x x   x   x x x x x x + x x x x x ", 
  1565. "          x           x   x   x Y x   x   x ", 
  1566. "          x             x   x   Y   x   x   ",
  1567. "          x           x   x   x Y x   x   x ", 
  1568. "          x             x   x   Y   x   x   ", 
  1569. "          x           x   x   x Y x   x   x ", 
  1570. "x x x x x x x x x x x x x x x x x x x x x x ", 
  1571. "          x           x   x   x Y x   x   x ", 
  1572. "          x             x   x   Y   x   x   ", 
  1573. "          x           x   x   x Y x   x   x ", 
  1574. "          x             x   x   Y   x   x   ", 
  1575. "          x           x   x   x Y x   x   x "
  1576. } ;
  1577. END_OF_SHAR_FOR_plaid_c
  1578. cat > plaid_ll << \END_OF_SHAR_FOR_plaid_ll
  1579. ; XPM2 Lisp 
  1580. (setq plaid '(
  1581. ; width height ncolors chars_per_pixel  
  1582. "22 22 4 2"
  1583. ; colors 
  1584. "   c red     m white  s light_color"
  1585. "Y  c yellow    m black  s lines_in_mix"
  1586. "+  c yellow    m white  s lines_in_dark"
  1587. "x         m black  s dark_color"
  1588. ; pixels 
  1589. "x   x   x x x   x   x x x x x x + x x x x x " 
  1590. "  x   x   x   x   x   x x x x x x x x x x x " 
  1591. "x   x   x x x   x   x x x x x x + x x x x x " 
  1592. "  x   x   x   x   x   x x x x x x x x x x x " 
  1593. "x   x   x x x   x   x x x x x x + x x x x x " 
  1594. "Y Y Y Y Y x Y Y Y Y Y + x + x + x + x + x + " 
  1595. "x   x   x x x   x   x x x x x x + x x x x x " 
  1596. "  x   x   x   x   x   x x x x x x x x x x x " 
  1597. "x   x   x x x   x   x x x x x x + x x x x x " 
  1598. "  x   x   x   x   x   x x x x x x x x x x x " 
  1599. "x   x   x x x   x   x x x x x x + x x x x x " 
  1600. "          x           x   x   x Y x   x   x " 
  1601. "          x             x   x   Y   x   x   "
  1602. "          x           x   x   x Y x   x   x " 
  1603. "          x             x   x   Y   x   x   " 
  1604. "          x           x   x   x Y x   x   x " 
  1605. "x x x x x x x x x x x x x x x x x x x x x x " 
  1606. "          x           x   x   x Y x   x   x " 
  1607. "          x             x   x   Y   x   x   " 
  1608. "          x           x   x   x Y x   x   x " 
  1609. "          x             x   x   Y   x   x   " 
  1610. "          x           x   x   x Y x   x   x "
  1611. ))
  1612. END_OF_SHAR_FOR_plaid_ll
  1613. cat > rep10.sty << \END_OF_SHAR_FOR_rep10.sty
  1614. % rep10.sty 23 Sep 85
  1615. \lineskip 1pt \normallineskip 1pt
  1616. \def\baselinestretch{1}
  1617.  
  1618. \def\@normalsize{\@setsize\normalsize{12pt}\xpt\@xpt
  1619. \abovedisplayskip 10pt plus2pt minus5pt\belowdisplayskip \abovedisplayskip
  1620. \abovedisplayshortskip \z@ plus3pt\belowdisplayshortskip 6pt plus3pt minus3pt}
  1621. \def\small{\@setsize\small{11pt}\ixpt\@ixpt
  1622. \abovedisplayskip 8.5pt plus 3pt minus 4pt\belowdisplayskip \abovedisplayskip
  1623. \abovedisplayshortskip \z@ plus2pt\belowdisplayshortskip 4pt plus2pt minus 2pt
  1624. \def\@listi{\topsep 4pt plus 2pt minus 2pt\parsep 2pt plus 1pt minus 1pt
  1625. \itemsep \parsep}}
  1626. \def\footnotesize{\@setsize\footnotesize{9.5pt}\viiipt\@viiipt
  1627. \abovedisplayskip 6pt plus 2pt minus 4pt\belowdisplayskip \abovedisplayskip
  1628. \abovedisplayshortskip \z@ plus 1pt\belowdisplayshortskip 3pt plus 1pt minus
  1629. 2pt
  1630. \def\@listi{\topsep 3pt plus 1pt minus 1pt\parsep 2pt plus 1pt minus 1pt
  1631. \itemsep \parsep}}
  1632. \def\scriptsize{\@setsize\scriptsize{8pt}\viipt\@viipt}
  1633. \def\tiny{\@setsize\tiny{6pt}\vpt\@vpt}
  1634. \def\large{\@setsize\large{14pt}\xiipt\@xiipt}
  1635. \def\Large{\@setsize\Large{18pt}\xivpt\@xivpt}
  1636. \def\LARGE{\@setsize\LARGE{22pt}\xviipt\@xviipt}
  1637. \def\huge{\@setsize\huge{25pt}\xxpt\@xxpt}
  1638. \def\Huge{\@setsize\Huge{30pt}\xxvpt\@xxvpt}
  1639. \normalsize 
  1640.  
  1641. \if@twoside \oddsidemargin 44pt \evensidemargin 82pt \marginparwidth 107pt
  1642. \else \oddsidemargin 63pt \evensidemargin 63pt
  1643.  \marginparwidth 90pt 
  1644. \fi
  1645. \marginparsep 11pt 
  1646.  \topmargin 27pt \headheight 12pt \headsep 25pt \footheight 12pt \footskip
  1647. 30pt 
  1648.  
  1649. \textheight 528pt \textwidth 345pt \columnsep 10pt \columnseprule 0pt 
  1650.  
  1651. \footnotesep 6.65pt 
  1652. \skip\footins 9pt plus 4pt minus 2pt 
  1653. \floatsep 12pt plus 2pt minus 2pt \textfloatsep 20pt plus 2pt minus 4pt
  1654. \intextsep 12pt plus 2pt minus 2pt \@maxsep 20pt \dblfloatsep 12pt plus 2pt
  1655. minus 2pt \dbltextfloatsep 20pt plus 2pt minus 4pt \@dblmaxsep 20pt 
  1656. \@fptop 0pt plus 1fil \@fpsep 8pt plus 2fil \@fpbot 0pt plus 1fil 
  1657. \@dblfptop 0pt plus 1fil \@dblfpsep 8pt plus 2fil \@dblfpbot 0pt plus 1fil
  1658. \marginparpush 5pt 
  1659.  
  1660. \parskip 0pt plus 1pt \parindent 15pt \topsep 8pt plus 2pt minus 4pt
  1661. \partopsep 2pt plus 1pt minus 1pt \itemsep 4pt plus 2pt minus 1pt 
  1662. \@lowpenalty 51 \@medpenalty 151 \@highpenalty 301 
  1663. \@beginparpenalty -\@lowpenalty \@endparpenalty -\@lowpenalty \@itempenalty
  1664. -\@lowpenalty 
  1665.  
  1666. \def\part{\cleardoublepage \thispagestyle{plain} \if@twocolumn \onecolumn
  1667. \@tempswatrue \else \@tempswafalse \fi \hbox{}\vfil \bgroup \centering
  1668. \secdef\@part\@spart} 
  1669.  
  1670. \def\@part[#1]#2{\ifnum \c@secnumdepth >-2\relax \refstepcounter{part}
  1671. \addcontentsline{toc}{part}{\thepart \hspace{1em}#1}\else
  1672. \addcontentsline{toc}{part}{#1}\fi \markboth{}{}
  1673.  \ifnum \c@secnumdepth >-2\relax \huge\bf Part \thepart \par \vskip 20pt \fi
  1674. \Huge \bf #1\@endpart} 
  1675. \def\@endpart{\par\egroup \vfil\newpage \if@twoside \hbox{}
  1676. \thispagestyle{empty} 
  1677.  \newpage 
  1678.  \fi \if@tempswa \twocolumn \fi} 
  1679. \def\@spart#1{\Huge \bf #1\@endpart}
  1680.  
  1681.  
  1682. \def\@makechapterhead#1{ \vspace*{50pt} { \parindent 0pt \raggedright 
  1683.  \ifnum \c@secnumdepth >\m@ne \huge\bf \@chapapp{} \thechapter \par 
  1684.  \vskip 20pt \fi \Huge \bf #1\par 
  1685.  \nobreak \vskip 40pt } }
  1686.  
  1687. \def\@makeschapterhead#1{ \vspace*{50pt} { \parindent 0pt \raggedright 
  1688.  \Huge \bf #1\par 
  1689.  \nobreak \vskip 40pt } }
  1690.  
  1691. \def\chapter{\clearpage \thispagestyle{plain} \global\@topnum\z@
  1692. \@afterindentfalse \secdef\@chapter\@schapter} 
  1693. \def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
  1694.  \refstepcounter{chapter}
  1695.  \typeout{\@chapapp\space\thechapter.}
  1696.  \addcontentsline{toc}{chapter}{\protect
  1697.  \numberline{\thechapter}#1}\else
  1698.  \addcontentsline{toc}{chapter}{#1}\fi
  1699.  \chaptermark{#1}
  1700.  \addtocontents{lof}{\protect\addvspace{10pt}}
  1701. \addtocontents{lot}{\protect\addvspace{10pt}} \if@twocolumn
  1702. \@topnewpage[\@makechapterhead{#2}] 
  1703.  \else \@makechapterhead{#2}
  1704.  \@afterheading \fi} 
  1705. \def\@schapter#1{\if@twocolumn \@topnewpage[\@makeschapterhead{#1}]
  1706.  \else \@makeschapterhead{#1} 
  1707.  \@afterheading\fi}
  1708.  
  1709. \def\section{\@startsection {section}{1}{\z@}{-3.5ex plus -1ex minus 
  1710.  -.2ex}{2.3ex plus .2ex}{\Large\bf}}
  1711. \def\subsection{\@startsection{subsection}{2}{\z@}{-3.25ex plus -1ex minus 
  1712.  -.2ex}{1.5ex plus .2ex}{\large\bf}}
  1713. \def\subsubsection{\@startsection{subsubsection}{3}{\z@}{-3.25ex plus
  1714. -1ex minus -.2ex}{1.5ex plus .2ex}{\normalsize\bf}}
  1715. \def\paragraph{\@startsection
  1716.  {paragraph}{4}{\z@}{3.25ex plus 1ex minus .2ex}{-1em}{\normalsize\bf}}
  1717. \def\subparagraph{\@startsection
  1718.  {subparagraph}{4}{\parindent}{3.25ex plus 1ex minus 
  1719.  .2ex}{-1em}{\normalsize\bf}}
  1720.  
  1721. \def\chaptermark#1{}
  1722.  
  1723. \setcounter{secnumdepth}{2}
  1724.  
  1725. \def\appendix{\par
  1726.  \setcounter{chapter}{0}
  1727.  \setcounter{section}{0}
  1728.  \def\@chapapp{Appendix}
  1729.  \def\thechapter{\Alph{chapter}}}
  1730.  
  1731.  
  1732. \leftmargini 25pt
  1733. \leftmarginii 22pt \leftmarginiii 18.7pt \leftmarginiv 17pt \leftmarginv 10pt
  1734. \leftmarginvi 10pt
  1735. \leftmargin\leftmargini
  1736. \labelwidth\leftmargini\advance\labelwidth-\labelsep
  1737. \labelsep 5pt
  1738. \parsep 4pt plus 2pt minus 1pt
  1739. \def\@listi{\leftmargin\leftmargini}
  1740. \def\@listii{\leftmargin\leftmarginii
  1741.  \labelwidth\leftmarginii\advance\labelwidth-\labelsep
  1742.  \topsep 4pt plus 2pt minus 1pt
  1743.  \parsep 2pt plus 1pt minus 1pt
  1744.  \itemsep \parsep}
  1745. \def\@listiii{\leftmargin\leftmarginiii
  1746.  \labelwidth\leftmarginiii\advance\labelwidth-\labelsep
  1747.  \topsep 2pt plus 1pt minus 1pt 
  1748.  \parsep \z@ \partopsep 1pt plus 0pt minus 1pt
  1749.  \itemsep \topsep}
  1750. \def\@listiv{\leftmargin\leftmarginiv
  1751.  \labelwidth\leftmarginiv\advance\labelwidth-\labelsep}
  1752. \def\@listv{\leftmargin\leftmarginv
  1753.  \labelwidth\leftmarginv\advance\labelwidth-\labelsep}
  1754. \def\@listvi{\leftmargin\leftmarginvi
  1755.  \labelwidth\leftmarginvi\advance\labelwidth-\labelsep}
  1756. END_OF_SHAR_FOR_rep10.sty
  1757. cat > value.c << \END_OF_SHAR_FOR_value.c
  1758. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  1759. /* value.c:
  1760.  *
  1761.  * routines for converting byte values to long values.  these are pretty
  1762.  * portable although they are not necessarily the fastest things in the
  1763.  * world.
  1764.  *
  1765.  * jim frost 10.02.89
  1766.  * Copyright 1989, 1990 Jim Frost
  1767.  *
  1768.  * Permission to use, copy, modify, distribute, and sell this software
  1769.  * and its documentation for any purpose is hereby granted without fee,
  1770.  * provided that the above copyright notice appear in all copies and
  1771.  * that both that copyright notice and this permission notice appear
  1772.  * in supporting documentation.  The author makes no representations
  1773.  * about the suitability of this software for any purpose.  It is
  1774.  * provided "as is" without express or implied warranty.
  1775.  *
  1776.  * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  1777.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
  1778.  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  1779.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  1780.  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1781.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
  1782.  * USE OR PERFORMANCE OF THIS SOFTWARE.
  1783.  *
  1784.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  1785.  */
  1786.  
  1787. typedef unsigned char  byte;      /* byte type */
  1788.  
  1789. unsigned long memToVal(p, len)
  1790.      byte         *p;
  1791.      unsigned int  len;
  1792. { unsigned int  a;
  1793.   unsigned long i;
  1794.  
  1795.   i= 0;
  1796.   for (a= 0; a < len; a++)
  1797.     i= (i << 8) + *(p++);
  1798.   return(i);
  1799. }
  1800.  
  1801. void valToMem(val, p, len)
  1802.      unsigned long  val;
  1803.      byte          *p;
  1804.      unsigned int   len;
  1805. { int a;
  1806.  
  1807.   for (a= len - 1; a >= 0; a--) {
  1808.     *(p + a)= val & 0xff;
  1809.     val >>= 8;
  1810.   }
  1811. }
  1812. END_OF_SHAR_FOR_value.c
  1813. cat > visual.c << \END_OF_SHAR_FOR_visual.c
  1814. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  1815. /* visual.c:
  1816.  *
  1817.  *  XPM2
  1818.  *  Visual utility for XPM2 file format
  1819.  *  Developped by Arnaud Le Hors
  1820.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  1821.  */
  1822.  
  1823. #include "xpmP.h"
  1824.  
  1825. visualType(visual)
  1826. Visual *visual;
  1827. {
  1828.   if (visual->class == GrayScale)
  1829.       switch(visual->map_entries) {
  1830.       case 2:
  1831.       return(MONO);
  1832.       break;
  1833.       case 4:
  1834.       return(GRAY4);
  1835.       break;
  1836.       default:
  1837.       return(GRAY);
  1838.       }
  1839.   else
  1840.       return(COLOR);
  1841. }
  1842.  
  1843. END_OF_SHAR_FOR_visual.c
  1844. cat > xpm.h << \END_OF_SHAR_FOR_xpm.h
  1845. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  1846. /* xpm.h:
  1847.  *
  1848.  *  XPM2
  1849.  *  Include file
  1850.  *  Developped by Arnaud Le Hors
  1851.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  1852.  */
  1853.  
  1854. #ifndef XPM_h
  1855. #define XPM_h
  1856.  
  1857. #define XPM_FORMAT 2
  1858.  
  1859. #include <X11/Xlib.h>
  1860. #include <stdio.h>
  1861.  
  1862. /* we keep the same codes as for Bitmap management */
  1863. #ifndef _XUTIL_H_
  1864. #ifdef VMS
  1865. #include "decw$include:Xutil.h"
  1866. #else
  1867. #include <X11/Xutil.h>
  1868. #endif
  1869. #endif
  1870.  
  1871. #define PixmapSuccess          0
  1872. #define PixmapOpenFailed       1
  1873. #define PixmapFileInvalid      2
  1874. #define PixmapNoMemory         3
  1875. #define PixmapParseColorFailed 4
  1876. #define PixmapAllocColorFailed 5
  1877.  
  1878.  
  1879. /* Global variables
  1880.  */
  1881.  
  1882. int XpmErrorStatus;
  1883. char *BCMT, *ECMT, BOS, EOS;
  1884.  
  1885. #define EOL '\n'
  1886. #define TAB '\t'
  1887. #define SPC ' '
  1888.  
  1889. typedef unsigned char  byte;      /* byte type */
  1890. typedef unsigned long  Pixel;     /* what X thinks a pixel is */
  1891.  
  1892. struct {
  1893.     char *type;            /* key word */
  1894.     char *Bcmt;            /* string begining comments */
  1895.     char *Ecmt;            /* string ending comments */
  1896.     char  Bos;            /* character begining strings */
  1897.     char  Eos;            /* character ending strings */
  1898.     char *Strs;            /* strings separator */
  1899.     char *Dec;            /* data declaration string */
  1900.     char *Boa;            /* string begining assignment */
  1901.     char *Eoa;            /* string ending assignment */
  1902. } DataTypes[] = {
  1903.     "", "!", "\n", '\0', '\n', "", "", "", "", /* Natural type */
  1904.     "C", "/*", "*/\n", '"', '"', ",\n", "static char **", " = {\n", "};\n",
  1905.     "Lisp", ";", "\n", '"', '"', "\n", "(setq ", " '(\n", "))\n",
  1906.     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
  1907. };
  1908.  
  1909. char *ColorKeys[] = {
  1910.     "s",            /* key #1: symbol */
  1911.     "m",            /* key #2: mono visual */
  1912.     "g4",            /* key #3: 4 grays visual */
  1913.     "g",            /* key #4: gray visual */
  1914.     "c",            /* key #5: color visual */
  1915. };
  1916. #define NKEYS 5            /* total number of Colorkeys */
  1917.  
  1918.  
  1919. typedef struct {
  1920.     char *name;
  1921.     char *value;
  1922. } ColorSymbol;
  1923.  
  1924. typedef struct {
  1925.     char *type;
  1926.     int ncolors;
  1927.     char ***colorTable;
  1928.     Pixel *pixels;
  1929.     char *hints_cmt;
  1930.     char *colors_cmt;
  1931.     char *pixels_cmt;
  1932. } XpmInfo;
  1933.  
  1934. #define MAXPRINTABLE 93             /* number of printable ascii chars 
  1935.                        minus \ and " for string compat. */
  1936.  
  1937. char *printable = 
  1938. " .XoO+@#$%&*=-;:?>,<1234567890qwertyuipasdfghjklzxcvbnmMNBVCZ\
  1939. ASDFGHJKLPIUYTREWQ!~^/()_`'][{}|" ;
  1940.            /* printable begin with a space, so in most case, due to
  1941.           my algorythm, when the number of different colors is
  1942.           less than MAXPRINTABLE, it will give a char follow by 
  1943.           "nothing" (a space) in the readable xpm file */
  1944.  
  1945.  
  1946. /* minimal portability layer between ansi and KR C 
  1947.  */
  1948.  
  1949. /* forward declaration of functions with prototypes */
  1950.  
  1951. #if __STDC__                /* ANSI */
  1952. #define FUNC(f, t, p) extern t f p
  1953. #define LFUNC(f, t, p) static t f p
  1954. #else                    /* K&R */
  1955. #define FUNC(f, t, p) extern t f()
  1956. #define LFUNC(f, t, p) static t f()
  1957. #endif                    /* end of K&R */
  1958.  
  1959. /* functions declarations
  1960.  */
  1961.  
  1962. FUNC(XCreatePixmapFromData, int, (Display *display,
  1963.                   Visual *visual,
  1964.                   Drawable d,
  1965.                   Colormap colormap,
  1966.                   char **data,
  1967.                   unsigned int depth,
  1968.                   Pixmap *pixmap_return,
  1969.                   unsigned int *width_return, 
  1970.                   unsigned int *height_return, 
  1971.                   Pixel **pixels_return,
  1972.                   unsigned int *npixels_return,
  1973.                   ColorSymbol colorsymbols[],
  1974.                   unsigned int numsymbols,
  1975.                   XpmInfo *infos));
  1976.  
  1977. FUNC(XReadPixmapFile, int, (Display *display,
  1978.                 Visual *visual,
  1979.                 Drawable d,
  1980.                 Colormap colormap,
  1981.                 char *filename,
  1982.                 unsigned int depth,
  1983.                 Pixmap *pixmap_return,
  1984.                 unsigned int *width_return, 
  1985.                 unsigned int *height_return, 
  1986.                 Pixel **pixels_return,
  1987.                 unsigned int *npixels_return,
  1988.                 ColorSymbol colorsymbols[],
  1989.                 unsigned int numsymbols,
  1990.                 XpmInfo *infos));
  1991.  
  1992. FUNC(XWritePixmapFile, int, (Display *display,
  1993.                  Colormap colormap,
  1994.                  char *filename,
  1995.                  Pixmap *pixmap,
  1996.                  unsigned int width,
  1997.                  unsigned int height,
  1998.                  char *type,
  1999.                  unsigned int cppm,
  2000.                  XpmInfo *infos));
  2001.  
  2002. FUNC(XFreeXpmInfo, int, (XpmInfo *infos));
  2003.  
  2004. #endif
  2005. END_OF_SHAR_FOR_xpm.h
  2006. cat > xpm.tex << \END_OF_SHAR_FOR_xpm.tex
  2007. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2008. %                              XPM MANUAL                                    %
  2009. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2010.  
  2011. % $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  2012. %
  2013. % adjust these for centering on the page:
  2014. % upper-left corner of frame in title page must be at 60mm,60mm from 
  2015. % upper-left corner of the page
  2016.  
  2017. % normal (A4) on our Apple Laserwriter with dvi2ps
  2018. %\hoffset 0cm
  2019. %\voffset 0cm
  2020. % normal (A4 & Letter) on our Apple Laserwriter with dvips v5.0
  2021. \hoffset -5.5mm
  2022. \voffset 0cm
  2023. % our imagen
  2024. %\hoffset -0.9cm
  2025. %\voffset -2.2cm
  2026.            
  2027. % NOTE: the following line MUST be commented out!
  2028. %\includeonly{standard}
  2029.  
  2030. \makeindex
  2031.  
  2032. \documentstyle[twoside,colas]{article}
  2033.  
  2034. % IF YOUR DVI PRINTER CHOKES ON INCLUDED POSTSCRIPT FILES
  2035. % by the \special command, uncomment the following line:
  2036. % \def\texpsfig#1#2#3{\fbox{Figure ``#1''}}
  2037.  
  2038.  
  2039. \pagestyle{headings}
  2040. \begin{document} 
  2041.  
  2042. \thispagestyle{empty}
  2043. \hbox{\colastitledisp
  2044. \vbox{
  2045. \vspace{3cm}
  2046. \begin{center}
  2047. \fboxrule 0.4pt \fboxsep 1pt
  2048. \fbox{\fboxrule 3pt \fboxsep 30pt \fbox{\Huge\bf XPM Manual}}
  2049. \end{center}
  2050. \vspace{2cm}
  2051. \begin{center}
  2052. \huge
  2053. The {\bf X} {\bf P}ix{\bf M}ap Format
  2054. \end{center}
  2055. \vspace{2cm}
  2056. \begin{center} 
  2057. \Large Version \RCSRevVersion$Version: 2.1 $\\
  2058. \end{center}
  2059. \vspace{2cm}
  2060. \begin{center}
  2061. \LARGE\sf Arnaud Le Hors\\
  2062. \large\tt lehors@mirsa.inria.fr
  2063. \end{center}
  2064. \vspace{1cm}
  2065. \vspace{1cm}
  2066. \begin{center}
  2067. \copyright BULL 1990
  2068. \end{center}
  2069. }}
  2070.  
  2071. \newpage
  2072.  
  2073. \section*{Copyright restrictions}
  2074. {\bf\begin{flushleft} 
  2075. Copyright 1990 GROUPE BULL\\
  2076. \end{flushleft}}
  2077.  
  2078. {\sf
  2079. Permission to use, copy, modify, and distribute this software and its
  2080. documentation for any purpose and without fee is hereby granted, provided
  2081. that the above copyright notice appear in all copies and that both that
  2082. copyright notice and this permission notice appear in supporting
  2083. documentation, and that the name of GROUPE BULL not be used in advertising
  2084. or publicity pertaining to distribution of the software without specific,
  2085. written prior permission.  GROUPE BULL makes no representations about the
  2086. suitability of this software for any purpose.  It is provided ``as is''
  2087. without express or implied warranty.
  2088.  
  2089. GROUPE BULL disclaims all warranties with regard to this software,
  2090. including all implied warranties of merchantability and fitness,
  2091. in no event shall GROUPE BULL be liable for any special,
  2092. indirect or consequential damages or any damages
  2093. whatsoever resulting from loss of use, data or profits,
  2094. whether in an action of contract, negligence or other tortious
  2095. action, arising out of or in connection with the use 
  2096. or performance of this software.
  2097. }
  2098.  
  2099. \section*{Acknowledgements}
  2100.  
  2101. I want to thank my team partner and friend Colas Nahaboo who proposed me this
  2102. project, and who actively participated to its design.
  2103.  
  2104. \begin{flushright}
  2105. {\Large Arnaud Le Hors.\quad}
  2106. {\small
  2107. KOALA Project -- BULL Research c/o INRIA\\
  2108. 2004 route des Lucioles -- 06565 Valbonne Cedex -- FRANCE\\
  2109. }
  2110. \end{flushright}
  2111.  
  2112. \section*{Support}
  2113.  
  2114. \sloppy 
  2115. You can mail any question or suggestion relative to {\bf XPM} by electronic
  2116. mail to {\tt lehors@mirsa.inria.fr}, and you can find the latest release by
  2117. anonymous ftp on avahi.inria.fr (192.5.60.47) or expo.lcs.mit.edu
  2118. (18.30.0.212).
  2119.  
  2120. \newpage
  2121. \section{Introduction}
  2122. First, Why another image format?  We (Koala team at Bull Research, France)
  2123. felt that most images bundled with X applications will be small "icons", and
  2124. that since many applications are color-customizable, existing image formats
  2125. such as gif, tiff, iff, etc... were intended for big images with well-defined
  2126. colors and so weren't adapted to the task.  So {\bf XPM} was designed with
  2127. these criterions in mind:
  2128. \begin{itemize}
  2129. \item be editable by hand (under emacs, vi...). Color pixmap editors aren't
  2130. available everywhere.
  2131. \item be includable in code either C, Lisp, ... It is unreasonable to load
  2132. 1000 pixmap files on each start of an application.
  2133. \item be a portable, mailable ascii format.
  2134. \item provide defaults for monochrome/color/grayscale renderings.
  2135. \item provide overriding of colors. This way if the user wants your
  2136. application
  2137. to be bluish instead of greenish, you can use the SAME icon files.
  2138. \item allow comments to be included in the file.
  2139. \end{itemize}
  2140.  
  2141. \newpage
  2142. \section{The {\bf XPM2} Format}
  2143.  
  2144. The {\bf XPM2} format presents different types of syntax, in order to provide
  2145. the ability to include {\bf XPM2} files in different languages. But the
  2146. different types are much alike if we consider the following type dependent
  2147. tokens: beginning and end of line, beginning and end of string, string
  2148. separator, beginning and end of comment, declaration string, beginning and end
  2149. of assignment. Depending on the type they may or may not exist.
  2150.  
  2151. The {\bf XPM2} format is conceptually an array of string. The Natural type
  2152. which is designed for manual editing is a syntax derived from the {\bf X}
  2153. resource file format, where strings are just lines ending with a newline
  2154. character and where comments start at an exclamation mark and end at the end
  2155. of the line.
  2156.  
  2157. The {\bf XPM2} format is composed of six different sections as follows:
  2158. {\tt
  2159. \begin{flushleft}
  2160. \hspace{1cm}<Header line>\\
  2161. \hspace{1cm}<Declaration and Beginning of Assignment line>\\
  2162. \hspace{1cm}<Hints>\\
  2163. \hspace{1cm}<Colors>\\
  2164. \hspace{1cm}<Pixels>\\
  2165. \hspace{1cm}<End of Assignment>
  2166. \end{flushleft}
  2167. }
  2168. The {\tt Header line} is composed as follows: 
  2169.  
  2170. {\tt <AnyWord>} XPM2 {\tt <Type>} {\tt <AnyWord>}
  2171.  
  2172. The words are separated by a white space which can be composed of space and
  2173. tabulation characters.  The {\tt AnyWord} can be anyone as it will just be
  2174. skipped, this is to allow any kind of language dependent comment string. The
  2175. {\tt Type} word defines the type of {\bf XPM2} format and thus the syntax of
  2176. the file being read. For now, this may be nothing for Natural type, C, or
  2177. Lisp.  The line must end by a newline character. From there, the different
  2178. type dependent syntax tokens are determined.
  2179.  
  2180. In case of Natural type, there is no {\tt Declaration and Beginning of
  2181. Assignment line}; otherwise it must end by a newline character and is composed
  2182. as follows: 
  2183.  
  2184. {\tt <Declaration string> <variable name> <Beginning of assignment>}
  2185.  
  2186. The {\tt Hints} section is composed of one line containing the four integers
  2187. in base 10, corresponding to the pixmap width and height, the number of colors
  2188. and the number of characters per pixel as follows:
  2189.  
  2190. {\tt <width> <height> <ncolors> <chars\_per\_pixel>}
  2191.  
  2192. The {\tt Colors} section is composed of as many lines as there are colors, and
  2193. each line is composed as follows: 
  2194.  
  2195. {\tt <chars> [[<key> <color>] ... ]}
  2196.  
  2197. Where {\tt chars} is the {\tt chars\_per\_pixel} length string (not surrounded
  2198. anything) representing the pixels, {\tt color} is the specified color, and
  2199. {\tt key} is a keyword describing in which context this color should be used.
  2200. For now these keys may have the following values:
  2201.  
  2202. \begin{tabbing}
  2203. \hspace{1cm}\= g4 \= for 4-level grayscale\kill
  2204. \> m  \>for mono visual\\
  2205. \> s  \> for symbolic name\\
  2206. \> g4 \> for 4-level grayscale\\
  2207. \> g  \> for grayscale with more than 4 levels\\
  2208. \> c  \> for color visual
  2209. \end{tabbing}
  2210.  
  2211. Colors can be specified by giving colorname, the RGB code following the \#
  2212. character, or the HSV code following the \% character (not implemented yet).
  2213. The symbolic name provides the ability of specifying the colors at load
  2214. time, and not to hard-code them in the file.
  2215.  
  2216. The {\tt Pixels} section is composed by {\tt height} strings of {\tt width} *
  2217. {\tt chars\_per\_pixel} characters, where every {\tt chars\_per\_pixel} length
  2218. string must be one of the previously defined in the {\tt Colors} section.
  2219.  
  2220. Finally the {\tt End of Assignment} section ends the format.
  2221.  
  2222.  
  2223. \newpage
  2224. \section{The {\bf XPM2} Library}
  2225.  
  2226. The {\bf XPM2} library provides three functions that you can use to read and
  2227. write a pixmap from and to a {\bf XPM2} format file, and to create a pixmap.
  2228. This section describes these functions.
  2229.  
  2230. \vspace{.5cm}
  2231. To provide a way to rewrite an {\bf XPM2} file without loosing information
  2232. such as comments, color defaults and symbols which may exist in the read file,
  2233. the {\bf XPM2} library defines the {\bf XpmInfo} structure to stores them.
  2234. This structure contains:
  2235.  
  2236. \begin{tabbing}
  2237.  
  2238. \hspace{1cm}\= Unsigned long *pixels; \= /* List of color pixels. */ \kill
  2239. typedef struct \{ \\
  2240. \> char *type; \> /* Type of {\bf XPM2} format: Natural, C, Lisp, ... */ \\
  2241. \> int ncolors; \> /* Number of colors. */ \\
  2242. \> char ***colorTable; \> /* Color table pointer. */ \\
  2243. \> Unsigned long *pixels; \> /* List of color pixels. */ \\
  2244. \> char *hints\_cmt; \> /* Comment of the hints section. */ \\
  2245. \> char *colors\_cmt; \> /* Comment of the colors section. */ \\
  2246. \> char *pixels\_cmt; \> /* Comment of the pixels section. */ \\
  2247. \} XpmInfo;
  2248.  
  2249. \end{tabbing}
  2250.  
  2251. The colorTable is a two dimensional array of strings, organized as follows:
  2252. \begin{flushleft}
  2253. \hspace{.5cm}colorTable[color\#][0] points to the character string associated
  2254. to the color.\\
  2255. \hspace{.5cm}colorTable[color\#][1] points to the symbolic name of the
  2256. color.\\
  2257. \hspace{.5cm}colorTable[color\#][2] points to the default color for monochrome
  2258. visuals.\\
  2259. \hspace{.5cm}colorTable[color\#][3] points to the default color for 4-level
  2260. grayscale visuals.\\
  2261. \hspace{.5cm}colorTable[color\#][4] points to the default color for other
  2262. grayscale visuals.\\
  2263. \hspace{.5cm}colorTable[color\#][5] points to the default color for color
  2264. visuals. 
  2265. \end{flushleft}
  2266.  
  2267. Comments are limited to a single comment string by section. If more exist in
  2268. the read file, then only the last comment of each section will be stored.
  2269.  
  2270. To get informations back while writting out to a file, you just have to pass a
  2271. pointer to an {\bf XpmInfo} structure to the {\bf XReadPixmapFile} {\bf XPM2}
  2272. function while reading the file, and then give it back to the {\bf
  2273. XWritePixmapFile} {\bf XPM2} function while writting.
  2274.  
  2275. \vspace{.5cm}
  2276. To allow overriding of colors at load time the {\bf XPM2} library defines the
  2277. {\bf ColorSymbol} structure which contains:
  2278.  
  2279. \begin{tabbing}
  2280. \hspace{1cm}\= char *value; \hspace{1.5cm}\= /* Color value */\kill
  2281. typedef struct \{\\
  2282. \> char *name; \> /* Symbolic color name */\\
  2283. \> char *value;\> /* Color value */\\
  2284. \} ColorSymbol;
  2285. \end{tabbing}
  2286.  
  2287. To override colors at load time, you just have to pass to the {\bf
  2288. XReadPixmapFile} or {\bf XCreatePixmapFromData} {\bf XPM2} functions a pointer
  2289. to a list of {\bf ColorSymbol} elements containing the desired colors.
  2290.  
  2291. \vspace{.5cm}
  2292. To read a pixmap from a file, use {\bf XReadPixmapFile}.
  2293.  
  2294. \begin{flushleft} 
  2295.  
  2296. int XReadPixmapFile({\it display, visual, d, colormap, filename, depth, \\
  2297. \hspace{3cm}pixmap\_return, width\_return, height\_return, \\
  2298. \hspace{3cm}pixels\_return, npixels\_return, \\
  2299. \hspace{3cm}colorsymbols, numsymbols, infos})\\
  2300.  
  2301. \hspace{1cm}Display {\it *display;}\\
  2302. \hspace{1cm}Visual {\it *visual;}\\
  2303. \hspace{1cm}Drawable {\it d;}\\
  2304. \hspace{1cm}Colormap {\it colormap;}\\
  2305. \hspace{1cm}char {\it *filename;}\\
  2306. \hspace{1cm}unsigned int {\it depth;}\\
  2307. \hspace{1cm}Pixmap {\it *pixmap\_return;}\\
  2308. \hspace{1cm}unsigned int {\it *width\_return, *height\_return;}\\
  2309. \hspace{1cm}unsigned long {\it **pixels\_return;}\\
  2310. \hspace{1cm}unsigned int {\it *npixels\_return;}\\
  2311. \hspace{1cm}ColorSymbol {\it colorsymbols[];}\\
  2312. \hspace{1cm}unsigned int {\it numsymbols;}\\
  2313. \hspace{1cm}XpmInfo {\it *infos;}
  2314.  
  2315. \end{flushleft}
  2316.  
  2317. \begin{description}
  2318.  
  2319. \itemit{display} Specifies the connection to the X server.
  2320. \itemit{visual} Specifies a pointer to the visual.
  2321. \itemit{d} Specifies the drawable that indicates the screen.
  2322. \itemit{colormap} Specifies the colormap to use.
  2323. \itemit{filename} Specifies the file name to use.
  2324. \itemit{depth} Specifies the depth.
  2325. \itemit{pixmap\_return} Returns the pixmap which is created.
  2326. \itemit{width\_return}
  2327. \itemit{height\_return} Return the width and height values of the read pixmap
  2328. file.
  2329. \itemit{pixels\_return} Returns the list of color pixels which have been
  2330. allocated.
  2331. \itemit{npixels\_return} Returns the length of the returned color pixels list.
  2332. \itemit{colorsymbols} Specifies an array of color symbols for overriding.
  2333. \itemit{numsymbols} Specifies the number of symbols.
  2334. \itemit{infos} Specifies the location of an {\bf XpmInfo} structure to store
  2335. informations. 
  2336.  
  2337. \end{description} 
  2338.  
  2339. The {\bf XReadPixmapFile} function reads in a file containing a pixmap in the
  2340. {\bf XPM2} format. If the file cannot be opened, {\bf XReadPixmapFile} returns
  2341. {\bf PixmapOpenFailed}. If the file can be opened but does not contain valid
  2342. {\bf XPM2} pixmap data, it returns {\bf PixmapFileInvalid}. If insufficient
  2343. working storage is allocated, it returns {\bf PixmapNoMemory}. If parsing a
  2344. color fails, it returns {\bf PixmapParseColorFailed}. If allocating a color
  2345. cell fails, it returns {\bf PixmapAllocColorFailed}. Finally if no error
  2346. occurs, it returns {\bf PixmapSuccess}.
  2347.  
  2348. {\bf XReadPixmapFile} returns the pixmap's height and width, as read from the
  2349. file, to width\_return and height\_return. It reads the colors and pixels data
  2350. from the file. It allocates colors, as read from the file or possibly
  2351. overridden as specified in the given colorsymbols array.  The colors are
  2352. allocated dependently on the type of visual and on the default colors. If no
  2353. default value exits for the specified visual, it first looks for other
  2354. defaults nearer to the monochrome visual type and secondly nearer to the color
  2355. visual type. Then it creates a pixmap of the appropriate size, which is
  2356. returned to pixmap\_return.  If a pointer to an {\bf XpmInfo} structure, other
  2357. than {\bf NULL}, is passed {\bf XReadPixmapFile} stores in it possible
  2358. comments, color defaults and symbols, and color pixels.  The caller must free
  2359. the pixmap using {\bf XFreePixmap}, the colors using {\bf XFreeColors} with
  2360. the returned pixels list, and finally the {\bf XpmInfo} if any using {\bf
  2361. XFreeXpmInfo} when finished.
  2362.  
  2363. \vspace{.5cm}
  2364. To write out a pixmap to a file, use {\bf XWritePixmapFile}.
  2365.  
  2366. \begin{flushleft} 
  2367.  
  2368. int XWritePixmapFile({\it display, colormap, filename, pixmap, width,
  2369. height,\\
  2370. \hspace{3cm}type, cppm, infos})\\
  2371.  
  2372. \hspace{1cm}Display {\it *display;}\\
  2373. \hspace{1cm}Colormap {\it colormap;}\\
  2374. \hspace{1cm}char {\it *filename;}\\
  2375. \hspace{1cm}Pixmap {\it *pixmap;}\\
  2376. \hspace{1cm}unsigned int {\it width, height;}\\
  2377. \hspace{1cm}char {\it *type;}\\
  2378. \hspace{1cm}unsigned int {\it cppm;}\\
  2379. \hspace{1cm}XpmInfo {\it *infos;}
  2380.  
  2381. \end{flushleft}
  2382.  
  2383. \begin{description}
  2384.  
  2385. \itemit{display} Specifies the connection to the X server.
  2386. \itemit{colormap} Specifies the colormap.
  2387. \itemit{filename} Specifies the file name to use.
  2388. \itemit{pixmap} Specifies the pixmap which is created.
  2389. \itemit{width}
  2390. \itemit{height} Specifies the width and height of the pixmap.
  2391. file.
  2392. \itemit{type} Specifies the type of {\bf XPM2} format.
  2393. \itemit{cppm} Specifies a minimum number of characters per pixels.
  2394. \itemit{infos} Specifies the location of an {\bf XpmInfo} structure containing
  2395. informations. 
  2396.  
  2397. \end{description} 
  2398.  
  2399. The {\bf XWritePixmapFile} function writes a pixmap out to a file in the {\bf
  2400. XPM2} format. If the file cannot be opened, it returns {\bf PixmapOpenFailed}.
  2401. If the specified type is not valid, it returns {\bf PixmapFileInvalid}. If
  2402. insufficient working storage is allocated, it returns {\bf PixmapNoMemory}. If
  2403. no error occurs then it returns {\bf PixmapSuccess}.
  2404.  
  2405. {\bf XWritePixmapFile} writes out in the type format specified in argument,
  2406. stored in the {\bf XpmInfo} structure if any is given, or in Natural type by
  2407. default.  If a {\bf XpmInfo} structure is passed, it will writes out possible
  2408. stored informations such as comments, and color defaults and symbols.
  2409.  
  2410. \vspace{.5cm}
  2411. To create a pixmap from file written out by {\bf XWritePixmapFile} and
  2412. directly include in a program, use {\bf XCreatePixmapFromData}.
  2413.  
  2414. \begin{flushleft} 
  2415.  
  2416. int XCreatePixmapFromData({\it display, visual, d, colormap, data, depth, \\
  2417. \hspace{3cm}pixmap\_return, width\_return, height\_return, \\
  2418. \hspace{3cm}pixels\_return, npixels\_return, \\
  2419. \hspace{3cm}colorsymbols, numsymbols, infos})\\
  2420.  
  2421. \hspace{1cm}Display {\it *display;}\\
  2422. \hspace{1cm}Visual {\it *visual;}\\
  2423. \hspace{1cm}Drawable {\it d;}\\
  2424. \hspace{1cm}Colormap {\it colormap;}\\
  2425. \hspace{1cm}char {\it **data;}\\
  2426. \hspace{1cm}unsigned int {\it depth;}\\
  2427. \hspace{1cm}Pixmap {\it *pixmap\_return;}\\
  2428. \hspace{1cm}unsigned int {\it *width\_return, *height\_return;}\\
  2429. \hspace{1cm}unsigned long {\it **pixels\_return;}\\
  2430. \hspace{1cm}unsigned int {\it *npixels\_return;}\\
  2431. \hspace{1cm}ColorSymbol {\it colorsymbols[];}\\
  2432. \hspace{1cm}unsigned int {\it numsymbols;}\\
  2433. \hspace{1cm}XpmInfo {\it *infos;}
  2434.  
  2435. \end{flushleft}
  2436.  
  2437. \begin{description}
  2438.  
  2439. \itemit{display} Specifies the connection to the X server.
  2440. \itemit{visual} Specifies a pointer to the visual.
  2441. \itemit{d} Specifies the drawable that indicates the screen.
  2442. \itemit{colormap} Specifies the colormap to use.
  2443. \itemit{data} Specifies the location of the pixmap data.
  2444. \itemit{depth} Specifies the depth.
  2445. \itemit{pixmap\_return} Returns the pixmap which is created.
  2446. \itemit{width\_return}
  2447. \itemit{height\_return} Return the width and height values of the read pixmap
  2448. data.
  2449. \itemit{pixels\_return} Returns the list of color pixels which have been
  2450. allocated.
  2451. \itemit{npixels\_return} Returns the length of the returned color pixels list.
  2452. \itemit{colorsymbols} Specifies an array of color symbols which for
  2453. overriding.
  2454. \itemit{numsymbols} Specifies the number of symbols.
  2455. \itemit{infos} Specifies the location of an {\bf XpmInfo} structure to store
  2456. informations. 
  2457.  
  2458. \end{description} 
  2459.  
  2460. The {\bf XCreatePixmapFromData} function allows you to include in your program
  2461. a pixmap file of the corresponding type (C, Lisp, ...) which was written out
  2462. by {\bf XWritePixmapFile} ({\bf XPM2} format only) without reading in the
  2463. pixmap file.
  2464.  
  2465. {\bf XCreatePixmapFromData} exactly works as {\bf XReadPixmapFile} does and
  2466. returns the same way. It just reads data instead of a file. Here again, it is
  2467. the caller's responsibility to free the pixmap, the colors, and possibly the
  2468. {\bf XpmInfo} structure.
  2469.  
  2470. \vspace{.5cm}
  2471. To free an {\bf XpmInfo} structure use {\bf XFreeXpmInfo}.
  2472.  
  2473. \begin{flushleft} 
  2474.  
  2475. int XFreeXpmInfo({\it infos})\\
  2476.  
  2477. \hspace{1cm}XpmInfo {\it *infos;}
  2478.  
  2479. \end{flushleft}
  2480.  
  2481. \begin{description}
  2482.  
  2483. \itemit{infos} Specifies the structure to free.
  2484.  
  2485. \end{description}
  2486.  
  2487. The {\bf XFreeXpmInfo} frees all the different members of the structure: the
  2488. character strings and the ColorTable. 
  2489.  
  2490. \end{document} 
  2491. END_OF_SHAR_FOR_xpm.tex
  2492. cat > xpmP.h << \END_OF_SHAR_FOR_xpmP.h
  2493. /* Copyright 1990 GROUPE BULL -- See licence conditions in file COPYRIGHT */
  2494. /* xpmP.h:
  2495.  *
  2496.  *  XPM2
  2497.  *  Private Include file
  2498.  *  Developped by Arnaud Le Hors
  2499.  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
  2500.  */
  2501.  
  2502. #ifndef XPMP_h
  2503. #define XPMP_h
  2504.  
  2505. #include <X11/Xlib.h>
  2506. #include<stdio.h>
  2507.  
  2508. /* we keep the same codes as for Bitmap management */
  2509. #ifndef _XUTIL_H_
  2510. #ifdef VMS
  2511. #include "decw$include:Xutil.h"
  2512. #else
  2513. #include <X11/Xutil.h>
  2514. #endif
  2515. #endif
  2516.  
  2517. typedef struct {
  2518.     unsigned int type;
  2519.     void         *stream;
  2520.     char         *cptr;
  2521.     unsigned int line;
  2522. } MData;
  2523.  
  2524. #define PixmapSuccess          0
  2525. #define PixmapOpenFailed       1
  2526. #define PixmapFileInvalid      2
  2527. #define PixmapNoMemory         3
  2528. #define PixmapParseColorFailed 4
  2529. #define PixmapAllocColorFailed 5
  2530.  
  2531.  
  2532. #define MARRAY 0
  2533. #define MFILE  1
  2534.  
  2535. extern int XpmErrorStatus;
  2536.  
  2537. typedef unsigned char  byte;      /* byte type */
  2538. typedef unsigned long  Pixel;     /* what X thinks a pixel is */
  2539.  
  2540. extern char *BCMT, *ECMT, BOS, EOS;
  2541.  
  2542. #define EOL '\n'
  2543. #define TAB '\t'
  2544. #define SPC ' '
  2545.  
  2546. extern struct {
  2547.     char *type;            /* key word */
  2548.     char *Bcmt;            /* string begining comments */
  2549.     char *Ecmt;            /* string ending comments */
  2550.     char  Bos;            /* character begining strings */
  2551.     char  Eos;            /* character ending strings */
  2552.     char *Strs;            /* strings separator */
  2553.     char *Dec;            /* data declaration string */
  2554.     char *Boa;            /* string begining assignment */
  2555.     char *Eoa;            /* string ending assignment */
  2556. } DataTypes[];
  2557.  
  2558. typedef struct {
  2559.     char *name;
  2560.     char *value;
  2561. } ColorSymbol;
  2562.  
  2563. typedef struct {
  2564.     char *type;
  2565.     int ncolors;
  2566.     char ***colorTable;
  2567.     Pixel *pixels;
  2568.     char *hints_cmt;
  2569.     char *colors_cmt;
  2570.     char *pixels_cmt;
  2571. } XpmInfo;
  2572.  
  2573. extern char *ColorKeys[];
  2574. #define NKEYS 5            /* number of ColorKeys */
  2575.  
  2576. #define MONO    2        /* key numbers for visual type, they must */
  2577. #define GRAY4    3        /* fit along with the number key of each */
  2578. #define GRAY     4        /* corresponding element in ColorKeys[] */
  2579. #define COLOR    5        /* defined in xpm.h */
  2580.  
  2581.  
  2582. #define MAXPRINTABLE 93             /* number of printable ascii chars 
  2583.                        minus \ and " for string compat. */
  2584. extern char *printable;
  2585.  
  2586. /* minimal portability layer between ansi and KR C 
  2587.  */
  2588.  
  2589. /* forward declaration of functions with prototypes */
  2590.  
  2591. #if __STDC__                /* ANSI */
  2592. #define FUNC(f, t, p) extern t f p
  2593. #define LFUNC(f, t, p) static t f p
  2594. #else                    /* K&R */
  2595. #define FUNC(f, t, p) extern t f()
  2596. #define LFUNC(f, t, p) static t f()
  2597. #endif                    /* end of K&R */
  2598.  
  2599. /* functions declarations
  2600.  */
  2601.  
  2602. FUNC(XCreatePixmapFromData, int, (Display *display,
  2603.                   Visual *visual,
  2604.                   Drawable d,
  2605.                   Colormap colormap,
  2606.                   char **data,
  2607.                   unsigned int depth,
  2608.                   Pixmap *pixmap_return,
  2609.                   unsigned int *width_return, 
  2610.                   unsigned int *height_return, 
  2611.                   Pixel **pixels_return,
  2612.                   unsigned int *npixels_return,
  2613.                   ColorSymbol colorsymbols[],
  2614.                   unsigned int numsymbols,
  2615.                   XpmInfo *infos));
  2616.  
  2617. FUNC(XReadPixmapFile, int, (Display *display,
  2618.                 Visual *visual,
  2619.                 Drawable d,
  2620.                 Colormap colormap,
  2621.                 char *filename,
  2622.                 unsigned int depth,
  2623.                 Pixmap *pixmap_return,
  2624.                 unsigned int *width_return, 
  2625.                 unsigned int *height_return, 
  2626.                 Pixel **pixels_return,
  2627.                 unsigned int *npixels_return,
  2628.                 ColorSymbol colorsymbols[],
  2629.                 unsigned int numsymbols,
  2630.                 XpmInfo *infos));
  2631.  
  2632. FUNC(XWritePixmapFile, int, (Display *display,
  2633.                  Colormap colormap,
  2634.                  char *filename,
  2635.                  Pixmap *pixmap,
  2636.                  unsigned int width,
  2637.                  unsigned int height,
  2638.                  char *type,
  2639.                  unsigned int cppm,
  2640.                  XpmInfo *infos));
  2641.  
  2642. FUNC(XFreeXpmInfo, int, (XpmInfo *infos));
  2643.  
  2644. /* XPM private routines */
  2645. FUNC(CreatePixmap, Pixmap, (Display *display,
  2646.                 Visual *visual,
  2647.                 Drawable d,
  2648.                 Colormap colormap,
  2649.                 MData *data,
  2650.                 unsigned int depth,
  2651.                 unsigned int *width_return, 
  2652.                 unsigned int *height_return, 
  2653.                 Pixel **pixels_return,
  2654.                 unsigned int *npixels_return,
  2655.                 ColorSymbol colorsymbols[],
  2656.                 unsigned int numsymbols,
  2657.                 XpmInfo *infos));
  2658.  
  2659. FUNC(visualType, int, (Visual *visual));
  2660. FUNC(freeColorTable, int, (char ***colorTable, int ncolors));
  2661.  
  2662. /* I/O utility */
  2663. FUNC(mnextstring, int, (MData *mdata));
  2664. FUNC(mnextui, unsigned int, (MData *mdata));
  2665. FUNC(mgetc, char, (MData *mdata));
  2666. FUNC(mungetc, char, (int c, MData *mdata));
  2667. FUNC(mnextc, char, (MData *mdata));
  2668. FUNC(mnextw, unsigned int, (MData *mdata, char *buf));
  2669. FUNC(mgetcmt, int, (MData *mdata, char **cmt));
  2670.  
  2671. /* Values routines */
  2672. FUNC(valToMem, void, (unsigned long val, byte *p, unsigned int len));
  2673. FUNC(memToVal, unsigned long, (byte *p, unsigned int len));
  2674.  
  2675.  
  2676. #endif
  2677. END_OF_SHAR_FOR_xpmP.h
  2678.