https://gitlab.winehq.org/wine/wine/-/tree/master/programs/notepad is WINE's notepad
It would have been too easy if it had compiled in one go, but here's where I run into a problem:
I don't actually code C and I have no idea what the fuck I'm doing.
There's an annoying "✨Fix" button now when I right click, but I can just pester the Fediverse instead of paying for an LLM and compromising my integrity.
git grep "define ARRAY_SIZE" got me to tools/tools.h:#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) in the Wine source code, so like any good coder we're going to blindly copy and paste this while having no idea what the fuck that means.
It got worse. I'm not sure if I am more afraid of C errors or resource file errors. I have never understood resource files.
Commented out the accelerators for now (bookmarking https://learn.microsoft.com/en-us/windows/win32/menurc/about-resource-files for later)
Got to my least favourite errors ever: unresolved external symbol. Thankfully I am marginally smarter than I was 10-15 years ago.
I know what WINE's Makefile uses and I can add those same references in.
OK, #AskFedi is wdm.h in the Windows SDK or DDK?
WINE's notepad is using RtlUshortByteSwap and I am too impatient to keep following the documentation at https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/
I think I will just yoink WINE's implementation.
git grep "static.*RtlUshortByteSwap("
dlls/wineps.drv/type1.c:static inline WORD get_be_word(const void *p) { return RtlUshortByteSwap(*(const WORD*)p); }
include/winternl.h:static inline USHORT RtlUshortByteSwap(USHORT s)
(I don't know how to do the code formatting I see around the Fediverse)
That's all this is?
/* These are implemented as __fastcall, so we can't let Winelib apps link with them.
* Moreover, they're always inlined and not exported on 64bit systems.
*/
static inline USHORT RtlUshortByteSwap(USHORT s)
{
return (s >> 8) | (s << 8);
}
It's a standard trick to get the number of elements in an array:
sizeof(x) returns the allocated memory for the whole of the array. If your array has 10 elements and an element is a 32-bit int, then it returns 10 (elements) times 4 (bytes in a 32-bit int) = 40
sizeof(x[0]) dereferences the array to get the size of the first element. So in the same example, you get back 4.
Dividing 40 by 4 yields 10, the number of elements
This only works for arrays allocated on the stack, not for a pointer to a 40-byte region, as for that sizeof(x) returns the size of the pointer, which is a constant that has nothing to do with the size of your array.
I'm sure you didn't need to know any of that, but now you do 😂
- replies
- 0
- announces
- 0
- likes
- 0