fixed segfault with new function
This commit is contained in:
parent
96559b7870
commit
e9490940d0
3 changed files with 81 additions and 30 deletions
10
.gitignore
vendored
10
.gitignore
vendored
|
@ -1,5 +1,15 @@
|
||||||
|
# ide directories
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# binaries
|
||||||
uirc
|
uirc
|
||||||
|
d_uirc
|
||||||
|
|
||||||
|
# gcc output
|
||||||
*.o
|
*.o
|
||||||
|
|
||||||
|
# common image types
|
||||||
|
*.png
|
||||||
|
*.jpg
|
||||||
|
*.jpeg
|
||||||
|
*.bmp
|
||||||
|
|
7
Makefile
7
Makefile
|
@ -5,7 +5,12 @@ include config.mk
|
||||||
SRC = uirc.c
|
SRC = uirc.c
|
||||||
|
|
||||||
uirc: ${SRC}
|
uirc: ${SRC}
|
||||||
${CC} -DLICENSE_DIR='"./"' -o uirc -O ${SRC}
|
${CC} -o uirc -O ${SRC} -lm
|
||||||
|
|
||||||
|
debug: uirc
|
||||||
|
${CC} -g -o d_uirc -O ${SRC} -lm
|
||||||
|
gdb d_uirc
|
||||||
|
rm d_uirc
|
||||||
|
|
||||||
install: uirc
|
install: uirc
|
||||||
mkdir -p ${PREFIX}
|
mkdir -p ${PREFIX}
|
||||||
|
|
94
uirc.c
94
uirc.c
|
@ -32,11 +32,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stb/stb_image.h>
|
#include <stb/stb_image.h>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
const char *VERSION = "0.1.0";
|
const char *VERSION = "0.1.0";
|
||||||
|
|
||||||
|
@ -67,6 +71,8 @@ int handleArg(arg) char *arg; {
|
||||||
firstTwo[2] = '\0';
|
firstTwo[2] = '\0';
|
||||||
size = sizeof arg;
|
size = sizeof arg;
|
||||||
|
|
||||||
|
bool rFlag;
|
||||||
|
|
||||||
// determine if any arguments are flags
|
// determine if any arguments are flags
|
||||||
if (strcmp(longFlag, firstTwo) == 0) {
|
if (strcmp(longFlag, firstTwo) == 0) {
|
||||||
printf("ok");
|
printf("ok");
|
||||||
|
@ -76,49 +82,79 @@ int handleArg(arg) char *arg; {
|
||||||
switch (arg[i]) {
|
switch (arg[i]) {
|
||||||
case 'h':
|
case 'h':
|
||||||
printf("an unneccessary image ratio calculator (uirc) v%s\n\n", VERSION);
|
printf("an unneccessary image ratio calculator (uirc) v%s\n\n", VERSION);
|
||||||
printf("Copyright 2022 Bryson Steck\nLicensed under the BSD 2-Clause. You can read the license by running 'uirc -l'\n\n");
|
printf("Copyright 2022 Bryson Steck\n\n\n");
|
||||||
printf("%s\n", help);
|
printf("%s\n", help);
|
||||||
break;
|
exit(1);
|
||||||
case 'l':
|
case 'l':
|
||||||
readLicense();
|
//readLicense();
|
||||||
|
exit(1);
|
||||||
|
case 'r':
|
||||||
|
rFlag = true;
|
||||||
break;
|
break;
|
||||||
case '\0':
|
case '\0':
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
// if no more flags, run ratio calculations
|
// if no more flags, run ratio calculations
|
||||||
|
return readFile(arg, rFlag);
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int readFile() {
|
int readFile(file, showRes) char *file; bool showRes;{
|
||||||
|
int width, height, channels, biggestFactor;
|
||||||
}
|
unsigned char *img = stbi_load(file, &width, &height, &channels, 0);
|
||||||
|
if (img == NULL) {
|
||||||
void readLicense() {
|
printf("uirc: could not open file %s\n", file);
|
||||||
FILE *license;
|
exit(3);
|
||||||
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);
|
printf("Opened file \n");
|
||||||
return;
|
|
||||||
|
biggestFactor = getBiggestFactor(width, height);
|
||||||
|
stbi_image_free(img);
|
||||||
|
|
||||||
|
printf("Ratio of %s > %d:%d\n", file, width / biggestFactor, height / biggestFactor);
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(argc, argv) int argc; char *argv[]; {
|
int getBiggestFactor(int width, int height) {
|
||||||
|
int *widthFactors, *heightFactors;
|
||||||
|
int bcf;
|
||||||
|
for (int i = 1; i <= width; i++) {
|
||||||
|
for (int j = 1; j <= height; j++) {
|
||||||
|
if (width % i == 0) {
|
||||||
|
if (height % j == 0 && i == j) {
|
||||||
|
bcf = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bcf;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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. You can view it by visiting the GitHub repository for uirc:\nhttps://github.com/brysonsteck/uirc/blob/master/LICENSE\n");
|
||||||
|
// do {
|
||||||
|
// ch = fgetc(license);
|
||||||
|
// printf("%c", ch);
|
||||||
|
// } while (ch != EOF);
|
||||||
|
// }
|
||||||
|
// fclose(license);
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
//int i;
|
//int i;
|
||||||
char *i;
|
char *i;
|
||||||
|
|
||||||
|
@ -128,7 +164,7 @@ int main(argc, argv) int argc; char *argv[]; {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
char *a = argv[1];
|
char *a = argv[i];
|
||||||
int returned = handleArg(a);
|
int returned = handleArg(a);
|
||||||
if (returned != 0)
|
if (returned != 0)
|
||||||
return returned;
|
return returned;
|
||||||
|
|
Loading…
Add table
Reference in a new issue