'use strict';

var path = require('path')

exports.VERBOSE = 0

exports.pnGet = function() {
	return path.basename(process.argv[1])
}

exports.vputs = function(level /*, ...args */) {
	if (arguments.length < 2) throw new Error('vputs needs more args')
	if (level > exports.VERBOSE) return

	console.error.apply(this, Array.prototype.slice.call(arguments, 1))
}

exports.errx = function(exit_code, msg) {
	exports.vputs(0, `${exports.pnGet()} error: ${msg}`)
	if (exit_code) process.exit(exit_code)
}

exports.warnx = function(msg) {
	exports.vputs(0, `${exports.pnGet()} warning: ${msg}`)
}

exports.hash_size = function(hash) {
	return Object.keys(hash).length
}

@@ -490,24 +490,176 @@
 it_code)%0A%7D%0A%0A
+exports.errstack = function(exit_code, level, err) %7B%0A%09if (level %3C= exports.VERBOSE) console.error(err.stack)%0A%09if (exit_code) process.exit(exit_code)%0A%7D%0A%0A
 exports.warn

add errstack()