Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.6 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: implements the basic structures for a list of options
  5. // ThreadSafe: no
  6. // Locks: none
  7. // Please read stdinfo.txt for programming style.
  8. //================================================================================
  9. #include <mm.h>
  10. #include <opt.h>
  11. #include <array.h>
  12. //BeginExport(typedef)
  13. typedef ARRAY M_OPTLIST;
  14. typedef PARRAY PM_OPTLIST;
  15. typedef LPARRAY LPM_OPTLIST;
  16. //EndExport(typedef)
  17. //BeginExport(inline)
  18. DWORD _inline
  19. MemOptListInit(
  20. IN OUT PM_OPTLIST OptList
  21. ) {
  22. return MemArrayInit(OptList);
  23. }
  24. //EndExport(inline)
  25. //BeginExport(inline)
  26. DWORD _inline
  27. MemOptListCleanup(
  28. IN OUT PM_OPTLIST OptList
  29. ) {
  30. return MemArrayCleanup(OptList);
  31. }
  32. //EndExport(inline)
  33. //BeginExport(function)
  34. DWORD _inline
  35. MemOptListAddOption( // Add or replace an option
  36. IN OUT PM_OPTLIST OptList,
  37. IN PM_OPTION Opt,
  38. OUT PM_OPTION *DeletedOpt // OPTIONAL: old option or NULL
  39. ) // EndExport(function)
  40. { // if DeletedOpt is NULL, then the option would just be freed.
  41. ARRAY_LOCATION Loc;
  42. DWORD Error;
  43. PM_OPTION ThisOpt;
  44. AssertRet(OptList && Opt, ERROR_INVALID_PARAMETER);
  45. if( DeletedOpt ) *DeletedOpt = NULL;
  46. Error = MemArrayInitLoc(OptList, &Loc);
  47. while( ERROR_FILE_NOT_FOUND != Error ) {
  48. Require(ERROR_SUCCESS == Error);
  49. Error = MemArrayGetElement(OptList, &Loc, (LPVOID*)&ThisOpt);
  50. Require(ERROR_SUCCESS == Error );
  51. Require(ThisOpt);
  52. if( ThisOpt->OptId == Opt->OptId ) {
  53. Error = MemArraySetElement(OptList, &Loc, (LPVOID)Opt);
  54. Require(ERROR_SUCCESS == Error);
  55. if( DeletedOpt ) (*DeletedOpt) = ThisOpt;
  56. else MemOptCleanup(ThisOpt);
  57. return ERROR_SUCCESS;
  58. }
  59. Error = MemArrayNextLoc(OptList, &Loc);
  60. }
  61. Error = MemArrayAddElement(OptList, (LPVOID)Opt);
  62. return Error;
  63. }
  64. //BeginExport(inline)
  65. DWORD _inline
  66. MemOptListAddAnotherOption( // add without checking for duplicates
  67. IN OUT PM_OPTLIST OptList,
  68. IN PM_OPTION Opt
  69. ) {
  70. return MemArrayAddElement(OptList, (LPVOID)Opt);
  71. }
  72. //EndExport(inline)
  73. //BeginExport(inline)
  74. DWORD _inline
  75. MemOptListFindOption(
  76. IN PM_OPTLIST OptList,
  77. IN DWORD OptId,
  78. OUT PM_OPTION *Opt
  79. ) {
  80. ARRAY_LOCATION Loc;
  81. DWORD Error;
  82. AssertRet(OptList && Opt, ERROR_INVALID_PARAMETER );
  83. Error = MemArrayInitLoc(OptList, &Loc);
  84. while( ERROR_FILE_NOT_FOUND != Error ) {
  85. Require(ERROR_SUCCESS == Error);
  86. Error = MemArrayGetElement(OptList, &Loc, (LPVOID*)Opt);
  87. Require(ERROR_SUCCESS == Error);
  88. Require(*Opt);
  89. if( (*Opt)->OptId == OptId )
  90. return ERROR_SUCCESS;
  91. Error = MemArrayNextLoc(OptList, &Loc);
  92. }
  93. *Opt = NULL;
  94. return ERROR_FILE_NOT_FOUND;
  95. }
  96. //EndExport(inline)
  97. //BeginExport(function)
  98. DWORD
  99. MemOptListDelOption(
  100. IN PM_OPTLIST OptList,
  101. IN DWORD OptId
  102. ) //EndExport(function)
  103. {
  104. ARRAY_LOCATION Loc;
  105. DWORD Error;
  106. PM_OPTION Opt;
  107. AssertRet(OptList, ERROR_INVALID_PARAMETER );
  108. Error = MemArrayInitLoc(OptList, &Loc);
  109. while( ERROR_FILE_NOT_FOUND != Error ) {
  110. Require(ERROR_SUCCESS == Error);
  111. Error = MemArrayGetElement(OptList, &Loc, (LPVOID*)&Opt);
  112. Require(ERROR_SUCCESS == Error && Opt);
  113. if( Opt->OptId == OptId ) {
  114. Error = MemArrayDelElement(OptList, &Loc, (LPVOID*)&Opt);
  115. Require(ERROR_SUCCESS == Error && Opt);
  116. Error = MemOptCleanup(Opt);
  117. Require(ERROR_SUCCESS == Error);
  118. return ERROR_SUCCESS;
  119. }
  120. Error = MemArrayNextLoc(OptList, &Loc);
  121. }
  122. return ERROR_FILE_NOT_FOUND;
  123. }
  124. //BeginExport(inline)
  125. DWORD _inline
  126. MemOptListSize(
  127. IN PM_OPTLIST OptList
  128. ) {
  129. return MemArraySize(OptList);
  130. }
  131. //EndExport(inline)
  132. //================================================================================
  133. // end of file
  134. //================================================================================