11 static size_t file_size(int fd
)
19 static void init_ayas(struct quran
*quran
)
22 char *s
= quran
->text
;
23 quran
->ayas
[0] = quran
->text
;
24 while (i
< NAYA
&& (s
= strchr(s
, '\n')))
25 quran
->ayas
[++i
] = ++s
;
28 struct quran
*quran_alloc(char *path
)
30 struct quran
*quran
= xmalloc(sizeof(struct quran
));
31 memset(quran
, 0, sizeof(quran
));
32 quran
->fd
= open(path
, O_RDONLY
);
35 quran
->text
= mmap(NULL
, file_size(quran
->fd
), PROT_READ
,
36 MAP_SHARED
, quran
->fd
, 0);
37 if (quran
->text
== MAP_FAILED
)
43 void quran_aya(struct quran
*quran
, char *buf
, size_t len
, int aya
)
45 char *s
= quran
->ayas
[aya
];
46 char *e
= strchr(s
, '\n');
51 buf
[buf
[n
- 1] == '\r' ? n
- 1 : n
] = '\0';
54 void quran_free(struct quran
*quran
)
56 munmap(quran
->text
, file_size(quran
->fd
));
62 7, 286, 200, 176, 120, 165, 206, 75, 129, 109,
63 123, 111, 43, 52, 99, 128, 111, 110, 98, 135,
64 112, 78, 118, 64, 77, 227, 93, 88, 69, 60,
65 34, 30, 73, 54, 45, 83, 182, 88, 75, 85,
66 54, 53, 89, 59, 37, 35, 38, 29, 18, 45,
67 60, 49, 62, 55, 78, 96, 29, 22, 24, 13,
68 14, 11, 11, 18, 12, 12, 30, 52, 52, 44,
69 28, 28, 20, 56, 40, 31, 50, 40, 46, 42,
70 29, 19, 36, 25, 22, 17, 19, 26, 30, 20,
71 15, 21, 11, 8, 8, 19, 5, 8, 8, 11,
72 11, 8, 3, 9, 5, 4, 7, 3, 6, 3,
75 int sura_ayas(int sura
)
77 return ayas
[sura
- 1];
80 int sura_start(int sura
)
84 for (i
= 0; i
< sura
- 1; i
++)
89 int aya_num(int sura
, int aya
)
91 return sura_start(sura
) + aya
;
94 #define AYAHASH(sura, aya) (((sura) << 10) | (aya))
96 int juz_start(int sura
, int aya
)
98 switch (AYAHASH(sura
, aya
)) {
101 case AYAHASH(2, 142):
103 case AYAHASH(2, 253):
109 case AYAHASH(4, 148):
113 case AYAHASH(6, 111):
123 case AYAHASH(12, 53):
129 case AYAHASH(18, 75):
135 case AYAHASH(25, 21):
137 case AYAHASH(27, 56):
139 case AYAHASH(29, 46):
141 case AYAHASH(33, 31):
143 case AYAHASH(36, 28):
145 case AYAHASH(39, 32):
147 case AYAHASH(41, 47):
151 case AYAHASH(51, 31):
163 enum sajda
sajda_kind(int sura
, int aya
)
165 switch (AYAHASH(sura
, aya
)) {
166 case AYAHASH(7, 206):
168 case AYAHASH(13, 15):
170 case AYAHASH(16, 50):
172 case AYAHASH(17, 109):
174 case AYAHASH(19, 58):
176 case AYAHASH(22, 18):
178 case AYAHASH(22, 77):
180 case AYAHASH(25, 60):
182 case AYAHASH(27, 26):
184 case AYAHASH(32, 15):
186 case AYAHASH(38, 24):
188 case AYAHASH(41, 38):
190 case AYAHASH(53, 62):
192 case AYAHASH(84, 21):
194 case AYAHASH(96, 19):