home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
dirs
/
libtool_463.lzh
/
LibTool
/
LibTool.lzh
/
CComplex
/
Complex.c
next >
Wrap
C/C++ Source or Header
|
1990-06-27
|
7KB
|
244 lines
/**************************************************************************
Complex.c
A set of C routines to be turned into a library called "complex.library".
We use LibTool to make our lib startup asm code (-m option) to be linked with
this module. This creates a library. We also use LibTool to create glue
code for a C application which expects to call C library functions (-c
option). Note that this module should NOT be compiled with small code/data
because we do not bother setting up and restoring a4 (which is what you
would have to do at the start and end of each callable function).
Manx 3.6
cc +pb Complex.c
LibTool -cmo glue.asm ComplexC.fd
as -cd -o LibStart.o ComplexC.src
ln -o libs:complex.library LibStart.o Complex.o -lcl32
Lattice 5.0
lc -b0 Complex.c
LibTool -cmo glue.asm ComplexC.fd
assemble ComplexC.src as LibStart.o
blink LibStart.o Complex.o LIB lib:lcnb.lib TO libs:complex.library
***************************************************************************/
extern struct LibBase; /* this library's base */
#ifdef AZTEC_C
#define NARGS
#define NO_PRAGMAS
#endif
#include "exec/types.h"
#include "exec/tasks.h"
#include "exec/memory.h"
#include "libraries/dos.h"
#include "libraries/dosextens.h"
#ifdef AZTEC_C
#include "functions.h"
#else
#include "proto/all.h"
#endif
#include "intuition/intuition.h"
#include "intuition/intuitionbase.h"
#include "graphics/gfx.h"
#include "graphics/gfxbase.h"
#include "graphics/rastport.h"
#include "graphics/gfxmacros.h"
#include "graphics/view.h"
#include "graphics/text.h"
/* We allocate one of these in OpenUp for every task that opens the lib */
struct workBuf {
struct workBuf *wb_Succ;
struct workBuf *wb_Pred;
struct Process *taskAddr;
struct NewWindow nWind;
};
struct List memyList;
struct NewWindow newWind =
{
20, 20, /* LeftEdge, TopEdge */
300, 145, /* Width, Height */
-1, -1, /* Detail/BlockPens */
CLOSEWINDOW, /* IDCMP Flags */
WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|WINDOWCLOSE|ACTIVATE,
/* Window Specification Flags */
0L, /* FirstGadget */
0L, /* Checkmark */
0L, /* WindowTitle */
0L, /* Screen */
0L, /* SuperBitMap */
303, 145, /* MinWidth, MinHeight */
600, 200, /* MaxWidth, MaxHeight */
WBENCHSCREEN,
};
/**************************************************************************
This function finds the app's workBuf from within our memyList. We tagged
the mem with the app's task address, so we just look for a workBuf whose
taskAddr field is the same. Note the Forbid/Permit around the examining of
the memyList. This is because memyList is a global. When accessing globals
in a shared library, you must prevent other tasks from using the functions
until done accessing the libs globals. This is why you should always use
local (i.e. register) variables, allocate mem per task as we did the work
buffer, or only operate on application data structures passed into these
lib functions.
Also note that this function is for internal use only and so does not
appear listed in our fd file.
***************************************************************************/
struct workBuf *FindMem()
{
register struct workBuf *thisBuf;
register struct Process *thisTask;
/* Find the application's address */
thisTask = (struct Process *) FindTask(0L);
/* Forbid so that we can examine our global memyList without another
task messing with it */
Forbid();
/* Search the list for this task's work buffer */
thisBuf = (struct workBuf *) memyList.lh_Head;
while ( thisBuf->wb_Succ )
{
if ( thisTask == thisBuf->taskAddr )
{
/* Permit and return the work buffer */
Permit();
return(thisBuf);
}
thisBuf = thisBuf->wb_Succ;
}
/* Permit and return(0), we couldn't find its work buffer!! */
Permit();
return(0);
}
/**************************************************************************
***************************************************************************/
struct Window *MakeWindow()
{
register struct workBuf *wBuf;
register struct Window *myWind;
/* Find this task's work buffer */
if ( !( wBuf = FindMem() ) )
return(0);
/* Copy the newWindow template to our work buffer's new window */
wBuf->nWind = newWind;
/* Open the window and return result */
myWind = OpenWindow(&wBuf->nWind);
return(myWind);
}
/**************************************************************************
***************************************************************************/
VOID PrintMsg(x, y, myWind, msg)
SHORT x, y;
UBYTE *msg;
struct Window *myWind;
{
register struct Message *reply;
/* Move to (x,y) */
Move( myWind->RPort, x, y );
/* Print the msg */
Text( myWind->RPort, msg, (strlen(msg)) );
/* Wait for CLOSEWINDOW */
WaitPort(myWind->UserPort);
reply = GetMsg(myWind->UserPort);
}
/**************************************************************************
***************************************************************************/
VOID RemWindow(myWind)
struct Window *myWind;
{
/* Close the window */
CloseWindow(myWind);
}
/**************************************************************************
This is called each time an application opens the lib. It allocates the app's
workBuf, links it into our memyList, and tags it with the app's task address.
This is the Open vector function (i.e. ##open in the fd file).
***************************************************************************/
BOOL OpenUp()
{
register struct workBuf *wBuf;
/* Allocate a work buffer */
wBuf = AllocMem(sizeof(struct workBuf),MEMF_CLEAR|MEMF_PUBLIC);
/* Link it into our memyList */
if (wBuf)
{
AddTail(&memyList, wBuf);
wBuf->taskAddr = (struct Process *) FindTask(0L);
return(TRUE);
}
return(FALSE);
}
/**************************************************************************
This is called each time as application closes the lib. It finds the app's
workBuf within our memyList, removes it from the list, and frees it. This is
the Close vector function (i.e. ##clos in the fd file).
***************************************************************************/
VOID CloseUp()
{
register struct workBuf *wBuf;
/* Find this task's work buffer, remove from list, and free it */
if ( wBuf = FindMem() )
{
Remove(wBuf);
FreeMem(wBuf, sizeof(struct workBuf));
}
}
/**************************************************************************
This is called only once when the lib is first loaded. It just initializes
our memyList. This is the Init vector function (i.e. ##init in the fd file).
***************************************************************************/
BOOL myInit()
{
NewList(&memyList);
return(TRUE);
}