home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / mytinfo / part02 / ttest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  4.9 KB  |  283 lines

  1. /*
  2.  * ttest.c
  3.  *
  4.  * By Ross Ridge
  5.  * Public Domain
  6.  * 92/02/01 07:30:47
  7.  *
  8.  */
  9.  
  10. #define NOTLIB
  11. #include "defs.h"
  12. #include "term.h"
  13.  
  14. static const char SCCSid[] = "@(#) mytinfo ttest.c 3.2 92/02/01 public domain, By Ross Ridge";
  15.  
  16. int
  17. cup(x,y)
  18. int x, y; {
  19.     if (columns < 2 || lines < 2)
  20.         return -1;
  21.     if (cursor_address != NULL) 
  22.         putp(tparm(cursor_address, y, x));
  23.     else if (cursor_home != NULL && cursor_down != NULL
  24.          && cursor_right != NULL) {
  25.         putp(cursor_home);
  26.         if (parm_down_cursor != NULL)
  27.             putp(tparm(parm_down_cursor, y));
  28.         else
  29.             for(; y > 0; y--)
  30.                 putp(cursor_down);
  31.         if (parm_right_cursor != NULL)
  32.             putp(tparm(parm_right_cursor, y));
  33.         else
  34.             for(; y > 0; y--)
  35.                 putp(cursor_right);
  36.     } else if (cursor_to_ll != NULL && cursor_up != NULL
  37.            && cursor_right != NULL) {
  38.         putp(cursor_to_ll);
  39.         if (parm_up_cursor != NULL)
  40.             putp(tparm(parm_up_cursor, y));
  41.         else
  42.             for(y++; y < columns ; y++)
  43.                 putp(cursor_up);
  44.         if (parm_right_cursor != NULL)
  45.             putp(tparm(parm_right_cursor, y));
  46.         else
  47.             for(; y > 0; y--)
  48.                 putp(cursor_right);
  49.     } else
  50.         return 1;
  51.     return 0;
  52. }
  53.  
  54. int
  55. clear() {
  56.     int r;
  57.     if (clear_screen != NULL)
  58.         putp(clear_screen);
  59.     else if (clr_eos != NULL) {
  60.         r = cup(0,0);
  61.         if (r != 0)
  62.             return r;
  63.         putp(clr_eos);
  64.     } else
  65.         return -2;
  66.     return 0;
  67. }
  68.  
  69. void
  70. nl() {
  71.     if (newline != NULL) 
  72.         putp(newline);
  73.     else if (carriage_return != NULL && cursor_down != NULL) {
  74.         putp(cursor_down);
  75.         putp(carriage_return);
  76.     } else 
  77.         quit(-1, "can't do a newline");
  78.     return;
  79. }
  80.  
  81. void
  82. putln(s)
  83. char *s; {
  84.     int i;
  85.  
  86.     if (columns < 2 || auto_right_margin)
  87.         fputs(s, stdout);
  88.     else {
  89.         i = 0;
  90.         while(*s) {
  91.             putchar(*s);
  92.             s++;
  93.             if (++i == columns) {
  94.                 nl();
  95.                 i = 0;
  96.             }
  97.         }
  98.     }
  99.     nl();
  100. }
  101.  
  102. void
  103. anykey() {
  104.     fputs("-- press any key --", stdout);
  105.     fflush(stdout);
  106.     getchar();
  107.     nl();
  108. }
  109.  
  110. void
  111. do_cleanup(e)
  112. int e; {
  113.     fflush(stdout);
  114.     fflush(stderr);
  115.     reset_shell_mode();
  116.     fprintf(stderr, "\n");
  117. }
  118.  
  119. #ifdef USE_SGTTY
  120. struct sgttyb new_tty;
  121. #else
  122. struct termio new_tty;
  123. #endif
  124.  
  125. int
  126. main(argc, argv)
  127. int argc;
  128. char **argv; {
  129.     int r;
  130.     register int i;
  131.  
  132.     prg_name = argv[0];
  133.     cleanup = do_cleanup;
  134.  
  135.     if (argc == 1)
  136.         setupterm(NULL, 1, (int *) 0);
  137.     else if (argc == 2)
  138.         setupterm(argv[1], 1, (int *) 0);
  139.     else {
  140.         fprintf(stderr, "usage: %s [terminal]\n", argv[0]);
  141.         return 1;
  142.     }
  143.     fflush(stderr);
  144.     fflush(stdout);
  145. #ifdef USE_SGTTY
  146.     ioctl(1, TIOCGETP, &new_tty);
  147.     new_tty.sg_flags &= ~(CRMOD | ECHO | XTABS);
  148. #ifdef CBREAK
  149.     new_tty.sg_flags |= CBREAK;
  150. #else
  151.     new_tty.sg_flags |= RAW;
  152. #endif
  153.     ioctl(1, TIOCSETP, &new_tty);
  154. #endif
  155. #ifdef USE_TERMIO
  156.     ioctl(1, TCGETA, &new_tty);
  157.     new_tty.c_lflag &= ~(ICANON | ECHO);
  158.     new_tty.c_oflag &= ~(OPOST);
  159.     new_tty.c_cc[VMIN] = 1;
  160.     new_tty.c_cc[VTIME] = 1;
  161.     ioctl(1, TCSETA, &new_tty);
  162. #endif
  163.     def_prog_mode();
  164.     
  165.     clear();
  166.     printf("columns = %d", columns);
  167.     nl();
  168.     printf("lines = %d", lines);
  169.     if (columns < 2)
  170.         quit(-1, "columns must be > 1");
  171.     nl();
  172.     anykey();
  173.     nl();
  174.     if (auto_right_margin) {
  175.         putln("auto_right_margin = TRUE");
  176.         nl();
  177.         for(i = 0; i < columns; i++)
  178.             putchar('1');
  179.         for(i = 0; i < columns / 2; i++)
  180.             putchar('2');
  181.         nl();
  182.     } else {
  183.         putln("auto_right_margin = FALSE");
  184.         nl();
  185.         for(i = 0; i < columns + columns / 2; i++)
  186.             putchar('1');
  187.         nl();
  188.         for(i = 0; i < columns / 2; i++)
  189.             putchar('2');
  190.         nl();
  191.     }
  192.     nl();
  193.     putln("***a line of 1's followed by a line of 2's");
  194.     nl();
  195.     anykey();
  196.     nl();
  197.  
  198.     if (over_strike) {
  199.         putln("over_strike = TRUE");
  200.         if (cursor_left != NULL) {
  201.             for(i = 0; i < columns / 4 + 1; i++) {
  202.                 putchar('/');
  203.                 putp(cursor_left);
  204.                 putchar('\\');
  205.             }
  206.         } else if (carriage_return != NULL) {
  207.             for(i = 0; i < columns / 4 + 1; i++) 
  208.                 putchar('/');
  209.             putp(carriage_return);
  210.             for(i = 0; i < columns / 4 + 1; i++) 
  211.                 putchar('\\');
  212.         }
  213.         nl();
  214.         nl();
  215.         putln("*** X's made from \\'s overstriking /'s");
  216.         nl();
  217.         anykey();
  218.         nl();
  219.     }
  220.  
  221.     if (cup(0,0) == 0) {
  222.         clear();
  223.         putln("cup test");
  224.         for(i = 1; i < columns; i++)
  225.             putp(tparm(cursor_address, 0, i));
  226.         for(i = 0; i < lines; i++)
  227.             putp(tparm(cursor_address, i, columns - 1));
  228.         for(i = columns; i--;)
  229.             putp(tparm(cursor_address, lines - 1, i));
  230.         for(i = lines; i--;)
  231.             putp(tparm(cursor_address, i, 0));
  232.         nl();
  233.         anykey();
  234.     }
  235.     clear();
  236.  
  237.     putln("Attribute test");
  238.     nl();
  239.     if (enter_blink_mode != NULL) {
  240.         putp(enter_blink_mode);
  241.         printf("blink");
  242.         putp(exit_attribute_mode);
  243.         nl();
  244.     }
  245.     if (enter_bold_mode != NULL) {
  246.         putp(enter_bold_mode);
  247.         printf("bold");
  248.         putp(exit_attribute_mode);
  249.         nl();
  250.     }
  251.     if (enter_dim_mode != NULL) {
  252.         putp(enter_dim_mode);
  253.         printf("dim");
  254.         putp(exit_attribute_mode);
  255.         nl();
  256.     }
  257.     if (enter_reverse_mode != NULL) {
  258.         putp(enter_reverse_mode);
  259.         printf("reverse");
  260.         putp(exit_attribute_mode);
  261.         nl();
  262.     }
  263.     if (enter_standout_mode != NULL) {
  264.         putp(enter_standout_mode);
  265.         printf("standout");
  266.         putp(exit_standout_mode);
  267.         nl();
  268.     }
  269.     if (enter_underline_mode != NULL) {
  270.         putp(enter_underline_mode);
  271.         printf("underline");
  272.         putp(exit_underline_mode);
  273.         nl();
  274.     }
  275.     nl();
  276.     anykey();
  277.  
  278.     clear();
  279.     reset_shell_mode();
  280.     
  281.     return (0);
  282. }
  283.