Leaked source code of windows server 2003
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.

135 lines
3.2 KiB

  1. //****************************************************************************
  2. // DWORD NEAR PASCAL ImportFile(LPCSTR szImportFile)
  3. //
  4. // This function imports a file from the given section
  5. //
  6. // History:
  7. // Mon 21-Mar-1996 12:40:00 -by- Mark MacLin [mmaclin]
  8. // Created.
  9. //****************************************************************************
  10. #include "isignup.h"
  11. #define MAXLONGLEN 80
  12. #define SIZE_ReadBuf 0x00008000 // 32K buffer size
  13. #pragma data_seg(".rdata")
  14. static TCHAR szNull[] = TEXT("");
  15. #pragma data_seg()
  16. //int atoi (LPCSTR szBuf)
  17. //{
  18. // int iRet = 0;
  19. //
  20. // while ((*szBuf >= '0') && (*szBuf <= '9'))
  21. // {
  22. // iRet = (iRet*10)+(int)(*szBuf-'0');
  23. // szBuf++;
  24. // };
  25. // return iRet;
  26. //}
  27. DWORD ImportFile(LPCTSTR lpszImportFile, LPCTSTR lpszSection, LPCTSTR lpszOutputFile)
  28. {
  29. HFILE hFile;
  30. LPTSTR pszLine, pszFile;
  31. int i, iMaxLine;
  32. UINT cbSize, cbRet;
  33. DWORD dwRet = ERROR_SUCCESS;
  34. // Allocate a buffer for the file
  35. //
  36. if ((pszFile = (LPTSTR)LocalAlloc(LMEM_FIXED, SIZE_ReadBuf * sizeof(TCHAR)))
  37. == NULL)
  38. {
  39. return ERROR_OUTOFMEMORY;
  40. }
  41. // Look for script
  42. //
  43. if (GetPrivateProfileString(lpszSection,
  44. NULL,
  45. szNull,
  46. pszFile,
  47. SIZE_ReadBuf,
  48. lpszImportFile) != 0)
  49. {
  50. // Get the maximum line number
  51. //
  52. pszLine = pszFile;
  53. iMaxLine = -1;
  54. while (*pszLine)
  55. {
  56. i = _ttoi(pszLine);
  57. iMaxLine = max(iMaxLine, i);
  58. pszLine += lstrlen(pszLine)+1;
  59. };
  60. // If we have at least one line, we will import the script file
  61. //
  62. if (iMaxLine >= 0)
  63. {
  64. // Create the script file
  65. //
  66. #ifdef UNICODE
  67. CHAR szTmp[MAX_PATH+1];
  68. wcstombs(szTmp, lpszOutputFile, MAX_PATH+1);
  69. hFile = _lcreat(szTmp, 0);
  70. #else
  71. hFile = _lcreat(lpszOutputFile, 0);
  72. #endif
  73. if (hFile != HFILE_ERROR)
  74. {
  75. TCHAR szLineNum[MAXLONGLEN+1];
  76. // From The first line to the last line
  77. //
  78. for (i = 0; i <= iMaxLine; i++)
  79. {
  80. // Read the script line
  81. //
  82. wsprintf(szLineNum, TEXT("%d"), i);
  83. if ((cbSize = GetPrivateProfileString(lpszSection,
  84. szLineNum,
  85. szNull,
  86. pszLine,
  87. SIZE_ReadBuf,
  88. lpszImportFile)) != 0)
  89. {
  90. // Write to the script file
  91. //
  92. lstrcat(pszLine, TEXT("\x0d\x0a"));
  93. #ifdef UNICODE
  94. wcstombs(szTmp, pszLine, MAX_PATH+1);
  95. cbRet=_lwrite(hFile, szTmp, cbSize+2);
  96. #else
  97. cbRet=_lwrite(hFile, pszLine, cbSize+2);
  98. #endif
  99. };
  100. };
  101. _lclose(hFile);
  102. }
  103. else
  104. {
  105. dwRet = ERROR_PATH_NOT_FOUND;
  106. };
  107. }
  108. else
  109. {
  110. dwRet = ERROR_PATH_NOT_FOUND;
  111. };
  112. }
  113. else
  114. {
  115. dwRet = ERROR_PATH_NOT_FOUND;
  116. };
  117. LocalFree(pszFile);
  118. return dwRet;
  119. }