Read the Bible on a FreeDOS 1.44mb Floppy Disk
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.

163 lines
2.7 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5. #include "fbrp/reference.h"
  6. #include "fbrp/fbrp.h"
  7. #include "biblec/main.h"
  8. #include "biblec/biblec.h"
  9. #include "option.h"
  10. struct Translation translation;
  11. // Simple function to print strings with text break
  12. void printBreak(char *string, int breakAt) {
  13. for (int c = 0; string[c] != '\0'; c++) {
  14. putchar(string[c]);
  15. if (c > breakAt && string[c] == ' ') {
  16. putchar('\n');
  17. breakAt *= 2;
  18. }
  19. }
  20. }
  21. void printError(int type) {
  22. putchar('!');
  23. putchar(' ');
  24. switch (type) {
  25. case FILE_NOT_FOUND:
  26. puts("File not found: ");
  27. break;
  28. case BOOK_NOT_FOUND:
  29. puts("Book not found: ");
  30. break;
  31. case FILE_ERROR:
  32. puts("File I/O Error: ");
  33. break;
  34. default:
  35. puts("Unknown Error: ");
  36. }
  37. // Put error as char
  38. putchar(type * -1 + '0');
  39. putchar('\n');
  40. }
  41. int printVerses(char *input, bool fancyPrint) {
  42. struct Reference ref = parseReference(input);
  43. int verses = ref.verseLength;
  44. if (verses == 0 && ref.chapterLength == 1) {verses = 1;}
  45. for (int r = 0; r < verses; r++) {
  46. int verseStart = 1;
  47. int verseEnd = 0;
  48. if (ref.verseLength != 0) {
  49. verseStart = ref.verse[r].r[0];
  50. verseEnd = ref.verse[r].r[1];
  51. }
  52. int tryReader;
  53. struct Reader reader = reader_new(
  54. &tryReader,
  55. &translation,
  56. ref.book,
  57. ref.chapter[0].r[0],
  58. verseStart,
  59. verseEnd
  60. );
  61. if (tryReader) {
  62. printError(tryReader);
  63. return -1;
  64. }
  65. while (1) {
  66. if (reader_next(&reader)) {break;}
  67. if (fancyPrint) {
  68. putchar('\n');
  69. printf("%d. ", verseStart + reader.linesRead - 1);
  70. printBreak(reader.result, 70);
  71. putchar('\n');
  72. } else {
  73. puts(reader.result);
  74. }
  75. }
  76. if (fancyPrint) {
  77. putchar('\n');
  78. }
  79. fclose(reader.file);
  80. }
  81. return 0;
  82. }
  83. int main(int argc, char *argv[]) {
  84. // Parse if the user wants a command line interface
  85. if (argc != 1) {
  86. for (int i = 1; i < argc; i++) {
  87. if (argv[i][0] == '-') {
  88. if (argv[i][1] == 't') {
  89. i++;
  90. defaultIndex = argv[i];
  91. } else if (argv[i][1] == 'r') {
  92. i++;
  93. defaultReference = argv[i];
  94. }
  95. }
  96. }
  97. int tryFile = 0;
  98. parseIndexFile(
  99. &tryFile,
  100. &translation,
  101. defaultIndex
  102. );
  103. if (tryFile) {
  104. printError(tryFile);
  105. }
  106. printVerses(defaultReference, 0);
  107. return 0;
  108. }
  109. puts("@ Heb12Lite");
  110. int tryFile = 0;
  111. parseIndexFile(
  112. &tryFile,
  113. &translation,
  114. defaultIndex
  115. );
  116. if (tryFile) {
  117. printError(tryFile);
  118. return 0;
  119. } else {
  120. puts("@ Default Bible Loaded");
  121. }
  122. while (1) {
  123. printf(": ");
  124. char input[50];
  125. fgets(input, 50, stdin);
  126. if (input[0] == '?') {
  127. printf("\n%s\n", "@ Type a reference to see the verses");
  128. continue;
  129. } else if (input[0] == 'x') {
  130. return 0;
  131. }
  132. printVerses(input, 1);
  133. }
  134. return 0;
  135. }