home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume23 / asp / part01 / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-16  |  4.1 KB  |  207 lines

  1. /*
  2.  * This code is copyright ADE Muffett, September 1991, and is distributed as
  3.  * part of the ASP .plan description language compiler.  This code is freely
  4.  * redistributable as long as this copyright notice remains intact. No
  5.  * responsibility is assumed by the author for any situation which arises
  6.  * from the use of this code, including insanity, late nights, or disk
  7.  * storage problems.
  8.  */
  9.  
  10. #include "asp.h"
  11. #undef DEBUG
  12.  
  13. static char currline[SCREENWIDTH + 1];    /* The state of the union... */
  14.  
  15. /* nothing */
  16. void
  17. Noop ()
  18. {
  19. }
  20. /* Throw a newline */
  21. void
  22. LineFeed ()
  23. {
  24.     static char lf = '\n';
  25.  
  26.     putchar (lf);
  27.     NullSet (currline, sizeof (currline));
  28.     SpaceFlood (currline, sizeof (currline));
  29.     currline[SCREENWIDTH] = '\0';
  30. }
  31. /* Throw a carriage return */
  32. void
  33. CReturn ()
  34. {
  35.     static char cr = '\r';
  36.  
  37.     putchar (cr);
  38. }
  39. /* Fast clear of the current line */
  40. void
  41. Wipe ()
  42. {
  43.     NullSet (stdline, sizeof (stdline));
  44. }
  45. /* Fast clear of the current line */
  46. void
  47. Clear ()
  48. {
  49.     Wipe ();
  50.     UpdateCR ();
  51. }
  52. /* show something onto screen destructively */
  53. void
  54. Show (cstring, dstring)
  55.     char *cstring;
  56.     char *dstring;
  57. {
  58.     Wipe ();
  59.     Overlay (stdline, dstring);
  60.     UpdateCR ();
  61. }
  62. /* show something onto screen non destructively */
  63. void
  64. TShow (cstring, dstring)
  65.     char *cstring;
  66.     char *dstring;
  67. {
  68.     TransparentOverlay (stdline, dstring);
  69.     UpdateCR ();
  70. }
  71. /* Pause about 1 second @ 9600 baud */
  72. void
  73. Pause ()
  74. {
  75.     register int i;
  76.  
  77.     for (i = 0; i < LOOP_COUNT; i++)
  78.     {
  79.     CReturn ();
  80.     }
  81.     for (i = (LOOP_COUNT * (speed / DUMMY_RETURNS)); i; i--)
  82.     {
  83.     CReturn ();
  84.     }
  85. }
  86. /* Trim off all whitespace from a text line */
  87. void
  88. Trim (ptr)
  89.     register char *ptr;
  90. {
  91.     while (*ptr)
  92.     {
  93.     ptr++;
  94.     }
  95.     while (isspace (*(--ptr)));
  96.     *(++ptr) = '\0';
  97. }
  98. /* the display primitive */
  99. int
  100. Update ()
  101. {
  102.     register int i;
  103.     int j;
  104.     int print_anim;
  105.     int print_stdline;
  106.     char diffline[SCREENWIDTH + 1];
  107.  
  108.     /* fix up all spaces */
  109.     SpaceFlood (background, SCREENWIDTH);
  110.     background[SCREENWIDTH] = '\0';
  111.     Trim (background);
  112.  
  113.     SpaceFlood (stdline, SCREENWIDTH);
  114.     stdline[SCREENWIDTH] = '\0';
  115.     Trim (stdline);
  116.  
  117.     SpaceFlood (anim_buffer, SCREENWIDTH);
  118.     anim_buffer[SCREENWIDTH] = '\0';
  119.     Trim (anim_buffer);
  120.  
  121.     SpaceFlood (foreground, SCREENWIDTH);
  122.     foreground[SCREENWIDTH] = '\0';
  123.     Trim (foreground);
  124.  
  125. #ifdef DEBUG
  126.     printf ("bg'%s'\n", background);
  127.     printf ("st'%s'\n", stdline);
  128.     printf ("ab'%s'\n", anim_buffer);
  129.     printf ("fg'%s'\n", foreground);
  130. #endif
  131.  
  132.     /* zero the differences buffer */
  133.     NullSet (diffline, sizeof (diffline));
  134.     SpaceFlood (diffline, SCREENWIDTH);
  135.     diffline[SCREENWIDTH] = '\0';
  136.  
  137.     TransparentOverlay (diffline, background);
  138.     TransparentOverlay (diffline, stdline);
  139.     TransparentOverlay (diffline, anim_buffer);
  140.     TransparentOverlay (diffline, foreground);
  141.     Trim (diffline);
  142.  
  143.     /* and tidy up the memory copy of the current line */
  144.     Trim (currline);        /* this is what the screen is */
  145.  
  146.     i = strlen (diffline);
  147.     j = strlen (currline);
  148.     if (i < j)
  149.     {
  150.     for (; i < j && i < SCREENWIDTH; i++)
  151.     {
  152.         diffline[i] = ' ';
  153.     }
  154.     diffline[j] = '\0';
  155.     }
  156.     diffline[SCREENWIDTH] = '\0';
  157.  
  158.     /* there is a difference between screen and stdline+overstrikes */
  159.     if (strcmp (currline, diffline))
  160.     {
  161.     char printline[SCREENWIDTH + 1];
  162.  
  163.     /* backup diffline */
  164.     Memcpy (printline, diffline, sizeof (printline));
  165.  
  166.     /* don't print common trailing characters except space */
  167.     if ((i = strlen (currline)) == strlen (diffline))
  168.     {
  169.         while (i-- && (diffline[i] == currline[i]))
  170.         {
  171.         printline[i] = '\0';
  172.         }
  173.     }
  174.     /* print only what is necessary to make changes */
  175.     printf ("%s", printline);
  176.  
  177.     /* make diffline the current line */
  178.     Memcpy (currline, diffline, sizeof (currline));
  179.  
  180.     /* fill out line */
  181.     return (strlen (printline));
  182.     } else
  183.     {
  184.     return (SCREENWIDTH);
  185.     }
  186. }
  187. /* save typing */
  188. void
  189. UpdateCR ()
  190. {
  191.     register int i;
  192.  
  193.     i = Update ();
  194.     CReturn ();
  195.  
  196.     while (smooth && (i++ < SCREENWIDTH))
  197.     {
  198.     CReturn ();
  199.     }
  200.  
  201.     for (i = 0; i < (speed * DUMMY_RETURNS); i++)
  202.     {
  203.     CReturn ();
  204.     }
  205. }
  206. /* END OF DISPLAY PRIMITIVES */
  207.