/* exlibsrc.c (usually archived in a linker library) */

#include <intuition/intuition.h>
#include <proto/graphics.h>
void Block(win,col,x1,y1,width,height)         /* Block zeichnen */
struct Window *win;
int col,x1,y1,width,height;
{
  struct RastPort *RP;
  if(width==0 || height ==0) return;
  RP=win->RPort;
  SetDrMd(RP,JAM1);
  SetAPen(RP,col);
  RectFill(RP,x1,y1,x1+width-1,y1+height-1);
}
#include <intuition/intuition.h>
#include <proto/graphics.h>

void Box(win,col1,col2,x1,y1,width,height)   /*  leere Box mit Rahmen zeichnen */
struct Window *win;
int col1,col2,x1,y1,width,height;
{
  struct RastPort *RP;
  if(width==0 || height==0) return;
  RP=win->RPort;
  SetDrMd(RP,JAM1);
  SetAPen(RP,col1);
  RectFill(RP,x1,y1,x1+width-1,y1+height-1);
  SetAPen(RP,col2);
  RectFill(RP,x1+1,y1+1,x1+width-2,y1+height-2);
}
#include <intuition/intuition.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
void Cls(win,col)                  /* Bildschirm löschen in Farbe col */
struct Window *win;
int col;
{
  Move(win->RPort,0,0);       /* Rastport in die obere linke Ecke setzen */
  SetRast(win->RPort,col);
  RefreshWindowFrame(win);
  RemakeDisplay();
}

/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1991 by Metalworx
 *
 *	Name .....: DispAlert.c
 *	Created ..: Mon 18-Nov-91 19:08
 *	Revision .: 0
 *
 *	Date		Author		Comment
 *	=========	========	====================
 *	18-Nov-91	Mtwx		Created this file!
 *
 * $Revision Header ********************************************************/
 #define REVISION 0

/***************************************************************************
* DispAlert.c: zeigt zweizeiligen Alert an				   *
***************************************************************************/

/* ------------------------------- includes ----------------------------- */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <proto/intuition.h>

/* ------------------------------- global references -------------------- */

static char AlertMessage[128]; /* statischer Buffer, spart den ganzen
				  malloc()-Kram! */

/* ------------------------------- routines ----------------------------- */

BOOL DispAlert(long type,char *line1,char *line2)
{
  short x;
  char y,endflag,*pointer;

  setmem(AlertMessage,128,NULL);  /* erst einmal alles auf NULL setzen */
  pointer=&AlertMessage[0];
  x=(640-strlen(line1)*8)/2;
  y=12;
  memcpy(pointer,&x,sizeof(short));
  pointer+=sizeof(short);
  memcpy(pointer,&y,sizeof(char));
  pointer+=sizeof(char);
  strcpy(pointer,line1);
  pointer+=strlen(line1)+1;   /* abschließende \0 beachten! */
  endflag=0xff; 	      /* noch kein Ende */
  memcpy(pointer,&endflag,sizeof(char));
  pointer+=sizeof(char);

/* das Ganze für die zweite Alertzeile */
  x=(640-strlen(line2)*8)/2;
  y=24;
  memcpy(pointer,&x,sizeof(short));
  pointer+=sizeof(short);
  memcpy(pointer,&y,sizeof(char));
  pointer+=sizeof(char);
  strcpy(pointer,line2);
  pointer+=strlen(line2)+1;   /* abschließende \0 beachten! */
  endflag=0;		      /* jetzt das Ende */
  memcpy(pointer,&endflag,sizeof(char));

/* Alert-Funktion aus der Intuition-Lib aufrufen */
  return(DisplayAlert(type,&AlertMessage[0],35L));
}
#include <intuition/intuition.h>
#include <proto/graphics.h>

void Ellipse(win,col,x,y,rx,ry)                 /* Ellipse zeichnen */
struct Window *win;
int col,x,y,rx,ry;
{
  struct RastPort *RP;
  RP=win->RPort;
  SetDrMd(RP,JAM1);
  SetAPen(RP,col);
  DrawEllipse(RP,x,y,rx,ry);
}
/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1991 by Metalworx
 *
 *	Name .....: messagewin.c
 *	Created ..: Sun 27-Oct-91 11:36
 *	Revision .: 2
 *
 *	Date		Author		Comment
 *	=========	========	====================
 *	12-Jul-92	Mtwx		Closegadget, wenn delay=-1
 *	07-Dec-91	Mtwx		Fehler in der Festerbreite behoben
 *	27-Oct-91	Mtwx		Created this file!
 *
 * $Revision Header ********************************************************/
 #define REVISION 2

/***************************************************************************
* messagewin.c: öffnet kleines Fenster mit Grafik (Ausrufezeichen !),      *
*		sowie einer Titel- und einer Textzeile, schließt entweder  *
*		selbstständig nach Zeitintervall oder durch ein 	   *
*		CloseWindow() des aufrufenden Programms oder durch ein     *
*		Klick auf das CloseGadget (je nach Wert des Übergabe-      *
*		parameters 'delay')                                        *
***************************************************************************/

/* ------------------------------- includes ----------------------------- */

#include <string.h>
#include <intuition/intuition.h>
#include <proto/dos.h>
#include <proto/intuition.h>

#include <mtwx_defs.h>

#include "messagewin.h"

/* ------------------------------- routines ----------------------------- */

struct Window *Messagewin(struct Screen *screen, char *title, char *text,
			  int delay)
{
  int width;
  struct Window *win;

  MessageFenster.Screen=screen;
  width=(strlen(title)*8) > (strlen(text)*8+68) ? strlen(title)*8+33 :
    strlen(text)*8+68;
  if(width>640)
    width=640;
  MessageFenster.Width=width;
  MessageFenster.LeftEdge=(640-width)/2;
  MessageFenster.TopEdge=(screen->Height-MessageFenster.Height)/2;
  MessageFenster.Title=title;
  if(delay==-1)
  {
    MessageFenster.Flags|=WINDOWCLOSE;
    MessageFenster.IDCMPFlags|=CLOSEWINDOW;
  }
  if(!(win=OpenWindow(&MessageFenster)))
  {
    DisplayBeep(0L);
    return NULL;
  }
  DrawImage(win->RPort,&exclmImage,3,4);
  Shadow(win,text,2,1,60,20);
  if(delay > 0)
  {
    Delay(delay*50);
    CloseWindow(win);
  }
  if(delay == -1)
  {
    get_simpleinputs(win);
    CloseWindow(win);
  }
  return win;
}
/* oeffnet CONSOLE-Window f. (Revision-)Messages */

#include <exec/types.h>

extern char ProgId[],Version[];
extern int Revision;
extern char UserId[],Date[];

int OpenRevWin(size)
char *size;
{
  int window;
  char Str1[180],Str2[190];
  window=open(size,2,0);
  if(window==-1)
    return(-1);
  sprintf(Str1,"%s %s - Revision %d\n\n",ProgId,Version,Revision);
  sprintf(Str2,"latest update by: %s  %s\n\n",UserId,Date);
  WrConWin(window,Str1);
  WrConWin(window,Str2);
  return(window);
}

#include <intuition/intuition.h>
#include <proto/graphics.h>

void Pixel(win,col,x,y)               /* Punkt setzen */
struct Window *win;
int col,x,y;
{
  struct RastPort *RP;
  RP=win->RPort;
  SetDrMd(RP,JAM1);
  SetAPen(RP,col);
  WritePixel(RP,x,y);
}
#include <intuition/intuition.h>
#include <proto/intuition.h>
#include <proto/graphics.h>

Print(win,text,col1,col2,xpos,ypos)      /* Ausgabe von Text */
struct Window *win;
char *text;
int col1,col2,xpos,ypos;
{
  int dx=4,width=win->GZZWidth;
  struct RastPort *RP;

/*  if((width-strlen(text)*8) < 0) return; */   /* Text zu lang */
  RP=win->RPort;
  SetDrMd(RP,JAM2);
  SetAPen(RP,col1);
  SetBPen(RP,col2);
  if (win->Flags & GIMMEZEROZERO) dx=0;
  if(xpos == -1) xpos=(width-strlen(text)*8)/2+dx;   /* zentriert */
  if(xpos == -2) xpos=width-strlen(text)*8+dx;       /* rechtsbündig */
  Move(RP,xpos,ypos);
  Text(RP,text,strlen(text));
}
/***************************************************************************
* ReqBlock.c: zeichnet ein Viereck in einen Requester(!!)                  *
*									   *
* created: 1990 Mtwx							   *
* updated: 06-Aug-91 Mtwx						   *
***************************************************************************/

/* ------------------------------- includes ----------------------------- */

#include <intuition/intuition.h>
#include <proto/graphics.h>

/* ------------------------------- routines ----------------------------- */

void ReqBlock(req, col, x1, y1, width, height)
struct Requester *req;
int col, x1, y1, width, height;
{
  struct RastPort *RP;

  if (width == 0 || height == 0)
    return;
  RP = req->ReqLayer->rp;
  SetDrMd(RP, JAM1);
  SetAPen(RP, col);
  RectFill(RP, x1, y1, x1 + width - 1, y1 + height - 1);
}
#include <intuition/intuition.h>
ReqBox(req,col1,col2,x1,y1,width,height)   /*  leere Box mit Rahmen im
					       Requester zeichnen */
struct Requester *req;
int col1,col2,x1,y1,width,height;
{
  struct RastPort *RP;
  if(width==0 || height==0) return;
  RP=req->ReqLayer->rp;
  SetDrMd(RP,JAM1);
  SetAPen(RP,col1);
  RectFill(RP,x1,y1,x1+width-1,y1+height-1);
  SetAPen(RP,col2);
  RectFill(RP,x1+1,y1+1,x1+width-2,y1+height-2);
}


#include <intuition/intuition.h>
#include <proto/graphics.h>
void ReqPrint(req,text,col1,col2,xpos,ypos)      /* Ausgabe von Text */
struct Requester *req;
char *text;
int col1,col2,xpos,ypos;
{
  int width=req->Width;
  struct RastPort *RP;

  RP=req->ReqLayer->rp;
  SetDrMd(RP,JAM2);
  SetAPen(RP,col1);
  SetBPen(RP,col2);
  if(xpos == -1) xpos=(width-strlen(text)*8)/2;   /* zentriert */
  if(xpos == -2) xpos=width-strlen(text)*8;       /* rechtsbündig */
  Move(RP,xpos,ypos);
  Text(RP,text,strlen(text));
}
#include <intuition/intuition.h>
#include <proto/graphics.h>

void Shadow(win,text,txtc,shdwc,xpos,ypos)     /* Ausgabe von Text */
struct Window *win;			      /* mit Schatten	  */
char *text;
int txtc,shdwc,xpos,ypos;
{
  int dx=4,width=win->GZZWidth;
  struct RastPort *RP;

  RP=win->RPort;
  SetDrMd(RP,JAM1);
  SetAPen(RP,shdwc);
  if(win->Flags & GIMMEZEROZERO) dx=0;
  if(xpos==-1) xpos=(width-strlen(text)*8)/2+dx;
  if(xpos==-2) xpos=width-strlen(text)*8+dx;
  Move(RP,xpos+1,ypos+1);
  Text(RP,text,strlen(text));
  SetAPen(RP,txtc);
  Move(RP,xpos,ypos);
  Text(RP,text,strlen(text));
}
/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1992 by Metalworx
 *
 *	Name .....: Shadowbox.c
 *	Created ..: Tue 11-Feb-92 13:00
 *	Revision .: 1
 *
 *	Date		Author		Comment
 *	=========	========	====================
 *	12-Jul-92       Mtwx            Titelzeile in der Box
 *	11-Feb-92	Mtwx		Created this file!
 *
 * $Revision Header ********************************************************/
 #define REVISION 1

/***************************************************************************
* shadowbox.c: zeichnet eine Box mit zwei Farben, die linke und die	   *
*	       obere Linie in einer Farbe, die untere und die rechte Line  *
*	       in einer zweiten Farbe, wahlweise wird ein Text zentriert   *
*	       in die obere Line geschrieben				   *
***************************************************************************/

/* ------------------------------- includes ----------------------------- */

#include <string.h>
#include <intuition/intuition.h>

/* ------------------------------- routines ----------------------------- */

void Shadowbox(struct Window *Window,int hicol,int locol,int x,int y,
	       int width, int height,char *Text, int tcol,int bcol)
{
  register unsigned short l,xt;
  char Titel[80];

  Line(Window,hicol,x,y,x+width,y);   /* oben */
  Line(Window,hicol,x,y,x,y+height);  /* links */
  Line(Window,locol,x,y+height,x+width,y+height); /* unten */
  Line(Window,locol,x+width,y+height,x+width,y);  /* rechts */

  l=strlen(Text)*8;
  if(l)
  {
    if(l > width) /* Text breiter als Box -> abschneiden */
    {
      xt=0+x;
      stccpy(Titel,Text,width/8);
    }
    else
    {
      xt=(width-l)/2+x;
      strcpy(Titel,Text);
    }
    Print(Window,Titel,tcol,bcol,xt,y+3);
  }
}
int strpos(s1,s2)
char *s1,*s2;
{
  register int i;
  int n,pos=0,flag=0;

  if(strlen(s2) > strlen(s1)) return -1;
  for(i=0;i<strlen(s1)-strlen(s2)+1;i++)
  {
    n=strncmp(&s1[i],s2,strlen(s2));
    if(n==0)
    {
      pos=i;
      flag=1;
      break;
    }
  }
  if(!flag) pos=-1;
  return pos;
}
#include <exec/types.h>

#define EXIST 0
#define EXECUTE 1
#define WRITE 2
#define READ 4

BOOL TestFile(file)
char *file;
{
  int Erfolg;
  Erfolg=access(file,EXIST);
  if(Erfolg==0) return (TRUE);
  else return (FALSE);
}


void WrConWin(win,text)
int win;
char *text;
{
  write(win,text,strlen(text));
}
