From 1f83e0d0b618f94ed743c1e0f339550d5a47dad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Sun, 12 May 2024 19:45:27 +0200 Subject: [PATCH] Fixed segfault and edited help message --- main.c | 37 +++++++++++++++---------------------- my_utils.c | 2 +- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/main.c b/main.c index 82e567a..9811dd6 100644 --- a/main.c +++ b/main.c @@ -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 @@ -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"); @@ -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; @@ -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; @@ -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"); @@ -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 diff --git a/my_utils.c b/my_utils.c index 641403b..c866cd3 100644 --- a/my_utils.c +++ b/my_utils.c @@ -117,7 +117,7 @@ void printHelp() { " "COLOR_BOLD "-c" COLOR_OFF " or "COLOR_BOLD "--count" COLOR_OFF " \n" "\n" " "COLOR_BOLD "-f" COLOR_OFF " or "COLOR_BOLD "--format" COLOR_OFF " \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"