示例#1
0
/* output import stubs for exported entry points that link to external symbols */
static void output_external_link_imports( DLLSPEC *spec )
{
    unsigned int i, pos;

    if (!ext_link_imports.count) return;  /* nothing to do */

    sort_names( &ext_link_imports );

    /* get rid of duplicate names */
    for (i = 1; i < ext_link_imports.count; i++)
    {
        if (!strcmp( ext_link_imports.names[i-1], ext_link_imports.names[i] ))
            remove_name( &ext_link_imports, i-- );
    }

    output( "\n/* external link thunks */\n\n" );
    output( "\t.data\n" );
    output( "\t.align %d\n", get_alignment(get_ptr_size()) );
    output( ".L__wine_spec_external_links:\n" );
    for (i = 0; i < ext_link_imports.count; i++)
        output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports.names[i]) );

    output( "\n\t.text\n" );
    output( "\t.align %d\n", get_alignment(get_ptr_size()) );
    output( "%s:\n", asm_name("__wine_spec_external_link_thunks") );

    for (i = pos = 0; i < ext_link_imports.count; i++)
    {
        char *buffer = strmake( "__wine_spec_ext_link_%s", ext_link_imports.names[i] );
        output_import_thunk( buffer, ".L__wine_spec_external_links", pos );
        free( buffer );
        pos += get_ptr_size();
    }
    output_function_size( "__wine_spec_external_link_thunks" );
}
示例#2
0
int
main(int argc, char **argv)
{ int i;
  const char *program = argv[0];
  FILE *ic, *ih;

  argc--;				/* skip program */
  argv++;
  if ( argc < 3 || strcmp(argv[2], "--") )
  { fprintf(stderr, "Usage: %s ic-file ih-file -- file ...\n", program);
    exit(1);
  }

  if ( !(ic = fopen(argv[0], "w")) ||
       !(ih = fopen(argv[1], "w")) )
  { fprintf(stderr, "%s: Could not open output\n", program);
    exit(1);
  }

  argc -= 3;
  argv += 3;

  for(i=1; i<argc; i++)
    scan_file(argv[i]);

  sort_names();
  emit_names(ic, ih);

  fclose(ic);
  fclose(ih);

  return 0;
}
示例#3
0
文件: main.c 项目: acraig5075/euler
int main(int argc, char *argv[])
	{
	char **names = (char **)malloc(sizeof(char *) * NAME_COUNT);
	for (int j = 0; j < NAME_COUNT; j++)
		names[j] = (char *)malloc(sizeof(char) * MAX_LENGTH);

	const char *filename = "names.txt";
	if (!read_file(filename, names))
		return 1;

	sort_names(names);

	long score = total_score(names);
	printf("%ld\n", score);

	return 0;
	}
示例#4
0
/* resolve the imports for a Win32 module */
void resolve_imports( DLLSPEC *spec )
{
    int i;
    unsigned int j, removed;
    ORDDEF *odp;

    check_undefined_forwards( spec );

    for (i = 0; i < nb_imports; i++)
    {
        struct import *imp = dll_imports[i];

        for (j = removed = 0; j < undef_symbols.count; j++)
        {
            odp = find_export( undef_symbols.names[j], imp->exports, imp->nb_exports );
            if (odp)
            {
                if (odp->flags & FLAG_PRIVATE) continue;
                if (odp->type != TYPE_STDCALL && odp->type != TYPE_CDECL)
                    warning( "winebuild: Data export '%s' cannot be imported from %s\n",
                             odp->link_name, imp->spec->file_name );
                else
                {
                    add_import_func( imp, odp );
                    remove_name( &undef_symbols, j-- );
                    removed++;
                }
            }
        }
        if (!removed)
        {
            /* the dll is not used, get rid of it */
            if (check_unused( imp, spec ))
                warning( "winebuild: %s imported but no symbols used\n", imp->spec->file_name );
            remove_import_dll( i );
            i--;
        }
    }

    sort_names( &undef_symbols );
    check_undefined_exports( spec );
}
示例#5
0
/*******************************************************************
 *         ParseTopLevel
 *
 * Parse a spec file.
 */
SPEC_TYPE ParseTopLevel( FILE *file )
{
    const char *token;

    input_file = file;
    current_line = 1;
    while ((token = GetToken(1)) != NULL)
    {
        if (strcmp(token, "name") == 0)
        {
            strcpy(DLLName, GetToken(0));
        }
        else if (strcmp(token, "file") == 0)
        {
            strcpy(DLLFileName, GetToken(0));
        }
        else if (strcmp(token, "type") == 0)
        {
            token = GetToken(0);
            if (!strcmp(token, "win16" )) SpecType = SPEC_WIN16;
            else if (!strcmp(token, "win32" )) SpecType = SPEC_WIN32;
            else fatal_error( "Type must be 'win16' or 'win32'\n" );
        }
        else if (strcmp(token, "mode") == 0)
        {
            token = GetToken(0);
            if (!strcmp(token, "dll" )) SpecMode = SPEC_MODE_DLL;
            else if (!strcmp(token, "guiexe" )) SpecMode = SPEC_MODE_GUIEXE;
            else if (!strcmp(token, "cuiexe" )) SpecMode = SPEC_MODE_CUIEXE;
            else if (!strcmp(token, "guiexe_unicode" )) SpecMode = SPEC_MODE_GUIEXE_UNICODE;
            else if (!strcmp(token, "cuiexe_unicode" )) SpecMode = SPEC_MODE_CUIEXE_UNICODE;
            else fatal_error( "Mode must be 'dll', 'guiexe', 'cuiexe', 'guiexe_unicode' or 'cuiexe_unicode'\n" );
        }
        else if (strcmp(token, "heap") == 0)
        {
            token = GetToken(0);
            if (!IsNumberString(token)) fatal_error( "Expected number after heap\n" );
            DLLHeapSize = atoi(token);
        }
        else if (strcmp(token, "stack") == 0)
        {
            token = GetToken(0);
            if (!IsNumberString(token)) fatal_error( "Expected number after stack\n" );
            stack_size = atoi(token);
        }
        else if (strcmp(token, "imagesize") == 0)
        {
            token = GetToken(0);
            if (!IsNumberString(token)) fatal_error( "Expected number after imagesize\n" );
            size_of_image = atoi(token);
        }
        else if (strcmp(token, "init") == 0)
        {
            if (SpecType == SPEC_WIN16)
                fatal_error( "init cannot be used for Win16 spec files\n" );
            init_func = xstrdup( GetToken(0) );
        }
        else if (strcmp(token, "DelayElfInitialization") == 0)
        {
            delay_initialization = 1;
        }
        else if (strcmp(token, "import") == 0)
        {
            const char* name;
            int delay = 0;

            if (SpecType != SPEC_WIN32)
                fatal_error( "Imports not supported for Win16\n" );
            name = GetToken(0);
            if (*name == '-')
            {
                name = GetToken(0);
                if (!strcmp(name, "delay"))
                {

                    name = GetToken(0);
#ifndef __PPC__
                    delay = 1;
#else
                    warning( "The 'delay' option is not yet supported on the PPC. 'delay' will be ignored.\n");
#endif /* __PPC__ */
                }
                else fatal_error( "Unknown option '%s' for import directive\n", name );
            }
            add_import_dll( name, delay );
        }
        else if (strcmp(token, "rsrc") == 0)
        {
            if (SpecType != SPEC_WIN16) load_res32_file( GetToken(0) );
            else load_res16_file( GetToken(0) );
        }
        else if (strcmp(token, "owner") == 0)
        {
            if (SpecType != SPEC_WIN16)
                fatal_error( "Owner only supported for Win16 spec files\n" );
            strcpy( owner_name, GetToken(0) );
        }
        else if (strcmp(token, "debug_channels") == 0)
        {
            if (SpecType != SPEC_WIN32)
                fatal_error( "debug channels only supported for Win32 spec files\n" );

            ParseDebug();
         }
        else if (strcmp(token, "ignore") == 0)
        {
            if (SpecType != SPEC_WIN32)
                fatal_error( "'ignore' only supported for Win32 spec files\n" );
            ParseIgnore();
        }
        else if (strcmp(token, "@") == 0)
        {
            if (SpecType != SPEC_WIN32)
                fatal_error( "'@' ordinals not supported for Win16\n" );
            ParseOrdinal( -1 );
        }
        else if (IsNumberString(token))
        {
            ParseOrdinal( atoi(token) );
        }
        else
            fatal_error( "Expected name, id, length or ordinal\n" );
    }


    if (SpecType == SPEC_WIN32)
    {
        extern void imports_debugchannels( );
        imports_debugchannels( );
    }



    if (!DLLFileName[0])
    {
        if (SpecMode == SPEC_MODE_DLL)
        {
            strcpy( DLLFileName, DLLName );
            /* Append .dll to name if no extension present */
            if (!strrchr( DLLFileName, '.'))
                strcat( DLLFileName, ".dll" );
        }
        else
            sprintf( DLLFileName, "%s.exe", DLLName );
    }

    if (SpecType == SPEC_INVALID) fatal_error( "Missing 'type' declaration\n" );
    if (SpecType == SPEC_WIN16 && !owner_name[0])
        fatal_error( "'owner' not specified for Win16 dll\n" );

    current_line = 0;  /* no longer parsing the input file */
    sort_names();
    return SpecType;
}