dictionary.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef DICTIONARY__H
  2. #define DICTIONARY__H
  3. /**
  4. * Copyright (C) 2011 Anders Sundman <anders@4zm.org>
  5. *
  6. * This file is part of mfterm.
  7. *
  8. * mfterm is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * mfterm is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with mfterm. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. typedef struct key_list_t_ {
  24. uint8_t key[6];
  25. struct key_list_t_* next;
  26. } key_list_t;
  27. /**
  28. * Parse the input file and import all keys found in the dictionary.
  29. */
  30. int dictionary_import(FILE* input);
  31. /**
  32. * Clear the dictionary and free all allocated memory.
  33. */
  34. void dictionary_clear();
  35. /**
  36. * Add a new key to the dictionary. If the dictionary does not exist
  37. * (is empty), it will be created and the key inserted. If the key
  38. * already exists in the list, it will be moved to the head of the
  39. * list and 0 will be returned; else != 0 is returned.
  40. * Note: this operation is O(n)
  41. */
  42. int dictionary_add(const uint8_t* key);
  43. /**
  44. * Return a head pointer to the current dictionary (or NULL if it is
  45. * empty). Don't hang on to this pointer after an add operation, since
  46. * the list head migt change; rather, use this function again
  47. * everywhere a ref. to the list is required.
  48. */
  49. key_list_t* dictionary_get();
  50. #endif