home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1707 / move5.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  5.9 KB  |  354 lines

  1. /* m_5.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    16820 SW Tallac Way
  6.  *    Beaverton, OR 97006
  7.  *    kirkenda@jove.cs.pdx.edu, or ...uunet!tektronix!psueea!jove!kirkenda
  8.  */
  9.  
  10.  
  11. /* This file contains the word-oriented movement functions */
  12.  
  13. #include <ctype.h>
  14. #include "config.h"
  15. #include "vi.h"
  16.  
  17. #ifndef isascii
  18. # define isascii(c)    !((c) & ~0x7f)
  19. #endif
  20.  
  21.  
  22. MARK    m_fword(m, cnt)
  23.     MARK    m;    /* movement is relative to this mark */
  24.     long    cnt;    /* a numeric argument */
  25. {
  26.     register long    l;
  27.     register char    *text;
  28.     register int    i;
  29.  
  30.     DEFAULT(1);
  31.  
  32.     l = markline(m);
  33.     pfetch(l);
  34.     text = ptext + markidx(m);
  35.     while (cnt-- > 0) /* yes, ASSIGNMENT! */
  36.     {
  37.         i = *text++;
  38.         /* if we hit the end of the line, continue with next line */
  39.         if (!isascii(i) || isalnum(i) || i == '_')
  40.         {
  41.             /* include an alphanumeric word */
  42.             while (i && (!isascii(i) || isalnum(i) || i == '_'))
  43.             {
  44.                 i = *text++;
  45.             }
  46.         }
  47.         else
  48.         {
  49.             /* include contiguous punctuation */
  50.             while (i && isascii(i) && !isalnum(i) && !isspace(i))
  51.             {
  52.                 i = *text++;
  53.             }
  54.         }
  55.  
  56.         /* include trailing whitespace */
  57.         while (!i || isascii(i) && isspace(i))
  58.         {
  59.             /* did we hit the end of this line? */
  60.             if (!i)
  61.             {
  62.                 /* move to next line, if there is one */
  63.                 l++;
  64.                 if (l > nlines)
  65.                 {
  66.                     return MARK_UNSET;
  67.                 }
  68.                 pfetch(l);
  69.                 text = ptext;
  70.             }
  71.  
  72.             i = *text++;
  73.         }
  74.         text--;
  75.     }
  76.  
  77.     /* construct a MARK for this place */
  78.     m = buildmark(text);
  79.     return m;
  80. }
  81.  
  82.  
  83. MARK    m_bword(m, cnt)
  84.     MARK    m;    /* movement is relative to this mark */
  85.     long    cnt;    /* a numeric argument */
  86. {
  87.     register long    l;
  88.     register char    *text;
  89.  
  90.     DEFAULT(1);
  91.  
  92.     l = markline(m);
  93.     pfetch(l);
  94.     text = ptext + markidx(m);
  95.     while (cnt-- > 0) /* yes, ASSIGNMENT! */
  96.     {
  97.         text--;
  98.  
  99.         /* include preceding whitespace */
  100.         while (text < ptext || isascii(*text) && isspace(*text))
  101.         {
  102.             /* did we hit the end of this line? */
  103.             if (text < ptext)
  104.             {
  105.                 /* move to preceding line, if there is one */
  106.                 l--;
  107.                 if (l <= 0)
  108.                 {
  109.                     return MARK_UNSET;
  110.                 }
  111.                 pfetch(l);
  112.                 text = ptext + plen - 1;
  113.             }
  114.             else
  115.             {
  116.                 text--;
  117.             }
  118.         }
  119.  
  120.         if (!isascii(*text) || isalnum(*text) || *text == '_')
  121.         {
  122.             /* include an alphanumeric word */
  123.             while (text >= ptext && (!isascii(*text) || isalnum(*text) || *text == '_'))
  124.             {
  125.                 text--;
  126.             }
  127.         }
  128.         else
  129.         {
  130.             /* include contiguous punctuation */
  131.             while (text >= ptext && isascii(*text) && !isalnum(*text) && !isspace(*text))
  132.             {
  133.                 text--;
  134.             }
  135.         }
  136.         text++;
  137.     }
  138.  
  139.     /* construct a MARK for this place */
  140.     m = buildmark(text);
  141.     return m;
  142. }
  143.  
  144. MARK    m_eword(m, cnt)
  145.     MARK    m;    /* movement is relative to this mark */
  146.     long    cnt;    /* a numeric argument */
  147. {
  148.     register long    l;
  149.     register char    *text;
  150.     register int    i;
  151.  
  152.     DEFAULT(1);
  153.  
  154.     l = markline(m);
  155.     pfetch(l);
  156.     text = ptext + markidx(m);
  157.     while (cnt-- > 0) /* yes, ASSIGNMENT! */
  158.     {
  159.         text++;
  160.         i = *text++;
  161.  
  162.         /* include preceding whitespace */
  163.         while (!i || isascii(i) && isspace(i))
  164.         {
  165.             /* did we hit the end of this line? */
  166.             if (!i)
  167.             {
  168.                 /* move to next line, if there is one */
  169.                 l++;
  170.                 if (l > nlines)
  171.                 {
  172.                     return MARK_UNSET;
  173.                 }
  174.                 pfetch(l);
  175.                 text = ptext;
  176.             }
  177.  
  178.             i = *text++;
  179.         }
  180.  
  181.         if (!isascii(i) || isalnum(i) || i == '_')
  182.         {
  183.             /* include an alphanumeric word */
  184.             while (i && (!isascii(i) || isalnum(i) || i == '_'))
  185.             {
  186.                 i = *text++;
  187.             }
  188.         }
  189.         else
  190.         {
  191.             /* include contiguous punctuation */
  192.             while (i && isascii(i) && !isalnum(i) && !isspace(i))
  193.             {
  194.                 i = *text++;
  195.             }
  196.         }
  197.         text -= 2;
  198.     }
  199.  
  200.     /* construct a MARK for this place */
  201.     m = buildmark(text);
  202.     return m;
  203. }
  204.  
  205. MARK    m_fWord(m, cnt)
  206.     MARK    m;    /* movement is relative to this mark */
  207.     long    cnt;    /* a numeric argument */
  208. {
  209.     register long    l;
  210.     register char    *text;
  211.     register int    i;
  212.  
  213.     DEFAULT(1);
  214.  
  215.     l = markline(m);
  216.     pfetch(l);
  217.     text = ptext + markidx(m);
  218.     while (cnt-- > 0) /* yes, ASSIGNMENT! */
  219.     {
  220.         i = *text++;
  221.         /* if we hit the end of the line, continue with next line */
  222.         /* include contiguous non-space characters */
  223.         while (i && !isspace(i))
  224.         {
  225.             i = *text++;
  226.         }
  227.  
  228.         /* include trailing whitespace */
  229.         while (!i || isascii(i) && isspace(i))
  230.         {
  231.             /* did we hit the end of this line? */
  232.             if (!i)
  233.             {
  234.                 /* move to next line, if there is one */
  235.                 l++;
  236.                 if (l > nlines)
  237.                 {
  238.                     return MARK_UNSET;
  239.                 }
  240.                 pfetch(l);
  241.                 text = ptext;
  242.             }
  243.  
  244.             i = *text++;
  245.         }
  246.         text--;
  247.     }
  248.  
  249.     /* construct a MARK for this place */
  250.     m = buildmark(text);
  251.     return m;
  252. }
  253.  
  254.  
  255. MARK    m_bWord(m, cnt)
  256.     MARK    m;    /* movement is relative to this mark */
  257.     long    cnt;    /* a numeric argument */
  258. {
  259.     register long    l;
  260.     register char    *text;
  261.  
  262.     DEFAULT(1);
  263.  
  264.     l = markline(m);
  265.     pfetch(l);
  266.     text = ptext + markidx(m);
  267.     while (cnt-- > 0) /* yes, ASSIGNMENT! */
  268.     {
  269.         text--;
  270.  
  271.         /* include trailing whitespace */
  272.         while (text < ptext || isascii(*text) && isspace(*text))
  273.         {
  274.             /* did we hit the end of this line? */
  275.             if (text < ptext)
  276.             {
  277.                 /* move to next line, if there is one */
  278.                 l--;
  279.                 if (l <= 0)
  280.                 {
  281.                     return MARK_UNSET;
  282.                 }
  283.                 pfetch(l);
  284.                 text = ptext + plen - 1;
  285.             }
  286.             else
  287.             {
  288.                 text--;
  289.             }
  290.         }
  291.  
  292.         /* include contiguous non-whitespace */
  293.         while (text >= ptext && (!isascii(*text) || !isspace(*text)))
  294.         {
  295.             text--;
  296.         }
  297.         text++;
  298.     }
  299.  
  300.     /* construct a MARK for this place */
  301.     m = buildmark(text);
  302.     return m;
  303. }
  304.  
  305. MARK    m_eWord(m, cnt)
  306.     MARK    m;    /* movement is relative to this mark */
  307.     long    cnt;    /* a numeric argument */
  308. {
  309.     register long    l;
  310.     register char    *text;
  311.     register int    i;
  312.  
  313.     DEFAULT(1);
  314.  
  315.     l = markline(m);
  316.     pfetch(l);
  317.     text = ptext + markidx(m);
  318.     while (cnt-- > 0) /* yes, ASSIGNMENT! */
  319.     {
  320.         text++;
  321.         i = *text++;
  322.  
  323.         /* include preceding whitespace */
  324.         while (!i || isascii(i) && isspace(i))
  325.         {
  326.             /* did we hit the end of this line? */
  327.             if (!i)
  328.             {
  329.                 /* move to next line, if there is one */
  330.                 l++;
  331.                 if (l > nlines)
  332.                 {
  333.                     return MARK_UNSET;
  334.                 }
  335.                 pfetch(l);
  336.                 text = ptext;
  337.             }
  338.  
  339.             i = *text++;
  340.         }
  341.  
  342.         /* include contiguous non-whitespace */
  343.         while (i && (!isascii(i) || !isspace(i)))
  344.         {
  345.             i = *text++;
  346.         }
  347.         text -= 2;
  348.     }
  349.  
  350.     /* construct a MARK for this place */
  351.     m = buildmark(text);
  352.     return m;
  353. }
  354.