home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************
- File: ATOM.CPP Copyright 1989 by John M. Dlugosz
- store strings
- *****************************************************/
-
- #include "usual.hpp"
- #include "atom.hpp"
-
- extern "C" void* malloc (unsigned size);
- extern "C" void free (void*);
- extern "C" void* realloc (void*, unsigned);
-
- atom_storage atoms(16);
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-
- atom_storage::atom_storage (int size)
- {
- count= 0;
- capacity= size;
- list= (char**) malloc (size * sizeof(char*));
- }
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-
- atom_storage::~atom_storage()
- {
- free (list);
- }
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-
- extern "C" int strcmp(char*,char*);
- extern "C" char* strdup(char*);
-
- atom atom_storage::operator[] (char* s)
- {
- for (int loop= 0; loop < count; loop++) {
- if (!strcmp(s, list[loop])) return loop; //found it
- }
- if (count == capacity) { // make it bigger
- capacity += capacity/2;
- list= (char**)realloc(list,capacity*sizeof(char*));
- }
- list[count]= strdup(s);
- return count++;
- }
-
- /* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
-