]> git.cryptolib.org Git - arm-crypto-lib.git/blob - host/find_tv.rb
Adding Khazad
[arm-crypto-lib.git] / host / find_tv.rb
1 #!/usr/bin/ruby 
2 # shavs_test.rb
3 =begin
4     This file is part of the ARM-Crypto-Lib.
5     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
6
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 =end
20
21 require 'find'
22
23 def read_record(file)
24   record = Hash.new
25   lb = file.gets() until /[\s]*Set[\s]*[\d]+[\s]*,[\s]*vector#[\s]*[\d]+[\s]*:[\s]*/.match(lb)
26   term=false
27   lastkey=nil
28   begin
29     term = true
30     lb=file.gets();
31         if m=/[\s]*([^=]+)[\s]*=[\s]*(.*)/.match(lb)
32           lastkey=m[1]
33           record[m[1]] = m[2]
34           term = false
35         else
36           if m=/[\s]*([0-9a-fA-F]+)[\s]*/.match(lb) and lastkey!=nil
37             record[lastkey] += m[1]
38                 term = false
39           end
40         end
41   end until term
42   record
43 end
44
45 def check_match(fname1, fname2)
46   r1 = Hash.new
47   r2 = Hash.new
48   if File.directory?(fname1)
49     return false
50   end
51   if File.directory?(fname2)
52     return false
53   end
54   file1 = File.new(fname1, "r");
55   file2 = File.new(fname2, "r");
56   r1 = read_record(file1)
57   r2 = read_record(file2)
58   return r1==r2
59 end
60
61 def get_params_from_fn(fname)
62   params = Array.new
63   if not p = /[^\.]*\.(([\d]+)\.*).*/.match(fname)
64     return params
65   end
66   params = p[1].split(/\./)
67   return params
68 end
69
70 def get_params_from_fn2(fname)
71   params = Array.new
72   if not p = /[^\.]*\.((-([\d]+))*\.).*/.match(fname)
73     return params
74   end
75   params = p[1].split(/\./)
76   return params
77 end
78
79 def find_files(fname1, afnames)
80   files = Array.new
81   params = Array.new
82   params = get_params_from_fn(fname1)
83   afnames.each{ |fn|
84     p = get_params_from_fn2(fn)
85         puts("#{params} ?=  #{p}")
86     if params.eql?(p)
87           files << fn
88         end
89   }
90   return files
91 end
92
93
94 if ARGV.size<2 or File.directory?(ARGV[0]) or (File.directory?(ARGV[1])==false)
95   STDERR.print <<EOF
96   Usage: ruby #{$0} file directory [formatstring]
97    
98 EOF
99   exit(1)
100 end
101
102 fmt=String.new
103 if ARGV.size>=3
104   fmt=ARGV[2]
105 else
106   fmt = "%s --> %s\n"
107 end
108 files = Array.new
109 files = Dir.entries(ARGV[1])
110 files.each{ |fn|
111   if check_match(ARGV[0], ARGV[1]+fn) 
112         printf(fmt, ARGV[0].to_s, ARGV[1]+fn.to_s)
113         puts ""
114 #       puts("#{ARGV[0]} --> #{ARGV[1]+fn}")
115   end
116 }
117