home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lclint.zip / lclint-2_3h-os2-bin.zip / test / db1 / eref.c < prev    next >
Text File  |  1997-09-03  |  2KB  |  88 lines

  1. # include <stdio.h>
  2. # include <stdlib.h>
  3. # include "eref.h"
  4.  
  5. eref_ERP eref_Pool;            /* private */
  6. static bool needsInit = TRUE;  /* private */
  7.  
  8. eref eref_alloc (void) 
  9. {
  10.   int i, res;
  11.   
  12.   for (i=0; (eref_Pool.status[i] == used) && (i < eref_Pool.size); i++);
  13.   
  14.   res = i;
  15.  
  16.   if (res == eref_Pool.size) 
  17.     {
  18.       eref_Pool.conts =
  19.     (employee *) realloc (eref_Pool.conts,
  20.                   2 * eref_Pool.size * sizeof (employee));
  21.       
  22.       if (eref_Pool.conts == 0) 
  23.     {
  24.       printf ("Malloc returned null in eref_alloc\n");
  25.       exit (1);
  26.     }
  27.       
  28.       eref_Pool.status =
  29.     (eref_status *) realloc (eref_Pool.status,
  30.                  2 * eref_Pool.size * sizeof (eref_status));
  31.  
  32.       if (eref_Pool.status == 0) 
  33.     {
  34.       printf ("Malloc returned null in eref_alloc\n");
  35.       exit (1);
  36.     }
  37.       
  38.       eref_Pool.size = 2*eref_Pool.size;
  39.  
  40.       for (i = res+1; i < eref_Pool.size; i++)
  41.         eref_Pool.status[i] = avail;
  42.     }
  43.   
  44.   eref_Pool.status[res] = used;
  45.   return (eref) res;
  46. }
  47.  
  48. void eref_initMod (void) 
  49. {
  50.   int i;
  51.   const int size = 16;
  52.   
  53.   if (needsInit == FALSE) 
  54.     {
  55.       return;
  56.     }
  57.  
  58.   needsInit = FALSE;
  59.   bool_initMod ();
  60.   employee_initMod ();
  61.  
  62.   eref_Pool.conts = (employee *) malloc (size * sizeof (employee));
  63.  
  64.   if (eref_Pool.conts == 0) 
  65.     {
  66.       printf ("Malloc returned null in eref_initMod\n");
  67.       exit (1);
  68.     }
  69.   
  70.   eref_Pool.status = (eref_status *) malloc (size * sizeof (eref_status));
  71.  
  72.   if (eref_Pool.status == 0) 
  73.     {
  74.       printf ("Malloc returned null in eref_initMod\n");
  75.       exit (1);
  76.     }
  77.   
  78.   eref_Pool.size = size;
  79.  
  80.   for (i = 0; i < size; i++)
  81.     {
  82.       eref_Pool.status[i] = avail;
  83.     }
  84. }
  85.  
  86.  
  87.  
  88.