Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

tprefix.c File Reference

#include <stdio.h>
#include <string.h>
#include "nt.h"
#include "ntrtl.h"

Go to the source code of this file.

Classes

struct  _PREFIX_NODE

Defines

#define BUFFER_LENGTH   8192
#define PREFIXES   512

Typedefs

typedef _PREFIX_NODE PREFIX_NODE
typedef PREFIX_NODEPPREFIX_NODE

Functions

ULONG RtlRandom (IN OUT PULONG Seed)
PSZ AnotherPrefix (IN ULONG MaxNameLength)
int main (int argc, char *argv[])

Variables

ULONG Seed
ULONG AlphabetLength
PSZ Alphabet
CHAR Buffer [BUFFER_LENGTH]
ULONG NextBufferChar = 0
PREFIX_NODE Prefixes [PREFIXES]
PREFIX_TABLE PrefixTable


Define Documentation

#define BUFFER_LENGTH   8192
 

Definition at line 67 of file tprefix.c.

#define PREFIXES   512
 

Definition at line 83 of file tprefix.c.

Referenced by main().


Typedef Documentation

typedef PREFIX_NODE* PPREFIX_NODE
 

Definition at line 81 of file tprefix.c.

Referenced by main().

typedef struct _PREFIX_NODE PREFIX_NODE
 


Function Documentation

PSZ AnotherPrefix IN ULONG  MaxNameLength  ) 
 

Definition at line 282 of file tprefix.c.

References Alphabet, AlphabetLength, Buffer, BUFFER_LENGTH, NextBufferChar, NULL, RtlRandom(), and Seed.

Referenced by main().

00283 { 00284 ULONG AlphabetPosition; 00285 00286 ULONG NameLength; 00287 ULONG IndividualNameLength; 00288 00289 ULONG StartBufferPosition; 00290 ULONG i; 00291 ULONG j; 00292 00293 // 00294 // Check if there is enough room for another name 00295 // 00296 00297 if (NextBufferChar > (BUFFER_LENGTH - (MaxNameLength * 4))) { 00298 return NULL; 00299 } 00300 00301 // 00302 // Where in the alphabet soup we start 00303 // 00304 00305 AlphabetPosition = RtlRandom(&Seed) % AlphabetLength; 00306 00307 // 00308 // How many names we want in our prefix 00309 // 00310 00311 NameLength = (RtlRandom(&Seed) % MaxNameLength) + 1; 00312 00313 // 00314 // Compute each name 00315 // 00316 00317 StartBufferPosition = NextBufferChar; 00318 00319 for (i = 0; i < NameLength; i += 1) { 00320 00321 Buffer[NextBufferChar++] = '\\'; 00322 00323 IndividualNameLength = (RtlRandom(&Seed) % 3) + 1; 00324 00325 for (j = 0; j < IndividualNameLength; j += 1) { 00326 00327 Buffer[NextBufferChar++] = Alphabet[AlphabetPosition]; 00328 AlphabetPosition = (AlphabetPosition + 1) % AlphabetLength; 00329 00330 } 00331 00332 } 00333 00334 Buffer[NextBufferChar++] = '\0'; 00335 00336 return &Buffer[StartBufferPosition]; 00337 00338 }

int main int  argc,
char *  argv[]
 

Definition at line 90 of file tprefix.c.

References Alphabet, AlphabetLength, AnotherPrefix(), DbgPrint, FALSE, NextBufferChar, NULL, PfxFindPrefix(), PfxInitialize(), PfxInsertPrefix(), PfxRemovePrefix(), PPREFIX_NODE, PREFIXES, Prefixes, PrefixTable, RtlInitString(), Seed, _PREFIX_NODE::String, String, strlen(), and TRUE.

00094 { 00095 ULONG i; 00096 PSZ Psz; 00097 00098 PPREFIX_TABLE_ENTRY PfxEntry; 00099 PPREFIX_NODE PfxNode; 00100 00101 STRING String; 00102 00103 // 00104 // We're starting the test 00105 // 00106 00107 DbgPrint("Start Prefix Test\n"); 00108 00109 // 00110 // Calculate the alphabet size for use by AnotherPrefix 00111 // 00112 00113 AlphabetLength = strlen(Alphabet); 00114 00115 // 00116 // Initialize the prefix table 00117 // 00118 00119 PfxInitialize(&PrefixTable); 00120 00121 // 00122 // Insert the root prefix 00123 // 00124 00125 RtlInitString( &Prefixes[i].String, "\\" ); 00126 if (PfxInsertPrefix( &PrefixTable, 00127 &Prefixes[0].String, 00128 &Prefixes[0].PfxEntry )) { 00129 DbgPrint("Insert root prefix\n"); 00130 } else { 00131 DbgPrint("error inserting root prefix\n"); 00132 } 00133 00134 // 00135 // Insert prefixes 00136 // 00137 00138 Seed = 0; 00139 00140 for (i = 1, Psz = AnotherPrefix(3); 00141 (i < PREFIXES) && (Psz != NULL); 00142 i += 1, Psz = AnotherPrefix(3)) { 00143 00144 DbgPrint("[0x%x] = ", i); 00145 DbgPrint("\"%s\"", Psz); 00146 00147 RtlInitString(&Prefixes[i].String, Psz); 00148 00149 if (PfxInsertPrefix( &PrefixTable, 00150 &Prefixes[i].String, 00151 &Prefixes[i].PfxEntry )) { 00152 00153 DbgPrint(" inserted in table\n"); 00154 00155 } else { 00156 00157 DbgPrint(" already in table\n"); 00158 00159 } 00160 00161 } 00162 00163 // 00164 // Enumerate the prefix table 00165 // 00166 00167 DbgPrint("Enumerate Prefix Table the first time\n"); 00168 00169 for (PfxEntry = PfxNextPrefix(&PrefixTable, TRUE); 00170 PfxEntry != NULL; 00171 PfxEntry = PfxNextPrefix(&PrefixTable, FALSE)) { 00172 00173 PfxNode = CONTAINING_RECORD(PfxEntry, PREFIX_NODE, PfxEntry); 00174 00175 DbgPrint("%s\n", PfxNode->String.Buffer); 00176 00177 } 00178 00179 DbgPrint("Start Prefix search 0x%x\n", NextBufferChar); 00180 00181 // 00182 // Search for prefixes 00183 // 00184 00185 for (Psz = AnotherPrefix(4); Psz != NULL; Psz = AnotherPrefix(4)) { 00186 00187 DbgPrint("0x%x ", NextBufferChar); 00188 00189 RtlInitString(&String, Psz); 00190 00191 PfxEntry = PfxFindPrefix( &PrefixTable, &String, FALSE ); 00192 00193 if (PfxEntry == NULL) { 00194 00195 PfxEntry = PfxFindPrefix( &PrefixTable, &String, TRUE ); 00196 00197 if (PfxEntry == NULL) { 00198 00199 DbgPrint("Not found \"%s\"\n", Psz); 00200 00201 NOTHING; 00202 00203 } else { 00204 00205 PfxNode = CONTAINING_RECORD(PfxEntry, PREFIX_NODE, PfxEntry); 00206 00207 DbgPrint("Case blind \"%s\" is \"%s\"\n", Psz, PfxNode->String.Buffer); 00208 00209 PfxRemovePrefix( &PrefixTable, PfxEntry ); 00210 00211 } 00212 00213 } else { 00214 00215 PfxNode = CONTAINING_RECORD(PfxEntry, PREFIX_NODE, PfxEntry); 00216 00217 DbgPrint( "Case sensitive \"%s\" is \"%s\"\n", Psz, PfxNode->String.Buffer); 00218 00219 if (PfxNode != &Prefixes[0]) { 00220 00221 PfxRemovePrefix( &PrefixTable, PfxEntry ); 00222 00223 } 00224 00225 } 00226 00227 } 00228 00229 // 00230 // Enumerate the prefix table 00231 // 00232 00233 DbgPrint("Enumerate Prefix Table a second time\n"); 00234 00235 for (PfxEntry = PfxNextPrefix(&PrefixTable, TRUE); 00236 PfxEntry != NULL; 00237 PfxEntry = PfxNextPrefix(&PrefixTable, FALSE)) { 00238 00239 PfxNode = CONTAINING_RECORD(PfxEntry, PREFIX_NODE, PfxEntry); 00240 00241 DbgPrint("%s\n", PfxNode->String.Buffer); 00242 00243 } 00244 00245 // 00246 // Now enumerate and zero out the table 00247 // 00248 00249 for (PfxEntry = PfxNextPrefix(&PrefixTable, TRUE); 00250 PfxEntry != NULL; 00251 PfxEntry = PfxNextPrefix(&PrefixTable, FALSE)) { 00252 00253 PfxNode = CONTAINING_RECORD(PfxEntry, PREFIX_NODE, PfxEntry); 00254 00255 DbgPrint("Delete %s\n", PfxNode->String.Buffer); 00256 00257 PfxRemovePrefix( &PrefixTable, PfxEntry ); 00258 00259 } 00260 00261 // 00262 // Enumerate again but this time the table should be empty 00263 // 00264 00265 for (PfxEntry = PfxNextPrefix(&PrefixTable, TRUE); 00266 PfxEntry != NULL; 00267 PfxEntry = PfxNextPrefix(&PrefixTable, FALSE)) { 00268 00269 PfxNode = CONTAINING_RECORD(PfxEntry, PREFIX_NODE, PfxEntry); 00270 00271 DbgPrint("This Node should be gone \"%s\"\n", PfxNode->String.Buffer); 00272 00273 } 00274 00275 DbgPrint("End PrefixTest()\n"); 00276 00277 return TRUE; 00278 }

ULONG RtlRandom IN OUT PULONG  Seed  ) 
 

Definition at line 72 of file rtl/random.c.

00078 : 00079 00080 An every better random number generator based on MacLaren and Marsaglia. 00081 00082 Arguments: 00083 00084 Seed - Supplies a pointer to the random number generator seed. 00085 00086 Return Value: 00087 00088 ULONG - returns a random number uniformly distributed over [0..MAXLONG] 00089 00090 --*/ 00091 00092 { 00093 ULONG X; 00094 ULONG Y; 00095 ULONG j; 00096 ULONG Result; 00097 00098 RTL_PAGED_CODE(); 00099 00100 X = UniformMacro(Seed); 00101 Y = UniformMacro(Seed); 00102 00103 j = Y % 128; 00104 00105 Result = RtlpRandomConstantVector[j]; 00106 00107 RtlpRandomConstantVector[j] = X; 00108 00109 return Result; 00110 00111 } }


Variable Documentation

PSZ Alphabet
 

Initial value:

"\ Aa\ BBbb\ CCCccc\ DDDDdddd\ EEEEEeeeee\ FFFFFFffffff\ GGGGGGGggggggg\ HHHHHHHHhhhhhhhh\ IIIIIIIIIiiiiiiiii\ JJJJJJJJJJjjjjjjjjjj\ KKKKKKKKKKKkkkkkkkkkkk\ LLLLLLLLLLLLllllllllllll\ MMMMMMMMMMMMMmmmmmmmmmmmmm\ NNNNNNNNNNNNNNnnnnnnnnnnnnnn\ OOOOOOOOOOOOOOOooooooooooooooo\ PPPPPPPPPPPPPPPPpppppppppppppppp\ QQQQQQQQQQQQQQQQQqqqqqqqqqqqqqqqqq\ RRRRRRRRRRRRRRRRRRrrrrrrrrrrrrrrrrrr\ SSSSSSSSSSSSSSSSSSSsssssssssssssssssss\ TTTTTTTTTTTTTTTTTTTTtttttttttttttttttttt\ UUUUUUUUUUUUUUUUUUUUUuuuuuuuuuuuuuuuuuuuuu\ VVVVVVVVVVVVVVVVVVVVVVvvvvvvvvvvvvvvvvvvvvvv\ WWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwwwwwwwwwwwwwww\ XXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxx\ YYYYYYYYYYYYYYYYYYYYYYYYYyyyyyyyyyyyyyyyyyyyyyyyyy\ ZZZZZZZZZZZZZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzzzzzzzzzz"

Definition at line 39 of file tprefix.c.

Referenced by AnotherPrefix(), and main().

ULONG AlphabetLength
 

Definition at line 35 of file tprefix.c.

Referenced by AnotherPrefix(), and main().

CHAR Buffer[BUFFER_LENGTH]
 

Definition at line 69 of file tprefix.c.

ULONG NextBufferChar = 0
 

Definition at line 70 of file tprefix.c.

Referenced by AnotherPrefix(), and main().

PREFIX_NODE Prefixes[PREFIXES]
 

Definition at line 85 of file tprefix.c.

Referenced by main().

PREFIX_TABLE PrefixTable
 

Definition at line 87 of file tprefix.c.

Referenced by main(), PfxFindPrefix(), PfxInitialize(), PfxInsertPrefix(), RtlFindUnicodePrefix(), RtlInitializeUnicodePrefix(), RtlInsertUnicodePrefix(), RtlNextUnicodePrefix(), and RtlRemoveUnicodePrefix().

ULONG Seed
 

Definition at line 32 of file tprefix.c.

Referenced by AnotherPrefix(), ComputeNewSerialNumber(), main(), NtAllocateUuids(), NtSetUuidSeed(), RtlRandom(), RtlRunDecodeUnicodeString(), and RtlUniform().


Generated on Sat May 15 19:45:48 2004 for test by doxygen 1.3.7