(self, native_path, dos_name, defext, isdir, create)
Find or create a matching native file name for a given BASIC name.
Find or create a matching native file name for a given BASIC name.
Find or create a matching native file name for a given BASIC name .
def _get_native_name(self, native_path, dos_name, defext, isdir, create):
        """Find or create a matching native file name for a given BASIC name."""
        # if the name contains a dot, do not apply the default extension
        # to maintain GW-BASIC compatibility, a trailing single dot matches the name
        # with no dots as well as the name with a single dot.
        # file names with more than one dot are not affected.
        # file spec         attempted matches
        # LongFileName      (1) LongFileName.BAS (2) LONGFILE.BAS
        # LongFileName.bas  (1) LongFileName.bas (2) LONGFILE.BAS
        # LongFileName.     (1) LongFileName. (2) LongFileName (3) LONGFILE
        # LongFileName..    (1) LongFileName.. (2) [does not try LONGFILE.. - not allowable]
        # Long.FileName.    (1) Long.FileName. (2) LONG.FIL
        #
        # don't accept leading whitespace (internal whitespace should be preserved)
        # note that DosBox removes internal whitespace, but MS-DOS does not
        name_err = error.PATH_NOT_FOUND if isdir else error.FILE_NOT_FOUND
        if dos_name != dos_name.lstrip():
            raise error.BASICError(name_err)
        dos_name = self._get_dos_name_defext(dos_name, defext)
        if dos_name[-1:] == b'.' and b'.' not in dos_name[:-1]:
            # ends in single dot; first try with dot
            # but if it doesn't exist, base everything off dotless name
            uni_name = self._codepage.bytes_to_unicode(dos_name, box_protect=False)
            if istype(native_path, uni_name, isdir):
                return uni_name
            dos_name = dos_name[:-1]
        # check if the name exists as-is; should also match Windows short names.
        uni_name = self._codepage.bytes_to_unicode(dos_name, box_protect=False)
        if istype(native_path, uni_name, isdir):
            return uni_name
        # original name does not exist; try matching dos-names or create one
        # normalise to 8.3
        norm_name = dos_normalise_name(dos_name)
        # check for non-legal characters & spaces (but clip off overlong names)
        if not dos_is_legal_name(norm_name):
            raise error.BASICError(error.BAD_FILE_NAME)
        fullname = dos_to_native_name(native_path, norm_name, isdir)
        if fullname:
            return fullname
        # not found
        if create:
            # create a new filename
            # we should have only ascii due to dos_is_legal_name check above
            return norm_name.decode('ascii', errors='replace')
        else:
            raise error.BASICError(name_err)
def _get_native_name ( self , native_path , dos_name , defext , isdir , create ) : # if the name contains a dot, do not apply the default extension # to maintain GW-BASIC compatibility, a trailing single dot matches the name # with no dots as well as the name with a single dot. # file names with more than one dot are not affected. # file spec         attempted matches # LongFileName      (1) LongFileName.BAS (2) LONGFILE.BAS # LongFileName.bas  (1) LongFileName.bas (2) LONGFILE.BAS # LongFileName.     (1) LongFileName. (2) LongFileName (3) LONGFILE # LongFileName..    (1) LongFileName.. (2) [does not try LONGFILE.. - not allowable] # Long.FileName.    (1) Long.FileName. (2) LONG.FIL # # don't accept leading whitespace (internal whitespace should be preserved) # note that DosBox removes internal whitespace, but MS-DOS does not name_err = error . PATH_NOT_FOUND if isdir else error . FILE_NOT_FOUND if dos_name != dos_name . lstrip ( ) : raise error . BASICError ( name_err ) dos_name = self . _get_dos_name_defext ( dos_name , defext ) if dos_name [ - 1 : ] == b'.' and b'.' not in dos_name [ : - 1 ] : # ends in single dot; first try with dot # but if it doesn't exist, base everything off dotless name uni_name = self . _codepage . bytes_to_unicode ( dos_name , box_protect = False ) if istype ( native_path , uni_name , isdir ) : return uni_name dos_name = dos_name [ : - 1 ] # check if the name exists as-is; should also match Windows short names. uni_name = self . _codepage . bytes_to_unicode ( dos_name , box_protect = False ) if istype ( native_path , uni_name , isdir ) : return uni_name # original name does not exist; try matching dos-names or create one # normalise to 8.3 norm_name = dos_normalise_name ( dos_name ) # check for non-legal characters & spaces (but clip off overlong names) if not dos_is_legal_name ( norm_name ) : raise error . BASICError ( error . BAD_FILE_NAME ) fullname = dos_to_native_name ( native_path , norm_name , isdir ) if fullname : return fullname # not found if create : # create a new filename # we should have only ascii due to dos_is_legal_name check above return norm_name . decode ( 'ascii' , errors = 'replace' ) else : raise error . BASICError ( name_err )