SourceForge has been redesigned. Learn more.
Close

[4fea5c]: / libs / textedit / TextEdit_lib.c  Maximize  Restore  History

Download this file

189 lines (148 with data), 4.5 kB

  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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright Š1999-2008 pinc Software. All Rights Reserved.
* Licensed under the terms of the MIT License.
*/
//! library base functions
#include "TextEdit_includes.h"
struct Library * PUBLIC LibInit(REG(a0, BPTR Segment),REG(d0, struct ClassBase *cb),REG(a6, struct ExecBase *ExecBase));
struct Library * PUBLIC LibOpen(REG(a6, struct ClassBase *cb));
BPTR PUBLIC LibExpunge(REG(a6, struct ClassBase *cb));
BPTR PUBLIC LibClose(REG(a6, struct ClassBase *cb));
LONG PUBLIC LibNull(REG(a6, struct ClassBase *cb));
Class * PUBLIC GetClass(REG(a6, APTR cb))
{
return(((struct ClassBase *)cb)->cb_Class);
}
void PRIVATE TE_Exit(struct ClassBase *cb)
{
if (FreeClass(cb->cb_Class))
cb->cb_Class = NULL;
CloseLibrary(cb->cb_ScrollerBase);
cb->cb_ScrollerBase = NULL;
CloseLibrary(cb->cb_IFFParseBase);
CloseLibrary(cb->cb_DOSBase);
CloseLibrary(cb->cb_IntuitionBase);
CloseLibrary((struct Library *)cb->cb_GfxBase);
CloseLibrary(cb->cb_UtilityBase);
CloseDevice(&cb->cb_Console);
}
int PRIVATE TE_Init(struct ClassBase *cb)
{
if (cb->cb_IntuitionBase = OpenLibrary("intuition.library",37))
{
if (cb->cb_GfxBase = (APTR)OpenLibrary("graphics.library",37))
{
if (cb->cb_UtilityBase = OpenLibrary("utility.library",37))
{
if (!OpenDevice("console.device",-1,(struct IORequest *)&cb->cb_Console,0))
{
Class *cl;
if (cl = MakeClass("pinc-editgadget",GADGETCLASS,NULL,sizeof(struct EditGData),0))
{
cl->cl_Dispatcher.h_Entry = (APTR)DispatchEditGadget;
cl->cl_Dispatcher.h_Data = cb;
cl->cl_UserData = (ULONG)cb;
AddClass(cl);
if (cb->cb_IFFParseBase = OpenLibrary("iffparse.library",37))
cb->cb_DOSBase = OpenLibrary("dos.library",37);
cb->cb_Class = cl;
return(TRUE);
}
CloseDevice(&cb->cb_Console);
}
CloseLibrary(cb->cb_UtilityBase);
}
CloseLibrary(cb->cb_GfxBase);
}
CloseLibrary(cb->cb_IntuitionBase);
}
return(FALSE);
}
STATIC APTR LibVectors[] =
{
LibOpen,
LibClose,
LibExpunge,
LibNull,
GetClass,
Text2Clipboard,
TextFromClipboard,
FreeEditList,
PrepareEditText,
(APTR)-1
};
extern UBYTE __far LibName[], LibID[];
extern LONG __far LibVersion, LibRevision;
struct { ULONG DataSize; APTR Table; APTR Data; struct Library * (*Init)(); } __aligned LibInitTab =
{
sizeof(struct ClassBase),
LibVectors,
NULL,
LibInit
};
struct Library * PUBLIC LibInit(REG(a0, BPTR segment),REG(d0, struct ClassBase *cb),REG(a6, struct ExecBase *ExecBase))
{
if(ExecBase->LibNode.lib_Version < 37)
return(NULL);
cb->cb_LibNode.lib_Node.ln_Type = NT_LIBRARY;
cb->cb_LibNode.lib_Node.ln_Name = LibName;
cb->cb_LibNode.lib_Flags = LIBF_CHANGED | LIBF_SUMUSED;
cb->cb_LibNode.lib_Version = LibVersion;
cb->cb_LibNode.lib_Revision = LibRevision;
cb->cb_LibNode.lib_IdString = (APTR)LibID;
cb->cb_LibSegment = segment;
cb->cb_SysBase = ExecBase;
InitSemaphore(&cb->cb_LockSemaphore);
return((struct Library *)cb);
}
struct Library * PUBLIC LibOpen(REG(a6, struct ClassBase *cb))
{
cb->cb_LibNode.lib_Flags &= ~LIBF_DELEXP;
cb->cb_LibNode.lib_OpenCnt++;
ObtainSemaphore(&cb->cb_LockSemaphore);
if(cb->cb_LibNode.lib_OpenCnt == 1)
{
if (!TE_Init(cb))
{
TE_Exit(cb);
cb->cb_LibNode.lib_OpenCnt--;
ReleaseSemaphore(&cb->cb_LockSemaphore);
return(NULL);
}
}
ReleaseSemaphore(&cb->cb_LockSemaphore);
return((struct Library *)cb);
}
BPTR PUBLIC LibExpunge(REG(a6, struct ClassBase *cb))
{
if (!cb->cb_LibNode.lib_OpenCnt && cb->cb_LibSegment)
{
BPTR TempSegment = cb->cb_LibSegment;
Remove((struct Node *)cb);
FreeMem((BYTE *)cb - cb->cb_LibNode.lib_NegSize,cb->cb_LibNode.lib_NegSize + cb->cb_LibNode.lib_PosSize);
return(TempSegment);
}
else
{
cb->cb_LibNode.lib_Flags |= LIBF_DELEXP;
return(NULL);
}
}
BPTR PUBLIC LibClose(REG(a6, struct ClassBase *cb))
{
if (cb->cb_LibNode.lib_OpenCnt)
cb->cb_LibNode.lib_OpenCnt--;
if (!cb->cb_LibNode.lib_OpenCnt)
{
ObtainSemaphore(&cb->cb_LockSemaphore);
TE_Exit(cb);
ReleaseSemaphore(&cb->cb_LockSemaphore);
if (cb->cb_LibNode.lib_Flags & LIBF_DELEXP)
return(LibExpunge(cb));
}
return(NULL);
}
LONG PUBLIC LibNull(REG(a6, struct ClassBase *cb))
{
return(NULL);
}