home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 318_01 / redpmt.c < prev    next >
C/C++ Source or Header  |  1990-06-18  |  4KB  |  244 lines

  1. /*
  2.     RED prompt line module -- Full C version
  3.  
  4.     Source:  redpmt.c
  5.     Version: December 18, 1983; January 18, 1990.
  6.  
  7.     Written by
  8.     
  9.         Edward K. Ream
  10.         166 N. Prospect
  11.         Madison WI 53705
  12.         (608) 257-0802
  13.  
  14.  
  15.     PUBLIC DOMAIN SOFTWARE
  16.  
  17.     This software is in the public domain.
  18.  
  19.     See red.h for a disclaimer of warranties and other information.
  20. */
  21.  
  22. #include "red.h"
  23.  
  24. /*
  25.     Define routines local to this module.
  26. */
  27. static void    pmt1upd    (int x);
  28.  
  29. /*
  30.     Define variables local to this module.
  31. */
  32. static int    pmt_zapped;
  33. static int    pmt_hold;
  34. static int    pmt_line;
  35. static int    pmt_col;
  36. static int    pmt_newfn;
  37. static char    pmt_mode [MAXLEN];
  38. static int    pmt_newmd;
  39.  
  40. /*
  41.     Initialize this module.
  42. */
  43. void
  44. pmtclr(void)
  45. {
  46.     TICKB("pmtclr");
  47.  
  48.     pmt_zapped = TRUE;
  49.     pmt_hold   = FALSE;
  50.     pmt_newmd  = TRUE;
  51.     pmt_newfn  = TRUE;
  52.  
  53.     TICKX("pmtclr");
  54. }
  55.  
  56. /*
  57.     Indicate that the global file name has been changed.
  58. */
  59. void
  60. pmtfn(void)
  61. {
  62.     TICKB("pmtfn");
  63.  
  64.     pmt_newfn = TRUE;
  65.  
  66.     TICKX("pmtfn");
  67. }
  68.  
  69. /*
  70.     Disable updates to the prompt line.
  71. */
  72. void
  73. pmthold(int flag)
  74. {
  75.     TRACEPB("pmthold", sl_lpout(); sl_iout(flag); sl_rpout());
  76.  
  77.     pmt_hold = flag;
  78.  
  79.     TICKX("pmthold");
  80. }
  81.  
  82. /*
  83.     Return the position of the next free spot on the line.
  84. */
  85. int
  86. pmtlast(void)
  87. {
  88.     SL_DISABLE();
  89.  
  90.     return 41 + strlen(pmt_mode);
  91. }
  92.  
  93. /*
  94.     Put error message on prompt line.
  95.     Do NOT restore the cursor.
  96. */
  97. void
  98. pmtmess(char *s1, char *s2)
  99. {
  100.     /* Make sure line is correct. */
  101.     TRACEPB("pmtmess",   sl_lpout();
  102.         sl_sout(s1); sl_csout();
  103.         sl_sout(s2); sl_rpout());
  104.  
  105.     pmt_zapped = TRUE;
  106.     pmt1upd(outx);
  107.  
  108.     /* Output error messages. */
  109.     outxy(41, 0);
  110.     outdeol();
  111.     fmtsout(" ", outx);
  112.     fmtsout(s1,  outx);
  113.     fmtsout(" ", outx);
  114.     fmtsout(s2,  outx);
  115.  
  116.     /* Make sure the mode field gets restored. */
  117.     pmt_newmd = TRUE;
  118.  
  119.     TICKX("pmtmess");
  120. }
  121.  
  122. /*
  123.     Change the mode immediately.
  124. */
  125. void
  126. pmtmode(char *newmode)
  127. {
  128.     TRACEPB("pmtmode", sl_lpout(); sl_sout(newmode); sl_rpout());
  129.  
  130.     if (strcmp(newmode, pmt_mode) != 0) {
  131.         strcpy(pmt_mode, newmode);
  132.         pmt_newmd = TRUE;
  133.         pmthold(FALSE);
  134.     }
  135.     pmtupd();    /* 12/18/83 */
  136.  
  137.     TICKX("pmtmode");
  138. }
  139.  
  140. /*
  141.     Update the prompt line as needed.
  142. */
  143. void
  144. pmtupd(void)
  145. {
  146.     int x, y;
  147.  
  148.     TICKB("pmtupd");
  149.  
  150.     if (pmt_hold == TRUE) {
  151.         RETURN_VOID("pmtupd");
  152.     }
  153.  
  154.     /* Save cursor postion. */
  155.     x = outx;
  156.     y = outy;
  157.  
  158.     pmt1upd(x);
  159.  
  160.     /* Restore cursor position. */
  161.     outxy(x, y);
  162.  
  163.     TICKX("pmtupd");
  164. }
  165.  
  166. static void
  167. pmt1upd(int x)
  168. {
  169.     int i;
  170.  
  171.     TRACEPB("pmt1upd", sl_lpout(); sl_iout(x); sl_rpout());
  172.  
  173.     /* Clear the line if it may have been corrupted. */
  174.     if (pmt_zapped == TRUE) {
  175.         outxy(0, 0);
  176.         outdelln();
  177.     }
  178.  
  179.     /* Update the line field. */
  180.     if (pmt_zapped == TRUE) {
  181.         outxy(0, 0);
  182.         fmtsout("line: ",0);
  183.         putdec(bufln(), 5);
  184.     }
  185.     else if (bufln() != pmt_line) {
  186.         outxy(6, 0);
  187.         putdec(bufln(),5);
  188.     }
  189.     pmt_line = bufln();
  190.  
  191.     /* Update the column field. */
  192.     if (hascol == TRUE && pmt_zapped == TRUE) {
  193.         outxy(12, 0);
  194.         fmtsout("column: ", 12);
  195.         putdec(x, 3);
  196.     }
  197.     else if (hascol == TRUE &&  x != pmt_col) {
  198.         outxy(20,0);
  199.         putdec(x, 3);
  200.     }
  201.     pmt_col = x;
  202.  
  203.     /* Update the file name field. */
  204.     if (pmt_zapped == TRUE || pmt_newfn == TRUE) {
  205.         outxy(25,0);
  206.         if (g_file [0] == '\0') {
  207.             fmtsout(" ..no file.. ",25);
  208.         }
  209.         else {
  210.             fmtsout(g_file,25);
  211.             for (i = 0; i < 14 - strlen(g_file); i++) {
  212.                 fmtsout(" ", 0);
  213.             }
  214.         }
  215.     }
  216.     pmt_newfn = FALSE;
  217.  
  218.     /* Update the mode field. */
  219.     if (pmt_zapped == TRUE || pmt_newmd == TRUE) {
  220.         outxy(41,0);
  221.         fmtsout(pmt_mode,41);
  222.         outdeol();
  223.     }
  224.     pmt_newmd = FALSE;
  225.  
  226.     /* Clear the zapped flag. */
  227.     pmt_zapped = FALSE;
  228.  
  229.     TICKX("pmt1upd");
  230. }
  231.  
  232. /*
  233.     Indicate that the prompt line has been overwritten.
  234. */
  235. void
  236. pmtzap(void)
  237. {
  238.     TICKB("pmtzap");
  239.  
  240.     pmt_zapped = TRUE;
  241.  
  242.     TICKX("pmtzap");
  243. }
  244.