AmendHub

Download:

jcs

/

wifi_da

/

amendments

/

40

*: Don't rely on our static wifi_da persisting

Lookup str_res_id again when creating main DA window.

jcs made amendment 40 about 1 month ago
--- main.c Tue Jan 7 15:00:05 2025 +++ main.c Tue Jan 7 21:04:24 2025 @@ -43,7 +43,6 @@ bool handle_menu(short i); void handle_event(EventRecord *e); void handle_timer(void); void logger_vprintf(const char *format, va_list ap); -void find_str_res_id(void); short main(cntrlParam *p, DCtlPtr d, short n) @@ -61,7 +60,6 @@ main(cntrlParam *p, DCtlPtr d, short n) if (dce == NULL) { util_init(d); SysEnvirons(1, &world); - find_str_res_id(); } dce = d; @@ -127,7 +125,7 @@ da_open(void) menu = GetMenu(menuID); (**menu).menuID = menuID; menu = GetMenu(menuID); - GetIndString(str, wifi_da.str_res_id, STR_ABOUT_WIFI_ID); + GetIndString(str, find_str_res_id(), STR_ABOUT_WIFI_ID); SetItem(menu, MAIN_MENU_ABOUT_ID, str); InsertMenu(menu, 0); DrawMenuBar(); @@ -286,7 +284,7 @@ logger_printf(const char *format, ...) void logger_vprintf(const char *format, va_list ap) { - static char buf[512]; + static char buf[256]; GrafPtr savePort; ssize_t len; RgnHandle clip; @@ -312,32 +310,35 @@ logger_vprintf(const char *format, va_list ap) SetPort(savePort); } -void +short find_str_res_id(void) { Handle itlb_h, str_h; - ItlbRecord *itlb; - bool found_str = false; + ItlbRecord itlb; + short str_res_id; /* find language of this system */ - wifi_da.str_res_id = OwnedResourceID(STR_BASE_ID); + str_res_id = OwnedResourceID(STR_BASE_ID); itlb_h = GetResource('itlb', 0); if (itlb_h != NULL) { HLock(itlb_h); - itlb = (ItlbRecord *)(*itlb_h); + itlb = *(ItlbRecord *)(*itlb_h); ReleaseResource(itlb_h); - str_h = GetResource('STR#', wifi_da.str_res_id + itlb->itlbLang); + str_h = GetResource('STR#', str_res_id + itlb.itlbLang); if (str_h != NULL) { - wifi_da.str_res_id += itlb->itlbLang; + /* we have strings in this language */ + str_res_id += itlb.itlbLang; ReleaseResource(str_h); - found_str = true; + return str_res_id; } } - if (!found_str) { - str_h = GetResource('STR#', wifi_da.str_res_id); - if (str_h == NULL) - panic("Can't find STR# %d", wifi_da.str_res_id); - ReleaseResource(str_h); - } + + /* fall back to english (itlbLang 0) */ + str_h = GetResource('STR#', str_res_id); + if (str_h == NULL) + panic("Can't find STR# %d", str_res_id); + ReleaseResource(str_h); + + return str_res_id; } \ No newline at end of file --- wi-fi.h Tue Jan 7 17:59:45 2025 +++ wi-fi.h Tue Jan 7 20:53:14 2025 @@ -133,6 +133,7 @@ extern Cursor watch; void wifi_about(void); +short find_str_res_id(void); void logger_printf(const char *format, ...); void create_window(short ctlrefnum); --- window.c Tue Jan 7 17:46:04 2025 +++ window.c Tue Jan 7 21:09:30 2025 @@ -33,6 +33,7 @@ create_window(short ctlrefnum) GrafPtr savePort, tport; memset(&wifi_menu_networks, 0, sizeof(wifi_menu_networks)); + wifi_da.str_res_id = find_str_res_id(); GetPort(&savePort);