fmtscan.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 764 行 · 第 1/2 页
C
764 行
FChkDelimiter();
if( FRep() ) {
fmt_width = R_FRPConst();
if( fmt_width > 0 ) {
if( R_FR_Char( '.' ) ) {
fmt_min = R_FConst();
if( ( fmt_width < fmt_min ) || ( fmt_min < 0 ) ) {
R_FError( FM_MODIFIER );
}
} else {
fmt_min = 1;
}
FEmCode( I_FORMAT );
FEmByte( fmt_width );
FEmByte( fmt_min );
}
}
}
static void R_FColon( void ) {
//==========================
// Process a colon.
FNoRep();
FEmCode( C_FORMAT );
Fmt_delimited = YES_DELIM;
}
static void R_FA( void ) {
//======================
// Process an A format code.
int fmt_width;
FChkDelimiter();
if( FRep() ) {
fmt_width = R_FConst();
if( fmt_width == 0 ) {
R_FError( FM_WIDTH );
} else if( fmt_width < 0 ) {
// width of 0 is a flag to indicate that the width corresponds
// to the size of the variable being processed
fmt_width = 0;
}
FEmCode( A_FORMAT );
FEmNum( fmt_width );
}
}
static void R_FT( void ) {
//======================
// Process a T, TL or TR format specifier.
int width;
FChkDelimiter();
if( FNoRep() ) {
if( R_FR_Char( 'l' ) ) {
FEmCode( TL_FORMAT );
} else if( R_FR_Char( 'r' ) ) {
FEmCode( TR_FORMAT );
} else {
FEmCode( T_FORMAT );
}
width = R_FRPConst();
if( width > 0 ) {
FEmNum( width );
}
}
}
static void R_FS( void ) {
//======================
// Process an S, SP or SS format specifier.
FChkDelimiter();
if( FNoRep() ) {
if( R_FR_Char( 'p' ) ) {
FEmCode( SP_FORMAT );
} else if( R_FR_Char( 's' ) ) {
FEmCode( SS_FORMAT );
} else {
FEmCode( S_FORMAT );
}
}
}
static void R_FB( void ) {
//======================
// Process a BN or BZ format specifier.
FChkDelimiter();
if( FNoRep() ) {
if( R_FR_Char( 'n' ) ) {
FEmCode( BN_FORMAT );
} else {
R_FReqChar( 'z', FM_FMTCHAR );
FEmCode( BZ_FORMAT );
}
}
}
static void R_FL( void ) {
//======================
// Process an L format code.
int width;
FChkDelimiter();
if( FRep() ) {
FEmCode( L_FORMAT );
width = R_FRPConst();
if( width > 0 ) {
FEmByte( width );
}
}
}
static void R_FD( void ) {
//======================
// Process a D format code.
FReal( D_FORMAT );
}
static void R_FQ( void ) {
//======================
// Process a Q format code.
R_FExtension( FM_Q_FORMAT );
FReal( Q_FORMAT );
}
static void R_FF( void ) {
//======================
// Process an F format code.
FReal( F_FORMAT );
}
static void R_FE( void ) {
//======================
// Process an E format code.
FReal( E_FORMAT );
}
static void R_FG( void ) {
//======================
// Process a G format code.
FReal( G_FORMAT );
}
static void FReal( byte format_code ) {
//=========================================
// Process an F, D, Q, E or G format code.
int fmt_width;
int fmt_modifier;
int fmt_exp;
if( Fmt_delimited == NO_DELIM ) {
R_FExtension( FM_ASSUME_COMMA );
}
Fmt_delimited = NO_DELIM;
if( !FRep() ) return;
fmt_width = R_FRPConst();
if( fmt_width <= 0 ) return;
if( !R_FReqChar( '.', FM_DECIMAL ) ) return;
fmt_modifier = R_FConst();
if( ( fmt_modifier < 0 ) || ( fmt_width < fmt_modifier ) ) {
R_FError( FM_MODIFIER );
return;
}
if( ( format_code == E_FORMAT ) || ( format_code == G_FORMAT ) ) {
fmt_exp = 0;
if( isalpha( *Fmt_charptr ) ) {
if( ( format_code == E_FORMAT ) || R_FR_Char( 'e' ) ) {
if( format_code == E_FORMAT ) {
if( !R_FR_Char( 'e' ) ) {
if( !R_FR_Char( 'd' ) ) {
if( !R_FReqChar( 'q', FM_FMTCHAR ) ) return;
format_code = EQ_FORMAT;
R_FExtension( FM_Q_EXT );
} else {
format_code = ED_FORMAT;
R_FExtension( FM_D_EXT );
}
}
}
fmt_exp = R_FRPConst();
if( fmt_exp <= 0 ) return;
if( fmt_width < fmt_modifier ) {
R_FError( FM_MODIFIER );
}
}
}
}
FEmCode( format_code );
FEmByte( fmt_width );
FEmByte( fmt_modifier );
if( ( format_code == E_FORMAT ) || ( format_code == ED_FORMAT ) ||
( format_code == EQ_FORMAT ) || ( format_code == G_FORMAT ) ) {
FEmByte( fmt_exp );
}
}
static void R_FP( void ) {
//======================
// Process a P format delimiter/code.
// Note that Fmt_rep_spec represents the scale factor.
FChkDelimiter();
Fmt_delimited = P_DELIM;
FEmCode( P_FORMAT );
FEmNum( Fmt_rep_spec );
}
static void R_FLParen( void ) {
//===========================
// Process a left parenthesis.
FChkDelimiter();
if( Fmt_paren_level < 2 ) {
if( Fmt_rep_spec == 0 ) {
R_FError( FM_INV_REP );
} else if( Fmt_rep_spec > 1 ) {
FEmCode( REP_FORMAT | REV_CODE );
FEmNum( Fmt_rep_spec );
FEmCode( LP_FORMAT );
} else {
FEmCode( LP_FORMAT | REV_CODE );
}
} else {
FRep();
FEmCode( LP_FORMAT );
}
++Fmt_paren_level;
++Fmt_charptr;
if( R_FR_Char( ',' ) ) {
R_FError( FM_DELIM );
}
R_FSpec();
}
static void R_FZ( void ) {
//======================
// Process a z format code (extension).
int width;
FChkDelimiter();
if( FRep() ) {
width = R_FConst();
if( width == 0 ) {
R_FError( FM_WIDTH );
} else if( width < 0 ) {
// width of 0 is a flag to indicate that the width corresponds
// to the size of the variable being processed
width = 0;
}
FEmCode( Z_FORMAT );
FEmByte( width );
R_FExtension( FM_Z_EXT );
}
}
static void R_FM( void ) {
//======================
// Process a $ format code (extension).
FChkDelimiter();
FNoRep();
FEmCode( M_FORMAT );
R_FExtension( FM_M_EXT );
}
static void FChkDelimiter( void ) {
//===============================
// Make sure that an element has been delimited.
// Return TRUE if the element was delimited.
if( Fmt_delimited != YES_DELIM ) {
R_FExtension( FM_ASSUME_COMMA );
}
Fmt_delimited = NO_DELIM;
}
static const f_procs __FAR FP_Cod[] = {
'\'', &R_FLiteral,
'f', &R_FF,
'e', &R_FE,
'd', &R_FD,
'g', &R_FG,
'q', &R_FQ,
'h', &R_FH,
'l', &R_FL,
',', &R_FComma,
'/', &R_FSlash,
'x', &R_FX,
'i', &R_FI,
'(', &R_FLParen,
'a', &R_FA,
't', &R_FT,
's', &R_FS,
'b', &R_FB,
'p', &R_FP,
':', &R_FColon,
'$', &R_FM,
'\\', &R_FM,
'z', &R_FZ,
NULLCHAR, NULL
};
static void FCode( void ) {
//=======================
// Process a format code.
char current;
const f_procs __FAR *f_rtn;
if( R_FRecEos() ) {
R_FError( FM_FMTCHAR );
return;
}
current = tolower( *Fmt_charptr );
f_rtn = FP_Cod;
for(;;) {
if( f_rtn->code == NULLCHAR ) {
R_FError( FM_FMTCHAR );
return;
}
if( f_rtn->code == current ) break;
f_rtn++;
}
if( ( current != '\'' ) && ( current != '(' ) ) {
++Fmt_charptr;
if( current != 'h' ) {
FSkipSpaces();
}
}
f_rtn->routine();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?