Porting Notes - wrelam/typo GitHub Wiki

First compilation and run

A quick browse through the initial source shows a lot of pre standardized C conventions. Creating a Makefile (BSD flavor) to ease the process only confirmed this through the variety of errors that were produced.

Many were expected, such as leaving out int wherever it would normally be placed, as this was the default type when not specified. The use of the =- and =+ operators I've never seen before either (swapping the characters resolved those errors). The use of signal(2) was pretty much the same, but needed to use the macro SIG_INT rather than 1 which was the old func/label to indicate an ignored signal. There was a missing close bracket on the use of usort, but copying the pattern used for sort was an easy fix. Otherwise, creating function declarations above main and including a few extra headers and libraries were all that was needed to get it to compile.

Upon running it for the first time, it seg faulted. A quick run through gdb showed an out-of-bounds access when creating one of the various tables being used. This could be due to the sizes of types changing between then and now, but I needed to know what architecture UNIX v4 or v5 ran on.

Matching type sizes

The Evolution of the UNIX Time-Sharing System notes that Bell-Labs received a PDP-11 around 1971 and in 1973 the entire UNIX kernel was ported to C on the PDP-11. Since the manual for UNIX v5 is dated 1974, my guess is that the original version of typo was written for the PDP-11.

Looking at the PDP-11 Instruction Set was somewhat helpful, but what I really needed was an ABI. That doesn't exist as far as I know.

Table 5-2 from this PDP-11 C Guide to Programming listed the following types and sizes:

  • 32-bit: long, long int, signed int, signed long int, unsigned long, unsigned long int
  • 16-bit: int, short, short int, signed, signed int, signed short, signed short int, unsigned, unsigned short, unsighed short int
  • 8-bit: char, signed char, unsigned char

Based on this, converting certain ints and all shorts to int16_t should resolve any issues due to type size mismatches on current architectures.