📄 param.c
字号:
strcpy( CmdLineParms.CodePageFile, "kanji.uni" );
break;
case DB_WANSUNG_KOREAN:
strcpy( CmdLineParms.CodePageFile, "949.uni" );
break;
}
}
if( CmdLineParms.PreprocessOnly && CmdLineParms.NoPreprocess ) {
RcFatalError( ERR_OPT_NOT_VALID_TOGETHER, "-o", "-zn" );
}
SetIncludeVar();
} /* CheckParms */
static void defaultParms( void )
/******************************/
{
#ifdef SCANDEBUG
CmdLineParms.DebugScanner = FALSE;
#endif
#ifdef YYDEBUG
CmdLineParms.DebugParser = FALSE;
#endif
CmdLineParms.PrintHelp = FALSE;
CmdLineParms.Quiet = FALSE;
CmdLineParms.Pass1Only = FALSE;
CmdLineParms.Pass2Only = FALSE;
CmdLineParms.NoResFile = FALSE;
CmdLineParms.IgnoreINCLUDE = FALSE;
CmdLineParms.IgnoreCWD = FALSE;
CmdLineParms.PrivateDLL = FALSE;
CmdLineParms.GlobalMemEMS = FALSE;
CmdLineParms.EMSInstance = FALSE;
CmdLineParms.EMSDirect = FALSE;
CmdLineParms.ProtModeOnly = FALSE;
CmdLineParms.SegmentSorting = SEG_SORT_MANY;
CmdLineParms.FindAndReplace = FALSE;
CmdLineParms.Prepend = FALSE;
// CmdLineParms.WritableRes = FALSE;
CmdLineParms.InFileName[0] = '\0';
CmdLineParms.InExeFileName[0] = '\0';
CmdLineParms.OutResFileName[0] = '\0';
CmdLineParms.OutExeFileName[0] = '\0';
CmdLineParms.CodePageFile[0] = '\0';
CmdLineParms.PrependString[0] = '\0';
CmdLineParms.CPPArgs = NULL;
CmdLineParms.VersionStamp = VERSION_31_STAMP;
CmdLineParms.NoProtectCC = FALSE;
CmdLineParms.NoPreprocess = FALSE;
CmdLineParms.GenAutoDep = FALSE;
CmdLineParms.PreprocessOnly = FALSE;
CmdLineParms.ExtraResFiles = NULL;
CmdLineParms.FindReplaceStrings = NULL;
#ifdef __OSI__
if( __OS == OS_NT ) {
CmdLineParms.TargetOS = RC_TARGET_OS_WIN32;
} else {
CmdLineParms.TargetOS = RC_TARGET_OS_WIN16;
}
#elif defined(__NT__)
CmdLineParms.TargetOS = RC_TARGET_OS_WIN32;
#elif defined(__OS2__)
CmdLineParms.TargetOS = RC_TARGET_OS_OS2;
#else
CmdLineParms.TargetOS = RC_TARGET_OS_WIN16;
#endif
NewIncludeDirs = NULL;
} /* defaultParms */
#if( 0 )
// copied from windows.h
#define CP_ACP 0
__declspec(dllimport) int __stdcall MultiByteToWideChar(
uint_32 CodePage, uint_32 dwFlags, const char *lpMultiByteStr, int cchMultiByte,
char *lpWideCharStr, int cchWideChar);
int NativeDBStringToUnicode( int len, const char *str, char *buf ) {
/*******************************************************************/
int ret;
unsigned outlen;
if( len > 0 ) {
if( buf == NULL ) {
outlen = 0;
} else {
outlen = len * 2;
}
ret = MultiByteToWideChar( CP_ACP, 0, str, len, buf, outlen );
} else {
ret = 0;
}
return( ret * 2 );
}
#endif
static void getCodePage( void ) {
/********************************/
RcStatus ret;
char path[ _MAX_PATH ];
if( CmdLineParms.CodePageFile[0] != '\0' ) {
ret = OpenTable( CmdLineParms.CodePageFile, path );
switch( ret ) {
case RS_FILE_NOT_FOUND:
RcFatalError( ERR_CANT_FIND_CHAR_FILE, CmdLineParms.CodePageFile );
break;
case RS_READ_ERROR:
RcFatalError( ERR_READING_CHAR_FILE, path, strerror( errno ) );
break;
case RS_READ_INCMPLT:
case RS_BAD_FILE_FMT:
RcFatalError( ERR_BAD_CHAR_FILE, path );
break;
case RS_WRONG_VER:
RcFatalError( ERR_WRONG_CHAR_FILE_VER, path );
break;
case RS_OPEN_ERROR:
RcFatalError( ERR_CANT_OPEN_CHAR_FILE, path, strerror( errno ) );
break;
default:
SetDBChars( GetLeadBytes() );
break;
}
} else {
#ifdef NT_HOSTED
SetNativeLeadBytes();
ConvToUnicode = NativeDBStringToUnicode;
#endif
}
}
static bool doScanParams( int argc, char *argv[], int *nofilenames )
/*******************************************************************/
{
const char *arg;
int switchchar;
bool contok; /* continue with main execution */
int currarg;
contok = true;
switchchar = _dos_switch_char();
for( currarg = 1; currarg < argc && contok; currarg++) {
arg = argv[ currarg ];
if( *arg == switchchar || *arg == '-' ) {
contok = ScanOptionsArg( arg + 1 ) && contok;
} else if( *arg == '@' ) {
contok = scanEnvVar( arg + 1, nofilenames ) && contok;
} else if( *arg == '?' ) {
CmdLineParms.PrintHelp = true;
contok = false;
} else if( *nofilenames == 0 ) {
if( scanString( CmdLineParms.InFileName, arg, _MAX_PATH ) ) {
RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
}
(*nofilenames)++;
} else if( *nofilenames == 1 ) {
if( scanString( CmdLineParms.InExeFileName, arg, _MAX_PATH ) ) {
RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
}
(*nofilenames)++;
} else {
RcError( ERR_TOO_MANY_ARGS, arg );
contok = false;
}
}
return( contok );
}
extern unsigned ParseEnvVar( const char *env, char **argv, char *buf )
/********************************************************************/
{
/*
* Returns a count of the "command line" parameters in *env.
* Unless argv is NULL, both argv and buf are completed.
*
* This function ought to be fairly similar to clib(initargv@_SplitParms).
* Parameterisation does the same as _SplitParms with historical = 0.
*/
const char *start;
int switchchar;
unsigned argc;
char *bufend;
bool got_quote;
switchchar = _dos_switch_char();
bufend = buf;
argc = 1;
if( argv != NULL ) argv[0] = ""; //fill in the program name
for( ;; ) {
got_quote = FALSE;
while( isspace( *env ) && *env != '\0' ) env++;
start = env;
if( buf != NULL ) {
argv[ argc ] = bufend;
}
if( *env == switchchar || *env == '-' ) {
if( buf != NULL ) {
*bufend = *env;
bufend++;
}
env ++;
}
while( ( got_quote || !isspace( *env ) ) && *env != '\0' ) {
if( *env == '\"' ) {
got_quote = !got_quote;
}
if( buf != NULL ) {
*bufend = *env;
bufend++;
}
env++;
}
if( start != env ) {
argc++;
if( buf != NULL ) {
*bufend = '\0';
bufend++;
}
}
if( *env == '\0' ) break;
}
return( argc );
}
static bool scanEnvVar( const char *varname, int *nofilenames )
/*************************************************************/
{
/*
* Pass nofilenames and analysis of getenv(varname) into argc and argv
* to doScanParams. Return view on usability of data. (TRUE is usable.)
*
* Recursion is supported but circularity is rejected.
*
* The analysis is fairly similar to that done in clib(initargv@_getargv).
* It is possible to use that function but it is not generally exported and
* ParseEnvVar() above is called from other places.
*/
typedef struct EnvVarInfo {
struct EnvVarInfo *next;
char *varname;
char **argv; /* points into buf */
char buf[1]; /* dynamic array */
} EnvVarInfo;
unsigned argc;
EnvVarInfo *info;
static EnvVarInfo *stack = 0; // Needed to detect recursion.
unsigned argvsize;
unsigned argbufsize;
char *env;
size_t varlen; // size to hold varname copy.
bool result; // doScanParams Result.
env = RcGetEnv( varname );
if( env == NULL ) {
RcWarning( ERR_ENV_VAR_NOT_FOUND, varname );
return( TRUE );
}
// This used to cause stack overflow: set foo=@foo && wrc @foo.
for( info = stack; info != NULL; info = info->next ) {
#if !defined(__UNIX__)
if( stricmp( varname, info->varname ) == 0 ) // Case-insensitive
#else
if( strcmp( varname, info->varname ) == 0 ) // Case-sensitive
#endif
RcFatalError( ERR_RCVARIABLE_RECURSIVE, varname );
}
argc = ParseEnvVar( env, NULL, NULL ); // count parameters.
argbufsize = strlen( env ) + 1 + argc; // inter-parameter spaces map to 0
argvsize = ( argc + 1 ) * sizeof( char * ); // sizeof argv[argc+1]
varlen = strlen( varname ) + 1; // Copy taken to detect recursion.
info = RcMemMalloc( sizeof *info + argbufsize + argvsize + varlen );
info->next = stack;
stack = info; // push info on stack
info->argv = (char **)info->buf;
ParseEnvVar( env, info->argv, info->buf + argvsize );
info->varname = info->buf + argvsize + argbufsize;
strcpy( info->varname, varname );
info->argv[argc] = NULL; //there must be a NULL element on the end
// of the list
result = doScanParams( argc, info->argv, nofilenames );
stack = info->next; // pop stack
RcMemFree( info );
return( result );
}
bool ScanParams( int argc, char * argv[] )
/*****************************************/
{
int nofilenames; /* number of filename parms read so far */
bool contok; /* continue with main execution */
nofilenames = 0;
defaultParms();
contok = doScanParams( argc, argv, &nofilenames );
if( argc < 2 ) { /* 26-mar-94 */
CmdLineParms.PrintHelp = true;
contok = false;
}
if( contok ) {
if( nofilenames == 0 ) {
RcError( ERR_FILENAME_NEEDED );
contok = false;
} else {
CheckParms();
getCodePage();
}
}
return( contok );
} /* ScanParams */
extern void ScanParamShutdown( void )
/***********************************/
{
ExtraRes *tmpres;
FRStrings *strings;
if( CmdLineParms.CPPArgs != NULL ) {
RcMemFree( CmdLineParms.CPPArgs );
}
RcMemFree( NewIncludeDirs );
while( CmdLineParms.ExtraResFiles != NULL ) {
tmpres = CmdLineParms.ExtraResFiles;
CmdLineParms.ExtraResFiles = CmdLineParms.ExtraResFiles->next;
RcMemFree( tmpres );
}
while( CmdLineParms.FindReplaceStrings != NULL) {
strings = CmdLineParms.FindReplaceStrings;
CmdLineParms.FindReplaceStrings = CmdLineParms.FindReplaceStrings->next;
RcMemFree( strings );
}
} /* ScanParamShutdown */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -