#include <windows.h>

/*
 *	[t,w]lib.exe are DUMB.
 *	So we come with emulator.
 */

#define	EXECMD_LEN		(16 * 1024)		/* Hmmm ... is this enought ? */

int main(int argc,char *argv[])
{
	int i,len;
	char fname[256];
	char execmd[EXECMD_LEN];
	if(argc<=4)
	{
		MessageBox(NULL,
			"Usage: libemu <libmanager> <libname> "
			"<objfile 1> [<objfile 2> ... <objfile n>]",
			"MS 'lib.exe' emulator",MB_ICONINFORMATION);
		return -1;
	}
	/* parse all file names, appending '+' sign before each name */
	wsprintf(execmd,"%s %s /C ",argv[1],argv[2]);
	len=lstrlen(execmd);
	for(i=3;i<argc;i++)
	{
		wsprintf(fname,"+%s ",argv[i]);
		len+=lstrlen(fname);
		if(len>=EXECMD_LEN)
		{
			MessageBox(NULL,
				"Command line to long. Increase EXECMD_LEN.",
				"MS 'lib.exe' emulator",MB_ICONEXCLAMATION);
			return -1;
		}
		lstrcat(execmd,fname);
	}
	WinExec(execmd,SW_SHOWNORMAL);
	return 0;
}
