From 1eba88ca5e417b13c326a45e19f42ec843517e43 Mon Sep 17 00:00:00 2001 From: krustur Date: Mon, 3 Dec 2018 19:28:01 +0100 Subject: [PATCH] CleanExit --- IconSnap.code-workspace | 3 ++- src/main.c | 48 +++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/IconSnap.code-workspace b/IconSnap.code-workspace index 44f26d7..0fedc66 100644 --- a/IconSnap.code-workspace +++ b/IconSnap.code-workspace @@ -24,7 +24,8 @@ "exec_pragmas.h": "c", "dirent.h": "c", "unistd.h": "c", - "intuition.h": "c" + "intuition.h": "c", + "signal.h": "c" } } } \ No newline at end of file diff --git a/src/main.c b/src/main.c index f6137d7..1ccfc7b 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ #include #include #include +#include // TODO: Scripted tests! @@ -68,6 +69,10 @@ long argArray[] = 0, 0}; unsigned char argumentString[] = "FILE/K,DIR/K,PADLEFT/N,PADTOP/N,ALIGNX/N,ALIGNY/N,CENTERX/S,BOTTOMY/S,VERBOSE/S"; +struct RDArgs *rdargs = NULL; + +// clean exit handling +void CleanExit(); // Logging short verbose = FALSE; @@ -93,6 +98,17 @@ long Align(long orig, long pad, long align, long alignoffset); int main(int argc, char **argv) { + atexit(CleanExit); + + if (argc == 0) + { + //Opened from WB + } + else + { + // printf("fignal\n"); + // signal(SIGINT, intHandler); + } // Open libraries DosBase = OpenLibrary("dos.library", DosVersion); if (!DosBase) @@ -112,7 +128,7 @@ int main(int argc, char **argv) // check arguments - struct RDArgs *rdargs = ReadArgs(argumentString, argArray, NULL); + rdargs = ReadArgs(argumentString, argArray, NULL); if (!rdargs) { @@ -223,18 +239,30 @@ int main(int argc, char **argv) // return RETURN_ERROR; // } - if (rdargs) - { - FreeArgs(rdargs); - } - CloseLibrary(DosBase); - CloseLibrary(IconBase); - Verbose("Stack used: %lu\n", (unsigned long)__stack_usage); return RETURN_OK; } +void CleanExit() +{ + if (rdargs != NULL) + { + FreeArgs(rdargs); + rdargs = NULL; + } + if (DosBase != NULL) + { + CloseLibrary(DosBase); + DosBase = NULL; + } + if (IconBase != NULL) + { + CloseLibrary(IconBase); + IconBase = NULL; + } +} + // Logging void Verbose(const char *fmt, ...) { @@ -378,7 +406,7 @@ unsigned int AlignIcon(unsigned char *diskObjectName) if (iconLibraryV44Enabled) { Verbose("Icon found (>=V44): %s\n", fixedDiskObjectName); - diskObject = GetIconTags(fixedDiskObjectName, TAG_DONE);//ICONGETA_GetPaletteMappedIcon, FALSE, TAG_DONE); + diskObject = GetIconTags(fixedDiskObjectName, TAG_DONE); //ICONGETA_GetPaletteMappedIcon, FALSE, TAG_DONE); IconControl(diskObject, ICONCTRLA_GetWidth, &iconWidth, TAG_DONE); IconControl(diskObject, ICONCTRLA_GetHeight, &iconHeigth, TAG_DONE); } @@ -433,8 +461,6 @@ unsigned int AlignIcon(unsigned char *diskObjectName) // Verbose(" toolType IM1 not found :'(\n", toolType); // } - - // diskObject->do_CurrentX += 10; if (diskObject->do_CurrentX == NO_ICON_POSITION && diskObject->do_CurrentX == NO_ICON_POSITION) {