From ff039e5ee037db9b26c4e5964870a6dcb49bc490 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Mon, 10 May 2021 22:58:12 -0400 Subject: [PATCH] Implement some changes based on feedback from Kelvin: - Add the window position resource first. That way, if the style resource needs to grow, the window position resource will not need to be re-written. - Do not dispose of a handle passed to the resource manager through AddResource. The resource is owned by the resource manager after that. - No need to make the resource as changed when adding a resource. It is implied. Also, rename the disk image from Distribution to md2teach. --- md2teach/make/empty.2mg | Bin 819264 -> 819264 bytes md2teach/shell/io.c | 36 ++++++++++++++++++------------------ md2teach/shell/style.c | 7 +++++-- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/md2teach/make/empty.2mg b/md2teach/make/empty.2mg index 4b1474bda32c721052934ae6eb12edca353d1a85..0196ccbd49dec085e19b53833861da0ef8717210 100644 GIT binary patch delta 178 zcmX@mV056tXoCxj_YYqeqYzg|XAcG#Sfynq*6?0MOI(bV;jua|69XHA1Dmv)r=N>! zkY13#e+Wq7Np=QC22KVBkm7=U&%unz{VXc%AOR)@hRwTJ+Sr*G>L&;CY@eLK!#{b! zJo(KDY?6$N9fX*g9R%7P1Q>ys35c12m<5PgftU@5*@2h?h&h3n3y8UwI|%R;004#g BE1&=X delta 492 zcmZ9Ize@sP7{|Zfop+f(39%wfiUaGyE373NQoAz_Ma{d4wt}G5$uXs%f`*1$Bid>V zq#s6<5DhxiA0gG+*wE1PT7>k%=Xl}$-1qtNG^+7NHGZK9nJ>*St)h`ywv2oZ>>Mhw z(C34!^oN{iN4*?GBt#es`JCB#?|l3c8~}&Afq)BlZT8oMeI&@zp)wWXFjTu0_9V_R zZ!dYS?RAgeK0S%l*2S=+^7=2S{2MAO12ph4>SeK96lrU%psUG3A*(YZ)q_D)ClSAr z`#z3o;LdHNUjodm+8x*$frJA$wrkN~b)U4YOP`mtw2{;FqN*h;R+7av$Ed#o>K}BK z?%zB8L*!|?nX&Q(rm)i-#~kYu_X%!1w0XRZhS^jtZ%(Vzf0J9A;Bn5wTaWRyG$2?X zrXEP=w4%CV=&L_wYYYBa%nafA2I5PdJa!>3wY=E1TeQmPY~grZ22M$17s=jmKJ6v~ c`-y;q;0T@&2qz&D6467rh+e{dmI!!C-^dJURR910 diff --git a/md2teach/shell/io.c b/md2teach/shell/io.c index 97793c0..90c969f 100644 --- a/md2teach/shell/io.c +++ b/md2teach/shell/io.c @@ -177,13 +177,6 @@ static int writeResources(void) return 1; } - AddResource(styleHandle(), resChanged, rStyleBlock, STYLE_BLOCK_NUM); - if (toolerror()) { - fprintf(stderr, "%s: Unable to add style resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); - result = 1; - goto error; - } - windowPosHandle = NewHandle(sizeof(windowPos), userid(), attrNoPurge, NULL); if (toolerror()) { fprintf(stderr, "%s: Unable to allocate memory for window resource for file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); @@ -193,13 +186,19 @@ static int writeResources(void) HLock(windowPosHandle); PtrToHand((Pointer)windowPos, windowPosHandle, sizeof(windowPos)); - AddResource(windowPosHandle, resChanged, R_WINDOW_POSITION, WINDOW_POSITION_NUM); + AddResource(windowPosHandle, 0, R_WINDOW_POSITION, WINDOW_POSITION_NUM); if (toolerror()) { fprintf(stderr, "%s: Unable to add window position resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); result = 1; + DisposeHandle(windowPosHandle); + goto error; } - DisposeHandle(windowPosHandle); + AddResource(styleHandle(), 0, rStyleBlock, STYLE_BLOCK_NUM); + if (toolerror()) { + fprintf(stderr, "%s: Unable to add style resource to file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror()); + result = 1; + } error: CloseResourceFile(writeResId); @@ -241,13 +240,12 @@ static int writeRez(void) " hex string;\n" "};\n" "\n" -"resource rStyleBlock (%u) {\n" +"resource rWindowPosition (%u) {\n" " $\"", - rStyleBlock, R_WINDOW_POSITION, STYLE_BLOCK_NUM - ); + rStyleBlock, R_WINDOW_POSITION, WINDOW_POSITION_NUM); - ptr = stylePtr(); - size = styleSize(); + ptr = (uint8_t *)(&windowPos); + size = sizeof(windowPos); for (i = 0; i < size; i++) { if ((i > 0) && ((i % 32) == 0)) { @@ -260,12 +258,13 @@ static int writeRez(void) fprintf(rezFile, "\"\n" "};\n" "\n" -"resource rWindowPosition (%u) {\n" +"resource rStyleBlock (%u) {\n" " $\"", - WINDOW_POSITION_NUM); + STYLE_BLOCK_NUM + ); - ptr = (uint8_t *)(&windowPos); - size = sizeof(windowPos); + ptr = stylePtr(); + size = styleSize(); for (i = 0; i < size; i++) { if ((i > 0) && ((i % 32) == 0)) { @@ -274,6 +273,7 @@ static int writeRez(void) fprintf(rezFile, "%02x", (uint16_t)*ptr); ptr++; } + fprintf(rezFile, "\"\n" "};\n" "\n"); diff --git a/md2teach/shell/style.c b/md2teach/shell/style.c index 7559723..7b7932a 100644 --- a/md2teach/shell/style.c +++ b/md2teach/shell/style.c @@ -293,7 +293,9 @@ void closeStyle(void) Handle styleHandle(void) { - return formatHandle; + Handle result = formatHandle; + formatHandle = NULL; + return result; } uint8_t * stylePtr(void) @@ -309,5 +311,6 @@ uint32_t styleSize(void) void styleShutdown(void) { - DisposeHandle(formatHandle); + if (formatHandle != NULL) + DisposeHandle(formatHandle); }