File: libres.c

package info (click to toggle)
wine 0.0.20000109-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 22,652 kB
  • ctags: 59,973
  • sloc: ansic: 342,054; perl: 3,697; yacc: 3,059; tcl: 2,647; makefile: 2,466; lex: 1,494; sh: 394
file content (109 lines) | stat: -rw-r--r-- 2,625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * WINElib-Resources
 *
 * Copied and modified heavily from loader/resource.c
 */

#include <stdlib.h>
#include "wine/winestring.h"
#include "libres.h"
#include "resource.h"
#include "debugtools.h"
#include "heap.h"
#include "crtdll.h"
#include "xmalloc.h"

DEFAULT_DEBUG_CHANNEL(resource)

typedef struct RLE
{
    const wrc_resource32_t * const * Resources;  /* NULL-terminated array of pointers */
    struct RLE* next;
} ResListE;

static ResListE* ResourceList=NULL;

void LIBRES_RegisterResources(const wrc_resource32_t * const * Res)
{
  ResListE** Curr;
  ResListE* n;
  for(Curr=&ResourceList; *Curr; Curr=&((*Curr)->next)) { }
  n=xmalloc(sizeof(ResListE));
  n->Resources=Res;
  n->next=NULL;
  *Curr=n;
}

/**********************************************************************
 *	    LIBRES_FindResource
 */
typedef int (*CmpFunc_t)(LPCWSTR a, LPCWSTR b, int c);

int CompareOrdinal(LPCWSTR ordinal, LPCWSTR resstr, int resid)
{
    return !resstr && (resid == LOWORD(ordinal));
} 
	
int CompareName(LPCWSTR name, LPCWSTR resstr, int resid)
{
    return resstr && !CRTDLL__wcsnicmp(resstr+1, name, *(resstr));
}

HRSRC LIBRES_FindResource( HINSTANCE hModule, LPCWSTR name, LPCWSTR type )
{
  LPCWSTR nameid = name, typeid = type;
  ResListE* ResBlock;
  const wrc_resource32_t* const * Res;
  CmpFunc_t EqualNames = CompareOrdinal;
  CmpFunc_t EqualTypes = CompareOrdinal;

  if(HIWORD(name))
  {
    if(*name=='#')
    {
        LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
        nameid = (LPCWSTR) atoi(nameA+1);
        HeapFree( GetProcessHeap(), 0, nameA );
    }
  else
	EqualNames = CompareName;
  }

  if(HIWORD(type))
  {
    if(*type=='#')
    {
        LPSTR typeA = HEAP_strdupWtoA( GetProcessHeap(), 0, type );
        typeid= (LPCWSTR) atoi(typeA+1);
        HeapFree( GetProcessHeap(), 0, typeA );
    }
    else
	EqualTypes = CompareName;
  }
  
  for(ResBlock=ResourceList; ResBlock; ResBlock=ResBlock->next)
    for(Res=ResBlock->Resources; *Res; Res++)
	if (EqualNames(nameid, (*Res)->resname, (*Res)->resid) && 
		EqualTypes(typeid, (*Res)->restypename, (*Res)->restype))
	  return (HRSRC)*Res;

  return 0;
}


/**********************************************************************
 *	    LIBRES_LoadResource    
 */
HGLOBAL LIBRES_LoadResource( HINSTANCE hModule, HRSRC hRsrc )
{
  return (HGLOBAL)(((wrc_resource32_t*)hRsrc)->data);
}


/**********************************************************************
 *	    LIBRES_SizeofResource    
 */
DWORD LIBRES_SizeofResource( HINSTANCE hModule, HRSRC hRsrc )
{
  return (DWORD)(((wrc_resource32_t*)hRsrc)->datasize);
}