home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / xpm / XpmRdFToI.c < prev    next >
C/C++ Source or Header  |  2000-07-29  |  3KB  |  111 lines

  1. /* Copyright 1990-92 GROUPE BULL -- See license conditions in file COPYRIGHT */
  2. /*****************************************************************************\
  3. * XpmRdFToI.c:                                                                *
  4. *                                                                             *
  5. *  XPM library                                                                *
  6. *  Parse an XPM file and create the image and possibly its mask               *
  7. *                                                                             *
  8. *  Developed by Arnaud Le Hors                                                *
  9. \*****************************************************************************/
  10.  
  11. #include "xpmP.h"
  12.  
  13. xpmDataType xpmDataTypes[] =
  14. {
  15.  "", "!", "\n", '\0', '\n', "", "", "", "",    /* Natural type */
  16.  "C", "/*", "*/", '"', '"', ",\n", "static char *", "[] = {\n", "};\n",
  17.  "Lisp", ";", "\n", '"', '"', "\n", "(setq ", " '(\n", "))\n",
  18. #ifdef VMS
  19.  NULL
  20. #else
  21.  NULL, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL
  22. #endif
  23. };
  24.  
  25. int
  26. XpmReadFileToImage(display, filename, image_return,
  27.            shapeimage_return, attributes)
  28.     Display *display;
  29.     char *filename;
  30.     XImage **image_return;
  31.     XImage **shapeimage_return;
  32.     XpmAttributes *attributes;
  33. {
  34.     xpmData mdata;
  35.     char buf[BUFSIZ];
  36.     int l, n = 0;
  37.     int ErrorStatus;
  38.     xpmInternAttrib attrib;
  39.  
  40.     /*
  41.      * initialize return values 
  42.      */
  43.     if (image_return)
  44.     *image_return = NULL;
  45.     if (shapeimage_return)
  46.     *shapeimage_return = NULL;
  47.  
  48.     if ((ErrorStatus = xpmReadFile(filename, &mdata)) != XpmSuccess)
  49.     return (ErrorStatus);
  50.  
  51.     xpmInitInternAttrib(&attrib);
  52.  
  53.     /*
  54.      * parse the header file 
  55.      */
  56.     mdata.Bos = '\0';
  57.     mdata.Eos = '\n';
  58.     mdata.Bcmt = mdata.Ecmt = NULL;
  59.     xpmNextWord(&mdata, buf);        /* skip the first word */
  60.     l = xpmNextWord(&mdata, buf);    /* then get the second word */
  61.     if ((l == 3 && !strncmp("XPM", buf, 3)) ||
  62.     (l == 4 && !strncmp("XPM2", buf, 4))) {
  63.     if (l == 3)
  64.         n = 1;            /* handle XPM as XPM2 C */
  65.     else {
  66.         l = xpmNextWord(&mdata, buf); /* get the type key word */
  67.  
  68.         /*
  69.          * get infos about this type 
  70.          */
  71.         while (xpmDataTypes[n].type
  72.            && strncmp(xpmDataTypes[n].type, buf, l))
  73.         n++;
  74.     }
  75.     if (xpmDataTypes[n].type) {
  76.         if (n == 0) {        /* natural type */
  77.         mdata.Bcmt = xpmDataTypes[n].Bcmt;
  78.         mdata.Ecmt = xpmDataTypes[n].Ecmt;
  79.         xpmNextString(&mdata);    /* skip the end of headerline */
  80.         mdata.Bos = xpmDataTypes[n].Bos;
  81.         } else {
  82.         xpmNextString(&mdata);    /* skip the end of headerline */
  83.         mdata.Bcmt = xpmDataTypes[n].Bcmt;
  84.         mdata.Ecmt = xpmDataTypes[n].Ecmt;
  85.         mdata.Bos = xpmDataTypes[n].Bos;
  86.         mdata.Eos = '\0';
  87.         xpmNextString(&mdata);    /* skip the assignment line */
  88.         }
  89.         mdata.Eos = xpmDataTypes[n].Eos;
  90.  
  91.         ErrorStatus = xpmParseData(&mdata, &attrib, attributes);
  92.  
  93.         if (ErrorStatus == XpmSuccess)
  94.         ErrorStatus = xpmCreateImage(display, &attrib, image_return,
  95.                                              shapeimage_return, attributes);
  96.     } else
  97.         ErrorStatus = XpmFileInvalid;
  98.     } else
  99.     ErrorStatus = XpmFileInvalid;
  100.  
  101.     if (ErrorStatus >= 0)
  102.     xpmSetAttributes(&attrib, attributes);
  103.     else if (attributes)
  104.     XpmFreeAttributes(attributes);
  105.  
  106.     xpmFreeInternAttrib(&attrib);
  107.     XpmDataClose(&mdata);
  108.  
  109.     return (ErrorStatus);
  110. }
  111.