4 ms·
I think a lot of C programmers would find reading the source to the V6 ed interesting: http://www.tuhs.org/Archive/PDP-11/Trees/V6/usr/source/s1/ed.c 1333 l
by bodyfour 14y ago
I think a lot of C programmers would find reading the source to the V6 ed interesting:
http://www.tuhs.org/Archive/PDP-11/Trees/V6/usr/source/s1/ed.c
1333 lines of C, basically no library use at all (no printf, not even malloc -- the only thing dynamically allocated is the document, and it uses sbrk() to manage the memory itself), compiles down to about 6K on a PDP-11. And that includes a regex engine!
It contains a lot of 1970 C-isms that won't work today ("=+" instead of "+=" for example) but an experienced C programmer shouldn't have a hard time following it.
As a bonus, look at the commented-out getpid() implementation at the bottom of the file.
- dalke 14y agoI remember doing a=+1 in K&R days under IRIX and getting a warning that "=+" was deprecated. I had just started with Unix then, and had to get someone else to explain the source of that message. How does the "goto errlab" work? It looks like it calls errfunc() then gets to the reset(), which doesn't return. Does setexit() determine the entry point for a reset? This really is a bare bones system. An insert at the start shifts every character to the right by one, and memory growth is only 1024 bytes at a time. This leads to quadratic times. I wonder if that performance was noticeable on the PDP-11 when editing a large-for-the-time file.
- bodyfour 14y agoYes, setexit() and reset() were the precursors to setjmp()/longjmp(): http://man.cat-v.org/unix-6th/3/reset http://man.cat-v.org/unix-6th/3/reset
- ralph 14y agoIt probably also has vestiges of the assembler version in its structure and symbols. troff(1) certainly has; I had trouble groking one particular function's logic and asked Kernighan. He kindly replied and said that one had always troubled him too and was just a transliteration from Ossanna's assembler. Glad it wasn't just me. :-)