1 #!/usr/bin/perl -w --strict
8 # genword( accumulated, core )
9 # This function will generate a random sequens of character
10 # containing only characters from accum or core and all words
11 # generated will contain at lest on character from core
14 (my $accum, my $core) = @_;
19 for(my $i=0;$i<=rand(5);$i++)
21 my $ran_pos=int(rand(length($all)));
22 $res=$res.substr($all,$ran_pos,1);
25 # check if we have generated a walid word, containig some characters from $core
26 if ($res =~ m/[$core]/)
32 return genword
($accum,$core);
36 # This function will return a list of words containing only characters from
37 # accum or core. And all words will contain at lest on echaracter from core.
38 # If we can't find enough words, we will use genword to generate enough words
53 if (m/[$core]/ && m/^[($all)][$all]*$/)
59 for(my $i=@res;$i<30;$i++)
61 push @res,genword
($accum,$core);
68 # Genlevel will generate a level
73 my @list = genlist
($accum,$core);
74 my $max_lines = $number_of_line;
75 my $max_length = $length_of_line;
78 my $tmp=$list[rand(@list)-1];
79 $res = $res.$tmp; # first word on line should not have space
82 my $tmp=$list[rand(@list)-1];
84 $max_length = $max_length - (length($tmp) + 1); # +1 is for counting one extra space for each word
87 $max_length = $length_of_line;
88 $max_lines = $max_lines - 1;
96 s/\\/\\\\/g; #remove escape character...
97 s/-/\\-/g; #remove any - since this will mean range
105 "######################################################################\n".
107 "# KTouch training file generated ".localtime(time())."\n".
109 "# Perl Script written by Steinar Theigmann & Håvard Frøiland.\n".
117 "usage: ktouch-gen config_file\n".
118 " Example: ./ktouch-gen english-conf < english-word-file\n".
122 # --------------------- START ----------------------------
124 if(@ARGV == 0) # exit if there is no config_file specified
129 open(CONFIG
,$ARGV[0]) # First argument should be config file
130 or die "\ nCan't find config_file: $ARGV[0]\n\n";
132 # Read in all elements in config file
137 if(s/length\-of\-line//)
139 $length_of_line = $_;
141 elsif(s/number\-of\-line//)
143 $number_of_line = $_;
145 elsif($_) # Add to config if not empty
174 print "# Level $count\n";
176 print genlevel
($accum,$_);