From 2ea76d70ea86a4b7256ad13855562cbb81ced7a9 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Tue, 5 Jul 2016 22:19:49 -0400 Subject: [PATCH] Create osd_is_valid_filename_char() and osd_is_valid_filepath_char() functions to check to see if a character is legal, and moved retired is_valid_filename_char() in filecreate.cpp. POSIX versions not implemented yet. --- src/frontend/mame/ui/filecreate.cpp | 25 +--------------------- src/osd/modules/file/winfile.cpp | 33 +++++++++++++++++++++++++++++ src/osd/osdcomm.h | 5 +++++ src/osd/osdcore.h | 31 ++++++++++++++++++++++++++- 4 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/frontend/mame/ui/filecreate.cpp b/src/frontend/mame/ui/filecreate.cpp index 7d1a91b8c5c..7ea9fc53173 100644 --- a/src/frontend/mame/ui/filecreate.cpp +++ b/src/frontend/mame/ui/filecreate.cpp @@ -135,29 +135,6 @@ void menu_confirm_save_as::handle() FILE CREATE MENU ***************************************************************************/ -//------------------------------------------------- -// is_valid_filename_char - tests to see if a -// character is valid in a filename -//------------------------------------------------- - -static int is_valid_filename_char(unicode_char unichar) -{ - // this should really be in the OSD layer, and it shouldn't be 7-bit bullshit - static const char valid_filename_char[] = - { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00-0f - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10-1f - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, // !"#$%&'()*+,-./ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 0123456789:;<=>? - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // @ABCDEFGHIJKLMNO - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // PQRSTUVWXYZ[\]^_ - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // `abcdefghijklmno - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, // pqrstuvwxyz{|}~ - }; - return (unichar < ARRAY_LENGTH(valid_filename_char)) && valid_filename_char[unichar]; -} - - //------------------------------------------------- // ctor //------------------------------------------------- @@ -271,7 +248,7 @@ void menu_file_create::handle() case IPT_SPECIAL: if (get_selection() == ITEMREF_NEW_IMAGE_NAME) { - input_character(m_filename, event->unichar, &is_valid_filename_char); + input_character(m_filename, event->unichar, &osd_is_valid_filename_char); reset(reset_options::REMEMBER_POSITION); } break; diff --git a/src/osd/modules/file/winfile.cpp b/src/osd/modules/file/winfile.cpp index c304259b915..a8924c59229 100644 --- a/src/osd/modules/file/winfile.cpp +++ b/src/osd/modules/file/winfile.cpp @@ -14,6 +14,7 @@ #include "strconv.h" #include "winutil.h" #include "winutf8.h" +#include "unicode.h" // MAME headers #include "osdcore.h" @@ -465,6 +466,38 @@ const char *osd_get_volume_name(int idx) +//============================================================ +// osd_is_valid_filename_char +//============================================================ + +bool osd_is_valid_filename_char(unicode_char uchar) +{ + return osd_is_valid_filepath_char(uchar) + && uchar != '/' + && uchar != '\\' + && uchar != ':'; +} + + + +//============================================================ +// osd_is_valid_filepath_char +//============================================================ + +bool osd_is_valid_filepath_char(unicode_char uchar) +{ + return uchar >= 0x20 + && uchar != '<' + && uchar != '>' + && uchar != '\"' + && uchar != '|' + && uchar != '?' + && uchar != '*' + && uchar_isvalid(uchar); +} + + + //============================================================ // win_error_to_file_error //============================================================ diff --git a/src/osd/osdcomm.h b/src/osd/osdcomm.h index ff8ca667713..c6c15d0df2a 100644 --- a/src/osd/osdcomm.h +++ b/src/osd/osdcomm.h @@ -85,6 +85,11 @@ using INT64 = std::int64_t; /* pointer-sized values */ using FPTR = uintptr_t; +/* unicode types */ +using utf16_char = std::uint16_t; +using unicode_char = std::uint32_t; + + /*************************************************************************** diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h index a224fb7059c..7b12a51422c 100644 --- a/src/osd/osdcore.h +++ b/src/osd/osdcore.h @@ -290,9 +290,38 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN The number of characters required to form a Unicode character. -----------------------------------------------------------------------------*/ -int osd_uchar_from_osdchar(UINT32 /* unicode_char */ *uchar, const char *osdchar, size_t count); +int osd_uchar_from_osdchar(unicode_char *uchar, const char *osdchar, size_t count); +/*----------------------------------------------------------------------------- + osd_is_valid_filename_char: is the given character legal for filenames? + + Parameters: + + uchar - the character to check + + Return value: + + Whether this character is legal in a filename +-----------------------------------------------------------------------------*/ + +bool osd_is_valid_filename_char(unicode_char uchar); + + +/*----------------------------------------------------------------------------- + osd_is_valid_filepath_char: is the given character legal for paths? + + Parameters: + + uchar - the character to check + + Return value: + + Whether this character is legal in a file path +-----------------------------------------------------------------------------*/ + +bool osd_is_valid_filepath_char(unicode_char uchar); + /*************************************************************************** DIRECTORY INTERFACES