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.

143 lines
3.5 KiB

  1. #include <malloc.h>
  2. #include <windows.h>
  3. // #include <wincon.h>
  4. #include "list.h"
  5. static unsigned char* pData;
  6. static ULONG ulBlkOffset;
  7. static char* pBuffer;
  8. typedef enum {
  9. CT_LEAD = 0,
  10. CT_TRAIL = 1,
  11. CT_ANK = 2,
  12. CT_INVALID = 3,
  13. } DBCSTYPE;
  14. DBCSTYPE DBCScharType( char* str, int index )
  15. {
  16. // TT .. ??? maybe LEAD or TRAIL
  17. // FT .. second == LEAD
  18. // FF .. second == ANK
  19. // TF .. ??? maybe ANK or TRAIL
  20. if ( index >= 0 ){
  21. char* pos = str+index;
  22. DBCSTYPE candidate = (IsDBCSLeadByte( *pos-- ) ? CT_LEAD : CT_ANK);
  23. BOOL maybeTrail = FALSE;
  24. for ( ; pos >= str; pos-- ){
  25. if ( !IsDBCSLeadByte( *pos ) )
  26. break;
  27. maybeTrail ^= 1;
  28. }
  29. return maybeTrail ? CT_TRAIL : candidate;
  30. }
  31. return CT_INVALID;
  32. }
  33. void
  34. BuildLine(
  35. ULONG ulRow,
  36. char* pchDest
  37. )
  38. {
  39. ULONG ulIndentation;
  40. ULONG ulBufferIndex;
  41. ULONG ulDataLeft;
  42. ULONG ulNumberOfSpaces;
  43. unsigned char* pTOL = pData;
  44. ulBufferIndex = 0;
  45. ulDataLeft = vrgNewLen[ ulRow ];
  46. ulIndentation = vIndent;
  47. while ( (ulBufferIndex < (ULONG)(vWidth - 1)) && ulDataLeft ) {
  48. if ( ulBlkOffset >= BLOCKSIZE ) {
  49. ulBlkOffset = ulBlkOffset % BLOCKSIZE;
  50. while (vpBlockTop->next == NULL) {
  51. vReaderFlag = F_DOWN;
  52. SetEvent (vSemReader);
  53. WaitForSingleObject(vSemMoreData, WAITFOREVER);
  54. ResetEvent(vSemMoreData);
  55. }
  56. vpBlockTop = vpBlockTop->next;
  57. pData = vpBlockTop->Data + ulBlkOffset;
  58. pTOL = pData;
  59. }
  60. if ( ulIndentation ) {
  61. if ( *pData++ == 0x09 ) {
  62. ulIndentation -= vDisTab - (ulIndentation % vDisTab);
  63. } else {
  64. ulIndentation--;
  65. }
  66. } else {
  67. if (*pData >= 0x20) {
  68. *pchDest++ = *pData++;
  69. if ((ulBufferIndex == 0) &&
  70. vIndent &&
  71. (DBCScharType(pTOL, (int)(pData-1-pTOL)) == CT_TRAIL)
  72. )
  73. {
  74. *(pchDest-1) = 0x20;
  75. }
  76. ulBufferIndex++;
  77. } else if ( (*pData == 0x0d) || (*pData == 0x0a) ) {
  78. *pchDest++ = 0x20;
  79. pData++;
  80. ulBufferIndex++;
  81. } else if (*pData == 0x09) {
  82. ulNumberOfSpaces = vDisTab - ulBufferIndex % vDisTab;
  83. while (ulNumberOfSpaces && ( ulBufferIndex < (ULONG)( vWidth - 1 ) ) ) {
  84. *pchDest++ = 0x20;
  85. ulBufferIndex++;
  86. ulNumberOfSpaces--;
  87. }
  88. pData++;
  89. } else {
  90. *pchDest++ = *pData++;
  91. ulBufferIndex++;
  92. }
  93. }
  94. ulDataLeft--;
  95. ulBlkOffset++;
  96. }
  97. if (DBCScharType(pTOL, (int)(pData-1-pTOL)) == CT_LEAD){
  98. ulDataLeft++;
  99. ulBlkOffset--;
  100. ulBufferIndex--;
  101. pData--;
  102. pchDest--;
  103. }
  104. pData += ulDataLeft;
  105. ulBlkOffset += ulDataLeft;
  106. while (ulBufferIndex < (ULONG)(vWidth -1)) {
  107. *pchDest++ = 0x20;
  108. ulBufferIndex++;
  109. }
  110. }
  111. void
  112. DisTopDown(
  113. void
  114. )
  115. {
  116. ULONG ulRow;
  117. char *pt;
  118. pData = vpBlockTop->Data;
  119. pData += vOffTop;
  120. ulBlkOffset = vOffTop;
  121. pt = vScrBuf+vWidth;
  122. for (ulRow=0; ulRow < (ULONG)vLines; ulRow++ ) {
  123. BuildLine (ulRow, pt);
  124. pt += vWidth;
  125. }
  126. }