11 static size_t file_size(int fd
)
19 static int newlines(char *s
)
22 for (n
= 0; (s
= strchr(s
, '\n')); s
++, n
++);
26 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
)
39 nayas
= newlines(quran
->text
);
40 quran
->ayas
= xmalloc(sizeof(quran
->ayas
) * nayas
);
41 quran
->ayas
[0] = quran
->text
;
42 for (i
= 1; i
< nayas
; i
++)
43 quran
->ayas
[i
] = strchr(quran
->ayas
[i
- 1], '\n') + 1;
47 void quran_aya(struct quran
*quran
, char *buf
, size_t len
, int aya
)
49 char *s
= quran
->ayas
[aya
];
50 char *e
= strchr(s
, '\n');
55 buf
[buf
[n
- 1] == '\r' ? n
- 1 : n
] = '\0';
58 void quran_free(struct quran
*quran
)
60 munmap(quran
->text
, file_size(quran
->fd
));
67 7, 286, 200, 176, 120, 165, 206, 75, 129, 109,
68 123, 111, 43, 52, 99, 128, 111, 110, 98, 135,
69 112, 78, 118, 64, 77, 227, 93, 88, 69, 60,
70 34, 30, 73, 54, 45, 83, 182, 88, 75, 85,
71 54, 53, 89, 59, 37, 35, 38, 29, 18, 45,
72 60, 49, 62, 55, 78, 96, 29, 22, 24, 13,
73 14, 11, 11, 18, 12, 12, 30, 52, 52, 44,
74 28, 28, 20, 56, 40, 31, 50, 40, 46, 42,
75 29, 19, 36, 25, 22, 17, 19, 26, 30, 20,
76 15, 21, 11, 8, 8, 19, 5, 8, 8, 11,
77 11, 8, 3, 9, 5, 4, 7, 3, 6,
80 int sura_ayas(int sura
)
82 return ayas
[sura
- 1];
85 int sura_start(int sura
)
89 for (i
= 0; i
< sura
- 1; i
++)
94 int aya_num(int sura
, int aya
)
96 return sura_start(sura
) + aya
;
99 #define AYAHASH(sura, aya) (((sura) << 10) | (aya))
101 int juz_start(int sura
, int aya
)
103 switch (AYAHASH(sura
, aya
)) {
106 case AYAHASH(2, 142):
108 case AYAHASH(2, 253):
114 case AYAHASH(4, 148):
118 case AYAHASH(6, 111):
128 case AYAHASH(12, 53):
134 case AYAHASH(18, 75):
140 case AYAHASH(25, 21):
142 case AYAHASH(27, 56):
144 case AYAHASH(29, 46):
146 case AYAHASH(33, 31):
148 case AYAHASH(36, 28):
150 case AYAHASH(39, 32):
152 case AYAHASH(41, 47):
156 case AYAHASH(51, 31):
168 enum sajda
sajda_kind(int sura
, int aya
)
170 switch (AYAHASH(sura
, aya
)) {
171 case AYAHASH(7, 206):
173 case AYAHASH(13, 15):
175 case AYAHASH(16, 50):
177 case AYAHASH(17, 109):
179 case AYAHASH(19, 58):
181 case AYAHASH(22, 18):
183 case AYAHASH(22, 77):
185 case AYAHASH(25, 60):
187 case AYAHASH(27, 26):
189 case AYAHASH(32, 15):
191 case AYAHASH(38, 24):
193 case AYAHASH(41, 38):
195 case AYAHASH(53, 62):
197 case AYAHASH(84, 21):
199 case AYAHASH(96, 19):