Reactos

[NETSH] Sort sub-contexts in the help command

Eric Kohl d0333017 5ce7d883

+41 -4
+41 -4
base/applications/network/netsh/help.c
··· 214 214 HeapFree(GetProcessHeap(), 0, pHelpArray); 215 215 } 216 216 217 + 218 + static 219 + int 220 + SubContextCompare( 221 + _In_ const void *p1, 222 + _In_ const void *p2) 223 + { 224 + return _wcsicmp((*((PCONTEXT_ENTRY*)p1))->pszContextName, (*((PCONTEXT_ENTRY*)p2))->pszContextName); 225 + } 226 + 227 + 217 228 static 218 229 VOID 219 230 PrintSubcontexts( 220 231 _In_ PCONTEXT_ENTRY pContext) 221 232 { 233 + PCONTEXT_ENTRY pSubContext, *pSubContextArray = NULL; 234 + DWORD dwCount, dwIndex; 235 + 222 236 if (pContext->pSubContextHead == NULL) 223 237 return; 224 238 239 + dwCount = 0; 240 + pSubContext = pContext->pSubContextHead; 241 + while (pSubContext != NULL) 242 + { 243 + dwCount++; 244 + pSubContext = pSubContext->pNext; 245 + } 246 + 247 + pSubContextArray = HeapAlloc(GetProcessHeap(), 0, dwCount * sizeof(PCONTEXT_ENTRY)); 248 + if (pSubContextArray == NULL) 249 + return; 250 + 251 + dwIndex = 0; 252 + pSubContext = pContext->pSubContextHead; 253 + while (pSubContext != NULL) 254 + { 255 + pSubContextArray[dwIndex] = pSubContext; 256 + dwIndex++; 257 + pSubContext = pSubContext->pNext; 258 + } 259 + 260 + qsort(pSubContextArray, dwCount, sizeof(PCONTEXT_ENTRY), SubContextCompare); 261 + 225 262 ConResPrintf(StdOut, IDS_SUBCONTEXT_HEADER); 226 - pContext = pContext->pSubContextHead; 227 - while (pContext != NULL) 263 + for (dwIndex = 0; dwIndex < dwCount; dwIndex++) 228 264 { 229 - ConPrintf(StdOut, L" %s", pContext->pszContextName); 230 - pContext = pContext->pNext; 265 + ConPrintf(StdOut, L" %s", pSubContextArray[dwIndex]->pszContextName); 231 266 } 232 267 ConPuts(StdOut, L"\n"); 268 + 269 + HeapFree(GetProcessHeap(), 0, pSubContextArray); 233 270 } 234 271 235 272