home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vile-src.zip / vile-8.1 / wordmov.c < prev    next >
C/C++ Source or Header  |  1998-04-28  |  6KB  |  374 lines

  1. /* These routines report on transitions between word boundaries, both
  2.  *    in the punctuated vi sense, and in the whitespace/darkspace
  3.  *    sense.  The transition is reported _after_ it has occurred.  You
  4.  *    need to back up to get to the char. before the transition.
  5.  *    Written for vile: Copyright (c) 1990, 1995 by Paul Fox
  6.  *
  7.  * $Header: /usr/build/vile/vile/RCS/wordmov.c,v 1.19 1998/04/28 10:19:41 tom Exp $
  8.  *
  9.  */
  10.  
  11. #include "estruct.h"
  12. #include "edef.h"
  13.  
  14. #define WASSPACE 0
  15. #define ISSPACE 0
  16. #define WASIDENT 1
  17. #define ISIDENT 1
  18. #define WASOTHER 2
  19. #define ISOTHER 2
  20. #define WASNL 3
  21. #define ISNL 3
  22.  
  23. static int ochartype;
  24.  
  25. static int
  26. getchartype(void)
  27. {
  28.     register int    c;
  29.  
  30.     if (is_at_end_of_line(DOT))
  31.         return (ISNL);
  32.     else
  33.         c = char_at(DOT);
  34.     return (isSpace(c) ? ISSPACE :
  35.             ( isident(c) ? ISIDENT : ISOTHER ) );
  36. }
  37.  
  38. void
  39. setchartype(void)
  40. {
  41.     ochartype = getchartype();
  42. }
  43.  
  44.  
  45. int
  46. isnewwordf(void)
  47. {
  48.     register int    ret = FALSE;
  49.     register int    type;
  50.  
  51.     type = getchartype();
  52.  
  53.     switch (ochartype) {
  54.     case WASNL:
  55.     case WASSPACE:
  56.         switch (type) {
  57.         case ISNL:
  58.             if (doingopcmd) {
  59.                 ret = SORTOFTRUE;
  60.                 break;
  61.             }
  62.             /* FALLTHROUGH */
  63.         case ISSPACE:
  64.             ret = FALSE;
  65.             break;
  66.         case ISIDENT:
  67.             /* FALLTHROUGH */
  68.         case ISOTHER:
  69.             ret = TRUE;
  70.             break;
  71.         }
  72.         break;
  73.     case WASIDENT:
  74.     case WASOTHER:
  75.         switch (type) {
  76.         case ISNL:
  77.             if (doingopcmd) {
  78.                 ret = SORTOFTRUE;
  79.                 break;
  80.             }
  81.             /* FALLTHROUGH */
  82.         case ISSPACE:
  83.             if (doingopcmd && opcmd != OPDEL) {
  84.                 ret = SORTOFTRUE;
  85.                 break;
  86.             }
  87.             /* FALLTHROUGH */
  88.         case ISIDENT:
  89.             /* FALLTHROUGH */
  90.         case ISOTHER:
  91.             ret = FALSE;
  92.             break;
  93.         }
  94.         break;
  95.     }
  96.     ochartype = type;
  97.     return (ret);
  98. }
  99.  
  100. int
  101. isnewwordb(void)
  102. {
  103.     register int    ret = FALSE;
  104.     register int    type;
  105.  
  106.     type = getchartype();
  107.  
  108.     switch (ochartype) {
  109.     case WASNL:
  110.     case WASSPACE:
  111.         ret = FALSE;    break;
  112.     case WASIDENT:
  113.         switch (type) {
  114.         case ISNL:
  115.         case ISSPACE: ret = TRUE;    break;
  116.         case ISIDENT:
  117.         case ISOTHER: ret = FALSE;    break;
  118.         }
  119.         break;
  120.     case WASOTHER:
  121.         switch (type) {
  122.         case ISNL:
  123.         case ISSPACE: ret = TRUE;    break;
  124.         case ISIDENT:
  125.         case ISOTHER: ret = FALSE;    break;
  126.         }
  127.         break;
  128.     }
  129.     ochartype = type;
  130.     return (ret);
  131. }
  132.  
  133. int
  134. isnewviwordf(void)
  135. {
  136.     register int    ret = FALSE;
  137.     register int    type;
  138.  
  139.     type = getchartype();
  140.  
  141.     switch (ochartype) {
  142.     case WASNL:
  143.     case WASSPACE:
  144.         switch (type) {
  145.         case ISNL:
  146.             if (doingopcmd) {
  147.                 ret = SORTOFTRUE;
  148.                 break;
  149.             }
  150.             /* FALLTHROUGH */
  151.         case ISSPACE:
  152.             ret = FALSE;
  153.             break;
  154.         case ISIDENT:
  155.             /* FALLTHROUGH */
  156.         case ISOTHER:
  157.             ret = TRUE;
  158.             break;
  159.         }
  160.         break;
  161.     case WASIDENT:
  162.         switch (type) {
  163.         case ISNL:
  164.             if (doingopcmd) {
  165.                 ret = SORTOFTRUE;
  166.                 break;
  167.             }
  168.             /* FALLTHROUGH */
  169.         case ISSPACE:
  170.             if (doingopcmd && opcmd != OPDEL) {
  171.                 ret = SORTOFTRUE;
  172.                 break;
  173.             }
  174.             /* FALLTHROUGH */
  175.         case ISIDENT:
  176.             ret = FALSE;
  177.             break;
  178.         case ISOTHER:
  179.             ret = TRUE;
  180.             break;
  181.         }
  182.         break;
  183.     case WASOTHER:
  184.         switch (type) {
  185.         case ISNL:
  186.             if (doingopcmd) {
  187.                 ret = SORTOFTRUE;
  188.                 break;
  189.             }
  190.             /* FALLTHROUGH */
  191.         case ISSPACE:
  192.             if (doingopcmd && opcmd != OPDEL) {
  193.                 ret = SORTOFTRUE;
  194.                 break;
  195.             }
  196.             /* FALLTHROUGH */
  197.         case ISOTHER:
  198.             ret = FALSE;
  199.             break;
  200.         case ISIDENT:
  201.             ret = TRUE;
  202.             break;
  203.         }
  204.         break;
  205.     }
  206.     ochartype = type;
  207.     return (ret);
  208. }
  209.  
  210. int
  211. isnewviwordb(void)
  212. {
  213.     register int    ret = FALSE;
  214.     register int    type;
  215.  
  216.     type = getchartype();
  217.  
  218.     switch (ochartype) {
  219.     case WASNL:
  220.     case WASSPACE:
  221.         ret = FALSE;    break;
  222.     case WASIDENT:
  223.         switch (type) {
  224.         case ISNL:
  225.         case ISSPACE:
  226.         case ISOTHER: ret = TRUE;    break;
  227.         case ISIDENT: ret = FALSE;    break;
  228.         }
  229.         break;
  230.     case WASOTHER:
  231.         switch (type) {
  232.         case ISNL:
  233.         case ISSPACE:
  234.         case ISIDENT: ret = TRUE;    break;
  235.         case ISOTHER: ret = FALSE;    break;
  236.         }
  237.         break;
  238.     }
  239.     ochartype = type;
  240.     return (ret);
  241. }
  242.  
  243. int
  244. isendwordf(void)
  245. {
  246.     register int    ret = FALSE;
  247.     register int    type;
  248.  
  249.     type = getchartype();
  250.  
  251.     switch (ochartype) {
  252.     case WASNL:
  253.     case WASSPACE:
  254.         ret = FALSE;    break;
  255.     case WASIDENT:
  256.         switch (type) {
  257.         case ISNL:
  258.         case ISSPACE:
  259.             if (doingopcmd) ret = SORTOFTRUE;
  260.             else ret = TRUE;
  261.             if (doingsweep) sweephack = TRUE;
  262.             break;
  263.         case ISIDENT:
  264.         case ISOTHER: ret = FALSE;    break;
  265.         }
  266.         break;
  267.     case WASOTHER:
  268.         switch (type) {
  269.         case ISNL:
  270.         case ISSPACE:
  271.             if (doingopcmd) ret = SORTOFTRUE;
  272.             else ret = TRUE;
  273.             if (doingsweep) sweephack = TRUE;
  274.             break;
  275.         case ISIDENT:
  276.         case ISOTHER: ret = FALSE;    break;
  277.         }
  278.         break;
  279.     }
  280.     ochartype = type;
  281.     return (ret);
  282. }
  283.  
  284. int
  285. isendviwordf(void)
  286. {
  287.     register int    ret = FALSE;
  288.     register int    type;
  289.  
  290.     type = getchartype();
  291.  
  292.     switch (ochartype) {
  293.     case WASNL:
  294.     case WASSPACE:
  295.         ret = FALSE;    break;
  296.     case WASIDENT:
  297.         switch (type) {
  298.         case ISNL:
  299.         case ISSPACE:
  300.         case ISOTHER:
  301.             if (doingopcmd) ret = SORTOFTRUE;
  302.             else ret = TRUE;
  303.             if (doingsweep) sweephack = TRUE;
  304.             break;
  305.         case ISIDENT: ret = FALSE;    break;
  306.         }
  307.         break;
  308.     case WASOTHER:
  309.         switch (type) {
  310.         case ISNL:
  311.         case ISSPACE:
  312.         case ISIDENT:
  313.             if (doingopcmd) ret = SORTOFTRUE;
  314.             else ret = TRUE;
  315.             if (doingsweep) sweephack = TRUE;
  316.             break;
  317.         case ISOTHER: ret = FALSE;    break;
  318.         }
  319.         break;
  320.     }
  321.     ochartype = type;
  322.     return (ret);
  323. }
  324.  
  325. #ifdef template
  326. int
  327. isANYTHING(void)
  328. {
  329.     register int    ret = FALSE;
  330.     register int    type;
  331.  
  332.     type = getchartype();
  333.  
  334.     switch (ochartype) {
  335.     case WASNL:
  336.     case WASSPACE:
  337.         switch (type) {
  338.         case ISNL:
  339.         case ISSPACE:
  340.             ret = FALSE;    break;
  341.         case ISIDENT:
  342.             ret = FALSE;    break;
  343.         case ISOTHER:
  344.             ret = FALSE;    break;
  345.         }
  346.         break;
  347.     case WASIDENT:
  348.         switch (type) {
  349.         case ISNL:
  350.         case ISSPACE:
  351.             ret = TRUE;    break;
  352.         case ISIDENT:
  353.             ret = FALSE;    break;
  354.         case ISOTHER:
  355.             ret = TRUE;    break;
  356.         }
  357.         break;
  358.     case WASOTHER:
  359.         switch (type) {
  360.         case ISNL:
  361.         case ISSPACE:
  362.             ret = TRUE;    break;
  363.         case ISIDENT:
  364.             ret = TRUE;    break;
  365.         case ISOTHER:
  366.             ret = FALSE;    break;
  367.         }
  368.         break;
  369.     }
  370.     ochartype = type;
  371.     return (ret);
  372. }
  373. #endif /* template */
  374.