Define OSMAJOR as the OS major version, and add it to CFLAGS when
compiling libpkg sources.

Add new function: bool pkg_compiled_for_same_os_major(void) -- detect
when pkg(8) is running on a different OS major version than what it
was compiled for (presumably as a consequence of system upgrade)

Add INDEXDIR and INDEXFILE config file values to parallel the usage in
${PORTSDIR}/Makefile etc.  These are respectively the directory to
search for the ports index in (if undefined, defaults to the value of
PORTSDIR) and the filename of the index -- default INDEX-N where N is
the OS major version.
Fix typo.
Add some helpful advice for people doing major version upgrades.
Merge branch 'master' into indexfile
Merge branch 'master' into indexfile

Conflicts:
	libpkg/Makefile
	libpkg/pkg.h.in
	libpkg/pkg_config.c
Get the OS Major version we're being compiled under from the
__FreeBSD__ or __DragonFly__ macro built into cc.  Default to using
the ports INDEX as during our compilation, but warn when that does not
match the runtime OS major version -- ie. we're in the middle of an OS
upgrade.
Add a flag to indicate processing a named INDEX file from the command
line -- backwards compatibility with pkg_version, and also to make
'pkg version' do what the man page says it does...
Fix spelling
Ignore some more generated files
Refactor.  Add support for reading INDEXFILE from command line.
Merge branch 'master' into indexfile
Delete unused variable.
Fix typo.
Remove '!' so that error messages readds grammatically.
Don't alter a malloc'd variable and then try and free the altered result.

Fix off-by-one error when scanning backwards through a port origin

Always initialise struct pkgdb *db before pkgdb_open()
pkg version can read an arbitrary INDEX file now.
Fix ports tree detection logic
exec_buf() is only used by pkg version.
exec_buf() is only used in pkg version.

Reuse the same struct sbuf to contain the output of the command.

Return the number of characters read in command output.
Emit error if package pattern has not been found.

Signed-off-by: Vsevolod Stakhov <vsevolod@highsecure.ru>