Standalone Haplous Bible Parser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

  1. #ifndef HAPLOUS_H_
  2. #define HAPLOUS_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdio.h>
  7. #include <stdbool.h>
  8. // numbers from the spec
  9. #define MAX_ID_LEN 20
  10. enum haplous_error {
  11. HAPLOUS_CONTINUE = 1, // used for the reader
  12. HAPLOUS_OK = 0,
  13. HAPLOUS_OTHER_ERROR = -1,
  14. HAPLOUS_INVALID_REF = -2,
  15. HAPLOUS_REF_NOT_FOUND = -3,
  16. HAPLOUS_END_TOO_BIG = -4,
  17. HAPLOUS_INVALID_HAPLOUS = -5,
  18. HAPLOUS_META_MISSING = -6,
  19. HAPLOUS_META_FOUND_BOOK = -7,
  20. HAPLOUS_WORK_NOT_FOUND = -8,
  21. HAPLOUS_OUT_OF_MEMORY = -9,
  22. };
  23. struct haplous_reference {
  24. char *id;
  25. size_t chapter;
  26. size_t verse_start;
  27. size_t verse_end;
  28. };
  29. struct haplous_work_metadata {
  30. char lang[MAX_ID_LEN];
  31. char title[MAX_ID_LEN];
  32. char id[MAX_ID_LEN];
  33. bool public_domain;
  34. char type[MAX_ID_LEN];
  35. // this is only the required metadata,
  36. // other metadata may be available via work_metadata_get(id)
  37. };
  38. struct haplous_work {
  39. const char *path;
  40. FILE *file;
  41. struct haplous_work_metadata metadata;
  42. };
  43. struct haplous_reader {
  44. struct haplous_work work;
  45. struct haplous_reference reference;
  46. char *verse;
  47. size_t current_verse;
  48. };
  49. struct haplous_work haplous_work_init(const char *, int *);
  50. int haplous_work_cleanup(struct haplous_work *);
  51. char *haplous_work_chapter_get(FILE *, struct haplous_reference, int *);
  52. char *haplous_work_verses_get(FILE *, struct haplous_reference, int *);
  53. char *haplous_work_metadata_get(FILE *, const char[MAX_ID_LEN]);
  54. struct haplous_reader haplous_reader_new(struct haplous_work, struct haplous_reference, int *);
  55. int haplous_next(struct haplous_reader *);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif