Skip to content

Commit

Permalink
Fixed segfault and edited help message
Browse files Browse the repository at this point in the history
  • Loading branch information
SzBenedek2006 committed May 12, 2024
1 parent 5de1c7d commit 1f83e0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
37 changes: 15 additions & 22 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ int main(int argc, char* argv[])

*pStartTime = (double)ts.tv_sec + (double)ts.tv_nsec / 1.0e9;



printf("Welcome to RIG\n");

// Declaring vars
Expand Down Expand Up @@ -69,8 +71,8 @@ int main(int argc, char* argv[])
if (strcmp(argv[n], "-s") == 0 || strcmp(argv[n], "--size") == 0) { // -s,
sCount++;
if (argv[n + 1] != NULL && argv[n + 1] != NULL) {
height = atoi(argv[n + 2]);
width = atoi(argv[n + 1]);
height = atoi(argv[n + 2]);
n += 2;
} else {
printf("size is not set\n");
Expand All @@ -83,6 +85,7 @@ int main(int argc, char* argv[])
if (argv[n + 1] != NULL) {
count = atoi(argv[n + 1]);
cCount++;
n++;
} else {
printf("count is not set\n");
return 3;
Expand All @@ -101,10 +104,10 @@ int main(int argc, char* argv[])
if ((argv[n + 1]) != NULL) {
if (strcmp(argv[n + 1], "png") == 0) { // Segfaults here
strcpy(format, "png");
printDebugPlusStr("format: ", format);
} else if (strcmp(argv[n + 1], "jpg") == 0) {
n++;
} else if (strcmp(argv[n + 1], "jpeg") == 0 || strcmp(argv[n + 1], "jpg") == 0) {
strcpy(format, "jpg");
printDebugPlusStr("format: ", format);
n++;
} else {
printf("RIG currently only supports png (default) and jpg as a format option");
return 3;
Expand All @@ -117,16 +120,23 @@ int main(int argc, char* argv[])
} else {
printf("format is not set, defaulting to png\n");
strcpy(format, "png");
printDebugPlusStr("format (defaulted to): ", format);
}

}


// Depends on allowDebugInfo == true
errorFileOpener();


// All printDebug depends on errorFileOpener
printDebugPlusInt("sCount = ", sCount);
printDebugPlusInt("aCount = ", aCount);
printDebugPlusInt("cCount = ", cCount);
printDebugPlusInt("hCount = ", hCount);
printDebugPlusInt("tCount = ", tCount);
printDebugPlusInt("dCount = ", dCount);
printDebugPlusInt("fCount = ", fCount);

if (argc == 1) {
printf("Use -h to print help message.\n");
Expand Down Expand Up @@ -187,23 +197,6 @@ int main(int argc, char* argv[])
char fileExtension[5];


/*
// Replace this with user input
const int format = 2; //jpg
switch (format) {
case 1:
strcpy(fileExtension, "png");
break;
case 2:
strcpy(fileExtension, "jpeg");
break;
}
*/




// Start of the image loop
Expand Down
2 changes: 1 addition & 1 deletion my_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void printHelp() {
" "COLOR_BOLD "-c" COLOR_OFF " or "COLOR_BOLD "--count" COLOR_OFF " <number>\n"
"\n"
" "COLOR_BOLD "-f" COLOR_OFF " or "COLOR_BOLD "--format" COLOR_OFF " <image format>\n"
" It supports \"png\" or \"jpeg\". When not used, defaults to png.\n"
" It supports png or jpg (jpeg) formats. When not used, defaults to png.\n"
"\n"
" "COLOR_BOLD "-a" COLOR_OFF " or "COLOR_BOLD "--alpha" COLOR_OFF "\n"
" Use transparent pixels in png. With jpeg, this will be ignored.\n"
Expand Down

0 comments on commit 1f83e0d

Please sign in to comment.