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.

240 lines
5.7 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*
  4. ** Purpose:
  5. ** Allocates a new SDLE record from memory.
  6. ** Arguments:
  7. ** none
  8. ** Returns:
  9. ** non-Null empty SDLE if successful; Null otherwise (OOM).
  10. **
  11. *********************************************************************/
  12. PSDLE APIENTRY PsdleAlloc()
  13. {
  14. PSDLE psdle;
  15. if ((psdle = (PSDLE)SAlloc((CB)sizeof(SDLE))) != (PSDLE)NULL)
  16. {
  17. psdle->psdleNext = (PSDLE)NULL;
  18. psdle->did = (DID)0;
  19. psdle->didGlobal = (DID)0;
  20. psdle->szLabel = (SZ)NULL;
  21. psdle->szTagFile = (SZ)NULL;
  22. psdle->szNetPath = (SZ)NULL;
  23. }
  24. return(psdle);
  25. }
  26. /*
  27. ** Purpose:
  28. ** Frees a previously allocated SDLE record.
  29. ** Arguments:
  30. ** none
  31. ** Returns:
  32. ** fTrue if successful; fFalse otherwise.
  33. **
  34. *********************************************************************/
  35. BOOL APIENTRY FFreePsdle(PSDLE psdle)
  36. {
  37. ChkArg(psdle != (PSDLE)NULL, 1, fFalse);
  38. if(psdle->szLabel) {
  39. SFree(psdle->szLabel);
  40. }
  41. if(psdle->szTagFile) {
  42. SFree(psdle->szTagFile);
  43. }
  44. if(psdle->szNetPath) {
  45. SFree(psdle->szNetPath);
  46. }
  47. SFree(psdle);
  48. return(fTrue);
  49. }
  50. /*
  51. ** Purpose:
  52. ** Finds the [Source Media Descriptions] section of the INF File, and
  53. ** fills the Source Description List.
  54. ** Arguments:
  55. ** none
  56. ** Notes:
  57. ** Requires that the memory INF has been properly initialized.
  58. ** Returns:
  59. ** grcOkay if successful; grcOutOfMemory or grcINFSrcDescrSect otherwise.
  60. **
  61. *********************************************************************/
  62. GRC APIENTRY GrcFillSrcDescrListFromInf()
  63. {
  64. PPSDLE ppsdle;
  65. GRC grc = grcINFSrcDescrSect;
  66. RGSZ rgsz = (RGSZ)NULL;
  67. SZ szKey = (SZ)NULL;
  68. INT Line;
  69. PINFPERMINFO pPermInfo = pLocalInfPermInfo();
  70. PreCondInfOpen(grcNotOkay);
  71. EvalAssert(pPermInfo->psdleHead == (PSDLE)NULL ||
  72. FFreeSrcDescrList(pPermInfo));
  73. Assert(pPermInfo->psdleHead == (PSDLE)NULL &&
  74. pPermInfo->psdleCur == (PSDLE)NULL);
  75. ppsdle = &(pPermInfo->psdleHead);
  76. if((Line = FindFirstLineFromInfSection("Source Media Descriptions")) == -1)
  77. goto LSrcDescrErr;
  78. do {
  79. UINT cFields;
  80. USHORT iTag = 0, iNet = 0;
  81. DID did;
  82. if (!FKeyInInfLine(Line) ||
  83. ((cFields = CFieldsInInfLine(Line)) != 1 &&
  84. cFields != 4 &&
  85. cFields != 7))
  86. goto LSrcDescrErr;
  87. if ((rgsz = RgszFromInfScriptLine(Line,cFields)) == (RGSZ)NULL ||
  88. (szKey = SzGetNthFieldFromInfLine(Line,0)) == (SZ)NULL)
  89. {
  90. grc = grcOutOfMemory;
  91. goto LSrcDescrErr;
  92. }
  93. if ((did = (DID)atoi(szKey)) < didMin ||
  94. did > didMost ||
  95. PsdleFromDid(did, pPermInfo) != (PSDLE)NULL)
  96. goto LSrcDescrErr;
  97. SFree(szKey);
  98. szKey = (SZ)NULL;
  99. if (cFields == 4 ||
  100. cFields == 7)
  101. {
  102. if (CrcStringCompare(rgsz[2], "=") != crcEqual)
  103. goto LSrcDescrErr;
  104. else if (CrcStringCompare(rgsz[1], "TAGFILE") == crcEqual)
  105. iTag = 3;
  106. else if (CrcStringCompare(rgsz[1], "NETPATH") == crcEqual)
  107. iNet = 3;
  108. else
  109. goto LSrcDescrErr;
  110. }
  111. if (cFields == 7)
  112. {
  113. if (CrcStringCompare(rgsz[5], "=") != crcEqual)
  114. goto LSrcDescrErr;
  115. else if (iTag == 0 &&
  116. CrcStringCompare(rgsz[4], "TAGFILE") == crcEqual)
  117. iTag = 6;
  118. else if (iNet == 0 &&
  119. CrcStringCompare(rgsz[4], "NETPATH") == crcEqual)
  120. iNet = 6;
  121. else
  122. goto LSrcDescrErr;
  123. Assert(iTag != 0 &&
  124. iNet != 0);
  125. }
  126. if ((*ppsdle = PsdleAlloc()) == (PSDLE)NULL ||
  127. ((*ppsdle)->szLabel = SzDupl(rgsz[0])) == (SZ)NULL ||
  128. (iTag != 0 &&
  129. ((*ppsdle)->szTagFile = SzDupl(rgsz[iTag])) == (SZ)NULL) ||
  130. (iNet != 0 &&
  131. ((*ppsdle)->szNetPath = SzDupl(rgsz[iNet])) == (SZ)NULL))
  132. {
  133. grc = grcOutOfMemory;
  134. goto LSrcDescrErr;
  135. }
  136. SFree(rgsz);
  137. rgsz = (RGSZ)NULL;
  138. (*ppsdle)->did = did;
  139. ppsdle = &((*ppsdle)->psdleNext);
  140. Assert(pPermInfo->psdleHead != (PSDLE)NULL);
  141. pPermInfo->psdleCur = pPermInfo->psdleHead;
  142. Assert(*ppsdle == (PSDLE)NULL);
  143. } while ((Line = FindNextLineFromInf(Line)) != -1);
  144. pPermInfo->psdleCur = pPermInfo->psdleHead;
  145. return(grcOkay);
  146. LSrcDescrErr:
  147. if (szKey != (SZ)NULL)
  148. SFree(szKey);
  149. if (rgsz != (RGSZ)NULL)
  150. EvalAssert(FFreeRgsz(rgsz));
  151. EvalAssert(FFreeSrcDescrList(pPermInfo));
  152. return(grc);
  153. }
  154. /*
  155. ** Purpose:
  156. ** Frees each element in the Source Description List.
  157. ** Arguments:
  158. ** none
  159. ** Returns:
  160. ** fTrue if successful; fFalse otherwise.
  161. **
  162. *********************************************************************/
  163. BOOL APIENTRY FFreeSrcDescrList( PINFPERMINFO pPermInfo)
  164. {
  165. while ((pPermInfo->psdleCur = pPermInfo->psdleHead) != (PSDLE)NULL)
  166. {
  167. pPermInfo->psdleHead = pPermInfo->psdleCur->psdleNext;
  168. EvalAssert(FFreePsdle(pPermInfo->psdleCur));
  169. }
  170. return(fTrue);
  171. }
  172. /*
  173. ** Purpose:
  174. ** Search for a corresponding Source Description List Element.
  175. ** Arguments:
  176. ** did: did to search for.
  177. ** Notes:
  178. ** Requires that the Source Description List was initialized with a
  179. ** successful call to GrcFillSrcDescrListFromInf().
  180. ** Returns:
  181. ** non-Null SDLE if successful; Null otherwise (not in list).
  182. **
  183. *********************************************************************/
  184. PSDLE APIENTRY PsdleFromDid(DID did, PINFPERMINFO pPermInfo)
  185. {
  186. ChkArg(did >= didMin &&
  187. did <= didMost, 1, (PSDLE)NULL);
  188. if (pPermInfo->psdleHead == (PSDLE)NULL)
  189. return((PSDLE)NULL);
  190. Assert(pPermInfo->psdleCur != (PSDLE)NULL);
  191. if (pPermInfo->psdleCur->did == did)
  192. return(pPermInfo->psdleCur);
  193. pPermInfo->psdleCur = pPermInfo->psdleHead;
  194. while (pPermInfo->psdleCur != (PSDLE)NULL && pPermInfo->psdleCur->did != did)
  195. pPermInfo->psdleCur = pPermInfo->psdleCur->psdleNext;
  196. return(pPermInfo->psdleCur);
  197. }