abstract
| - Below is the full text to topl.c from the source code of NetHack 1.4f. To link to a particular line, write [[NetHack 1.4f/topl.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)topl.c 1.4 87/08/08 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* topl.c - version 1.0.2 */ 4. 5. #include 6. #include "hack.h" 7. #ifdef GENIX 8. #define void int /* jhn - mod to prevent compiler from bombing */ 9. #endif 10. 11. extern char *eos(); 12. extern int CO; 13. 14. char toplines[BUFSZ]; 15. xchar tlx, tly; /* set by pline; used by addtopl */ 16. 17. struct topl { 18. struct topl *next_topl; 19. char *topl_text; 20. } *old_toplines, *last_redone_topl; 21. #define OTLMAX 20 /* max nr of old toplines remembered */ 22. 23. doredotopl(){ 24. if(last_redone_topl) 25. last_redone_topl = last_redone_topl->next_topl; 26. if(!last_redone_topl) 27. last_redone_topl = old_toplines; 28. if(last_redone_topl){ 29. (void) strcpy(toplines, last_redone_topl->topl_text); 30. } 31. redotoplin(); 32. return(0); 33. } 34. 35. redotoplin() { 36. home(); 37. if(index(toplines, '
')) cl_end(); 38. putstr(toplines); 39. cl_end(); 40. tlx = curx; 41. tly = cury; 42. flags.toplin = 1; 43. if(tly > 1) 44. more(); 45. } 46. 47. remember_topl() { 48. register struct topl *tl; 49. register int cnt = OTLMAX; 50. if(last_redone_topl && 51. !strcmp(toplines, last_redone_topl->topl_text)) return; 52. if(old_toplines && 53. !strcmp(toplines, old_toplines->topl_text)) return; 54. last_redone_topl = 0; 55. tl = (struct topl *) 56. alloc((unsigned)(strlen(toplines) + sizeof(struct topl) + 1)); 57. tl->next_topl = old_toplines; 58. tl->topl_text = (char *)(tl + 1); 59. (void) strcpy(tl->topl_text, toplines); 60. old_toplines = tl; 61. while(cnt && tl){ 62. cnt--; 63. tl = tl->next_topl; 64. } 65. if(tl && tl->next_topl){ 66. free((char *) tl->next_topl); 67. tl->next_topl = 0; 68. } 69. } 70. 71. addtopl(s) char *s; { 72. curs(tlx,tly); 73. if(tlx + strlen(s) > CO) putsym('
'); 74. putstr(s); 75. tlx = curx; 76. tly = cury; 77. flags.toplin = 1; 78. } 79. 80. xmore(s) 81. char *s; /* allowed chars besides space/return */ 82. { 83. if(flags.toplin) { 84. curs(tlx, tly); 85. if(tlx + 8 > CO) putsym('
'), tly++; 86. } 87. 88. if(flags.standout) 89. standoutbeg(); 90. putstr("--More--"); 91. if(flags.standout) 92. standoutend(); 93. 94. xwaitforspace(s); 95. if(flags.toplin && tly > 1) { 96. home(); 97. cl_end(); 98. docorner(1, tly-1); 99. } 100. flags.toplin = 0; 101. } 102. 103. more(){ 104. xmore(""); 105. } 106. 107. cmore(s) 108. register char *s; 109. { 110. xmore(s); 111. } 112. 113. clrlin(){ 114. if(flags.toplin) { 115. home(); 116. cl_end(); 117. if(tly > 1) docorner(1, tly-1); 118. remember_topl(); 119. } 120. flags.toplin = 0; 121. } 122. 123. /*VARARGS1*/ 124. /* Because the modified mstatusline has 9 arguments KAA */ 125. pline(line,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9) 126. register char *line,*arg1,*arg2,*arg3,*arg4,*arg5,*arg6,*arg7,*arg8,*arg9; 127. { 128. char pbuf[BUFSZ]; 129. register char *bp = pbuf, *tl; 130. register int n,n0; 131. 132. if(!line || !*line) return; 133. if(!index(line, '%')) (void) strcpy(pbuf,line); else 134. (void) sprintf(pbuf,line,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9); 135. if(flags.toplin == 1 && !strcmp(pbuf, toplines)) return; 136. nscr(); /* %% */ 137. 138. /* If there is room on the line, print message on same line */ 139. /* But messages like "You die..." deserve their own line */ 140. n0 = strlen(bp); 141. if(flags.toplin == 1 && tly == 1 && 142. n0 + strlen(toplines) + 3 < CO-8 && /* leave room for --More-- */ 143. strncmp(bp, "You ", 4)) { 144. (void) strcat(toplines, " "); 145. (void) strcat(toplines, bp); 146. tlx += 2; 147. addtopl(bp); 148. return; 149. } 150. if(flags.toplin == 1) more(); 151. remember_topl(); 152. toplines[0] = 0; 153. while(n0){ 154. if(n0 >= CO){ 155. /* look for appropriate cut point */ 156. n0 = 0; 157. for(n = 0; n < CO; n++) if(bp[n] == ' ') 158. n0 = n; 159. if(!n0) for(n = 0; n < CO-1; n++) 160. if(!letter(bp[n])) n0 = n; 161. if(!n0) n0 = CO-2; 162. } 163. (void) strncpy((tl = eos(toplines)), bp, n0); 164. tl[n0] = 0; 165. bp += n0; 166. 167. /* remove trailing spaces, but leave one */ 168. while(n0 > 1 && tl[n0-1] == ' ' && tl[n0-2] == ' ') 169. tl[--n0] = 0; 170. 171. n0 = strlen(bp); 172. if(n0 && tl[0]) (void) strcat(tl, "
"); 173. } 174. redotoplin(); 175. } 176. 177. putsym(c) char c; { 178. switch(c) { 179. case '\b': 180. backsp(); 181. return; 182. case '
': 183. curx = 1; 184. cury++; 185. if(cury > tly) tly = cury; 186. break; 187. default: 188. if(curx == CO) 189. putsym('
'); /* 1 <= curx <= CO; avoid CO */ 190. else 191. curx++; 192. } 193. (void) putchar(c); 194. } 195. 196. putstr(s) register char *s; { 197. while(*s) putsym(*s++); 198. }
|