home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / EDREDUCE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.4 KB  |  67 lines

  1. /**
  2. *
  3. * Name        EDREDUCE  -  Reduce all consecutive whitespace to a
  4. *                 single blank.
  5. *
  6. * Synopsis    edreduce(pedit_buffer);
  7. *
  8. *        ED_BUFFER *pedit_buffer  Pointer to edit buffer to
  9. *                     reduce.
  10. *
  11. * Description    EDREDUCE will scan the pbuffer member of
  12. *        *pedit_buffer, reducing all runs of consecutive
  13. *        whitespace to a single blank. The data_end and
  14. *        cursor_pos fields are adjusted accordingly.
  15. *
  16. * Returns    nothing.
  17. *
  18. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  19. *
  20. **/
  21. #include <bedit.h>
  22.  
  23. void edreduce(pedit_buffer)
  24. ED_BUFFER *pedit_buffer;
  25. {
  26.     int   current_char;
  27.     int   in_white   = 0;
  28.     int   data_end   = pedit_buffer->data_end;
  29.     int   cursor_pos = pedit_buffer->cursor_pos;
  30.     char *pdest;
  31.  
  32.     pdest   = pedit_buffer->pbuffer;
  33.  
  34.     for (current_char = 0; current_char < pedit_buffer->data_end;
  35.      current_char++)
  36.     {
  37.     if (isspace(pedit_buffer->pbuffer[current_char]))
  38.     {
  39.         if (!in_white)
  40.         {
  41.         in_white = 1;
  42.         *pdest++ = ' ';
  43.         }
  44.         else
  45.         {
  46.         if (pedit_buffer->data_end >= current_char)
  47.             data_end--;
  48.         if (pedit_buffer->cursor_pos >= current_char)
  49.             cursor_pos--;
  50.         }
  51.     }
  52.     else
  53.     {
  54.         in_white = 0;
  55.         *pdest++ = pedit_buffer->pbuffer[current_char];
  56.     }
  57.     }
  58.  
  59.     while (pdest < (pedit_buffer->pbuffer + pedit_buffer->buffer_size))
  60.     {
  61.     *pdest++ = ' ';
  62.     }
  63.  
  64.     pedit_buffer->data_end = data_end;
  65.     pedit_buffer->cursor_pos = cursor_pos;
  66. }
  67.