#!/usr/bin/perl #------------------------------------------------------------------------------ # $Id$ #------------------------------------------------------------------------------ # NAME: # # convert_gre_1162.pl # # DESCRIPTION: # # Convert a list of 1162 question/answer GRE words from # Oleg Smirnov's list (http://www.uoregon.edu/~osmirnov/gre/list.html) # to Granule's Deck format. # # Each word comes in the format: # # q: word # a: meaning # [an empty line] # # SYNOPSIS: # # % convert_gre_1162.pl from-file to-file # # EXAMPLE: # # % convert_gre_1162.pl GRE_1162_Oleg_Smirnov.txt GRE_1162.dkf # # Convert ASCII GRE_1162_Oleg_Smirnov.txt into Granule's Deck file # GRE_1162.dkf. # # AUTHOR: # # Vladislav Grinchenko # November 11 2004 #------------------------------------------------------------------------------ # You might want to change these to your liking #-------------------------------------------------- # $sound_path="/usr/share/WyabdcRealPeopleTTS/"; $user_name=""; # Your name # #-------------------------------------------------- foreach $i (0 .. $#ARGV) { print "ARGV[", $i, "] = ", $ARGV[$i], "\n"; } if ($ARGV[1] eq "") { die "\nMissing to-file argument!\n"; } open(INFILE,"< $ARGV[0]") || die "\nCannot open from-file!"; open(OUTFILE,"> $ARGV[1]") || die "\nCannot create to-file!"; $date = `date`; chop ($date); $card_id = `date +%s`; # Number of seconds since Jan 1 1970 chop ($card_id); if ($user_name eq "") { $login_name = `whoami`; chop($login_name); open(PASSWD, "/etc/passwd") || die "\nCannot open /etc/passwd"; while () { chop; ($login,$passd,$uid,$gid,$gcos,$rest) = split(/:/); if ($login eq $login_name) { ($user_name,$rest) = split(/,/,$gcos); last; } } close(PASSWD); } # Write out the header # print OUTFILE "\n"; print OUTFILE "\n"; print OUTFILE "\n"; print OUTFILE " ", $user_name, "\n"; print OUTFILE " Created on ", $date, "\n"; print OUTFILE " ", $sound_path, "\n"; while() { chop($_); chop($_); ($tag,$data) = split(':'); if ($tag eq "") { next; } $data =~ s/\s+//; # eat leading whitespace $data =~ s/\s+$//; # remove extra whitespaces at the end # print "tag = [", $tag, "]\n"; # print "data = [", $data, "]\n"; # print "--------------------\n"; if ($tag eq "q") { print OUTFILE "\n"; $card_id += 1; print OUTFILE " ", $data, "\n"; } elsif ($tag eq "a") { print OUTFILE " ", $data, "\n"; print OUTFILE " \n"; print OUTFILE "\n"; } } # while(INFILE) print OUTFILE "\n"; close(OUTFILE); $time_now=`date +%s`; $time_now -=$card_id; # When we convert a batch of cards, we might overrunning Card ID numbers. # To avoid duplicates, wait for the current time to catch up. # if ($time_now < 0) { $time_now *= -1; print "Don't use this script in the next ", $time_now/60.0, " minutes\n"; } print "\nConversion has been completed!\n";