home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / PARSE.ZIP / ATOM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-25  |  1.1 KB  |  50 lines

  1. /*****************************************************
  2. File: ATOM.CPP       Copyright 1989 by John M. Dlugosz
  3.    store strings
  4. *****************************************************/
  5.  
  6. #include "usual.hpp"
  7. #include "atom.hpp"
  8.  
  9. extern "C" void* malloc (unsigned size);
  10. extern "C" void free (void*);
  11. extern "C" void* realloc (void*, unsigned);
  12.  
  13. atom_storage atoms(16);
  14.  
  15. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  16.  
  17. atom_storage::atom_storage (int size)
  18. {
  19. count= 0;
  20. capacity= size;
  21. list= (char**) malloc (size * sizeof(char*));
  22. }
  23.  
  24. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  25.  
  26. atom_storage::~atom_storage()
  27. {
  28. free (list);
  29. }
  30.  
  31. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  32.  
  33. extern "C" int strcmp(char*,char*);
  34. extern "C" char* strdup(char*);
  35.  
  36. atom atom_storage::operator[] (char* s)
  37. {
  38. for (int loop= 0;  loop < count;  loop++) {
  39.    if (!strcmp(s, list[loop])) return loop;  //found it
  40.    }
  41. if (count == capacity) {  // make it bigger
  42.    capacity += capacity/2;
  43.    list= (char**)realloc(list,capacity*sizeof(char*));
  44.    }
  45. list[count]= strdup(s);
  46. return count++;
  47. }
  48.  
  49. /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
  50.