qlutil.pas 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. {
  2. This file is part of the Free Pascal Sinclair QL support package.
  3. Copyright (c) 2021 by Karoly Balogh
  4. Interface QDOS OS functions for applications
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$MODE FPC}
  12. unit qlutil;
  13. interface
  14. procedure toqlstring(const s: ansistring; qlstring: pointer; qlstrbuflen: longint);
  15. function toqlstring(const s: ansistring): pointer;
  16. implementation
  17. procedure toqlstring(const s: ansistring; qlstring: pointer; qlstrbuflen: longint);
  18. var
  19. len: longint;
  20. begin
  21. len:=length(s);
  22. if len > qlstrbuflen-sizeof(word) then
  23. len:=qlstrbuflen-sizeof(word);
  24. if assigned(qlstring) then
  25. begin
  26. pword(qlstring)[0]:=len;
  27. move(s[1],pword(qlstring)[1],len);
  28. end;
  29. end;
  30. function toqlstring(const s: ansistring): pointer;
  31. var
  32. qlstring: pointer;
  33. begin
  34. qlstring:=GetMem(length(s)+sizeof(word));
  35. if assigned(qlstring) then
  36. begin
  37. pword(qlstring)[0]:=length(s);
  38. move(s[1],pword(qlstring)[1],length(s));
  39. end;
  40. toqlstring:=qlstring;
  41. end;
  42. end.