Major updates/fixes to the distfile handling code
=================================================
* Make all parts of the code SUBDIR-safe (most were already)
  - This involves using $port_subdir globally to refer to just the
    directory name under DISTDIR, and add a $full_port_subdir to contain
    the full path to the file for the places where that was used.
    This also allows simplifying a few places where both were needed.
  - Fix a few places where the relativity of the cwd was not respected,
    most often resulting in files not being deleted that should be
* When checking DI_FILES, anchor the grep pattern with a ^ to
  avoid false positives
* Move the storage of the distfile info back to /var/db/pkg where it
  should have been all along. Mostly for correctness, but also to deal
  with the problem of non-UNIQUENAMEs causing the wrong files to be
  deleted with -d.
* Clean up the old /var/db/ports/*/distfiles files after reading them,
  and delete the directory if it's empty. Since we are doing this
  unconditionally now, there is no longer a need for delete_dist_list().
  The new ones will live and die with the rest of the package directory.
* Update some of the messages printed out for distfile-related things
  to make it more clear what's going on.
* Check DI_FILES to see if the distfile could be valid for another port
  in more places, so add a function to deal with the common ones.
* Add 2 more functions, make_distfiles() and make_port_subdir() to bring
  that common code (3 places each, ugh) under the same umbrella. Improve
  both implementations to use fewer forks.

Other changes
=============
* Add -e to the echo for pm_sv so that we can easily add a newline
* Take advantage of the above, and other adjustments to the whitespace
  to try to fit with the general theme of ws after a section
* Change the last 'find -d foo' to 'find foo -depth'
* Use 'while read' for the installed distfiles file, less forks
One more tiny whitespace tweak
* More whitespace twiddles
* If using -i and there is an +IGNORME file, the default should be no
2 more small ws twiddles
For --features:
* Most don't create $IPC_SAVE, so don't try to source it in a trap if it
  doesn't exist
* $grep_deps may exist for some features, like --check-depends, so always
  delete it in safe_exit if it exists

Other:
* Don't try to clean out WRKDIRPREFIX if we're not actually building
* In update_contents() streamline the code that handles replacing the file
  if necessary
* Simplify the whitespace in the code that updates dependencies after an
  install, there will always be at least one pm_v printed, so no need to
  be coy about it
Minor bug fix
=============
* If we trap while working on a child port don't remove that child from
  the PM_NEEDS_UPDATE list so that when it gets printed in the parent
  that child is still on the list. While I'm here, tidy up the code that
  prints the list.

Cosmetic changes
================
* Add -e to the pm_v echo as well, to allow easier printing of ws without
  using multiple commands.
* Move the counting of categories and total ports to ports_by_category()
  so that it can be used in other places besides -[lL]
* Use the count of total ports as $num_of_deps for -Faf
* In multiport(), decrement the number of ports to work on and print a -v
  message if we have already encountered a port in the worklist as a dependency
  of another port in the list. This is not only better cosmetically, it means
  we don't have to reset it after the first pass.
* For -a, remove the old, unnecessary test for FIRST_PASS, and re-indent that
  code. Also, add the num_{roots|trunks|branches|leaves} values to the headers
* The ALL_FETCH var was only used in one place anymore, so use the values
  behind it instead.
Minor tweaks/fixes
==================
* Do not use variables where they are not needed
* Do not duplicate the same test
* Unset multiple variables with the same command instead of 2
* When deleting empty DISTDIR subdirs use -mindepth 1 so that it will not
  error out if the directory is totally empty.
* Unset more stuff after it is no longer needed
* Update some comments to match the current state of the code
* Remove some stuff that cannot be reached any longer

Performance enhancement
=======================
* In read_distinfos*() use while read instead of grep. Avoids the fork
  and cuts the total time for that feature 25%
Remove some more unnecessary temporary variables related to pm_mktemp()
Turns out there are a non-zero number of distinfo files that have SIZE
listed first, so in the code that parses them for the data to put into
/var/db/pkg/$port/distfiles, handle this situation gracefully.
Removing $ALL_FETCH was a mistake because the reason it existed previously
is that $UPDATE_ALL cannot be exported to the children. So bring it back
as $PM_ALL_FETCH.

This is basically a cosmetic bug which will only show up when using -Faf
Use a more robust method of determining portdir from $PWD. This also works
for bare 'portmaster' with no arguments now, if you're in a port directory.
Bug fix: Do read_distinfos() in the background for multiport() too, oops

Update the comment re read_distinfos() in the single port code to reflect
current reality
More minor code cleanups
Simplify update_build_l(). Nowadays when we call it we always know the
origin, and if the port is installed we don't need to search for either
In check_dependency_files() unset the grep_deps var if we unlink the file

In find_dl_distfiles() we only need to test -s $dist_list if we're looking
at the old file, since the test for the new file already does this.

Optimize determination of $new_port:
 * When first set, let it be global
 * Use a function to incorporate/optimize the various tests from the
   2 different places that it was being set
When -r, print a clearer message for term-title about what we're doing
when we are going through the ports that depend on the -r port(s)

If there is an installed version, always print that message, not just
when we're in the parent
Improve messages for processing of dependent ports when -r
Due to improvements in the efficiency of portmaster's method of killing
background processes when trap'ing, plus the declining quality of ports
generally, when the background process that reads the distinfo files
encountered a fatal error (which they have been doing more frequently of
late), the resulting call to fail() would end up neatly killing all of
that parent's background fetch processes as well.

Fix that problem by not making the disruption in read_distinfos() fatal
unless it's being used for --clean-distfiles. All the other calls to this
function are run in the background for the distfile gathering process, and
a missing file in that list is an inconvenience at worst.
Merge tag '3.13' into integrate-pkgng

Update for portmaster-3.13
Merge tag '3.13.1' into integrate-pkgng

Update ports/patch-portmaster-pkgng for portmaster-3.13.1

Fix issue #307 -- this means that /var/db/pkg needs to contain
a sub-dir for each port still.