AmendHub

Download:

vkoskiv

/

MacNTP

/

amendments

/

19

Display MacNTP errors in cdev

It now shows what went wrong at INIT time if it displayed the X
icon during boot. Error gets cleared when a successful run happens.
If no error, the space is just blank.
Also fixed HideDItem call IDs in closeDev, they were outdated.

vkoskiv made amendment 19 6 months ago
--- cdev.c Wed Sep 20 23:40:00 2023 +++ cdev.c Thu Sep 21 00:40:28 2023 @@ -30,6 +30,8 @@ #define ntp1_box_id 1 #define ntp2_box_id 2 #define utc_box_id 3 +#define err_title_id 9 +#define err_box_id 10 #define apply_btn_id 4 struct control { @@ -42,10 +44,13 @@ struct state { StringHandle ntp1; StringHandle ntp2; StringHandle utc; + StringHandle err; DialogPtr dialog; struct control ntp1_textbox; struct control ntp2_textbox; struct control utc_textbox; + struct control err_textbox; + struct control err_title; }; // Prototypes @@ -103,8 +108,9 @@ void *got_initDev(void *storage, DialogPtr dialog, sho s->ntp1 = GetString(NTP1_STR_ID); s->ntp2 = GetString(NTP2_STR_ID); s->utc = GetString(UTC_STR_ID); + s->err = GetString(ERR_STR_ID); s->dialog = dialog; - if (!s->ntp1 || !s->ntp2 || !s->utc) { + if (!s->ntp1 || !s->ntp2 || !s->utc || !s->err) { SysBeep(1); SysBeep(1); SysBeep(1); @@ -112,9 +118,11 @@ void *got_initDev(void *storage, DialogPtr dialog, sho SetHandleSize(s->ntp1, 256); SetHandleSize(s->ntp2, 256); SetHandleSize(s->utc, 256); + SetHandleSize(s->err, 256); HLock(s->ntp1); HLock(s->ntp2); HLock(s->utc); + HLock(s->err); // Grab our textboxes. The number is the one in our DITL // but the dialog manager wants the full range num, so add nitems GetDItem(s->dialog, @@ -148,6 +156,29 @@ void *got_initDev(void *storage, DialogPtr dialog, sho ShowDItem(s->dialog, utc_box_id); InvalRect(&s->utc_textbox.rect); + GetDItem(s->dialog, + err_box_id + nitems, + &s->err_textbox.type, + &s->err_textbox.handle, + &s->err_textbox.rect); + HLock(s->err_textbox.handle); + + GetDItem(s->dialog, + err_title_id + nitems, + &s->err_title.type, + &s->err_title.handle, + &s->err_title.rect); + HLock(s->err_title.handle); + + if (*s->err[0]) { + SetIText(s->err_textbox.handle, *s->err); + ShowDItem(s->dialog, err_box_id); + InvalRect(&s->err_textbox.rect); + } else { + HideDItem(s->dialog, err_box_id + nitems); + HideDItem(s->dialog, err_title_id + nitems); + } + return storage; } @@ -263,12 +294,13 @@ void *got_hitDev(void *storage, short item) { } void *got_closeDev(void *storage, short item) { struct state *s = *(struct state **)storage; - HideDItem(s->dialog, 3); - HideDItem(s->dialog, 5); - HideDItem(s->dialog, 7); + HideDItem(s->dialog, ntp1_box_id); + HideDItem(s->dialog, ntp2_box_id); + HideDItem(s->dialog, utc_box_id); DisposHandle(s->ntp1); DisposHandle(s->ntp2); DisposHandle(s->utc); + DisposHandle(s->err); DisposHandle(storage); return storage; } --- MacNTP.π.r Wed Sep 20 23:54:29 2023 +++ MacNTP.π.r Thu Sep 21 01:01:12 2023 @@ -10,6 +10,10 @@ data 'STR ' (-4047, "NTP2", sysheap) { $"0E74 696D 652E 6170 706C 652E 636F 6D" /* .time.apple.com */ }; +data 'STR ' (-4045, "ERROR", sysheap) { + $"00" /* . */ +}; + data 'ICN#' (128, "NTPPENDING", sysheap) { $"FFFF FFFF 8080 0001 8080 7C01 8881 8301" /* ....ÄÄ..ÄÄ|.àÅÉ. */ $"9482 0081 9484 0041 9484 8041 9488 4421" /* îÇ.ÅîÑ.AîÑÄAîàD! */ @@ -110,7 +114,7 @@ data 'nrct' (-4064) { }; data 'DITL' (-4064) { - $"0007 0000 0000 003B 0070 004A 0129 1000" /* .......;.p.J.).. */ + $"0009 0000 0000 003B 0070 004A 0129 1000" /* .∆.....;.p.J.).. */ $"0000 0000 0067 0070 0076 0129 1000 0000" /* .....g.p.v.).... */ $"0000 0095 0071 00A4 00C9 1000 0000 0000" /* ...ï.q.§.…...... */ $"0093 00D5 00A7 012D 0405 4170 706C 7922" /* .ì.’.ß.-..Apply" */ @@ -119,7 +123,10 @@ data 'DITL' (-4064) { $"6F6E 0000 0000 0027 0071 0037 00D9 880B" /* on.....'.q.7..à. */ $"5072 696D 6172 7920 4E54 5071 0000 0000" /* Primary NTPq.... */ $"0054 0071 0064 00D9 880C 4661 6C6C 6261" /* .T.q.d..à.Fallba */ - $"636B 204E 5450 0000 0000 0081 0071 0091" /* ck NTP.....Å.q.ë */ - $"00B6 880A 5554 4320 4F66 6673 6574" /* .∂à.UTC Offset */ + $"636B 204E 5450 0000 0000 0081 0070 0091" /* ck NTP.....Å.p.ë */ + $"00B5 880A 5554 4320 4F66 6673 6574 0000" /* .µà.UTC Offset.. */ + $"0000 00AF 0070 00BF 00BB 880B 4C61 7374" /* ...Ø.p.ø.ªà.Last */ + $"2045 7272 6F72 3A00 0000 0000 00C7 006E" /* Error:......«.n */ + $"00D7 012D 8808 4E6F 2045 7272 6F72" /* .◊.-à.No Error */ }; --- main.c Mon Sep 18 23:36:26 2023 +++ main.c Fri Jan 1 00:09:00 1904 @@ -16,8 +16,6 @@ /* TODO: -- Remove dump_error and save an error to rsrc STR instead -- Implement cdev - Display possible errors in cdev */ @@ -42,57 +40,67 @@ int utcstr_to_mins(Str255 utc, long *out); Handle g_mtcp_init_handle; -#ifdef DEBUGGING void dump_error(enum MacNTPError error, OSErr oserror) { Str255 numstr; + StringHandle err_str; + err_str = GetString(ERR_STR_ID); + if (!err_str) { + SysBeep(10); + SysBeep(1); + return; + } + SetHandleSize(err_str, 256); + HLock(err_str); NumToString(oserror, numstr); switch (error) { case Success: - DebugStr("\pSuccess"); + SetString(err_str, "\p"); //FIXME: Bit dumb to write this every time? break; case MacTCPInitFailed: - DebugStr(numstr); + SetString(err_str, "\pMacTCP init failed"); break; case InvalidURL: - DebugStr("\pInvalidURL"); + SetString(err_str, "\pInvalid URL"); break; case BadNtpStructSize: - DebugStr("\pBadNtpStructSize"); + SetString(err_str, "\pBad NTP struct size"); break; case UDPCreateFailed: - DebugStr("\pUDPCreateFailed"); + SetString(err_str, "\pUDPCreate failed"); break; case UDPSendFailed: - DebugStr("\pUDPSendFailed"); + SetString(err_str, "\pUDPSend failed"); break; case UDPRcvFailed: - DebugStr("\pUDPRcvFailed"); + SetString(err_str, "\pUDPRcv failed"); break; case InvalidNTPResponse: - DebugStr("\pInvalidNTPResponse"); + SetString(err_str, "\pInvalid NTP response"); break; case OriginTimestampMismatch: - DebugStr("\pOriginTimestampMismatch"); + SetString(err_str, "\pOrigin timestamp mismatch"); break; case DNSResolveFailed: - DebugStr("\pDNSResolveFailed"); - DebugStr(numstr); + SetString(err_str, "\pDNS resolve failed"); break; case ClockWriteFailed: - DebugStr("\pClockWriteFailed"); + SetString(err_str, "\pClock write failed"); break; case ClockReadFailed: - DebugStr("\pClockReadFailed"); + SetString(err_str, "\pClock read failed"); break; case UDPRcvTimedOut: - DebugStr("\pUDPRcvTimedOut"); + SetString(err_str, "\pUDPRcv timed out"); break; case PacketParamNull: - DebugStr("\pPacketParamNull"); + SetString(err_str, "\pPacket param null"); break; } + HUnlock(err_str); + ChangedResource(err_str); + ReleaseResource(err_str); + UpdateResFile(CurResFile()); } -#endif //FIXME: This is duplicated from cdev.c, but I didn't want to //make a library and all the extra build steps just for this. @@ -149,20 +157,12 @@ int TryMacNTP(Str255 ntp1, Str255 ntp2, Str255 utc) { PtoCstr(ntp2); error = MacNTPFetchTime((char *)(ntp2), &payload, &oserr, utc_offset); } - if (error) { -#ifdef DEBUGGING - dump_error(error, oserr); -#endif - return 1; - } + dump_error(error, oserr); + if (error) return 1; error = MacNTPSetSystemTime(&payload, utc_offset); - if (error) { -#ifdef DEBUGGING - dump_error(error, oserr); -#endif - return 1; - } + dump_error(error, oserr); + if (error) return 1; return 0; } @@ -242,13 +242,13 @@ void main() { // I have no idea if unlock is needed here. Maybe not. HUnlock(ntp1); - DisposHandle(ntp1); + //DisposHandle(ntp1); HUnlock(ntp2); // For whatever reason, System 6 crashes on boot if we // try to dispose this specific handle. Okay. //DisposHandle(ntp2); HUnlock(utc); - DisposHandle(utc); + //DisposHandle(utc); HUnlock(g_mtcp_init_handle); skip: error: --- rsrcid.h Thu Sep 14 00:29:06 2023 +++ rsrcid.h Thu Sep 21 00:13:45 2023 @@ -5,6 +5,7 @@ #define NTP1_STR_ID -4048 #define NTP2_STR_ID -4047 #define UTC_STR_ID -4046 +#define ERR_STR_ID -4045 #define MACNTP_ICN_ID_PENDING 128 #define MACNTP_ICN_ID_SUCCESS -4064 // Also used for cdev