hostsupport/hostopenvg/genheader/c_utils.py
branchbug235_bringup_0
changeset 53 c2ef9095503a
parent 20 d2d6724aef32
equal deleted inserted replaced
52:39e5f73667ba 53:c2ef9095503a
       
     1 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 #
       
     3 # Permission is hereby granted, free of charge, to any person obtaining a
       
     4 # copy of this software and /or associated documentation files
       
     5 # (the "Materials "), to deal in the Materials without restriction,
       
     6 # including without limitation the rights to use, copy, modify, merge,
       
     7 # publish, distribute, sublicense, and/or sell copies of the Materials,
       
     8 # and to permit persons to whom the Materials are furnished to do so,
       
     9 # subject to the following conditions:
       
    10 #
       
    11 # The above copyright notice and this permission notice shall be included
       
    12 # in all copies or substantial portions of the Materials.
       
    13 #
       
    14 # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    17 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
       
    18 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
       
    19 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
       
    20 # THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    21 
       
    22 def get_include_guard_name(filename):
       
    23     return "__" + filename.upper().replace('.', '_')
       
    24 
       
    25 def begin_include_guard(defstring):
       
    26     print "#ifndef " + defstring
       
    27     print "#define " + defstring
       
    28 
       
    29 def end_include_guard():
       
    30     print "#endif\n"
       
    31 
       
    32 def make_constant(c, v):
       
    33     print "enum { " + str(c) + " = " + str(v) + "};"
       
    34     
       
    35 def make_include(fname):
       
    36     print "#include \"" + str(fname) + "\""
       
    37 
       
    38 def make_generation_notice():
       
    39     print "// This file is automatically generated. Please do not edit."
       
    40 
       
    41 def begin_namespace(name):
       
    42     print "namespace " + str(name) + " {"
       
    43 
       
    44 def end_namespace():
       
    45     print "}"
       
    46 
       
    47 def hex_formatter(i):
       
    48     return hex(i)
       
    49 
       
    50 def empty_format(i):
       
    51     return str(i)
       
    52 
       
    53 def make_array(qualifiers, type, name, data, ffn = empty_format, items_per_line = 8):
       
    54     
       
    55     print qualifiers,
       
    56     print type,
       
    57     print name + '[' + str(len(data)) + '] = {'
       
    58     formatted_items = map(ffn, data)
       
    59     s = 0
       
    60     for i in formatted_items:
       
    61         t = ""
       
    62         if s == 0:
       
    63             t = "    "
       
    64         print t + i + ", ",
       
    65         s += 1
       
    66         if s == items_per_line:
       
    67             print ""
       
    68             s = 0
       
    69     print "};"
       
    70     return len(formatted_items)
       
    71 
       
    72