source: openpam/trunk/misc/relname.pl

Last change on this file was 938, checked in by Dag-Erling Smørgrav, 3 years ago

Switch from $Id$ to $OpenPAM$.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to OpenPAM=%I
File size: 2.3 KB
Line 
1#!/usr/bin/perl -Tw
2#-
3# Copyright (c) 2011 Dag-Erling Smørgrav
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14# 3. The name of the author may not be used to endorse or promote
15#    products derived from this software without specific prior written
16#    permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29#
30# $OpenPAM: relname.pl 938 2017-04-30 21:34:42Z des $
31#
32
33use strict;
34use warnings;
35use vars qw(@VOWELS $DICTFILE);
36
37our @VOWELS = qw(a e i o u y);
38our $DICTFILE = "/usr/share/dict/web2";
39
40sub usage() {
41    die("usage: relname [yyyy-mm-dd]\n");
42}
43
44MAIN:{
45    my ($year, $month);
46
47    if (@ARGV == 0) {
48        my @time = localtime();
49        ($year, $month) = (1900 + $time[5], 1 + $time[4]);
50    } elsif (@ARGV == 1) {
51        $ARGV[0] =~ m/^(\d\d\d\d)-(\d\d)(?:-\d\d)?$/
52            or usage();
53        ($year, $month) = ($1, $2);
54    } else {
55        usage();
56    }
57    if ($year < 2000 || $year > 2025 || $month < 1 || $month > 12) {
58        usage();
59    }
60    $year = chr(ord("A") + ($year - 2000));
61    $month = $VOWELS[($month - 1) / 2];
62    print("$year$month\n");
63    open(WEB, "<", $DICTFILE)
64        or die("$DICTFILE: $!\n");
65    while (<WEB>) {
66        print if m/^$year$month\w+$/o;
67    }
68    close(WEB);
69}
70
711;
Note: See TracBrowser for help on using the repository browser.