home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / lib / fs / FSFontInfo.c.orig < prev    next >
Encoding:
Text File  |  1991-05-13  |  7.2 KB  |  256 lines

  1. /* $XConsortium: FSFontInfo.c,v 1.2 91/05/13 15:11:37 gildea Exp $ */
  2.  
  3. /* @(#)FSFontInfo.c    4.1    91/05/02
  4.  * Copyright 1990 Network Computing Devices;
  5.  * Portions Copyright 1987 by Digital Equipment Corporation and the
  6.  * Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this protoype software
  9.  * and its documentation to Members and Affiliates of the MIT X Consortium
  10.  * any purpose and without fee is hereby granted, provided
  11.  * that the above copyright notice appear in all copies and that both that
  12.  * copyright notice and this permission notice appear in supporting
  13.  * documentation, and that the names of Network Computing Devices, Digital or
  14.  * MIT not be used in advertising or publicity pertaining to distribution of
  15.  * the software without specific, written prior permission.
  16.  *
  17.  * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
  18.  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  19.  * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
  20.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  21.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  22.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  23.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  */
  25.  
  26. #include    "FSlibint.h"
  27.  
  28. char      **
  29. FSListFontsWithXInfo(svr, pattern, maxNames, count, info, pprops, offsets, prop_data)
  30.     FSServer   *svr;
  31.     char       *pattern;
  32.     int         maxNames;
  33.     int        *count;
  34.     fsFontHeader ***info;
  35.     fsPropInfo ***pprops;
  36.     fsPropOffset ***offsets;
  37.     unsigned char ***prop_data;
  38. {
  39.     long        nbytes;
  40.     int         i,
  41.                 j;
  42.     int         size = 0;
  43.     fsFontHeader **fhdr = (fsFontHeader **) 0;
  44.     fsPropInfo **pi = (fsPropInfo **) 0;
  45.     fsPropOffset **po = (fsPropOffset **) 0;
  46.     unsigned char **pd = (unsigned char **) 0;
  47.     char      **flist = NULL;
  48.     fsListFontsWithXInfoReply reply;
  49.     fsListFontsWithXInfoReq *req;
  50.  
  51.     GetReq(ListFontsWithXInfo, req);
  52.     req->maxNames = maxNames;
  53.     nbytes = req->nbytes = pattern ? strlen(pattern) : 0;
  54.     req->length += (nbytes + 3) >> 2;
  55.     _FSSend(svr, pattern, nbytes);
  56.  
  57.     for (i = 0;; i++) {
  58.     if (!_FSReply(svr, (fsReply *) & reply,
  59.               ((SIZEOF(fsListFontsWithXInfoReply) -
  60.             SIZEOF(fsGenericReply)) >> 2), fsFalse)) {
  61.         for (j = (i - 1); j >= 0; j--) {
  62.         FSfree((char *) fhdr[j]);
  63.         FSfree((char *) pi[j]);
  64.         FSfree((char *) po[j]);
  65.         FSfree((char *) pd[j]);
  66.         FSfree(flist[j]);
  67.         }
  68.         if (flist)
  69.         FSfree((char *) flist);
  70.         if (fhdr)
  71.         FSfree((char *) fhdr);
  72.         if (pi)
  73.         FSfree((char *) pi);
  74.         if (po)
  75.         FSfree((char *) po);
  76.         if (pd)
  77.         FSfree((char *) pd);
  78.  
  79.         SyncHandle();
  80.         return (char **) NULL;
  81.     }
  82.     if (reply.nameLength == 0)    /* got last reply */
  83.         break;
  84.     if ((i + reply.nReplies) >= size) {
  85.         size = i + reply.nReplies + 1;
  86.  
  87.         if (fhdr) {
  88.         fsFontHeader **tmp_fhdr = (fsFontHeader **)
  89.         FSrealloc((char *) fhdr,
  90.               (unsigned) (sizeof(fsFontHeader *) * size));
  91.         char      **tmp_flist = (char **) FSrealloc((char *) flist,
  92.                      (unsigned) (sizeof(char *) * size));
  93.         fsPropInfo **tmp_pi = (fsPropInfo **)
  94.         FSrealloc((char *) pi,
  95.               (unsigned) (sizeof(fsPropInfo *) * size));
  96.         fsPropOffset **tmp_po = (fsPropOffset **)
  97.         FSrealloc((char *) po,
  98.               (unsigned) (sizeof(fsPropOffset *) * size));
  99.         unsigned char **tmp_pd = (unsigned char **)
  100.         FSrealloc((char *) pd,
  101.               (unsigned) (sizeof(unsigned char *) * size));
  102.  
  103.         if (!tmp_fhdr || !tmp_flist || !tmp_pi || !tmp_po || !tmp_pd) {
  104.             for (j = (i - 1); j >= 0; j--) {
  105.             FSfree((char *) flist[j]);
  106.             FSfree((char *) fhdr[j]);
  107.             FSfree((char *) pi[j]);
  108.             FSfree((char *) po[j]);
  109.             FSfree((char *) pd[j]);
  110.             }
  111.             if (tmp_flist)
  112.             FSfree((char *) tmp_flist);
  113.             else
  114.             FSfree((char *) flist);
  115.             if (tmp_fhdr)
  116.             FSfree((char *) tmp_fhdr);
  117.             else
  118.             FSfree((char *) fhdr);
  119.             if (tmp_pi)
  120.             FSfree((char *) tmp_pi);
  121.             else
  122.             FSfree((char *) pi);
  123.             if (tmp_po)
  124.             FSfree((char *) tmp_po);
  125.             else
  126.             FSfree((char *) po);
  127.             if (tmp_pd)
  128.             FSfree((char *) tmp_pd);
  129.             else
  130.             FSfree((char *) pd);
  131.             goto clearwire;
  132.         }
  133.         fhdr = tmp_fhdr;
  134.         flist = tmp_flist;
  135.         pi = tmp_pi;
  136.         po = tmp_po;
  137.         pd = tmp_pd;
  138.         } else {
  139.         if (!(fhdr = (fsFontHeader **)
  140.               FSmalloc((unsigned) (sizeof(fsFontHeader *) * size))))
  141.             goto clearwire;
  142.         if (!(flist = (char **)
  143.               FSmalloc((unsigned) (sizeof(char *) * size)))) {
  144.             FSfree((char *) fhdr);
  145.             goto clearwire;
  146.         }
  147.         if (!(pi = (fsPropInfo **)
  148.               FSmalloc((unsigned) (sizeof(fsPropInfo *) * size)))) {
  149.             FSfree((char *) fhdr);
  150.             FSfree((char *) flist);
  151.             goto clearwire;
  152.         }
  153.         if (!(po = (fsPropOffset **)
  154.               FSmalloc((unsigned) (sizeof(fsPropOffset *) * size)))) {
  155.             FSfree((char *) fhdr);
  156.             FSfree((char *) flist);
  157.             FSfree((char *) pi);
  158.             goto clearwire;
  159.         }
  160.         if (!(pd = (unsigned char **)
  161.             FSmalloc((unsigned) (sizeof(unsigned char *) * size)))) {
  162.             FSfree((char *) fhdr);
  163.             FSfree((char *) flist);
  164.             FSfree((char *) pi);
  165.             FSfree((char *) po);
  166.             goto clearwire;
  167.         }
  168.         }
  169.     }
  170.     fhdr[i] = (fsFontHeader *) FSmalloc(sizeof(fsFontHeader));
  171.     if (!fhdr[i]) {
  172.         goto badmem;
  173.     }
  174.     bcopy((char *) &reply.header, (char *) fhdr[i], sizeof(fsFontHeader));
  175.  
  176.     /* get the name */
  177.     flist[i] = (char *) FSmalloc((unsigned int) (reply.nameLength + 1));
  178.     if (!flist[i]) {
  179.         nbytes = reply.nameLength + 3 & ~3;
  180.         _FSEatData(svr, (unsigned long) nbytes);
  181.         goto badmem;
  182.     }
  183.     _FSReadPad(svr, flist[i], (long) reply.nameLength);
  184.     flist[i][reply.nameLength] = '\0';
  185.  
  186.     pi[i] = (fsPropInfo *) FSmalloc(sizeof(fsPropInfo));
  187.     if (!pi[i]) {
  188.         FSfree((char *) fhdr[i]);
  189.         goto badmem;
  190.     }
  191.     _FSReadPad(svr, (char *) pi[i], sizeof(fsPropInfo));
  192.  
  193.     po[i] = (fsPropOffset *)
  194.         FSmalloc(pi[i]->num_offsets * sizeof(fsPropOffset));
  195.     if (!po[i]) {
  196.         FSfree((char *) fhdr[i]);
  197.         FSfree((char *) pi[i]);
  198.         goto badmem;
  199.     }
  200.     pd[i] = (unsigned char *) FSmalloc(pi[i]->data_len);
  201.     if (!pd[i]) {
  202.         FSfree((char *) fhdr[i]);
  203.         FSfree((char *) pi[i]);
  204.         FSfree((char *) po[i]);
  205.         goto badmem;
  206.     }
  207.     /* get offsets */
  208.     _FSReadPad(svr, (char *) po[i],
  209.            (pi[i]->num_offsets * sizeof(fsPropOffset)));
  210.     /* get prop data */
  211.     _FSReadPad(svr, (char *) pd[i], pi[i]->data_len);
  212.  
  213.     }
  214.     *info = fhdr;
  215.     *count = i;
  216.     *pprops = pi;
  217.     *offsets = po;
  218.     *prop_data = pd;
  219.     SyncHandle();
  220.     return flist;
  221.  
  222. badmem:
  223.     for (j = (i - 1); j >= 0; j--) {
  224.     FSfree((char *) pi[j]);
  225.     FSfree((char *) po[j]);
  226.     FSfree((char *) pd[j]);
  227.     FSfree(flist[j]);
  228.     FSfree((char *) fhdr[j]);
  229.     }
  230.     if (flist)
  231.     FSfree((char *) flist);
  232.     if (fhdr)
  233.     FSfree((char *) fhdr);
  234.     if (pi)
  235.     FSfree((char *) pi);
  236.     if (po)
  237.     FSfree((char *) po);
  238.     if (pd)
  239.     FSfree((char *) pd);
  240.  
  241.  
  242. clearwire:
  243.     do {
  244.     fsPropInfo  ti;
  245.  
  246.     _FSEatData(svr, (reply.nameLength + 3) & ~3);
  247.     _FSReadPad(svr, (char *) &ti, sizeof(fsPropInfo));
  248.     _FSEatData(svr, (sizeof(fsPropOffset) * ti.num_offsets));
  249.     _FSEatData(svr, ti.data_len);
  250.     } while (_FSReply(svr, (fsReply *) & reply,
  251.               ((SIZEOF(fsListFontsWithXInfoReply)
  252.        - SIZEOF(fsGenericReply)) >> 2), fsFalse) && (reply.nameLength != 0));
  253.     SyncHandle();
  254.     return (char **) NULL;
  255. }
  256.