trying to read license from file instead
This commit is contained in:
parent
e872bca0e0
commit
96559b7870
2 changed files with 72 additions and 28 deletions
4
Makefile
4
Makefile
|
@ -5,7 +5,7 @@ include config.mk
|
||||||
SRC = uirc.c
|
SRC = uirc.c
|
||||||
|
|
||||||
uirc: ${SRC}
|
uirc: ${SRC}
|
||||||
${CC} -o uirc -O ${SRC}
|
${CC} -DLICENSE_DIR='"./"' -o uirc -O ${SRC}
|
||||||
|
|
||||||
install: uirc
|
install: uirc
|
||||||
mkdir -p ${PREFIX}
|
mkdir -p ${PREFIX}
|
||||||
|
@ -21,7 +21,7 @@ uninstall:
|
||||||
|
|
||||||
stb:
|
stb:
|
||||||
@echo "It is best to download the stb library from your system's package manager."
|
@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
|
@read
|
||||||
mkdir -p ${INCLUDE_PREFIX}/stb
|
mkdir -p ${INCLUDE_PREFIX}/stb
|
||||||
wget https://raw.githubusercontent.com/nothings/stb/master/stb_image.h -P /usr/include/stb/stb_image.h
|
wget https://raw.githubusercontent.com/nothings/stb/master/stb_image.h -P /usr/include/stb/stb_image.h
|
||||||
|
|
96
uirc.c
96
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 <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -11,9 +45,9 @@ int handleArg(arg) char *arg; {
|
||||||
char flag, *longFlag, first, firstTwo[3];
|
char flag, *longFlag, first, firstTwo[3];
|
||||||
const char *help;
|
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-h\t> Display this message\n"
|
||||||
"\t-l\t> Display the license disclaimer for uirc (BSD 2-Clause)\n\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';
|
firstTwo[2] = '\0';
|
||||||
size = sizeof arg;
|
size = sizeof arg;
|
||||||
|
|
||||||
//if (strcmp(longFlag, firstTwo) == 0) {
|
// determine if any arguments are flags
|
||||||
//printf("it has two dashes\n");
|
if (strcmp(longFlag, firstTwo) == 0) {
|
||||||
// switch (arg) {
|
printf("ok");
|
||||||
// case "--okay":
|
return 0;
|
||||||
// printf("success");
|
} else if (flag == first) {
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// printf("failure");
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// return 0;
|
|
||||||
//} else if (flag == first) {
|
|
||||||
// printf("it has a dash\n");
|
|
||||||
// return 0;
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (flag == first) {
|
|
||||||
for (int i = 1; i < size; i++) {
|
for (int i = 1; i < size; i++) {
|
||||||
switch (arg[i]) {
|
switch (arg[i]) {
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -58,16 +80,15 @@ int handleArg(arg) char *arg; {
|
||||||
printf("%s\n", help);
|
printf("%s\n", help);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
printf("%s\n", license);
|
readLicense();
|
||||||
break;
|
break;
|
||||||
case '\0':
|
case '\0':
|
||||||
break;
|
break;
|
||||||
//default:
|
|
||||||
// printf("uirc: invalid argument \"%s\"\n", arg);
|
|
||||||
// return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
// if no more flags, run ratio calculations
|
||||||
|
|
||||||
return 0;
|
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 main(argc, argv) int argc; char *argv[]; {
|
||||||
//int i;
|
//int i;
|
||||||
char *i;
|
char *i;
|
||||||
|
@ -86,9 +127,12 @@ int main(argc, argv) int argc; char *argv[]; {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *a = argv[1];
|
for (int i = 1; i < argc; i++) {
|
||||||
return handleArg(a);
|
char *a = argv[1];
|
||||||
|
int returned = handleArg(a);
|
||||||
|
if (returned != 0)
|
||||||
|
return returned;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue