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.

142 lines
3.6 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 -= ( ulIndentation - 1 ) % vDisTab;
  63. }
  64. ulIndentation--;
  65. } else {
  66. if (*pData >= 0x20) {
  67. *pchDest++ = *pData++;
  68. if ((ulBufferIndex == 0) &&
  69. vIndent &&
  70. (DBCScharType(pTOL, (int)(pData-1-pTOL)) == CT_TRAIL)
  71. )
  72. {
  73. *(pchDest-1) = 0x20;
  74. }
  75. ulBufferIndex++;
  76. } else if ( (*pData == 0x0d) || (*pData == 0x0a) ) {
  77. *pchDest++ = 0x20;
  78. pData++;
  79. ulBufferIndex++;
  80. } else if (*pData == 0x09) {
  81. ulNumberOfSpaces = vDisTab - ulBufferIndex % vDisTab;
  82. while (ulNumberOfSpaces && ( ulBufferIndex < (ULONG)( vWidth - 1 ) ) ) {
  83. *pchDest++ = 0x20;
  84. ulBufferIndex++;
  85. ulNumberOfSpaces--;
  86. }
  87. pData++;
  88. } else {
  89. *pchDest++ = *pData++;
  90. ulBufferIndex++;
  91. }
  92. }
  93. ulDataLeft--;
  94. ulBlkOffset++;
  95. }
  96. if (DBCScharType(pTOL, (int)(pData-1-pTOL)) == CT_LEAD){
  97. ulDataLeft++;
  98. ulBlkOffset--;
  99. ulBufferIndex--;
  100. pData--;
  101. pchDest--;
  102. }
  103. pData += ulDataLeft;
  104. ulBlkOffset += ulDataLeft;
  105. while (ulBufferIndex < (ULONG)(vWidth -1)) {
  106. *pchDest++ = 0x20;
  107. ulBufferIndex++;
  108. }
  109. }
  110. void
  111. DisTopDown(
  112. void
  113. )
  114. {
  115. ULONG ulRow;
  116. char *pt;
  117. pData = vpBlockTop->Data;
  118. pData += vOffTop;
  119. ulBlkOffset = vOffTop;
  120. pt = vScrBuf+vWidth;
  121. for (ulRow=0; ulRow < (ULONG)vLines; ulRow++ ) {
  122. BuildLine (ulRow, pt);
  123. pt += vWidth;
  124. }
  125. }