From 96559b7870450517711bb8ccf7c5bf0b9fba8df9 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Tue, 15 Mar 2022 10:52:23 -0600 Subject: trying to read license from file instead --- Makefile | 4 +-- uirc.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 7063fba..236977f 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ include config.mk SRC = uirc.c uirc: ${SRC} - ${CC} -o uirc -O ${SRC} + ${CC} -DLICENSE_DIR='"./"' -o uirc -O ${SRC} install: uirc mkdir -p ${PREFIX} @@ -21,7 +21,7 @@ uninstall: stb: @echo "It is best to download the stb library from your system's package manager." - @echo "Press ENTER to manually install the stb headers needed. Otherwise, quit with ^C" + @echo "Press ENTER to manually install the stb headers needed instead. Otherwise, quit with ^C" @read mkdir -p ${INCLUDE_PREFIX}/stb wget https://raw.githubusercontent.com/nothings/stb/master/stb_image.h -P /usr/include/stb/stb_image.h diff --git a/uirc.c b/uirc.c index bedf76d..1d62fe9 100644 --- a/uirc.c +++ b/uirc.c @@ -1,3 +1,37 @@ +/* + +uirc: an unnecessary image ratio calculator +Created by Bryson Steck (@brysonsteck on GitHub) +Free and Open Source Software under the BSD 2-Clause License + +BSD 2-Clause License + +Copyright (c) 2022, Bryson Steck +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + #include #include #include @@ -11,9 +45,9 @@ int handleArg(arg) char *arg; { char flag, *longFlag, first, firstTwo[3]; const char *help; - help = "usage: uirc [-hl] [-r] IMAGE1 [IMAGE2] [...]\n\n" + help = "usage: uirc [OPTIONS] IMAGE1 [IMAGE2] [...]\n\n" - "options:\n" + "OPTIONS:\n" "\t-h\t> Display this message\n" "\t-l\t> Display the license disclaimer for uirc (BSD 2-Clause)\n\n" @@ -33,23 +67,11 @@ int handleArg(arg) char *arg; { firstTwo[2] = '\0'; size = sizeof arg; - //if (strcmp(longFlag, firstTwo) == 0) { - //printf("it has two dashes\n"); - // switch (arg) { - // case "--okay": - // printf("success"); - // break; - // default: - // printf("failure"); - // break; - // } - // return 0; - //} else if (flag == first) { - // printf("it has a dash\n"); - // return 0; - //} - - if (flag == first) { + // determine if any arguments are flags + if (strcmp(longFlag, firstTwo) == 0) { + printf("ok"); + return 0; + } else if (flag == first) { for (int i = 1; i < size; i++) { switch (arg[i]) { case 'h': @@ -58,16 +80,15 @@ int handleArg(arg) char *arg; { printf("%s\n", help); break; case 'l': - printf("%s\n", license); + readLicense(); break; case '\0': break; - //default: - // printf("uirc: invalid argument \"%s\"\n", arg); - // return 1; } } + return 0; } + // if no more flags, run ratio calculations return 0; @@ -77,6 +98,26 @@ int readFile() { } +void readLicense() { + FILE *license; + char ch; + + license = fopen(LICENSE_DIR "LICENSE", "r"); + if (license == NULL) { + printf("uirc: cannot find LICENSE in %s\n", LICENSE_DIR); + printf("uirc: if you changed the location of the file, recompile uirc with the correct location or move the file back\n"); + exit(2); + } else { + printf("uirc is Free and Open Source Software under the BSD 2-Clause License:\n\n"); + do { + ch = fgetc(license); + printf("%c", ch); + } while (ch != EOF); + } + fclose(license); + return; +} + int main(argc, argv) int argc; char *argv[]; { //int i; char *i; @@ -86,9 +127,12 @@ int main(argc, argv) int argc; char *argv[]; { return 1; } - char *a = argv[1]; - return handleArg(a); - + for (int i = 1; i < argc; i++) { + char *a = argv[1]; + int returned = handleArg(a); + if (returned != 0) + return returned; + } } -- cgit v1.2.3