📄 main.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"
char *version = "7.2";
char newname[80];
char newname2[80];
char filename[80];
char name_bn[80];
char name_un[80];
char *bufptr;
char *bufptr2;
char *fileptr;
char *stubname;
char *stubname1="DOS32A.EXE";
char *stubname2="STUB32A.EXE";
char *stubname3="STUB32C.EXE";
char *errstr="SB/32A fatal:";
char *tempname="$$SB32$$.TMP";
int execargn = 1;
int filesize = 0;
int oldfilesize = 0;
int newfilesize = 0;
int Main_Type = -1;
int Exec_Type = -1;
int Extender_Type = -1;
int bind = FALSE;
int unbind = FALSE;
int overwrite = FALSE;
int quiet = FALSE;
int silent = TRUE;
int bind_name = FALSE;
int unbind_name = FALSE;
/****************************************************************************/
void err_open(char *str) {
printf("%s cannot open file \"%s\"\n",errstr,str);
exit(1);
}
void err_rdonly(char *str) {
printf("%s cannot open Read-Only file \"%s\"\n",errstr,str);
exit(1);
}
void err_seek(char *str) {
printf("%s error seeking in file \"%s\"\n",errstr,str);
exit(1);
}
void err_read(char *str) {
printf("%s error reading from file \"%s\"\n",errstr,str);
exit(1);
}
void err_support(char *str) {
printf("%s unsupported exec format in file \"%s\"\n",errstr,str);
exit(1);
}
void err_dest(char *str) {
printf("%s destination file \"%s\" already exists\n",errstr,str);
exit(1);
}
void err_mem(char *str) {
printf("%s not enough memory to load file \"%s\"\n",errstr,str);
exit(1);
}
void err_crtmp(void) {
printf("%s error creating temp file\n",errstr);
exit(1);
}
void err_wrtmp(void) {
printf("%s error writing to temp file\n",errstr);
exit(1);
}
void err_rdstub(void) {
printf("%s error reading from stub file\n",errstr);
exit(1);
}
void err_invstub(void) {
printf("%s invalid stub file format\n",errstr);
exit(1);
}
void err_nod32a(void) {
printf("%s cannot find file \"DOS32A.EXE\"\n",errstr);
exit(1);
}
void err_nostub(char *str) {
printf("%s cannot find file \"%s\"\n",errstr,str);
exit(1);
}
void err_arg(char *str) {
printf("%s invalid or misplaced command or option \"%s\"\n",errstr,str);
exit(1);
}
void err_sameact(void) {
printf("%s cannot Bind and Unbind at the same time\n",errstr);
exit(1);
}
void err_nullname(void) {
printf("%s you must specify a file name with /BN or /UN options\n",errstr);
exit(1);
}
void err_environment(void) {
printf("%s DOS/32A environment variable is not set up properly\n",errstr);
printf("You need to reinstall DOS/32 Advanced DOS Extender on this computer\n");
exit(1);
}
/****************************************************************************/
void ShowCopyright()
{
Print("SB/32A -- Protected Mode Bind Utility Version %s\n",version);
Print("Copyright (C) Supernar Systems, Ltd. 1996-2002\n");
}
void ArgInit(int argc, char *argv[])
{
int n,m;
int argn=14;
char *args[] = { "bs", "bc", "bn", "rs", "rc", "un",
"b", "r", "u", "o", "q", "s", "h", "?" };
execargn=1;
if(argc>=2)
{
for(n=1; n<argc; n++)
{
if(*argv[n]=='-' || *argv[n]=='/')
{
for(m=0; m<argn; m++)
{
if(strnicmp(argv[n]+1, args[m], strlen(args[m]))==0) switch(m)
{
case 0: execargn++;
bind=TRUE;
stubname=stubname2;
goto l0;
case 1: execargn++;
bind=TRUE;
stubname=stubname3;
goto l0;
case 2: execargn++;
bind_name=TRUE;
strcpy(name_bn,argv[n]+3);
if(strlen(name_bn)==0)
{
ShowCopyright();
err_nullname();
}
goto l0;
case 3: execargn++;
bind=TRUE;
stubname=stubname2;
overwrite=TRUE;
goto l0;
case 4: execargn++;
bind=TRUE;
stubname=stubname3;
overwrite=TRUE;
goto l0;
case 5: execargn++;
unbind_name=TRUE;
strcpy(name_un,argv[n]+3);
if(strlen(name_un)==0)
{
ShowCopyright();
err_nullname();
}
goto l0;
case 6: execargn++;
bind=TRUE;
stubname=stubname1;
goto l0;
case 7: execargn++;
bind=TRUE;
stubname=stubname1;
overwrite=TRUE;
goto l0;
case 8: execargn++;
unbind=TRUE;
goto l0;
case 9: execargn++;
overwrite=TRUE;
goto l0;
case 10: execargn++;
quiet=TRUE;
silent=FALSE;
goto l0;
case 11: execargn++;
quiet=TRUE;
silent=TRUE;
goto l0;
case 12:
case 13: ShowCopyright();
goto l1;
}
}
ShowCopyright();
err_arg(argv[n]);
}
l0: argn=14;
}
}
ShowCopyright();
if(argc<2 || execargn>=argc)
{
l1: Print("SB/32A fatal: syntax is SB [commands] [options] <execname.xxx>\n\n");
Print("Commands:\n");
Print("---------\n");
Print("/B Bind DOS/32A to Linear Executable\n");
Print("/BS Bind STUB/32A to Linear Executable\n");
Print("/BC Bind STUB/32C to Linear Executable\n");
Print("/R Replace existing Stub/Extender with DOS/32A\n");
Print("/RS Replace existing Stub/Extender with STUB/32A\n");
Print("/RC Replace existing Stub/Extender with STUB/32C\n");
Print("/U Unbind Linear Executable from the existing Stub\n\n");
Print("Options:\n");
Print("--------\n");
Print("/BNfilename.xxx Specify destination file name when Binding\n");
Print("/UNfilename.xxx Specify destination file name when Unbinding\n");
Print("/O Unconditionally Overwrite existing files\n");
Print("/Q Quiet mode (partially disables console output)\n");
Print("/S Silent mode (totally disables console output)\n");
Print("/H or /? This help\n");
exit(1);
}
}
void OpenExec(char *argv[])
{
int n,m;
strcpy(filename,argv[execargn]);
n=open_exec(filename);
if(n==-2) err_rdonly(argv[execargn]);
if(n!=0) { strcpy(filename,argv[execargn]);
strcat(filename,".exe");
n=open_exec(filename);
if(n==-2) err_rdonly(argv[execargn]);
if(n!=0) { strcpy(filename,argv[execargn]);
strcat(filename,".le");
n=open_exec(filename);
if(n==-2) err_rdonly(argv[execargn]);
if(n!=0) { strcpy(filename,argv[execargn]);
strcat(filename,".lx");
n=open_exec(filename);
if(n==-2) err_rdonly(argv[execargn]);
if(n!=0) { strcpy(filename,argv[execargn]);
strcat(filename,".lc");
n=open_exec(filename);
if(n==-2) err_rdonly(argv[execargn]);
} } } }
if(n==-1) err_open(argv[execargn]);
}
/****************************************************************************/
int GetExecType(char *argv[])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -