home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / lib / fs / FSFtNames.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-13  |  2.8 KB  |  95 lines

  1. /* $XConsortium: FSFtNames.c,v 1.2 91/05/13 15:11:40 gildea Exp $ */
  2.  
  3. /* @(#)FSFtNames.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. FSListFonts(svr, pattern, maxNames, actualCount)
  30.     FSServer   *svr;
  31.     char       *pattern;
  32.     int         maxNames;
  33.     int        *actualCount;
  34. {
  35.     long        nbytes;
  36.     int         i,
  37.                 length;
  38.     char      **flist;
  39.     char       *c;
  40.     fsListFontsReply rep;
  41.     fsListFontsReq *req;
  42.     long        rlen;
  43.  
  44.     GetReq(ListFonts, req);
  45.     req->maxNames = maxNames;
  46.     nbytes = req->nbytes = pattern ? strlen(pattern) : 0;
  47.     req->length += (nbytes + 3) >> 2;
  48.     _FSSend(svr, pattern, nbytes);
  49.     if (!_FSReply(svr, (fsReply *) & rep,
  50.       (sizeof(fsListFontsReply) - sizeof(fsGenericReply)) >> 2, fsFalse))
  51.     return (char **) 0;
  52.  
  53.     if (rep.nFonts) {
  54.     flist = (char **) FSmalloc((unsigned) rep.nFonts * sizeof(char *));
  55.     rlen = (rep.length << 2) - sizeof(fsListFontsReply);
  56.     c = (char *) FSmalloc((unsigned) (rlen + 1));
  57.  
  58.     if ((!flist) || (!c)) {
  59.         if (flist)
  60.         FSfree((char *) flist);
  61.         if (c)
  62.         FSFree(c);
  63.         _FSEatData(svr, (unsigned long) rlen);
  64.         SyncHandle();
  65.         return (char **) NULL;
  66.     }
  67.     _FSReadPad(svr, c, rlen);
  68.     /* unpack */
  69.     length = *c;
  70.     for (i = 0; i < rep.nFonts; i++) {
  71.         flist[i] = c + 1;
  72.         c += length + 1;
  73.         length = *c;
  74.         *c = '\0';
  75.     }
  76.     } else {
  77.  
  78.     flist = (char **) NULL;
  79.     }
  80.  
  81.     *actualCount = rep.nFonts;
  82.     SyncHandle();
  83.     return flist;
  84.  
  85. }
  86.  
  87. FSFreeFontNames(list)
  88.     char      **list;
  89. {
  90.     if (list) {
  91.     FSFree(list[0] - 1);
  92.     FSFree((char *) list);
  93.     }
  94. }
  95.