home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / z / zsh220.zip / zsh2.2 / src / zle_word.c < prev    next >
C/C++ Source or Header  |  1992-05-11  |  6KB  |  273 lines

  1. /*
  2.  *
  3.  * zle_word.c - word-related editor functions
  4.  *
  5.  * This file is part of zsh, the Z shell.
  6.  *
  7.  * This software is Copyright 1992 by Paul Falstad
  8.  *
  9.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  10.  * use this software as long as: there is no monetary profit gained
  11.  * specifically from the use or reproduction of this software, it is not
  12.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  13.  * included prominently in any copy made. 
  14.  *
  15.  * The author make no claims as to the fitness or correctness of this software
  16.  * for any use whatsoever, and it is provided as is. Any use of this software
  17.  * is at the user's own risk. 
  18.  *
  19.  */
  20.  
  21. #define ZLE
  22. #include "zsh.h"
  23.  
  24.  
  25. void forwardword() /**/
  26. {
  27.     if (mult < 0) { mult = -mult; backwardword(); return; }
  28.     while (mult--) {
  29.         while (cs != ll && iword(line[cs])) cs++;
  30.         if (wordflag && !mult) return;
  31.         while (cs != ll && !iword(line[cs])) cs++;
  32.     }
  33. }
  34.  
  35. void viforwardword() /**/
  36. {
  37.     if (mult < 0) { mult = -mult; backwardword(); return; }
  38.     while (mult--) {
  39.         if (iident(line[cs])) while (cs != ll && iident(line[cs])) cs++;
  40.         else while (cs != ll && !iident(line[cs]) && !iblank(line[cs])) cs++;
  41.         if (wordflag && !mult) return;
  42.         while (cs != ll && iblank(line[cs])) cs++;
  43.     }
  44. }
  45.  
  46. void viforwardblankword() /**/
  47. {
  48.     if (mult < 0) { mult = -mult; vibackwardblankword(); return; }
  49.     while (mult--) {
  50.         while (cs != ll && !iblank(line[cs])) cs++;
  51.         if (wordflag && !mult) return;
  52.         while (cs != ll && iblank(line[cs])) cs++;
  53.     }
  54. }
  55.  
  56. void emacsforwardword() /**/
  57. {
  58.     if (mult < 0) { mult = -mult; emacsbackwardword(); return; }
  59.     while (mult--)
  60.         {
  61.         while (cs != ll && !iword(line[cs])) cs++;
  62.         if (wordflag && !mult) return;
  63.         while (cs != ll && iword(line[cs])) cs++;
  64.         }
  65. }
  66.  
  67. void viforwardblankwordend() /**/
  68. {
  69.     if (mult < 0) return;
  70.     while (mult--) {
  71.         while (cs != ll && iblank(line[cs+1])) cs++;
  72.         while (cs != ll && !iblank(line[cs+1])) cs++;
  73.     }
  74.     if (cs != ll && virangeflag) cs++;
  75. }
  76.  
  77. void viforwardwordend() /**/
  78. {
  79.     if (mult < 0) { mult = -mult; backwardword(); return; }
  80.     while (mult--) {
  81.         if (iblank(line[cs+1])) while (cs != ll && iblank(line[cs+1])) cs++;
  82.         if (iident(line[cs+1])) while (cs != ll && iident(line[cs+1])) cs++;
  83.         else while (cs != ll && !iident(line[cs+1]) && !iblank(line[cs+1])) cs++;
  84.     }
  85.     if (cs != ll && virangeflag) cs++;
  86. }
  87.  
  88. void backwardword() /**/
  89. {
  90.     if (mult < 0) { mult = -mult; forwardword(); return; }
  91.     while (mult--) {
  92.         while (cs && !iword(line[cs-1])) cs--;
  93.         while (cs && iword(line[cs-1])) cs--;
  94.     }
  95. }
  96.  
  97. void vibackwardword() /**/
  98. {
  99.     if (mult < 0) { mult = -mult; backwardword(); return; }
  100.     while (mult--) {
  101.         while (cs && iblank(line[cs-1])) cs--;
  102.         if (iident(line[cs-1])) while (cs && iident(line[cs-1])) cs--;
  103.         else while (cs && !iident(line[cs-1]) && !iblank(line[cs-1])) cs--;
  104.     }
  105. }
  106.  
  107. void vibackwardblankword() /**/
  108. {
  109.     if (mult < 0) { mult = -mult; viforwardblankword(); return; }
  110.     while (mult--) {
  111.         while (cs && iblank(line[cs-1])) cs--;
  112.         while (cs && !iblank(line[cs-1])) cs--;
  113.     }
  114. }
  115.  
  116. void emacsbackwardword() /**/
  117. {
  118.     if (mult < 0) { mult = -mult; emacsforwardword(); return; }
  119.     while (mult--) {
  120.         while (cs && !iword(line[cs-1])) cs--;
  121.         while (cs && iword(line[cs-1])) cs--;
  122.     }
  123. }
  124.  
  125. void backwarddeleteword() /**/
  126. {
  127. int x = cs;
  128.  
  129.     if (mult < 0) { mult = -mult; deleteword(); return; }
  130.     while (mult--) {
  131.         while (x && !iword(line[x-1])) x--;
  132.         while (x && iword(line[x-1])) x--;
  133.     }
  134.     backdel(cs-x);
  135. }
  136.  
  137. void vibackwardkillword() /**/
  138. {
  139. int x = cs;
  140.  
  141.     if (mult < 0) { feep(); return; }
  142.     while (mult--) {
  143.         while (x > viinsbegin && !iword(line[x-1])) x--;
  144.         while (x > viinsbegin && iword(line[x-1])) x--;
  145.     }
  146.     backkill(cs-x,1);
  147. }
  148.  
  149. void backwardkillword() /**/
  150. {
  151. int x = cs;
  152.  
  153.     if (mult < 0) { mult = -mult; killword(); return; }
  154.     while (mult--) {
  155.         while (x && !iword(line[x-1])) x--;
  156.         while (x && iword(line[x-1])) x--;
  157.     }
  158.     backkill(cs-x,1);
  159. }
  160.  
  161. void upcaseword() /**/
  162. {
  163. int neg = mult < 0, ocs = cs;
  164.  
  165.     if (neg) mult = -mult;
  166.     while (mult--) {
  167.         while (cs != ll && !iword(line[cs])) cs++;
  168.         while (cs != ll && iword(line[cs])) {
  169.             line[cs] = tuupper(line[cs]);
  170.             cs++;
  171.         }
  172.     }
  173.     if (neg) cs = ocs;
  174. }
  175.  
  176. void downcaseword() /**/
  177. {
  178. int neg = mult < 0, ocs = cs;
  179.  
  180.     if (neg) mult = -mult;
  181.     while (mult--) {
  182.         while (cs != ll && !iword(line[cs])) cs++;
  183.         while (cs != ll && iword(line[cs])) {
  184.             line[cs] = tulower(line[cs]);
  185.             cs++;
  186.         }
  187.     }
  188.     if (neg) cs = ocs;
  189. }
  190.  
  191. void capitalizeword() /**/
  192. {
  193. int first;
  194. int neg = mult < 0, ocs = cs;
  195.     
  196.     if (neg) mult = -mult;
  197.     while (mult--) {
  198.         first = 1;
  199.         while (cs != ll && !iword(line[cs])) cs++;
  200.         while (cs != ll && iword(line[cs])) {
  201.             line[cs] = (first) ? tuupper(line[cs]) : tulower(line[cs]);
  202.             first = 0;
  203.             cs++;
  204.         }
  205.     }
  206.     if (neg) cs = ocs;
  207. }
  208.  
  209. void deleteword() /**/
  210. {
  211. int x = cs;
  212.  
  213.     if (mult < 0) { mult = -mult; backwarddeleteword(); return; }
  214.     while (mult--) {
  215.         while (x != ll && !iword(line[x])) x++;
  216.         while (x != ll && iword(line[x])) x++;
  217.     }
  218.     foredel(x-cs);
  219. }
  220.  
  221. void killword() /**/
  222. {
  223. int x = cs;
  224.  
  225.     if (mult < 0) { mult = -mult; backwardkillword(); return; }
  226.     while (mult--) {
  227.         while (x != ll && !iword(line[x])) x++;
  228.         while (x != ll && iword(line[x])) x++;
  229.     }
  230.     forekill(x-cs,0);
  231. }
  232.  
  233. void transposewords() /**/
  234. {
  235. int p1,p2,p3,p4,x = cs;
  236. char *temp,*pp;
  237. int neg = mult < 0, ocs = cs;
  238.  
  239.     if (neg) mult = -mult;
  240.     while (mult--) {
  241.         while (x != ll && line[x] != '\n' && !iword(line[x]))
  242.             x++;
  243.         if (x == ll || line[x] == '\n') {
  244.             x = cs;
  245.             while (x && line[x-1] != '\n' && !iword(line[x]))
  246.                 x--;
  247.             if (!x || line[x-1] == '\n') {
  248.                 feep();
  249.                 return;
  250.             }
  251.         }
  252.         for (p4 = x; p4 != ll && iword(line[p4]); p4++);
  253.         for (p3 = p4; p3 && iword(line[p3-1]); p3--);
  254.         if (!p3) {
  255.             feep();
  256.             return;
  257.         }
  258.         for (p2 = p3; p2 && !iword(line[p2-1]); p2--);
  259.         if (!p2) {
  260.             feep();
  261.             return;
  262.         }
  263.         for (p1 = p2; p1 && iword(line[p1-1]); p1--);
  264.         pp = temp = halloc(p4-p1+1);
  265.         struncpy(&pp,line+p3,p4-p3);
  266.         struncpy(&pp,line+p2,p3-p2);
  267.         struncpy(&pp,line+p1,p2-p1);
  268.         strncpy((char *) line+p1,temp,p4-p1);
  269.         cs = p4;
  270.     }
  271.     if (neg) cs = ocs;
  272. }
  273.