atom.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright (c) 2003-2006 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. typedef struct _Atom {
  20. unsigned int refcount;
  21. struct _Atom *next;
  22. unsigned short length;
  23. char string[1];
  24. } AtomRec, *AtomPtr;
  25. typedef struct _AtomList {
  26. int length;
  27. int size;
  28. AtomPtr *list;
  29. } AtomListRec, *AtomListPtr;
  30. #define LOG2_ATOM_HASH_TABLE_SIZE 10
  31. #define LARGE_ATOM_REFCOUNT 0xFFFFFF00U
  32. extern int used_atoms;
  33. void initAtoms(void);
  34. AtomPtr internAtom(const char *string);
  35. AtomPtr internAtomN(const char *string, int n);
  36. AtomPtr internAtomLowerN(const char *string, int n);
  37. AtomPtr atomCat(AtomPtr atom, const char *string);
  38. int atomSplit(AtomPtr atom, char c, AtomPtr *return1, AtomPtr *return2);
  39. AtomPtr retainAtom(AtomPtr atom);
  40. void releaseAtom(AtomPtr atom);
  41. AtomPtr internAtomError(int e, const char *f, ...)
  42. ATTRIBUTE ((format (printf, 2, 3)));
  43. AtomPtr internAtomF(const char *format, ...)
  44. ATTRIBUTE ((format (printf, 1, 2)));
  45. char *atomString(AtomPtr) ATTRIBUTE ((pure));
  46. AtomListPtr makeAtomList(AtomPtr *atoms, int n);
  47. void destroyAtomList(AtomListPtr list);
  48. int atomListMember(AtomPtr atom, AtomListPtr list)
  49. ATTRIBUTE ((pure));
  50. void atomListCons(AtomPtr atom, AtomListPtr list);