home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / jove414s.zip / case.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  4KB  |  221 lines

  1. /***************************************************************************
  2.  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  3.  * is 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 "disp.h"
  10. #include "ctype.h"
  11.  
  12. private    int
  13. # if !(defined(IBMPC) || defined(MAC))
  14.     lower proto((char *)),
  15. # endif
  16.     upper proto((char *));
  17.  
  18. private void
  19.     CaseReg proto((int up)),
  20.     case_reg proto((struct line *line1,int char1,struct line *line2,int char2,int up)),
  21.     case_word proto((int up));
  22.  
  23. void
  24. CapChar()
  25. {
  26.     register  int    num,
  27.             restore = NO;
  28.     Bufpos    b;
  29.  
  30.     DOTsave(&b);
  31.  
  32.     num = arg_value();
  33.     if (num < 0) {
  34.         restore = YES;
  35.         num = -num;
  36.         b_char(num);    /* Cap previous EXP chars */
  37.     }
  38.     while (num--) {
  39.         if (upper(&linebuf[curchar])) {
  40.             modify();
  41.             makedirty(curline);
  42.         }
  43.         if (eolp()) {
  44.             if (curline->l_next == 0)
  45.                 break;
  46.             SetLine(curline->l_next);
  47.         } else
  48.             curchar += 1;
  49.     }
  50.     if (restore)
  51.         SetDot(&b);
  52. }
  53.  
  54. void
  55. CapWord()
  56. {
  57.     register  int    num,
  58.             restore = NO;
  59.     Bufpos    b;
  60.  
  61.     DOTsave(&b);
  62.     num = arg_value();
  63.     if (num < 0) {
  64.         restore = YES;
  65.         num = -num;
  66.         b_word(num);        /* Cap previous EXP words */
  67.     }
  68.     while (num--) {
  69.         to_word(1);    /* Go to the beginning of the next word. */
  70.         if (eobp())
  71.             break;
  72.         if (upper(&linebuf[curchar])) {
  73.             modify();
  74.             makedirty(curline);
  75.         }
  76.         curchar += 1;
  77.         while (!eolp() && isword(linebuf[curchar])) {
  78.             if (lower(&linebuf[curchar])) {
  79.                 modify();
  80.                 makedirty(curline);
  81.             }
  82.             curchar += 1;
  83.         }
  84.     }
  85.     if (restore)
  86.         SetDot(&b);
  87. }
  88.  
  89. private void
  90. case_word(up)
  91. int    up;
  92. {
  93.     Bufpos    before;
  94.  
  95.     DOTsave(&before);
  96.     ForWord();    /* this'll go backward if negative argument */
  97.     case_reg(before.p_line, before.p_char, curline, curchar, up);
  98. }
  99.  
  100. private int
  101. upper(c)
  102. register  char    *c;
  103. {
  104.     if (islower(*c)) {
  105. #if !defined(ASCII)            /* check for IBM extended character set */
  106.         if (*c <= 127)
  107. #endif /* ASCII */
  108.         *c -= ' ';
  109. #if defined(IBMPC)            /* ... and change Umlaute    */
  110.         else
  111.            switch (*c) {
  112.              case 129: *c = 154; break;        /* ue */
  113.              case 132: *c = 142; break;        /* ae */
  114.              case 148: *c = 153; break;        /* oe */
  115.            }
  116. #endif /* IBMPC */
  117. #if defined(MAC)
  118.         else *c = CaseEquiv[*c];
  119. #endif
  120.         return 1;
  121.     }
  122.     return 0;
  123. }
  124.  
  125. #if !(defined(IBMPC) || defined(MAC))
  126. private
  127. #endif
  128. int
  129. lower(c)
  130. char    *c;
  131. {
  132.     if (isupper(*c)) {
  133. #if !defined(ASCII)
  134.         if (*c <= 127)
  135. #endif /* ASCII */
  136.         *c += ' ';
  137. #if defined(IBMPC)
  138.         else
  139.            switch (*c) {
  140.              case 142: *c = 132; break;        /* Ae */
  141.              case 153: *c = 148; break;        /* Oe */
  142.              case 154: *c = 129; break;        /* Ue */
  143.            }
  144. #endif /* IBMPC */
  145. #if defined(MAC)
  146.         else {
  147.             int n;
  148.  
  149.             for(n = 128; n < 256; n++) {
  150.                 if((CaseEquiv[n] == *c) && islower(n)) {
  151.                     *c = n;
  152.                     break;
  153.                 }
  154.             }
  155.             if(n > 255) return(0);
  156.         }
  157. #endif /* MAC */
  158.         return 1;
  159.     }
  160.     return 0;
  161. }
  162.  
  163. private void
  164. case_reg(line1, char1, line2, char2, up)    
  165. Line    *line1,
  166.     *line2;
  167. int    char1,
  168.     char2,
  169.     up;
  170. {
  171.     (void) fixorder(&line1, &char1, &line2, &char2);
  172.     DotTo(line1, char1);
  173.  
  174.     for (;;) {
  175.         if (curline == line2 && curchar == char2)
  176.             break;
  177.         if (!eolp())
  178.             if ((up) ? upper(&linebuf[curchar]) : lower(&linebuf[curchar])) {
  179.                 makedirty(curline);
  180.                 modify();
  181.             }
  182.         f_char(1);
  183.     }
  184. }
  185.  
  186. void
  187. CasRegLower()
  188. {
  189.     CaseReg(0);
  190. }
  191.  
  192. void
  193. CasRegUpper()
  194. {
  195.     CaseReg(1);
  196. }
  197.  
  198. private void
  199. CaseReg(up)
  200. int    up;
  201. {
  202.     register  Mark    *mp = CurMark();
  203.     Bufpos    savedot;
  204.  
  205.     DOTsave(&savedot);
  206.     case_reg(curline, curchar, mp->m_line, mp->m_char, up);
  207.     SetDot(&savedot);
  208. }
  209.  
  210. void
  211. UppWord()
  212. {
  213.     case_word(1);
  214. }
  215.  
  216. void
  217. LowWord()
  218. {
  219.     case_word(0);
  220. }
  221.