ptrlist: add ptrlist_sort()

The need to sort ptrlists is starting to show in several areas of the
code. It makes sense to implement a general sorting function
ptrlist_sort(), which is used in the same way as qsort_r().
map: use ptrlist_sort() for sorting system list

It makes more sense to use the recently implemented ptrlist_sort()
function instead of hving a separate implementation in map.

This also moves the system distance compare function to universe and
names it cmp_system_distances().
port: always initialize system pointer

As we have only implemented support for planet based ports so far,
initializing the system pointer in the port struct in port_genesis() was
missed. This is still useful, so let's do it.
common: add wrapper function for strtol()

As checking errors from strtol() requires a lot of boilerplate code, add
a wrapper function that converts strings to longs using strtol() with
proper error checking in common.
ptrlist: reset length in ptrlist_free()

When freeing a ptrlist, the length count was not reset. Fix this.
player: add list ports command

Enable players to list all ports within a certain radius. In the future,
we should probably think about implementing some kind of explored /
non-explored sectors, and take that into account, but lets not
complicate things just yet.
player: sort neighbouring systems before listing them

Use the new ptrlist_sort() function to present the list of neighbouring
systems sorted on distances. This makes the interface a bit nicer.
planet: name planets sorted mean distance from sun

So far, planets have been randomly named. As we now have a sorting
function for ptrlists, use that and fix this age-old problem.
ptrlist: return NULL in ptrlist_get() if outside of list

Previously, if ptrlist_get() was called with an index that was outside
the ptrlist, the function would return the last element in the list.

This is not particularly intuitive behaviour. Return NULL instead.
test: add ptrlist_test

Add tests for the functions in ptrlist.c.
ptrlist: cleanup includes

ptrlist included some unnecessary headers that were probably old
leftovers. Remove them, and update some other files that by mistake
depended on these includes in ptrlist.h.
ptrlist: replace qsort with proper linked list mergesort

Previously, ptrlists were sorted by memcopying them into an array and
calling qsort_r(). While this works and allowed us to use already
implemented and properly tested glibc functions, it uses a lot of extra
memory and the compare function will have a confusing declaration.

Replace ptrlist_sort() with a proper linked list mergesort. This
implementation is a bit slower on very large lists (probably due to
cache misses), taking about twice as long in tests to sort a list with
13 million entries on an i7, but the benefits of a much lower memory
footprint, less overhead on smaller lists and a more sane compare
function outweigh the drawbacks.