#include "./main.h" void printhelp(void) { fprintf(stderr, "even: a binary by ZachIR to check if a number is even or "); fprintf(stderr, "odd.\n"); fprintf(stderr, "even [-hcv]\n"); fprintf(stderr, "even [--help]\n"); fprintf(stderr, "even [--copyright]\n"); fprintf(stderr, "even [--version]\n"); fprintf(stderr, "even [-q] [--quiet] NUMBER\n"); fprintf(stderr, "\t-h: prints this help message\n"); fprintf(stderr, "\t-c: prints the copyright information\n"); fprintf(stderr, "\t-v: prints the version\n"); fprintf(stderr, "\t-q: just uses error codes, no text\n"); return; } void printcopyright(void) { fprintf(stderr, "Copyright (c) 2024 Zachary Smith\n"); fprintf(stderr, "even is Free software under the MIT license, and is "); fprintf(stderr, "provided without warranty of any kind.\n"); return; } void printversion(void) { fprintf(stderr, "even version %s, 2024\n", VERSION); return; } int main(int argc, char **argv) { bool quiet; bool value; long result; quiet = false; value = false; result = 0; char *output; if (argc > 1) { for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'h': printhelp(); return SUCCESS; case 'c': printcopyright(); return SUCCESS; case 'v': printversion(); return SUCCESS; case 'q': quiet = true; break; } } result = strtol(argv[i], &output, 10); value = true; } } else { printhelp(); return ERR; } if (value) { if (result % 2 == 0) { if (!quiet) { fprintf(stdout, "even\n"); } return 0; } else { if (!quiet) { fprintf(stdout, "odd\n"); return 0; } return 1; } } return ERR; }