示例#1
0
    def valueCheck(self, params, context):
        def _cmp(operator, lhs, rhs, parens):
            # operator is either "<=" or "<"
            if operator == "<=":
                return "!(%s < %s)" % (rhs, lhs)
            elif parens:
                return "(%s < %s)" % (lhs, rhs)
            else:
                return "%s < %s" % (lhs, rhs)

        var = params[0] if params else "result." + self.memberName
        lines = []
        for lo, hi, loCmp, hiCmp in self.member.values:
            if lo == hi:
                lines.append("(%s == %s)" % (var, lo))
            elif lo and hi:
                lines.append("(%s && %s)" % (_cmp(loCmp, lo, var, False), _cmp(hiCmp, var, hi, False)))
            elif lo:
                lines.append(_cmp(loCmp, lo, var, True))
            elif hi:
                lines.append(_cmp(hiCmp, var, hi, True))
        if lines:
            return codegen.join(lines, 76 - context[1], " || ", " ||")
        else:
            return "true"
示例#2
0
 def checkFinalOption(self, params, context):
     words = []
     for m in self._members:
         if m.type == "final":
             for a in m.arguments:
                 for f in a.flags:
                     words.append('arg == "%s"' % f)
     return codegen.join(words, 79 - context[1], " || ", " ||")
示例#3
0
def main(args):
    if len(args) != 1:
        print("usage: %s <configuration file>" % sys.argv[0])
        return 1
    config = read_config_file(args[0])
    arrays = {}
    for label, path in config:
        print(f"{label} {path}", file=sys.stderr)
        name = os.path.basename(path)
        name = os.path.splitext(name)[0].replace("-", "_")
        mapping = read_character_map(path)
        ranges = get_char_ranges(mapping)
        if not ranges:
            continue
        ranges.sort(key=lambda v: v[1])
        lines = [f"constexpr CodePageRange {label}_{name}_CHARS[] = {{"]
        strs = []
        for index, char, count in ranges:
            count -= 1
            if char < 65536:
                strs.append(f"{{0x{char:04X}, {index:3d}, {count:3d}}}")
            else:
                first = (char >> 16) & 0xFFFF
                second = char & 0xFFFF
                strs.append(f"{{0x{first:04X}, 255, 255}}")
                strs.append(f"{{0x{second:04X}, {index:3d}, {count:3d}}}")
        value_lines = codegen.join(strs,
                                   line_width=70,
                                   sep=", ",
                                   newline_sep=",")
        lines.extend("    " + s for s in value_lines)
        lines.append("};")
        entry = arrays.setdefault(label, ([], []))
        entry[0].append(lines)
        entry[1].append(f"{label}_{name}")
    lines = []
    for key in arrays:
        lines.append("")
        lines.append(f"#ifdef YCONVERT_ENABLE_{key}_CODE_PAGES")
        for arr_lines in arrays[key][0]:
            lines.append("")
            lines.extend(arr_lines)
        lines.append("")
        cases = []
        for c in arrays[key][1]:
            expander = codegen.DictExpander(dict(name=c))
            cases.extend(codegen.make_lines(CASE_TEMPLATE, expander))
        expander = codegen.DictExpander(dict(cases=cases, label=key.title()))
        lines.extend(codegen.make_lines(GET_RANGES_TEMPLATE, expander))
        lines.append("#endif")
    date = datetime.date.today()
    expander = codegen.DictExpander(
        dict(arrays=lines,
             year=date.year,
             date="%d-%02d-%02d" % (date.year, date.month, date.day)))
    print(codegen.make_text(FILE_TEMPLATE, expander))
    return 0
示例#4
0
 def declareOptionProcessors(self, params, context):
     words = []
     for o in self._options:
         m = o.member
         if m.type in ("help", "info"):
             for f in o.flags:
                 words.append('OptionProcessor("%s", process_%s_option)' % (f, m.name))
         elif m.type not in ("final"):
             for f in o.flags:
                 words.append('OptionProcessor("%s", process_%s_option)' % (f, o.name))
         else:
             pass
     return codegen.join(words, 79 - context[1], ", ", ",")
示例#5
0
 def initializeTrackedOptions(self, params, context):
     lines = []
     for m in self._members:
         if isTrackable(m):
             lines.append("%(name)s(false)" % m)
     return codegen.join(lines, 79 - context[1], ", ", ",")