const char* versionstring="$VER:Iconer v1.3";

#define	ERR_ARGS		1
#define	ERR_INFOFILE	2
#define ERR_SHOWINFO	3

#include <exec/types.h>

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

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

void	Bye(int);
BOOL	CheckForInfoFile(char *);

char	command[512];

main(argc,argv)
int		argc;
char	**argv;
{
	char*	cp;
	if (*argv[1] == '?') Bye(ERR_SHOWINFO);
	if (argc !=3) Bye(ERR_ARGS);
	if (CheckForInfoFile(argv[1])) Bye(ERR_INFOFILE);
	cp = &argv[1][strlen(argv[1])-1];
	if (*cp == '/') *cp=0;
	else if (*cp == '"' && *(cp-1) == '/')
	{
		*cp=0;
		*(cp-1)='"';
	}
	command[0]=0;
	strcat(command,"Copy Iconer:");
	strcat(command,argv[2]);
	strcat(command,".info \"");
	strcat(command,argv[1]);
	strcat(command,".info\"");
	Execute(command,0,0);
	Bye(0);
}

void	Bye(error)
int error;
{
	if (error)
	{
		switch (error)
		{
			case ERR_ARGS:
			printf("Wrong number of arguments!\n");
			break;
			
			case ERR_INFOFILE:
			printf("File is an info file!\n");
			break;
			
			case ERR_SHOWINFO:
			printf("Usage : Iconer <file/dir> <icon>\nWill cause the dos command\nCopy Iconer:<icon>.info <file/dir>.info\n%s © by The Hanged Man\n",&versionstring[5]);
			break;
			
			default:
			printf("Unknown error code!\n");
			break;
		}
		exit(0);
	}
}

BOOL	CheckForInfoFile(str)
char	*str;
{
	int	length=0;
	
	while(*++str != 0) length++;
	while(*--str != '.' && length--);
	if (!length) return(FALSE);
	if (stricmp(++str,"info")) return(FALSE);
	return(TRUE);
}
