home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / src / baseline / jove-4.14.6.lha / jove-4.14.6 / misc.c < prev    next >
C/C++ Source or Header  |  1992-01-10  |  6KB  |  351 lines

  1. /***************************************************************************
  2.  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  3.  * is provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is    *
  5.  * included in all the files.                                              *
  6.  ***************************************************************************/
  7.  
  8. #include "jove.h"
  9. #include "ctype.h"
  10. #include "disp.h"
  11.  
  12. #include <signal.h>
  13.  
  14. void
  15. prCTIME()
  16. {
  17.     s_mess(": %f %s", get_time((time_t *)NULL, (char *)NULL, 0, -1));
  18. }
  19.  
  20. void
  21. ChrToOct()
  22. {
  23.     int    c,
  24.         slow = NO;
  25.  
  26.     c = waitchar(&slow);
  27.     ins_str(sprint("\\%03o", c), NO);
  28. }
  29.  
  30. void
  31. StrLength()
  32. {
  33.     static const char    inquotes[] = "Where are the quotes?";
  34.     char    *first = StrIndex(BACKWARD, linebuf, curchar, '"'),
  35.         *last = StrIndex(FORWARD, linebuf, curchar + 1, '"'),
  36.         c;
  37.     int    numchars = 0;
  38.  
  39.     if (first == NULL || last == NULL)
  40.         complain(inquotes);
  41.     first += 1;
  42.     while (first < last) {
  43.         c = *first++;
  44.         if (c == '\\') {
  45.             int    num;
  46.  
  47.             if (!jisdigit(*first)) {
  48.                 first += 1;
  49.             } else {
  50.                 num = 3;
  51.                 do ; while (num-- && jisdigit(*first++) && first < last);
  52.             }
  53.         }
  54.         numchars += 1;
  55.     }
  56.     s_mess("%d characters", numchars);
  57. }
  58.  
  59. /* Transpos cur_char with cur_char - 1 */
  60.  
  61. void
  62. TransChar()
  63. {
  64.     char    before;
  65.  
  66.     if (curchar == 0 || (eolp() && curchar == 1))
  67.         complain((char *)NULL);    /* BEEP */
  68.     if (eolp())
  69.         b_char(1);
  70.     before = linebuf[curchar - 1];
  71.     del_char(BACKWARD, 1, NO);
  72.     f_char(1);
  73.     insert_c(before, 1);
  74. }
  75.  
  76. /* Switch current line with previous one */
  77.  
  78. void
  79. TransLines()
  80. {
  81.     daddr    old_prev;
  82.  
  83.     if (firstp(curline))
  84.         return;
  85.     lsave();
  86.     old_prev = curline->l_prev->l_dline;
  87.     curline->l_prev->l_dline = curline->l_dline;
  88.     curline->l_dline = old_prev;
  89.     getDOT();
  90.     if (!lastp(curline))
  91.         line_move(FORWARD, 1, NO);
  92.     modify();
  93. }
  94.  
  95. void
  96. Leave()
  97. {
  98.     longjmp(mainjmp, QUIT);
  99. }
  100.  
  101. /* If argument is specified, kill that many lines down.  Otherwise,
  102.    if we "appear" to be at the end of a line, i.e. everything to the
  103.    right of the cursor is white space, we delete the line separator
  104.    as if we were at the end of the line. */
  105.  
  106. void
  107. KillEOL()
  108. {
  109.     Line    *line2;
  110.     int    char2;
  111.     int    num = arg_value();
  112.  
  113.     if (is_an_arg()) {
  114.         if (num == 0) {    /* Kill to beginning of line */
  115.             line2 = curline;
  116.             char2 = 0;
  117.         } else {
  118.             line2 = next_line(curline, num);
  119.             if ((LineDist(curline, line2) < num) || (line2 == curline))
  120.                 char2 = length(line2);
  121.             else
  122.                 char2 = 0;
  123.         }
  124.     } else if (blnkp(&linebuf[curchar])) {
  125.         line2 = next_line(curline, 1);
  126.         if (line2 == curline)
  127.             char2 = length(curline);
  128.         else
  129.             char2 = 0;
  130.     } else {
  131.         line2 = curline;
  132.         char2 = length(curline);
  133.     }
  134.     reg_kill(line2, char2, NO);
  135. }
  136.  
  137. /* kill to beginning of sentence */
  138.  
  139. void
  140. KillBos()
  141. {
  142.     negate_arg_value();
  143.     KillEos();
  144. }
  145.  
  146. /* Kill to end of sentence */
  147.  
  148. void
  149. KillEos()
  150. {
  151.     Line    *line1;
  152.     int    char1;
  153.  
  154.     line1 = curline;
  155.     char1 = curchar;
  156.     Eos();
  157.     reg_kill(line1, char1, YES);
  158. }
  159.  
  160. void
  161. KillExpr()
  162. {
  163.     Line    *line1;
  164.     int    char1;
  165.  
  166.     line1 = curline;
  167.     char1 = curchar;
  168.     FSexpr();
  169.     reg_kill(line1, char1, YES);
  170. }
  171.  
  172. void
  173. Yank()
  174. {
  175.     Line    *line,
  176.         *lp;
  177.     Bufpos    *dot;
  178.  
  179.     if (killbuf[killptr] == NULL)
  180.         complain("[Nothing to yank!]");
  181.     lsave();
  182.     this_cmd = YANKCMD;
  183.     line = killbuf[killptr];
  184.     lp = lastline(line);
  185.     dot = DoYank(line, 0, lp, length(lp), curline, curchar, curbuf);
  186.     set_mark();
  187.     SetDot(dot);
  188. }
  189.  
  190. void
  191. WtModBuf()
  192. {
  193.     if (!ModBufs(NO))
  194.         message("[No buffers need saving]");
  195.     else
  196.         put_bufs(is_an_arg());
  197. }
  198.  
  199. void
  200. put_bufs(askp)
  201. bool    askp;
  202. {
  203.     register Buffer    *oldb = curbuf,
  204.             *b;
  205.  
  206.     for (b = world; b != NULL; b = b->b_next) {
  207.         if (!IsModified(b) || b->b_type != B_FILE)
  208.             continue;
  209.         SetBuf(b);    /* Make this current Buffer */
  210.         if (curbuf->b_fname == NULL) {
  211.             char    *newname;
  212.  
  213.             newname = ask(NullStr, "Buffer \"%s\" needs a file name; type Return to skip: ", b->b_name);
  214.             if (*newname == '\0')
  215.                 continue;
  216.             setfname(b, newname);
  217.         }
  218.         if (askp && (yes_or_no_p("Write %s? ", curbuf->b_fname) == NO))
  219.             continue;
  220.         filemunge(curbuf->b_fname);
  221.         chk_mtime(curbuf, curbuf->b_fname, "save");
  222.         file_write(curbuf->b_fname, NO);
  223.     }
  224.     SetBuf(oldb);
  225. }
  226.  
  227. void
  228. ToIndent()
  229. {
  230.     Bol();
  231.     skip_wht_space();
  232. }
  233.  
  234. void
  235. skip_wht_space()
  236. {
  237.     register char    *cp,
  238.             c;
  239.  
  240.     for (cp = linebuf + curchar; (c = *cp)!='\0'; cp++)
  241.         if (c != ' ' && c != '\t')
  242.             break;
  243.     curchar = cp - linebuf;
  244. }
  245.  
  246. /* GoLine -- go to a line, usually wired to goto-line, ESC g or ESC G.
  247.    If no argument is specified it asks for a line number. */
  248. void
  249. GoLine()
  250. {
  251.     Line    *newline;
  252.  
  253.     if (!is_an_arg())
  254.         set_arg_value(ask_int("Line: ",10));
  255.     newline = next_line(curbuf->b_first, arg_value() - 1);
  256.     PushPntp(newline);
  257.     SetLine(newline);
  258. }
  259.  
  260. void
  261. NotModified()
  262. {
  263.     unmodify();
  264. }
  265.  
  266. void
  267. SetLMargin()
  268. {
  269.     int    lmarg = calc_pos(linebuf, curchar);
  270.  
  271.     if (lmarg >= RMargin)
  272.         complain("[Left margin must be left of right margin]");
  273.     LMargin = lmarg;
  274. }
  275.  
  276. void
  277. SetRMargin()
  278. {
  279.     int    rmarg = calc_pos(linebuf, curchar);
  280.  
  281.     if (rmarg <= LMargin)
  282.         complain("[Right margin must be right of left margin]");
  283.     RMargin = rmarg;
  284. }
  285.  
  286. /*
  287.  *    Mouse support for Xterm
  288.  *    The Xterm program sends
  289.  *    Esc [ M
  290.  *        button + space
  291.  *        col + space + 1
  292.  *        row + space + 1
  293.  */
  294. static void MoveToCursor(/* int, int */);
  295.  
  296. void
  297. XtermMouse()
  298. {
  299.     int mouse;
  300.     int line;
  301.     int col;
  302.     int slow = NO;
  303.     register struct scrimage *sp;
  304.     char    *msg;
  305.     
  306.     mouse = waitchar(&slow) - ' ';
  307.     col = waitchar(&slow) - ' ' - 1;
  308.     line = waitchar(&slow) - ' ' - 1;
  309.  
  310.     sp = &PhysScreen[line];
  311.  
  312.     while (sp->s_id == NULL)
  313.         sp = &PhysScreen[--line];
  314.     if (curwind != sp->s_window)
  315.         SetWind(sp->s_window);
  316.     if (sp->s_flags & MODELINE)
  317.     {
  318.         switch (mouse)
  319.         {
  320.         case 0:
  321.             WindSize(curwind, 1);
  322.             msg = "[Grow window]";
  323.             break;
  324.         default:
  325.             WindSize(curwind, -1);
  326.             msg = "[Shrink window]";
  327.             break;
  328.         }
  329.         s_mess(msg);
  330.  
  331.     }
  332.     else
  333.     {    SetLine(sp->s_lp);
  334.         curchar = how_far(sp->s_lp, col);
  335.         switch (mouse)
  336.         {
  337.         case 0:            /* left button */
  338.             set_mark();
  339.             break;
  340.         case 1:            /* paste on middle button */
  341.             Yank();
  342.             s_mess("[Region pasted]");
  343.             break;
  344.         case 2:            /* end of region on right button */
  345.             CopyRegion();
  346.             s_mess("[Region copied]");
  347.             break;
  348.         }
  349.     }
  350. }
  351.