File: create-boards

package info (click to toggle)
nvram-wakeup 1.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,068 kB
  • sloc: ansic: 1,943; sh: 309; ruby: 190; makefile: 102
file content (105 lines) | stat: -rwxr-xr-x 3,179 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/ruby

#
# NVRAM WakeUp - Code generator for mainboard "database"
#
# Copyright (c) 2008 Tobias Grimm
#
# $Id$
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

require 'yaml'
require 'pp'
require 'keys'

@infowriters = []
@boards = []
@auto_infowriter_number = 0

def add_or_get_infowriter(board)
    infowriter_name = board['infowriter']
    if infowriter_name == 'AUTO'
        # find info write with matching settings
        infowriter = @infowriters.find {|iw|  board.slice(@biosinfo_keys) == infowriter}
        if not infowriter
            @auto_infowriter_number = @auto_infowriter_number + 1
            infowriter_name = "infowriter_%.4d" % @auto_infowriter_number
        end
    else
        # find info write with same name
        infowriter = @infowriters.find {|iw| iw.iw_name == infowriter_name}
    end

    if not infowriter
        infowriter = { 'iw_name' => infowriter_name }
        infowriter.merge!(board.slice(@biosinfo_keys))
        @infowriters << infowriter
    end

    return infowriter
end

def generate_info_writers
    file = File.new('infowriters.c.inc', 'w')
    for infowriter in @infowriters
        if infowriter.iw_name == 'AUTO'
            puts "ERROR"
            exit
        end
        file.puts
        file.puts "void #{infowriter.iw_name}(struct biosinfo *b)"
        file.puts "{"
        for key_value in @biosinfo_keys 
            if infowriter[key_value]
                file.puts "    b->#{key_value} = #{infowriter[key_value]};"
            end
        end
        file.puts "}"
    end
    file.close
end

def format_string(string)
    if string != "NULL"
        return '"' + string.gsub('\\', '\\\\\\') + '"'
    else
        return string
    end
end

def generate_boards
    file = File.new('boards.c.inc', 'w')
    file.puts "static struct mainboard boards[] = {"
    for board in @boards
        file.puts "    { IW(#{board.infowriter.iw_name}), #{format_string(board.vendor)}, #{format_string(board['type'])}, #{format_string(board.version)}, #{format_string(board.biosvendor)}, #{format_string(board.biosversion)}, #{format_string(board.biosrelease)}},"
    end
    file.puts"    { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }"
    file.puts "};"
    file.close
end

#
# main()
#

for board_data in YAML.load(File.new(File.dirname(__FILE__)+'/boards.yaml', 'r'))
    board = { 'infowriter' => add_or_get_infowriter(board_data) }
    board.merge!(board_data.slice(@dmi_keys))
    @boards << board
end

generate_info_writers
generate_boards