10 static size_t file_size(char *path
)
18 static char *file_read(char *path
)
24 size_t size
= file_size(path
);
26 fd
= open(path
, O_RDONLY
);
27 while ((c
= read(fd
, buf
+ n
, size
- n
)) > 0)
33 static int newlines(char *s
)
36 for (n
= 0; (s
= strchr(s
, '\n')); s
++, n
++);
40 struct quran
*quran_alloc(char *path
)
44 struct quran
*quran
= xmalloc(sizeof(struct quran
));
45 memset(quran
, 0, sizeof(quran
));
46 quran
->text
= file_read(path
);
47 nayas
= newlines(quran
->text
);
48 quran
->ayas
= xmalloc(sizeof(quran
->ayas
) * nayas
);
49 quran
->ayas
[0] = quran
->text
;
50 for (i
= 1; i
< nayas
; i
++)
51 quran
->ayas
[i
] = strchr(quran
->ayas
[i
- 1], '\n') + 1;
55 void quran_aya(struct quran
*quran
, char *buf
, size_t len
, int aya
)
57 char *s
= quran
->ayas
[aya
];
58 char *e
= strchr(s
, '\n');
63 buf
[buf
[n
- 1] == '\r' ? n
- 1 : n
] = '\0';
66 void quran_free(struct quran
*quran
)
74 7, 286, 200, 176, 120, 165, 206, 75, 129, 109,
75 123, 111, 43, 52, 99, 128, 111, 110, 98, 135,
76 112, 78, 118, 64, 77, 227, 93, 88, 69, 60,
77 34, 30, 73, 54, 45, 83, 182, 88, 75, 85,
78 54, 53, 89, 59, 37, 35, 38, 29, 18, 45,
79 60, 49, 62, 55, 78, 96, 29, 22, 24, 13,
80 14, 11, 11, 18, 12, 12, 30, 52, 52, 44,
81 28, 28, 20, 56, 40, 31, 50, 40, 46, 42,
82 29, 19, 36, 25, 22, 17, 19, 26, 30, 20,
83 15, 21, 11, 8, 8, 19, 5, 8, 8, 11,
84 11, 8, 3, 9, 5, 4, 7, 3, 6,
87 int sura_ayas(int sura
)
89 return ayas
[sura
- 1];
92 int sura_start(int sura
)
96 for (i
= 0; i
< sura
- 1; i
++)
101 int aya_num(int sura
, int aya
)
103 return sura_start(sura
) + aya
;
106 #define AYAHASH(sura, aya) (((sura) << 10) | (aya))
108 int juz_start(int sura
, int aya
)
110 switch (AYAHASH(sura
, aya
)) {
113 case AYAHASH(2, 142):
115 case AYAHASH(2, 253):
121 case AYAHASH(4, 148):
125 case AYAHASH(6, 111):
135 case AYAHASH(12, 53):
141 case AYAHASH(18, 75):
147 case AYAHASH(25, 21):
149 case AYAHASH(27, 56):
151 case AYAHASH(29, 46):
153 case AYAHASH(33, 31):
155 case AYAHASH(36, 28):
157 case AYAHASH(39, 32):
159 case AYAHASH(41, 47):
163 case AYAHASH(51, 31):
175 enum sajda
sajda_kind(int sura
, int aya
)
177 switch (AYAHASH(sura
, aya
)) {
178 case AYAHASH(7, 206):
180 case AYAHASH(13, 15):
182 case AYAHASH(16, 50):
184 case AYAHASH(17, 109):
186 case AYAHASH(19, 58):
188 case AYAHASH(22, 18):
190 case AYAHASH(22, 77):
192 case AYAHASH(25, 60):
194 case AYAHASH(27, 26):
196 case AYAHASH(32, 15):
198 case AYAHASH(38, 24):
200 case AYAHASH(41, 38):
202 case AYAHASH(53, 62):
204 case AYAHASH(84, 21):
206 case AYAHASH(96, 19):