translator.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. History:
  14. Added the defines use_amiga_smartlink and
  15. use_auto_openlib. Implemented autoopening
  16. of the library.
  17. 14 Jan 2003.
  18. Changed startcode for unit.
  19. [email protected] Nils Sjoholm
  20. }
  21. {$I useamigasmartlink.inc}
  22. {$ifdef use_amiga_smartlink}
  23. {$smartlink on}
  24. {$endif use_amiga_smartlink}
  25. UNIT translator;
  26. INTERFACE
  27. USES exec;
  28. Const
  29. TR_NotUsed = -1; { This is an oft used system rc }
  30. TR_NoMem = -2; { Can't allocate memory }
  31. TR_MakeBad = -4; { Error in MakeLibrary call }
  32. VAR TranslatorBase : pLibrary;
  33. const
  34. TRANSLATORNAME : PChar = 'translator.library';
  35. FUNCTION Translate(const inputString : pCHAR; inputLength : LONGINT; outputBuffer : pCHAR; bufferSize : LONGINT) : LONGINT;
  36. {Here we read how to compile this unit}
  37. {You can remove this include and use a define instead}
  38. {$I useautoopenlib.inc}
  39. {$ifdef use_init_openlib}
  40. procedure InitTRANSLATORLibrary;
  41. {$endif use_init_openlib}
  42. {This is a variable that knows how the unit is compiled}
  43. var
  44. TRANSLATORIsCompiledHow : longint;
  45. IMPLEMENTATION
  46. {$ifndef dont_use_openlib}
  47. uses msgbox;
  48. {$endif dont_use_openlib}
  49. FUNCTION Translate(const inputString : pCHAR; inputLength : LONGINT; outputBuffer : pCHAR; bufferSize : LONGINT) : LONGINT;
  50. BEGIN
  51. ASM
  52. MOVE.L A6,-(A7)
  53. MOVEA.L inputString,A0
  54. MOVE.L inputLength,D0
  55. MOVEA.L outputBuffer,A1
  56. MOVE.L bufferSize,D1
  57. MOVEA.L TranslatorBase,A6
  58. JSR -030(A6)
  59. MOVEA.L (A7)+,A6
  60. MOVE.L D0,@RESULT
  61. END;
  62. END;
  63. const
  64. { Change VERSION and LIBVERSION to proper values }
  65. VERSION : string[2] = '0';
  66. LIBVERSION : longword = 0;
  67. {$ifdef use_init_openlib}
  68. {$Info Compiling initopening of translator.library}
  69. {$Info don't forget to use InitTRANSLATORLibrary in the beginning of your program}
  70. var
  71. translator_exit : Pointer;
  72. procedure ClosetranslatorLibrary;
  73. begin
  74. ExitProc := translator_exit;
  75. if TranslatorBase <> nil then begin
  76. CloseLibrary(TranslatorBase);
  77. TranslatorBase := nil;
  78. end;
  79. end;
  80. procedure InitTRANSLATORLibrary;
  81. begin
  82. TranslatorBase := nil;
  83. TranslatorBase := OpenLibrary(TRANSLATORNAME,LIBVERSION);
  84. if TranslatorBase <> nil then begin
  85. translator_exit := ExitProc;
  86. ExitProc := @ClosetranslatorLibrary;
  87. end else begin
  88. MessageBox('FPC Pascal Error',
  89. 'Can''t open translator.library version ' + VERSION + #10 +
  90. 'Deallocating resources and closing down',
  91. 'Oops');
  92. halt(20);
  93. end;
  94. end;
  95. begin
  96. TRANSLATORIsCompiledHow := 2;
  97. {$endif use_init_openlib}
  98. {$ifdef use_auto_openlib}
  99. {$Info Compiling autoopening of translator.library}
  100. var
  101. translator_exit : Pointer;
  102. procedure ClosetranslatorLibrary;
  103. begin
  104. ExitProc := translator_exit;
  105. if TranslatorBase <> nil then begin
  106. CloseLibrary(TranslatorBase);
  107. TranslatorBase := nil;
  108. end;
  109. end;
  110. begin
  111. TranslatorBase := nil;
  112. TranslatorBase := OpenLibrary(TRANSLATORNAME,LIBVERSION);
  113. if TranslatorBase <> nil then begin
  114. translator_exit := ExitProc;
  115. ExitProc := @ClosetranslatorLibrary;
  116. TRANSLATORIsCompiledHow := 1;
  117. end else begin
  118. MessageBox('FPC Pascal Error',
  119. 'Can''t open translator.library version ' + VERSION + #10 +
  120. 'Deallocating resources and closing down',
  121. 'Oops');
  122. halt(20);
  123. end;
  124. {$endif use_auto_openlib}
  125. {$ifdef dont_use_openlib}
  126. begin
  127. TRANSLATORIsCompiledHow := 3;
  128. {$Warning No autoopening of translator.library compiled}
  129. {$Warning Make sure you open translator.library yourself}
  130. {$endif dont_use_openlib}
  131. END. (* UNIT TRANSLATOR *)