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

📄 main.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
字号:
/*
 * Copyright (C) 1996-2002 Supernar Systems, Ltd. All rights reserved.
 *
 * Redistribution  and  use  in source and  binary  forms, with or without
 * modification,  are permitted provided that the following conditions are
 * met:
 *
 * 1.  Redistributions  of  source code  must  retain  the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * 2.  Redistributions  in binary form  must reproduce the above copyright
 * notice,  this  list of conditions and  the  following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * 3. The end-user documentation included with the redistribution, if any,
 * must include the following acknowledgment:
 *
 * "This product uses DOS/32 Advanced DOS Extender technology."
 *
 * Alternately,  this acknowledgment may appear in the software itself, if
 * and wherever such third-party acknowledgments normally appear.
 *
 * 4.  Products derived from this software  may not be called "DOS/32A" or
 * "DOS/32 Advanced".
 *
 * THIS  SOFTWARE AND DOCUMENTATION IS PROVIDED  "AS IS" AND ANY EXPRESSED
 * OR  IMPLIED  WARRANTIES,  INCLUDING, BUT  NOT  LIMITED  TO, THE IMPLIED
 * WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN  NO  EVENT SHALL THE  AUTHORS  OR  COPYRIGHT HOLDERS BE
 * LIABLE  FOR  ANY DIRECT, INDIRECT,  INCIDENTAL,  SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE  GOODS  OR  SERVICES;  LOSS OF  USE,  DATA,  OR  PROFITS; OR
 * BUSINESS  INTERRUPTION) HOWEVER CAUSED AND  ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE)  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "main.h"


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

//	Debug_Init();

	memset(startdir,0,sizeof(startdir));
	memset(cfgfilename,0,sizeof(cfgfilename));
	ArgInit(argc, argv);
	VideoInit();
	ShowCopyright(argc, argv);
	CheckIfLocked();
	ShowSysInfo();
	ShowEnvInfo();
	ShowMainMenu();
	ShowMemory();
	CheckVersion();
	ValidateConfig();

l1:	ShowMemory();
	SelectMainMenu();
l2:	switch(mainmenu_sel)
	{
		case 0:		ShowKernelMenu();
					if(keycode==F2)
					{
						ShowMemory();
						mainmenu_sel=1;
						goto l2;
					} else break;
		case 1:		ShowExtenderMenu();
					if(keycode==F1)
					{
						ShowMemory();
						mainmenu_sel=0;
						goto l2;
					} else break;
		case 2:		CreateConfig(); break;
		case 3:		RestoreConfig();break;
		case 4:		id32=id32_old; ClearConfigName(); break;
		case 5:		DiscardExit(); break;
		case 6:		ApplyExit(); break;
	}
	goto l1;
}




/****************************************************************************/
void ArgInit(int argc, char *argv[])
{
	int n;
	char *ptr;
	char *envname;
	char envbuf[256];
	char buf[80];
	char buf2[80];

	if(argc==4)
	{
	  if(stricmp(argv[3],"/q")==0 ||
		stricmp(argv[3],"-q")==0 ||
		stricmp(argv[3],"/quiet")==0 ||
		stricmp(argv[3],"-quiet")==0) goto l1;

	  if(stricmp(argv[3],"/s")==0 ||
		stricmp(argv[3],"-s")==0 ||
		stricmp(argv[3],"/silent")==0 ||
		stricmp(argv[3],"-silent")==0) { silent=TRUE; goto l1; }
	}


	printf("SS/32A -- Protected Mode Setup Utility  Version %s\n",version);
	printf("Copyright (C) Supernar Systems, Ltd. 1996-2002\n");

l1:	if(argc<2)
	{
l2:	  printf("%s syntax is SS <execname.xxx> [config.d32 | command] [option]\n\n", errstr);
	  printf("Commands:\n");
	  printf("---------\n");
	  printf("/I or /INFO        Write DOS/32A Configuration to console\n");
	  printf("/L or /LOCK        Lock Configuration in <execname.xxx> file\n");
	  printf("/U or /UNLOCK      Unlock Configuration in <execname.xxx> file\n\n");
	  printf("Options:\n");
	  printf("--------\n");
	  printf("/Q or /QUIET       Quiet mode (partially disables console output)\n");
	  printf("/S or /SILENT      Silent mode (totally disables console output)\n");
	  printf("/H or /?           This help\n");
	  exit(1);
	}
	if(	stricmp(argv[1],"/h")==0 ||
		stricmp(argv[1],"-h")==0 ||
		stricmp(argv[1],"-?")==0) goto l2;

	strcpy(buf,argv[1]);
	n=ReadHeader(buf,&id32);
	if(n==1)
	{
		strcat(buf,".exe");
		n=ReadHeader(buf,&id32);
	}
	if(n==1) { printf("%s cannot open file \"%s\"\n", errstr, argv[1]); exit(1); }
	if(n==2) { printf("%s cannot read from file \"%s\"\n", errstr, argv[1]); exit(1); }
	if(n==3) { printf("%s unsupported executable format in file \"%s\"\n", errstr, argv[1]); exit(1); }
	if(id32.id!='23DI') { printf("%s \"%s\" is not a DOS/32A executable\n", errstr, argv[1]); exit(1); }
	id32_old=id32;

	if(argc>2)
	{
		if(	stricmp(argv[2],"-lock")==0 ||
			stricmp(argv[2],"/lock")==0 ||
			stricmp(argv[2],"-l")==0 ||
			stricmp(argv[2],"/l")==0)
		{
			id32.dos32a_misc2=((id32.dos32a_misc2&0x3F)|0x40);
			if(WriteHeader(&id32)==0) if(!silent) printf("SS/32A: Configuration has been successfully locked!\n");
			else printf("SS/32A: Could not lock configuration!\n");
			CloseFile();
			exit(0);
		}
		else
		if(	stricmp(argv[2],"-unlock")==0 ||
			stricmp(argv[2],"/unlock")==0 ||
			stricmp(argv[2],"-u")==0 ||
			stricmp(argv[2],"/u")==0)
		{
			id32.dos32a_misc2=((id32.dos32a_misc2&0x3F)&0xBF);
			if(WriteHeader(&id32)==0) if(!silent) printf("SS/32A: Configuration has been successfully unlocked!\n");
			else printf("SS/32A: Could not unlock configuration!\n");
			CloseFile();
	 		exit(0);
		}
		else
		if(	stricmp(argv[2],"-info")==0 ||
			stricmp(argv[2],"/info")==0 ||
			stricmp(argv[2],"-i")==0 ||
			stricmp(argv[2],"/i")==0)
		{
			ShowHeaderInfo();
			CloseFile();
			exit(0);
		}
		if((id32.dos32a_misc2&0x40)==0x40)
		{
			printf("SS/32A: Configuration in file \"%s\" is locked!\n",buf);
			exit(0);
		}


		n=open(argv[2],O_RDONLY | O_BINARY);
		if(n==-1)
		{
			strcpy(buf2,argv[2]);
			strcat(buf2,".d32");
			n=open(buf2,O_RDONLY | O_BINARY);
			if(n==-1)
			{
				envname=getenv("DOS32A");
				if(envname!=NULL)
				{
					ptr=strchr(envname,' ');
					if(ptr==NULL) ptr=strchr(envname,0);
					memset(envbuf,0,256);
					strncpy(envbuf,envname,(dword)ptr-(dword)envname);
					strcat(envbuf,"\\D32\\"); strcat(envbuf,buf2);
					n=open(envbuf,O_RDWR | O_BINARY);
				}
			}
		}
		if(n!=-1)
		{
			read(n,&id32,24);
			close(n);
			if(id32.id!='23DI') { printf("%s \"%s\" is not a DOS/32A configuration file\n", errstr, argv[2]); exit(1); }
			id32.dos32a_misc2=((id32.dos32a_misc2&0x3F) | (id32_old.dos32a_misc2&0xC0));
			if(WriteHeader(&id32)!=0) { printf("%s could not configure file \"%s\"\n", errstr, buf); exit(1); }
			CloseFile();
			if(!silent) printf("SS/32A: File \"%s\" has been successfully configured\n",buf);
			exit(0);
		}
		else
		{
			printf("%s cannot open configuration file \"%s\"\n", errstr, argv[2]);
			exit(1);
		}
	}
	file_type=GetFileType();
	extn_type=GetExtenderType();
}




/****************************************************************************/
void ShowCopyright(int argc, char *argv[])
{
	char buf[80];
	DrawBackground();
	SetColor(YELLOW);
	SetBackColor(BLUE);
	Print_At(0,31,"

⌨️ 快捷键说明

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