From d7164333991adeff98368a2153c6bab72fcda8df Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 24 Apr 2009 20:01:06 +0400 Subject: [PATCH] src/strutil.h: created align_crt_t type for string alignment on terminal. Changed type of related function arguments. src/strutil.c (str_fit_to_term): changed type of 3rd argument from int to align_crt_t. src/strutil8bit.c (str_8bit_fit_to_term): likewise. src/strutilascii.c (str_ascii_fit_to_term): likewise. src/strutilutf8.c (str_utf8_fit_to_term): likewise. src/screen.c: changed type of alignment variables and structure fields --- src/screen.c | 6 +++--- src/strutil.c | 2 +- src/strutil.h | 36 +++++++++++++++++------------------- src/strutil8bit.c | 2 +- src/strutilascii.c | 2 +- src/strutilutf8.c | 2 +- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/screen.c b/src/screen.c index 1c533c2b7..76ba3d07c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -70,7 +70,7 @@ typedef struct format_e { struct format_e *next; int requested_field_len; int field_len; - int just_mode; + align_crt_t just_mode; int expand; const char *(*string_fn)(file_entry *, int len); const char *title; @@ -419,7 +419,7 @@ static struct { const char *id; int min_size; int expands; - int default_just; + align_crt_t default_just; const char *title; int use_in_gui; const char *(*string_fn)(file_entry *, int); @@ -1304,7 +1304,7 @@ parse_display_format (WPanel *panel, const char *format, char **error, int issta format_e *darr, *old = 0, *home = 0; /* The formats we return */ int total_cols = 0; /* Used columns by the format */ int set_justify; /* flag: set justification mode? */ - int justify = 0; /* Which mode. */ + align_crt_t justify = J_LEFT; /* Which mode. */ int items = 0; /* Number of items in the format */ size_t i; diff --git a/src/strutil.c b/src/strutil.c index 36e594b42..cd0fd8d38 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -407,7 +407,7 @@ str_term_form (const char *text) } const char * -str_fit_to_term (const char *text, int width, int just_mode) +str_fit_to_term (const char *text, int width, align_crt_t just_mode) { return used_class.fit_to_term (text, width, just_mode); } diff --git a/src/strutil.h b/src/strutil.h index 552bbe950..1be000df7 100644 --- a/src/strutil.h +++ b/src/strutil.h @@ -52,28 +52,26 @@ typedef enum { ESTR_FAILURE = 2 } estr_t; -/* constanst originally from screen.c - * used for alignment strings on terminal +/* alignment strings on terminal */ -#define J_LEFT 0x01 -#define J_RIGHT 0x02 -#define J_CENTER 0x03 -/* - if there is enough space for string on terminal, string is centered - otherwise is aligned to left -*/ -#define J_CENTER_LEFT 0x04 +typedef enum { + J_LEFT = 0x01, + J_RIGHT = 0x02, + J_CENTER = 0x03, + /* if there is enough space for string on terminal, + * string is centered otherwise is aligned to left */ + J_CENTER_LEFT = 0x04, + /* fit alignment, if string is to long, is truncated with '~' */ + J_LEFT_FIT = 0x11, + J_RIGHT_FIT = 0x12, + J_CENTER_FIT = 0x13, + J_CENTER_LEFT_FIT = 0x14 +} align_crt_t; #define IS_FIT(x) ((x) & 0x0010) #define MAKE_FIT(x) ((x) | 0x0010) #define HIDE_FIT(x) ((x) & 0x000f) -/* fit alignment, if string is to long, is truncated with '~' */ -#define J_LEFT_FIT 0x11 -#define J_RIGHT_FIT 0x12 -#define J_CENTER_FIT 0x13 -#define J_CENTER_LEFT_FIT 0x14 - #define INVALID_CONV ((GIConv) (-1)) /* standard convertors */ @@ -85,7 +83,7 @@ extern GIConv str_cnv_not_convert; /* all functions in str_class must be defined for every encoding */ struct str_class { estr_t (*vfs_convert_to) (GIConv coder, const char *string, - int size, GString *buffer); /*I*/ + int size, GString *buffer); /*I*/ void (*insert_replace_char) (GString *buffer); int (*is_valid_string) (const char *); /*I*/ int (*is_valid_char) (const char *, size_t); /*I*/ @@ -108,7 +106,7 @@ struct str_class { int (*tolower) (const char *, char **, size_t *); void (*fix_string) (char *); /*I*/ const char *(*term_form) (const char *); /*I*/ - const char *(*fit_to_term) (const char *, int, int); /*I*/ + const char *(*fit_to_term) (const char *, int, align_crt_t); /*I*/ const char *(*term_trim) (const char *text, int width); /*I*/ void (*msg_term_size) (const char *, int *, int *); /*I*/ const char *(*term_substring) (const char *, int, int); /*I*/ @@ -366,7 +364,7 @@ const char *str_term_form (const char *text); * result is completed with spaces to width * I */ -const char *str_fit_to_term (const char *text, int width, int just_mode); +const char *str_fit_to_term (const char *text, int width, align_crt_t just_mode); /* like str_term_form, but when text is wider than width, three dots are * inserted at begin and result is completed with suffix of text diff --git a/src/strutil8bit.c b/src/strutil8bit.c index c0ae88add..0eae4cec6 100644 --- a/src/strutil8bit.c +++ b/src/strutil8bit.c @@ -208,7 +208,7 @@ str_8bit_term_form (const char *text) } static const char * -str_8bit_fit_to_term (const char *text, int width, int just_mode) +str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode) { static char result[BUF_MEDIUM]; char *actual; diff --git a/src/strutilascii.c b/src/strutilascii.c index bdd6b38fc..4b02f5306 100644 --- a/src/strutilascii.c +++ b/src/strutilascii.c @@ -201,7 +201,7 @@ str_ascii_term_form (const char *text) } static const char * -str_ascii_fit_to_term (const char *text, int width, int just_mode) +str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode) { static char result[BUF_MEDIUM]; char *actual; diff --git a/src/strutilutf8.c b/src/strutilutf8.c index 9d619701d..6a3136faf 100644 --- a/src/strutilutf8.c +++ b/src/strutilutf8.c @@ -575,7 +575,7 @@ utf8_tool_compose (char *buffer, size_t size) static const char * -str_utf8_fit_to_term (const char *text, int width, int just_mode) +str_utf8_fit_to_term (const char *text, int width, align_crt_t just_mode) { static char result[BUF_MEDIUM * 6]; const struct term_form *pre_form;