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.

373 lines
8.1 KiB

  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <string.h>
  4. #include <memory.h>
  5. #include <windows.h>
  6. #include "list.h"
  7. extern void DisTopDown(void);
  8. void
  9. Update_head ()
  10. {
  11. char s[80], t[20], u[20];
  12. /*
  13. * Display file location (line #)
  14. */
  15. t[0] = 0;
  16. if (vLastLine < NOLASTLINE)
  17. sprintf (t, " of %ld", vLastLine);
  18. if (vIndent)
  19. sprintf (u, "Col %d-%d", vIndent, vIndent+vWidth-1);
  20. else
  21. strcpy (u, " ");
  22. sprintf (s, "Line: %ld%s %s ", vTopLine, t, u);
  23. dis_str (22, 0, s);
  24. }
  25. void
  26. Update_display ()
  27. {
  28. COORD dwWriteCoord;
  29. DWORD dwNumWritten;
  30. /*
  31. * Is the full display in memory?
  32. * If not, block on MoreData.
  33. */
  34. while (InfoReady () == 0) {
  35. if (ScrLock (0) == 0) {
  36. Update_head ();
  37. DisLn (vWidth-6, vLines+1, "WAIT");
  38. ScrUnLock ();
  39. }
  40. ResetEvent (vSemMoreData);
  41. SetEvent (vSemReader);
  42. WaitForSingleObject(vSemMoreData, WAITFOREVER);
  43. ResetEvent(vSemMoreData);
  44. }
  45. /*
  46. * Value which InfoReady set:
  47. * vpCur, vOffTop, vpBlockTop, vrgNewLen.
  48. * Also complete video range is in memory. It should
  49. * stay there. The reader thread should not be discarding
  50. * data on the screen. Only at the other end of the chain.
  51. * (home may have a race condition... should check this)
  52. */
  53. DisTopDown();
  54. dwWriteCoord.X = 0;
  55. dwWriteCoord.Y = 1;
  56. WriteConsoleOutputCharacter( vhConsoleOutput,
  57. ( LPSTR ) vScrBuf+vWidth,
  58. vSizeScrBuf-vWidth,
  59. dwWriteCoord,
  60. &dwNumWritten );
  61. if (vHighTop >= 0L)
  62. UpdateHighNoLock ();
  63. }
  64. void
  65. calc_percent ()
  66. {
  67. char c;
  68. long l;
  69. if (vTopLine+vLines >= vLastLine) {
  70. l = 100;
  71. } else {
  72. if (vTopLine == 0L) {
  73. l = 0L;
  74. } else {
  75. l = (vpCalcBlock->offset+vOffTop)*100L/(vFInfo.nFileSizeLow-vScrMass);
  76. if (l > 100L)
  77. l = 100;
  78. }
  79. }
  80. /*
  81. * Update thumb on scroll bar
  82. */
  83. c = (char)(((long) (vLines - 3) * l + 5L) / 100L);
  84. if (c < 0)
  85. c = 0;
  86. else if (c > (char)(vLines - 3))
  87. c = (char)(vLines-3);
  88. c += 2; /* Adjust to first scroll bar line */
  89. if (vLastBar != c) {
  90. dis_str ((Uchar)(vWidth-1), (Uchar)(vLastBar), szScrollBarOff);
  91. dis_str ((Uchar)(vWidth-1), vLastBar = c, szScrollBarOn);
  92. }
  93. }
  94. void
  95. DrawBar ()
  96. {
  97. int i, off;
  98. off = vWidth-1;
  99. dis_str ((Uchar)off, 1, szScrollBarUp);
  100. dis_str ((Uchar)off, 2, szScrollBarOn);
  101. dis_str ((Uchar)off, (Uchar)vLines, szScrollBarDown);
  102. for (i=3; i < vLines; i++)
  103. dis_str ((Uchar)off, (Uchar)i, szScrollBarOff);
  104. vLastBar = 2; /* Top line + 1 */
  105. return ;
  106. }
  107. void
  108. fancy_percent ()
  109. {
  110. int hOffTop;
  111. if (ScrLock (0))
  112. return;
  113. hOffTop = vOffTop; /* Setup for calc */
  114. vOffTop = 0;
  115. vpCalcBlock = vpBlockTop;
  116. calc_percent ();
  117. vOffTop = hOffTop;
  118. ScrUnLock ();
  119. }
  120. /*** dis_str - Displays string at corrds given
  121. *
  122. */
  123. void
  124. dis_str (
  125. Uchar x,
  126. Uchar y,
  127. char* s
  128. )
  129. {
  130. COORD dwWriteCoord;
  131. DWORD dwNumWritten;
  132. int len;
  133. len = strlen (s);
  134. memcpy (vScrBuf+y*vWidth+x, s, len);
  135. dwWriteCoord.X = x;
  136. dwWriteCoord.Y = y;
  137. WriteConsoleOutputCharacter( vhConsoleOutput,
  138. s,
  139. strlen( s ),
  140. dwWriteCoord,
  141. &dwNumWritten );
  142. }
  143. /*** DisLn - Displays string at corrds given, clear to EOL
  144. *
  145. *
  146. */
  147. void
  148. DisLn (
  149. int x,
  150. int y,
  151. char* s
  152. )
  153. {
  154. COORD dwWriteCoord;
  155. DWORD dwNumWritten;
  156. if (y == vLines+1)
  157. vStatCode |= S_UPDATE | S_CLEAR;
  158. dwWriteCoord.X = (SHORT)x;
  159. dwWriteCoord.Y = (SHORT)y;
  160. ScrLock( 1 );
  161. WriteConsoleOutputCharacter( vhConsoleOutput,
  162. s,
  163. strlen( s ),
  164. dwWriteCoord,
  165. &dwNumWritten );
  166. dwWriteCoord.X += (SHORT) strlen( s );
  167. FillConsoleOutputCharacter( vhConsoleOutput,
  168. 0x20,
  169. vWidth - dwWriteCoord.X,
  170. dwWriteCoord,
  171. &dwNumWritten );
  172. ScrUnLock ();
  173. }
  174. void
  175. setattr (
  176. int line,
  177. char attr
  178. )
  179. {
  180. COORD dwWriteCoord;
  181. DWORD dwNumWritten;
  182. if (line == 0 || line == vLines+1)
  183. vStatCode |= S_UPDATE;
  184. dwWriteCoord.X = 0;
  185. dwWriteCoord.Y = (SHORT)line;
  186. FillConsoleOutputCharacter( vhConsoleOutput,
  187. ' ',
  188. vWidth,
  189. dwWriteCoord,
  190. &dwNumWritten );
  191. FillConsoleOutputAttribute( vhConsoleOutput,
  192. attr,
  193. vWidth,
  194. dwWriteCoord,
  195. &dwNumWritten );
  196. // Scroll Bar is in last Column
  197. dwWriteCoord.X = (SHORT)(vWidth-1);
  198. FillConsoleOutputCharacter( vhConsoleOutput,
  199. ' ',
  200. 1,
  201. dwWriteCoord,
  202. &dwNumWritten );
  203. FillConsoleOutputAttribute( vhConsoleOutput,
  204. vAttrBar,
  205. 1,
  206. dwWriteCoord,
  207. &dwNumWritten );
  208. }
  209. void
  210. setattr1 (
  211. int line,
  212. char attr
  213. )
  214. {
  215. COORD dwWriteCoord;
  216. DWORD dwNumWritten;
  217. dwWriteCoord.X = 0;
  218. dwWriteCoord.Y = (SHORT)line;
  219. FillConsoleOutputAttribute( vhConsoleOutput,
  220. attr,
  221. vWidth-1,
  222. dwWriteCoord,
  223. &dwNumWritten );
  224. }
  225. void
  226. setattr2 (
  227. int line,
  228. int start,
  229. int len,
  230. char attr
  231. )
  232. {
  233. COORD dwWriteCoord;
  234. DWORD dwNumWritten;
  235. dwWriteCoord.X = (SHORT)start;
  236. dwWriteCoord.Y = (SHORT)line;
  237. ScrLock (1);
  238. FillConsoleOutputAttribute( vhConsoleOutput,
  239. attr,
  240. len,
  241. dwWriteCoord,
  242. &dwNumWritten );
  243. ScrUnLock ();
  244. }
  245. /*** ScrLock - With levels for multiple threads
  246. *
  247. * n = 0 - Return 0 if locked, 1 if not locked. Do not wait.
  248. * 1 - Return when screen locked
  249. */
  250. int
  251. ScrLock (
  252. int n
  253. )
  254. {
  255. n=0; // to get rid of warning message
  256. WaitForSingleObject(vSemLock, WAITFOREVER);
  257. ResetEvent(vSemLock);
  258. vcntScrLock++;
  259. SetEvent (vSemLock);
  260. return (0);
  261. }
  262. void
  263. ScrUnLock ()
  264. {
  265. WaitForSingleObject(vSemLock, WAITFOREVER);
  266. ResetEvent(vSemLock);
  267. --vcntScrLock;
  268. SetEvent (vSemLock);
  269. }
  270. void
  271. SpScrUnLock ()
  272. {
  273. COORD dwWriteCoord;
  274. DWORD dwNumWritten;
  275. if (vStatCode & S_CLEAR)
  276. setattr (vLines+1, (char)vAttrCmd);
  277. if (vStatCode & S_UPDATE) {
  278. dis_str ((Uchar)(vWidth - ST_ADJUST), 0, vDate); /* warning: also print vdate*/
  279. DisLn (0, (Uchar)(vLines+1), "Command> "); /* in lread.c */
  280. DisLn (0, (Uchar)(vLines+2), ""); /* in lread.c */
  281. vStatCode &= ~(S_CLEAR|S_UPDATE|S_WAIT);
  282. }
  283. /*
  284. * If no file, then make error blink
  285. */
  286. if (vFInfo.nFileSizeLow == -1L) {
  287. dwWriteCoord.X = (SHORT)(vWidth-ST_ADJUST);
  288. dwWriteCoord.Y = 0;
  289. FillConsoleOutputAttribute( vhConsoleOutput,
  290. (WORD) (vAttrTitle | BACKGROUND_INTENSITY),
  291. ST_ADJUST,
  292. dwWriteCoord,
  293. &dwNumWritten );
  294. }
  295. /*
  296. * Calculate file position. (percent to EOF)
  297. */
  298. calc_percent ();
  299. if (vSpLockFlag) {
  300. vSpLockFlag = 0;
  301. ScrUnLock ();
  302. }
  303. }