Exemplo n.º 1
0
TOKEN ChkControl( void )
{
    int         lines_skipped;
    ppctl_t     old_ppctl;

    if( !CompFlags.doing_macro_expansion ) {
        if( CompFlags.cpp_output ) {
            PrintWhiteSpace = FALSE;
        }
    }
    while( CurrChar == '\n' ) {
        if( TBreak() ) {
            CErr1( ERR_BREAK_KEY_HIT );
            CSuicide();
        }
        lines_skipped = 0;
        old_ppctl = CompFlags.pre_processing;
        for( ; CurrChar != EOF_CHAR; ) {
            if( CompFlags.cpp_output ) {
                CppPrtChar( '\n' );
            }
            NextChar();
            if( CurrChar != PreProcChar ) {
                SkipAhead();
            }
            if( CurrChar == EOF_CHAR )
                break;
            if( CurrChar == PreProcChar ) { /* start of comp control line */
                PPCTL_ENABLE_EOL();
                PPCTL_DISABLE_MACROS();
                PreProcStmt();
                PPFlush2EOL();
                CompFlags.pre_processing = old_ppctl;
            } else if( NestLevel != SkipLevel ) {
                PPCTL_ENABLE_EOL();
                PPCTL_DISABLE_MACROS();
                PPNextToken();              /* get into token mode */
                PPFlush2EOL();
                CompFlags.pre_processing = old_ppctl;
            }
            if( NestLevel == SkipLevel )
                break;
            if( CurrChar == '\n' ) {
                lines_skipped = 1;
            }
        }
        if( CompFlags.cpp_output ) {
            if( lines_skipped ) {
                if( SrcFile != NULL ) {                 /* 14-may-92 */
                    EmitLine( SrcFile->src_loc.line, SrcFile->src_name );
                }
            }
        }
    }
    // we have already skipped past all white space at the start of the line
    CurToken = T_WHITE_SPACE;
//  CurToken = ScanToken();
    return( T_WHITE_SPACE );
}
Exemplo n.º 2
0
local void CLine( void )
{
    FNAMEPTR        flist;
    unsigned long   src_line;

    src_line = 0;
    PPCTL_ENABLE_MACROS();
    PPNextToken();
    if( ExpectingConstant() ) {
        if( CompFlags.cpp_ignore_line == 0 ) {
            src_line = Constant; // stash in case of side effects
            SrcFile->src_loc.line = src_line - 1; /* don't count this line */
        }
        PPNextToken();
        if( CurToken == T_NULL ) {
            if( CompFlags.cpp_ignore_line == 0 ) {
                if( CompFlags.cpp_output ) {
                    EmitLine( src_line, SrcFile->src_name );
                }
            }
        } else {
            if( ExpectingToken( T_STRING ) ) {
                if( CompFlags.wide_char_string ) {
                    /* wide char string not allowed */
                    ExpectString();
                } else {
                    if( CompFlags.cpp_ignore_line == 0 ) {
                        // RemoveEscapes( Buffer );
                        flist = AddFlist( Buffer );
                        flist->rwflag = FALSE;  // not a real file so no autodep
                        SrcFile->src_name = flist->name;
                        SrcFile->src_loc.fno  = flist->index;
                        if( CompFlags.cpp_output ) {
                            EmitLine( src_line, SrcFile->src_name );
                        }
                    }
                }
            }
            PPNextToken();
            ChkEOL();
        }
    }
    PPCTL_DISABLE_MACROS();
}
Exemplo n.º 3
0
void  FindSrcLine( uint_32 addr )
/*******************************/
{
    line_num            *line;
    line_num            *check;
    unsigned            next;
    int                 len;
    char                txt_line[ MAX_LINE_LEN + 1 ];

    line = Mod->src_rover;
    if( line == NULL ) return;
    if( line->seg != Segment ) {
        if( Segment->src_done )
            return;
        check = line;
        for( ;; ) {
           check = check->next_num;
           if( check == NULL ) {
               Segment->src_done = true;
               return;
           }
           if( check->seg == Segment ) break;
        }
        FlipToSeg( line->seg );
        return;
    }
    if( line->address > addr ) return;

    if( addr == Segment->start && LastNum <= 1 ) {
        if( line->next_num == NULL ) {
            next = UINT_MAX;
        } else {
            next = line->next_num->num;
        }
    } else if( addr == Segment->size ) {
        for( ;; ) {
            if( line == NULL ) break;
            if( line->seg != Segment ) break;
            line = line->next_num;
        }
    } else {
        next = LastNum;
        for( ;; ) {
            if( line == NULL ) return;
            if( line->seg != Segment ) return;
            if( line->address == addr ) break;
            line = line->next_num;
        }
        for( ;; ) {
            line = line->next_num;
            if( line == NULL ) {
                next = UINT_MAX;
                break;
            }
            if( line->num < next ) continue;
            next = line->num;
            if( line->seg != Segment ) break;
            if( line->address > addr ) break;
        }
    }
    Mod->src_rover = line;
    EmitNL();
    for( ;; ) {
        if( LastNum + 1 >= next ) return;
        len = FGetTxtRec( Source, txt_line, MAX_LINE_LEN );
        txt_line[ len ] = NULLCHAR;
        if( feof( Source ) ) break;
        if( Options & FORM_ASSEMBLER ) {
            if( DO_UNIX ) {
                Emit( "/ " );
            } else {
                Emit( "; " );
            }
        }
        EmitLine( txt_line );
        ++LastNum;
    }
    if( next != UINT_MAX ) {
        DoEmitError( ERR_EOF_ENCOUNTERED );
    }
}
Exemplo n.º 4
0
	bool MTLParser::Save(Stream& stream) const
	{
		m_currentStream = &stream;

		// Force stream in text mode, reset it at the end
		Nz::CallOnExit resetTextMode;
		if ((stream.GetStreamOptions() & StreamOption_Text) == 0)
		{
			stream.EnableTextMode(true);

			resetTextMode.Reset([&stream] ()
			{
				stream.EnableTextMode(false);
			});
		}

		m_outputStream.Clear();

		EmitLine("# Exported by Nazara Engine");
		EmitLine();

		Emit("# material count: ");
		Emit(m_materials.size());
		EmitLine();

		for (auto& pair : m_materials)
		{
			const String& matName = pair.first;
			const Material& mat = pair.second;

			Emit("newmtl ");
			EmitLine(matName);
			EmitLine();

			Emit("Ka ");
			Emit(mat.ambient.r / 255.f);
			Emit(' ');
			Emit(mat.ambient.g / 255.f);
			Emit(' ');
			Emit(mat.ambient.b / 255.f);
			EmitLine();

			Emit("Kd ");
			Emit(mat.diffuse.r / 255.f);
			Emit(' ');
			Emit(mat.diffuse.g / 255.f);
			Emit(' ');
			Emit(mat.diffuse.b / 255.f);
			EmitLine();

			Emit("Ks ");
			Emit(mat.specular.r / 255.f);
			Emit(' ');
			Emit(mat.specular.g / 255.f);
			Emit(' ');
			Emit(mat.specular.b / 255.f);
			EmitLine();

			if (!NumberEquals(mat.alpha, 1.f))
			{
				Emit("d ");
				EmitLine(mat.alpha);
			}

			if (!NumberEquals(mat.refractionIndex, 1.f))
			{
				Emit("ni ");
				EmitLine(mat.refractionIndex);
			}

			if (!NumberEquals(mat.shininess, 1.f))
			{
				Emit("ns ");
				EmitLine(mat.shininess);
			}

			if (mat.illumModel != 0)
			{
				Emit("illum ");
				EmitLine(mat.illumModel);
			}

			if (!mat.ambientMap.IsEmpty())
			{
				Emit("map_Ka ");
				EmitLine(mat.ambientMap);
			}

			if (!mat.diffuseMap.IsEmpty())
			{
				Emit("map_Kd ");
				EmitLine(mat.diffuseMap);
			}

			if (!mat.specularMap.IsEmpty())
			{
				Emit("map_Ks ");
				EmitLine(mat.specularMap);
			}

			if (!mat.bumpMap.IsEmpty())
			{
				Emit("map_bump ");
				EmitLine(mat.bumpMap);
			}

			if (!mat.alphaMap.IsEmpty())
			{
				Emit("map_d ");
				EmitLine(mat.alphaMap);
			}

			if (!mat.decalMap.IsEmpty())
			{
				Emit("map_decal ");
				EmitLine(mat.decalMap);
			}

			if (!mat.displacementMap.IsEmpty())
			{
				Emit("map_disp ");
				EmitLine(mat.displacementMap);
			}

			if (!mat.reflectionMap.IsEmpty())
			{
				Emit("map_refl ");
				EmitLine(mat.reflectionMap);
			}
			EmitLine();
		}

		Flush();

		return true;
	}
Exemplo n.º 5
0
void  EmitModule()
/****************/

{
    char                *name;
    import_sym          *imp;
    char                sp_buf[ _MAX_PATH2 ];
    char                *root_name;

    if( ( Options & FORM_ASSEMBLER ) == 0 ) {
        EmitNL();
        DoEmit( MSG_MODULE );
        EmitLine( Mod->name );
        if( Mod->main ) {
            EmitLine( "MAIN MODULE " );
        }
        if( Mod->start != NULL ) {
            DoEmit( MSG_START_ADDR );
            name = GetFixName( Mod->start );
            if( name == NULL ) {
                name = NewName( Mod->start );
            }
            Emit( name );
            EmitNL();
        }
    } else {
        _splitpath2( Mod->name, sp_buf, NULL, NULL, &root_name, NULL );
        if( DO_UNIX ) {
            EmitBlanks( LABEL_LEN );
            EmitSpaced( ".file", OPCODE_LEN );
            Emit( "\"" );
            Emit( root_name );
            Emit( "\"" );
            EmitNL();
        } else {
            if( RetFarUsed ) {
                EmitRetFMacro();
            }
            if( Is32BitObj ) EmitLine( ".386p" );
            EmitBlanks( LABEL_LEN );
            EmitSpaced( "NAME", OPCODE_LEN );
            EmitLine( root_name );
        }
        if( ( Options & FORM_DO_WTK )  &&  HaveWtk() ) {
            Emit( "INCLUDE" );
            EmitBlanks( LABEL_LEN - 7 );
            EmitLine( "67MACROS.EQU" );
        }
    }
    for( imp = Mod->imports; imp != NULL; imp = imp->next_imp ) {
        switch( imp->class ) {
        case TYPE_IMPORT:
            if( !DO_UNIX
                && ( Options & FORM_ASSEMBLER )
                && imp->public
                && !imp->exported
                && strcmp( imp->name, WTLBASEStr ) != 0 ) {
                EmitBlanks( LABEL_LEN );
                EmitSpaced( "EXTRN", OPCODE_LEN );
                EmitSym( imp->name, 0 );
                Emit( ":BYTE" );        // so that output would assemble
                EmitNL();
            }
            break;
        case TYPE_COMDEF:
            if( DO_UNIX ) {
                if( imp->public ) {
                    EmitBlanks( LABEL_LEN );
                    EmitSpaced( ".globl", OPCODE_LEN );
                    EmitLine( imp->name );
                }
                EmitBlanks( LABEL_LEN );
                EmitSpaced( ".lcomm", OPCODE_LEN );
                EmitSym( imp->name, 0 );
                Emit( ", " );
            } else {
                if( imp->public ) {
                    EmitBlanks( LABEL_LEN );
                    EmitSpaced( "COMM", OPCODE_LEN );
                } else {
                    if( Options & FORM_ASSEMBLER ) {
                        DoEmitError( MSG_LCL_COMM_WONT_ASM );
                    }
                    EmitBlanks( LABEL_LEN );
                    EmitSpaced( "LCOMM", OPCODE_LEN );
                }
                if( imp->far_common ) {
                    Emit( "FAR  " );
                } else {
                    Emit( "NEAR " );
                }
                EmitSym( imp->name, 0 );
                Emit( ":BYTE:" );
            }
            EmitHex( imp->u.size );
            EmitNL();
            break;
        }