Commit Graph

40620 Commits

Author SHA1 Message Date
Jonas Maebe
df6a2dce00 + unicodestring support for assign/erase/rename
+ codepage support for textrec/filerec and the above routines
  * textrec/filerec now store the filename by default using widechar. It is
    possible to switch back to ansichars using the FPC_ANSI_TEXTFILEREC define.
    In that case, from now on the filename will always be stored in
    DefaultFileSystemEncoding
  * fixed potential buffer overflows and non-null-terminated file names in
    textrec/filerec
  + dodirseparators(pwidechar), changed the dodirseparators(pchar/pwidechar)
    parameters into var-parameters and gave those routines an extra parameter
    that indicates whether the p(wide)char can be changed in place if
    necessary or whether a copy must be made first (avoids us having to make
    all strings always unique everywhere, because they might be changed on
    some platforms via a pchar)
  * do_open/do_erase/do_rename got extra boolean parameters indicating whether
    the passed pchars point to data that can be freely changed (to pass on to
    dodirseparators() if applicable)
  * objects.pp: force assign(pchar) to be called, because
    assign(array[0..255]) cannot choose between pchar and rawbytestring
    versions (and removing the pchar version means that assign(pchar) will
    be mapped to assign(shortstring) in {$h-})
  * fixed up some routines in other units that depend on the format of
    the textrec/filerec.name field

git-svn-id: branches/cpstrrtl@25137 -
2013-07-19 16:30:51 +00:00
Jonas Maebe
d676bbf9af * the filerec.name field is 0-based, not 1-based -> to check for an empty
file name, check character 0

git-svn-id: branches/cpstrrtl@25136 -
2013-07-19 16:29:59 +00:00
Jonas Maebe
a00828e3e2 * fixed buffer overrun in SysPCharToNtStr
git-svn-id: branches/cpstrrtl@25135 -
2013-07-19 16:29:32 +00:00
Jonas Maebe
953e088c14 + unicodestring support for POpen(), and DefaultFileSystemCodePage support
for POpen(RawByteString)

git-svn-id: branches/cpstrrtl@25134 -
2013-07-19 16:29:13 +00:00
Jonas Maebe
8538f48fda * made the ansistring parameters of the fp*() overloads constant, changed
them to rawbytestring and added DefaultFileSystemCodePage conversions

git-svn-id: branches/cpstrrtl@25133 -
2013-07-19 16:28:49 +00:00
Jonas Maebe
e132a77709 - reverted optimisation from r24962, it's already performed in SetCodePage()
git-svn-id: branches/cpstrrtl@25132 -
2013-07-19 16:28:27 +00:00
Jonas Maebe
155aafc255 * moved SYSUTILS_HAS_ANSISTR/UNICODESTR_FILEUTIL_IMPL define to interface
so declarations can also depend on it and similar defines (not yet the
    case)
  + added SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL/SYSUTILS_HAS_UNICODESTR_ENVVAR_IMPL
    to indicate whether the platform-dependent part of the unit provides
    an ansistring/unicodestring interface to get environment variables
  + Windows version of getenvironmentvariable(unicodestring)
  + generic ansistring/unicodestring versions of GetEnvironmentVariable()
    in case the platform doesn't provide them
  * result of GetEnvironmentString() is ansistring/unicodestring depending
    on the state of the FPC_RTL_UNICODE define

git-svn-id: branches/cpstrrtl@25116 -
2013-07-16 14:16:34 +00:00
Jonas Maebe
09014e8716 * missing SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL define for wii
* string -> rawbytestring for SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL routines

git-svn-id: branches/cpstrrtl@25115 -
2013-07-16 14:16:21 +00:00
Jonas Maebe
a0f2d3c12f * don't compile classes for wii, because sysutils doesn't contain a sleep()
which is now required for classes (and neither compile fmtbcd, because it
    depends on classes)
  * fixed stray "\" that caused the implicit units to be parsed wrongly

git-svn-id: branches/cpstrrtl@25114 -
2013-07-16 14:16:10 +00:00
Jonas Maebe
eeb98a0c0f - removed platform-specific implementations of GetCurrentDir, SetCurrentDir,
CreateDir and RemoveDir, and implemented a generic one (based on the OS/2
    version) in the shared sysutils code (so that the filesystem code page
    support for the system unit routines can be reused)
  * include both ansistring and unicodestring versions of the above routines,
    and of ForceDirectories. Exception: GetCurrentDir, which cannot be
    overloaded based on function result and whose return type currently
    dependends on the FPC_UNICODE_RTL define

git-svn-id: branches/cpstrrtl@25113 -
2013-07-16 14:15:55 +00:00
Jonas Maebe
06d9b35ed3 * don't truncate the result of GetEnvironmentVariable to 255 characters
git-svn-id: branches/cpstrrtl@25105 -
2013-07-15 09:21:51 +00:00
Jonas Maebe
42be54a00f * fixed codepage of result of GetEnvironmentVariable(ansistring)
* don't uppercase the name of the environment variable we are looking for
    in every loop iteration

git-svn-id: branches/cpstrrtl@25104 -
2013-07-15 09:21:35 +00:00
Jonas Maebe
8b77f62873 * don't truncate environment variable strings in GetEnvironmentString()
* set the correct code page for the result of GetEnvironmentString() on
    Windows and NativeNT

git-svn-id: branches/cpstrrtl@25103 -
2013-07-15 09:21:20 +00:00
Jonas Maebe
08099c8558 * explicitly call *A routines from ansistring environment variable routines
git-svn-id: branches/cpstrrtl@25102 -
2013-07-15 09:21:03 +00:00
Jonas Maebe
d919794fdf * handle the fact that GetEnvironmentStringsA returns the environment in the
OEM instead of in the Ansi code page (mantis #22524, #15233)

git-svn-id: branches/cpstrrtl@25092 -
2013-07-12 17:18:28 +00:00
Jonas Maebe
a5273abc9c + support for CP_OEMCP
* changed all mappings from CP_ACP to DefaultSystemCodePage to calls to the
    new TranslatePlaceholderCP() routine (which also handles CP_OEMCP)
  * removed unnecessary CP_ACP adaptations in fpc_AnsiStr_Concat_multi()
    for JVM target (now handled in the ansistring to unicodestring conversion
    routine)

git-svn-id: branches/cpstrrtl@25091 -
2013-07-12 17:18:24 +00:00
Jonas Maebe
44f4bdfb2e - removed stray stringcodepage assignment in fpc_AnsiStr_Concat_multi()
git-svn-id: branches/cpstrrtl@25090 -
2013-07-12 17:18:20 +00:00
Jonas Maebe
0ef0206417 * fixed off-by-one error in the optimised rawbytestring/unicodestring
dodirseparators() routines + added test (only testable under Windows)

git-svn-id: branches/cpstrrtl@25089 -
2013-07-12 17:18:16 +00:00
Jonas Maebe
ba49e4a29d * fixed do_getdir() for non-defaultdrive after r25042 ("drive" array has to
be an array of widechar now)
  * fixed restoring of original path in do_getdir() (pass contents of
    unicodestring to SetCurrentDirectoryW(), not its address)

git-svn-id: branches/cpstrrtl@25088 -
2013-07-12 17:18:11 +00:00
Jonas Maebe
26b2149ced * converted the following sysutils routines to unicodestring and
rawbytestring: FileExists, DirectoryExists, FileSetDate, FileGetAttr,
    FileSetAttr, DeleteFile, RenameFile, FileSearch, ExeSearch,
    FileIsReadOnly

git-svn-id: branches/cpstrrtl@25078 -
2013-07-09 19:01:45 +00:00
Jonas Maebe
c0d2ebb682 * export PathConv(RawByteString) from the system unit and import/use it in
the sysutils unit instead of the ShortString version

git-svn-id: branches/cpstrrtl@25077 -
2013-07-09 19:01:40 +00:00
Jonas Maebe
60365489e2 * converted fileopen/filecreate interface to RawByteString for
msdos/embedded, but do not perform any code page conversions
    (size limits prevent widestring manager on msdos, and the
     embedded routines are empty)

git-svn-id: branches/cpstrrtl@25076 -
2013-07-09 19:01:36 +00:00
Jonas Maebe
93bd1dd12a * factored out ToSingleByteFileSystemEncodedFileName() calls for fileopen/
filecreate and ensure the result gets passed to a rawbytestring parameter

git-svn-id: branches/cpstrrtl@25075 -
2013-07-09 19:01:32 +00:00
Jonas Maebe
00ce3c1f52 * converted nativent sysutils routines to accept unicodestring instead
of rawbytestring and indicate that this platform now uses a two-byte
    file system API for the sysutils unit

git-svn-id: branches/cpstrrtl@25074 -
2013-07-09 19:01:28 +00:00
Jonas Maebe
c604e5af17 * small reorganisation of ansistring/unicodestring routine declarations, so
they are the same as in the unicode branch (to more easily apply patches)

git-svn-id: branches/cpstrrtl@25073 -
2013-07-09 19:01:24 +00:00
Jonas Maebe
b1c10cff02 * actually use the filename converted to the file system codepage in
FileCreate()

git-svn-id: branches/cpstrrtl@25072 -
2013-07-09 19:01:21 +00:00
Jonas Maebe
d66d15aad3 + added mkdir/chdir/rmdir(rawbytestring) and (unicodestring) to the system unit
* renamed platform-specific pchar versions of those rouines to do_*() and
    changed them to either rawbytestring or unicodestring depending on the
    FPCRTL_FILESYSTEM_SINGLE_BYTE_API/FPCRTL_FILESYSTEM_TWO_BYTE_API setting
  * implemented generic shortstring versions of those routines on top of either
    rawbytestring or unicodestring depending on the API-kind (in case of the
    embedded target, if ansistring are not supported they will map directly
    to shortstring routines instead)
  * all platform-specific *dir() routines with rawbytestring parameters now
    receive their parameters in DefaultFileSystemCodePage
  - removed no longer required ansistring variants from the objpas unit
  - removed no longer required FPC_SYS_MKDIR etc aliases
  * factored out empty string and inoutres<>0 checks from platform-specific
    *dir() routines to generic ones
  o platform-specific notes:
   o amiga/morphos: check new pathconv(rawbytestring) function
   o macos TODO: convert PathArgToFSSpec (and the routines it calls) to
     rawbytestring
   o nativent: added SysUnicodeStringToNtStr() function
   o wii: convert dirio callbacks to use rawbytestring to avoid conversion
  + test for unicode mk/ch/rm/getdir()

git-svn-id: branches/cpstrrtl@25048 -
2013-07-04 22:28:37 +00:00
Jonas Maebe
e26210f448 * fixed wii compilation after r24993
git-svn-id: branches/cpstrrtl@25047 -
2013-07-04 22:28:31 +00:00
Jonas Maebe
893a9a57c6 * missing getdir -> do_getdir rename for r24993
git-svn-id: branches/cpstrrtl@25046 -
2013-07-04 22:28:27 +00:00
Jonas Maebe
ab9036ecbf + missing unicodestring version of ExpandUNCFileName
* make ansistring version of ExpandUNCFileName call the unicodestring version

git-svn-id: branches/cpstrrtl@25045 -
2013-07-04 22:28:24 +00:00
Jonas Maebe
8368f7dba5 * call unicodestring version of ExpandUNCFileName from ansistring version
instead of infinitely recursing into the ansistring version

git-svn-id: branches/cpstrrtl@25044 -
2013-07-04 22:28:20 +00:00
Jonas Maebe
3ba39f8e71 * fixed building after cpall unit addition
git-svn-id: branches/cpstrrtl@25043 -
2013-07-04 22:28:17 +00:00
Jonas Maebe
08ab4dcabe * convert calls to GetCurrentDirectory to *W in Windows do_getdir()
git-svn-id: branches/cpstrrtl@25042 -
2013-07-04 22:28:13 +00:00
Jonas Maebe
6dbcb7db80 + rawbytestring version of PathConv()
git-svn-id: branches/cpstrrtl@25041 -
2013-07-04 22:28:09 +00:00
Jonas Maebe
fd0a2ac365 + SysUnicodeStringToNtStr() helper
git-svn-id: branches/cpstrrtl@25040 -
2013-07-04 22:28:05 +00:00
Jonas Maebe
2e9b642a3b * rtldefs.inc include file for embedded targets (forgot to commit earlier)
git-svn-id: branches/cpstrrtl@25009 -
2013-06-28 15:46:31 +00:00
Jonas Maebe
5ed4e99dc1 + uppercase/lowercase(unicodestring) (fixes a warning in fina.inc when
compiled with unicodestring)
  * changed uppercase/lowercase(ansistring) to use the same logic as the
    new unicode versions (unify code for lower/upper, only make result
    unique if necessary)
  + test for all four routines

git-svn-id: branches/cpstrrtl@25006 -
2013-06-28 12:46:25 +00:00
Jonas Maebe
bae3c0296e * fixed result type of StrBufSize(PWideChar) for 64 bit targets
git-svn-id: branches/cpstrrtl@25002 -
2013-06-28 08:41:46 +00:00
Jonas Maebe
8a4b092ab9 * made ToSingleByteFileSystemEncodedFileName(unicodestring) overridable by
target-specific code and implemented a JVM-compatible version

git-svn-id: branches/cpstrrtl@25001 -
2013-06-27 21:38:17 +00:00
Jonas Maebe
1da05d1553 * declared CharInSet(ansichar,tsyscharset) as inline
* moved the inclusion of sysansi.inc to before the inclusion of all other
    sysutils include files so the inline body of CharInSet is available

git-svn-id: branches/cpstrrtl@25000 -
2013-06-27 21:38:13 +00:00
Jonas Maebe
b08d8091b2 * made fexpand unicodestring-safe (use charinset instead of "in" --
"widechar in set" compiles, but results in a runtime conversion of
    the widechar into an ansistring and then getting the first character
    of that ansistring, which is horribly slow -- and Delphi-incompatible,
    but introduced a long time ago because of bug #7758)
  * replaced all "in" operations in sysutils fina.inc with CharInSet for
    the same reason
  * replaced all "string" declarations in finah.inc/fina.inc with "PathStr"
    and "pchar" with "PathPChar", and include them twice in sysutilh.inc/
    sysutils.inc, once with PathStr=UnicodeString/PathPChar=PWideChar and
    once with PathStr=AnsiString/PathPChar=PAnsiChar (not rawbytestring
    because there are several routines with var-parameters and then the
    string type has to match exactly; the "rtlproc" modifier could circumvent
    this, but should be used sparingly, and additionally the routine's
    internals would then first also have to be reviewed to ensure that at
    no point they start mixing in strings with the defaultsystemcodepage
    (e.g. directory separators) without first adjusting their codepage)
  * call GetShortPathNameA or GetShortPathNameW in ExtractShortPathName on
    Windows depending on whether we are parsing the RawByteString/UnicodeString
    version of fina.inc
  + ExpandUNCFileName(unicode) version for Windows, let its
    ExpandUNCFileName(ansistring) call the unicode version (avoid data loss
    due to ansi conversion) and convert the result to
    DefaultRTLFileSystemCodePage (to have no more data loss than what's
    specified by the user)

git-svn-id: branches/cpstrrtl@24999 -
2013-06-27 21:38:10 +00:00
Jonas Maebe
746546ed09 + remaining missing pwidechar overloads/equivalents of pchar functions
(strecopy, strend, strcat, strcomp, strlcomp, stricomp, strlcat, strrscan,
     strlower, strupper, strlicomp, strpos, WideStrAlloc, StrBufSize,
     StrDispose)
  * adjusted pwidechar version of strnew to call WideStrAlloc instead of
    StrAlloc
  + tests for several newly added sysutils pwidechar routines based on
    existing tests for equivalent pchar routines
  * converted several sysutils ansistr*() function tests to tests for str*
    functions

git-svn-id: branches/cpstrrtl@24998 -
2013-06-27 21:38:06 +00:00
Jonas Maebe
eb93429cf0 * prefer "constant string" -> pwidechar for {$modeswitch unicodestrings}
* prefer "constant char" -> pchar to "constant char" -> pwidechar, and
    "constant widechar" -> pwidechar to "constant widechar" -> pchar

git-svn-id: branches/cpstrrtl@24997 -
2013-06-27 21:38:02 +00:00
Jonas Maebe
c49ae76837 * let StrBufSize return a cardinal rather than a sizeuint, and also change
its internal pointer arithmetic to use cardinal, because that's also what
    stralloc uses to initialize that value

git-svn-id: branches/cpstrrtl@24996 -
2013-06-27 21:37:58 +00:00
Jonas Maebe
8f1e85d9ae * moved SameFileName from finah.inc to sysansih.inc, since the implementation
is in sysansi.inc

git-svn-id: branches/cpstrrtl@24995 -
2013-06-27 21:37:55 +00:00
Jonas Maebe
95a877c7e5 * moved GetFileHandle() from fina.inc to filutil.inc because fina.inc
will be included twice using different string types (and those two
    routines don't have a string argument, so this would result in duplicate
    definitions), and their declaration is in filutilh.inc rather than
    finah.inc anyway
  * ensure that the fina.inc "MaxDirs" constant gets declared only once
  * ensure that the finah.inc "TFilenameCaseMatch" type gets declared only
    once

git-svn-id: branches/cpstrrtl@24994 -
2013-06-27 21:37:51 +00:00
Jonas Maebe
62ee16278b * changed getdir(ansistring):ansistring to
getdir(rawbytestring):rawbytestring so it can accept strings in any
    encoding and cleanly return results in DefaultRTLFileSystemCodePage
  + getdir(unicodestring):unicodestring
  * renamed the getdir implementation of all platforms except for embedded-
    without-ansistring-support to do_getdir(), and depending on the
    FPCRTL_FILESYSTEM_SINGLE_BYTE_API/FPCRTL_FILESYSTEM_TWO_BYTE_API define
    changed its shortstring parameter to ansistring or unicodestring. The
    do_getdir(rawbytestring) routine should just set the code page of the
    return value to DefaultFileSystemCodePage without conversion (not
    DefaultRTLFileSystemCodePage with conversion, that conversion is performed
    in getdir if necessary; this avoids double conversions in case
    getdir(unicodestring) is called)
  + generic getdir(shortstring) for platforms supporting either ansistrings or widestrings
  o platform maintainers:
   o OS/2: adjust code to supports paths > 255 characters if those are supported
   o Wii: adjust used callback to use rawbytestring to support paths > 255 characters and
     avoid shortstring->rawbytestring conversion overhead
   o Windows: GetCurrentDirectoryW is now always used (to prevent data loss)

git-svn-id: branches/cpstrrtl@24993 -
2013-06-27 21:37:47 +00:00
Jonas Maebe
679785f90c + rawbytestring and unicodestring versions of DoDirSeparators (optimised to
prevent calling uniquestring multiple times)

git-svn-id: branches/cpstrrtl@24992 -
2013-06-27 21:37:43 +00:00
Jonas Maebe
da7a67bc74 + FPCRTL_FILESYSTEM_SINGLE_BYTE_API define that is set for targets where we
use a single byte API for file system operations
  + FPCRTL_FILESYSTEM_TWO_BYTE_API define that is set for targets where we
    use a single byte API for file system operations
   o in principle, both can be set if both are supprted and implemented in
     the RTL in order to minimise conversions depending on the scenario

git-svn-id: branches/cpstrrtl@24991 -
2013-06-27 21:37:39 +00:00
Jonas Maebe
7659bfc01b - removed internal error if savesize of tfiledef is 0 when writing the def
to the ppu file, because it does not exist on the JVM platform and
    hence will be 0 (and on other platforms, you'll get a fatal error earlier
    in case the filerec type cannot be found) (originally added as part of
    r24957)

git-svn-id: branches/cpstrrtl@24990 -
2013-06-27 21:37:32 +00:00