Narthex

Modular dictionary generator
git clone git@git.mcdim.xyz:/var/www/git/Narthex.git
Log | Files | Refs | README | LICENSE

commit e509529a845c6522a9a3a82a2af7aedc4a7e8c87
parent 827f8abd4b8d5722cd5e919a14ce71fba92cc843
Author: Michael Constantine Dimopoulos <mk@mcdim.xyz>
Date:   Wed, 11 Aug 2021 10:30:21 +0000

Updated ninc

Diffstat:
Minc/nin.c | 64+++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 35 insertions(+), 29 deletions(-)

diff --git a/inc/nin.c b/inc/nin.c @@ -1,8 +1,3 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> - /* * ninc - Narthex incrementor * @@ -23,9 +18,36 @@ * */ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> + #define VERSION "v1.0" #define BUFFER_SIZE 256 +static void +help(char * exename) +{ + printf( "ninc - Narthex incrementor %s\n" + "By Michael C. Dim. <mk@mcdim.xyz>\n\n" + + "-n Increment numerical lines as well\n" + "-h Print this panel & exit\n" + "-v Print current version & exit\n\n" + + "Usage: cat [FILENAME] | %s [MIN] [MAX] [OPTIONS]\n", + VERSION, exename); + exit(EXIT_SUCCESS); +} + +static void +die(char * str) +{ + printf("%d\n", str); + exit(EXIT_SUCCESS); +} + FILE * save_stdin(FILE *f) { @@ -48,6 +70,12 @@ isnumber(char * str) return 0; } +static int +check_num(int numerical, char * buffer) +{ + return ((numerical == 0 && isnumber(buffer) == 0) || numerical == 1); +} + static void ninc(FILE *f, int min, int max, int numerical) { @@ -55,14 +83,14 @@ ninc(FILE *f, int min, int max, int numerical) while (fgets(buffer, sizeof(buffer), f) != NULL) { strtok(buffer, "\n"); for (int i = min; i <= max; i++) { - if ((numerical == 0 && isnumber(buffer) == 0) || numerical == 1) { + if (check_num(numerical, buffer) == 1) { printf("%s%d\n", buffer, i); } } } } -void +static void print_only(FILE *f) { char buffer[BUFFER_SIZE]; @@ -71,28 +99,6 @@ print_only(FILE *f) } } -static void -help(char * exename) -{ - printf( "ninc - Narthex incrementor %s\n" - "By Michael C. Dim. <mk@mcdim.xyz>\n\n" - - "-n Increment numerical lines as well\n" - "-h Print this panel & exit\n" - "-v Print current version & exit\n\n" - - "Usage: cat [FILENAME] | %s [MIN] [MAX] [OPTIONS]\n", - VERSION, exename); - exit(EXIT_SUCCESS); -} - -static void -die(char * str) -{ - printf("%d\n", str); - exit(EXIT_SUCCESS); -} - void main(int argc, char * argv[]) {