diff options
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | config.mk | 6 | ||||
-rw-r--r-- | uirc.1 | 18 | ||||
-rw-r--r-- | uirc.c | 20 |
4 files changed, 42 insertions, 23 deletions
@@ -5,21 +5,26 @@ include config.mk SRC = uirc.c uirc: ${SRC} - ${CC}${OPTIONS} -o uirc -O3 ${SRC} -lcurl -lm + ${CC} ${OPTIONS} -o uirc ${SRC} -lcurl -lm debug: uirc - ${CC} -g${OPTIONS} -o d_uirc -O3 ${SRC} -lcurl -lm + ${CC} -g ${OPTIONS} -o d_uirc -O3 ${SRC} -lcurl -lm gdb d_uirc rm d_uirc +clean: + rm ./uirc + install: uirc - mkdir -p ${PREFIX} - cp -f uirc ${PREFIX} - chmod 755 ${PREFIX}/uirc + mkdir -p ${PREFIX}/bin + cp -f uirc ${PREFIX}/bin + chmod 755 ${PREFIX}/bin/uirc + mkdir -p ${MAN_PREFIX}/man1 + cp -f uirc.1 ${MAN_PREFIX}/man1 uninstall: - rm ${PREFIX}/uirc - test -s ${INCLUDE_PREFIX}/uirc && rm -r ${INCLUDE_PREFIX}/uirc + rm ${PREFIX}/bin/uirc + rm ${MAN_PREFIX}/man1/uirc.1 stb: @echo "It is best to download the stb library from your system's package manager." @@ -28,4 +33,4 @@ stb: mkdir -p ${INCLUDE_PREFIX}/stb wget https://raw.githubusercontent.com/nothings/stb/master/stb_image.h -P ${INCLUDE_PREFIX}/stb -.PHONY: uirc install stb +.PHONY: uirc clean install uninstall stb @@ -1,11 +1,15 @@ # install location -PREFIX = /usr/local/bin +PREFIX = /usr/local +MAN_PREFIX = ${PREFIX}/share/man LIB_PREFIX = ${PREFIX}/lib INCLUDE_PREFIX = /usr/include # comment the line above and uncomment the following line # if you are building on macOS, otherwise it is optional #INCLUDE_PREFIX = /usr/local/include +# additional compiler options +OPTIONS = -O2 + # manual install location MANPREFIX = ${PREFIX}/share/man @@ -1,9 +1,9 @@ -.TH UIRC 1 "Updated March 26, 2022" "Bryson Steck" +.TH UIRC 1 "Updated June 20, 2022" "Bryson Steck" .SH NAME uirc \- an unneccessary image ratio calculator .SH SYNOPSIS .B uirc -[OPTIONS] IMAGE/URL1 [IMAGE/URL2]... +[\fB-hlvr\fR] [\fIarguments\fR ...] .SH DESCRIPTION uirc is, well, an unnecessary image ratio calculator for us UNIX nerds. It takes files with an image format and returns the ratio of the image. .P @@ -11,7 +11,7 @@ Here are some examples for you. You can use uirc in three different ways. .P .B 1. Using files on the local filesystem .P -You can get the ratio of different images on the local filesystem. You can do this by supplying the name of the file in order to get the ratio of the image. +You can get the ratio of different images on the local filesystem. You can do this by supplying the name of the file as an \fIargument\fR in order to get the ratio of the image. .P $ uirc image1.png image1.png > 4:3 @@ -26,7 +26,7 @@ You may also run into images where their ratios don't factor down nicely. So, ui .P .B 2. Downloading images from a web server .P -You can also get the ratio of images present on a web server. By supplying the URL to an image file, uirc will download the image inside the /tmp folder of your system, evaluate it, then remove it. That isn't important though, you will just end up seeing the name of the file on the web server anyways. +You can also get the ratio of images present on a web server. By supplying the URL to an image file as an \fIargument\fR, uirc will download the image inside the /tmp folder of your system, evaluate it, then remove it. That isn't important though, you will just end up seeing the name of the file on the web server anyways. .P $ uirc https://brysonsteck.net/resurrection-sc.png downloading "https://brysonsteck.net/resurrection-sc.png"...ok @@ -38,7 +38,7 @@ You can also get the ratio of images present on a web server. By supplying the U .P .B 3. Multiple files and URLs .P -uirc can take multiple arguments of images at once and will evaluate them in order. You can do multiple local files, multiple URLs, or multiple of both. +uirc can take multiple \fIarguments\fR of images at once and will evaluate them in order. You can do multiple local files, multiple URLs, or multiple of both. .P $ uirc image1.png homework/yes-this-is-legitimately-homework/quadratic_formula.jpg /usr/share/imgs/popcorn.bmp image1.png > 4:3 @@ -57,8 +57,7 @@ uirc can take multiple arguments of images at once and will evaluate them in ord /usr/share/imgs/popcorn.bmp > 1.24:1 (uneven) .P .SH OPTIONS -.sp 1 -Informational: +.sp .TP 0.5i \fB\-h\fR, \fB\-\-help\fR Display a brief help message on the command line. @@ -69,7 +68,6 @@ Display the brief license disclaimer for uirc on the command line. You can also \fB\-v\fR, \fB\-\-version\fR Display the version of uirc on the command line. .P -Functional: .TP 0.5i \fB\-r\fR, \fB\-\-res\fR Display the resolution of the image(s) in addition to the ratio. @@ -78,9 +76,9 @@ Display the resolution of the image(s) in addition to the ratio. .B Bryson Steck ( GitHub: @brysonsteck ) .br -steck.bryson@gmail.com +brysonsteck@protonmail.com .br -.IR https://brysonsteck.net +.IR https://brysonsteck.xyz .P Please report any bugs/provide feedback for uirc by creating an issue on the GitHub repository: .IR https://github.com/brysonsteck/uirc @@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <curl/curl.h> #include <curl/easy.h> #include <unistd.h> +#include <stdbool.h> const char *VERSION = "0.1.0"; int rFlag = 1; @@ -58,6 +59,10 @@ int getBcf(int width, int height) { return bcf; } +bool compare_float(float a, float b) { + return fabs(a-b) < 0.0000001; +} + int readFile(char *file, int rFlag, int req, char* url) { int width, height, channels, factor; unsigned char *img = stbi_load(file, &width, &height, &channels, 0); @@ -97,6 +102,8 @@ int readFile(char *file, int rFlag, int req, char* url) { } } + // see if uneven values equal normal aspect ratios + if (factor == 1) { if (width < height) { printf("%s > 1:%.2f (uneven)", file, wuneven); @@ -125,6 +132,7 @@ int download(char *url) { CURLcode res; char outfilename[15] = "/tmp/uirc.tmp"; curl = curl_easy_init(); + long returnCode = 0; if (curl) { fp = fopen(outfilename,"wb"); @@ -132,17 +140,19 @@ int download(char *url) { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, returnCode); curl_easy_cleanup(curl); fclose(fp); } + printf("%ld\n", returnCode); return 0; } // end of stack overflow snippet int handleArg(char *arg) { - int value, complete; - char flag, *longFlag, *http, first, firstTwo[3], firstFour[5]; + int complete; + char flag, first, firstTwo[3], firstFour[5]; const char *help; help = "USAGE: uirc [OPTIONS] IMAGE1 [IMAGE2] [...]\n\n" @@ -212,7 +222,7 @@ int handleArg(char *arg) { int main(int argc, char *argv[]) { char *i, *a; - int runs; + int runs, code, arg_code; if (argc <= 1) { printf("uirc: at least one argument is required\n"); @@ -221,7 +231,9 @@ int main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { a = argv[i]; - handleArg(a); + arg_code = handleArg(a); + if (arg_code > code) + code = arg_code; runs++; } |