2 *******************************************************************************
5 * RCS: $Header: /home/matthew/cvs/bible-kjv-4.10/brl.c,v 2.7 2005/01/23 11:19:58 matthew Exp $
6 * Description: Bible Retrieval Library
7 * Author: Chip Chapin, Hewlett Packard Company
8 * Created: Jan 14 1989, Chip Chapin
9 * Modified: Mon Apr 26 11:11:59 1993 (Chip Chapin) chip@hpclbis
11 * Package: Bible Retrieval System
12 * Status: Experimental (Do Not Distribute)
14 *******************************************************************************
18 * Thu Dec 30 1999 (Oliver Elphick) olly@lfix.co.uk
19 * Increase VBSIZE from 512 to 550, because very long verses were
20 * being truncated in pretty printing.
21 * Thu Apr 22 14:39:43 1993 (Chip Chapin) chip@hpclbis
22 * Fix bad return value from brl_printverse when no errors occurred.
23 * Support non-POSIX sprintf.
24 * Tue Jan 5 18:23:41 1993 (Chip Chapin) chip@hpclbis
25 * Change how current context is handled. Now use single var
26 * "brl_cur_vnum", and make our caller responsible for updating it.
27 * brl_getverse is now commented out. Nobody uses it anymore.
28 * Added file parameter to brl_printverse.
29 * Mon Jan 4 10:11:19 1993 (Chip Chapin) chip@hpclbis
30 * Renamed verse_spec() as brl_verse_spec() and exposed it to callers.
31 * Thu Dec 24 11:04:42 1992 (Chip Chapin) chip@hpclbis
32 * Added brl_cur_ref(), and converted all absolute verse refs to use
33 * "ref_t", instead of "int" and "long".
34 * Tue Dec 22 17:11:41 1992 (Chip Chapin) chip@hpclbis
35 * Fix bug parsing "ma.." books.
36 * Added tolower fix submitted by Stephen North, AT&T.
37 * Mon Dec 21 19:13:10 1992 (Chip Chapin) chip@hpclbis
38 * Fixed minor verse ref parsing bugs.
39 * Added brl_num_to_ref to support concordance.
40 *******************************************************************************
43 * Revision 2.7 2005/01/23 11:19:58 matthew
46 * Revision 2.6 2005/01/22 17:47:40 matthew
47 * remove improper function declarations
49 * Revision 2.5 2005/01/22 16:40:34 matthew
50 * cast return value of strlen to signed int
52 * Revision 2.4 2005/01/21 19:38:25 matthew
53 * Code clean-up - initialise vref, remove unused variable.
55 * Revision 2.3 2005/01/21 19:07:31 matthew
56 * disambiguate an else
58 * Revision 2.2 2005/01/21 19:05:51 matthew
59 * Prototype all functions
61 * Revision 2.1 2003/01/08 15:50:53 matthew
62 * applied debian patch
64 * Revision 2.0 2003/01/08 15:29:52 matthew
65 * versions collected from the net
67 * Revision 1.16 93/04/26 11:18:12 11:18:12 chip (Chip Chapin)
69 * Public release of portable datafile version.
71 * Revision 1.15 93/04/23 13:08:01 13:08:01 chip (Chip Chapin)
73 * This version supports portable data files, usable on machines with
74 * differing native byte-orders.
75 * Also, this version compiles and runs on non-HPUX systems. It has been
76 * tested on SunOS 4.? and ULTRIX 4.?, using SPARC and DEC 3100 hardware
77 * respectively. Note that the data file format has rolled again.
79 * Revision 1.14 93/01/05 19:05:30 19:05:30 chip (Chip Chapin)
80 * Release 3.00: (not for distribution)
81 * Fixed errors (blank lines) in bible.data file. Data file is not compatible
82 * with previous (1.x and 2.x) distributions. Further changes pending.
83 * Rewrote context handling, and added "<" and ">" commands.
84 * Tools for building brl-index are now part of release.
86 * Revision 1.13 93/01/05 10:49:09 10:49:09 chip (Chip Chapin)
87 * Release 2.2, Added ?w command and line formatting to ?l output.
89 * Revision 1.12 93/01/04 16:20:57 16:20:57 chip (Chip Chapin)
90 * Release 2.1, implements ?in and ?or commands.
92 * Revision 1.11 92/12/24 11:09:14 11:09:14 chip (Chip Chapin)
93 * Release 2.04. Include verse ref in prompt line.
95 * Revision 1.10 92/12/23 14:10:43 14:10:43 chip (Chip Chapin)
96 * Release 2.03: minor tweaks and bug fixes.
98 * Revision 1.9 92/12/22 18:17:06 18:17:06 chip (Chip Chapin)
99 * Minor tweaks for release 2.02.
101 * Revision 1.8 92/12/21 20:00:47 20:00:47 chip (Chip Chapin)
102 * Release 2.0. This release adds the concordance, and some small fixes.
104 * Revision 1.7 89/10/02 22:20:45 22:20:45 chip (Chip Chapin)
105 * Fix bugs: looping when lwidth very small,
106 * and blank-line after verse range not printing verse AFTER the last
107 * verse of the range.
109 * Revision 1.6 89/09/14 20:33:45 20:33:45 chip (Chip Chapin)
110 * Release 1-2. Supports -f and -l options for formatting the output.
111 * Updates primarily brl.c, bible.c, and bible.1.
113 * Revision 1.5 89/09/13 21:49:13 21:49:13 chip (Chip Chapin)
114 * Implement -f and -l options for pretty-printing and linewidth limitation.
116 * Revision 1.4 89/09/08 13:22:47 13:22:47 chip (Chip Chapin)
117 * Better error checking on verse syntax; automatic test suite.
119 * Revision 1.3 89/09/08 09:01:22 09:01:22 chip (Chip Chapin)
120 * Bug fix and simplification: send whole input lines or arguments to BRL,
121 * and let BRL worry about multiple references. We don't care.
123 * Revision 1.2 89/09/05 20:22:59 20:22:59 chip (Chip Chapin)
124 * Workaround 6.2 C compiler enum gripes.
126 * Revision 1.1 89/09/05 17:49:15 17:49:15 chip (Chip Chapin)
129 *******************************************************************************
132 /*----------------------------------------------------------------------
137 | Provide a set of routines for retrieving Bible text from
138 | the Text Storage Library (tsl). All of these routines
139 | should take a high-level view of the text itself; they may
140 | know something about the structure of the Bible, but
141 | should *not* depend in any way upon the manner in which
142 | the text is stored. Call on the TSL for that.
145 | Grammar Functions: Used within the BRL to parse verse
147 | brl_verse_spec (also called from applications)
151 | Access Functions: Called from application programs to
152 | retrieve Bible text.
156 | Utility Functions: Called from application programs.
162 | 890114 cc Initial creation.
163 | 890824 cc Improved partitioning between BRL and TSL. Created
164 | brl_getverse to hide brl_verse_spec and verse numbers from
165 | user programs. Fix bug in verse_id parsing "jn".
166 | 921217 cc Added brl_num_to_ref.
168 \*----------------------------------------------------------------------*/
180 char *booknamestr[] = { "Genesis",
249 /* Standard abbreviations */
250 char *bookabbrvstr[] = { "Gen",
320 ref_t brl_cur_vnum; /* Current context. */
322 /* Name of text. This should really be initialized or provided by tsl */
323 char brl_textname[]="KJV";
328 /*----------------------------------------------------------------------
330 | Verse Specification Grammar
332 | The following routines implement the grammar by which
333 | verses may be specified.
334 | See each routine, starting with brl_verse_spec, for the grammar.
336 \*----------------------------------------------------------------------*/
338 #define getnum(s,n) n=0; get_nonblank(s); \
339 while (isdigit((int)*s)) n = 10 * n + (*s++ - '0');
343 int get_book(char **s,int book)
344 /*----------------------------------------------------------------------
349 | Parse a bible book name or abbreviation. Defaults to the
350 | book number passed in "book" if no book is specified.
352 | Returns the number of the book, 0..65, -1 if an
353 | unrecognizable book name is given, or -2 if no book name
354 | is given (needs a bit of cleanup!).
357 | 890902 cc Extracted from verse_id.
358 | 890904 cc Revised to allow non-fatal errors.
360 \*----------------------------------------------------------------------*/
365 book = -2; /* assume no book is given */
368 if (*s1 && (isalpha((int)*s1) || isalpha((int)*(s1+1)))) {
370 case '1': /* 1Sa, 1Ki, 1Ch, 1Co, 1Th, 1Ti, 1Pe, 1Jn */
371 case '2': /* 2Sa, 2Ki, 2Ch, 2Co, 2Th, 2Ti, 2Pe, 2Jn */
376 if (*s1=='h') book= (int)CHRON1;
377 else if (*s1=='o') book= (int)COR1;
379 tsl_error( FALSE, BADBOOK, *s );
396 if (*s1=='h') book= (int)THESS1;
397 else if (*s1=='i') book= (int)TIM1;
399 tsl_error( FALSE, BADBOOK, *s );
404 tsl_error( FALSE, BADBOOK, *s );
407 if (c != '1') book++;
409 if (book == (int)JOHN2) book++;
411 tsl_error( FALSE, BADBOOK, *s );
416 case 'a': /* amos, acts */
418 if (c == 'm') book = (int)AMOS;
419 else if (c == 'c') book = (int)ACTS;
421 tsl_error( FALSE, BADBOOK, *s );
428 case 'd': /* deut, dan */
430 if (c == 'e' || c == 't') book = (int)DEUT; /* de, dt */
431 else if (c == 'a') book = (int)DANIEL;
433 tsl_error( FALSE, BADBOOK, *s );
437 case 'e': /* exodus, ezra, esther, eccl, ezekiel, eph */
439 if (c == 'x') book = (int)EXODUS; /* ex */
440 else if (c == 's') book = (int)ESTHER; /* es */
441 else if (c == 'c') book = (int)ECCL; /* ec */
442 else if (c == 'p') book = (int)EPH; /* ep */
444 if (c == 'z') c = *s1++;
445 if (c == 'r') book = (int)EZRA; /* ezr, er */
446 else if (c == 'e' || c == 'k')
447 book = (int)EZEKIEL; /* eze,ee,ezk,ek */
449 tsl_error( FALSE, BADBOOK, *s );
454 case 'g': /* gen, gal */
456 if (c == 'e' || c == 'n') book = (int)GENESIS;
457 else if (c == 'a' || c == 'l') book = (int)GAL;
459 tsl_error( FALSE, BADBOOK, *s );
463 case 'h': /* hebrews, hosea, habakkuk, haggai */
465 if (c == 'o') book = (int)HOSEA; /* ho */
466 else if (c == 'e' || c == 'b')
467 book = (int)HEBREWS; /* he, hb (more likely than Hab.) */
469 if (c == 'a') c = *s1++;
470 if (c == 'b') book = (int)HABAK; /* hab */
471 else if (c == 'g') book = (int)HAGGAI; /* hag, hg */
473 tsl_error( FALSE, BADBOOK, *s );
478 case 'i': /* isaiah */
481 case 'j': /* josh, judges, job, jer, joel, jonah, john, jam, jude */
483 if (c == 'a') book = (int)JAMES; /* ja */
484 else if (c == 'e' || c == 'r') book = (int)JEREM; /* je, jr */
485 else if (c == 'b') book = (int)JOB; /* jb */
487 if ((c = *s1++) == 'g') book = (int)JUDGES; /* jdg */
488 else if (c == 'e') book = (int)JUDE; /* jde */
490 tsl_error( FALSE, BADBOOK, *s );
494 else if (c == 'g') book = (int)JUDGES; /* jg */
495 else if (c == 'l') book = (int)JOEL; /* jl */
496 else if (c == 'n') book = (int)JOHN; /* jn */
498 if ((c = *s1++) == 'h') book = (int)JOSHUA; /* jsh */
500 tsl_error( FALSE, BADBOOK, *s );
505 if ((c = *s1++) == 'd') c = *s1++;
506 if (c == 'g') book = (int)JUDGES; /* judg, jug (ha-ha) */
507 else if (c == 'e') book = (int)JUDE; /* jude, jue (ha-ha) */
509 tsl_error( FALSE, BADBOOK, *s );
514 if ((c = *s1++) == 's') book = (int)JOSHUA; /* jos */
515 else if (c == 'b') book = (int)JOB; /* job */
516 else if (c == 'e') book = (int)JOEL; /* joe */
517 else if (c == 'n') book = (int)JONAH; /* jon */
518 else if (c == 'h') book = (int)JOHN; /* joh */
520 tsl_error( FALSE, BADBOOK, *s );
525 tsl_error( FALSE, BADBOOK, *s );
529 case 'l': /* lev, lam, luke */
531 if (c == 'e' || c == 'v') book = (int)LEVIT;
532 else if (c == 'a' || c == 'm') book = (int)LAMENT;
533 else if (c == 'u' || c == 'k') book = (int)LUKE;
535 tsl_error( FALSE, BADBOOK, *s );
539 case 'm': /* micah, malachi, matt, mark */
541 if (c == 'i' || c == 'c') book = (int)MICAH;
543 /* mal, ml, mat, mt, mar, mr, mk (and "mak"!) */
544 if (c == 'a') c = *s1++;
545 if (c == 'l') book = (int)MALACHI;
546 else if (c == 't') book = (int)MATT;
547 else if (c == 'r' || c == 'k') book = (int)MARK;
549 tsl_error( FALSE, BADBOOK, *s );
554 case 'n': /* num, neh, nahum */
556 if (c == 'u' || c == 'm') book = (int)NUM;
557 else if (c == 'e') book = (int)NEHEM;
558 else if (c == 'a') book = (int)NAHUM;
560 tsl_error( FALSE, BADBOOK, *s );
564 case 'o': /* obadiah */
567 case 'p': /* psalms, proverbs, philippians, philemon */
569 if (c == 's') book = (int)PSALMS;
570 else if (c == 'r') book = (int)PROV;
572 if (c == 'h') c = *s1++;
573 if (c == 'i') c = *s1++;
574 if (c == 'l') c = *s1++;
575 if (c == 'i' || c == 'p' || !isalpha(c)) {
576 /* phili, philp, phil, phi, ph, php, pp, etc. */
577 /* This gives preference to Philippians over Philemon */
579 if (!isalpha(c)) s1--; /* point back to the chapter number */
580 } else if (c == 'e' || c == 'm') book = (int)PHILEM;
582 tsl_error( FALSE, BADBOOK, *s );
587 case 'q': /* Not a book, but it makes typing easier */
591 case 'r': /* ruth, romans, revelation */
593 if (c == 'u' || c == 't') book = (int)RUTH;
594 else if (c == 'o' || c == 'm') book = (int)ROMANS;
595 else if (c == 'e' || c == 'v') book = (int)REV;
597 tsl_error( FALSE, BADBOOK, *s );
604 case 't': /* titus */
607 case 'z': /* zeph, zech */
608 if ((c = *s1++) == 'e') c = *s1++;
609 if (c == 'p') book = (int)ZEPH;
610 else if (c == 'c') book = (int)ZECH;
612 tsl_error( FALSE, BADBOOK, *s );
617 tsl_error( FALSE, BADBOOK, *s );
619 } /* switch on first letter of book name */
621 /* Skip any remaining letters in book name */
622 while (isalpha((int)*s1)) s1++;
631 int verse_continuation(char **s,int book,int chapter,int verse,ref_t absverse)
632 /*----------------------------------------------------------------------
637 | <verse continuation> ::= <null>
640 | "s" is pointing to the first char of the <verse
641 | continuation>. If it is a null continuation we leave it
642 | where it is, otherwise on exit we update it to point to
643 | the first non-blank after the continuation.
645 | book -- Number of the book in which the verse spec began.
646 | chapter -- Number of the chapter ...
647 | absverse -- ABSOLUTE VERSE NUMBER where verse spec began
648 | (this is more useful than the relative num).
650 | Returns the total number of verses to be fetched, unless
651 | there was a problem. Returns zero if there was a problem.
655 | 890829 cc Initial implementation (formerly always returned 1).
656 | 890908 cc Error return.
658 \*----------------------------------------------------------------------*/
663 s1 = *s; /* For easier handling. Be sure to update it */
664 n = 1; /* Assume NO following verses */
667 /* yup, there's a continuation */
670 /* special case - end of chapter */
671 n = verse_num( book, chapter, 1000);
674 if (verse_id( &s1, &book, &chapter, &verse ) == 0)
678 /* Determine absolute verse number of ending verse */
679 n = verse_num( book, chapter, verse );
682 /* how many verses is that? */
687 } /* verse_continuation */
691 ref_t verse_id(char **s,int *bookp,int *chapterp,int *versep )
692 /*----------------------------------------------------------------------
697 | <verse id> ::= <book> <chapter> : <verse>
698 | ::= <book> <chapter> # implies vs. 1
699 | ::= <book> # implies 1:1
700 | ::= <chapter> : <verse> # implies current book
701 | ::= <verse> # implies current book/chapter
703 | "s" is pointing to the first character of the <verse id>.
704 | On exit, we update it to be pointing to the next non-blank
705 | after what we've parsed.
707 | The values of *bookp, and *chapterp are used as
708 | defaults in case of a partial verse spec. For example,
709 | "15" would mean verse 15 in the default book/chapter.
711 | We return an absolute verse number (Gen 1:1 == 1) for the
712 | referenced verse. Also update *bookp, *chapterp*, and
713 | *versep with the book, chapter, and verse numbers.
715 | If a problem occurs, we return 0.
718 | 890902 cc Revised to handle incomplete verse specs.
719 | 890908 cc Fix to blank line handling. Revised error return.
721 \*----------------------------------------------------------------------*/
723 short book, chapter, verse;
728 s1 = *s; /* For easier handling. Be sure to update it */
729 if ((book = get_book( &s1, *bookp )) == -1) return 0;
732 /* <verse spec> ::= <book> */
734 /* Special case: if this is a blank line, then print
735 the very next verse. But if there's still junk on
736 the line, then what we have here is an error.
740 tsl_error( FALSE, "Extra garbage on line: '%s'", s1 );
744 /* Get the last verse printed, increment it,
745 and translate that back into book/chapter/verse,
746 while making sure it stays in the proper range.
748 vn = verse_num( *bookp, *chapterp, *versep );
750 vn = brl_extract_num( vn, bookp, chapterp, versep );
761 /* <verse spec> ::= <verse> */
766 /* <verse spec> ::= <book> <chapter> */
771 /* <verse spec> ::= <book> <chapter> : <verse> */
772 /* <verse spec> ::= <chapter> : <verse> */
773 s1++; /* skip past the ':' */
775 book = *bookp; /* default book */
779 tsl_error( FALSE, NO_VERSE, *s );
786 *s = s1; /* Update the pointer we were passed */
790 /* return absolute verse number */
791 return( verse_num( book, chapter, verse ) );
796 ref_t brl_extract_num(ref_t absverse,int *bp,int *cp,int *vp)
797 /*----------------------------------------------------------------------
802 | Extract the book, chapter, [relative] verse corresponding
803 | to the absolute verse number passed in "absverse", if
804 | "absverse" is valid. If it is not valid, then coerce it
805 | into something reasonable. Update book, chapter, and
806 | verse through their pointers "bp", "cp", and "vp",
807 | respectively. Return the [possibly changed] value of
811 | 890904 cc Created (in a hurry)
813 \*----------------------------------------------------------------------*/
818 absverse = 1; /* cheap insurance */
820 for (bk= (int)GENESIS; bk <= (int)REV; bk++)
821 if (absverse <= start_verse[start_chapter[bk+1]+1])
822 /* we've got the right book */
823 for (chp=start_chapter[bk]+1; chp <= start_chapter[bk+1]; chp++)
824 if (absverse <= start_verse[chp+1]) {
825 /* we've got the right chapter */
827 *cp = chp - start_chapter[bk];
828 *vp = absverse - start_verse[chp];
831 /* if we got here, then things are messed up.
832 Assume that the verse is off the back.
835 *cp = start_chapter[ (int)REV+1 ] - start_chapter[(int)REV];
836 *vp = start_verse[(*cp)+1] - start_verse[*cp];
837 return verse_num( *bp, *cp, *vp );
838 } /* brl_extract_num */
842 ref_t verse_num(int b,int c,int v)
843 /*----------------------------------------------------------------------
848 | Return the absolute verse number, given the book, chapter
849 | and [relative] verse number.
851 | Look up the starting absolute verse number of the
852 | specified book/chapter, using the "start_verse" and
853 | "start_chapter" tables, then add the [relative] verse
856 | Error checking: Ensure chapter is not too big for the
857 | book, and that verse is not too big for the chapter.
860 | 890830 cc Created. The original lookup didn't do any
863 \*----------------------------------------------------------------------*/
868 /* force book into proper range */
869 if (b < (int)GENESIS) b = (int)GENESIS;
870 else if (b > (int)REV) b = (int)REV;
872 if ((abschapter = start_chapter[b] + c) > start_chapter[b+1])
873 abschapter = start_chapter[b+1];
874 if ((absverse = start_verse[abschapter] + v) > start_verse[abschapter+1])
875 absverse = start_verse[abschapter+1];
881 ref_t brl_verse_spec(char **s,int *n)
882 /*----------------------------------------------------------------------
888 | <verse spec> ::= <verse id> <verse continuation>
890 | Translate a <verse specifier> string s into a starting
891 | absolute verse number, returned as the function result,
892 | and a count n of verses to read. Gen. 1:1 == verse 1.
894 | Returns 0 if something went wrong, leaving n undefined.
898 \*----------------------------------------------------------------------*/
902 int book, chapter, verse;
904 /* Munge off leading spaces,
905 convert string to lower case,
906 convert commas into blanks, and
907 dispose of possible yucky '\n'.
912 if (isupper((int)*s1)) *s1 = tolower((int)*s1);
915 else if (*s1 == '\n')
920 brl_cur_vnum = brl_extract_num( brl_cur_vnum, &book, &chapter, &verse );
921 if ((av = verse_id( &(*s), &book, &chapter, &verse )) == 0)
924 if ((*n = verse_continuation( &(*s), book, chapter, verse, av )) == 0)
930 } /* brl_verse_spec */
934 #if 0 /* COMMENTED OUT -- NOT USED ANYMORE */
935 int brl_getverse( vs, vb, vbsize, pretty, lwidth )
936 /*----------------------------------------------------------------------
941 | Stuff buffer "vb" with text of verses specified by string
942 | "vs", a <verse spec>.
944 | "pretty" and "lwidth" are formatting options passed to
945 | tsl_gettext. (NOT IMPLEMENTED!)
948 | 890824 cc Created to hide internal functions
949 | tsl_gettext and brl_verse_spec from user programs.
950 | 890912 cc Added pretty and lwidth.
952 \*----------------------------------------------------------------------*/
963 while (*vs && (vn = brl_verse_spec( &vs, &vc )))
964 bytecount += tsl_gettext( vn, vc, vb, vbsize );
971 ref_t brl_printverse(char *vs,int pretty,int lwidth,FILE *outf)
972 /*----------------------------------------------------------------------
977 | Print text to stdout of verses specified by string "vs".
979 | pretty -- If true, then we want special output formatting.
980 | lwidth -- If non-zero, then insert new-lines if necessary
981 | between words to prevent lines from being longer
983 | outf -- If non-NULL, then copy output to this file in
984 | addition to stdout.
986 | Returns absolute verse number of last verse printed.
989 | 890902 cc Created as alternative to brl_getverse.
990 | 890912 cc Added pretty and lwidth.
991 | 921221 cc Print bookname with chapter.
992 | 921223 cc Print chapter heading anytime v.1 is printed.
993 | 930105 cc Added outf functionality & return verse number.
994 | 930422 cc Return correct versenum when errors occur.
995 | 991230 oe Increase VBSIZE to avoid verse truncation.
997 \*----------------------------------------------------------------------*/
1002 /* Length of the longest line is 535, so original length of 512 was not enough */
1004 char vb1[VBSIZE], vb2[VBSIZE];
1005 char *srcp, *dstp, *endp;
1006 int curbook, curchapter, curverse;
1007 int oldbook, oldchapter, oldverse;
1009 if (pretty || lwidth) {
1010 /* Get current context info to help with pretty printing */
1011 brl_cur_vnum = brl_extract_num( brl_cur_vnum,
1012 &oldbook, &oldchapter, &oldverse );
1014 /* Process all verse specs that we're given */
1015 while (*vs && (vref = brl_verse_spec( &vs, &vcount ))) {
1016 brl_cur_vnum = vref +vcount -1; /* Update context.
1017 Won't be used unless next loop
1019 for (vc=vcount, vn=vref; vc; vc--) {
1020 /* get text for a single verse */
1021 len=tsl_gettext( vn++, 1, vb1, VBSIZE );
1026 brl_extract_num( vn-1, &curbook, &curchapter, &curverse );
1027 /* print book/chapter heading?? */
1028 if (curbook != oldbook ||
1029 curchapter != oldchapter ||
1031 /* print chapter heading */
1032 sprintf( dstp, "\n%s %d\n\n",
1033 booknamestr[curbook], curchapter );
1034 /* Advance dstp (supports non-POSIX sprintf) */
1035 while (*dstp) dstp++;
1038 oldchapter = curchapter;
1039 oldverse = curverse;
1041 /* advance to the verse number in source */
1042 while (*srcp != ':') srcp++;
1045 /* insert indentation in dest */
1046 indent = 2; /* two for verse */
1047 *dstp++ = ' '; *dstp++ = ' ';
1051 /* Line width limitation. */
1052 while ((int)strlen(srcp) > (lwidth-indent)) {
1053 /* split this line. But where? */
1054 endp=srcp+lwidth-indent;
1055 while (*endp!=' ' && endp>srcp) endp--;
1057 /* oops. Not enough room for even one word.
1061 while (*endp!=' ' && *endp!='\n' && *endp) endp++;
1064 /* style is to indent only the first line of the
1065 * verse, before the verse number. Subsequent lines
1066 * are *not* indented.
1071 strncpy(dstp, srcp, len);
1074 srcp = ++endp; /* past the ' ' */
1076 /* last line, get the rest */
1079 /* No line length limit.
1080 Just copy the rest of the verse line.
1084 /* now print out the verse */
1085 printf( "%s", vb2 );
1087 fprintf( outf, "%s", vb2 );
1091 /* Raw output. Not pretty or line-wrapped */
1092 while (*vs && (vref = brl_verse_spec( &vs, &vcount )))
1093 tsl_printtext( vref, vcount );
1095 if (vref) return vref + vcount-1;
1096 else return brl_cur_vnum;
1097 } /* brl_printverse */
1101 char* brl_num_to_ref(char *vbuf,ref_t *absversep)
1102 /*----------------------------------------------------------------------
1107 | Accepts an absolute verse number and returns
1108 | a string containing a legal verse reference.
1110 | This is useful with some concordance functions.
1112 | vbuf -- Points to buffer to use for string.
1114 | Returns a copy of vbuf pointer.
1117 | 921217 cc Initial creation.
1119 \*----------------------------------------------------------------------*/
1123 *absversep = brl_extract_num( *absversep, &bk, &chp, &v);
1124 sprintf(vbuf, "%s%d:%d", bookabbrvstr[bk], chp, v);
1126 } /* brl_num_to_ref */
1130 void brl_init(char *dfname,char *dfpath,int memlimit)
1131 /*----------------------------------------------------------------------
1136 | Initialize the library.
1138 | memlimit Limit (in Kbytes) on buffer space used by TSL.
1139 | dfname Name of the data file.
1140 | dfpath List of paths to use in searching for the
1144 | 890830 cc Added memlimit.
1145 | 890905 cc Added filename and paths.
1147 \*----------------------------------------------------------------------*/
1150 dfname = "bible.data";
1152 dfpath = "./ " DESTLIB "/"; /* /usr/lib/; */
1153 tsl_init( dfname, dfpath, memlimit );
1155 /* Set (low) illegal value for current context.
1156 Making it low means that it will be coerced to Gen1:1 if
1157 the user gives a null input.
1163 void brl_close(void)
1164 /*----------------------------------------------------------------------
1169 | Close the library.
1173 \*----------------------------------------------------------------------*/