Handle out-of-order charset descriptors

The ZOC emulator returns the primary character set descriptor after the
alternate descriptor. Need to pick the right one based on searching for ID 0.
This commit is contained in:
Matthew R. Wilson committed 2025-11-27 00:27:40 -08:00
1 parent 7b7d375e91
commit ab58ba7a87
1 file changed
+22 -9
+22 -9
View File
@@ -480,17 +480,30 @@ func getCodepageID(buf []byte) int {
return 0
}
// Descriptor length -- and do we have at least one descriptor?
// Descriptor length
dl := int(buf[10])
if len(buf) < 11+dl {
return 0
// There may be more than one descriptors, and we need to find the first
// one with local ID 0.
pos := 11 // first descriptor
for {
if len(buf) < pos+dl {
// No more descriptors and we haven't found anything yet
return 0
}
if buf[pos] != 0 {
// not the descriptor we're looking for, try the next one
pos += dl
continue
}
// This is the first descriptor we've seen with ID 0, we'll use it.
// No matter how long the descriptor is, the code page will 2-byte big
// endian integer in the last two bytes.
cpid := int(buf[pos+dl-2])<<8 + int(buf[pos+dl-1])
return cpid
}
// No matter how long the descriptor is, the code page will 2-byte big
// endian integer in the last two bytes.
cpid := int(buf[11+dl-2])<<8 + int(buf[11+dl-1])
return cpid
}
// getRPGNames checks the "Query Reply (RPQ NAMES)" response to see if the