summaryrefslogtreecommitdiff
path: root/uirc.c
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2022-03-15 10:52:23 -0600
committerBryson Steck <steck.bryson@gmail.com>2022-03-15 10:52:23 -0600
commit96559b7870450517711bb8ccf7c5bf0b9fba8df9 (patch)
tree2bac45fff0006ab2a48b8e4ba1bb2a00f78e2328 /uirc.c
parente872bca0e085e6ef7b91e21a2d9399a8db5414df (diff)
downloaduirc-96559b7870450517711bb8ccf7c5bf0b9fba8df9.tar
uirc-96559b7870450517711bb8ccf7c5bf0b9fba8df9.tar.gz
uirc-96559b7870450517711bb8ccf7c5bf0b9fba8df9.tar.bz2
trying to read license from file instead
Diffstat (limited to 'uirc.c')
-rw-r--r--uirc.c96
1 files changed, 70 insertions, 26 deletions
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 <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -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;
+ }
}