fix RtlFindMessage
[reactos.git] / reactos / lib / rtl / message.c
1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS system libraries
3 * FILE: lib/rtl/message.c
4 * PURPOSE: Message table functions
5 * PROGRAMMERS: Eric Kohl <ekohl@zr-online.de>
6 */
7
8 /* INCLUDES *****************************************************************/
9
10 #include <rtl.h>
11
12 #define NDEBUG
13 #include <debug.h>
14
15 /* FUNCTIONS *****************************************************************/
16
17 /*
18 * @implemented
19 */
20 NTSTATUS NTAPI
21 RtlFindMessage(PVOID BaseAddress,
22 ULONG Type,
23 ULONG Language,
24 ULONG MessageId,
25 PRTL_MESSAGE_RESOURCE_ENTRY *MessageResourceEntry)
26 {
27 LDR_RESOURCE_INFO ResourceInfo;
28 PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
29 PRTL_MESSAGE_RESOURCE_DATA MessageTable;
30 NTSTATUS Status;
31 ULONG EntryOffset, IdOffset = 0;
32 PRTL_MESSAGE_RESOURCE_ENTRY MessageEntry;
33 ULONG i;
34
35 DPRINT("RtlFindMessage()\n");
36
37 ResourceInfo.Type = Type;
38 ResourceInfo.Name = 1;
39 ResourceInfo.Language = Language;
40
41 Status = LdrFindResource_U(BaseAddress,
42 &ResourceInfo,
43 RESOURCE_DATA_LEVEL,
44 &ResourceDataEntry);
45 if (!NT_SUCCESS(Status))
46 {
47 return Status;
48 }
49
50 DPRINT("ResourceDataEntry: %p\n", ResourceDataEntry);
51
52 Status = LdrAccessResource(BaseAddress,
53 ResourceDataEntry,
54 (PVOID*)&MessageTable,
55 NULL);
56 if (!NT_SUCCESS(Status))
57 {
58 return Status;
59 }
60
61 DPRINT("MessageTable: %p\n", MessageTable);
62
63 DPRINT("NumberOfBlocks %lu\n", MessageTable->NumberOfBlocks);
64 for (i = 0; i < MessageTable->NumberOfBlocks; i++)
65 {
66 DPRINT("LoId 0x%08lx HiId 0x%08lx Offset 0x%08lx\n",
67 MessageTable->Blocks[i].LowId,
68 MessageTable->Blocks[i].HighId,
69 MessageTable->Blocks[i].OffsetToEntries);
70 }
71
72 for (i = 0; i < MessageTable->NumberOfBlocks; i++)
73 {
74 if ((MessageId >= MessageTable->Blocks[i].LowId) &&
75 (MessageId <= MessageTable->Blocks[i].HighId))
76 {
77 EntryOffset = MessageTable->Blocks[i].OffsetToEntries;
78 IdOffset = MessageId - MessageTable->Blocks[i].LowId;
79 break;
80 }
81
82 if (MessageId < MessageTable->Blocks[i].LowId)
83 {
84 return STATUS_MESSAGE_NOT_FOUND;
85 }
86 }
87
88 MessageEntry = (PRTL_MESSAGE_RESOURCE_ENTRY)((PUCHAR)MessageTable + MessageTable->Blocks[i].OffsetToEntries);
89
90 DPRINT("EntryOffset 0x%08lx\n", EntryOffset);
91 DPRINT("IdOffset 0x%08lx\n", IdOffset);
92
93 DPRINT("MessageEntry: %p\n", MessageEntry);
94
95 for (i = 0; i < MessageTable->NumberOfBlocks; i++)
96 {
97 if (MessageId >= MessageTable->Blocks[i].LowId && MessageId <= MessageTable->Blocks[i].HighId)
98 MessageEntry = (PRTL_MESSAGE_RESOURCE_ENTRY)((char *)MessageEntry + MessageEntry->Length);
99 }
100
101 if (MessageEntry->Flags == 0)
102 {
103 DPRINT("AnsiText: %s\n", MessageEntry->Text);
104 }
105 else
106 {
107 DPRINT("UnicodeText: %S\n", (PWSTR)MessageEntry->Text);
108 }
109
110 if (MessageResourceEntry != NULL);
111 {
112 *MessageResourceEntry = MessageEntry;
113 }
114
115 return STATUS_SUCCESS;
116 }
117
118
119 /**********************************************************************
120 * RtlFormatMessage (NTDLL.@)
121 *
122 * Formats a message (similar to sprintf).
123 *
124 * PARAMS
125 * Message [I] Message to format.
126 * MaxWidth [I] Maximum width in characters of each output line.
127 * IgnoreInserts [I] Whether to copy the message without processing inserts.
128 * Ansi [I] Whether Arguments may have ANSI strings.
129 * ArgumentsIsArray [I] Whether Arguments is actually an array rather than a va_list *.
130 * Arguments [I]
131 * Buffer [O] Buffer to store processed message in.
132 * BufferSize [I] Size of Buffer (in bytes?).
133 *
134 * RETURNS
135 * NTSTATUS code.
136 *
137 * @unimplemented
138 */
139 NTSTATUS NTAPI
140 RtlFormatMessage(PWSTR Message,
141 UCHAR MaxWidth,
142 BOOLEAN IgnoreInserts,
143 BOOLEAN Ansi,
144 BOOLEAN ArgumentIsArray,
145 va_list *Arguments,
146 PWSTR Buffer,
147 ULONG BufferSize)
148 {
149 DPRINT1("RtlFormatMessage(%S, %u, %s, %s, %s, %s, %p, %lu)\n",
150 Message, MaxWidth, IgnoreInserts ? "TRUE" : "FALSE", Ansi ? "TRUE" : "FALSE",
151 ArgumentIsArray ? "TRUE" : "FALSE", Arguments, Buffer, BufferSize);
152
153 UNIMPLEMENTED;
154 return STATUS_NOT_IMPLEMENTED;
155 }
156
157 /* EOF */