I added a new document on a lesser used feature of computers these days, command parsing. In Python I generally used both the shlex and cmd modules a lot to create interactive command-line tools which were also able to load external script files. I was originally going to port shlex over to Object Pascal, but I managed to find an easier method by using just two pascal functions. You can see the document and related example code here:
http://tech406.com/kdocs/parsing.xmlThe second document of the day is on
UNIX Signals:
http://tech406.com/kdocs/signals.xmlThe first part of the document explains why you would want to trap these signals if you plan on writing a UNIX service, and explains the various use-cases for the most common signal types.
I just updated the
UNIX Signals page with a fully working Pascal Unit called
UnixSignals, if you wish to use the most common signals within your program, and this means any program type, except a shared library. You can merely just check the included booleans within the Unit to see if a specific signal was sent to your program. You should of course place this into your programs idle/event loop and check for the signals there and act upon them as needed. This can enable either your GUI program or server process under UNIX-like systems to easily reload their configuration files from disk when the
SIGHUP is sent to your process for example by just checking the
HangUp boolean from the unit file. Be sure to set the boolean back to false after handing the signal so it won't constantly trigger. Enjoy!
Update to Pointers: Need to work with large binary data in Pascal in a very specific way, and
TMemoryStream just does not fulfill that requirement for you? I ended up making a new class, which is similar to TMemoryStream, but does not expand or shrink, it is set to a constant allocation size defined by the class. Why would you want to use such a class, you might be asking? If you are writing a strict emulator or virtual machine with a very specific heap size requirement, that's why! When writing the 6502 emulator I wrote, the CPU needs to see and have a constant 64k of memory, and the overhead of TMemoryStream constantly reallocating the pointer size just isn't ideal. This new class simulates the flat memory model required to write emulators and virtual machines with a static amount of memory. It has handy functions such as reading and writing both 8 and 16-bit integers from random address locations, the seek procedure is only used for the TStream compatible
LoadFromStream and
SaveToSteam procedures, other than that, your program is free to
PEEK and
POKE around at any memory location with ease.
http://tech406.com/kdocs/pointers.xml Then click on
Using flat memory in Pascal at the top. Enjoy!
June 10th update: I added a new page on
Checksums with examples on how to use the built-in
crc unit to generate and store a checksum for
CRC32,
CRC64, and
CRC128. I still do not know how to display the
u128 custom type as a GUID string, any ideas anybody? I checked the system unit documentation where the custom type is defined to see if there are any functions or procedures to work with
TGuid types, such as converting it to a GUID string, and back over to a u128, but I couldn't find anything. If you know, please let me know and I will update the document to reflect that knowledge. The really cool part about the custom u128 type is that it can be placed into a custom record, and easily written to disk. The hex dump of the created file appears to have the whole 128-bit Integer intact as expected.