/* muformat.c, no comments or docs, but it's pretty simple       */
/* freely distributable software, email tez@tezboyes.demon.co.uk */

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

#define BUFLEN 32

main(int argc,char *argv[])
	{
	FILE *fp_in;
	char s[BUFLEN];
	char drive[BUFLEN],command[256];
	int ret,x,ok=0;

	if(argc==1||argv[1][0]=='?'||argv[1][1]=='?')
		{
		strcpy(command,"format ? < nil:");
		ret=system(command);
		exit(ret);
		}
	if((fp_in=fopen("s:muformat.allow","rb"))==NULL)
		{
		fprintf(stderr,"%s : cannot open s:muformat.allow%s\n",argv[0]);
		exit(1);
		}

	strncpy(drive,argv[2],BUFLEN);
	fgets(s,BUFLEN,fp_in);
    while(!feof(fp_in))
		{
		if(!strnicmp(s,drive,strlen(drive)))
			{
			ok=1;
			strcpy(command,"format ");
			for(x=1;x<argc;x++)
				{
				strcat(command,argv[x]);
				strcat(command," ");
				}
			ret=system(command);
			break;
			}
		fgets(s,BUFLEN,fp_in);
		}
	fclose(fp_in);
	if(!ok)
		{
		fprintf(stderr,"%s : not allowed to format %s\n",argv[0],drive);
		ret=2;
		}
	exit(ret);
	}


