/*******************************************************************/
/* 																					 */
/*  Systemstartprogramm zur Auswahl der verschiedenen Anwendungen  */
/* 				Lingscheidt Hermann-Josef									 */
/* 					WallenthalerStr. 15										 */
/* 																					 */
/* 					 5370 Kall-Scheven										 */
/* 					 Tel.: 02441 - 6983										 */
/* 																					 */
/* 					  © 03.April 1991 										 */
/* 																					 */
/*  Aztec_C V5.0 -->   cc start.c  --> ln start.o -lc 				 */
/* 																					 */
/*******************************************************************/

#define START    0  /* Requester */
#define OK       0  /* Gadget */
#define DPAINT   1  /* Gadget */
#define ABSIC	  2  /* Gadget */
#define GBASIC   3  /* Gadget */
#define AZTEC	  4  /* Gadget */
#define SHELL	  5  /* Gadget */
#define WBENCH   6  /* Gadget */

#include <exec/types.h>
#include <intuition/intuition.h>
#include <exec/memory.h>
#include <stdio.h>

/* Funktion anmelden */
SHORT Einladen ();

struct TextAttr starttxtattr = {(UBYTE *)"topaz.font",8,0,65};

/* Gadgettexte und Fenstertexte: */
struct IntuiText startinttxt[] = {
/* 0 */{0,1,1,28,3,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"OK !",NULL},
/* 1 */{0,1,1,13,4,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"________________",NULL},
/* 2 */{0,1,1,13,4,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"________________",NULL},
/* 3 */{0,1,1,13,4,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"________________",NULL},
/* 4 */{0,1,1,13,4,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"________________",NULL},
/* 5 */{0,1,1,13,4,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"________________",NULL},
/* 6 */{0,1,1,13,4,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"________________",NULL},
/* 7 */{0,1,1,41,18,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"Wählen Sie bitte aus:",
		  (struct IntuiText *)&startinttxt[8]},
/* 8 */{0,1,1,81,4,(struct TextAttr *)&starttxtattr,
		  (UBYTE *)"SYSTEMSTART",NULL},
  };

/* Borderdaten: */
SHORT startbrddat[] = {
/*  0 */ -4 , -2 , 91 , -2 , 91 , 15 , -4 , 15 , -4 , -2 ,
/* 10 */ -8 , -4 , 95 , -4 , 95 , 17 , -8 , 17 , -8 , -4 ,
/* 20 */ -3 , -2 ,157 , -2 ,157 , 18 , -3 , 18 , -3 , -2 ,
/* 30 */ -7 , -4 ,161 , -4 ,161 , 20 , -7 , 20 , -7 , -4 ,
/* 40 */  0 ,	0 ,195 ,  0 ,195 ,167 ,  0 ,167 ,  0 ,  0 ,
/* 50 */  0 ,	0 ,203 ,  0 ,203 ,171 ,  0 ,171 ,  0 ,  0 ,
/* 60 */  0 ,	0 ,100 ,  0 ,
/* 64 */  0 ,	0 ,106 ,  0 ,
  };

/* Borderstrukturen: */
struct Border startbrd[] = {
/* 0 */{ 0,  0, 2, 0, 1, 5,(SHORT *)&startbrddat[ 0],
			(struct Border *)&startbrd[1]},
/* 1 */{ 0,  0, 3, 0, 1, 5,(SHORT *)&startbrddat[10],NULL},
/* 2 */{ 0,  0, 2, 0, 1, 5,(SHORT *)&startbrddat[20],
			(struct Border *)&startbrd[3]},
/* 3 */{ 0,  0, 3, 0, 1, 5,(SHORT *)&startbrddat[30],NULL},
/* 4 */{27, 32, 2, 0, 1, 5,(SHORT *)&startbrddat[40],
			(struct Border *)&startbrd[5]},
/* 5 */{23, 30, 3, 0, 1, 5,(SHORT *)&startbrddat[50],
			(struct Border *)&startbrd[6]},
/* 6 */{75, 13, 2, 0, 1, 2,(SHORT *)&startbrddat[60],
			(struct Border *)&startbrd[7]},
/* 7 */{72, 14, 3, 0, 1, 2,(SHORT *)&startbrddat[64],NULL},
  };

/* Gadgetstrukturen: */
struct Gadget startgad[] = {
/* 0 */{(struct Gadget *)&startgad[1], 81, 212, 88, 14, 0, 5, 4097,
		  (APTR)&startbrd[0], 0, (struct IntuiText *)&startinttxt[0],
		  0, 0, OK, 0},
/* 1 */{(struct Gadget *)&startgad[2], 47, 175, 155, 17, 0, 257, 4097,
		  (APTR)&startbrd[2], 0, (struct IntuiText *)&startinttxt[1],
		  0, 0, DPAINT, 0},
/* 2 */{(struct Gadget *)&startgad[3], 47, 148, 155, 17, 0, 257, 4097,
		  (APTR)&startbrd[2], 0, (struct IntuiText *)&startinttxt[2],
		  0, 0, ABSIC, 0},
/* 3 */{(struct Gadget *)&startgad[4], 47, 121, 155, 17, 0, 257, 4097,
		  (APTR)&startbrd[2], 0, (struct IntuiText *)&startinttxt[3],
		  0, 0, GBASIC, 0},
/* 4 */{(struct Gadget *)&startgad[5], 47, 94, 155, 17, 0, 257, 4097,
		  (APTR)&startbrd[2], 0, (struct IntuiText *)&startinttxt[4],
		  0, 0, AZTEC, 0},
/* 5 */{(struct Gadget *)&startgad[6], 47, 67, 155, 17, 0, 257, 4097,
		  (APTR)&startbrd[2], 0, (struct IntuiText *)&startinttxt[5],
		  0, 0, SHELL, 0},
/* 6 */{NULL, 47, 40, 155, 17, 128, 257, 4097, (APTR)&startbrd[2], 0,
		  (struct IntuiText *)&startinttxt[6], 0, 0, WBENCH, 0},
  };

struct Requester start;

/* Einstellen und Anzeigen des Requesters im Fenster */
startstart(window)
struct Window *window;
{
InitRequester(&start);
start.LeftEdge  = 0;
start.TopEdge	 = 0;
start.Width 	 = 250;
start.Height	 = 235;
start.BackFill  = 1;
start.Flags 	 = 0;
start.ReqGadget = &startgad[0];
start.ReqBorder = &startbrd[4];
start.ReqText	 = &startinttxt[7];
return( Request( &start,window));
}

/* Initialisierung von Variablen */
struct IntuitionBase *IntuitionBase;
struct Window			*Fenster;

/* Fensterstruktur */
struct NewWindow MeinFenster =
{
	195,	10,
	250, 235,
	  1,	 0,
	GADGETUP | REQCLEAR,
	ACTIVATE | SMART_REFRESH | BORDERLESS,
	NULL, NULL, NULL, NULL, NULL,
	0, 0, 0, 0, WBENCHSCREEN
};

char Ausgabe[6][100],	 /* Ausgabetexte */
	  Exe_Str[6][255];	 /* Executetexte */

main ()

{
struct IntuiMessage *Nachricht;
ULONG  class;
SHORT  t = 0;

/* Gadgetdaten und Befehle einladen */
	if (!(Einladen ()))
		{
		printf ("\nFinde keine START.INIT Datei !!!\n\n");
		goto SCHLIESSEN;
		}
/* Öffnen der Intuitionlibrary */
	if ((IntuitionBase = (struct IntuitionBase *)
		  OpenLibrary ("intuition.library", 0)) == NULL)
		{
		printf ("Keine Library !!!\n\n");
		goto SCHLIESSEN;
		}
/* Öffnen des Fensters */
	if ((Fenster = (struct Window *)
		  OpenWindow (&MeinFenster)) == NULL)
		{
		printf ("Kein Fenster !!!\n\n");
		goto SCHLIESSEN;
		}
/* Requester anzeigen */
	startstart (Fenster);

FOREVER
	{
/* Auf Nachricht warten */
	Wait (1 << Fenster->UserPort->mp_SigBit);
/* Auswertung der Nachricht */
	while (Nachricht = (struct IntuiMessage *)
			 GetMsg (Fenster->UserPort))
		{
		class = Nachricht->Class;
		ReplyMsg (Nachricht);
		if (class == REQCLEAR) /* OK - Gadget gedrückt */
			{
			t = 1;
			goto SCHLIESSEN;
			}
		}
	}

SCHLIESSEN:
/* Intuitionlibrary und Fenster schliessen */
	if (Fenster)		 CloseWindow  (Fenster);
	if (IntuitionBase) CloseLibrary (IntuitionBase);

/* Auswertung der Gadgets */
	if (t)
		{
		for (t=6; t>=1; t--)
			{
			if ((startgad[t].Flags & SELECTED) == SELECTED)
				{
				printf  (&Ausgabe[t-1][0]);
				Execute (&Exe_Str[t-1][0], NULL, NULL);
				}
			}
		exit (TRUE);
		}
	else
		exit (FALSE);
}

SHORT
Einladen () /* Einlesen der Einstellungen */

{
FILE *fp;

	fp = fopen ("S:START.INIT", "r");

	if (!(fp))
		return (0);
	else
		{
		SHORT t;
		char dummy[20];

		for (t=6; t>=1; t--)
			{
/* Gadgettext einlesen und in die Mitte des Gadgets bringen */
			fgets (&dummy[0], 20, fp);
			dummy[strlen(&dummy[0])-1]='\0';
			strcpy (startinttxt[t].IText, &dummy[0]);
			startinttxt[t].LeftEdge =
				(155-((strlen(&dummy[0])-1)*8))/2;
/* Ausgabestring einlesen */
			fgets (&Ausgabe[t-1][0], 100, fp);
/* Executestring einlesen */
			fgets (&Exe_Str[t-1][0], 255, fp);
			}
		fclose (fp);
		return (1);
		}
}

