AmendHub

jcs

/

wikipedia

/

amendments

/

30

util: Move about-box code into an about() function


jcs made amendment 30 4 months ago
--- main.c Tue Sep 6 18:54:34 2022 +++ main.c Tue Sep 6 19:08:52 2022 @@ -178,36 +178,9 @@ handle_menu(long menu_id) switch (menu) { case APPLE_MENU_ID: switch (item) { - case APPLE_MENU_ABOUT_ID: { - VersRecHndl vers; - char vers_s[255]; - char short_vers[255] = { 0 }; - short vlen, n; - - if ((vers = (VersRecHndl)GetResource('vers', 1))) { - /* - * vers "long version string" is a pascal string after the - * short version pascal string - */ - HLock(vers); - vlen = (*vers)->shortVersion[0]; - memcpy(short_vers, (*vers)->shortVersion + vlen + 1, - sizeof((*vers)->shortVersion) - vlen - 1); - PtoCstr(short_vers); - snprintf(vers_s, sizeof(vers_s), "%s %s", PROGRAM_NAME, - short_vers); - for (n = 0; n < sizeof(vers_s); n++) { - if (vers_s[n] == '©') { - vers_s[n - 1] = '\r'; - break; - } - } - ReleaseResource(vers); - appicon_note("%s", vers_s); - } else - warnx("Can't find version number!"); + case APPLE_MENU_ABOUT_ID: + about(PROGRAM_NAME); break; - } default: { Str255 da; GrafPtr save_port; --- util.c Tue Sep 6 18:57:47 2022 +++ util.c Tue Sep 6 19:08:22 2022 @@ -605,6 +605,38 @@ ask(const char *format, ...) } void +about(char *program_name) +{ + VersRecHndl vers; + char vers_s[255]; + char short_vers[255] = { 0 }; + short vlen, n; + + if ((vers = (VersRecHndl)GetResource('vers', 1))) { + /* + * vers "long version string" is a pascal string after the + * short version pascal string + */ + HLock(vers); + vlen = (*vers)->shortVersion[0]; + memcpy(short_vers, (*vers)->shortVersion + vlen + 1, + sizeof((*vers)->shortVersion) - vlen - 1); + PtoCstr(short_vers); + snprintf(vers_s, sizeof(vers_s), "%s %s", program_name, + short_vers); + for (n = 0; n < sizeof(vers_s); n++) { + if (vers_s[n] == '©') { + vers_s[n - 1] = '\r'; + break; + } + } + ReleaseResource(vers); + appicon_note("%s", vers_s); + } else + warnx("Can't find version number!"); +} + +void progress(char *format, ...) { static Str255 progress_s; --- util.h Tue Sep 6 18:50:37 2022 +++ util.h Tue Sep 6 19:08:45 2022 @@ -116,6 +116,7 @@ void appicon_note(const char *format, ...); short ask(const char *format, ...); #define ASK_YES 1 #define ASK_NO 2 +void about(char *program_name); void progress(char *format, ...); void window_rect(WindowPtr win, Rect *ret); void center_in_screen(short width, short height, bool titlebar, Rect *b);