123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- using System;
- using System.Linq;
- using System.IO;
- namespace QuranCalc
- {
- class MainClass
- {
- public static string[] SurahNames = new string[] { "Al-Fatihah", "Al-Baqarah", "Aal Imran", "An-Nisa'", "Al-Ma'idah", "Al-An'am", "Al-A'raf", "Al-Anfal", "At-Tawbah", "Yunus", "Hud", "Yusuf", "Ar-Ra'd", "Ibraheem", "Al-Hijr", "An-Nahl", "Al-Isra", "Al-Kahf", "Maryam", "Ta-Ha", "Al-Anbiya'", "Al-Hajj", "Al-Mu'minoon", "An-Nur", "Al-Furqan", "Ash-Shu`ara'", "An-Naml", "Al-Qasas", "Al-`Ankabut", "Ar-Rum", "Luqman", "As-Sajdah", "Al-Ahzab", "Saba'", "Fatir", "Ya Sin", "As-Saffat", "Sad", "Az-Zumar", "Ghafir", "Fussilat", "Ash-Shura", "Az-Zukhruf", "Ad-Dukhan", "Al-Jathiyah", "Al-Ahqaf", "Muhammad", "Al-Fath", "Al-Hujurat", "Qaf", "Ad-Dhariyat", "At-Tur", "An-Najm", "Al-Qamar", "Ar-Rahman", "Al-Waqi'ah", "Al-Hadeed", "Al-Mujadilah", "Al-Hashr", "Al-Mumtahanah", "As-Saff", "Al-Jumu'ah", "Al-Munafiqun", "At-Taghabun", "At-Talaq", "At-Tahreem", "Al-Mulk", "Al-Qalam", "Al-Haqqah", "Al-Ma'aarij", "Nuh", "Al-Jinn", "Al-Muzzammil", "Al-Muddathir", "Al-Qiyamah", "Al-Insan", "Al-Mursalat", "An-Naba'", "An-Nazi'at", "`Abasa", "At-Takweer", "Al-Infitar", "Al-Mutaffifeen", "Al-Inshiqaq", "Al-Burooj", "At-Tariq", "Al-A'la", "Al-Ghashiyah", "Al-Fajr", "Al-Balad", "Ash-Shams", "Al-Lail", "Ad-Duha", "Al-Inshirah", "At-Teen", "Al-`Alaq", "Al-Qadr", "Al-Bayyinah", "Az-Zalzala", "Al-Adiyat", "Al-Qari`ah", "At-Takathur", "Al-Asr", "Al-Humazah", "Al-Feel", "Al-Quraish", "Al-Maa'oun", "Al-Kawthar", "Al-Kafiroun", "An-Nasr", "Al-Masad", "Al-Ikhlas", "Al-Falaq", "Al-Nas" };
- public static int Main (string[] args)
- {
- try
- {
- if(AyahIncrementer.Finished)
- AyahIncrementer.Finished = false;
- else
- {
- Console.Error.WriteLine("QuranCalc");
- Console.Error.WriteLine("Copyright (c) 2016 Muhammad Moaz Imtiaz");
- Console.Error.WriteLine(".......................................");
- }
- Console.Write("In how many days would you like to finish the Qur'an? ");
- double days = double.Parse(Console.ReadLine());
- Console.Write("Sittings per day: ");
- double sittings_per_day = double.Parse(Console.ReadLine());
- AyahIncrementer ai = new AyahIncrementer();
- Console.Write("Custom starting point (y/N)? ");
- int startingPoint = 0;
- if(Console.ReadLine().ToLower() == "y")
- {
- Console.Write("Surah number: ");
- int sn = int.Parse(Console.ReadLine());
- for(int i = 1;i < sn;i++)
- ai.Increment(AyahIncrementer.AyahCounts[i-1]);
- Console.Write("Ayah number: ");
- if((startingPoint += int.Parse(Console.ReadLine())) > AyahIncrementer.AyahCounts[sn - 1])
- throw new IndexOutOfRangeException();
- ai.Increment(startingPoint);
- ai.Increment(-1);
- }
- // We do not have support for numbers of pages or ruku' at this time, so we will just calculate based on ayaat.
- int ayaat_per_sitting = (int)Math.Ceiling((6236-startingPoint)/(days*sittings_per_day)); // 6236 is the number of ayaat in the Qur'an.
- string output = string.Empty;
- for(int i = 1; i <= days; i++)
- {
- if(AyahIncrementer.Finished)
- break;
- for(int j = 1;j <= sittings_per_day;j++)
- {
- if(sittings_per_day != 1)
- {
- output += "Day " + i + ",Sitting " + j + "," + ai.NextAyah + " to ";
- Console.Write("Day " + i + ", Sitting " + j + ":\t" + ai.NextAyah + " to ");
- }
- else
- {
- output += "Day " + i + "," + ai.NextAyah + " to ";
- Console.Write("Day " + i + ":\t" + ai.NextAyah + " to ");
- }
- ai.Increment(ayaat_per_sitting);
- output += ai.LastAyah;
- Console.Write(ai.LastAyah);
- if(j == sittings_per_day && sittings_per_day != 1)
- {
- output += " *";
- Console.Write(" *");
- }
- output += Environment.NewLine;
- Console.WriteLine();
- }
- }
- output += "Ayaat per sitting: " + ayaat_per_sitting + Environment.NewLine;
- output += "Ayaat per day: " + ayaat_per_sitting*sittings_per_day + Environment.NewLine;
- Console.Write("Ayaat per sitting: " + ayaat_per_sitting + Environment.NewLine);
- Console.Write("Ayaat per day: " + ayaat_per_sitting*sittings_per_day + Environment.NewLine);
- Console.Write("Output to CSV? (y/N)? ");
- if(Console.ReadLine().ToLower() == "y") {
- string name = string.Empty;
- using(Stream stream = File.OpenWrite(name = DateTime.Now.ToString("s").Replace("-", "").Replace(":", "").Replace('T', '_') + ".csv"))
- using(StreamWriter sw = new StreamWriter(stream)) {
- sw.Write(output.TrimEnd(Environment.NewLine.ToArray()));
- }
- Console.WriteLine("Done! File written to " + name + ".");
- }
- Console.Write("Calculate again (y/N)? ");
- if(Console.ReadLine().ToLower() == "y")
- Main(args);
- return 0;
- }
- catch(Exception e) {
- Console.Error.WriteLine ("Traceback (most recent call last):");
- Console.Error.Write (Traceback.Read ());
- Console.Error.WriteLine ("At int Main(string[]) (class MainClass):");
- Console.Error.WriteLine ("Error: " + e.GetType ().ToString () + " occurred.");
- Console.Error.WriteLine ("Description: " + e.Message);
- return -1;
- }
- }
- }
- }
|