From e32922e795eb9d539acf373e23d748d779423cc5 Mon Sep 17 00:00:00 2001 From: faissaloo Date: Fri, 26 Aug 2016 18:46:30 +0100 Subject: [PATCH 11/20] Code formatting --- src/utils.c | 6 ++--- src/winio.c | 90 ++++++++++++++++++++++++++++--------------------------------- 2 files changed, 44 insertions(+), 52 deletions(-) diff --git a/src/utils.c b/src/utils.c index a32a2b0..dd21bbe 100644 --- a/src/utils.c +++ b/src/utils.c @@ -439,12 +439,12 @@ char *free_and_assign(char *dest, char *src) * get_page_start(column) < COLS). */ size_t get_page_start(size_t column) { - if (column == 0 || column < COLS - 1-margin) + if (column == 0 || column < COLS - 1 - margin) return 0; else if (COLS > 8) - return column - 7 - (column - 7) % (COLS - 8-margin); + return column - 7 - (column - 7) % (COLS - 8 - margin); else - return column - (COLS - 2-margin); + return column - (COLS - 2 - margin); } /* Return the placewewant associated with current_x, i.e. the zero-based diff --git a/src/winio.c b/src/winio.c index f40d292..9adc7d6 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1439,7 +1439,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts) return -1; /* Save the screen coordinates where the mouse event took place. */ - *mouse_x = mevent.x-margin; + *mouse_x = mevent.x - margin; *mouse_y = mevent.y; in_bottomwin = wenclose(bottomwin, *mouse_y, *mouse_x); @@ -1470,7 +1470,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts) if (*mouse_y == 0) { /* Restore the untranslated mouse event coordinates, so * that they're relative to the entire screen again. */ - *mouse_x = mevent.x-margin; + *mouse_x = mevent.x - margin; *mouse_y = mevent.y; return 0; @@ -1817,7 +1817,7 @@ char *display_string(const char *buf, size_t start_col, size_t span, converted[index] = '\0'; /* Make sure converted takes up no more than span columns. */ - index = actual_x(converted, span-margin-1); + index = actual_x(converted, span - margin - 1); null_at(&converted, index); return converted; @@ -2138,13 +2138,13 @@ void reset_cursor(void) openfile->current_y = 0; while (line != NULL && line != openfile->current) { - openfile->current_y += (strlenpt(line->data)) / (COLS-margin) + 1; + openfile->current_y += (strlenpt(line->data)) / (COLS - margin) + 1; line = line->next; } - openfile->current_y += xpt / (COLS-margin); + openfile->current_y += xpt / (COLS - margin); if (openfile->current_y < editwinrows) - wmove(edit, openfile->current_y, (xpt % (COLS-margin))+margin); + wmove(edit, openfile->current_y, (xpt % (COLS - margin)) + margin); } else #endif { @@ -2158,23 +2158,20 @@ void reset_cursor(void) int intlen(int n) { - if (n < 100000) - { + if (n < 100000) { // 5 or less - if (n < 100){ + if (n < 100) { // 1 or 2 if (n < 10) return 1; else return 2; } - else - { + else { // 3 or 4 or 5 if (n < 1000) return 3; - else - { + else { // 4 or 5 if (n < 10000) return 4; @@ -2186,21 +2183,18 @@ int intlen(int n) else { // 6 or more - if (n < 10000000) - { + if (n < 10000000) { // 6 or 7 if (n < 1000000) return 6; else return 7; } - else - { + else { // 8 to 10 if (n < 100000000) return 8; - else - { + else { // 9 or 10 if (n < 1000000000) return 9; @@ -2214,8 +2208,7 @@ int intlen(int n) int hexlen(int n) { int len=0; - while (n!=0) - { + while (n!=0) { n>>=4; //One hex digit = one nibble len++; } @@ -2233,29 +2226,28 @@ void edit_draw(filestruct *fileptr, const char *converted, int line, size_t start) { #ifndef DISABLE_LINE_NUM - if (ISSET(LINE_NUM)) - { - if (margin!=intlen(openfile->filebot->lineno)+3) - { + if (ISSET(LINE_NUM)) { + if (margin != intlen(openfile->filebot->lineno) + 3) { refresh_needed = TRUE; - margin = intlen(openfile->filebot->lineno)+3; + margin = intlen(openfile->filebot->lineno) + 3; } - wattron(edit,A_BOLD); - mvwprintw(edit,line,margin-(intlen(((long)openfile->edittop->lineno)+line)+2),"%i│",((long)openfile->edittop->lineno)+line); - wattroff(edit,A_BOLD); - } - else if (ISSET(HEX_LINE_NUM)) - { - if (margin!=hexlen(openfile->filebot->lineno)+3) - { + wattron(edit, A_BOLD); + mvwprintw(edit, line, + margin - (intlen(((long)openfile->edittop->lineno) + line) + 2), + "%i│", ((long)openfile->edittop->lineno) + line); + wattroff(edit, A_BOLD); + } else if (ISSET(HEX_LINE_NUM)) { + if (margin != hexlen(openfile->filebot->lineno) + 3) { refresh_needed = TRUE; - margin = hexlen(openfile->filebot->lineno)+3; + margin = hexlen(openfile->filebot->lineno) + 3; } - wattron(edit,A_BOLD); - mvwprintw(edit,line,margin-(hexlen(((long)openfile->edittop->lineno)+line)+2),"%X│",((long)openfile->edittop->lineno)+line); - wattroff(edit,A_BOLD); + wattron(edit, A_BOLD); + mvwprintw(edit, line, + margin - (hexlen(((long)openfile->edittop->lineno) + line) + 2), + "%X│", ((long)openfile->edittop->lineno) + line); + wattroff(edit, A_BOLD); } #endif #if !defined(NANO_TINY) || !defined(DISABLE_COLOR) @@ -2353,7 +2345,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int assert(0 <= x_start && 0 <= paintlen); - mvwaddnstr(edit, line, x_start+margin, converted + + mvwaddnstr(edit, line, x_start + margin, converted + index, paintlen); } k = startmatch.rm_eo; @@ -2523,7 +2515,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int assert(0 <= x_start && x_start < COLS); - mvwaddnstr(edit, line, x_start+margin, + mvwaddnstr(edit, line, x_start + margin, converted + index, paintlen); if (paintlen > 0) { fileptr->multidata[varnish->id] = CSTARTENDHERE; @@ -2553,7 +2545,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int assert(0 <= x_start && x_start < COLS); /* Paint the rest of the line. */ - mvwaddnstr(edit, line, x_start+margin, converted + index, -1); + mvwaddnstr(edit, line, x_start + margin, converted + index, -1); fileptr->multidata[varnish->id] = CENDAFTER; #ifdef DEBUG fprintf(stderr, " Marking for id %i line %i as CENDAFTER\n", varnish->id, line); @@ -2628,10 +2620,10 @@ void edit_draw(filestruct *fileptr, const char *converted, int index = actual_x(converted, x_start); if (paintlen > 0) - paintlen = actual_x(converted + index+margin, paintlen); + paintlen = actual_x(converted + index + margin, paintlen); wattron(edit, hilite_attribute); - mvwaddnstr(edit, line, x_start+margin, converted + index, paintlen); + mvwaddnstr(edit, line, x_start + margin, converted + index, paintlen); wattroff(edit, hilite_attribute); } } @@ -2659,7 +2651,7 @@ int update_line(filestruct *fileptr, size_t index) filestruct *tmp; for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next) - line += ((strlenpt(tmp->data)+margin) / COLS) + 1; + line += ((strlenpt(tmp->data) + margin) / COLS) + 1; } else #endif line = fileptr->lineno - openfile->edittop->lineno; @@ -2701,12 +2693,12 @@ int update_line(filestruct *fileptr, size_t index) #endif if (page_start > 0) mvwaddch(edit, line, margin-1, '$'); - if (strlenpt(fileptr->data) > page_start + COLS-margin-1) + if (strlenpt(fileptr->data) > page_start + COLS - margin - 1) mvwaddch(edit, line, COLS-1, '$'); #ifndef NANO_TINY } else { size_t full_length = strlenpt(fileptr->data); - for (index += COLS-margin; index <= full_length && line < editwinrows - 1; index += COLS-margin) { + for (index += COLS - margin; index <= full_length && line < editwinrows - 1; index += COLS-margin) { line++; #ifdef DEBUG fprintf(stderr, "update_line(): softwrap code, moving to %d index %lu\n", line, (unsigned long)index); @@ -2758,7 +2750,7 @@ void compute_maxrows(void) maxrows = 0; for (n = 0; n < editwinrows && foo; n++) { maxrows++; - n += (strlenpt(foo->data)+margin) / COLS; + n += (strlenpt(foo->data) + margin) / COLS; foo = foo->next; } @@ -2803,7 +2795,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines) #ifndef NANO_TINY /* Don't over-scroll on long lines. */ if (ISSET(SOFTWRAP) && direction == UPWARD) { - ssize_t len = (strlenpt(openfile->edittop->data)+margin) / COLS; + ssize_t len = (strlenpt(openfile->edittop->data) + margin) / COLS; i -= len; if (len > 0) refresh_needed = TRUE; @@ -2992,7 +2984,7 @@ void edit_update(update_type manner) goal --; #ifndef NANO_TINY if (ISSET(SOFTWRAP)) - goal -= (strlenpt(openfile->edittop->data)+margin) / COLS; + goal -= (strlenpt(openfile->edittop->data) + margin) / COLS; #endif } #ifdef DEBUG -- 2.7.4