home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / word / text / 019 / replace.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  1KB  |  51 lines

  1. /*
  2.  *  Copyright (c) 1992 John E. Davis  (davis@amy.tch.harvard.edu)
  3.  *  All Rights Reserved.
  4.  */
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. #include "buffer.h"
  9. #include "replace.h"
  10. #include "search.h"
  11. #include "screen.h"
  12. #include "ins.h"
  13.  
  14. int replace_next(char *old, char *new)
  15. {
  16.     char *p;
  17.  
  18.     if (search(old, 1, 0) == 0) return(0);
  19.  
  20.     /* In the future, I will make this somewhat smart in the following way:
  21.        If new = "Hello" and old = "heLLo" then replace it with "Hello".
  22.        But if old is "World" and new is "hello", then replace it with "Hello".
  23.        */
  24.  
  25.     while(1)
  26.       {
  27.  
  28.       if ((*old != 0) && (*new != 0))
  29.         {
  30.            p = (char *) (CLine->data + Point);
  31.            *p = *new;
  32.            Point++;
  33.         }
  34.  
  35.       else if ((*old == 0) && (*new != 0)) ins((char) *new);
  36.       else if ((*old != 0) && (*new == 0)) del();
  37.       else if ((*old == 0) && (*new == 0))
  38.         {
  39.         register_change(0);
  40.         CBuf->flags |= BUFFER_TRASHED;
  41.         }
  42.  
  43.       if ((*new == 0) && (*old == 0)) break;
  44.  
  45.       if (*new != 0) new++;
  46.       if (*old != 0) old++;
  47.       }
  48.     return(1);
  49. }
  50.  
  51.