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

tprefix.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1989 Microsoft Corporation 00004 00005 Module Name: 00006 00007 tprefix.c 00008 00009 Abstract: 00010 00011 Test program for the Prefix table package 00012 00013 Author: 00014 00015 Gary Kimura [GaryKi] 03-Aug-1989 00016 00017 Revision History: 00018 00019 --*/ 00020 00021 #include <stdio.h> 00022 #include <string.h> 00023 00024 #include "nt.h" 00025 #include "ntrtl.h" 00026 00027 // 00028 // Routines and types for generating random prefixes 00029 // 00030 00031 ULONG RtlRandom ( IN OUT PULONG Seed ); 00032 ULONG Seed; 00033 00034 PSZ AnotherPrefix(IN ULONG MaxNameLength); 00035 ULONG AlphabetLength; 00036 00037 //PSZ Alphabet = "AlphaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJuliettKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu"; 00038 00039 PSZ Alphabet = "\ 00040 Aa\ 00041 BBbb\ 00042 CCCccc\ 00043 DDDDdddd\ 00044 EEEEEeeeee\ 00045 FFFFFFffffff\ 00046 GGGGGGGggggggg\ 00047 HHHHHHHHhhhhhhhh\ 00048 IIIIIIIIIiiiiiiiii\ 00049 JJJJJJJJJJjjjjjjjjjj\ 00050 KKKKKKKKKKKkkkkkkkkkkk\ 00051 LLLLLLLLLLLLllllllllllll\ 00052 MMMMMMMMMMMMMmmmmmmmmmmmmm\ 00053 NNNNNNNNNNNNNNnnnnnnnnnnnnnn\ 00054 OOOOOOOOOOOOOOOooooooooooooooo\ 00055 PPPPPPPPPPPPPPPPpppppppppppppppp\ 00056 QQQQQQQQQQQQQQQQQqqqqqqqqqqqqqqqqq\ 00057 RRRRRRRRRRRRRRRRRRrrrrrrrrrrrrrrrrrr\ 00058 SSSSSSSSSSSSSSSSSSSsssssssssssssssssss\ 00059 TTTTTTTTTTTTTTTTTTTTtttttttttttttttttttt\ 00060 UUUUUUUUUUUUUUUUUUUUUuuuuuuuuuuuuuuuuuuuuu\ 00061 VVVVVVVVVVVVVVVVVVVVVVvvvvvvvvvvvvvvvvvvvvvv\ 00062 WWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwwwwwwwwwwwwwww\ 00063 XXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxx\ 00064 YYYYYYYYYYYYYYYYYYYYYYYYYyyyyyyyyyyyyyyyyyyyyyyyyy\ 00065 ZZZZZZZZZZZZZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzzzzzzzzzz"; 00066 00067 #define BUFFER_LENGTH 8192 00068 00069 CHAR Buffer[BUFFER_LENGTH]; 00070 ULONG NextBufferChar = 0; 00071 00072 // 00073 // record structure and variables for the prefix table and it 00074 // elements 00075 // 00076 00077 typedef struct _PREFIX_NODE { 00078 PREFIX_TABLE_ENTRY PfxEntry; 00079 STRING String; 00080 } PREFIX_NODE; 00081 typedef PREFIX_NODE *PPREFIX_NODE; 00082 00083 #define PREFIXES 512 00084 00085 PREFIX_NODE Prefixes[PREFIXES]; 00086 00087 PREFIX_TABLE PrefixTable; 00088 00089 int 00090 main( 00091 int argc, 00092 char *argv[] 00093 ) 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 } 00279 00280 00281 PSZ 00282 AnotherPrefix(IN ULONG MaxNameLength) 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 } 00339

Generated on Sat May 15 19:42:02 2004 for test by doxygen 1.3.7