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.

134 lines
3.9 KiB

  1. /*************************************************
  2. * convold.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. #include <stdio.h>
  8. #include <windows.h>
  9. void _cdecl main( int argc, TCHAR **argv) {
  10. HANDLE hInFile, hOutFile;
  11. HANDLE hInMap;
  12. LPWORD lpInFile, lpCur;
  13. WORD OutLine[20];
  14. DWORD dwInFileSize, i, NumberOfBytesWritten;
  15. DWORD iLine, MaxLine, MaxLen;
  16. if ( argc != 3 ) {
  17. printf("Usage: convold File1 File2\n");
  18. return;
  19. }
  20. hInFile = CreateFile( argv[1], // pointer to name of the file
  21. GENERIC_READ, // access (read-write) mode
  22. FILE_SHARE_READ, // share mode
  23. NULL, // pointer to security attributes
  24. OPEN_EXISTING, // how to create
  25. FILE_ATTRIBUTE_NORMAL, // file attributes
  26. NULL);
  27. if ( hInFile == INVALID_HANDLE_VALUE ) return;
  28. dwInFileSize = GetFileSize(hInFile, NULL);
  29. hOutFile=CreateFile( argv[2], // pointer to name of the file
  30. GENERIC_WRITE, // access (read-write) mode
  31. FILE_SHARE_WRITE, // share mode
  32. NULL, // pointer to security attributes
  33. CREATE_ALWAYS, // how to create
  34. FILE_ATTRIBUTE_NORMAL, // file attributes
  35. NULL);
  36. if ( hOutFile == INVALID_HANDLE_VALUE ) {
  37. printf("hOutFile is INVALID_HANDLE_VALUE\n");
  38. return;
  39. }
  40. hInMap = CreateFileMapping(hInFile, // handle to file to map
  41. NULL, // optional security attributes
  42. PAGE_READONLY, // protection for mapping object
  43. 0, // high-order 32 bits of object size
  44. 0, // low-order 32 bits of object size
  45. NULL); // name of file-mapping object);
  46. if ( !hInMap ) {
  47. printf("hInMap is NULL\n");
  48. return;
  49. }
  50. lpInFile = (LPWORD) MapViewOfFile(hInMap, FILE_MAP_READ, 0, 0, 0);
  51. OutLine[0] = 0xFEFF;
  52. WriteFile(hOutFile, // handle to file to write to
  53. OutLine, // pointer to data to write to file
  54. 2, // number of bytes to write
  55. &NumberOfBytesWritten, // pointer to number of bytes written
  56. NULL); // pointer to structure needed for
  57. // overlapped I/O
  58. lpCur = lpInFile + 1; // skip FEFF
  59. i = 0;
  60. iLine =1;
  61. MaxLine = 1;
  62. MaxLen = 0;
  63. while ( i < (dwInFileSize / sizeof(WORD) -1)) {
  64. WORD iStart;
  65. iStart = 0;
  66. while ( *lpCur != 0x000D ) {
  67. OutLine[iStart++] = *lpCur;
  68. lpCur ++;
  69. i++;
  70. }
  71. if ( (OutLine[iStart-1] != L' ') && (OutLine[iStart-1] != L'*') )
  72. OutLine[iStart++] = L' ';
  73. OutLine[iStart++] = 0x000D;
  74. OutLine[iStart++] = 0x000A;
  75. lpCur++;
  76. lpCur++;
  77. i++;
  78. i++;
  79. if ( MaxLen < iStart ) {
  80. MaxLen = iStart;
  81. MaxLine = iLine;
  82. }
  83. iLine ++;
  84. WriteFile(hOutFile, // handle to file to write to
  85. OutLine, // pointer to data to write to file
  86. iStart * sizeof(WORD), // number of bytes to write
  87. &NumberOfBytesWritten, // number of bytes written
  88. NULL); // pointer to structure needed for
  89. // overlapped I/O
  90. } // while i<dwInFileSize
  91. UnmapViewOfFile(lpInFile);
  92. CloseHandle(hInMap);
  93. CloseHandle(hInFile);
  94. CloseHandle(hOutFile);
  95. printf("maxLen=%d, maxLine=%d\n", MaxLen, MaxLine);
  96. return;
  97. }