syspch.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. *********************************************************************
  3. $Id$
  4. Copyright (C) 1997, 1998 Gertjan Schouten
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. *********************************************************************
  17. System Utilities For Free Pascal
  18. }
  19. { PChar functions }
  20. type
  21. pbyte = ^byte;
  22. CharArray = array[0..0] of char;
  23. { Processor dependent part, shared withs strings unit }
  24. {$i strings.inc }
  25. { Processor independent part, shared with strings unit }
  26. {$i stringsi.inc }
  27. { StrPas converts a PChar to a pascal string }
  28. function StrPas(Str: PChar): string;
  29. begin
  30. SetLength(result, StrLen(Str));
  31. Move(Str^, result[1], Length(result));
  32. end ;
  33. { StrAlloc allocates a buffer of Size + 4
  34. the size of the allocated buffer is stored at result - 4
  35. StrDispose should be used to destroy the buffer }
  36. function StrAlloc(Size: cardinal): PChar;
  37. begin
  38. inc(size,sizeof(cardinal));
  39. getmem(result,size);
  40. cardinal(pointer(result)^):=size;
  41. inc(result,sizeof(cardinal));
  42. end;
  43. { StrPCopy copies the pascal string Source to Dest and returns Dest }
  44. function StrPCopy(Dest: PChar; Source: string): PChar;
  45. begin
  46. result := StrMove(Dest, PChar(Source), length(Source)+1);
  47. end ;
  48. { StrPLCopy copies MaxLen or less characters from the pascal string
  49. Source to Dest and returns Dest }
  50. function StrPLCopy(Dest: PChar; Source: string; MaxLen: cardinal): PChar;
  51. var Count: cardinal;
  52. begin
  53. result := Dest;
  54. if (Result <> Nil) and (MaxLen <> 0) then begin
  55. Count := Length(Source);
  56. if Count > MaxLen then
  57. Count := MaxLen;
  58. StrMove(Dest, PChar(Source), Count);
  59. CharArray(result^)[Count] := #0; { terminate ! }
  60. end ;
  61. end ;
  62. { StrDispose clears the memory allocated with StrAlloc }
  63. procedure StrDispose(Str: PChar);
  64. begin
  65. if (Str <> Nil) then
  66. begin
  67. dec(Str,sizeof(cardinal));
  68. Freemem(str,cardinal(pointer(str)^));
  69. end;
  70. end;
  71. { StrBufSize returns the amount of memory allocated for pchar Str allocated with StrAlloc }
  72. function StrBufSize(Str: PChar): cardinal;
  73. begin
  74. if Str <> Nil then
  75. result := cardinal(pointer(Str - SizeOf(cardinal))^)-sizeof(cardinal)
  76. else
  77. result := 0;
  78. end ;
  79. {
  80. $Log$
  81. Revision 1.6 1999-08-24 13:14:50 peter
  82. * disposestr allocstr compatible with delphi
  83. Revision 1.5 1999/07/09 10:06:34 peter
  84. * merged
  85. Revision 1.4.2.1 1999/07/09 10:05:05 peter
  86. * fixed strpcopy
  87. Revision 1.4 1999/02/25 07:39:57 michael
  88. * Joined strings and sysutils
  89. Revision 1.3 1999/02/10 22:15:11 michael
  90. + Changed to ansistrings
  91. Revision 1.2 1998/09/16 08:28:40 michael
  92. Update from gertjan Schouten, plus small fix for linux
  93. 1998/08/26 Gertjan
  94. Most functions rewritten in pascal.
  95. Revision 1.1 1998/04/10 15:17:46 michael
  96. + Initial implementation; Donated by Gertjan Schouten
  97. His file was split into several files, to keep it a little bit structured.
  98. }