# Path: ship/utils/dbfread/ifiles.py
# def ifind(pat, ext=None):
#     """Look for a file in a case insensitive way.
# 
#     Returns filename it a matching file was found, or None if it was not.
#     """
# 
#     if ext:
#         pat = os.path.splitext(pat)[0] + ext
# 
#     files = iglob(pat)
#     if files:
#         return files[0]  # Return an arbitrary file
#     else:
#         return None


from collections import namedtuple
from .ifiles import ifind
from .struct_parser import StructParser
                return data[:end_of_memo]

            # Alternative end of memo markers:
            # \x1a\x1a
            # \x0d\x0a

        return data[:eom]


class DB4MemoFile(MemoFile):
    """dBase IV memo file"""

    def __getitem__(self, index):
        if index <= 0:
            return None

        # Todo: read this from the file header.
        block_size = 512

        self._seek(index * block_size)
        memo_header = DB4MemoHeader.read(self.file)
        data = self._read(memo_header.length)
        # Todo: fields are terminated in different ways.
        # \x1a is one of them
        # \x1f seems to be another (dbase_8b.dbt)
        return data.split(b'\x1f', 1)[0]


def find_memofile(dbf_filename):
    for ext in ['.fpt', '.dbt']:

# Path: ship/utils/dbfread/ifiles.py
# def ifind(pat, ext=None):
#     """Look for a file in a case insensitive way.
# 
#     Returns filename it a matching file was found, or None if it was not.
#     """
# 
#     if ext:
#         pat = os.path.splitext(pat)[0] + ext
# 
#     files = iglob(pat)
#     if files:
#         return files[0]  # Return an arbitrary file
#     else:
#         return None


# Path: ship/utils/dbfread/memo.py
from collections import namedtuple
from .ifiles import ifind
from .struct_parser import StructParser

                return data[:end_of_memo]

            # Alternative end of memo markers:
            # \x1a\x1a
            # \x0d\x0a

        return data[:eom]


class DB4MemoFile(MemoFile):
    """dBase IV memo file"""

    def __getitem__(self, index):
        if index <= 0:
            return None

        # Todo: read this from the file header.
        block_size = 512

        self._seek(index * block_size)
        memo_header = DB4MemoHeader.read(self.file)
        data = self._read(memo_header.length)
        # Todo: fields are terminated in different ways.
        # \x1a is one of them
        # \x1f seems to be another (dbase_8b.dbt)
        return data.split(b'\x1f', 1)[0]


def find_memofile(dbf_filename):
    for ext in ['.fpt', '.dbt']:

        name = ifind(dbf_filename, ext=ext)