5ee73e526e8940583e1256eead21ffea5f491967
[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 for (i = 0; i < IdOffset; i++)
95 {
96 MessageEntry = (PRTL_MESSAGE_RESOURCE_ENTRY)((PUCHAR)MessageEntry + (ULONG)MessageEntry->Length);
97 }
98
99 if (MessageEntry->Flags == 0)
100 {
101 DPRINT("AnsiText: %s\n", MessageEntry->Text);
102 }
103 else
104 {
105 DPRINT("UnicodeText: %S\n", (PWSTR)MessageEntry->Text);
106 }
107
108 if (MessageResourceEntry != NULL);
109 {
110 *MessageResourceEntry = MessageEntry;
111 }
112
113 return STATUS_SUCCESS;
114 }
115
116
117 /**********************************************************************
118 * RtlFormatMessage (NTDLL.@)
119 *
120 * Formats a message (similar to sprintf).
121 *
122 * PARAMS
123 * Message [I] Message to format.
124 * MaxWidth [I] Maximum width in characters of each output line.
125 * IgnoreInserts [I] Whether to copy the message without processing inserts.
126 * Ansi [I] Whether Arguments may have ANSI strings.
127 * ArgumentsIsArray [I] Whether Arguments is actually an array rather than a va_list *.
128 * Arguments [I]
129 * Buffer [O] Buffer to store processed message in.
130 * BufferSize [I] Size of Buffer (in bytes?).
131 *
132 * RETURNS
133 * NTSTATUS code.
134 *
135 * @unimplemented
136 */
137 NTSTATUS NTAPI
138 RtlFormatMessage(PWSTR Message,
139 UCHAR MaxWidth,
140 BOOLEAN IgnoreInserts,
141 BOOLEAN Ansi,
142 BOOLEAN ArgumentIsArray,
143 va_list *Arguments,
144 PWSTR Buffer,
145 ULONG BufferSize)
146 {
147 DPRINT1("RtlFormatMessage(%S, %u, %s, %s, %s, %s, %p, %lu)\n",
148 Message, MaxWidth, IgnoreInserts ? "TRUE" : "FALSE", Ansi ? "TRUE" : "FALSE",
149 ArgumentIsArray ? "TRUE" : "FALSE", Arguments, Buffer, BufferSize);
150
151 UNIMPLEMENTED;
152 return STATUS_NOT_IMPLEMENTED;
153 }
154
155 /* EOF */