Debian almquist shell on Mac OS X

I’ve recently changed the default shell /bin/sh on my Leopard install to dash from bash. Why would I do this? Well, by bash’s own admission (see BUGS in its manpage), bash is “too big and too slow”. dash is used for /bin/sh by default on Ubuntu nowadays, and it’s a goal for Debian (supposedly for Lenny, but I can’t see it noted in the release notes and it’s only “confirmed” in the Lenny goals). dash is significantly smaller and faster.

Ubuntu and Debian ran into plenty of bashisms when they tried to change, how about Mac OS X? So far I’ve found problems with /usr/libexec/path_helper (I just changed the shebang line to #!/bin/bash). There was also a problem with X11’s startx, and my patch was quickly committed.

Interestingly enough, when I went to move the sh binary, there are actually two versions of bash in /bin. Both report

GNU bash, version 3.2.17(1)-release (i386-apple-darwin9.0)

but differ at the binary level (they aren’t even the same size). I wonder if Apple tried to optimize their /bin/sh given that it gets more usage.

I built dash-0.5.5.1 from the tarball without a problem.

Firefox NS_ERROR_INVALID_POINTER with innerHTML

When trying to use prettify here on Defective Semantics I ran into problems with firefox. Here are the errors from the error console:

Error: undefined entity
Error: uncaught exception: [Exception...
 "Component returned failure code: 0x80004003 
 (NS_ERROR_INVALID_POINTER) [nsIDOMNSHTMLElement.innerHTML]"  
  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"
  location: "JS frame :: hxxp://example.net/prettify.js :: 
             replaceWithPrettyPrintedHtml :: line 1414"
  data: no]

My insistence on trying to use XHTML on the blog is partly to blame. Prettify tries to add “ ” entities to the source (even if it’s a pre element) to appease Internet Explorer. This entity only semi-works in XHTML: I’ve run into similar problems with some HTML entities not being loaded, because some browsers don’t load the DTD (which in turn loads the entity sets). It also appears that while Firefox claims to support HTML latin 1 entities in a document with a PUBLIC XHTML identifier, it doesn’t actually reparse innerHTML assignments according to those rules.

My solution is to add a conditional test for XML. Having a look at the Javascript document object there doesn’t seem to be a reliable way to detect whether the browser is treating the document as XML from javascript. My best attempt was:

document.xmlVersion && (document.compatMode=='CSS1Compat');

which works for Firefox and Opera.

As a separate issue, Chrome and Safari (and presumably anything WebKit based) don’t allow assignment of innerHTML for XML documents, giving NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7.
Fixing prettify to use only DOM methods instead of building up a string and assigning it to innerHTML could be a lot of work. At least this exception, unlike the Firefox error, doesn’t leave the pretty-printed block in an inconsistent state.

I submitted a patch to the prettify issue tracker.

Region-free Macbook Pro DVD drive

After receiving some regioned dvds for xmas, I decided it was about time to get them working on my Core 2 Duo Macbook Pro. It’s unusual to have a region-locked DVD player here in Australia; a recent Toshiba player I purchased came with instructions for entering an activation code via the remote, presumably slipped in by the Australian distributor. It’s slightly surprising that Apple Australia doesn’t do the same with the optical drives distributed in Apple hardware.

When I first got the MacBook Pro, the region was unset and although Apple’s “DVD Player” would complain, VLC would play regioned DVDs just fine. However, one day I decided to use DVD Player to play a regioned DVD from the video store, and after that the drive was region locked.

I found a good summary of the options for region-free macbook drives. I put the RPC-1 patched KCVB onto my UJ-857D superdrive using the SimpleFlash utility. ben11’s patched version of Apple’s “Superdrive Firmware Update” errored with

LSOpenFromURLSpec() failed with error -10810

The hacks for getting the patched Updater to work on Mac OS X Leopard didn’t work, so SimpleFlash seemed like a good (if slightly scarier) option.

It worked a treat. Now I can play regioned DVDs in VLC again. Apparently I can also use DVD Player after faking a region using xvi’s Region X.