#!/usr/local/bin/perl
# colwide 0.01
# Copyright (c) 2014 Neel Chauhan <neel@neelc.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR  PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGE (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use strict;
my $char = "#";
my $defwidth = 80;

sub wholenumerr {
	print "\"@ARGV[0]\" is not a whole number\n";
	print "For colwide to work, you need to either:\n";
	print " * Specify a whole number in the arguments and print out the ";
	print "specified amount \n";
	print "   of characters based on the number defined\n";
	print " * Don't specify anything and default to 80 characters\n";
	exit();
}

sub usage {
	print "Usage: colwide [nochar]\n";
	print "[nochar] is optional. If specified, has to be a whole number\n";
	print "If [nochar] isn't specified, it will default to 80\n";
	exit();
}

my $nochar;

if (defined(@ARGV[0])) {
	if (@ARGV[0] =~ m/^\d+\z/) {
		$nochar = @ARGV[0];
	}
	elsif (lc(@ARGV[0]) eq "help") {
		usage();
	}
	else {
		wholenumerr();
	}
}
else {
	$nochar = $defwidth;
}

for (my $oncol = 0; $oncol < $nochar; $oncol++) {
	print $char;
}

print "\n";
