Make cur_pos unsigned long in append()

Suppress a warning caused by comparing signed cur_pos to unsigned
main_header_size (warning only present on gcc 4.5 for some reason, not 4.9.1).
Merge working version of copy_ptw test

Merge the full version of copy_ptw into master, and all the commits which made
it possible.
Merge branch 'arith_ops'

Files all nicely separated out, mostly working too.