home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
programs
/
amiga
/
pastex
/
pastex14-beta-6
/
specialhost
/
source
/
tools.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-03
|
12KB
|
553 lines
/*
** SpecialHost for PasTeX
**
** Copyright © by Olaf Barthel & Georg Heßmann
*/
#include "Global.h"
STATIC int UseFastMem = 0; /* (hes) some kind of test: does SpecialHost work with Bitmap in FAST-RAM too? */
/* No! There are used some OS functions, which need CHIP-RAM! */
VOID __regargs
FreeVecPooled(APTR Mem)
{
if(Mem)
{
ULONG *Data = Mem;
LibFreePooled(Pool,&Data[-1],Data[-1]);
}
}
APTR __regargs
AllocVecPooled(LONG Size,ULONG Flags)
{
if(Size)
{
ULONG *Data;
Size += sizeof(ULONG);
if(Data = (ULONG *)LibAllocPooled(Pool,Size))
{
*Data++ = Size;
if(Flags & MEMF_CLEAR)
memset(Data,0,Size - sizeof(ULONG));
return((APTR)Data);
}
}
return(NULL);
}
VOID __regargs
ClearList(struct List *List)
{
struct Node *Node,
*Next;
Node = List -> lh_Head;
while(Next = Node -> ln_Succ)
{
FreeVecPooled(Node);
Node = Next;
}
NewList(List);
}
struct ListEntry * __regargs
NewEntry(STRPTR Title)
{
struct ListEntry *Entry;
if(Entry = (struct ListEntry *)AllocVecPooled(sizeof(struct ListEntry) + strlen(Title),MEMF_ANY))
{
Entry -> Title = (STRPTR)(Entry + 1);
strcpy(Entry -> Title,Title);
}
return(Entry);
}
WORD __stdargs
ShowRequest(struct Window *Window,STRPTR Text,STRPTR Gadgets,...)
{
WORD Result;
if(AP_Application)
{
va_list VarArgs;
va_start(VarArgs,Gadgets);
Result = MUI_RequestA(AP_Application,WI_Main,NULL,"SpecialHost",Gadgets,Text,VarArgs);
va_end(VarArgs);
}
else
{
struct EasyStruct Easy;
ULONG IDCMP = NULL;
va_list VarArgs;
Easy . es_StructSize = sizeof(struct EasyStruct);
Easy . es_Flags = NULL;
Easy . es_Title = "SpecialHost";
Easy . es_TextFormat = Text;
Easy . es_GadgetFormat = Gadgets;
va_start(VarArgs,Gadgets);
Result = EasyRequestArgs(Window,&Easy,&IDCMP,VarArgs);
va_end(VarArgs);
}
return(Result);
}
STRPTR __regargs
ShowError(LONG Primary,LONG Secondary,BOOL GetPrimary)
{
STATIC struct { LONG Code; STRPTR Name; } LocalErrors[] =
{
ERR_NO_INTUITION, "Error opening intuition.library v37",
ERR_NO_GRAPHICS, "Error opening graphics.library v37",
ERR_NO_GADTOOLS, "Error opening gadtools.library v37",
ERR_NO_ICON, "Error opening icon.library v37",
ERR_NO_IFFPARSE, "Error opening iffparse.library v37",
ERR_NO_UTILITY, "Error opening utility.library v37",
ERR_NO_ASL, "Error opening asl.library v37",
ERR_NO_MUI, "Error opening muimaster.library",
ERR_NO_MATHFFP, "Error opening mathieeedoubbas.library",
ERR_NO_MATHTRANS, "Error opening mathieeedoubtrans.library",
ERR_NO_POOL, "Error creating memory pool",
ERR_NO_GUI, "Error opening window",
ERR_ALREADY_RUNNING, "SpecialHost process already running",
ERR_NO_PORT, "Error opening message port",
ERR_READ_ERROR, "Error reading file",
ERR_NO_MEM, "Out of memory",
ERR_FILE_FORMAT_ERROR, "File format corrupt",
ERR_WEIRD_COMPRESSION, "Image compression type not supported",
ERR_WRONG_IMAGE_FORMAT, "Cannot handle picture file format",
ERR_TOO_LARGE, "Requested image size is too large",
ERR_TOO_SMALL, "Requested image size is too small",
ERR_NO_NIL, "Error opening NIL: stream",
ERR_NO_POST, "Error opening post.library v15",
DTERROR_UNKNOWN_DATATYPE, "Unknown file format",
DTERROR_COULDNT_SAVE, "Could not store file",
DTERROR_COULDNT_OPEN, "Could not open file",
DTERROR_COULDNT_SEND_MESSAGE, "Internal send message error",
DTERROR_COULDNT_OPEN_CLIPBOARD, "Could not open clipboard",
DTERROR_UNKNOWN_COMPRESSION, "Compression method unknown",
DTERROR_NOT_ENOUGH_DATA, "Not enough data available",
DTERROR_INVALID_DATA, "Invalid data",
19999, "Postscript error: File not found",
20001, "Postscript error: Dictionary full",
20002, "Postscript error: Dictionary stack overflow",
20003, "Postscript error: Dictionary stack underflow",
20004, "Postscript error: Exec stack overflow",
20005, "Postscript error: Interrupted",
20006, "Postscript error: Invalid access",
20007, "Postscript error: Invalid exit",
20008, "Postscript error: Invalid file access",
20009, "Postscript error: Invalid font",
20010, "Postscript error: Invalid restore",
20011, "Postscript error: Invalid stop",
20012, "Postscript error: I/O error",
20013, "Postscript error: Limit check trap",
20014, "Postscript error: No current point",
20015, "Postscript error: Range check trap",
20016, "Postscript error: Stack overflow",
20017, "Postscript error: Stack underflow",
20018, "Postscript error: Syntax error",
20019, "Postscript error: Timeout",
20020, "Postscript error: Typecheck",
20021, "Postscript error: Undefined",
20022, "Postscript error: Undefined filename",
20023, "Postscript error: Undefined result",
20024, "Postscript error: Unmatched mark",
20025, "Postscript error: Unregistered",
20026, "Postscript error: Virtual memory error",
20027, "Postscript error: Memory allocation error",
20028, "Postscript error: Killed",
20029, "Postscript error: Configuration",
20030, "Postscript error: Undefined resource",
IFFERR_NOMEM, "Out of memory",
IFFERR_READ, "File read error",
IFFERR_WRITE, "File write error",
IFFERR_SEEK, "File seek error",
IFFERR_MANGLED, "File structure damaged",
IFFERR_NOTIFF, "Not an IFF format file",
0, NULL
};
STRPTR PrimaryError = NULL,
SecondaryError = NULL;
if(Primary)
{
LONG i;
for(i = 0 ; LocalErrors[i] . Name ; i++)
{
if(LocalErrors[i] . Code == Primary)
{
PrimaryError = LocalErrors[i] . Name;
break;
}
}
if(!PrimaryError)
{
STATIC UBYTE __far Buffer[256];
Fault(Primary,"",Buffer,256);
PrimaryError = Buffer + 2;
}
if(GetPrimary)
return(PrimaryError);
}
if(Secondary)
{
LONG i;
for(i = 0 ; LocalErrors[i] . Name ; i++)
{
if(LocalErrors[i] . Code == Secondary)
{
SecondaryError = LocalErrors[i] . Name;
break;
}
}
if(!SecondaryError)
{
STATIC UBYTE __far Buffer[256];
Fault(Secondary,"",Buffer,256);
SecondaryError = Buffer + 2;
}
}
if(PrimaryError)
{
if(ThisProcess -> pr_CLI)
{
if(SecondaryError)
Printf("SpecialHost: %s, %s\a\n",PrimaryError,SecondaryError);
else
Printf("SpecialHost: %s\a\n",PrimaryError);
}
else
{
if(IntuitionBase)
{
if(SecondaryError)
ShowRequest(NULL,"%s\n%s","Continue",PrimaryError,SecondaryError);
else
ShowRequest(NULL,"%s","Continue",PrimaryError);
}
}
}
}
VOID __regargs
DeleteBitMap(struct BitMap *BitMap)
{
if(GfxBase -> LibNode . lib_Version >= 39 && !UseFastMem)
FreeBitMap(BitMap);
else
{
LONG i;
for(i = 0 ; i < BitMap -> Depth ; i++)
{
if(BitMap -> Planes[i])
FreeVec(BitMap -> Planes[i]);
}
FreeVecPooled(BitMap);
}
}
struct BitMap * __regargs
CreateBitMap(LONG Width,LONG Height,LONG Depth,ULONG Flags,struct BitMap *Friend)
{
if(GfxBase -> LibNode . lib_Version < 39 || UseFastMem)
{
struct BitMap *BitMap;
LONG Plus;
if(Depth > 8)
Plus = (Depth - 8) * sizeof(PLANEPTR);
else
Plus = 0;
if(BitMap = (struct BitMap *)AllocVecPooled(sizeof(struct BitMap) + Plus,MEMF_ANY | MEMF_CLEAR))
{
LONG i,PageSize;
InitBitMap(BitMap,Depth,Width,Height);
PageSize = BitMap -> BytesPerRow * BitMap -> Rows;
for(i = 0 ; i < BitMap -> Depth ; i++)
{
if (UseFastMem)
{
BitMap -> Planes[i] = (PLANEPTR)AllocVec(PageSize,MEMF_ANY | ((Flags & BMF_CLEAR) ? MEMF_CLEAR : 0));
}
else
{
BitMap -> Planes[i] = (PLANEPTR)AllocVec(PageSize,MEMF_CHIP);
}
if(!BitMap -> Planes[i])
{
LONG j;
for(j = 0 ; j < i ; j++)
FreeVec(BitMap -> Planes[j]);
FreeVecPooled(BitMap);
return(NULL);
}
}
if((Flags & BMF_CLEAR) && !UseFastMem)
BltBitMap(BitMap,0,0,BitMap,0,0,Width,Height,0x00,(1 << Depth) - 1,NULL);
return(BitMap);
}
}
else
return(AllocBitMap(Width,Height,Depth,Flags,Friend));
}
VOID __regargs
DeleteTempLine(UBYTE *Line)
{
FreeVecPooled(Line);
}
UBYTE * __regargs
CreateTempLine(LONG Width,LONG Height)
{
return((UBYTE *)A