home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / jove-4.16-src.tgz / tar.out / bsd / jove / misc.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  5KB  |  280 lines

  1. /************************************************************************
  2.  * This program is Copyright (C) 1986-1996 by Jonathan Payne.  JOVE is  *
  3.  * 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 "jctype.h"
  10. #include "disp.h"
  11. #include "ask.h"
  12. #include "c.h"
  13. #include "delete.h"
  14. #include "insert.h"
  15. #include "extend.h"
  16. #include "fmt.h"
  17. #include "marks.h"
  18. #include "misc.h"
  19. #include "move.h"
  20. #include "paragraph.h"
  21.  
  22. void
  23. prCTIME()
  24. {
  25.     f_mess(": %f %s", get_time((time_t *)NULL, (char *)NULL, 0, -1));
  26.     stickymsg = YES;
  27. }
  28.  
  29. void
  30. ChrToOct()
  31. {
  32.     ZXchar    c = ask_ks();
  33.  
  34.     ins_str(sprint("\\%03o", c));
  35. #ifdef PCNONASCII
  36.     if (c == PCNONASCII) {
  37.         c = waitchar();
  38.         ins_str(sprint("\\%03o", c));
  39.     }
  40. #endif
  41. }
  42.  
  43. void
  44. StrLength()
  45. {
  46.     static const char    inquotes[] = "Where are the quotes?";
  47.     char    *cp;
  48.     int    numchars = 0;
  49.  
  50.     for (cp = linebuf+curchar; ; cp--) {
  51.         if (*cp == '"' && (cp == linebuf || cp[-1] != '\\'))
  52.             break;
  53.         if (cp == linebuf)
  54.             complain(inquotes);
  55.     }
  56.  
  57.     cp += 1;    /* skip opening quote */
  58.     for (;;) {
  59.         switch (*cp++) {
  60.         case '\0':
  61.             complain(inquotes);
  62.             /*NOTREACHED*/
  63.         case '"':
  64.             f_mess("%d characters", numchars);
  65.             stickymsg = YES;
  66.             return;
  67.         case '\\':
  68.             if (!jisdigit(*cp)) {
  69.                 if (*cp == '\0')
  70.                     complain(inquotes);
  71.                 cp += 1;
  72.             } else {
  73.                 int    num = 3;
  74.  
  75.                 do cp += 1; while (--num != 0 && jisdigit(*cp));
  76.             }
  77.             break;
  78.         }
  79.         numchars += 1;
  80.     }
  81. }
  82.  
  83. /* Transpose cur_char with cur_char - 1 */
  84.  
  85. void
  86. TransChar()
  87. {
  88.     char    before;
  89.  
  90.     if (curchar == 0 || (eolp() && curchar == 1))
  91.         complain((char *)NULL);    /* BEEP */
  92.     if (eolp())
  93.         b_char(1);
  94.     before = linebuf[curchar - 1];
  95.     del_char(BACKWARD, 1, NO);
  96.     f_char(1);
  97.     insert_c(before, 1);
  98. }
  99.  
  100. /* Switch current line with previous one */
  101.  
  102. void
  103. TransLines()
  104. {
  105.     daddr    old_prev;
  106.  
  107.     if (firstp(curline))
  108.         return;
  109.     lsave();
  110.     /* Exchange l_dline values.
  111.      * CHEAT: this breaks the buffer abstraction.
  112.      * The getDOT unfools a few caching mechanisms.
  113.      */
  114.     old_prev = curline->l_prev->l_dline;
  115.     curline->l_prev->l_dline = curline->l_dline;
  116.     curline->l_dline = old_prev;
  117.     getDOT();
  118.  
  119.     if (!lastp(curline))
  120.         line_move(FORWARD, 1, NO);
  121.     else
  122.         Eol();    /* can't move to next line, so we do the next best thing */
  123.     modify();
  124.     DOLsave = NO;    /* CHEAT: contents of linebuf need not override l_dline. */
  125. }
  126.  
  127. void
  128. Leave()
  129. {
  130.     longjmp(mainjmp, JMP_QUIT);
  131. }
  132.  
  133. /* If argument is specified, kill that many lines down.  Otherwise,
  134.    if we "appear" to be at the end of a line, i.e. everything to the
  135.    right of the cursor is white space, we delete the line separator
  136.    as if we were at the end of the line. */
  137.  
  138. void
  139. KillEOL()
  140. {
  141.     LinePtr    line2;
  142.     int    char2;
  143.     int    num = arg_value();
  144.  
  145.     if (is_an_arg()) {
  146.         if (num == 0) {    /* Kill to beginning of line */
  147.             line2 = curline;
  148.             char2 = 0;
  149.         } else {
  150.             line2 = next_line(curline, num);
  151.             if ((LineDist(curline, line2) < num) || (line2 == curline))
  152.                 char2 = length(line2);
  153.             else
  154.                 char2 = 0;
  155.         }
  156.     } else if (blnkp(&linebuf[curchar])) {
  157.         line2 = next_line(curline, 1);
  158.         if (line2 == curline)
  159.             char2 = length(curline);
  160.         else
  161.             char2 = 0;
  162.     } else {
  163.         line2 = curline;
  164.         char2 = length(curline);
  165.     }
  166.     reg_kill(line2, char2, NO);
  167. }
  168.  
  169. /* kill to beginning of sentence */
  170.  
  171. void
  172. KillBos()
  173. {
  174.     negate_arg();
  175.     KillEos();
  176. }
  177.  
  178. /* Kill to end of sentence */
  179.  
  180. void
  181. KillEos()
  182. {
  183.     LinePtr    line1;
  184.     int    char1;
  185.  
  186.     line1 = curline;
  187.     char1 = curchar;
  188.     Eos();
  189.     reg_kill(line1, char1, YES);
  190. }
  191.  
  192. void
  193. KillExpr()
  194. {
  195.     LinePtr    line1;
  196.     int    char1;
  197.  
  198.     line1 = curline;
  199.     char1 = curchar;
  200.     FSexpr();
  201.     reg_kill(line1, char1, YES);
  202. }
  203.  
  204. void
  205. Yank()
  206. {
  207.     LinePtr    line,
  208.         lp;
  209.     Bufpos    *dot;
  210.  
  211.     if (killbuf[killptr] == NULL)
  212.         complain("[Nothing to yank!]");
  213.     lsave();
  214.     line = killbuf[killptr];
  215.     lp = lastline(line);
  216.     dot = DoYank(line, 0, lp, length(lp), curline, curchar, curbuf);
  217.     set_mark();
  218.     SetDot(dot);
  219. }
  220.  
  221. void
  222. ToIndent()
  223. {
  224.     Bol();
  225.     skip_wht_space();
  226. }
  227.  
  228. void
  229. skip_wht_space()
  230. {
  231.     register char    *cp = linebuf + curchar;
  232.  
  233.     while (jiswhite(*cp))
  234.         cp += 1;
  235.     curchar = cp - linebuf;
  236. }
  237.  
  238. /* GoLine -- go to a line, usually wired to goto-line, ESC g or ESC G.
  239.    If no argument is specified it asks for a line number. */
  240. void
  241. GoLine()
  242. {
  243.     LinePtr    newline;
  244.  
  245.     if (!is_an_arg())
  246.         set_arg_value(ask_int("1", "Line: ", 10));
  247.     if (arg_value() < 0)
  248.         newline = prev_line(curbuf->b_last, -1 - arg_value());
  249.     else
  250.         newline = next_line(curbuf->b_first, arg_value() - 1);
  251.     PushPntp(newline);
  252.     SetLine(newline);
  253. }
  254.  
  255. void
  256. NotModified()
  257. {
  258.     unmodify();
  259. }
  260.  
  261. void
  262. SetLMargin()
  263. {
  264.     int    lmarg = calc_pos(linebuf, curchar);
  265.  
  266.     if (lmarg >= RMargin)
  267.         complain("[Left margin must be left of right margin]");
  268.     LMargin = lmarg;
  269. }
  270.  
  271. void
  272. SetRMargin()
  273. {
  274.     int    rmarg = calc_pos(linebuf, curchar);
  275.  
  276.     if (rmarg <= LMargin)
  277.         complain("[Right margin must be right of left margin]");
  278.     RMargin = rmarg;
  279. }
  280.