# -- perl --

#************************************************************
#		  DHAVAL RAJ
#	LINACCESS PROJECT For PROFESSOR MANN
#************************************************************

# Jun 14 2002
# modified by Suryadi Suryadi for distribution


&MainFunction;


#***************************************************************
#***************************************************************
#                    MAIN FUNCTION
#***************************************************************
#***************************************************************

sub MainFunction
{
	if (@ARGV[0] eq "--help")
	{
    		&ExtendedHelp;
    		exit;
	}

	$i=0;
	while(@ARGV[$i])
	{
    		@Input=split(//,@ARGV[$i]);
    		if ($Input[0] eq "-")
    		{
    			&CheckOptions(@ARGV[$i]);
    		}
    		$i++;
	}
	$try=`dmesg @ARGV > ~/.garbage`;
	&PrintOnScreen;
	exit;
}



#***************************************************************
#***************************************************************
#                    PROCEDURES
#***************************************************************
#***************************************************************



sub PrintOnScreen
{
	$DIR = $ENV{"HOME"};
	open(MYFILE,"$DIR/.garbage") or die "Can't Open File  \n";
	$line=<MYFILE>;
	while($line ne "")
	{
		$line=~s/( +)/ /g;
		@linesplit=split(/ /,$line);
		$linesize=0;
		$count=0;
		while($linesplit[$count] ne "")
		{
			$linesize=$linesize + length($linesplit[$count]);
			if ($linesize >= 29)
			{
				print("\n");
				$linesize=length($linesplit[$count]);

			}
			printf("%s ",$linesplit[$count]);
			$count++;
		}
	$line=<MYFILE>;
	}
	close(MYFILE);
}


sub CheckOptions
{
    my($Option)=@_;
    if (($Option ne "-c") && ($Option ne "-n") && ($Option ne "-s"))
    {
	&Help;
	exit;
    }
}

sub Help
{
    print("\nUSAGE: dmesg [-c] [-s buffersize] [-n level] [--help] \n\n");
}


sub ExtendedHelp
{
    print("ls - \n"); 
    print("     \n\n");
    print("Options\n");
    print("   : \n"); 
    print("     \n");
    print("     \n");
    print("   : \n");
}
