41 lines
944 B
C
41 lines
944 B
C
|
/** @license 2022 Neil Edelman, distributed under the terms of the
|
||
|
[MIT License](https://opensource.org/licenses/MIT).
|
||
|
Is intended to use
|
||
|
<https://github.com/scrollmapper/bible_databases/master/txt/KJV/>. */
|
||
|
|
||
|
#include "../src/kjv.h"
|
||
|
#include <assert.h>
|
||
|
#include <errno.h>
|
||
|
#include <stdio.h> /* debug */
|
||
|
|
||
|
static int parse_natural(const char *s, const char *const e, unsigned *const n) {
|
||
|
unsigned a = 0;
|
||
|
while(s < e) {
|
||
|
unsigned b = a * 10 + (unsigned)(*s - '0');
|
||
|
if(a >= b) return errno = ERANGE, 0;
|
||
|
a = b;
|
||
|
s++;
|
||
|
}
|
||
|
*n = a;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
/*!re2c /**/
|
||
|
re2c:yyfill:enable = 0;
|
||
|
re2c:define:YYCTYPE = char;
|
||
|
sentinel = "\x00";
|
||
|
newline = "\n";
|
||
|
natural = [1-9][0-9]*;
|
||
|
*/
|
||
|
|
||
|
int kjv_filename(const char *fn, unsigned *book_no) {
|
||
|
const char *YYCURSOR = fn, *YYMARKER, *yyt1, *yyt2, *s0, *s1;
|
||
|
assert(fn && book_no);
|
||
|
/*!re2c /**/
|
||
|
*
|
||
|
{ return 0; }
|
||
|
@s0 natural @s1 [^.\x00]* ".txt" sentinel
|
||
|
{ return parse_natural(s0, s1, book_no); }
|
||
|
*/
|
||
|
}
|