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.

276 lines
6.1 KiB

  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <windows.h>
  4. #include "list.h"
  5. void
  6. UpdateHighLighted (
  7. int dlen,
  8. int end
  9. )
  10. {
  11. int i;
  12. long l;
  13. ScrLock (1);
  14. if (vHighLen + dlen == 0 && vHighLen) {
  15. i = vAttrHigh;
  16. vAttrHigh = vAttrList;
  17. vHLBot = vHLTop;
  18. UpdateHighNoLock ();
  19. vAttrHigh = (WORD) i;
  20. }
  21. vHighLen += dlen;
  22. UpdateHighNoLock ();
  23. ScrUnLock ();
  24. switch (end) {
  25. case 1:
  26. l = vHighTop + (vHighLen < 0 ? vHighLen : 0);
  27. if (l < vTopLine) {
  28. vTopLine = l;
  29. SetUpdate (U_ALL);
  30. }
  31. break;
  32. case 2:
  33. l = vHighTop + (vHighLen > 0 ? vHighLen : 0);
  34. if (l > vTopLine+vLines-1) {
  35. vTopLine = l - vLines + 1;
  36. SetUpdate (U_ALL);
  37. }
  38. break;
  39. case 3:
  40. l = vHighTop + vHighLen;
  41. if (l < vTopLine) {
  42. vTopLine = l;
  43. SetUpdate (U_ALL);
  44. } else if (l > vTopLine+vLines-1) {
  45. vTopLine = l - vLines + 1;
  46. SetUpdate (U_ALL);
  47. }
  48. break;
  49. }
  50. }
  51. void
  52. UpdateHighClear ()
  53. {
  54. int i;
  55. ScrLock (1);
  56. if (vHLTop)
  57. for (i=vHLTop; i <= vHLBot; i++)
  58. if (i >= 1 && i <= vLines)
  59. setattr1 (i, (char) vAttrList);
  60. vHLTop = vHLBot = 0;
  61. vHighTop = -1L;
  62. ScrUnLock ();
  63. }
  64. void
  65. MarkSpot ()
  66. {
  67. UpdateHighClear ();
  68. vHighTop = vTopLine + vLines / 2;
  69. if (vHighTop >= vLastLine)
  70. vHighTop = vLastLine - 1;
  71. vHighLen = 0;
  72. UpdateHighLighted (0, 0);
  73. }
  74. void
  75. UpdateHighNoLock ()
  76. {
  77. int TopLine, BotLine;
  78. int i;
  79. if (vHighLen == 0) {
  80. if (vHLTop)
  81. setattr1 (vHLTop, (char) vAttrList);
  82. if (vHighTop < vTopLine || vHighTop > vTopLine+vLines-1) {
  83. vHLTop = vHLBot = 0;
  84. return;
  85. }
  86. vHLTop = vHLBot = (char)(vHighTop - vTopLine + 1);
  87. setattr1 (vHLTop, (char)vAttrHigh);
  88. return;
  89. }
  90. if (vHighLen < 0) {
  91. TopLine = (int)(vHighTop + vHighLen - vTopLine);
  92. BotLine = (int)(vHighTop - vTopLine);
  93. } else {
  94. TopLine = (int)(vHighTop - vTopLine);
  95. BotLine = (int)(vHighTop + vHighLen - vTopLine);
  96. }
  97. TopLine ++;
  98. BotLine ++;
  99. for (i=1; i <= vLines; i++) {
  100. if (i >= TopLine && i <= BotLine) {
  101. if (i < vHLTop || i > vHLBot)
  102. setattr1 (i, (char)vAttrHigh);
  103. } else
  104. if (i >= vHLTop && i <= vHLBot)
  105. setattr1 (i, (char)vAttrList);
  106. }
  107. vHLTop = (char)(TopLine < 1 ? 1 : TopLine);
  108. vHLBot = (char)(BotLine > vLines ? (int)vLines : BotLine);
  109. }
  110. void
  111. FileHighLighted ()
  112. {
  113. char *data;
  114. char s[50];
  115. char c, lastc;
  116. FILE *fp;
  117. long hTopLine;
  118. long CurLine, BotLine;
  119. long LastOffset, CurOffset;
  120. if (vHighTop < 0L) // || vHighLen == 0
  121. return;
  122. GetInput ("File As> ", s, 40);
  123. if (s[0] == 0) {
  124. SetUpdate (U_HEAD);
  125. return;
  126. }
  127. fp = fopen( s, "a+b" );
  128. ckerr (fp == NULL, "Could not create or open file");
  129. DisLn (0, (Uchar)vLines+1, "Saving...");
  130. if (vHighLen < 0) {
  131. CurLine = vHighTop + vHighLen;
  132. BotLine = vHighTop;
  133. } else {
  134. CurLine = vHighTop;
  135. BotLine = vHighTop + vHighLen;
  136. }
  137. hTopLine = vTopLine;
  138. vTopLine = CurLine;
  139. QuickRestore (); /* Jump to starting line */
  140. while (InfoReady () == 0) { /* Set extern values */
  141. ResetEvent (vSemMoreData);
  142. SetEvent (vSemReader);
  143. WaitForSingleObject(vSemMoreData, WAITFOREVER);
  144. ResetEvent(vSemMoreData);
  145. }
  146. lastc = 0;
  147. BotLine ++;
  148. CurOffset = vpBlockTop->offset + vOffTop;
  149. LastOffset = vprgLineTable[BotLine/PLINES][BotLine%PLINES];
  150. while (CurOffset++ < LastOffset) {
  151. data = vpBlockTop->Data;
  152. data += vOffTop;
  153. c = *data;
  154. if (c == '\n' || c == '\r') {
  155. if ((c == '\n' && lastc == '\r') || (c == '\r' && lastc == '\n'))
  156. lastc = 0;
  157. else {
  158. lastc = c;
  159. fputc ('\r', fp);
  160. fputc ('\n', fp);
  161. }
  162. } else fputc (lastc=c, fp);
  163. vOffTop++;
  164. if (vOffTop >= BLOCKSIZE) {
  165. ckdebug (vpBlockTop->flag == F_EOF, "internal error");
  166. while (vpBlockTop->next == NULL) {
  167. vpCur = vpBlockTop;
  168. vReaderFlag = F_DOWN;
  169. SetEvent (vSemReader);
  170. WaitForSingleObject(vSemMoreData, WAITFOREVER);
  171. ResetEvent(vSemMoreData);
  172. }
  173. vOffTop = 0;
  174. vpBlockTop = vpBlockTop->next;
  175. }
  176. }
  177. fclose (fp);
  178. vTopLine = hTopLine;
  179. QuickRestore ();
  180. SetUpdate (U_ALL);
  181. }
  182. void
  183. HUp ()
  184. {
  185. if (vHighTop < 0L)
  186. MarkSpot ();
  187. if (vHighTop > 0L && vHighTop+vHighLen > 0L)
  188. UpdateHighLighted (-1, 3);
  189. }
  190. void
  191. HDn ()
  192. {
  193. if (vHighTop < 0L)
  194. MarkSpot ();
  195. if (vHighTop+vHighLen < vLastLine)
  196. UpdateHighLighted (+1, 3);
  197. }
  198. void
  199. HPgDn ()
  200. {
  201. if (vHighTop < 0L)
  202. MarkSpot ();
  203. if (vHighTop+vHighLen+vLines < vLastLine)
  204. UpdateHighLighted (+vLines, 3);
  205. }
  206. void
  207. HPgUp ()
  208. {
  209. if (vHighTop < 0L)
  210. MarkSpot ();
  211. if (vHighTop > 0L && vHighTop+vHighLen-vLines > 0L)
  212. UpdateHighLighted (-vLines, 3);
  213. }
  214. void
  215. HSDn () /* Highlight Slide dn 1 */
  216. {
  217. if (vHighTop < vLastLine && vHighTop >= 0L &&
  218. vHighTop+vHighLen < vLastLine) {
  219. vHighTop++;
  220. UpdateHighLighted (0, 2);
  221. }
  222. }
  223. void
  224. HSUp() /* Highlight Slike up 1 */
  225. {
  226. if (vHighTop > 0L && vHighTop+vHighLen > 0L) {
  227. vHighTop--;
  228. UpdateHighLighted (0, 1);
  229. }
  230. }