home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / scm / wb1a1.lha / wb / sys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-29  |  4.3 KB  |  170 lines

  1. /* WB-tree File Based Associative String Data Base System.
  2.    Copyright (c) 1991, 1992, 1993 Holland Mark Martin
  3.  
  4. Permission to use, copy, modify, and distribute this software and its
  5. documentation for educational, research, and non-profit purposes and
  6. without fee is hereby granted, provided that the above copyright
  7. notice appear in all copies and that both that copyright notice and
  8. this permission notice appear in supporting documentation, and that
  9. the name of Holland Mark Martin not be used in advertising or
  10. publicity pertaining to distribution of the software without specific,
  11. written prior consent in each case.  Permission to incorporate this
  12. software into commercial products can be obtained from Jonathan
  13. Finger, Holland Mark Martin, 174 Middlesex Turnpike, Burlington, MA,
  14. 01803-4467, USA.  Holland Mark Martin makes no representations about
  15. the suitability or correctness of this software for any purpose.  It
  16. is provided "as is" without express or implied warranty.  Holland Mark
  17. Martin is under no obligation to provide any services, by way of
  18. maintenance, update, or otherwise. */
  19.  
  20. #include "sys.h"
  21. #include "defs.h"
  22.  
  23. /* this is where all diagnostic and error messages will appear */
  24. FILE *diagout;
  25.  
  26. #ifndef STDC_INCLUDES
  27. unsigned char *memcpy(dest, src, len)
  28.      unsigned char *dest, *src;
  29.      int len;
  30. {
  31.   while(len--) dest[len]=src[len];
  32.   return src;
  33. }
  34. #define LACK_MEMMOVE
  35. #endif
  36. #ifdef GNUDOS
  37. #define LACK_MEMMOVE
  38. #endif
  39. #ifdef LACK_MEMMOVE
  40. unsigned char *memmove(dest, src, len)
  41.      unsigned char *dest, *src;
  42.      int len;
  43. {
  44.   if (dest >= src)
  45.     while(len--) dest[len]=src[len];
  46.   else
  47.     {
  48.       int i=0;
  49.       while(i<len)
  50.     {
  51.       dest[i]=src[i];
  52.       i++;
  53.     }
  54.     }
  55.   return src;
  56. }
  57. #endif
  58.  
  59. LCK *last_lck=0;
  60.  
  61. LCK *make_lck(name)
  62.      int name;
  63. {
  64.   LCK *l = (LCK *)malloc(sizeof (LCK));
  65.   if (!l) {
  66.     fprintf(diagout, ">>>>ERROR<<<< could not allocate lck\n");
  67.     exit(errno);
  68.   }
  69.   l->NEXT = last_lck;
  70.   l->FLG = 0;
  71.   l->NAME = name;
  72.   last_lck=l;
  73.   return l;
  74. }
  75.  
  76. /* #define try_lck(lk) (!((lk)->FLG--)) */
  77. int try_lck(lk)
  78.      LCK *lk;
  79. {
  80.   return !(lk->FLG--);
  81. }
  82.  
  83. /* #define lck(lk) {if((lk)->FLG--)fprintf(diagout,">>>>ERROR<<<< spinning on lck %d\n,(lk)->NAME");} */
  84. void lck(lk)
  85.      LCK *lk;
  86. {
  87.   if (lk->FLG--) fprintf(diagout,">>>>ERROR<<<< spinning on lck %d\n",(lk)->NAME);
  88. }
  89.  
  90. /* #define unlck(lk) {if((lk)->FLG)(lk)->FLG=0;else fprintf(diagout,"unlcking unlck %d\n",(lk)->NAME);} */
  91. void unlck(lk)
  92.      LCK *lk;
  93. {
  94.   if (lk->FLG) lk->FLG=0;
  95.   else fprintf(diagout,">>>>ERROR<<<< unlcking unlck %d\n",lk->NAME);
  96. }
  97.  
  98. void check_lcks()
  99. {
  100.   LCK *ll = last_lck;
  101.   while(ll) {
  102.     if (ll->FLG) {
  103.       if (ll->NAME < 0)
  104.     switch (ll->NAME) {
  105.       case -1:fprintf(diagout,">>>>ERROR<<<< free-ent-lck left lcked\n");
  106.       case -2:fprintf(diagout,">>>>ERROR<<<< flush-buk-lck left lcked\n");
  107.       default:fprintf(diagout,">>>>ERROR<<<< unknown lck left lcked\n");
  108.     }
  109.       else fprintf(diagout,">>>>ERROR<<<< lck %d left lcked\n", ll->NAME);
  110.       ll->FLG = 0;
  111.     }
  112.     ll = ll->NEXT;
  113.   }
  114. }
  115.  
  116. SEGD segd_tab[num_segs]
  117.   = {{0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  118.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  119.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  120.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  121.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  122.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  123.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  124.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  125.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0},
  126.        {0,0,0,0,{0,0,0},{0,0,0},{0,0,0},{0,0,0},0,0}};
  127.  
  128. ENTRY *make_ent(tag)
  129.      int tag;
  130. {
  131.   ENTRY *ent = (ENTRY *)malloc(sizeof (ENTRY));
  132.   if (!ent) {
  133.     fprintf(diagout, "WARNING: could not allocate entry\n");
  134.     return 0;
  135.   }
  136.   ent->TAG = tag;
  137.   ent->NEXT = 0;
  138.   ent->SEG = -1;
  139.   ent->ID = -1;
  140.   ent->BLK = (unsigned char *)malloc(blk_size);
  141.   if (!ent->BLK) {
  142.     fprintf(diagout, "WARNING: could not allocate blk for entry\n");
  143.     free(ent);
  144.     return 0;
  145.   }
  146.   ent->AGE = 0;
  147.   ent->DTY = 0;
  148.   ent->PUS = 0;
  149.   ent->ACC = 0;
  150.   ent->REF = 0;
  151.   return ent;
  152. }
  153.  
  154. HAND *make_han()
  155. {
  156.   HAND *han;
  157.   han = (HAND *)calloc(1,sizeof(HAND));
  158.   if (!han) {
  159.     fprintf(diagout, ">>>>ERROR<<<< could not allocate handle\n");
  160.     exit(errno);
  161.   }
  162. /*
  163.   han_set_num(han, 0);
  164.   han_set_seg(han, 0);
  165.   han_set_typ(han, 0);
  166.   han_set_last(han, 0);
  167. */
  168.   return han;
  169. }
  170.