summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/amunits/src/coreunits/translator.pas
blob: 47f93cdede6d0c95f3b11b64207f6bb1cc23f07f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{
    This file is part of the Free Pascal run time library.

    A file in Amiga system run time library.
    Copyright (c) 1998-2003 by Nils Sjoholm
    member of the Amiga RTL 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.

 **********************************************************************}
{
    History:

    Added the defines use_amiga_smartlink and
    use_auto_openlib. Implemented autoopening
    of the library.
    14 Jan 2003.

    Changed startcode for unit.
    nils.sjoholm@mailbox.swipnet.se Nils Sjoholm
}

{$I useamigasmartlink.inc}
{$ifdef use_amiga_smartlink}
   {$smartlink on}
{$endif use_amiga_smartlink}

UNIT translator;

INTERFACE
USES exec;

Const

    TR_NotUsed          = -1;   { This is an oft used system rc }
    TR_NoMem            = -2;   { Can't allocate memory }
    TR_MakeBad          = -4;   { Error in MakeLibrary call }

VAR TranslatorBase : pLibrary;

const
    TRANSLATORNAME : PChar = 'translator.library';

FUNCTION Translate(const inputString : pCHAR; inputLength : LONGINT; outputBuffer : pCHAR; bufferSize : LONGINT) : LONGINT;

{Here we read how to compile this unit}
{You can remove this include and use a define instead}
{$I useautoopenlib.inc}
{$ifdef use_init_openlib}
procedure InitTRANSLATORLibrary;
{$endif use_init_openlib}

{This is a variable that knows how the unit is compiled}
var
    TRANSLATORIsCompiledHow : longint;

IMPLEMENTATION

{$ifndef dont_use_openlib}
uses msgbox;
{$endif dont_use_openlib}

FUNCTION Translate(const inputString : pCHAR; inputLength : LONGINT; outputBuffer : pCHAR; bufferSize : LONGINT) : LONGINT;
BEGIN
  ASM
    MOVE.L  A6,-(A7)
    MOVEA.L inputString,A0
    MOVE.L  inputLength,D0
    MOVEA.L outputBuffer,A1
    MOVE.L  bufferSize,D1
    MOVEA.L TranslatorBase,A6
    JSR -030(A6)
    MOVEA.L (A7)+,A6
    MOVE.L  D0,@RESULT
  END;
END;

const
    { Change VERSION and LIBVERSION to proper values }

    VERSION : string[2] = '0';
    LIBVERSION : longword = 0;

{$ifdef use_init_openlib}
  {$Info Compiling initopening of translator.library}
  {$Info don't forget to use InitTRANSLATORLibrary in the beginning of your program}

var
    translator_exit : Pointer;

procedure ClosetranslatorLibrary;
begin
    ExitProc := translator_exit;
    if TranslatorBase <> nil then begin
        CloseLibrary(TranslatorBase);
        TranslatorBase := nil;
    end;
end;

procedure InitTRANSLATORLibrary;
begin
    TranslatorBase := nil;
    TranslatorBase := OpenLibrary(TRANSLATORNAME,LIBVERSION);
    if TranslatorBase <> nil then begin
        translator_exit := ExitProc;
        ExitProc := @ClosetranslatorLibrary;
    end else begin
        MessageBox('FPC Pascal Error',
        'Can''t open translator.library version ' + VERSION + #10 +
        'Deallocating resources and closing down',
        'Oops');
        halt(20);
    end;
end;

begin
    TRANSLATORIsCompiledHow := 2;
{$endif use_init_openlib}

{$ifdef use_auto_openlib}
  {$Info Compiling autoopening of translator.library}

var
    translator_exit : Pointer;

procedure ClosetranslatorLibrary;
begin
    ExitProc := translator_exit;
    if TranslatorBase <> nil then begin
        CloseLibrary(TranslatorBase);
        TranslatorBase := nil;
    end;
end;

begin
    TranslatorBase := nil;
    TranslatorBase := OpenLibrary(TRANSLATORNAME,LIBVERSION);
    if TranslatorBase <> nil then begin
        translator_exit := ExitProc;
        ExitProc := @ClosetranslatorLibrary;
        TRANSLATORIsCompiledHow := 1;
    end else begin
        MessageBox('FPC Pascal Error',
        'Can''t open translator.library version ' + VERSION + #10 +
        'Deallocating resources and closing down',
        'Oops');
        halt(20);
    end;

{$endif use_auto_openlib}

{$ifdef dont_use_openlib}
begin
    TRANSLATORIsCompiledHow := 3;
   {$Warning No autoopening of translator.library compiled}
   {$Warning Make sure you open translator.library yourself}
{$endif dont_use_openlib}


END. (* UNIT TRANSLATOR *)