home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / educatio / xcoral16.zip / FILE_DIC.C < prev    next >
C/C++ Source or Header  |  1993-01-15  |  2KB  |  95 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 "browser_util.h"
  18. #include <string.h>
  19. #include <stdio.h>
  20.  
  21. /*------------------------------------------------------------------------------
  22. //                         Le dictionnaire des fichiers
  23. //------------------------------------------------------------------------------
  24. */
  25.  
  26. FileRec* file_dict[FILE_DICT_SIZE];
  27.  
  28. int      file_count = 0;
  29.  
  30.  
  31. /*------------------------------------------------------------------------------
  32. */
  33. FileRec* create_file (file_name)
  34.   char* file_name;
  35. {
  36.     FileRec**  head;
  37.   FileRec*   current_file;
  38.     int        x_size;
  39.  
  40.     get_head_Rec(file_name, file_dict, FILE_DICT_SIZE, head);
  41.   search_Rec(file_name, FileRec, head, current_file);
  42.   if (current_file == Null) {
  43.     x_size = sizeof(FileRec) + FILE_PLENGTH + strlen(file_name)  + 1;
  44.     current_file = (FileRec*) xmalloc(x_size);
  45.     if (current_file != Null) {
  46.       create_Rec(file_name, FileRec, head, current_file, FILE_PREFIX, FILE_PLENGTH);
  47.             file_count++;
  48.         }
  49.     }
  50.   return(current_file);
  51. }
  52.  
  53.  
  54. /*------------------------------------------------------------------------------
  55. */
  56. FileRec* find_file(file_name)
  57.   char* file_name;
  58. {
  59.     FileRec**  head;
  60.   FileRec*   current_file;
  61.  
  62.     get_head_Rec(file_name, file_dict, FILE_DICT_SIZE, head);
  63.   search_Rec(file_name, FileRec, head, current_file);
  64.   return(current_file);
  65. }
  66.  
  67.  
  68. /*------------------------------------------------------------------------------
  69. */
  70. void remove_file(file_name)
  71.   char* file_name;
  72. {
  73.   FileRec**  head;
  74.   FileRec*   current_file;
  75.  
  76.     get_head_Rec(file_name, file_dict, FILE_DICT_SIZE, head);
  77.   extract_Rec(file_name, FileRec, head, current_file);
  78.     if (current_file != Null) {
  79.       free(current_file);
  80.         --file_count;
  81.     }
  82. }
  83.  
  84.  
  85. /*------------------------------------------------------------------------------
  86. */
  87. void init_file() {
  88.   int index;
  89.  
  90.   for (index = 0; index < FILE_DICT_SIZE; index++)
  91.     file_dict[index] = Null;
  92. }
  93.  
  94.  
  95.