📄 wordwrap.c
字号:
while (i < rm) { g_status.line_buff[rm] = g_status.line_buff[i]; if (g_status.line_buff[rm] == ' ') { /* * this while loop copies extra blanks after a period or * blanks otherwise intentionally left in the text. */ while (g_status.line_buff[i-1] == ' ') g_status.line_buff[--rm] = g_status.line_buff[--i]; nb = side == LEFT ? spaces / holes : (spaces - 1) / holes + 1; spaces -= nb; --holes; while (nb-- > 0) g_status.line_buff[--rm] = ' '; } --i; --rm; } un_copy_line( ll, window, TRUE, TRUE );}/* * Name: remove_spaces * Purpose: remove any extra spaces in the text * Date: December 30, 1992 * Passed: lm: left margin * Notes: this routine squeezes out extra space from a previous format. * the line must be placed in the line buffer before calling this * function. */void remove_spaces( int lm ){int period;int len;int i;int c;text_ptr s;text_ptr d; if ((i = len = g_status.line_buff_len) <= lm) return; period = FALSE; s = d = g_status.line_buff + lm; i -= lm; c = (int)*s++; while (c == ' ' && i > 0) { c = *s++; --i; --len; } period = c == '.' ? TRUE : FALSE; while (i > 0) { *d++ = (char)c; c = (int)*s++; --i; if (c != ' ') period = c == '.' ? TRUE : FALSE; else { *d++ = (char)c; c = (int)*s++; --i; if (period && c == ' ') { *d++ = (char)c; period = FALSE; if (i > 0) ++len; } while (c == ' ' && i > 0) { c = (int)*s++; --len; --i; } } } *d = (char)c; g_status.line_buff_len = len;}/* * Name: find_word * Purpose: find a word on a line * Date: November 29, 1991 * Passed: p: pointer to a line of text * len: len of line * start_col: col to start the search * Notes: returns the column of the next word or -1 (ERROR) if no more words * * jmh 990501: this function is only called twice, both times with a detabbed * line buff - no point testing tabs. */int find_word( text_ptr p, int len, int start_col/*, int tabs, int tab_size*/){register int rc;/* register char c; */ if (len <= start_col || len < 0 || start_col < 0) return( ERROR ); p += start_col; rc = start_col; if (rc == 0 && len > 0) { if (*p != ' ' /*|| !tabs || *p != '\t'*/) return( rc ); }/* if (tabs) { while (len-- > 0 && ((c = *p++) == ' ' || c == '\t')) if (c != '\t') ++rc; else rc += tab_size - (rc % tab_size); } else*/ while (len-- > 0 && *p++ == ' ') ++rc; if (len < 0) rc = ERROR; return( rc );}/* * Name: flush_left * Purpose: flush line on left margin * Date: November 27, 1991 * Passed: window: pointer to current window */int flush_left( TDE_WIN *window ){int len; /* length of current line */register int spaces;text_ptr source;text_ptr dest;int rcol;int lm;register TDE_WIN *win; /* put window pointer in a register */ win = window; copy_line( win->ll, win, TRUE ); lm = mode.left_margin; source = g_status.line_buff; len = g_status.line_buff_len; rcol = find_word( source, len, 0 ); if (rcol != ERROR && rcol != lm) { /* * must add spaces to get the indentation correct */ if (rcol < lm) { spaces = lm - rcol; dest = source + spaces; if (len + spaces >= MAX_LINE_LENGTH) { /* * line would be too long */ error( WARNING, win->bottom_line, ww1 ); return( ERROR ); } else { assert( len >= 0 ); assert( len < MAX_LINE_LENGTH ); memmove( dest, source, len ); g_status.line_buff_len += spaces; while (spaces--) *source++ = ' '; } /* * else delete spaces to get the indentation correct */ } else { dest = g_status.line_buff + lm; source += rcol; assert( len - rcol >= 0 ); assert( len - rcol < MAX_LINE_LENGTH ); memmove( dest, source, len - rcol ); g_status.line_buff_len -= (rcol - lm); } if (g_status.command != BlockLeftJustify) shift_block( win->file_info, win->rline, rcol, lm - rcol ); win->ll->type |= DIRTY; win->file_info->dirty = GLOBAL; show_changed_line( win ); } return( OK );}/* * Name: flush_right * Purpose: flush line on right margin * Date: November 27, 1991 * Passed: window: pointer to current window */int flush_right( TDE_WIN *window ){int len; /* length of current line */int i;int spaces;text_ptr source;text_ptr dest;register int rcol;int rm;register TDE_WIN *win; /* put window pointer in a register */ win = window; copy_line( win->ll, win, TRUE ); source = g_status.line_buff; len = g_status.line_buff_len; i = first_non_blank( source, len, 0, 0 ); if (i != len) { rm = mode.right_margin; for (rcol = len-1; /* rcol >= 0 && */ *(source+rcol) == ' '; rcol--) ; if (rcol != rm) { /* * if rcol is less than right margin then we need to add spaces. */ if (rcol < rm) { spaces = rm - rcol; dest = source + spaces; if (len + spaces >= MAX_LINE_LENGTH) { /* * line would be too long */ error( WARNING, win->bottom_line, ww1 ); return( ERROR ); } else { assert( len >= 0 ); assert( len < MAX_LINE_LENGTH ); memmove( dest, source, len ); g_status.line_buff_len += spaces; while (spaces--) *source++ = ' '; } /* * if rcol is greater than right margin then we need to sub spaces. */ } else { rcol -= rm; if (rcol > i) rcol = i; dest = source + rcol; assert( len - rcol >= 0 ); assert( len - rcol < MAX_LINE_LENGTH ); memmove( source, dest, len - rcol ); g_status.line_buff_len -= (rcol - rm); } if (g_status.command != BlockRightJustify) shift_block( win->file_info, win->rline, i, rm - rcol ); win->ll->type |= DIRTY; win->file_info->dirty = GLOBAL; show_changed_line( win ); } } return( OK );}/* * Name: flush_center * Purpose: flush line in center of margins * Date: November 27, 1991 * Passed: window: pointer to current window */int flush_center( TDE_WIN *window ){int len; /* length of current line */text_ptr source; /* temp line buffer pointers */text_ptr dest;int rm;int lm;register int spaces; /* center of text on current line */int center; /* center of current margins */int first; /* column of first char on line */int last; /* column of last char on line */register TDE_WIN *win; /* put window pointer in a register */ win = window; copy_line( win->ll, win, TRUE ); source = g_status.line_buff; len = g_status.line_buff_len; first = first_non_blank( source, len, 0, 0 ); if (first != len) { rm = mode.right_margin; lm = mode.left_margin; center = (rm + lm) / 2; for (last = len-1; /* last >= 0 && */ *(source+last) == ' '; last--) ; spaces = (last + first) / 2; if (spaces != center) { /* * if spaces is less than center margin then we need to add spaces. */ if (spaces < center) { spaces = center - spaces; dest = source + spaces; if (len + spaces >= MAX_LINE_LENGTH) { /* * line would be too long */ error( WARNING, win->bottom_line, ww1 ); return( ERROR ); } assert( len >= 0 ); assert( len < MAX_LINE_LENGTH ); memmove( dest, source, len ); memset( source, ' ', spaces ); g_status.line_buff_len += spaces; /* * if spaces is greater than center margin then we need to sub spaces. */ } else { spaces -= center; if (spaces > first) spaces = first; dest = source + spaces; assert( len - spaces >= 0 ); assert( len - spaces < MAX_LINE_LENGTH ); memmove( source, dest, len - spaces ); g_status.line_buff_len -= spaces; spaces = -spaces; } if (g_status.command != BlockCenterJustify) shift_block( win->file_info, win->rline, first, spaces ); win->ll->type |= DIRTY; win->file_info->dirty = GLOBAL; show_changed_line( win ); } } return( OK );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -