home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume29 / therm / part01 next >
Text File  |  1992-05-19  |  7KB  |  268 lines

  1. Newsgroups: comp.sources.misc
  2. From: erc@Apple.COM (Ed Carp)
  3. Subject:  v29i127:  therm - simple ASCII graphic display of numerical data, Part01/01
  4. Message-ID: <1992May17.185749.1274@sparky.imd.sterling.com>
  5. X-Md4-Signature: 02fd6fefb761fb03aa14455d8614ce2d
  6. Date: Sun, 17 May 1992 18:57:49 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: erc@Apple.COM (Ed Carp)
  10. Posting-number: Volume 29, Issue 127
  11. Archive-name: therm/part01
  12. Environment: UNIX, MS-DOS
  13.  
  14. Here are some simple (yet powerful) routines for displaying numerical
  15. data in a graphical way.  I use these routines when I need to give a
  16. status report to a user showing how much, how far, or how long.
  17. They've managed to worm their way into DES routines, compress(1) --
  18. anywhere there's a need to give a status feedback to the user.
  19.  
  20. These routines work under unix (well, sort of), but they aren't
  21. really fancy-looking, since most unix curses implementations
  22. don't pay attention to graphics characters.  They work very well
  23. (and look nicest) under MS-DOS.
  24.  
  25. Comments, suggesions, and (shudder) bug fixes are welcome!
  26.  
  27. #! /bin/sh
  28. #
  29. # Created by shar, version 0.5 - 04/10/91
  30. #
  31. # This is a shell archive, meaning:
  32. # 1. Remove everything about the #! /bin/sh line.
  33. # 2. Save the resulting text in a file.
  34. # 3. Execute the file with /bin/sh to create:
  35. #
  36. #        length  name
  37. #        ------  -------------------------------------
  38. #          1892  therm.3
  39. #          2245  therm.c
  40. #
  41.  
  42. #
  43. # Archive number 1
  44. # This archive created Tue Apr 28 12:03:06 1992
  45. #
  46.  
  47. echo "shar: extracting therm.3 - (1892 characters)"
  48. if test -f 'therm.3' ; then
  49.    echo shar: will not over-write existing file therm.3
  50. else
  51. sed 's/^X//' << \SHAR_EOF > 'therm.3'
  52. X.TH THERM 3 "April 28, 1992" "Version 1.0"
  53. X.SH NAME
  54. Xtherm \- ASCII graphic display of data
  55. X.SH SYNOPSIS
  56. X.DS
  57. X.sp
  58. XWINDOW *thermstart(title, comment, ypos, xpos)
  59. X.br
  60. Xchar *title; /* window title */
  61. X.br
  62. Xchar *comment; /* window text */
  63. X.br
  64. Xint ypos; /* starting vertical position of window, EOF if centered */
  65. X.br
  66. Xint xpos; /* starting horiz position of window, EOF if centered */
  67. X.br
  68. X
  69. Xthermometer(w1, percent)
  70. X.br
  71. XWINDOW *w1; /* returned from thermstart() */
  72. X.br
  73. Xint percent; /* percent (0-100) of scale */
  74. X.br
  75. X
  76. Xthermend(w1)
  77. X.br
  78. XWINDOW *w1; /* returned from thermstart() */
  79. X.br
  80. X.DE
  81. X.SH DESCRIPTION
  82. XThese routines give the programmer a simple way to display
  83. Xnumerical information graphically.  Any number of therm windows
  84. Xmay be active at one time.
  85. X.PP
  86. XThe therm window is opened by calling
  87. X.I thermstart(),
  88. Xwhich returns a WINDOW pointer which is used in subsequent references.
  89. XTo display data, call
  90. X.I thermometer()
  91. Xwith the appropriate parameters.
  92. XTo end a therm window display, call
  93. X.I thermend().
  94. X.SH EXAMPLE
  95. XThe following is a trivial code fragment illustrating the use of the therm
  96. Xroutines:
  97. X.PP
  98. X.DS
  99. XWINDOW *tw1, *tw2, *thermstart();
  100. X.br
  101. X.I ...
  102. X.br
  103. Xsprintf(message, "Copying file %s to %s", argv[1], argv[2]);
  104. X.br
  105. X/* center therm windows horizontally */
  106. X.br
  107. Xtw1 = thermstart("File 1 Status", message, 2, EOF);
  108. X.br
  109. Xtw2 = thermstart("File 2 Status", message, 10, EOF);
  110. X.br
  111. X.I ...
  112. X.br
  113. Xwhile(.../* copying */...)
  114. X.br
  115. X{
  116. X.br
  117. X.I ...
  118. X.br
  119. X   thermometer(tw1, (int) (100.0 * ((float) read / (float) total)));
  120. X.br
  121. X.I ...
  122. X   thermometer(tw2, (int) (100.0 * ((float) written / (float) total)));
  123. X.br
  124. X.I ...
  125. X.br
  126. X}
  127. X.br
  128. X.I ...
  129. X.br
  130. Xthermend(tw2); /* drop window */
  131. X.br
  132. Xthermend(tw1); /* drop window */
  133. X.br
  134. X.I ...
  135. X.br
  136. X.DE
  137. X.SH SEE ALSO
  138. Xcurses(3).
  139. X.SH CREDITS
  140. XThese routines were written by Ed Carp (erc@apple.com).
  141. XCopyright 1992 by Ed Carp.
  142. XCommercial use of these routines without permission is prohibited.
  143. SHAR_EOF
  144. if test 1892 -ne "`wc -c < 'therm.3'`" ; then
  145.    echo "shar: ***** error transmitting file therm.3 (should have been 1892 characters, but was "`wc -c < 'therm.3'`" characters) *****"
  146. fi
  147. fi
  148.  
  149. touch 0428120392 therm.3
  150. chmod 0644 therm.3
  151.  
  152. echo "shar: extracting therm.c - (2245 characters)"
  153. if test -f 'therm.c' ; then
  154.    echo shar: will not over-write existing file therm.c
  155. else
  156. sed 's/^X//' << \SHAR_EOF > 'therm.c'
  157. X/*
  158. X * therm - thermometer-like "walking bar" status boxes for curses
  159. X * 
  160. X * This stuff will work on either unix or ms-dos (with just about anyone's
  161. X * curses package).
  162. X * 
  163. X * written 04/92 by ed carp (erc@apple.com)
  164. X * 
  165. X * Copyright 1992 by Ed Carp. Commercial use prohibited without permission.
  166. X * 
  167. X */
  168. X
  169. X#include <curses.h>
  170. X#define THERMLEN 70
  171. X#ifdef MSDOS
  172. X#define TFULL '\333'
  173. X#define TEMPTY '\261'
  174. X#define TLFBAR '\336'
  175. X#define TRTBAR '\335'
  176. X#else
  177. X#define TFULL '*'
  178. X#define TEMPTY ' '
  179. X#define TLFBAR '|'
  180. X#define TRTBAR '|'
  181. X#endif
  182. Xchar            therm[THERMLEN];
  183. Xint             therm_m, therm_m2;
  184. X
  185. XWINDOW         *
  186. Xthermstart(title, comment, ypos, xpos)
  187. X   char           *title, *comment;
  188. X   int             ypos, xpos;
  189. X{
  190. X   int             i, mx, mt, mc;
  191. X   WINDOW         *therm_w1;
  192. X
  193. X   mt = strlen(title);
  194. X   mc = strlen(comment);
  195. X   mx = (mt > mc ? mt : mc);
  196. X   if (ypos == EOF)
  197. X      ypos = (LINES - 5) / 2;
  198. X   if (xpos == EOF)
  199. X      xpos = (COLS - THERMLEN) / 2;
  200. X   therm_w1 = newwin(5, THERMLEN + 2, (LINES - 5) / 2, (COLS - THERMLEN) / 2);
  201. X   if (therm_w1 != (WINDOW *) ERR)
  202. X   {
  203. X      attron(A_ALTCHARSET);
  204. X      box(therm_w1, NULL, NULL);
  205. X      mvwaddstr(therm_w1, 0, ((THERMLEN + 2 - mt) / 2), title);
  206. X      mvwaddstr(therm_w1, 1, ((THERMLEN + 2 - mc) / 2), comment);
  207. X      for (i = 0; i < THERMLEN; i++)
  208. X     *(therm + i) = TEMPTY;
  209. X      *(therm) = TLFBAR;
  210. X      *(therm + (THERMLEN - 2)) = TRTBAR;
  211. X      *(therm + (THERMLEN - 1)) = (0);
  212. X      mvwaddstr(therm_w1, 3, 2, therm);
  213. X      wrefresh(therm_w1);
  214. X      therm_m2 = 0;
  215. X   }
  216. X   attron(A_NORMAL);
  217. X   return (therm_w1);
  218. X}
  219. X
  220. Xthermend(therm_w1)
  221. X   WINDOW         *therm_w1;
  222. X{
  223. X   delwin(therm_w1);
  224. X}
  225. X
  226. Xthermometer(therm_w1, percent)
  227. X   WINDOW         *therm_w1;
  228. X   int             percent;
  229. X{
  230. X   int             i;
  231. X
  232. X   if (percent > 100)
  233. X      percent = 100;
  234. X   if (percent < 0)
  235. X      percent = 0;
  236. X   therm_m = 1 + (int) ((float) (THERMLEN - 4) * ((float) percent / 100.0));
  237. X   if (therm_m != therm_m2)
  238. X   {
  239. X      for (i = 0; i < THERMLEN - 2; i++)
  240. X     if (i < therm_m + 1)
  241. X        *(therm + i) = TFULL;
  242. X     else
  243. X        *(therm + i) = TEMPTY;
  244. X      therm_m2 = therm_m;
  245. X      attron(A_ALTCHARSET);
  246. X      mvwaddstr(therm_w1, 3, 2, therm);
  247. X      attron(A_NORMAL);
  248. X      wrefresh(therm_w1);
  249. X   }
  250. X}
  251. SHAR_EOF
  252. if test 2245 -ne "`wc -c < 'therm.c'`" ; then
  253.    echo "shar: ***** error transmitting file therm.c (should have been 2245 characters, but was "`wc -c < 'therm.c'`" characters) *****"
  254. fi
  255. fi
  256.  
  257. touch 0428120392 therm.c
  258. chmod 0644 therm.c
  259. echo End of all shell archives
  260. exit 0
  261. -- 
  262. Ed Carp  N7EKG/6    erc@khijol.UUCP        erc@apple.com
  263.             Cupertino, CA        415/336-0797
  264.  
  265. -- Absolutely unabashed Gates McFadden groupie! --
  266.  
  267. exit 0 # Just in case...
  268.