ShellSortTestApp.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** @file
  2. This is a test application that demonstrates how to use the sorting functions.
  3. Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Uefi.h>
  7. #include <Library/UefiLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/ShellCEntryLib.h>
  10. #include <Library/SortLib.h>
  11. /**
  12. Test comparator.
  13. @param[in] b1 The first INTN
  14. @param[in] b2 The other INTN
  15. @retval 0 They are the same.
  16. @retval -1 b1 is less than b2
  17. @retval 1 b1 is greater then b2
  18. **/
  19. INTN
  20. EFIAPI
  21. Test (
  22. CONST VOID *b1,
  23. CONST VOID *b2
  24. )
  25. {
  26. if (*(INTN *)b1 == *(INTN *)b2) {
  27. return (0);
  28. }
  29. if (*(INTN *)b1 < *(INTN *)b2) {
  30. return (-1);
  31. }
  32. return (1);
  33. }
  34. /**
  35. UEFI application entry point which has an interface similar to a
  36. standard C main function.
  37. The ShellCEntryLib library instance wrappers the actual UEFI application
  38. entry point and calls this ShellAppMain function.
  39. @param Argc Argument count
  40. @param Argv The parsed arguments
  41. @retval 0 The application exited normally.
  42. @retval Other An error occurred.
  43. **/
  44. INTN
  45. EFIAPI
  46. ShellAppMain (
  47. IN UINTN Argc,
  48. IN CHAR16 **Argv
  49. )
  50. {
  51. INTN Array[10];
  52. Array[0] = 2;
  53. Array[1] = 3;
  54. Array[2] = 4;
  55. Array[3] = 1;
  56. Array[4] = 5;
  57. Array[5] = 6;
  58. Array[6] = 7;
  59. Array[7] = 8;
  60. Array[8] = 1;
  61. Array[9] = 5;
  62. Print (L"Array = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\r\n", Array[0], Array[1], Array[2], Array[3], Array[4], Array[5], Array[6], Array[7], Array[8], Array[9]);
  63. PerformQuickSort (Array, 10, sizeof (INTN), Test);
  64. Print (L"POST-SORT\r\n");
  65. Print (L"Array = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\r\n", Array[0], Array[1], Array[2], Array[3], Array[4], Array[5], Array[6], Array[7], Array[8], Array[9]);
  66. return 0;
  67. }