"Fossies" - the Fresh Open Source Software Archive

Member "xearth-1.1/extarr.c" (7 Nov 1999, 2786 Bytes) of package /linux/misc/old/xearth-1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * extarr.c
    3  * kirk johnson
    4  * july 1993
    5  *
    6  * Copyright (C) 1989, 1990, 1993-1995, 1999 Kirk Lauritz Johnson
    7  *
    8  * Parts of the source code (as marked) are:
    9  *   Copyright (C) 1989, 1990, 1991 by Jim Frost
   10  *   Copyright (C) 1992 by Jamie Zawinski <jwz@lucid.com>
   11  *
   12  * Permission to use, copy, modify and freely distribute xearth for
   13  * non-commercial and not-for-profit purposes is hereby granted
   14  * without fee, provided that both the above copyright notice and this
   15  * permission notice appear in all copies and in supporting
   16  * documentation.
   17  *
   18  * Unisys Corporation holds worldwide patent rights on the Lempel Zev
   19  * Welch (LZW) compression technique employed in the CompuServe GIF
   20  * image file format as well as in other formats. Unisys has made it
   21  * clear, however, that it does not require licensing or fees to be
   22  * paid for freely distributed, non-commercial applications (such as
   23  * xearth) that employ LZW/GIF technology. Those wishing further
   24  * information about licensing the LZW patent should contact Unisys
   25  * directly at (lzw_info@unisys.com) or by writing to
   26  *
   27  *   Unisys Corporation
   28  *   Welch Licensing Department
   29  *   M/S-C1SW19
   30  *   P.O. Box 500
   31  *   Blue Bell, PA 19424
   32  *
   33  * The author makes no representations about the suitability of this
   34  * software for any purpose. It is provided "as is" without express or
   35  * implied warranty.
   36  *
   37  * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
   38  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
   39  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT
   40  * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
   41  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
   42  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
   43  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   44  */
   45 
   46 #include "xearth.h"
   47 #include "kljcpyrt.h"
   48 
   49 
   50 ExtArr extarr_alloc(eltsize)
   51      unsigned eltsize;
   52 {
   53   ExtArr rslt;
   54 
   55   rslt = (ExtArr) malloc((unsigned) sizeof(struct extarr));
   56   assert(rslt != NULL);
   57 
   58   rslt->eltsize = eltsize;
   59   rslt->limit   = 1;
   60   rslt->count   = 0;
   61 
   62   rslt->body = (void *) malloc((unsigned) eltsize*rslt->limit);
   63   assert(rslt->body != NULL);
   64 
   65   return rslt;
   66 }
   67 
   68 
   69 void extarr_free(x)
   70      ExtArr x;
   71 {
   72   free(x->body);
   73   free(x);
   74 }
   75 
   76 
   77 void *extarr_next(x)
   78      ExtArr x;
   79 {
   80   unsigned eltsize;
   81   unsigned limit;
   82   unsigned count;
   83   void    *body;
   84   void    *rslt;
   85 
   86   eltsize = x->eltsize;
   87   limit   = x->limit;
   88   count   = x->count;
   89   body    = x->body;
   90 
   91   if (count == limit)
   92   {
   93     limit *= 2;
   94     body   = (void *) realloc(body, (unsigned) eltsize*limit);
   95     assert(body != NULL);
   96 
   97     x->limit = limit;
   98     x->body  = body;
   99   }
  100 
  101   rslt = (void *) ((char *) body + (count * eltsize));
  102   x->count = count + 1;
  103 
  104   return rslt;
  105 }