From 6c7bd414287c7ebdbfa4a6f38615b5b72562b595 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 30 May 2001 17:18:28 +0000 Subject: [PATCH] * editdraw.c (status_string): Use is_printable(). Declare static. Eliminate intermediate buffer. Use memset() for filling. Print byte as unsigned. Use C notation for hex numbers. --- gtkedit/ChangeLog | 4 ++++ gtkedit/editdraw.c | 58 +++++++++++++++++++++------------------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/gtkedit/ChangeLog b/gtkedit/ChangeLog index 5703d5b14..a5afaea72 100644 --- a/gtkedit/ChangeLog +++ b/gtkedit/ChangeLog @@ -1,5 +1,9 @@ 2001-05-30 Pavel Roskin + * editdraw.c (status_string): Use is_printable(). Declare + static. Eliminate intermediate buffer. Use memset() for filling. + Print byte as unsigned. Use C notation for hex numbers. + * editdraw.c (status_string): Don't print non-printable chars. Better formatting. Print "" at the end of file instead of -1. Use snprintf instead of sprintf. diff --git a/gtkedit/editdraw.c b/gtkedit/editdraw.c index 800d44abb..1c6595829 100644 --- a/gtkedit/editdraw.c +++ b/gtkedit/editdraw.c @@ -35,12 +35,11 @@ extern int column_highlighting; #if defined (MIDNIGHT) || defined (GTK) -void status_string (WEdit * edit, char *s, int w, int fill, int font_width) +static void status_string (WEdit * edit, char *s, int w, int fill, int font_width) { #ifdef MIDNIGHT int i; #endif - char t[160]; /* 160 just to be sure */ char byte_str[16]; /* @@ -49,9 +48,9 @@ void status_string (WEdit * edit, char *s, int w, int fill, int font_width) * as decimal and as hex. */ if (edit->curs1 < edit->last_byte) { - char cur_byte = edit_get_byte (edit, edit->curs1); - snprintf(byte_str, sizeof(byte_str), "%c %3d %2xH", - isprint(cur_byte) ? cur_byte : '.', + unsigned char cur_byte = edit_get_byte (edit, edit->curs1); + snprintf(byte_str, sizeof(byte_str), "%c %3d 0x%02X", + is_printable(cur_byte) ? cur_byte : '.', cur_byte, cur_byte); } else { @@ -59,36 +58,31 @@ void status_string (WEdit * edit, char *s, int w, int fill, int font_width) } /* The field lengths just prevent the status line from shortening to much */ - snprintf (t, sizeof(t), - "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s", - edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-', - edit->modified ? 'M' : '-', - edit->macro_i < 0 ? '-' : 'R', - edit->overwrite == 0 ? '-' : 'O', - edit->curs_col / font_width, - - edit->start_line + 1, - edit->curs_row, - edit->curs_line + 1, - edit->total_lines + 1, - - edit->curs1, - edit->last_byte, - byte_str); + snprintf (s, w, + "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s", + edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-', + edit->modified ? 'M' : '-', + edit->macro_i < 0 ? '-' : 'R', + edit->overwrite == 0 ? '-' : 'O', + edit->curs_col / font_width, + + edit->start_line + 1, + edit->curs_row, + edit->curs_line + 1, + edit->total_lines + 1, + + edit->curs1, + edit->last_byte, + byte_str); + #ifdef MIDNIGHT - sprintf (s, "%.*s", w + 1, t); + /* + * Make string exactly w chars wide + * Fill the remainder with the fill char + */ i = strlen (s); - s[i] = ' '; - i = w; - do { - if (strchr ("+-*=/:b", s[i])) /* chop off the last word/number */ - break; - s[i] = fill; - } while (i--); - s[i] = fill; + memset (s + i, fill, w - i); s[w] = 0; -#else - strcpy (s, t); #endif }