#!/usr/bin/perl
# Copyright 2003 Vlado Keselj www.cs.dal.ca/~vlado

sub help { print <<"#EOT" }
# Octal manipulation functions, version $VERSION
#
# Usage: oct [switches] [input string]
# With no switches, reads sequence of decimal numbers and coverts them
# to octal numbers.
#  -o  produce octal representation of the input string
#  -h  Print help and exit.
#  -v  Print version of the program and exit.
#EOT

use strict;
use vars qw($VERSION);
$VERSION = sprintf "%d.%d", q$Revision: 1.0 $ =~ /(\d+)/g;

use Getopt::Std;
use vars qw($opt_v $opt_h $opt_o);
getopts("vho");

if ($opt_v) { print "$VERSION\n"; exit; }
elsif ($opt_h) { &help(); exit; }
elsif (!@ARGV) { &help(); exit; }

if ($opt_o) { print map sprintf("\\%o", ord($_)), split(//, join(' ', @ARGV)) }
else { print join(' ', map sprintf("%o", $_), @ARGV) }

print "\n";