#!/usr/local/bin/perl -Tw # # $Id: $ # # David Syzdek's Tilde Website # Copyright (c) 2006 David M. Syzdek # # @SYZDEK_COPYING_START@ # @SYZDEK_COPYING_END@ # # ~/misc/geekdecoder.pl - Decodes Geek Code # # +-=-=-=-=-=-+ # | | # | Headers | # | | # +-=-=-=-=-=-+ use 5.0008; use strict; $|++; our $PROGRAM_NAME = 'geekdecoder.pl'; our $VERSION = '0.01'; our $DESCRIPTION = 'Decodes Geek Code'; our $AUTHOR = 'David M. Syzdek "syzdek@gmail.com"'; # +-=-=-=-=-=-=-=+ # | | # | Prototypes | # | | # +-=-=-=-=-=-=-=+ sub geekdecode(%); # decodes Geek Code sub main(@); # main statement sub parse_file($); # parses config file # +-=-=-=-=-=-=-+ # | | # | Functions | # | | # +-=-=-=-=-=-=-+ # decodes Geek Code sub geekdecode(%) { # grabs passed args my %data = @_; # Geek Type: if ($data{'GB'}) { printf("Geek of Business\n"); }; if ($data{'GC'}) { printf("Geek of Classics\n"); }; if ($data{'GCA'}) { printf("Geek of Commercial Arts\n"); }; if ($data{'GCM'}) { printf("Geek of Computer Management\n"); }; if ($data{'GCS'}) { printf("Geek of Computer Science\n"); }; if ($data{'GCC'}) { printf("Geek of Communications\n"); }; if ($data{'GE'}) { printf("Geek of Engineering\n"); }; if ($data{'GED'}) { printf("Geek of Education\n"); }; if ($data{'GFA'}) { printf("Geek of Fine Arts\n"); }; if ($data{'GG'}) { printf("Geek of Government\n"); }; if ($data{'GH'}) { printf("Geek of Humanities\n"); }; if ($data{'GIT'}) { printf("Geek of Information Technology\n"); }; if ($data{'GJ'}) { printf("Geek of Jurisprudence (Law)\n"); }; if ($data{'GLS'}) { printf("Geek of Library Science\n"); }; if ($data{'GL'}) { printf("Geek of Literature\n"); }; if ($data{'GMC'}) { printf("Geek of Mass Communications\n"); }; if ($data{'GM'}) { printf("Geek of Math\n"); }; if ($data{'GMD'}) { printf("Geek of Medicine\n"); }; if ($data{'GMU'}) { printf("Geek of Music\n"); }; if ($data{'GPA'}) { printf("Geek of Performing Arts\n"); }; if ($data{'GP'}) { printf("Geek of Philosophy\n"); }; if ($data{'GS'}) { printf("Geek of Science (Physics, Chemistry, Biology, etc.)\n"); }; if ($data{'GSS'}) { printf("Geek of Social Science (Psychology, Sociology, etc.)\n"); }; if ($data{'GTW'}) { printf("Geek of Technical Writing\n"); }; if ($data{'GO'}) { printf("Geek of Other\n"); }; if ($data{'GU'}) { printf("Geek of Undecided\n"); }; if ($data{'GAT'}) { printf("Geek of All Trades\n"); }; if ($data{'G'}) { if ($data{'G'} eq '!') { printf("Geek of No Quakifications\n"); }; }; # Dress if ($data{'d'}) { printf("Dress: "); if ($data{'d'} eq '++') { printf("I tend to wear conservative dress such as a business suit or worse, a tie.\n"); } elsif ($data{'d'} eq '+') { printf("Good leisure-wear. Slacks, button-shirt, etc. No jeans, tennis shoes, or t-shirts.\n"); } elsif ($data{'d'} eq 'true') { printf("I dress a lot like those found in catalog ads. Bland, boring, without life or meaning."); }; elsif ($data{'d'} eq '-') { printf("I'm usually in jeans and a t-shirt."); }; elsif ($data{'d'} eq '--') { printf("My t-shirts go a step further and have a trendy political message on them."); }; elsif ($data{'d'} eq '---') { printf("Punk dresser, including, but not limited to, torn jeans and shirts, body piercings, and prominent tattoos."); }; elsif ($data{'d'} eq '?') { printf("I have no idea what I am wearing right now, let alone what I wore yesterday."); }; elsif ($data{'d'} eq '+') { printf(""); }; }; # ends function return(0); }; # parses config file sub parse_file($) { # grabs passed args my $filename = shift; # declares local vars my $buff; my $key; my %data; # checks for file if (! -f $filename) { printf STDERR ("file not found\n"); return(); }; # opens file for reading if (! open(FD, "$filename")) { return(); }; # reads header while () { $buff = $_; chomp($buff); if ($buff =~ /-----BEGIN GEEK CODE BLOCK-----/) { last; }; }; while () { $buff = $_; chomp($buff); if ($buff =~ /-----END GEEK CODE BLOCK-----/) { close(FD); return(%data); } elsif ($buff !~ /^Version: [\d].[\d]+$/) { foreach $key (split(/ /, $buff)) { if ($key =~ /^([\w]+)(.*)$/) { $data{$1} = $2 ? $2 : 'true'; }; }; }; }; # closes file close(FD); # ends function return(); }; # +-=-=-=-=-=-=-=-=-=+ # | | # | Main Statement | # | | # +-=-=-=-=-=-=-=-=-=+ sub main(@) { # grabs passed args my @argv = @_; # declares local vars my $filename; my $key; my %data; # checks args if (@argv < 1) { printf STDERR ("usage: %s \n", $PROGRAM_NAME); return(0); }; $filename= $ARGV[0]; # parses file if (!(%data = parse_file($filename))) { return(0); }; # parses file geekdecode(%data); # ends function return(0); }; exit(main(@ARGV)); # ends script