J. David Bryan wrote:
My second question then is, would it be reasonable to change the routine declarations in gpc units so that an EP program can call them? Currently, routine declarations with multiple string parameters are usually constructed as in these examples:
function Pos (const SubString, s: String): Integer; function LastPos (const SubString, s: String): Integer; function PosCase (const SubString, s: String): Integer;
The EP rule requires the string parameter lengths to be identical, so, e.g.,
LastPos ('/', SomeVar)
...fails unless SomeVar is exactly one character in length. The above would be allowed if the declaration was:
function LastPos (const SubString: String const s: String): Integer;
...I believe.
-- Dave
Yes, we forgot about this problem. The following implements the change:
Index: fname.pas =================================================================== RCS file: /mn/a8/cvsroot/gpc/p/rts/fname.pas,v retrieving revision 1.2 diff -u -r1.2 fname.pas --- fname.pas 4 Feb 2006 05:59:21 -0000 1.2 +++ gpc-20060325/p/rts/fname.pas 22 Jul 2006 20:48:49 -0000 @@ -236,14 +236,14 @@ otherwise returns an empty string. If aFileName already contains an element of DirSeparators, returns Slash2OSDirSeparator (aFileName) if it exists. } -function FSearch (const aFileName, DirList: String): TString; attribute (name = '_p_FSearch'); +function FSearch (const aFileName: String; const DirList: String): TString; attribute (name = '_p_FSearch');
{ Like FSearch, but only find executable files. Under Dos, if not found, the function tries appending '.com', '.exe', '.bat' and `.cmd' (the last one only if $COMSPEC points to a `cmd.exe'), so you don't have to specify these extensions in aFileName (and with respect to portability, it might be preferable not to do so). } -function FSearchExecutable (const aFileName, DirList: String) = Result: TString; attribute (name = '_p_FSearchExecutable'); +function FSearchExecutable (const aFileName: String; const DirList: String) = Result: TString; attribute (name = '_p_FSearchExecutable');
{ Replaces all occurrences of `$FOO' and `~' in s by the value of the environment variables FOO or HOME, respectively. If a variable @@ -281,7 +281,7 @@
{ Splits a file name into directory, name and extension. Each of Dir, BaseName and Ext may be Null. } -procedure FSplit (const Path: String; var Dir, BaseName, Ext: String); attribute (name = '_p_FSplit'); +procedure FSplit (const Path: String; var Dir: String; var BaseName: String; var Ext: String); attribute (name = '_p_FSplit');
{ Functions that extract one or two of the parts from FSplit. DirFromPath returns DirSelf + DirSeparator if the path contains no @@ -310,7 +310,7 @@
{ Returns the first occurence of SubString in s that is not quoted at the beginning, or 0 if no such occurence exists. } -function FindNonQuotedStr (const SubString, s: String; From: Integer): Integer; attribute (name = '_p_FindNonQuotedStr'); +function FindNonQuotedStr (const SubString: String; const s: String; From: Integer): Integer; attribute (name = '_p_FindNonQuotedStr');
{ Does a string contain non-quoted wildcard characters? } function HasWildCards (const s: String): Boolean; attribute (name = '_p_HasWildCards'); @@ -337,10 +337,10 @@ procedure DisposePPStrings (Strings: PPStrings); attribute (name = '_p_DisposePPStrings');
{ Tests if a file name matches a shell wildcard pattern (?, *, []) } -function FileNameMatch (const Pattern, FileName: String): Boolean; attribute (name = '_p_FileNameMatch'); +function FileNameMatch (const Pattern: String; const FileName: String): Boolean; attribute (name = '_p_FileNameMatch');
{ FileNameMatch with BraceExpand } -function MultiFileNameMatch (const Pattern, FileName: String): Boolean; attribute (name = '_p_MultiFileNameMatch'); +function MultiFileNameMatch (const Pattern: String; const FileName: String): Boolean; attribute (name = '_p_MultiFileNameMatch');
{ File name globbing } { GlobInit is implied by Glob and MultiGlob, not by GlobOn and @@ -458,7 +458,7 @@ HOME is not. However, it is easy for users to set it if they want their config files in a certain directory rather than with the executables. } -function ConfigFileName (const Prefix, BaseName: String; Global: Boolean): TString; attribute (name = '_p_ConfigFileName'); +function ConfigFileName (const Prefix: String; const BaseName: String; Global: Boolean): TString; attribute (name = '_p_ConfigFileName');
{ Returns a directory name suitable for global, machine-independent data. The function garantees that the name returned ends with a @@ -479,7 +479,7 @@
About the symbols used above, and the two possibilities under Dos, see the comments for ConfigFileName. } -function DataDirectoryName (const Prefix, BaseName: String): TString; attribute (name = '_p_DataDirectoryName'); +function DataDirectoryName (const Prefix: String; const BaseName: String): TString; attribute (name = '_p_DataDirectoryName');
{ Executes a command line. Reports execution errors via the IOResult mechanism and returns the exit status of the executed program. @@ -740,12 +740,12 @@ Res := '' end;
-function FSearch (const aFileName, DirList: String): TString; +function FSearch (const aFileName: String; const DirList: String): TString; begin FSearch := InternalFSearch (aFileName, DirList, False) end;
-function FSearchExecutable (const aFileName, DirList: String) = Result: TString; +function FSearchExecutable (const aFileName: String; const DirList: String) = Result: TString; begin Result := InternalFSearch (aFileName, DirList, True); {$ifdef __OS_DOS__} @@ -903,7 +903,7 @@ {$endif} end;
-procedure FSplit (const Path: String; var Dir, BaseName, Ext: String); +procedure FSplit (const Path: String; var Dir: String; var BaseName: String; var Ext: String); var d, e: Integer; p, t: TString; @@ -976,7 +976,7 @@ if i > Length (s) then FindNonQuotedChar := 0 else FindNonQuotedChar := i end;
-function FindNonQuotedStr (const SubString, s: String; From: Integer): Integer; +function FindNonQuotedStr (const SubString: String; const s: String; From: Integer): Integer; var i, n: Integer; begin i := From; @@ -1185,7 +1185,7 @@ FNMatch2 := zn > Length (FileName) end;
-function FileNameMatch (const Pattern, FileName: String): Boolean; +function FileNameMatch (const Pattern: String; const FileName: String): Boolean; begin { DJGPP's fnmatch(), e.g., doesn't exclude dot files from `*...' patterns. } if (FileName <> '') and (FileName[1] = '.') and (Pattern <> '') and (Pattern[1] in ['*', '?']) then @@ -1200,7 +1200,7 @@ {$endif} end;
-function MultiFileNameMatch (const Pattern, FileName: String): Boolean; +function MultiFileNameMatch (const Pattern: String; const FileName: String): Boolean; var s: PPStrings; i: Integer; @@ -1463,7 +1463,7 @@ end; {$endif}
-function ConfigFileName (const Prefix, BaseName: String; Global: Boolean): TString; +function ConfigFileName (const Prefix: String; const BaseName: String; Global: Boolean): TString; var PName: TString; begin {$ifdef __OS_DOS__} @@ -1488,7 +1488,7 @@ {$endif} end;
-function DataDirectoryName (const Prefix, BaseName: String): TString; +function DataDirectoryName (const Prefix: String; const BaseName: String): TString; var RealPrefix, PName: TString; begin RealPrefix := Prefix; Index: string1.pas =================================================================== RCS file: /mn/a8/cvsroot/gpc/p/rts/string1.pas,v retrieving revision 1.4 diff -u -r1.4 string1.pas --- string1.pas 4 Feb 2006 05:59:21 -0000 1.4 +++ gpc-20060325/p/rts/string1.pas 22 Jul 2006 20:37:24 -0000 @@ -83,27 +83,27 @@ function UpCaseStr (const s: String) = Result: TString; attribute (name = '_p_UpCaseStr'); function LoCaseStr (const s: String) = Result: TString; attribute (name = '_p_LoCaseStr');
-function StrEqualCase (const s1, s2: String): Boolean; attribute (name = '_p_StrEqualCase'); +function StrEqualCase (const s1: String; const s2: String): Boolean; attribute (name = '_p_StrEqualCase');
-function Pos (const SubString, s: String): Integer; attribute (name = '_p_Pos'); +function Pos (const SubString: String; const s: String): Integer; attribute (name = '_p_Pos'); function PosChar (const ch: Char; const s: String): Integer; attribute (name = '_p_PosChar'); -function LastPos (const SubString, s: String): Integer; attribute (name = '_p_LastPos'); -function PosCase (const SubString, s: String): Integer; attribute (name = '_p_PosCase'); -function LastPosCase (const SubString, s: String): Integer; attribute (name = '_p_LastPosCase'); +function LastPos (const SubString: String; const s: String): Integer; attribute (name = '_p_LastPos'); +function PosCase (const SubString: String; const s: String): Integer; attribute (name = '_p_PosCase'); +function LastPosCase (const SubString: String; const s: String): Integer; attribute (name = '_p_LastPosCase'); function CharPos (const Chars: CharSet; const s: String): Integer; attribute (name = '_p_CharPos'); function LastCharPos (const Chars: CharSet; const s: String): Integer; attribute (name = '_p_LastCharPos');
-function PosFrom (const SubString, s: String; From: Integer): Integer; attribute (name = '_p_PosFrom'); -function LastPosTill (const SubString, s: String; Till: Integer): Integer; attribute (name = '_p_LastPosTill'); -function PosFromCase (const SubString, s: String; From: Integer): Integer; attribute (name = '_p_PosFromCase'); -function LastPosTillCase (const SubString, s: String; Till: Integer): Integer; attribute (name = '_p_LastPosTillCase'); +function PosFrom (const SubString: String; const s: String; From: Integer): Integer; attribute (name = '_p_PosFrom'); +function LastPosTill (const SubString: String; const s: String; Till: Integer): Integer; attribute (name = '_p_LastPosTill'); +function PosFromCase (const SubString: String; const s: String; From: Integer): Integer; attribute (name = '_p_PosFromCase'); +function LastPosTillCase (const SubString: String; const s: String; Till: Integer): Integer; attribute (name = '_p_LastPosTillCase'); function CharPosFrom (const Chars: CharSet; const s: String; From: Integer): Integer; attribute (name = '_p_CharPosFrom'); function LastCharPosTill (const Chars: CharSet; const s: String; Till: Integer): Integer; attribute (name = '_p_LastCharPosTill');
-function IsPrefix (const Prefix, s: String): Boolean; attribute (name = '_p_IsPrefix'); -function IsSuffix (const Suffix, s: String): Boolean; attribute (name = '_p_IsSuffix'); -function IsPrefixCase (const Prefix, s: String): Boolean; attribute (name = '_p_IsPrefixCase'); -function IsSuffixCase (const Suffix, s: String): Boolean; attribute (name = '_p_IsSuffixCase'); +function IsPrefix (const Prefix: String; const s: String): Boolean; attribute (name = '_p_IsPrefix'); +function IsSuffix (const Suffix: String; const s: String): Boolean; attribute (name = '_p_IsSuffix'); +function IsPrefixCase (const Prefix: String; const s: String): Boolean; attribute (name = '_p_IsPrefixCase'); +function IsSuffixCase (const Suffix: String; const s: String): Boolean; attribute (name = '_p_IsSuffixCase');
function CStringLength (Src: CString): SizeType; attribute (inline, name = '_p_CStringLength'); function CStringEnd (Src: CString): CString; attribute (inline, name = '_p_CStringEnd'); @@ -226,12 +226,12 @@ MemCompCase := True end;
-function StrEqualCase (const s1, s2: String): Boolean; +function StrEqualCase (const s1: String; const s2: String): Boolean; begin StrEqualCase := (Length (s1) = Length (s2)) and ((s1 = '') or MemCompCase (s1[1], s2[1], Length (s1))) end;
-function Pos (const SubString, s: String): Integer; +function Pos (const SubString: String; const s: String): Integer; begin Pos := PosFrom (SubString, s, 1) end; @@ -244,17 +244,17 @@ if i > Length (s) then PosChar := 0 else PosChar := i end;
-function LastPos (const SubString, s: String): Integer; +function LastPos (const SubString: String; const s: String): Integer; begin LastPos := LastPosTill (SubString, s, Length (s)) end;
-function PosCase (const SubString, s: String): Integer; +function PosCase (const SubString: String; const s: String): Integer; begin PosCase := PosFromCase (SubString, s, 1) end;
-function LastPosCase (const SubString, s: String): Integer; +function LastPosCase (const SubString: String; const s: String): Integer; begin LastPosCase := LastPosTillCase (SubString, s, Length (s)) end; @@ -275,7 +275,7 @@ LastCharPos := i end;
-function PosFrom (const SubString, s: String; From: Integer): Integer; +function PosFrom (const SubString: String; const s: String; From: Integer): Integer; var m, i, n: Integer; begin m := Max (1, From); @@ -299,7 +299,7 @@ end end;
-function LastPosTill (const SubString, s: String; Till: Integer): Integer; +function LastPosTill (const SubString: String; const s: String; Till: Integer): Integer; var m, i: Integer; begin m := Max (0, Min (Length (s), Till)); @@ -317,7 +317,7 @@ end end;
-function PosFromCase (const SubString, s: String; From: Integer): Integer; +function PosFromCase (const SubString: String; const s: String; From: Integer): Integer; var m, i, n: Integer; begin m := Max (1, From); @@ -336,7 +336,7 @@ end end;
-function LastPosTillCase (const SubString, s: String; Till: Integer): Integer; +function LastPosTillCase (const SubString: String; const s: String; Till: Integer): Integer; var m, i: Integer; begin m := Max (0, Min (Length (s), Till)); @@ -370,22 +370,22 @@ LastCharPosTill := i end;
-function IsPrefix (const Prefix, s: String): Boolean; +function IsPrefix (const Prefix: String; const s: String): Boolean; begin IsPrefix := (Prefix = '') or ((Length (s) >= Length (Prefix)) and EQ (s[1 .. Length (Prefix)], Prefix)) end;
-function IsSuffix (const Suffix, s: String): Boolean; +function IsSuffix (const Suffix: String; const s: String): Boolean; begin IsSuffix := (Suffix = '') or ((Length (s) >= Length (Suffix)) and EQ (s[Length (s) - Length (Suffix) + 1 .. Length (s)], Suffix)) end;
-function IsPrefixCase (const Prefix, s: String): Boolean; +function IsPrefixCase (const Prefix: String; const s: String): Boolean; begin IsPrefixCase := (Prefix = '') or ((Length (s) >= Length (Prefix)) and StrEqualCase (s[1 .. Length (Prefix)], Prefix)) end;
-function IsSuffixCase (const Suffix, s: String): Boolean; +function IsSuffixCase (const Suffix: String; const s: String): Boolean; begin IsSuffixCase := (Suffix = '') or ((Length (s) >= Length (Suffix)) and StrEqualCase (s[Length (s) - Length (Suffix) + 1 .. Length (s)], Suffix)) end; Index: string2.pas =================================================================== RCS file: /mn/a8/cvsroot/gpc/p/rts/string2.pas,v retrieving revision 1.4 diff -u -r1.4 string2.pas --- string2.pas 24 Apr 2006 02:05:41 -0000 1.4 +++ gpc-20060325/p/rts/string2.pas 22 Jul 2006 20:39:27 -0000 @@ -126,7 +126,7 @@
{ Sets an environment variable with the name given in VarName to the value Value. A previous value, if any, is overwritten. } -procedure SetEnv (const VarName, Value: String); attribute (name = '_p_SetEnv'); +procedure SetEnv (const VarName: String; const Value: String); attribute (name = '_p_SetEnv');
{ Un-sets an environment variable with the name given in VarName. } procedure UnSetEnv (const VarName: String); attribute (name = '_p_UnSetEnv'); @@ -236,7 +236,7 @@ if Temp = nil then GetEnv := '' else GetEnv := CString2String (Temp) end;
-procedure SetEnv (const VarName, Value: String); +procedure SetEnv (const VarName: String; const Value: String); var i: Integer; NewEnvironment: PEnvironment;