# Path: ma/core.py
# X86_PATTERNS = ["amd64", "AMD64", "[xX]86", "[xX]86_64", "[iI]386", "[iI]486",
#                 "[iI]686"]
# PPC_PATTERNS = ["PPC", "ppc", "power[pP][cC]", "POWER[pP][cC]"]
# def get_supported_checkers():
# def get_supported_extensions():
# def execute(command):
# def execute_stdout(command):
# def cmdexists(command):
# def get_timestamp():
# def get_files(location, hint=''):
# def get_file_content(file_name, offset, length):
# def get_raw_node(node):
# def get_includes(file_path):
# def get_ifdefs(file_path):
# def get_ifdef_regex(arch, separator):


import re
from ma import core

def get_all_statements(names, file_name):
    """ Get all statements from a file that contains specific names. The
    parameter 'names' is a list of names that will be searched in the file.
    This function returns a list with the line number and the statement, e.g:
        <line_number>$<statement>
     """
    # Split list to avoid problem with command size
    size = 2500
    names = [names[x: x + size] for x in range(0, len(names), size)]

    lines = []
    for name in names:
        lines.extend(_get_lines(name, file_name))

    # Removes line comment
    comments_positions = __get_comments_position(file_name)
    lines = __remove_comments(lines, comments_positions)

    # If lines list is empty it avoid to use Awk and return an empty list
    if not lines:
        return []

    # Run awk command to get entire statements from problematic lines
    awk_delimiter = '||'
    command = "awk '"
    for line in lines:
        command += "NR==" + line + awk_delimiter
    command = command[:-len(awk_delimiter)]
    command += ",/;/ {print NR\"" + LINE_DELIMITER + "\", $0}' " + file_name

# Path: ma/core.py
# X86_PATTERNS = ["amd64", "AMD64", "[xX]86", "[xX]86_64", "[iI]386", "[iI]486",
#                 "[iI]686"]
# PPC_PATTERNS = ["PPC", "ppc", "power[pP][cC]", "POWER[pP][cC]"]
# def get_supported_checkers():
# def get_supported_extensions():
# def execute(command):
# def execute_stdout(command):
# def cmdexists(command):
# def get_timestamp():
# def get_files(location, hint=''):
# def get_file_content(file_name, offset, length):
# def get_raw_node(node):
# def get_includes(file_path):
# def get_ifdefs(file_path):
# def get_ifdef_regex(arch, separator):


# Path: ma/checkers/checker_file_utils.py
import re
from ma import core


def get_all_statements(names, file_name):
    """ Get all statements from a file that contains specific names. The
    parameter 'names' is a list of names that will be searched in the file.
    This function returns a list with the line number and the statement, e.g:
        <line_number>$<statement>
     """
    # Split list to avoid problem with command size
    size = 2500
    names = [names[x: x + size] for x in range(0, len(names), size)]

    lines = []
    for name in names:
        lines.extend(_get_lines(name, file_name))

    # Removes line comment
    comments_positions = __get_comments_position(file_name)
    lines = __remove_comments(lines, comments_positions)

    # If lines list is empty it avoid to use Awk and return an empty list
    if not lines:
        return []

    # Run awk command to get entire statements from problematic lines
    awk_delimiter = '||'
    command = "awk '"
    for line in lines:
        command += "NR==" + line + awk_delimiter
    command = command[:-len(awk_delimiter)]
    command += ",/;/ {print NR\"" + LINE_DELIMITER + "\", $0}' " + file_name

    output = core.execute_stdout(command)[1]