LoginSignup
2
1

More than 5 years have passed since last update.

mapファイルから追加された変数を列挙

Posted at
#coding: utf-8

import codecs
import sys

file_path = u""
text_coding = "utf-8"

def read_text(input_file_name):
    ret_text = ""
    with codecs.open(input_file_name, 'r', text_coding) as inf:
        for aline in inf:
            if u" " not in aline:
                ret_text += aline.strip()
            else:
                ret_text += aline
    return ret_text

def rekkyo_and_write_variables_in_map_file(soft_code):
    input_file_name = file_path + soft_code+u".map"

    vars_list=[]
    flag_start_get_var = False
    inf = read_text(input_file_name)
    for aline in inf.split(u"\n"):
        if u"*** ENTRY LIST" in aline:
            flag_start_get_var = True
        elif aline.strip().startswith(u"[1]"):
            flag_start_get_var = False

        if flag_start_get_var == True:
            if aline.startswith(u" ") or u" Code " in aline:
                continue
            else:
                vars_list.append(aline.strip().split(u" ")[0])

    output_file_name = file_path + soft_code + u"_variables.txt"

    with codecs.open(output_file_name, 'w', text_coding) as outf:
        for avar in vars_list:
            outf.write(avar+"\n")

    for avar in vars_list:
        print avar

def rekkyo_new_added_variables(old_variables_soft_code, new_variables_soft_code):
    old_variables=[]
    new_variables=[]
    added_variables=[]

    input_file_name = file_path + old_variables_soft_code + u"_variables.txt"
    flag_start_get_var = False
    with codecs.open(input_file_name, 'r', text_coding) as inf:
        for aline in inf:
            if aline.startswith(u"----"):
                flag_start_get_var = True
            if flag_start_get_var == True:
                old_variables.append(aline.strip())

    input_file_name = file_path + new_variables_soft_code + u"_variables.txt"
    flag_start_get_var = False
    with codecs.open(input_file_name, 'r', text_coding) as inf:
        for aline in inf:
            if aline.startswith(u"----"):
                flag_start_get_var = True
            if flag_start_get_var == True:
                new_variables.append(aline.strip())
    for avar in new_variables:
        if avar not in old_variables:
            added_variables.append(avar)

    #書き出し
    #関数
    output_file_name = file_path + old_variables_soft_code + u"_to_" + new_variables_soft_code + u"_added_functions.txt"
    with codecs.open(output_file_name, 'w', text_coding) as outf:
        for avar in added_variables:
            if len(avar) < 1:
                continue
            if avar[0].isupper() and not avar.endswith(u"_Handler") and not u"$$" in avar:
                outf.write(avar+"\n")
    #変数
    output_file_name = file_path + old_variables_soft_code + u"_to_" + new_variables_soft_code + u"_added_variables.txt"
    with codecs.open(output_file_name, 'w', text_coding) as outf:
        for avar in added_variables:
            if len(avar) < 1:
                continue
            if avar[0].islower():
                outf.write(avar+"\n")

rekkyo_and_write_variables_in_map_file(u"")
rekkyo_and_write_variables_in_map_file(u"")

rekkyo_new_added_variables(u"",u"")
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1