Example #1
0
/* Compile a string */
void compile_string(compiler_type *comp_void, char *str, bool include_baselib) {
  compiler_core_type *compiler = (compiler_core_type *)comp_void;
  ins_stream_type *baselib = 0; /* TODO: should be gc root */
  char path[PATH_MAX];

  /* Actually parse the input stream. */
  yylex_init_extra(compiler, &(compiler->scanner));
  yy_scan_string(str, compiler->scanner);

  /* TODO: Need a better way to handle GC than leaking */
  gc_protect(compiler->gc);

  /* Inject include for base library */
  if (include_baselib) {
    strcpy(path, compiler->home);
    strcat(path, "/lib/baselib.scm");

    STREAM_NEW(baselib, string, path);
    setup_include(compiler, baselib); 
  }
  
  parse_internal(compiler, compiler->scanner);
  
  gc_unprotect(compiler->gc);

  yylex_destroy(compiler->scanner);
}
Example #2
0
bool FeMameXMLParser::parse( const std::string &prog )
{
	std::string base_args = "-listxml";
	FeRomInfoListType::iterator itr;
	m_percent=m_count=0;

	// special case for mess parsing
	if ( m_ctx.romlist.size() == 1 )
		return ( parse_internal( prog, base_args + " " + m_ctx.romlist.front().get_info( FeRomInfo::Romname ) ) );

	//
	// run "mame -listxml" and find each rom.
	//
	m_map.clear();
	for ( FeRomInfoListType::iterator itr=m_ctx.romlist.begin();
			itr != m_ctx.romlist.end(); ++itr )
		m_map[ (*itr).get_info( FeRomInfo::Romname ).c_str() ] = itr;

	std::cout << "    ";

	if ( parse_internal( prog, base_args ) == false )
	{
		std::cout << std::endl;
		return false;
	}

	std::cout << std::endl;

	if ( !m_discarded.empty() )
	{
		std::cout << " - Discarded " << m_discarded.size()
				<< " entries based on xml info: ";
		std::vector<FeRomInfoListType::iterator>::iterator itr;
		for ( itr = m_discarded.begin(); itr != m_discarded.end(); ++itr )
		{
			std::cout << (*(*itr)).get_info( FeRomInfo::Romname ) << " ";
			m_ctx.romlist.erase( (*itr) );
		}
		std::cout << std::endl;
	}

	return true;
}
Example #3
0
/* Parse used by load */
object_type *parse_chain(interp_core_type *interp) {
    reset(interp);
    
    if(!interp->scanner) {
	create_parser(interp);
    }
    
    if(parse_internal(interp, peek_scanner)) {
	return 0;
    }

    return interp->added;
}
Example #4
0
/* Parse a string */
object_type *parse_string(interp_core_type *interp, char *in) {
    reset(interp);

    if(!interp->scanner) {
	create_parser(interp);
    }
    
    yy_scan_string(in, peek_scanner);
    
    if(parse_internal(interp, peek_scanner)) {
	return 0;
    }

    TRACE("\n")
    
    return interp->added;
}
Example #5
0
/* Parse a file */
object_type *parse(interp_core_type *interp, FILE *in) {
    reset(interp);
    
    if(!interp->scanner) {
	create_parser(interp);
    }
    
    yyset_in(in, peek_scanner);
    
    if(parse_internal(interp, peek_scanner)) {
	return 0;
    }

    TRACE("\n")
    
    return interp->added;
}
Example #6
0
/* Compile a file */
void compile_file(compiler_type *comp_void, char *file_name, bool include_baselib) {
  compiler_core_type *compiler = (compiler_core_type *)comp_void;
  ins_stream_type *baselib = 0; /* TODO: should be gc root */
  FILE *in = 0;
  char path[PATH_MAX];

  /* Actually parse the input stream. */
  yylex_init_extra(compiler, &(compiler->scanner));

  in = fopen(file_name, "r");
  if (!in) {
    (void)fprintf(stderr, "Error %i while attempting to open '%s'\n",
      errno, file_name);
      assert(0);
  }

  //yyset_in(in, compiler->scanner);
  yy_switch_to_buffer(
    yy_create_buffer(in, YY_BUF_SIZE, compiler->scanner), compiler->scanner);

  push_include_path(compiler, file_name);

  /* TODO: Need a better way to handle GC than leaking */
  gc_protect(compiler->gc);

  /* Inject include for base library */
  if (include_baselib) {
    strcpy(path, compiler->home);
    strcat(path, "/lib/baselib.scm");

    STREAM_NEW(baselib, string, path);
    setup_include(compiler, baselib); 
  }
  
  parse_internal(compiler, compiler->scanner);
  
  gc_unprotect(compiler->gc);

  yylex_destroy(compiler->scanner);
}
Example #7
0
/* static */
bool fx_ver_t::parse(const pal::string_t& ver, fx_ver_t* fx_ver, bool parse_only_production)
{
    bool valid = parse_internal(ver, fx_ver, parse_only_production);
    assert(!valid || fx_ver->as_str() == ver);
    return valid;
}
Example #8
0
bool FeMessXMLParser::parse( const std::string &prog,
		const std::vector < std::string > &system_names )
{
	// First get our machine -listxml settings
	//
	std::string system_name;
	FeRomInfoListType::iterator itr;

	for ( std::vector<std::string>::const_iterator its=system_names.begin(); its!=system_names.end(); ++its )
	{
		FeRomInfoListType temp_list;
		temp_list.push_back( FeRomInfo( *its ) );

		FeEmulatorInfo ignored;
		FeImporterContext temp( ignored, temp_list );
		FeMameXMLParser listxml( temp );

		if (( listxml.parse( prog ) )
				&& ( !temp_list.empty() ))
		{
			const FeRomInfo &ri = temp_list.front();
			for ( itr=m_ctx.romlist.begin(); itr!=m_ctx.romlist.end(); ++itr )
			{
				(*itr).set_info( FeRomInfo::Players, ri.get_info( FeRomInfo::Players ));
				(*itr).set_info( FeRomInfo::Rotation, ri.get_info( FeRomInfo::Rotation ));
				(*itr).set_info( FeRomInfo::Control, ri.get_info( FeRomInfo::Control ));
				(*itr).set_info( FeRomInfo::Status, ri.get_info( FeRomInfo::Status ));
				(*itr).set_info( FeRomInfo::DisplayCount, ri.get_info( FeRomInfo::DisplayCount ));
				(*itr).set_info( FeRomInfo::DisplayType, ri.get_info( FeRomInfo::DisplayType ));

				// A bit of a hack here: the Category field gets repurposed for this stage of a MESS
				// import...We temporarily store a "fuzzy" match romname
				//
				(*itr).set_info( FeRomInfo::BuildScratchPad,
							get_fuzzy( (*itr).get_info( FeRomInfo::Romname ) ) );
			}
			system_name=(*its);
			break;
		}
	}

	if ( system_name.empty() )
	{
		std::cerr << " * Error: No system identifier found that is recognized by MESS -listxml" << std::endl;
		return false;
	}

	std::cout << " - Obtaining -listsoftware info [" << system_name << "]" << std::endl;

	// Now get the individual game -listsoftware settings
	//
	int retval=parse_internal( prog, system_name + " -listsoftware" );

	if ( !retval )
	{
		std::cout << " * Error: No XML output found, command: " << prog << " "
					<< system_name + " -listsoftware" << std::endl;
	}

	// We're done with our "fuzzy" matching, so clear where we were storing them
	//
	for ( itr=m_ctx.romlist.begin(); itr!=m_ctx.romlist.end(); ++itr )
		(*itr).set_info( FeRomInfo::BuildScratchPad, "" );

	return retval;
}