home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xcoral16.zip / PROC_DIC.C < prev    next >
C/C++ Source or Header  |  1993-01-15  |  5KB  |  174 lines

  1. /*
  2. ** Copyright 1989, 1992 by Lionel Fournigault
  3. **
  4. ** Permission to use, copy, and distribute for non-commercial purposes,
  5. ** is hereby granted without fee, providing that the above copyright
  6. ** notice appear in all copies and that both the copyright notice and this
  7. ** permission notice appear in supporting documentation.
  8. ** The software may be modified for your own purposes, but modified versions
  9. ** may not be distributed.
  10. ** This software is provided "as is" without any expressed or implied warranty.
  11. **
  12. **
  13. */
  14.  
  15. #include "result_types.h"
  16. #include "file_dict.h"
  17. #include "proc_dict.h"
  18. #include "browser_util.h"
  19. #include <string.h>
  20. #include <stdio.h>
  21.  
  22. /*------------------------------------------------------------------------------
  23. //                         Le dictionnaire des procedures
  24. //------------------------------------------------------------------------------
  25. */
  26.  
  27. ProcRec* proc_dict[PROC_DICT_SIZE];
  28.  
  29. int proc_count = 0;
  30.  
  31.  
  32. /*------------------------------------------------------------------------------
  33. */
  34. ProcRec* create_proc(proc_name)
  35.   char* proc_name;
  36. {
  37.   ProcRec**  head;
  38.   ProcRec*   current_proc;
  39.   int        x_size;
  40.   
  41.   get_head_Rec(proc_name, proc_dict, PROC_DICT_SIZE, head);
  42.   search_Rec(proc_name, ProcRec, head, current_proc);
  43.   if (current_proc == Null) {
  44.     x_size = sizeof(ProcRec) + PROC_PLENGTH + strlen(proc_name)  + 1;
  45.     current_proc = (ProcRec*) xmalloc(x_size);
  46.     if (current_proc != Null) {
  47.       create_Rec(proc_name, ProcRec, head, current_proc, PROC_PREFIX, PROC_PLENGTH);
  48.       current_proc->_impl_file = Null;
  49.       current_proc->_impl_line = 0;
  50.       current_proc->_proc_type = UNKNOWN_PROC;
  51.       proc_count++;
  52.     }
  53.   }
  54.   return(current_proc);
  55. }
  56.  
  57.  
  58. /*------------------------------------------------------------------------------
  59. */
  60. ProcRec* find_proc(proc_name)
  61.   char* proc_name;
  62. {
  63.   ProcRec**  head;
  64.   ProcRec*   current_proc;
  65.  
  66.   get_head_Rec(proc_name, proc_dict, PROC_DICT_SIZE, head);
  67.   search_Rec(proc_name, ProcRec, head, current_proc);
  68.   return(current_proc);
  69. }
  70.  
  71.  
  72. /*------------------------------------------------------------------------------
  73. */
  74. typedef long Bits;
  75.  
  76. #define LAST_BIT  ((sizeof(Bits) * 8) - 1)
  77.  
  78. static Bits erazed_bits[(PROC_DICT_SIZE + LAST_BIT) / (LAST_BIT + 1)];
  79.  
  80.  
  81. void proc_eraze_file(file_name)
  82.     char* file_name;
  83. {
  84.   Bits*      erazed_slice;
  85.   FileRec*   current_file;
  86.   ProcRec*   current_proc;
  87.   int        index;
  88.   
  89.   current_file = find_file(file_name);
  90.   if (current_file != Null) {
  91.     erazed_slice = erazed_bits;
  92.     for (index = 0; index < PROC_DICT_SIZE; index++) {
  93.       current_proc = proc_dict[index];
  94.       while (current_proc != Null) {
  95.         if (current_proc->_impl_file == current_file) {
  96.           current_proc->_impl_file = Null;
  97.           current_proc->_impl_line = 0;
  98.           (*erazed_slice) |= ((0x00000001L) << (index & LAST_BIT));
  99.         }
  100.         current_proc = current_proc->_next;
  101.       }
  102.       if ((index & LAST_BIT) == LAST_BIT)
  103.         erazed_slice++;
  104.     }
  105.   }  
  106. }
  107.  
  108.  
  109. /*------------------------------------------------------------------------------
  110. */
  111. void garbage_proc()
  112. {
  113.   Bits*     erazed_slice;
  114.   ProcRec*  previous_proc;
  115.   ProcRec*  current_proc;
  116.   ProcRec*  next_proc;
  117.   int       index;
  118.  
  119.   erazed_slice = erazed_bits;
  120.   for (index = 0; index < PROC_DICT_SIZE; index++) {
  121.     if ((*erazed_slice) == 0) {
  122.       index += LAST_BIT;
  123.       erazed_slice++;
  124.     }
  125.     else {
  126.       if (((*erazed_slice) & ((0x00000001L) << (index & LAST_BIT))) != 0) {
  127.         previous_proc = Null;
  128.         current_proc = proc_dict[index];
  129.         while (current_proc != Null) {
  130.           if (current_proc->_impl_file == Null) {
  131.             next_proc = current_proc->_next;
  132.             if (previous_proc == Null)
  133.               proc_dict[index] = next_proc;
  134.             else
  135.               previous_proc->_next = next_proc;
  136.             --proc_count;
  137.             free(current_proc);
  138.             current_proc = next_proc;
  139.           }
  140.           else {
  141.             previous_proc = current_proc;
  142.             current_proc  = current_proc->_next;
  143.           }
  144.         }
  145.       }
  146.       if ((index & LAST_BIT) == LAST_BIT) {
  147.         *erazed_slice = 0;
  148.         erazed_slice++;
  149.       }
  150.     }
  151.   }
  152. }  
  153.  
  154.  
  155. /*------------------------------------------------------------------------------
  156. */
  157. void init_proc() {
  158.   Bits* erazed_slice;
  159.   int   index;
  160.  
  161.   erazed_slice = erazed_bits;
  162.   for (index = 0; index < PROC_DICT_SIZE; index++) {
  163.     if ((index & LAST_BIT) == LAST_BIT) {
  164.       *erazed_slice = 0;
  165.       erazed_slice++;
  166.     }
  167.     proc_dict[index] = Null;
  168.   }
  169. }
  170.  
  171.  
  172.  
  173.  
  174.