Pārlūkot izejas kodu

* use some more string routines from libc if FPC_USE_LIBC is used

Jonas Maebe 21 gadi atpakaļ
vecāks
revīzija
dedf697f3a

+ 30 - 1
rtl/i386/strings.inc

@@ -17,6 +17,7 @@
 
 {$ASMMODE ATT}
 
+{$ifndef FPC_UNIT_HAS_STRCOPY}
 {$define FPC_UNIT_HAS_STRCOPY}
 function strcopy(dest,source : pchar) : pchar;assembler;
 var
@@ -92,8 +93,10 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRCOPY}
 
 
+{$ifndef FPC_UNIT_HAS_STRECOPY}
 {$define FPC_UNIT_HAS_STRECOPY}
 function strecopy(dest,source : pchar) : pchar;assembler;
 var
@@ -124,8 +127,10 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRECOPY}
 
 
+{$ifndef FPC_UNIT_HAS_STRLCOPY}
 {$define FPC_UNIT_HAS_STRLCOPY}
 function strlcopy(dest,source : pchar;maxlen : longint) : pchar;assembler;
 var
@@ -155,13 +160,17 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRLCOPY}
 
 
+{$ifndef FPC_UNIT_HAS_STRLEN}
 {$define FPC_UNIT_HAS_STRLEN}
 function strlen(p : pchar) : longint;assembler;
 {$i strlen.inc}
+{$endif FPC_UNIT_HAS_STRLEN}
 
 
+{$ifndef FPC_UNIT_HAS_STREND}
 {$define FPC_UNIT_HAS_STREND}
 function strend(p : pchar) : pchar;assembler;
 var
@@ -182,9 +191,11 @@ asm
 .LStrEndNil:
         movl    saveedi,%edi
 end;
+{$endif FPC_UNIT_HAS_STREND}
 
 
 
+{$ifndef FPC_UNIT_HAS_STREND}
 {$define FPC_UNIT_HAS_STRCOMP}
 function strcomp(str1,str2 : pchar) : longint;assembler;
 var
@@ -218,9 +229,11 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STREND}
 
 
 
+{$ifndef FPC_UNIT_HAS_STRLCOMP}
 {$define FPC_UNIT_HAS_STRLCOMP}
 function strlcomp(str1,str2 : pchar;l : longint) : longint;assembler;
 var
@@ -263,9 +276,11 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRLCOMP}
 
 
 
+{$ifndef FPC_UNIT_HAS_STRICOMP}
 {$define FPC_UNIT_HAS_STRICOMP}
 function stricomp(str1,str2 : pchar) : longint;assembler;
 var
@@ -315,9 +330,11 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRICOMP}
 
 
 
+{$ifndef FPC_UNIT_HAS_STRLICOMP}
 {$define FPC_UNIT_HAS_STRLICOMP}
 function strlicomp(str1,str2 : pchar;l : longint) : longint;assembler;
 var
@@ -376,9 +393,11 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRLICOMP}
 
 
 
+{$ifndef FPC_UNIT_HAS_STRSCAN}
 {$define FPC_UNIT_HAS_STRSCAN}
 function strscan(p : pchar;c : char) : pchar;assembler;
 var
@@ -504,8 +523,10 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRSCAN}
 
 
+{$ifndef FPC_UNIT_HAS_STRRSCAN}
 {$define FPC_UNIT_HAS_STRRSCAN}
 function strrscan(p : pchar;c : char) : pchar;assembler;
 var
@@ -538,8 +559,10 @@ asm
 .LSTRRSCAN:
         movl    saveedi,%edi
 end;
+{$endif FPC_UNIT_HAS_STRRSCAN}
 
 
+{$ifndef FPC_UNIT_HAS_STRUPPER}
 {$define FPC_UNIT_HAS_STRUPPER}
 function strupper(p : pchar) : pchar;assembler;
 var
@@ -571,8 +594,10 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRUPPER}
 
 
+{$ifndef FPC_UNIT_HAS_STRLOWER}
 {$define FPC_UNIT_HAS_STRLOWER}
 function strlower(p : pchar) : pchar;assembler;
 var
@@ -604,10 +629,14 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRLOWER}
 
 {
   $Log$
-  Revision 1.13  2003-12-19 09:28:00  michael
+  Revision 1.14  2004-05-01 15:26:33  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.13  2003/12/19 09:28:00  michael
   + Patch from Peter to fix strlcomp
 
   Revision 1.12  2003/12/17 21:56:33  peter

+ 8 - 1
rtl/i386/stringss.inc

@@ -16,10 +16,13 @@
  **********************************************************************}
 
 
+{$ifndef FPC_UNIT_HAS_STRPAS}
 {$define FPC_UNIT_HAS_STRPAS}
 function strpas(p : pchar) : string; assembler;
 {$i strpas.inc}
+{$endif FPC_UNIT_HAS_STRPAS}
 
+{$ifndef FPC_UNIT_HAS_STRPCOPY}
 {$define FPC_UNIT_HAS_STRPCOPY}
 function strpcopy(d : pchar;const s : string) : pchar;assembler;
 var
@@ -46,10 +49,14 @@ asm
         movl    saveedi,%edi
         movl    saveesi,%esi
 end;
+{$endif FPC_UNIT_HAS_STRPCOPY}
 
 {
   $Log$
-  Revision 1.11  2003-11-19 16:58:44  peter
+  Revision 1.12  2004-05-01 15:26:33  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.11  2003/11/19 16:58:44  peter
     * make strpas assembler function
 
   Revision 1.10  2003/11/11 21:08:17  peter

+ 19 - 2
rtl/inc/cgeneric.inc

@@ -124,7 +124,7 @@ end;
 {$define FPC_SYSTEM_HAS_COMPARECHAR0}
 function strncmp_comparechar0(Const buf1,buf2;len:cardinal):longint; cdecl; external 'c' name 'strncmp';
 
-function CompareChar0(Const buf1,buf2;len:longint):longint;
+function CompareChar0(Const buf1,buf2;len:longint):longint;{$ifdef SYSTEMINLINE}inline;{$endif}
 begin
   if len <= 0 then
     exit(0);
@@ -134,9 +134,26 @@ end;
 {$endif not FPC_SYSTEM_HAS_COMPARECHAR0}
 
 
+
+{$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
+{$define FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
+
+function libc_pchar_length(p:pchar):cardinal; cdecl; external 'c' name 'strlen';
+
+function fpc_pchar_length(p:pchar):longint;[public,alias:'FPC_PCHAR_LENGTH']; {$ifdef hascompilerproc} compilerproc; {$endif} {$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+  fpc_pchar_length:=libc_pchar_length(p);
+end;
+
+{$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
+
+
 {
   $Log$
-  Revision 1.1  2004-01-11 11:10:07  jonas
+  Revision 1.2  2004-05-01 15:26:33  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.1  2004/01/11 11:10:07  jonas
     + cgeneric.inc: implementations of rtl routines based on libc
     * system.inc: include cgeneric.inc before powerpc.inc/i386.inc/... if
       FPC_USE_LIBC is defined

+ 149 - 0
rtl/inc/cgenstr.inc

@@ -0,0 +1,149 @@
+{
+    $Id$
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 1999-2000 by Carl-Eric Codere,
+    member of the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{ we have to call the libc routines, because simply declaring our routines }
+{ as cdecl and external in libc cause problems because the calling         }
+{ convention the interface is different                                    }
+
+{$ifndef FPC_UNIT_HAS_STRLEN}
+{$define FPC_UNIT_HAS_STRLEN}
+ function libc_strlen(const p: pchar): cardinal; cdecl; external 'c' name 'strlen';
+
+ function strlen(P : pchar) : longint;
+   begin
+     strlen := libc_strlen(p);
+   end;
+{$endif FPC_UNIT_HAS_STRLEN}
+
+
+{$ifndef FPC_UNIT_HAS_STREND}
+{$define FPC_UNIT_HAS_STREND}
+
+ function StrEnd(P: PChar): PChar;{$ifdef SYSTEMINLINE}inline;{$endif}
+   begin
+     strend := p+strlen(p);
+   end;
+{$endif FPC_UNIT_HAS_STREND}
+
+
+{$ifndef FPC_UNIT_HAS_STRCOPY}
+{$define FPC_UNIT_HAS_STRCOPY}
+ function libc_strcpy(dest: pchar; const src: pchar): pchar; cdecl; external 'c' name 'strcpy';
+
+ Function StrCopy(Dest, Source:PChar): PChar;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     StrCopy := libc_strcpy(dest,source);
+   end;
+{$endif FPC_UNIT_HAS_STRCOPY}
+
+
+{$ifndef FPC_UNIT_HAS_STRSCAN}
+{$define FPC_UNIT_HAS_STRSCAN}
+ function libc_strchr(const p: pchar; c: longint): pchar; cdecl; external 'c' name 'strchr';
+
+ function StrScan(P: PChar; C: Char): PChar;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     StrScan := libc_strchr(p,longint(c));
+   end;
+{$endif FPC_UNIT_HAS_STRSCAN}
+
+
+{$ifndef FPC_UNIT_HAS_STRRSCAN}
+{$define FPC_UNIT_HAS_STRRSCAN}
+ function libc_strrchr(const p: pchar; c: longint): pchar; cdecl; external 'c' name 'strrchr';
+
+ function StrRScan(P: PChar; C: Char): PChar;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     StrRScan := libc_strrchr(p,longint(c));
+   end;
+{$endif FPC_UNIT_HAS_STRRSCAN}
+
+(*
+{$ifndef FPC_UNIT_HAS_STRECOPY}
+{$define FPC_UNIT_HAS_STRECOPY}
+ function libc_stpcpy(dest: pchar; const src: pchar): pchar; cdecl; external 'c' name 'stpcpy';
+
+  Function StrECopy(Dest, Source: PChar): PChar;{$ifdef SYSTEMINLINE}inline;{$endif}
+    Begin
+      StrECopy := libc_stpcpy(dest,source);
+    end;
+{$endif FPC_UNIT_HAS_STRECOPY}
+*)
+
+(*
+{$ifndef FPC_UNIT_HAS_STRLCOPY}
+{$define FPC_UNIT_HAS_STRLCOPY}
+
+ function libc_strlcpy(dest: pchar; const src: pchar; maxlen: StrLenInt): StrLenInt; cdecl; external 'c' name 'strlcpy';
+
+ Function StrLCopy(Dest,Source: PChar; MaxLen: StrLenInt): PChar;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     libc_strlcpy(dest,source,maxlen);
+     StrLCopy := Dest;
+   end;
+{$endif FPC_UNIT_HAS_STRLCOPY}
+*)
+
+{$ifndef FPC_UNIT_HAS_STRCOMP}
+{$define FPC_UNIT_HAS_STRCOMP}
+ function libc_strcmp(const str1,str2: pchar): longint; cdecl; external 'c' name 'strcmp';
+
+ function StrComp(Str1, Str2 : PChar): StrLenInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     strcomp := libc_strcmp(str1,str2);
+   end;
+{$endif FPC_UNIT_HAS_STRCOMP}
+
+
+{$ifndef FPC_UNIT_HAS_STRICOMP}
+{$define FPC_UNIT_HAS_STRICOMP}
+ function libc_strcasecmp(const str1,str2: pchar): longint; cdecl; external 'c' name 'strcasecmp';
+
+ function StrIComp(Str1, Str2 : PChar): StrLenInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     stricomp := libc_strcasecmp(str1,str2);
+   end;
+{$endif FPC_UNIT_HAS_STRICOMP}
+
+
+{$ifndef FPC_UNIT_HAS_STRLCOMP}
+{$define FPC_UNIT_HAS_STRLCOMP}
+ function libc_strncmp(const str1,str2: pchar; l: Cardinal): longint; cdecl; external 'c' name 'strncmp';
+
+ function StrLComp(Str1, Str2 : PChar; L: StrLenInt): StrLenInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     strlcomp := libc_strncmp(str1,str2,l);
+   end;
+{$endif FPC_UNIT_HAS_STRLCOMP}
+
+
+{$ifndef FPC_UNIT_HAS_STRLICOMP}
+{$define FPC_UNIT_HAS_STRLICOMP}
+ function libc_strncasecmp(const str1,str2: pchar; l: Cardinal): longint; cdecl; external 'c' name 'strncasecmp';
+
+ function StrLIComp(Str1, Str2 : PChar; L: StrLenInt): StrLenInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+   Begin
+     strlicomp := libc_strncasecmp(str1,str2,l);
+   end;
+{$endif FPC_UNIT_HAS_STRLICOMP}
+
+
+{
+  $Log$
+  Revision 1.1  2004-05-01 15:26:33  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+
+}

+ 8 - 2
rtl/inc/generic.inc

@@ -652,8 +652,11 @@ end;
 { also add a strpas alias for internal use in the system unit (JM) }
 function strpas(p:pchar):shortstring; [external name 'FPC_PCHAR_TO_SHORTSTR'];
 
-{ also add a strlen alias for internal use in the system unit (JM) }
+{$ifndef FPC_UNIT_HAS_STRLEN}
+
+{ if strlen is not yet defined, we need a forward declaration here }
 function strlen(p:pchar):longint; [external name 'FPC_PCHAR_LENGTH'];
+{$endif FPC_UNIT_HAS_STRLEN}
 
 {$ifndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
 
@@ -1158,7 +1161,10 @@ end;
 
 {
   $Log$
-  Revision 1.73  2004-04-29 19:50:13  peter
+  Revision 1.74  2004-05-01 15:26:33  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.73  2004/04/29 19:50:13  peter
     * x86-64 fixes
 
   Revision 1.72  2004/04/28 21:01:29  florian

+ 8 - 1
rtl/inc/strings.pp

@@ -93,6 +93,10 @@ interface
 
 implementation
 
+{$ifdef FPC_USE_LIBC}
+{$i cgenstr.inc}
+{$endif FPC_USE_LIBC}
+
 {  Read Processor dependent part, shared with sysutils unit }
 {$i strings.inc }
 
@@ -144,7 +148,10 @@ end.
 
 {
   $Log$
-  Revision 1.6  2004-02-18 22:00:59  peter
+  Revision 1.7  2004-05-01 15:26:33  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.6  2004/02/18 22:00:59  peter
     * use strlenint instead of longint
 
   Revision 1.5  2003/07/07 20:22:05  peter

+ 5 - 1
rtl/inc/system.inc

@@ -84,6 +84,7 @@ Procedure Rewrite(var f : TypedFile); [INTERNPROC: In_Rewrite_TypedFile];
 {$ifdef FPC_USE_LIBC}
 { prefer libc implementations over our own, as they're most likely faster }
 {$i cgeneric.inc}
+{$i cgenstr.inc}
 {$endif FPC_USE_LIBC}
 
 {$ifdef cpui386}
@@ -881,7 +882,10 @@ end;
 
 {
   $Log$
-  Revision 1.56  2004-04-22 19:43:43  peter
+  Revision 1.57  2004-05-01 15:26:33  jonas
+    * use some more string routines from libc if FPC_USE_LIBC is used
+
+  Revision 1.56  2004/04/22 19:43:43  peter
     * fix 64bit address printing
 
   Revision 1.55  2004/04/22 17:10:38  peter