home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / lib / fs / FSGetCats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  2.5 KB  |  79 lines

  1. /* $XConsortium: FSGetCats.c,v 1.1 91/07/16 20:31:55 keith Exp $ */
  2.  
  3. /* @(#)FSFlush.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. FSGetCatalogues(svr, num)
  30.     FSServer   *svr;
  31.     int        *num;
  32. {
  33.     fsGetCataloguesReply rep;
  34.     char      **list;
  35.     char       *c;
  36.     int         i,
  37.                 length;
  38.     fsReq      *req;
  39.     long        rlen;
  40.  
  41.     GetEmptyReq(GetCatalogues, req);
  42.  
  43.     if (!_FSReply(svr, (fsReply *) & rep, 0, fsFalse)) {
  44.     SyncHandle();
  45.     return (char **) NULL;
  46.     }
  47.     if (rep.num_catalogues) {
  48.     list = (char **)
  49.         FSmalloc((unsigned) (rep.num_catalogues * sizeof(char *)));
  50.     rlen = (rep.length << 2) - sizeof(fsGetCataloguesReply);
  51.     c = (char *) FSmalloc((unsigned) rlen + 1);
  52.     if ((!list) || (!c)) {
  53.         if (list)
  54.         FSfree((char *) list);
  55.         if (c)
  56.         FSfree(c);
  57.         _FSEatData(svr, (unsigned long) rlen);
  58.         SyncHandle();
  59.         return (char **) NULL;
  60.     }
  61.     _FSReadPad(svr, c, rlen);
  62.     /*
  63.      * unpack the strings
  64.      */
  65.     length = *c;
  66.     for (i = 0; i < rep.num_catalogues; i++) {
  67.         list[i] = c + 1;    /* skip length */
  68.         c += length + 1;    /* find next length */
  69.         length = *c;
  70.         *c = '\0';        /* change length to NULL */
  71.     }
  72.     } else {
  73.     list = (char **) NULL;
  74.     }
  75.     SyncHandle();
  76.     *num = rep.num_catalogues;
  77.     return list;
  78. }
  79.