/*
** Remote booter Version 1.00
** By The Reaper
**
** © 1996 Eden Software
*/

#define Prototype extern

#include <exec/types.h>
#include <dos/dos.h>

#include <clib/dos_protos.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/* Globals */
char *s;
char *c;
char *devs;
char *libs;
char *sys;
char *l;
char *t;
char *boot;

/* Prototypes */
Prototype void ReadConfig(void);
Prototype void DoBoot(void);

main()
{
	printf("RemoteBoot Version 1.00 by The Reaper\n\n");

	ReadConfig();
#ifndef DEBUG
	printf("Booting...\n");
	DoBoot();
#else
	printf("%s\n", s);
	printf("%s\n", c);
	printf("%s\n", l);
	printf("%s\n", devs);
	printf("%s\n", libs);
	printf("%s\n", t);
#endif
	return(0);
}
void ReadConfig(void)
{
	FILE *fp;
	char buf[256];
	char *tmp;
	
	if(fp = fopen("s:Boot.cfg", "r"))
	{
		while(!feof(fp))
		{
			fgets(buf, sizeof(buf), fp);
			
			tmp = strtok(buf, "=");
			
			if(strcmp(tmp, "S") == NULL)
				s = strdup(strtok(NULL, "\n"));
			
			if(strcmp(tmp, "C") == NULL)
				c = strdup(strtok(NULL, "\n"));
			
			if(strcmp(tmp, "L") == NULL)
				l = strdup(strtok(NULL, "\n"));
			
			if(strcmp(tmp, "LIBS") == NULL)
				libs = strdup(strtok(NULL, "\n"));
			
			if(strcmp(tmp, "DEVS") == NULL)
				devs = strdup(strtok(NULL, "\n"));
			
			if(strcmp(tmp, "SYS") == NULL)
				sys = strdup(strtok(NULL, "\n"));
			
			if(strcmp(tmp, "T") == NULL)
				t = strdup(strtok(NULL, "\n"));
			
			if(strcmp(tmp, "BOOT") == NULL)
				boot = strdup(strtok(NULL, "\n"));
		}
		
		fclose(fp);
	}
}
void DoBoot(void)
{
	AssignPath("s", s);
	AssignPath("c", c);
	AssignPath("t", t);
	AssignPath("l", l);
	AssignPath("libs", libs);
	AssignPath("devs", devs);
	AssignPath("sys", sys);
	
	system(boot);
}