home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name EDWRAP -- Perform word wrapping on an edit buffer.
- *
- * Synopsis edwrap(pedit_buffer)
- *
- * ED_BUFFER *pedit_buffer edit buffer structure.
- *
- * Description EDWRAP accepts a pointer to an edit buffer and
- * performs word wrapping on it. A word is defined as a
- * series of non-whitespace characters surrounded by
- * whitespace. Any word which would touch the right edge
- * of the field will have blanks inserted in front of it
- * to force it onto the next line. If the word is longer
- * than one line long, it is broken. Note that word
- * wrapping may force data off the end of the buffer, in
- * which case it is lost.
- *
- * Returns nothing.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
- #include <bedit.h>
-
- void edwrap(pedit_buffer)
- ED_BUFFER *pedit_buffer;
- {
- int current_row;
- int last_char_on_row;
- int current_index;
-
- /* If the displayed field is only one row, there's nothing to do. */
- if (pedit_buffer->dimensions.h == 1)
- return;
-
- for (current_row = 0; current_row < (pedit_buffer->dimensions.h - 1);
- current_row++)
- {
- last_char_on_row = (pedit_buffer->dimensions.w *
- (current_row + 1)) - 1;
- if (last_char_on_row >= pedit_buffer->buffer_size)
- return;
-
- /* Find the last non-space on the current line. */
- for (current_index = last_char_on_row;
- (current_index > last_char_on_row -
- pedit_buffer->dimensions.w) &&
- (!isspace(pedit_buffer->pbuffer[current_index]));
- current_index--)
- ;
-
- /* Check to see if we should wrap here. */
- if (!utrange(current_index, last_char_on_row -
- pedit_buffer->dimensions.w + 1,
- last_char_on_row - 1) &&
- !isspace(pedit_buffer->pbuffer[current_index + 1]))
- {
- current_index++;
-
- memmove(&(pedit_buffer->pbuffer[last_char_on_row + 1]),
- &pedit_buffer->pbuffer[current_index],
- pedit_buffer->buffer_size - last_char_on_row - 1);
- memset(&pedit_buffer->pbuffer[current_index], ' ',
- (last_char_on_row - current_index) + 1);
-
- /* Update current end of data, if necessary. */
- if (pedit_buffer->data_end >= current_index)
- {
- pedit_buffer->data_end += (last_char_on_row -
- current_index) + 1;
- utuplim(pedit_buffer->data_end,
- pedit_buffer->buffer_size);
- }
-
- /* Update current edit position, if necessary. */
- if (pedit_buffer->cursor_pos >= current_index)
- {
- pedit_buffer->cursor_pos += (last_char_on_row -
- current_index) + 1;
- utuplim(pedit_buffer->cursor_pos,
- pedit_buffer->buffer_size - 1);
- }
- }
- }
- }