Mercurial Hosting > scripturereader
changeset 0:6e1857de3922
Finished
author | VilyaemKenyaz |
---|---|
date | Fri, 25 Aug 2023 14:14:24 -0400 |
parents | |
children | 11373687393b |
files | README.md c.ksh scripturereader scripturereader.c |
diffstat | 4 files changed, 110 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r 000000000000 -r 6e1857de3922 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Aug 25 14:14:24 2023 -0400 @@ -0,0 +1,9 @@ +# ScriptureReader +'scripturereader' is a plaintext file reader in C, it is helpful for reading scripture or any text. +NB to traverse and Q to quit. +Usage: + +scripturereader (textfile name) + +Reading the Orthodox Study Bible +scripturereader OSB
diff -r 000000000000 -r 6e1857de3922 c.ksh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c.ksh Fri Aug 25 14:14:24 2023 -0400 @@ -0,0 +1,7 @@ +#!/bin/ksh +rm scripturereader +clear +printf "Compiling\n" +tcc scripturereader.c -o scripturereader +cp scripturereader /usr/bin/ +
diff -r 000000000000 -r 6e1857de3922 scripturereader.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripturereader.c Fri Aug 25 14:14:24 2023 -0400 @@ -0,0 +1,94 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define PAGE_SIZE 50 + +void print_page(const char* filename, int page_number, int total_pages) { + system("clear"); + printf("---SCRIPTURE-READER---\n"); + FILE* file = fopen(filename, "r"); + if (file == NULL) { + printf("Error opening file: %s\n", filename); + exit(1); + } + + char line[256]; + int line_count = 0; + int current_page = 1; + + while (fgets(line, sizeof(line), file)) { + line_count++; + if (line_count > (page_number - 1) * PAGE_SIZE && line_count <= page_number * PAGE_SIZE) { + printf("%s", line); + } + if (line_count > page_number * PAGE_SIZE) { + break; + } + } + + fclose(file); + + printf("\n--- Page %d of %d ---\n", page_number, total_pages); +} + +int get_total_pages(const char* filename) { + FILE* file = fopen(filename, "r"); + if (file == NULL) { + printf("Error opening file: %s\n", filename); + exit(1); + } + + char line[256]; + int line_count = 0; + + while (fgets(line, sizeof(line), file)) { + line_count++; + } + + fclose(file); + + return (line_count + PAGE_SIZE - 1) / PAGE_SIZE; +} + +int main(int argc, char* argv[]) { + if (argc < 2 || argc > 3) { + printf("ScriptureReader by William @ peepsoftgames.github.io thekenyaz@yandex.com\n"); + printf("Usage:\n"); + printf(" scripturereader <textfile>\n"); + return 1; + } + + const char* filename = argv[1]; + + int total_pages = get_total_pages(filename); + int current_page = 1; + + while (1) { + system("clear"); + print_page(filename, current_page, total_pages); + + char ch; + scanf(" %c", &ch); + switch (ch) { + case 'l': + case 'L': + if (current_page > 1) { + current_page--; + } + break; + case 'r': + case 'R': + if (current_page < total_pages) { + current_page++; + } + break; + case 'q': + case 'Q': + exit(0); + } + } + + exit(0); +} +