⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
{
	int n;
	n=check_if_unbound_exec();
	if(n==-1) err_seek(argv[execargn]);
	else if(n==-2) err_read(argv[execargn]);
	else if(n==-3) err_support(argv[execargn]);
	return(n);
}

int FindExecType(char *argv[])
{
	int n;
	n=get_exec_start();
	if(n==-1) err_read(argv[execargn]);
	else if(n==-2) return(-1);
	n=get_exec_type();
	if(n==-1) err_read(argv[execargn]);
	else if(n==-2) return(-1);
	return(n);
}

int GetExtenderType(char *argv[])
{
	int n;
	n=get_extender_type();
	if(n==-1) err_read(argv[execargn]);
	return(n);
}










/****************************************************************************/
void main(int argc, char *argv[])
{

	int n=-1;
	int m=-1;
	int l=-1;
	int e=-1;
	int x,y;
	char buf[80];

//	Debug_Init();

	CheckEnvironment();
	ArgInit(argc, argv);
	OpenExec(argv);
	filesize=filelength(exec_handle);
	n=GetExecType(argv);

	if(n==0) {
	  m=FindExecType(argv);
	  l=GetExtenderType(argv);
	}

	Main_Type=n;		/* file format: LE, LX, LC, PE */
	Exec_Type=m;		/* same as "n" when bound */
	Extender_Type=l;	/* Stub/Extender type */

	Print("\n");
	Print("Application Name:   \"%s\"\n",argv[execargn]);
	Print("Application Size:   %d bytes\n",filesize);
	Print("Application Type:  ");
	if(n!=0)
	{
	  if(n==1) Print(" Unbound LE-style file format Linear Executable");
	  if(n==2) Print(" Unbound LX-style file format Linear Executable");
	  if(n==3) Print(" Unbound LC-style file format Linear Executable");
	  if(n==4) Print(" Unbound PE-style file format Linear Executable");
	  if(n==5) Print(" Unbound PMW1-style file format Linear Executable");
	}
	else
	{
	  if(m==-1)
	  {
		Print(" Standard DOS Executable\n");
		close_exec();
		exit(127);	/* signal error to SC compressor */
	  }
	  if(l==0) Print(" Unknown Stub File bound to\n");
	  if(l==1) Print(" DOS/32 Advanced DOS Extender bound to\n");
	  if(l==2) Print(" STUB/32C Configurable Stub File bound to\n");
	  if(l==3) Print(" STUB/32A Standard Stub File bound to\n");
	  if(l==4) Print(" DOS/4G DOS Extender bound to\n");
	  if(l==5) Print(" PMODE/W DOS Extender bound to\n");

	  if(m==1) Print("                    LE-style file format Linear Executable");
	  if(m==2) Print("                    LX-style file format Linear Executable");
	  if(m==3) Print("                    LC-style file format Linear Executable");
	  if(m==4) Print("                    PE-style file format Portable Executable");
	  if(m==5) Print("                    PMW1-style file format Linear Executable");
	}
	Print("\n");

	if(n==3 || m==3) DisplayOEMInfo();

	unlink(tempname);

	if(unbind_name==FALSE)
	{
	  strcpy(newname,filename);
	  bufptr=(char *)strchr(newname,'.');
	  if(bufptr!=NULL) strset(bufptr,0);
	  if(Main_Type==1 || Exec_Type==1) strcat(newname,".le");
	  if(Main_Type==2 || Exec_Type==2) strcat(newname,".lx");
	  if(Main_Type==3 || Exec_Type==3) strcat(newname,".lc");
	  if(Main_Type==4 || Exec_Type==4) strcat(newname,".pe");
	  if(Main_Type==5 || Exec_Type==5) strcat(newname,".pmw");
	}
	else strcpy(newname,name_un);

	if(bind_name==FALSE)
	{
	  strcpy(newname2,filename);
	  bufptr2=(char *)strchr(newname2,'.');
	  if(bufptr2!=NULL) strset(bufptr2,0);
	  strcat(newname2,".exe");
	}
	else strcpy(newname2,name_bn);


	if(bind==TRUE && unbind==TRUE) err_sameact();
	if(bind)
	{
		BindExec(argv);
		if(!silent) printf("SB/32A: File \"%s\" has been successfully bound\n", filename);
	}
	else if(n==0) if(unbind)
	{
		UnbindExec(argv);
		if(!silent) printf("SB/32A: File \"%s\" has been successfully unbound\n", filename);
	}

	close_exec();
	exit(0);
}










void UnbindExec(char *argv[])
{
	int n,m;

	Print("\n");
	Print("  Unbinding file:   \"%s\"\n",filename);
	Print("Destination file:   \"%s\"\n",newname);
	CheckIfExists(newname);

	n=unbind_exec();
	if(n==-1) err_mem(filename);
	if(n==-2) err_read(filename);
	if(n==-3) err_crtmp();
	if(n==-4) err_wrtmp();

	unlink(newname);
	copy_file(tempname,newname);
	unlink(tempname);

	oldfilesize=GetFileSize(newname);
	if(quiet!=TRUE)	printf("Destination size:   %d bytes (%1.1f%%)\n",
	oldfilesize, (float)(oldfilesize+0.01)/(float)(filesize+0.01) *100);
}


void BindExec(char *argv[])
{
	int n,m;
	int stubsize;
	int execsize;
	int stubhandle;
	int exechandle;
	char *ptr;
	char *envname;
	char envbuf[256];

	CheckIfExists(newname2);
	if(Main_Type==0) UnbindExec(argv);

	Print("\n");
	Print("    Binding file:   \"%s\"\n",newname);
	Print("Destination file:   \"%s\"\n",newname2);

	stubhandle=open(stubname,O_RDWR | O_BINARY);
	if(stubhandle==-1)
	{
		envname=getenv("DOS32A");
		if(envname==0) err_nod32a();
		ptr=strchr(envname,' ');
		if(ptr==NULL) ptr=strchr(envname,0);
		memset(envbuf,0,256);
		strncpy(envbuf,envname,(dword)ptr-(dword)envname);
		strcat(envbuf,"\\BINW\\"); strcat(envbuf,stubname);
		stubhandle=open(envbuf,O_RDWR | O_BINARY);
	}
	if(stubhandle==-1) err_nostub(envbuf);
	stubsize=filelength(stubhandle);

	exechandle=open(newname,O_RDWR | O_BINARY);
	if(exechandle==-1) err_open(newname);

	execsize=filelength(exechandle);

	n=bind_exec(stubhandle, exechandle, stubsize, execsize);
	close(exechandle);
	close(stubhandle);
	unlink(newname);
	close_exec();
	switch(n)
	{
		case -1:	err_mem(newname);
		case -2:	err_rdstub();
		case -3:	err_read(newname);
		case -4:	err_crtmp();
		case -5:	err_wrtmp();
		case -6:	err_invstub();
	}

	unlink(newname2);
	copy_file(tempname,newname2);
	unlink(tempname);

	newfilesize=GetFileSize(newname2);
	if(quiet!=TRUE)	printf("Destination size:   %d bytes (%1.1f%%)\n",
	newfilesize, (float)(newfilesize+0.01)/(float)(filesize+0.01) *100);
	if(quiet!=TRUE) printf("  Stub file used:   \"%s\"\n",stubname);
}



/****************************************************************************/
void Print(char *format, ...)
{
	va_list arglist;
	char buffer[1024];
	if(quiet==FALSE)
	{
		va_start(arglist,format);
		vsprintf(buffer,format,arglist);
		printf(buffer);
		va_end(arglist);
	}
}
void CheckIfExists(char *name)
{
	int n;
	n=open(name,O_RDWR | O_BINARY);
	if(n!=-1)
	{
		close(n); if(!overwrite) err_dest(name);
	}
}
int GetFileSize(char *name)
{
	int n;
	int m=0;
	n=open(name,O_RDWR | O_BINARY);
	if(n!=-1)
	{
		m=filelength(n);
		close(n);
	}
	return(m);
}
void CheckEnvironment()
{
	if(getenv("DOS32A")==NULL) err_environment();
}
void copy_file(char *f1, char *f2)
{
	int c;
	FILE *src;
	FILE *dest;

	if( (f1[1] != ':') && (f2[1] != ':') )
	{
		rename(f1,f2);
		return;
	}

	if((src=fopen(f1,"rb"))!=NULL)
	{
		if((dest=fopen(f2,"wb"))!=NULL)
		{
			while((c=fgetc(src))!=EOF) fputc(c,dest);
			fclose(dest);
		}
	fclose(src);
	}
}

void DisplayOEMInfo()
{

	char *ptr;

	if( (ptr=find_oem_info()) == NULL) return;

	Print("\n");
	Print("Application OEM Information:\n");

	Print("-------------------------------------------------------------------------------\n");
	Print("%s\n",ptr);
	Print("-------------------------------------------------------------------------------\n");

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -