/*
** Remote booter Version 1.00 (OS1.3 Version)
** 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 (OS1.3+ Version) Version 1.00 by The Reaper\n\n");

	ReadConfig();
#ifndef DEBUG
	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)
{
	printf("Booting...\n");
	
	char exe[256];
	
	sprintf(exe, "Assign S: %s", s);
	system(exe);
	
	sprintf(exe, "Assign C: %s", c);
	system(exe);
	
	sprintf(exe, "Assign L: %s", l);
	system(exe);
	
	sprintf(exe, "Assign T: %s", t);
	system(exe);
	
	sprintf(exe, "Assign SYS: %s", sys);
	system(exe);
	
	sprintf(exe, "Assign DEVS: %s", devs);
	system(exe);
	
	sprintf(exe, "Assign LIBS: %s", libs);
	system(exe);
	
	system(boot);
}