home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / emacs / src / zmaxs01.lzr / OVWORD1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-20  |  3.9 KB  |  170 lines

  1. /*
  2.  * The routines in this file
  3.  * implement commands that work word at
  4.  * a time. There are all sorts of word mode
  5.  * commands. If I do any sentence and/or paragraph
  6.  * mode commands, they are likely to be put in
  7.  * this file.
  8.  */
  9. #include    "stdio.h"
  10. #include    "ed.h"
  11.  
  12. ovmain( x, f, n )
  13. {    switch ( x )
  14.     {    case 0: return ( upperword( f, n ));
  15.         case 1: return ( lowerword( f, n ));
  16.         case 2: return ( capword( f, n ));
  17. /*        case 3: return ( setfillcol( f, n )); */
  18. /*        case 4: return ( wrapword( )); */
  19.     }
  20. }
  21. #ifdef NEVER
  22. /* Word wrap on n-spaces.
  23.  * Back-over whatever precedes the point on the current line and
  24.  * stop on the first word-break or the beginning of the line.
  25.  * If we reach the beginning of the line, jump back to the end of the
  26.  * word and start a new line.  Otherwise, break the line at the
  27.  * word-break, eat it, and jump back to the end of the word.
  28.  *    NOTE:  This function may leaving trailing blanks.
  29.  * Returns TRUE on success, FALSE on errors.
  30.  */
  31. wrapword()
  32. {
  33.     register int cnt;
  34.     register LINE *oldp;
  35.  
  36.     oldp = curwp->w_dotp;
  37.     cnt = -1;
  38.     do {                
  39.         cnt++;
  40.         if (! backchar(NULL, 1))
  41.             return(FALSE);
  42.     }
  43.     while (! inword());
  44.     if (! backword(NULL, 1))
  45.         return(FALSE);
  46.     if (oldp == curwp->w_dotp && curwp->w_doto ) {
  47.         if (! backdel(NULL, 1))
  48.             return(FALSE);
  49.         if (! newline(NULL, 1))
  50.             return(FALSE);
  51.     }
  52.     return(forwword(NULL, 1) && forwchar(NULL, cnt));
  53. }
  54.  
  55. /*
  56.  * Set fill column to n. 
  57.  */
  58. setfillcol(f, n)
  59. {
  60.     fillcol = n;
  61.     return(TRUE);
  62. }
  63. #endif
  64. /*
  65.  * Move the cursor forward by
  66.  * the specified number of words. As you move,
  67.  * convert any characters to upper case. Error
  68.  * if you try and move beyond the end of the
  69.  * buffer. Bound to "M-U".
  70.  */
  71. upperword(f, n)
  72. {
  73.     register int    c;
  74.  
  75.     if (n < 0)
  76.         return (FALSE);
  77.     while (n--) {
  78.         while (inword() == FALSE) {
  79.             if (forwchar(FALSE, 1) == FALSE)
  80.                 return (FALSE);
  81.         }
  82.         while (inword() != FALSE) {
  83.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  84.             if (c>='a' && c<='z') {
  85.                 c -= 'a'-'A';
  86.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  87.                 lchange(WFHARD);
  88.             }
  89.             if (forwchar(FALSE, 1) == FALSE)
  90.                 return (FALSE);
  91.         }
  92.     }
  93.     return (TRUE);
  94. }
  95.  
  96. /*
  97.  * Move the cursor forward by
  98.  * the specified number of words. As you move
  99.  * convert characters to lower case. Error if you
  100.  * try and move over the end of the buffer.
  101.  * Bound to "M-L".
  102.  */
  103. lowerword(f, n)
  104. {
  105.     register int    c;
  106.  
  107.     if (n < 0)
  108.         return (FALSE);
  109.     while (n--) {
  110.         while (inword() == FALSE) {
  111.             if (forwchar(FALSE, 1) == FALSE)
  112.                 return (FALSE);
  113.         }
  114.         while (inword() != FALSE) {
  115.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  116.             if (c>='A' && c<='Z') {
  117.                 c += 'a'-'A';
  118.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  119.                 lchange(WFHARD);
  120.             }
  121.             if (forwchar(FALSE, 1) == FALSE)
  122.                 return (FALSE);
  123.         }
  124.     }
  125.     return (TRUE);
  126. }
  127.  
  128. /*
  129.  * Move the cursor forward by
  130.  * the specified number of words. As you move
  131.  * convert the first character of the word to upper
  132.  * case, and subsequent characters to lower case. Error
  133.  * if you try and move past the end of the buffer.
  134.  * Bound to "M-C".
  135.  */
  136. capword(f, n)
  137. {
  138.     register int    c;
  139.  
  140.     if (n < 0)
  141.         return (FALSE);
  142.     while (n--) {
  143.         while (inword() == FALSE) {
  144.             if (forwchar(FALSE, 1) == FALSE)
  145.                 return (FALSE);
  146.         }
  147.         if (inword() != FALSE) {
  148.             c = lgetc(curwp->w_dotp, curwp->w_doto);
  149.             if (c>='a' && c<='z') {
  150.                 c -= 'a'-'A';
  151.                 lputc(curwp->w_dotp, curwp->w_doto, c);
  152.                 lchange(WFHARD);
  153.             }
  154.             if (forwchar(FALSE, 1) == FALSE)
  155.                 return (FALSE);
  156.             while (inword() != FALSE) {
  157.                 c = lgetc(curwp->w_dotp, curwp->w_doto);
  158.                 if (c>='A' && c<='Z') {
  159.                     c += 'a'-'A';
  160.                     lputc(curwp->w_dotp, curwp->w_doto, c);
  161.                     lchange(WFHARD);
  162.                 }
  163.                 if (forwchar(FALSE, 1) == FALSE)
  164.                     return (FALSE);
  165.             }
  166.         }
  167.     }
  168.     return (TRUE);
  169. }
  170.