My idea for a "libheb12" (what I would want to use)
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.

123 lines
3.5 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include "book.h"
  6. struct OSISBooks osisbooks[66] = {
  7. {"Gen", {"Genesis", "genesis"}, 2},
  8. {"Exod", {"Exodus", "exodus"}, 2},
  9. {"Lev", {"Leviticus", "leviticus"}, 2},
  10. {"Num", {"Numbers", "numbers"}, 2},
  11. {"Deut", {"Deuteronomy", "deuteronomy"}, 2},
  12. {"Josh", {"Joshua", "joshua"}, 2},
  13. {"Judg", {"Judges", "judges"}, 2},
  14. {"Ruth", {"Ruth", "ruth"}, 2},
  15. {"1Sam", {"1 Samuel", "1samuel"}, 2},
  16. {"2Sam", {"2 Samuel", "2samuel"}, 2},
  17. {"1Kng", {"1 Kings", "1kings"}, 2},
  18. {"2Kng", {"2 Kings", "2kings"}, 2},
  19. {"1Chr", {"1 Chronicles", "1chronicles"}, 2},
  20. {"2Chr", {"2 Chronicles", "2chronicles"}, 2},
  21. {"Ezr", {"Ezra", "ezra"}, 2},
  22. {"Neh", {"Nehemiah", "nehemiah"}, 2},
  23. {"Est", {"Esther", "esther"}, 2},
  24. {"Job", {"Job", "job"}, 2},
  25. {"Ps", {"Psalms", "psalms"}, 2},
  26. {"Pro", {"Proverbs", "proverbs"}, 2},
  27. {"Ecc", {"Ecclesiastes", "ecclesiastes"}, 2},
  28. {"Song", {"Song of Solomon", "songofsolomon", "songs", "sos"}, 4},
  29. {"Isa", {"Isaiah", "isaiah"}, 2},
  30. {"Jer", {"Jeremiah", "jeremiah"}, 2},
  31. {"Lam", {"Lamentations", "lamentations"}, 2},
  32. {"Eze", {"Ezekiel", "ezekiel"}, 2},
  33. {"Dan", {"Daniel", "daniel"}, 2},
  34. {"Hos", {"Hosea", "hosea"}, 2},
  35. {"Joe", {"Joel", "joel"}, 2},
  36. {"Amo", {"Amos", "amos"}, 2},
  37. {"Oba", {"Obadiah", "obadiah"}, 2},
  38. {"Jon", {"Jonah", "jonah"}, 2},
  39. {"Mic", {"Micah", "micah"}, 2},
  40. {"Nah", {"Nahum", "nahum"}, 2},
  41. {"Hab", {"Habakkuk", "habakkuk"}, 2},
  42. {"Zep", {"Zephaniah", "zephaniah"}, 2},
  43. {"Hag", {"Haggai", "haggai"}, 2},
  44. {"Zec", {"Zechariah", "zechariah"}, 2},
  45. {"Mal", {"Malachi", "malachi"}, 2},
  46. {"Mat", {"Matthew", "matthew"}, 2},
  47. {"Mar", {"Mark", "mark"}, 2},
  48. {"Luk", {"Luke", "luke"}, 2},
  49. {"John", {"John", "john"}, 2},
  50. {"Act", {"Acts", "acts"}, 2},
  51. {"Rom", {"Romans", "romans"}, 2},
  52. {"1Cor", {"1 Corinthians", "1corinthians"}, 2},
  53. {"2Cor", {"2 Corinthians", "2corinthians"}, 2},
  54. {"Gal", {"Galatians", "galatians"}, 2},
  55. {"Eph", {"Ephesians", "ephesians"}, 2},
  56. {"Phi", {"Philippians", "philippians"}, 2},
  57. {"Col", {"Colossians", "colossians"}, 2},
  58. {"1The", {"1 Thessalonians", "1thessalonians"}, 2},
  59. {"2The", {"2 Thessalonians", "2thessalonians"}, 2},
  60. {"1Tim", {"1 Timothy", "1timothy"}, 2},
  61. {"2Tim", {"2 Timothy", "2timothy"}, 2},
  62. {"Titus", {"Titus", "titus"}, 2},
  63. {"Phil", {"Philemon", "philemon"}, 2},
  64. {"Heb", {"Hebrews", "hebrews"}, 2},
  65. {"Jam", {"James", "james"}, 2},
  66. {"1Pet", {"1 Peter", "1peter"}, 2},
  67. {"2Pet", {"2 Peter", "2peter"}, 2},
  68. {"1Joh", {"1 John", "1john"}, 2},
  69. {"2Joh", {"2 John", "2john"}, 2},
  70. {"3Joh", {"3 John", "3john"}, 2},
  71. {"Jude", {"Jude", "jude"}, 2},
  72. {"Rev", {"Revelation", "revelation"}, 2}
  73. };
  74. // Case insensitive strcmp
  75. // I wrote this quickly without testing
  76. // it very much, so it may be flawed.
  77. int strcmpcase(char *s1, char *s2) {
  78. int diff = 0;
  79. while (*s1 | *s2) {
  80. s1++;
  81. s2++;
  82. if (tolower(*s1) != tolower(*s2)) {
  83. diff++;
  84. }
  85. }
  86. return diff;
  87. }
  88. int osisbook(char *string, char buffer[], unsigned int len) {
  89. #define BOOKSLEN (int)(sizeof(osisbooks) / sizeof(osisbooks[0]))
  90. // Loop through all the books
  91. for (int b = 0; b < BOOKSLEN; b++) {
  92. if (!strcmpcase(string, osisbooks[b].osis)) {
  93. strncpy(buffer, osisbooks[b].osis, len);
  94. return 0;
  95. }
  96. // Check alt book names
  97. for (int a = 0; a < osisbooks[b].length; a++) {
  98. if (!strcmpcase(string, osisbooks[b].alt[a])) {
  99. strncpy(buffer, osisbooks[b].osis, len);
  100. return 0;
  101. }
  102. }
  103. }
  104. return 1;
  105. }
  106. #ifdef TEST
  107. int main() {
  108. char buffer[100];
  109. osisbook("Song", buffer);
  110. puts(buffer);
  111. }
  112. #endif