#!/usr/pkg/bin/perl

=begin metadata

Name: arch
Description: display system machine type
Author: Theo Van Dinter, felicity@kluge.net
License:

=end metadata

=cut

use strict;

use File::Basename qw(basename);
use Getopt::Std qw(getopts);
use POSIX qw(uname);

use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

my $Program = basename($0);

my %opt;
getopts('k', \%opt) or usage();
usage() if @ARGV;

# system ... (uname -s)
# arch   ... (uname -m)
my ($system, $arch) = (uname())[0,4];

# sun3.* -> sun3, sun4.* -> sun4, etc. SunOS hooey.
# looks like `uname -m` eq `arch -k` on suns ...
unless ($opt{'k'}) {
	$arch =~ s/^(sun\d+).*$/$1/;
}

$arch = "$system.$arch" if ( $system eq "OpenBSD" ); # OpenBSD hooey.
print "$arch\n";
exit EX_SUCCESS;

sub usage {
	warn "usage: $Program [-k]\n";
	exit EX_FAILURE;
}

=head1 NAME

arch - display system machine type

=head1 SYNOPSIS

B<arch> [ C<-k> ]

=head1 DESCRIPTION

arch displays the current system architecture type.  It tends to be
equivilent to C<uname -m> (except on SunOS platforms, see B<NOTES>).

=head1 OPTIONS

C<-k>	Displays kernel architecture on SunOS platforms.

=head1 NOTES

SunOS tends to differentiate between kernel and system architecture.  I<uname
-m> will return kernel architecture.  System architecture is the same
information except it doesn't include the trailing alpha chars.  I.e.:
'sun4m' (kernel) = 'sun4' (system), 'sun3x' = 'sun3', etc, etc.

=head1 HISTORY

Perl version rewritten for the Perl Power Tools project from the
description of the arch program in OpenBSD.

=head1 AUTHOR

Theo Van Dinter (felicity@kluge.net)

=head1 SEE ALSO

uname(1) uname(2) machine(1)
