change G command to move to the specified aya
[cnoor.git] / cnoor.c
blobf7886dac1f3c1c5f52c99865c215702acd0e4264
1 /*
2 * cnoor - a small framebuffer/GTK+ Quran viewer
4 * Copyright (C) 2009-2011 Ali Gholami Rudi
6 * This program is released under GNU GPL version 2.
7 */
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include "config.h"
13 #include "txtwin.h"
14 #include "quran.h"
16 #define LENGTH(vars) (sizeof(vars) / sizeof(vars[0]))
18 static void ins_sura(struct quran *quran, struct quran *trans, int sura)
20 char buf[16 * 1024];
21 int start = sura_start(sura);
22 int ayas = sura_ayas(sura);
23 int i;
24 for (i = 0; i < ayas; i++) {
25 int juz = juz_start(sura, i + 1);
26 int sajda = sajda_kind(sura, i + 1);
27 txtwin_line();
28 if (juz) {
29 sprintf(buf, "%d\n", juz);
30 txtwin_append(buf, FONT_JUZ);
32 quran_aya(quran, buf, LENGTH(buf), start + i);
33 txtwin_append(buf, FONT_QURAN);
34 sprintf(buf, " %d ", i + 1);
35 txtwin_append(buf, FONT_NUM);
36 if (sajda != SAJDA_NONE) {
37 char *s = sajda == SAJDA_RECOM ? "*" : "**";
38 txtwin_append(s, FONT_SAJDA);
40 if (trans) {
41 quran_aya(trans, buf, LENGTH(buf), start + i);
42 txtwin_append("\n", NULL);
43 txtwin_append(buf, FONT_TRANS);
45 txtwin_append("\n\n", NULL);
49 int show(int sura)
51 char name[128];
52 struct quran *quran;
53 struct quran *trans = NULL;
54 sprintf(name, "%d(%s)", sura, sura_name(sura));
55 quran = quran_alloc(QURAN_PATH);
56 if (TRANS_PATH)
57 trans = quran_alloc(TRANS_PATH);
58 txtwin_init(name);
59 ins_sura(quran, trans, sura);
60 txtwin_loop();
61 txtwin_free();
62 if (trans)
63 quran_free(trans);
64 quran_free(quran);
65 return 0;
68 int main(int argc, char **argv)
70 int sura;
71 if (argc == 1 || !strcmp(argv[1], "-h")) {
72 printf("usage: %s sura_number\n", argv[0]);
73 return 0;
75 sura = atoi(argv[1]);
76 if (sura <= 0 || sura > 114) {
77 fprintf(stderr, "cnoor: invalid sura number\n");
78 return 1;
80 txtwin_gtk_init(argc, argv);
81 show(sura);
82 return 0;