Top Level Namespace

Defined Under Namespace

Modules: GPGME

Constant Summary collapse

BUILD =
Dir::pwd
SRC =
File.expand_path(File.dirname(__FILE__))
PREFIX =
"#{BUILD}/dst"
ARCH_CFLAGS =
""
TARGET_IS_FAT =
false

Instance Method Summary collapse

Instance Method Details

#rubify(filename, enums) ⇒ Object



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
# File 'ext/gpgme/extract_enums.rb', line 3

def rubify(filename, enums)

  state = :source
  fields = {}
  last_field = nil

  enums.puts "  # rubified #{File.basename(filename)}"

  close_enum = ->(name) do

    enums.puts "  # #{$1}"
    fields.each do |key, value|
      enums.puts "  #{key} = #{value}"
    end

    fields = {}
    last_field = nil


    enums.puts ""
  end

  File.open(filename, "r") do |io|
    loop do
      line = io.gets
      break if line.nil?
      line.strip!
      next if line.empty?

      case state
      when :source
        state = :enum if line == "typedef enum"

      when :enum
        state = :enum_block if line == "{"
        if line =~ /^([a-z0-9_]+);$/
          state = :source

          close_enum.call $1
        end

      when :enum_block
        state = :enum if line == "}"

        if line =~ /^([A-Z0-9_a-z]+)\s*=([^,\/]+),?/
          fields[$1] = $2

          last_field = $1
        elsif line =~ /^([A-Z0-9_a-z]+)\s*,?/
          if last_field.nil?
            fields[$1] = 0
          else
            fields[$1] = "#{last_field} + 1"
          end

          last_field = $1
        elsif line =~ /^} ([a-z0-9_]+);$/
          state = :source
          close_enum.call $1
        end
      end

      if line =~ /^#define ([A-Z0-9_a-z]+)\s+([^\/]+)/
        if $1.start_with?("Gpgme") ||
           $1.start_with?("_GPG") ||
           $1 == "GPG_ERROR_H" ||
           $1 == "GPG_ERR_INLINE"

          next
        else
          enums.puts "  #{$1} = #{$2}"
        end
      end
    end
  end

  enums.puts ""
end