keyword.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,426 行 · 第 1/3 页
C
1,426 行
static void ProcData( void )
/**************************/
// NYI: serious copied code from ProcCode. Should be united into one routine.
{
char buffer[ CODE_BUFFER_LEN ];
char * result;
int len;
memcpy( buffer, "segment type data", 17 );
OptionBuffer = buffer + 17;
BufferLeft = CODE_BUFFER_LEN - 18;
if( !ProcessKeyword( DataAttributes ) ) {
Warning( "argument for data statement not valid", OPTION_SLOT );
} else { // get the rest of the attributes.
while( ProcessKeyword( DataAttributes ) ) {} // NULL statement.
if( BufferLeft != CODE_BUFFER_LEN - 18 ) { // attribute spec'd.
len = CODE_BUFFER_LEN - BufferLeft - 1;
result = MemAlloc( CODE_BUFFER_LEN - BufferLeft + 1);
memcpy( result, buffer, len );
*(result + len) = '\0';
AddCommand( result, OPTION_SLOT, FALSE );
}
}
}
static void AddToBuffer( char *cmd, int len )
/*******************************************/
{
if( BufferLeft - (len+1) < 0 ) {
Warning( "too many code attributes", OPTION_SLOT );
} else {
BufferLeft -= len + 1;
*OptionBuffer++ = ' ';
memcpy( OptionBuffer, cmd, len );
OptionBuffer += len;
}
}
static void ProcPreload( void )
/*****************************/
{
AddToBuffer( "preload", 7 );
}
static void ProcLoadOnCall( void )
/********************************/
{
AddToBuffer( "loadoncall", 10 );
}
static void ProcExecuteOnly( void )
/*********************************/
{
AddToBuffer( "executeonly", 11 );
}
static void ProcExecuteRead( void )
/*********************************/
{
AddToBuffer( "executeread", 11 );
}
static void ProcIopl( void )
/**************************/
{
AddToBuffer( "iopl", 4 );
}
static void ProcNoIopl( void )
/****************************/
{
AddToBuffer( "noiopl", 6 );
}
static void ProcConforming( void )
/********************************/
{
AddToBuffer( "conforming", 10 );
}
static void ProcNonConforming( void )
/***********************************/
{
AddToBuffer( "nonconforming", 13 );
}
static void ProcMoveable( void )
/*****************************/
{
AddToBuffer( "moveable", 8 );
ImplyFormat( FMT_WINDOWS );
}
static void ProcFixed( void )
/***************************/
{
AddToBuffer( "fixed", 5 );
ImplyFormat( FMT_WINDOWS );
}
static void ProcDiscardable( void )
/*********************************/
{
AddToBuffer( "discardable", 11 );
ImplyFormat( FMT_WINDOWS );
}
static void ProcNonDiscardable( void )
/************************************/
{
AddToBuffer( "nondiscardable", 14 );
ImplyFormat( FMT_WINDOWS );
// NotNecessary( "nondiscardable" );
}
static void ProcNone( void )
/**************************/
{
AddOption( "noautodata" );
}
static void ProcSingle( void )
/****************************/
{
AddOption( "oneautodata" );
}
static void ProcMultiple( void )
/******************************/
{
AddOption( "manyautodata" );
}
static void ProcReadOnly( void )
/******************************/
{
AddToBuffer( "readonly", 8 );
}
static void ProcReadWrite( void )
/*******************************/
{
AddToBuffer( "readwrite", 9 );
}
static void ProcShared( void )
/****************************/
{
AddToBuffer( "shared", 6 );
}
static void ProcNonShared( void )
/*******************************/
{
AddToBuffer( "nonshared", 11 );
}
static void ProcDescription( void )
/*********************************/
{
#define PREFIX "description '"
char *msg;
MakeToken( SEP_QUOTE, TRUE );
msg = alloca( CmdFile->len + (sizeof( PREFIX ) + 1 ) );
memcpy( msg, PREFIX, sizeof( PREFIX ) );
memcpy( msg + (sizeof( PREFIX )-1), CmdFile->token, CmdFile->len );
strcpy( msg + (sizeof( PREFIX )-1) + CmdFile->len, "'" );
AddOption( msg );
}
static void NullRoutine( void )
/*****************************/
{
}
static void ProcExeType( void )
/*****************************/
{
ProcessKeyword( ExeTypeKeywords ); // skip the keywords
}
static void GetExport( void )
/***************************/
{
char * internal;
int intlen;
char * name;
int namelen;
unsigned long value;
unsigned long iopl;
bool isresident;
bool gottoken;
bool gotnodata;
int toklen;
char * command;
char * currloc;
if( !MakeToken( SEP_NO, TRUE ) ) {
Warning( "invalid export name", OPTION_SLOT );
return;
}
name = alloca( CmdFile->len ); // store it temporarily
toklen = namelen = CmdFile->len;
memcpy( name, CmdFile->token, namelen );
internal = NULL;
if( MakeToken( SEP_EQUALS, TRUE ) ) { // got an internal name.
internal = alloca( CmdFile->len ); // store it temporarily
intlen = CmdFile->len;
memcpy( internal, CmdFile->token, intlen );
toklen += intlen + 1; // +1 for = sign.
}
value = 0xFFFFF; // arbitrary >64K.
if( MakeToken( SEP_AT, TRUE ) ) { // got an ordinal.
if( !GetNumber( &value ) || value > (64*1024UL) ) {
Warning( "export ordinal value is invalid", OPTION_SLOT );
return;
} else {
toklen += 6; // maximum integer length + dot
}
}
isresident = FALSE;
EatWhite();
gottoken = MakeToken( SEP_NO, TRUE );
if( gottoken ) {
if( CmdFile->len == 12 && memicmp(CmdFile->token, "residentname", 12)==0){
isresident = TRUE;
gottoken = MakeToken( SEP_NO, TRUE );
toklen += 9; // length of resident + space.
}
}
gotnodata = FALSE;
if( gottoken ) {
if( memicmp( CmdFile->token, "nodata", 6 ) == 0 ) {
gottoken = MakeToken( SEP_NO, TRUE );
gotnodata = TRUE;
}
}
iopl = 1024; // arbitrary > 63
if( gottoken ) {
if( !GetNumber( &iopl ) || iopl > 63 ) {
Warning( "iopl value is invalid", OPTION_SLOT );
} else {
toklen += 3; // maximum iopl length + space.
}
if( !gotnodata ) {
gottoken = MakeToken( SEP_NO, TRUE );
}
}
if( gottoken && !gotnodata ) {
if( memicmp( CmdFile->token, "nodata", 6 ) == 0 ) {
gotnodata = TRUE;
} else {
CmdFile->current = CmdFile->token; // reparse the token later
}
}
toklen += 8; // export keyword + space + nullchar;
command = MemAlloc( toklen );
memcpy( command, "export ", 7 );
currloc = command + 7;
memcpy( currloc, name, namelen );
currloc += namelen;
if( value <= (64*1024UL) ) { // if an ordinal was specified....
*currloc++ = '.';
utoa( value, currloc, 10 );
while( *currloc != '\0' ) { // find end of string.
currloc++;
}
}
if( internal != NULL ) {
*currloc++ = '=';
memcpy( currloc, internal, intlen );
currloc += intlen;
}
if( isresident ) {
*currloc++ = ' ';
memcpy( currloc, "resident", 8 );
currloc += 8;
}
if( iopl <= 63 ) {
*currloc++ = ' ';
utoa( iopl * 2, currloc, 10 ); // convert iopl value to a byte value
} else {
*currloc = '\0';
}
AddCommand( command, OPTION_SLOT, FALSE );
}
static void ProcExports( void )
/*****************************/
// indicate that a keyword with multiple lines of arguments is to be parsed.
{
MultiLine = GetExport;
}
static void SkipFunction( void )
/******************************/
// this skips a function name
{
MakeToken( SEP_SPACE, TRUE ); // skip a function name
}
static void ProcFunctions( void )
/*******************************/
{
Warning( "Functions style overlay management not directly translatable to watcom", OPTION_SLOT );
MakeToken( SEP_COLON, FALSE ); // skip number.
MultiLine = SkipFunction;
}
static void ProcHeapsize( void )
/******************************/
{
unsigned long value;
if( !MakeToken( SEP_NO, TRUE ) ) {
Warning( "argument for heapsize not recognized", OPTION_SLOT );
} else if( memicmp( CmdFile->token, "maxval", 6 ) == 0 ) {
AddNumOption( "heapsize", 0xFFFF );
} else if( !GetNumber( &value ) || value >= (64*1024UL) ) {
Warning( "argument for heapsize not valid", OPTION_SLOT );
} else {
AddNumOption( "heapsize", value );
}
}
static void GetImport( void )
/***************************/
{
char * first;
int firstlen;
char * second;
int secondlen;
unsigned long value;
char * result;
int toklen;
char * currloc;
if( !MakeToken( SEP_NO, FALSE ) ) {
Warning( "import library name is invalid", OPTION_SLOT );
return;
}
toklen = firstlen = CmdFile->len;
first = alloca( firstlen );
memcpy( first, CmdFile->token, firstlen );
second = NULL;
if( MakeToken( SEP_EQUALS, FALSE ) ) { // got an internal name.
secondlen = CmdFile->len;
second = alloca( secondlen );
memcpy( second, CmdFile->token, secondlen );
toklen += secondlen + 1; // name & = sign.
}
if( !MakeToken( SEP_PERIOD, TRUE ) ) {
Warning( "import entry is invalid", OPTION_SLOT );
return;
}
value = 0xFFFFF; // arbitrary > 64k.
if( GetNumber( &value ) ) {
if( second == NULL ) {
Warning("must have an internal name when an ordinal is specified",
OPTION_SLOT );
return;
} else if( value >= (64*1024UL) ) {
Warning( "import ordinal out of range", OPTION_SLOT );
return;
}
toklen += 6; // maximum size of ordinal + dot.
} else {
toklen += CmdFile->len + 1; // string length + dot.
}
toklen += 8; // import keyword + space + nullchar;
result = MemAlloc( toklen );
memcpy( result, "import ", 7 );
currloc = result + 7;
if( second != NULL ) { // got a internal name in first.
memcpy( currloc, first, firstlen );
currloc += firstlen;
first = second; // make sure module name is in first.
firstlen = secondlen;
} else {
memcpy( currloc, CmdFile->token, CmdFile->len );
currloc += CmdFile->len;
}
*currloc++ = ' ';
memcpy( currloc, first, firstlen ); // module name
currloc += firstlen;
if( value < (64*1024UL) ) {
*currloc++ = '.';
utoa( value, currloc, 10 );
} else {
if( second != NULL ) {
*currloc++ = '.';
memcpy( currloc, CmdFile->token, CmdFile->len );
currloc += CmdFile->len;
}
*currloc = '\0';
}
AddCommand( result, OPTION_SLOT, FALSE );
}
static void ProcImports( void )
/*****************************/
{
MultiLine = GetImport;
}
static void ProcInclude ( void )
/******************************/
{
if( MakeToken( SEP_QUOTE, TRUE ) || MakeToken( SEP_NO, TRUE ) ) {
StartNewFile( ToString() );
ParseDefFile();
} else {
Warning( "invalid include statement", OPTION_SLOT );
}
}
static bool IsInitType( void )
/****************************/
{
if( CmdFile->len == 10 && memicmp( CmdFile->token, "initglobal", 10 )==0 ) {
FmtInfo = DLL_INITGLOBAL;
return( TRUE );
} else if ( CmdFile->len == 12
&& memicmp( CmdFile->token, "initinstance", 12 )==0 ) {
FmtInfo = DLL_INITINSTANCE;
return( TRUE );
}
return( FALSE );
}
static void ProcPrivateLib( void )
/********************************/
{
NotSupported( "privatelib" );
}
static void ProcLibrary( void )
/*****************************/
{
bool gotprivate;
gotprivate = ProcessKeyword( LibraryTypes );
FmtInfo = DLL_INITGLOBAL;
if( !MakeToken( SEP_NO, TRUE ) ) {
return;
}
if( !IsInitType() ) {
if( CmdFile->len > 8 ) {
Warning( "module name too large", OPTION_SLOT );
} else if( GotModName ) {
Warning( "module name multiply defined" , OPTION_SLOT );
} else {
AddStringOption( "modname", CmdFile->token, CmdFile->len );
GotModName = TRUE;
}
if( !MakeToken( SEP_NO, TRUE ) ) {
return;
}
}
if( !IsInitType() ) {
DirectiveError();
}
if( !gotprivate ) {
ProcessKeyword( LibraryTypes );
}
}
static void ProcName( void )
/**************************/
{
int index;
if( !MakeToken( SEP_NO, TRUE ) ) {
return;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?