I saw something pretty funny tonight. Macabre, but funny. A road sign in a cemetery: “Not a through street.”
Go ahead and think about it; I’ll wait.
Newer versions of Palm’s SDK recommend an XML-based resource description format (XRD). This is good news, because it makes it easy to write tools to help work around some of the problems associated with PalmOS resources.
A problem I recently faced was creating multiple instances of a form based on a single resource. Each instance had a different C++ class in which its code was contained, but the control layout was identical and should stay so through maintenance changes, so I didn’t want to make three different copies of the resource and have to maintain all three. However, the Palm Forms API is designed to only load one instance of a form with a given ID at a time, and each resource has exactly one ID.
The solution I hit upon was to create an XSLT stylesheet that knows how to pass most elements through, duplicating a few of them. A separate XML control file specifies which elements to duplicate and what their IDs should be. The output is written to a temporary file, and that temporary file is fed to palmrc instead of the original. Now I can pick a few forms that I need to load multiple instances of and duplicate them as many times as necessary.
Here’s what the control file looks like.
<?xml version="1.0" encoding="utf-8"?>
A control file for use with ResourceDup.xslt. Specifies and controls
compile-time resource duplications, allowing a single resource maintained
in an XRD file to become multiple resources in a compiled PRC.
<!-- Main List Forms -->
<!-- List1 = 1600 -->
<dup id="1600" new-id="1601" /> <!-- List2 -->
<dup id="1600" new-id="1602" /> <!-- List3 -->
<!-- Main Edit Forms -->
<!-- List1 = 1700 -->
<dup id="1700" new-id="1701" /> <!-- List2 -->
<dup id="1700" new-id="1702" /> <!-- List3 -->
I also just ran across this: http://www.llamagraphics.com/developer/xrd2header.html. I haven’t used it yet, but I am likely to. It allows you to generate a header file containing symbolic names for your resources, rather than referring to them by number in code or maintaining your own mapping in a header file. That tool is probably a temporary solution, though: tools existed for the older resource formats that could generate header files, and I think it’s likely that the lack of any such tool for XRD files in the SDK is just an oversight that Palm will likely fix sometime.
Finally, I can verify that it is possible to use the new Windows-only Palm development tools on Linux, to some extent, using
wine. Palmrc works perfectly, but I haven’t been able to get pacc to work; it shows its logo banner, but then silently exits with no error messages. The utility of pacc on Linux is of dubious value right now anyway, since so much of the rest of the development suite is Windows-only (Palm! We want our Linux tools!) But getting palmrc and prcmerge to work means that I can use the newer XRD resource files without being stuck on Cygwin. I put the following in my current project’s Makefile to make this work.
UNAME :=$(shell uname)
# Linux Settings
PRCMERGE :=wine -- ~/prc-bin/PalmOSTools/PRCMerge.exe
PALMRC :=wine -- ~/prc-bin/PalmOSTools/PalmRc.exe
# Cygwin Settings
I hacked together a quickie perl script today that searches a set of files given by a shell wildcard for a set of strings and writes the lines to standard output. In addition to the wildcard, you can pass it -r to cause it to process subdirectories. It’s basically grep -r, but with a few differences:
- It uses a dictionary of phrases so you don’t have to pass them on the command line (you’ll see why in a moment).
- It colorizes its output depending on the phrase.
- If given no wildcard argument, it defaults to all files in the current directory.
My dictionary includes phrases that I often put into files to indicate that I need to come back and do something else, such as TODO:, HACK: and ENHANCE:. The intent of the program is that I can enter a directory containing source code, type “todo”, and be given a list of lines things to do in that directory based on the phrases I’d left in my files earlier.
$ cd myproj && todo
NotesForm.cpp:11: TODO: There are several menu commands that the note form may send that we’re
NotesForm.cpp:23: TODO: This should really be two MAP_CTLREPEAT_EVENT()s, but I don’t
NotesForm.cpp:46: TODO:I think there’s a frmDrawEvent or something that we should be
Util.cpp:10: TODO:This always sorts. It actually should get the table’s sort-info
Util.cpp:11: ENHANCE:To support descending sorts, we’d just flip res from 1 to
Output is written in the same format as GCC, so this theoretically could be driven by vi or Emacs to jump directly to a line containing a phrase. I don’t use that much (I tend to make from the command line but edit in Visual Studio), so I haven’t tested that.
If you’re thinking that this looks a lot like the automatically generated Task List included in modern versions of Microsoft Visual Studio, you’d be right — but this is better.