home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume13 / rolodex / part01 / clear.c < prev    next >
C/C++ Source or Header  |  1988-01-30  |  2KB  |  105 lines

  1. /* clear.c */
  2. #include <stdio.h>
  3. #ifdef TERMINFO
  4. #include <term.h>
  5. #endif
  6. #undef putchar
  7.  
  8. int putchar();
  9.  
  10. #ifdef TERMCAP
  11. static int ok_to_clear;
  12. #endif
  13.  
  14. #ifdef TERMINFO
  15. static int ok_to_clear;
  16. #endif
  17.  
  18. #ifdef TERMCAP
  19. static char clear_screen[128] = 0;
  20. static int lines;
  21. #endif
  22.  
  23. #ifdef MSDOS
  24. /*
  25.  * IF we assume the standard ANSI terminal driver, we can't go TOO far wrong...
  26.  * but allow a bailout.  Making this assumption, we realize that it's a
  27.  * VT-100 sequence, so for this one file...
  28.  */
  29. #ifndef GENERIC_SCR
  30. #define VMS
  31. #endif
  32. #endif
  33.  
  34. #ifdef VMS
  35. /*
  36.  * VMS is so heavily targeted to VT-100 screens that we can assume...
  37.  */
  38. static char vt100_clear[128] = { '\033','[','H','\033','[','2','J','\0' };
  39. #endif
  40.  
  41.  
  42. #ifdef GENERIC_SCR
  43. /* This is pretty generic... */
  44. #define CLR_LINES    30
  45. #endif
  46.  
  47. clearinit ()
  48. {
  49. #ifdef TERMINFO
  50.   int i;        
  51.   char *getenv();
  52.   char *name = "TERM";
  53. /* setupterm(getenv(name),1,&i); *//* As of at least SVID Issue 2, Vol. 2 */
  54.   i = setterm(getenv(name));
  55.   ok_to_clear = (i == 1) ? 1 : 0;
  56.   if (i != 1) {
  57.      fprintf(stderr,"Warning: Terminal type unknown\n");
  58.   }
  59.   return (i == 1) ? 0 : -1;
  60. #endif
  61. #ifdef TERMCAP
  62.   char tc[1024];
  63.   char *ptr = clear_screen;
  64.   char *getenv();
  65.   char *name = "TERM";
  66.   
  67.   if (tgetent(tc, getenv(name)) < 1) {
  68.     ok_to_clear = 0;
  69.     return;
  70.   }
  71.   tgetstr("cl", &ptr);
  72.   lines = tgetnum("li");
  73.   ok_to_clear = (clear_screen[0] != 0 && lines > 0);
  74.  
  75. #endif
  76. }        
  77.         
  78. clear_the_screen ()
  79. {
  80. #ifdef TERMINFO
  81.   if (!ok_to_clear) return;        
  82.   tputs(clear_screen,lines,putchar);
  83.   fflush(stdout);
  84. #endif
  85. #ifdef TERMCAP
  86.   if (!ok_to_clear) return;
  87.   tputs(clear_screen,lines,putchar);
  88.   fflush(stdout);
  89. #endif
  90.  
  91. #ifdef VMS
  92.   fputs(vt100_clear,stdout);
  93.   fflush(stdout);
  94. #endif
  95. #ifdef GENERIC_SCR
  96.   {
  97.     register int index;
  98.  
  99.     for(index = 0;index < CLR_LINES ;index++)
  100.         putchar('\n');
  101.   }
  102.   fflush(stdout);
  103. #endif
  104. }
  105.