more adventures programming with AI
Jun. 25th, 2025 04:34 pmWell, that was different!
A couple of days ago, I almost completely wasted a couple of hours asking ChatGPT's help in understanding the format of the mouse cursor image files in Linux.
Today I started from scratch, writing a program myself to play with the files. I decided the easiest way to was read a cursor file into an array as a series of 32-bit values because it uses 32-bit numbers in the headers and the images are 4 byte pixels of RGBA values. Using something like 'hexdump' is easiest, and then fiddle with its ASCII in order to output it as, for example, a netpbm file. But I couldn't help thinking there might be a better way.
I asked Gemini this time, and it was very helpful. It agreed that 'hexdump' was a good way to do it, and gave me a command format that I didn't know 'hexdump' was capable of:
hexdump -v -e '4/1 "%02x " "\n"'
This gave me 4 space-separated hex bytes per line.
Gemini suggested converting those to a single 32-bit number by setting up a loop to read each byte and reverse the order, but I realised I could simply use 'awk' to read each line and convert it directly from little-endian to just a 32-bit hex number. For example if I want to read the 5th line:
awk 'NR==5 {print $4 $3 $2 $1; exit}'
Ta-da! :D
A little hesitantly, I asked Gemini what would be involved in writing a program in 'C' to list a file as 32-bit hex numbers (fixing the endianness). It explained the steps then wrote a surprisingly simple program, which compiled and ran perfectly.
However I think I'll stick to hexdump and awk and other already existing tools, because they let me fiddle with the process more. But this was an eyeopener. I really must improve my C skills. I'm a really crappy C programmer. There are so many things I want to do. I need a few more centuries.
A couple of days ago, I almost completely wasted a couple of hours asking ChatGPT's help in understanding the format of the mouse cursor image files in Linux.
Today I started from scratch, writing a program myself to play with the files. I decided the easiest way to was read a cursor file into an array as a series of 32-bit values because it uses 32-bit numbers in the headers and the images are 4 byte pixels of RGBA values. Using something like 'hexdump' is easiest, and then fiddle with its ASCII in order to output it as, for example, a netpbm file. But I couldn't help thinking there might be a better way.
I asked Gemini this time, and it was very helpful. It agreed that 'hexdump' was a good way to do it, and gave me a command format that I didn't know 'hexdump' was capable of:
hexdump -v -e '4/1 "%02x " "\n"'
This gave me 4 space-separated hex bytes per line.
Gemini suggested converting those to a single 32-bit number by setting up a loop to read each byte and reverse the order, but I realised I could simply use 'awk' to read each line and convert it directly from little-endian to just a 32-bit hex number. For example if I want to read the 5th line:
awk 'NR==5 {print $4 $3 $2 $1; exit}'
Ta-da! :D
A little hesitantly, I asked Gemini what would be involved in writing a program in 'C' to list a file as 32-bit hex numbers (fixing the endianness). It explained the steps then wrote a surprisingly simple program, which compiled and ran perfectly.
However I think I'll stick to hexdump and awk and other already existing tools, because they let me fiddle with the process more. But this was an eyeopener. I really must improve my C skills. I'm a really crappy C programmer. There are so many things I want to do. I need a few more centuries.