summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--list.c19
-rw-r--r--smenu.c15
-rw-r--r--utf8.c25
-rw-r--r--utils.c70
4 files changed, 62 insertions, 67 deletions
diff --git a/list.c b/list.c
index e561f8f..baa51ca 100644
--- a/list.c
+++ b/list.c
@@ -28,7 +28,7 @@ ll_partition(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *),
static void
ll_quicksort(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *),
- void (*swap)(void * a, void *));
+ void (*swap)(void *, void *));
/* ========================== */
/* Creates a new linked list. */
@@ -59,9 +59,7 @@ ll_init(ll_t * list)
ll_node_t *
ll_new_node(void)
{
- ll_node_t * ret = xmalloc(sizeof(ll_node_t));
-
- return ret;
+ return xmalloc(sizeof(ll_node_t));
}
/* ====================================================================== */
@@ -224,7 +222,7 @@ ll_partition(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *),
/* ======================================================== */
static void
ll_quicksort(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *),
- void (*swap)(void * a, void *))
+ void (*swap)(void *, void *))
{
if (h != NULL && l != h && l != h->next)
{
@@ -238,8 +236,7 @@ ll_quicksort(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *),
/* A linked list sort function. */
/* ============================ */
void
-ll_sort(ll_t * list, int (*comp)(void *, void *),
- void (*swap)(void * a, void *))
+ll_sort(ll_t * list, int (*comp)(void *, void *), void (*swap)(void *, void *))
{
/* Call the recursive ll_quicksort function. */
/* """"""""""""""""""""""""""""""""""""""""" */
@@ -254,10 +251,10 @@ ll_delete(ll_t * const list, ll_node_t * node)
{
if (list->head == list->tail)
{
- if (list->head != NULL)
- list->head = list->tail = NULL;
- else
+ if (list->head == NULL)
return 0;
+
+ list->head = list->tail = NULL;
}
else if (node->prev == NULL)
{
@@ -289,7 +286,7 @@ ll_delete(ll_t * const list, ll_node_t * node)
/* ==========================================================================*/
ll_node_t *
ll_find(ll_t * const list, void * const data,
- int (*cmpfunc)(const void * a, const void * b))
+ int (*cmpfunc)(const void *, const void *))
{
ll_node_t * node;
diff --git a/smenu.c b/smenu.c
index c4d6fe8..e908ab7 100644
--- a/smenu.c
+++ b/smenu.c
@@ -206,15 +206,16 @@ help(win_t * win, term_t * term, long last_line)
(void)tputs(TPARM1(save_cursor), 1, outch);
/* Center the help line if the -M (Middle) option is set. */
+ /* May update the variable offset as a side effect. */
/* """""""""""""""""""""""""""""""""""""""""""""""""""""" */
- if (win->offset > 0)
- if ((offset = win->offset + win->max_width / 2 - help_len / 2) > 0)
- {
- int i;
+ if (win->offset > 0
+ && ((offset = win->offset + win->max_width / 2 - help_len / 2) > 0))
+ {
+ int i;
- for (i = 0; i < offset; i++)
- fputc_safe(' ', stdout);
- }
+ for (i = 0; i < offset; i++)
+ fputc_safe(' ', stdout);
+ }
/* Print the different objects forming the help line. */
/* A new line is added each time the next entry does not fit in the */
diff --git a/utf8.c b/utf8.c
index 8e7dfec..24fa7f7 100644
--- a/utf8.c
+++ b/utf8.c
@@ -228,11 +228,11 @@ utf8_interpret(char * s, langinfo_t * langinfo, char substitute)
else
good = 0;
- if (!good)
+ if (good)
+ *(tmp + i) = byte;
+ else
utf8_ascii_len = 2 * i; /* Force the new length according to the *
| number of valid UTF-8 bytes read. */
- else
- *(tmp + i) = byte;
}
tmp[utf8_ascii_len / 2] = '\0';
@@ -298,8 +298,8 @@ utf8_get_length(unsigned char c)
return 2;
else if (c < 0xf0)
return 3;
- else
- return 4;
+
+ return 4;
}
/* ==================================================== */
@@ -351,7 +351,8 @@ utf8_next(char * p)
for (++p; (*p & 0xc0) == 0x80; ++p)
;
}
- return (*p == '\0' ? NULL : p);
+
+ return *p == '\0' ? NULL : p;
}
/* ============================================================= */
@@ -415,8 +416,8 @@ utf8_validate(char * s)
/* 110XXXXx 10xxxxxx */
if ((us[1] & 0xc0) != 0x80 || (us[0] & 0xfe) == 0xc0) /* overlong? */
return (char *)us;
- else
- us += 2;
+
+ us += 2;
}
else if ((us[0] & 0xf0) == 0xe0)
{
@@ -428,8 +429,8 @@ utf8_validate(char * s)
(us[0] == 0xef && us[1] == 0xbf &&
(us[2] & 0xfe) == 0xbe)) /* U+FFFE or U+FFFF? */
return (char *)us;
- else
- us += 3;
+
+ us += 3;
}
else if ((us[0] & 0xf8) == 0xf0)
{
@@ -440,8 +441,8 @@ utf8_validate(char * s)
(us[0] == 0xf0 && (us[1] & 0xf0) == 0x80) || /* overlong? */
(us[0] == 0xf4 && us[1] > 0x8f) || us[0] > 0xf4) /* > U+10FFFF? */
return (char *)us;
- else
- us += 4;
+
+ us += 4;
}
else
return (char *)us;
diff --git a/utils.c b/utils.c
index 5b384c4..4744a03 100644
--- a/utils.c
+++ b/utils.c
@@ -28,9 +28,7 @@
interval_t *
interval_new(void)
{
- interval_t * ret = xmalloc(sizeof(interval_t));
-
- return ret;
+ return xmalloc(sizeof(interval_t));
}
/* ======================================= */
@@ -94,39 +92,37 @@ merge_intervals(ll_t * list)
if (!list || list->len < 2)
return;
- else
- {
- /* Step 1: sort the intervals list. */
- /* """""""""""""""""""""""""""""""" */
- ll_sort(list, interval_comp, interval_swap);
- /* Step 2: merge the list by merging the consecutive intervals. */
- /* """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
- node1 = list->head;
- node2 = node1->next;
+ /* Step 1: sort the intervals list. */
+ /* """""""""""""""""""""""""""""""" */
+ ll_sort(list, interval_comp, interval_swap);
+
+ /* Step 2: merge the list by merging the consecutive intervals. */
+ /* """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
+ node1 = list->head;
+ node2 = node1->next;
- while (node2)
+ while (node2)
+ {
+ data1 = (interval_t *)(node1->data);
+ data2 = (interval_t *)(node2->data);
+
+ if (data1->high >= data2->low - 1)
{
- data1 = (interval_t *)(node1->data);
- data2 = (interval_t *)(node2->data);
-
- if (data1->high >= data2->low - 1)
- {
- /* Interval 1 overlaps interval 2. */
- /* ''''''''''''''''''''''''''''''' */
- if (data2->high >= data1->high)
- data1->high = data2->high;
- ll_delete(list, node2);
- free(data2);
- node2 = node1->next;
- }
- else
- {
- /* No overlap. */
- /* ''''''''''' */
- node1 = node2;
- node2 = node2->next;
- }
+ /* Interval 1 overlaps interval 2. */
+ /* ''''''''''''''''''''''''''''''' */
+ if (data2->high >= data1->high)
+ data1->high = data2->high;
+ ll_delete(list, node2);
+ free(data2);
+ node2 = node1->next;
+ }
+ else
+ {
+ /* No overlap. */
+ /* ''''''''''' */
+ node1 = node2;
+ node2 = node2->next;
}
}
}
@@ -280,7 +276,7 @@ my_strcpy(char * str1, char * str2)
int
isprint7(int i)
{
- return (i >= 0x20 && i <= 0x7e);
+ return i >= 0x20 && i <= 0x7e;
}
/* ================================ */
@@ -313,7 +309,7 @@ my_wcscasecmp(const wchar_t * s1, const wchar_t * s2)
s1++;
s2++;
}
- return (-*s2);
+ return -*s2;
}
/* ==================================================================== */
@@ -331,6 +327,6 @@ is_integer(const char * const s)
if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX)
return 1;
- else
- return 0;
+
+ return 0;
}