/* create a hardlink to a existent file.
   
   see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createhardlink.asp
   
   no copyright for this source code, its freeware do whatever you want with it.

   2006-11-25 Ralf Huesing <ralf@stormbind.net>
		initial release


	notes:
		softlinks seams to be possible by using "Junctions":
		see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/hard_links_and_junctions.asp
			
*/


/* need at least windows >= 2000 */
#define _WIN32_WINNT 0x0500

#include <windows.h>

#define MAX_ARGV	10

static void Message (const char *sText, BOOL bError);

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	char	*seperator;
	char	*argv[MAX_ARGV] = {NULL, };
	int		argc = 0;

	seperator = strtok (lpCmdLine, " ");
	while (seperator) {
		if (argc > MAX_ARGV-1) {
			Message ( "Too much arguments given.", TRUE);
			return -1;
		}
		argv[argc++] = seperator;
		seperator = strtok( NULL, " "); 
	}

	if (NULL == argv[0] || NULL == argv[1]) {
		Message (	"Missing source and/or destination file."
					"\r\n"
					"Argument1 = existent filename"
					"\r\n"
					"Argument2 = destination filename"
                    , TRUE);
		return -1;
	}


	if (FALSE == CreateHardLink(argv[1], argv[0], NULL)) {
		Message ("Linkcreation failed.", TRUE);
		return -1;
	}

	return 0;
}

static void Message (const char *sText, BOOL bError)
{
	MessageBox (NULL, sText, "ln", MB_OK | (bError ? MB_ICONERROR : MB_ICONINFORMATION));
}