home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume25 / ted / part06 / modes.c next >
Encoding:
C/C++ Source or Header  |  1991-11-06  |  19.0 KB  |  585 lines

  1. /*
  2. ** This software is Copyright (c) 1991 by Daniel Weaver.
  3. **
  4. ** Permission is hereby granted to copy, distribute or otherwise
  5. ** use any part of this package as long as you do not try to make
  6. ** money from it or pretend that you wrote it.  This copyright
  7. ** notice must be maintained in any copy made.
  8. **
  9. ** Use of this software constitutes acceptance for use in an AS IS
  10. ** condition. There are NO warranties with regard to this software.
  11. ** In no event shall the author be liable for any damages whatsoever
  12. ** arising out of or in connection with the use or performance of this
  13. ** software.  Any use of this software is at the user's own risk.
  14. **
  15. **  If you make modifications to this software that you feel
  16. **  increases it usefulness for the rest of the community, please
  17. **  email the changes, enhancements, bug fixes as well as any and
  18. **  all ideas to me. This software is going to be maintained and
  19. **  enhanced as deemed necessary by the community.
  20. */
  21. /* this module tests boolian flags and terminal modes */
  22.  
  23. #include "curses.h"
  24. #include "ted.h"
  25.  
  26. static void
  27. uprint(s)
  28. char *s;
  29.    {  /* underline string for (ul) test */
  30.       if (s)
  31.          while (*s) {
  32.             put_str("_\b");
  33.             putchp(*s++);
  34.          }
  35.    }
  36.  
  37.  
  38. /* Note: uprint() sends underscore back-space character, and
  39.         ucprint() sends character back-space underscore.  */
  40.  
  41. static void
  42. ucprint(s)
  43. char *s;
  44.    {  /* underline string for (uc) test */
  45.       if (s)
  46.          while (*s) {
  47.             putchp(*s++);
  48.             putchp('\b');
  49.             putp(underline_char);
  50.          }
  51.    }
  52.  
  53.  
  54. static void
  55. subtest_tbc()
  56.    {  /* test clear tabs (tbc) */
  57.       int i;
  58.  
  59.       put_clear();
  60.       putp(clear_all_tabs);
  61.       ptext("Clear tabs (tbc)");
  62.       go_home();
  63.       put_crlf();  putchp('\t');  putchp('T');
  64.       go_home();
  65.       put_newlines(2);
  66.          for (i = 1; i < columns; i++) {
  67.             putchp('.');
  68.          }
  69.       putchp('T');  go_home();
  70.       ptext("\n\n\nDone. (tbc)");
  71.    }
  72.  
  73.  
  74. static void
  75. subtest_hts()
  76.    {  /* set tabs with (hts), also (xt) glitch */
  77.       int i, tabat;
  78.  
  79.       put_clear();
  80.       tabat = init_tabs;
  81.       if (set_tab)
  82.          {
  83.             ptext("Tabs set with (hts)");
  84.             put_crlf();
  85.                for (i = 1; i < columns; i++) {
  86.                   if (i % 8 == 1) putp(set_tab);
  87.                   putchp(' ');
  88.                }
  89.             tabat = 8;
  90.          }
  91.       else
  92.          {
  93.             ptext("(hts) not defined.  The following tabs are set:");
  94.          }
  95.       go_home();
  96.       put_newlines(2);
  97.       if (tabat <= 0) tabat = 8;
  98.          for (i = tabat; i < columns; i += tabat) {
  99.             putchp('\t');  putchp('T');
  100.          }
  101.       go_home();
  102.       put_newlines(3);
  103.          for (i = 1; i < columns; i++) {
  104.             putchp('.');
  105.          }
  106.       go_home();
  107.       put_newlines(3);
  108.          for (i = tabat; i < columns; i += tabat) {
  109.             putchp('\t');  putchp('T');
  110.          }
  111.       go_home();
  112.       put_newlines(4);
  113.       putchp('.');
  114.          for (i = 2; i < columns; i++) {
  115.             if (i % tabat == 1) putchp('T');
  116.             else putchp('.');
  117.          }
  118.       go_home();
  119.       put_newlines(5);
  120.       ptextln("The last two lines should be the same.");
  121.  
  122. #if defined(SVR3) || defined(XENIX)
  123.       if (!over_strike && (init_tabs > 0 || set_tab))
  124.          {
  125.             ptextln("\nDestructive tab test");
  126.             ptext("(xt) should not ");  put_cr();
  127.             ptext("(xt) should");
  128.                while (char_count < 16) {
  129.                   if (translate_mode && tab) putp(tab);
  130.                   else putp(TM_tab);
  131.                   char_count = ((char_count / tabat) + 1) * tabat;
  132.                }
  133.             putln("be set.");
  134.             sprintf(temp, "(xt) is %s in the data base.",
  135.                dest_tabs_magic_smso ? "true": "false");
  136.             ptextln(temp);
  137.          }
  138. #endif
  139.    }
  140.  
  141. static void
  142. subtest_cbt()
  143.    {  /* test back tab (cbt) */
  144.       int i;
  145.  
  146.       if (back_tab)
  147.          {
  148.             put_clear();
  149.             ptext("Back tabs (cbt)");
  150.             go_home();
  151.             put_crlf();
  152.                for (i = 1; i < columns; i++) {
  153.                   putchp(' ');
  154.                }
  155.                for (i = 0; i < columns; i += 8) {
  156.                   putp(back_tab);  putchp('T');
  157.                   putp(back_tab);
  158.                }
  159.             go_home();
  160.             put_newlines(2);
  161.                for (i = 1; i < columns; i++) {
  162.                   if (i % 8 == 1) putchp('T');
  163.                   else putchp('.');
  164.                }
  165.             go_home();
  166.             put_newlines(4);
  167.          }
  168.       else
  169.          {
  170.             if (init_tabs <= 0 && !set_tab)
  171.                {
  172.                   /* setupterm() resets (cbt) if both (it) and (hts) are
  173.                      missing. */
  174.                   ptextln("(it) and (hts) missing...  (cbt) back tab not tested!");
  175.                }
  176.             else ptextln("(cbt) back tab not present");
  177.          }
  178.    }
  179.  
  180.  
  181. static void
  182. test_os_set()
  183.    {  /* test (am) (smam) (rmam) (xenl) on overstrike terminals */
  184.       int i, j;
  185.  
  186. #if defined(SVR3) || defined(XENIX)
  187.       if (exit_am_mode && can_go_home)
  188.          {
  189.             go_home();
  190.             putp(exit_am_mode);
  191.             ptext("\n(rmam) will     reset (am)");
  192.             go_home();
  193.                for (j = 0; j < columns; j++) put_this(' ');
  194.             ptext("(rmam) will not reset (am)");
  195.          }
  196.       else ptext("(rmam) not present.");
  197.  
  198.       if (enter_am_mode && can_go_home)
  199.          {
  200.             go_home();
  201.             putp(enter_am_mode);
  202.             ptext("\n\n\n(smam) will ");
  203.             i = char_count;
  204.             ptext("not set (am)");
  205.             go_home();
  206.             put_newlines(2);
  207.                for (j = -i; j < columns; j++) put_this(' ');
  208.             put_str("@@@");
  209.          }
  210.       else ptext("\n\n(smam) not present.");
  211. #endif
  212.  
  213.       if (can_go_home)
  214.          {
  215.             go_home();
  216.             ptext("\n\n\n\n\n(am) should ");
  217.             i = char_count;
  218.             ptext("not be set");
  219.             go_home();
  220.             put_newlines(4);
  221.                for (j = -i; j < columns; j++) put_this(' ');
  222.             put_str("@@@");
  223.             go_home();
  224.             put_newlines(6);
  225.          }
  226.       else put_crlf();
  227.       sprintf(temp, "(am) is %s in the data base",
  228.          auto_right_margin ? "true" : "false");
  229.       ptextln(temp);
  230.  
  231.       ptext("\n(bw) should ");
  232.       i = char_count;
  233.       ptextln("not be set.");
  234.          for (j = i; j < columns; j++) put_str("\b");
  235.       put_str("@@@");
  236.       put_crlf();
  237.       sprintf(temp, "(bw) is %s in the data base",
  238.          auto_left_margin ? "true" : "false");
  239.       ptextln(temp);
  240.    }
  241.  
  242.  
  243. static void
  244. subtest_os_xenl()
  245.    {  /* test (xenl) on overstrike terminals */
  246.       int i, j, k;
  247.  
  248.       if (can_go_home && can_clear_screen)
  249.          {  /* (xenl) test */
  250.             put_clear();
  251.             /* this test must be done in raw mode.  Otherwise UNIX
  252.                will translate CR to CRLF. */
  253.             if (stty_query(TTY_OUT_TRANS)) tty_raw(1, char_mask);
  254.             ptext("\nreset (xenl). Does ");
  255.             i = char_count;
  256.             put_str("not ignore CR, does ");
  257.             k = char_count;
  258.             put_str("not ignore LF");
  259.             go_home();
  260.                for (j = 0; j < columns; j++) put_this(' ');
  261.             put_cr();
  262.                for (j = 0; j < i; j++) putchp(' ');
  263.             put_str("@@@\n@@");
  264.             go_home();
  265.                for (j = 0; j < columns; j++) put_this(' ');
  266.             put_lf();
  267.                for (j = 0; j < k; j++) putchp(' ');
  268.             put_str("@@@\r@@");
  269.             tty_set();
  270.             go_home();
  271.             put_newlines(4);
  272.          }
  273.       else ptextln("\n(xenl) not tested, (clear) (cup) or (home) missing");
  274.       sprintf(temp, "(xenl) is %s in the data base",
  275.          eat_newline_glitch ? "true" : "false");
  276.       ptextln(temp);
  277.    }
  278.  
  279.  
  280. static void
  281. test_os_reset()
  282.    {  /* test (am) (smam) (rmam) (xenl) on non-overstrike terminals */
  283.       int i, j;
  284.  
  285. #if defined(SVR3) || defined(XENIX)
  286.       if (exit_am_mode && can_go_home)
  287.          {
  288.             go_home();
  289.             putp(exit_am_mode);
  290.             ptext("\n(rmam) will reset (am)");
  291.             go_home();
  292.                for (j = 0; j < columns; j++) put_this(' ');
  293.             ptext("(rmam) will not reset (am) ");
  294.             go_home();
  295.             put_str("                          ");
  296.          }
  297.       else ptext("(rmam) not present.");
  298.  
  299.       if (enter_am_mode && can_go_home)
  300.          {
  301.             go_home();
  302.             putp(enter_am_mode);
  303.             ptext("\n\n\n(smam) will not set (am)");
  304.             go_home();
  305.             put_newlines(2);
  306.                for (j = 0; j < columns; j++) put_this(' ');
  307.             ptext("(smam) will set (am)    ");
  308.             go_home();
  309.             put_str("\n\n                          ");
  310.          }
  311.       else ptext("\n\n(smam) not present.");
  312. #endif
  313.  
  314.       if (can_go_home)
  315.          {
  316.             go_home();
  317.             ptext("\n\n\n\n\n(am) should not be set");
  318.             go_home();
  319.             put_newlines(4);
  320.                for (j = 0; j < columns; j++) put_this(' ');
  321.             ptext("(am) should be set    ");
  322.             go_home();
  323.             put_str("\n\n\n\n                       \n\n");
  324.          }
  325.       else put_crlf();
  326.       sprintf(temp, "(am) is %s in the data base",
  327.          auto_right_margin ? "true" : "false");
  328.       ptextln(temp);
  329.  
  330.       /* (ul) is used only if (os) is reset */
  331.       sprintf(temp, "\n(ul) is %s in the data base",
  332.          transparent_underline ? "true" : "false");
  333.       ptextln(temp);
  334.       sprintf(temp, "This text should %sbe underlined.",
  335.          transparent_underline ? "" : "not ");
  336.       uprint(temp);
  337.       put_newlines(2);
  338.  
  339.       if (underline_char)
  340.          {
  341.             ptextln("Test underline character (uc)");
  342.             ucprint("This text should be underlined.");
  343.             put_newlines(2);
  344.          }
  345.       else
  346.       if (!enter_underline_mode)
  347.          ptextln("(uc) underline character, is not defined\n");
  348.  
  349.       ptextln("(bw) should not be set.");
  350.          for (i = 12; i < columns; i++) put_str("\b");
  351.       if (delete_character)
  352.          for (i = 0; i < 4; i++) putp(delete_character);
  353.       else put_str("   ");
  354.       put_crlf();
  355.       sprintf(temp, "(bw) is %s in the data base",
  356.          auto_left_margin ? "true" : "false");
  357.       ptextln(temp);
  358.    }
  359.  
  360.  
  361. static void
  362. subtest_xenl()
  363.    {  /* test (xenl) when (os) is reset */
  364.       int j;
  365.  
  366.       if (can_go_home)
  367.          {  /* (xenl) test */
  368.             put_clear();
  369.             /* this test must be done in raw mode.  Otherwise UNIX
  370.                will translate CR to CRLF. */
  371.             if (stty_query(TTY_OUT_TRANS)) tty_raw(1, char_mask);
  372.                for (j = 0; j < columns; j++) put_this(' ');
  373.             put_cr();
  374.             ptext("(xenl) should be set. Does not ignore CR");
  375.             go_home();
  376.             put_crlf();
  377.                for (j = 0; j < columns; j++) put_this(' ');
  378.             put_lf();  /* test (cud1) */
  379.             ptext("(xenl) should be set. Ignores (cud1)");
  380.             go_home();
  381.             put_newlines(3);
  382.             if (scroll_forward && cursor_down &&
  383.                strcmp(scroll_forward, cursor_down))
  384.                {
  385.                      for (j = 0; j < columns; j++) put_this(' ');
  386.                   put_ind();  /* test (ind) */
  387.                   ptext("(xenl) should be set. Ignores (ind)");
  388.                   go_home();
  389.                   put_newlines(5);
  390.                }
  391.             tty_set();
  392.             ptextln("If the above lines are blank then (xenl) should be false");
  393.          }
  394.       else ptextln("(xenl) not tested, (clear) (cup) or (home) missing");
  395.       sprintf(temp, "(xenl) is %s in the data base",
  396.          eat_newline_glitch ? "true" : "false");
  397.       ptextln(temp);
  398.    }
  399.  
  400.  
  401. test_mode()
  402.    {
  403.       int i, j;
  404.       char *s;
  405.  
  406.       new_test(3);
  407.       if (run_mode("(os)"))
  408.          do {
  409.             ptext("\n(os) should be true, not false.");  put_cr();
  410.             ptextln("(os) should be           false.");
  411.             sprintf(temp, "(os) is %s in the data base",
  412.                over_strike ? "true" : "false");
  413.             ptextln(temp);
  414.          } while (repeat_test(FALSE));
  415.  
  416.       if (run_mode("(smam)(rmam)(ul)(uc)(am)(bw)"))
  417.          do {
  418.             put_clear();
  419.             if (over_strike) test_os_set();
  420.             else test_os_reset();
  421.          } while (repeat_test(FALSE));
  422.  
  423.       if (run_mode("(xenl)(eo)(xmc)(xhp)"))
  424.          do {
  425.             if (over_strike) subtest_os_xenl();
  426.             else subtest_xenl();
  427.  
  428.             if (transparent_underline || over_strike || underline_char)
  429.                {  /* test (eo) */
  430.                   sprintf(temp, "\n(eo) is %s in the data base",
  431.                      erase_overstrike ? "true" : "false");
  432.                   ptextln(temp);
  433.                   ptext("(eo) should ");
  434.                   if (underline_char) ucprint("not");
  435.                   else uprint("not");
  436.                   put_cr();
  437.                   ptextln("(eo) should     be set");
  438.                }
  439.  
  440.             if (enter_standout_mode)
  441.                {
  442.                   sprintf(temp, "\n(xmc) is %d", magic_cookie_glitch);
  443.                   ptextln(temp);
  444.                   j = magic_cookie_glitch * 8;
  445.                      for (i = 0; i < j; i++) put_str(" ");
  446.                   ptextln("        These two lines should line up.");
  447.                   if (j > 0) char_count += j;
  448.                      for (i = 0; i < 4; i++) {
  449.                         put_mode(enter_standout_mode);
  450.                         putchp(' ');
  451.                         put_mode(exit_standout_mode);
  452.                         putchp(' ');
  453.                      }
  454.                   ptextln("These two lines should line up.");
  455.       
  456.                   /* test (xhp) */
  457.                   put_crlf();  put_mode(enter_standout_mode);
  458.                   put_str("Stand out");  put_mode(exit_standout_mode);
  459.                   put_cr();
  460.                   ptextln("If any part of this line is standout then (xhp) should be set.");
  461.                   sprintf(temp, "(xhp) is %s in the data base",
  462.                      ceol_standout_glitch ? "true" : "false");
  463.                   ptextln(temp);
  464.                }
  465.          } while (repeat_test(FALSE));
  466.  
  467.       if (run_test(cursor_address,
  468.          "(mir) and (msgr) not tested because (cup) is missing", FALSE))
  469.          do {
  470.             put_clear();
  471.             if (enter_insert_mode != (char *)0 &
  472.                exit_insert_mode != (char *)0)
  473.                {
  474.                   ptextln("If the block of X's are square then (mir) should be set. (smir) (rmir) (cup)");
  475.                   i = line_count;
  476.                   put_str("\nXXX\nXXX\nXXX\nXXX");
  477.                   putp(enter_insert_mode);
  478.                   s = tcup(cursor_address, i + 1, 0);
  479.                   tputs(s, lines, putch);
  480.                   putchp('x');
  481.                   s = tcup(cursor_address, i + 2, 1);
  482.                   tputs(s, lines, putch);
  483.                   putchp('x');
  484.                   s = tcup(cursor_address, i + 3, 2);
  485.                   tputs(s, lines, putch);
  486.                   putchp('x');
  487.                   s = tcup(cursor_address, i + 4, 3);
  488.                   tputs(s, lines, putch);
  489.                   putchp('x');
  490.                   putp(exit_insert_mode);
  491.                   put_crlf();
  492.                }
  493.             else ptextln("(smir) (rmir) not present. (mir) not tested.");
  494.             if ((enter_standout_mode && exit_standout_mode) ||
  495.                (enter_alt_charset_mode && exit_alt_charset_mode))
  496.                {
  497.                   put_crlf();
  498.                   ptext("If you see a diagonal line of standout X's then (msgr) should be set, if any of the blanks are standout then (msgr) should be reset. (smacs) (rmacs) (cup)");
  499.                   i = line_count + 1;
  500.                   tputs(tcup(cursor_address, i, 0), lines, putch);
  501.                   put_mode(enter_alt_charset_mode);
  502.                   put_crlf();
  503.                   /* some versions of the wy-120 can not clear lines or
  504.                      screen when in alt charset mode.  If (el) and (ed)
  505.                      are defined then I can test them.  If they are not
  506.                      defined then they can not break (msgr) */
  507.                   putp(clr_eos);
  508.                   putp(clr_eol);
  509.                   put_mode(exit_alt_charset_mode);
  510.                   put_mode(enter_standout_mode);
  511.                   putchp('X');
  512.                   tputs(tcup(cursor_address, i + 2, 1), lines, putch);
  513.                   putchp('X');
  514.                   tputs(tcup(cursor_address, i + 3, 2), lines, putch);
  515.                   putchp('X');
  516.                   tputs(tcup(cursor_address, i + 4, 3), lines, putch);
  517.                   putchp('X');
  518.                   put_mode(exit_standout_mode);
  519.                   put_crlf();
  520.                   putp(clr_eos);  /* OK if missing */
  521.                   put_crlf();
  522.                }
  523.             else ptextln("(smso) (rmso) (smacs) (rmacs) not present. (msgr) not tested.");
  524.             sprintf(temp, "(mir) is %s and (msgr) is %s in the data base",
  525.                move_insert_mode ? "true" : "false",
  526.                move_standout_mode ? "true" : "false");
  527.             ptextln(temp);
  528.          } while (repeat_test(FALSE));
  529.  
  530.       if (run_test(clear_all_tabs,
  531.          "Clear all tabs (tbc) not defined.", TRUE))
  532.          do {
  533.             subtest_tbc();
  534.          } while (repeat_test(FALSE));
  535.  
  536.       if (run_mode("(hts)(xt)"))
  537.          do {
  538.             subtest_hts();
  539.          } while (repeat_test(FALSE));
  540.  
  541.       if (run_mode("(cbt)(in)"))
  542.          do {
  543.             subtest_cbt();
  544.  
  545.             if (enter_insert_mode && exit_insert_mode)
  546.                {  /* test (in) */
  547.                   ptextln("\nTesting (in) with (smir) and (rmir)");
  548.                   putln("\tIf these two lines line up ...");
  549.                   put_str("\tIf these two lines line up ...");
  550.                   put_cr();
  551.                   putp(enter_insert_mode);
  552.                   putchp(' ');
  553.                   putp(exit_insert_mode);
  554.                   ptext("\nthen (in) should be set.  ");
  555.                   sprintf(temp,
  556.                      "(in) is %s in the data base.",
  557.                      insert_null_glitch ? "true" : "false");
  558.                   ptextln(temp);
  559.                }
  560.          } while (repeat_test(FALSE));
  561.  
  562.       if (run_mode("(da)(db)")
  563.          && can_clear_screen && scroll_reverse && scroll_forward)
  564.          do {  /* test (da) and (db) */
  565.             put_clear();
  566.             if (scroll_reverse) ptext("(da) should be set\r");
  567.             move_to(0, 0, lines - 1, 0, 3);
  568.             if (scroll_forward) ptext("(db) should be set\r");
  569.             putp(scroll_forward);
  570.             move_to(lines - 1, 0, 0, 0, 3);
  571.             putp(scroll_reverse);
  572.             putp(scroll_reverse);
  573.             move_to(0, 0, lines - 1, 0, 3);
  574.             putp(scroll_forward);
  575.             move_to(lines - 1, 0, 0, 0, 3);
  576.             ptextln("\n\n\n\n\nIf the top line is blank then (da) should be false.");
  577.             ptextln("If the bottom line is blank then (db) should be false.");
  578.             sprintf(temp, "\n(da) is %s, and (db) is %s, in the data base.",
  579.             memory_above ? "true" : "false",
  580.             memory_below ? "true" : "false");
  581.             ptextln(temp);
  582.             line_count = lines;
  583.          } while (repeat_test(FALSE));
  584.    }
  585.