Fix braces in if-else statements

From the Linux kernel coding guidelines:

    Do not unnecessarily use braces where a single statement will do.
    [...] This does not apply if one branch of a conditional statement
    is a single statement. Use braces in both branches.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2013-02-17 09:01:46 +01:00
parent 8e16853201
commit a363cb9b91
20 changed files with 172 additions and 132 deletions

View File

@ -117,16 +117,16 @@ void apoint_sec2str(struct apoint *o, long day, char *start, char *end)
struct tm lt; struct tm lt;
time_t t; time_t t;
if (o->start < day) if (o->start < day) {
strncpy(start, "..:..", 6); strncpy(start, "..:..", 6);
else { } else {
t = o->start; t = o->start;
localtime_r(&t, &lt); localtime_r(&t, &lt);
snprintf(start, HRMIN_SIZE, "%02u:%02u", lt.tm_hour, lt.tm_min); snprintf(start, HRMIN_SIZE, "%02u:%02u", lt.tm_hour, lt.tm_min);
} }
if (o->start + o->dur > day + DAYINSEC) if (o->start + o->dur > day + DAYINSEC) {
strncpy(end, "..:..", 6); strncpy(end, "..:..", 6);
else { } else {
t = o->start + o->dur; t = o->start + o->dur;
localtime_r(&t, &lt); localtime_r(&t, &lt);
snprintf(end, HRMIN_SIZE, "%02u:%02u", lt.tm_hour, lt.tm_min); snprintf(end, HRMIN_SIZE, "%02u:%02u", lt.tm_hour, lt.tm_min);

View File

@ -561,8 +561,9 @@ int parse_args(int argc, char **argv)
usage_try(); usage_try();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} else } else {
tnum = -1; tnum = -1;
}
break; break;
case 'v': case 'v':
vflag = 1; vflag = 1;
@ -572,11 +573,11 @@ int parse_args(int argc, char **argv)
multiple_flag++; multiple_flag++;
load_data++; load_data++;
if (optarg != NULL) { if (optarg != NULL) {
if (strcmp(optarg, "ical") == 0) if (strcmp(optarg, "ical") == 0) {
xfmt = IO_EXPORT_ICAL; xfmt = IO_EXPORT_ICAL;
else if (strcmp(optarg, "pcal") == 0) } else if (strcmp(optarg, "pcal") == 0) {
xfmt = IO_EXPORT_PCAL; xfmt = IO_EXPORT_PCAL;
else { } else {
fputs(_("Argument for '-x' should be either " fputs(_("Argument for '-x' should be either "
"'ical' or 'pcal'\n"), stderr); "'ical' or 'pcal'\n"), stderr);
usage(); usage();

View File

@ -256,8 +256,9 @@ static inline void key_edit_note(void)
if (wins_slctd() == APP && ui_day_hilt() != 0) { if (wins_slctd() == APP && ui_day_hilt() != 0) {
day_edit_note(day_get_item(ui_day_hilt()), conf.editor); day_edit_note(day_get_item(ui_day_hilt()), conf.editor);
inday = do_storage(0); inday = do_storage(0);
} else if (wins_slctd() == TOD && ui_todo_hilt() != 0) } else if (wins_slctd() == TOD && ui_todo_hilt() != 0) {
todo_edit_note(todo_get_item(ui_todo_hilt()), conf.editor); todo_edit_note(todo_get_item(ui_todo_hilt()), conf.editor);
}
wins_update(FLAG_ALL); wins_update(FLAG_ALL);
} }
@ -465,14 +466,15 @@ static inline void key_generic_quit(void)
note_gc(); note_gc();
if (conf.confirm_quit) { if (conf.confirm_quit) {
if (status_ask_bool(_("Do you really want to quit ?")) == 1) if (status_ask_bool(_("Do you really want to quit ?")) == 1) {
exit_calcurse(EXIT_SUCCESS); exit_calcurse(EXIT_SUCCESS);
else { } else {
wins_erase_status_bar(); wins_erase_status_bar();
wins_update(FLAG_STA); wins_update(FLAG_STA);
} }
} else } else {
exit_calcurse(EXIT_SUCCESS); exit_calcurse(EXIT_SUCCESS);
}
} }
/* /*

View File

@ -275,8 +275,9 @@ static int config_parse_input_datefmt(void *dummy, const char *val)
if (conf.input_datefmt <= 0 || conf.input_datefmt > DATE_FORMATS) if (conf.input_datefmt <= 0 || conf.input_datefmt > DATE_FORMATS)
conf.input_datefmt = 1; conf.input_datefmt = 1;
return 1; return 1;
} else } else {
return 0; return 0;
}
} }
/* Set a configuration variable. */ /* Set a configuration variable. */
@ -359,16 +360,16 @@ static void config_color_theme_name(char *theme_name)
"white" "white"
}; };
if (!colorize) if (!colorize) {
strncpy(theme_name, "none", BUFSIZ); strncpy(theme_name, "none", BUFSIZ);
else { } else {
pair_content(COLR_CUSTOM, &color[0], &color[1]); pair_content(COLR_CUSTOM, &color[0], &color[1]);
for (i = 0; i < NBCOLORS; i++) { for (i = 0; i < NBCOLORS; i++) {
if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT)) if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT)) {
color_name[i] = default_color; color_name[i] = default_color;
else if (color[i] >= 0 && color[i] <= MAXCOLORS) } else if (color[i] >= 0 && color[i] <= MAXCOLORS) {
color_name[i] = name[color[i]]; color_name[i] = name[color[i]];
else { } else {
EXIT(_("unknown color")); EXIT(_("unknown color"));
/* NOTREACHED */ /* NOTREACHED */
} }
@ -453,10 +454,11 @@ config_serialize_conf(char *buf, const char *key,
if (status) if (status)
status->done[i] = 1; status->done[i] = 1;
return 1; return 1;
} else } else {
return 0; return 0;
} }
} }
}
return -1; return -1;
} }
@ -489,8 +491,7 @@ config_file_walk(config_fn_walk_cb_t fn_cb,
if (value) { if (value) {
*value = '\0'; *value = '\0';
value++; value++;
} } else {
else {
EXIT(_("invalid configuration directive: \"%s\""), e_conf); EXIT(_("invalid configuration directive: \"%s\""), e_conf);
} }
@ -538,12 +539,13 @@ static int config_load_cb(const char *key, const char *value, void *dummy)
{ {
int result = config_set_conf(key, value); int result = config_set_conf(key, value);
if (result < 0) if (result < 0) {
EXIT(_("configuration variable unknown: \"%s\""), key); EXIT(_("configuration variable unknown: \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
else if (result == 0) } else if (result == 0) {
EXIT(_("wrong configuration variable format for \"%s\""), key); EXIT(_("wrong configuration variable format for \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
}
return 1; return 1;
} }
@ -560,12 +562,13 @@ static int config_save_cb(const char *key, const char *value, void *status)
int result = int result =
config_serialize_conf(buf, key, (struct config_save_status *)status); config_serialize_conf(buf, key, (struct config_save_status *)status);
if (result < 0) if (result < 0) {
EXIT(_("configuration variable unknown: \"%s\""), key); EXIT(_("configuration variable unknown: \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
else if (result == 0) } else if (result == 0) {
EXIT(_("wrong configuration variable format for \"%s\""), key); EXIT(_("wrong configuration variable format for \"%s\""), key);
/* NOTREACHED */ /* NOTREACHED */
}
fputs(key, ((struct config_save_status *)status)->fp); fputs(key, ((struct config_save_status *)status)->fp);
fputc('=', ((struct config_save_status *)status)->fp); fputc('=', ((struct config_save_status *)status)->fp);

View File

@ -455,21 +455,23 @@ display_color_config(struct window *cwin, int *mark_fore, int *mark_back,
/* Retrieve the actual color theme. */ /* Retrieve the actual color theme. */
pair_content(COLR_CUSTOM, &colr_fore, &colr_back); pair_content(COLR_CUSTOM, &colr_fore, &colr_back);
if ((colr_fore == DEFAULTCOLOR) || (colr_fore == DEFAULTCOLOR_EXT)) if ((colr_fore == DEFAULTCOLOR) || (colr_fore == DEFAULTCOLOR_EXT)) {
*mark_fore = NBUSERCOLORS; *mark_fore = NBUSERCOLORS;
else } else {
for (i = 0; i < NBUSERCOLORS + 1; i++) for (i = 0; i < NBUSERCOLORS + 1; i++)
if (colr_fore == colr[i]) if (colr_fore == colr[i])
*mark_fore = i; *mark_fore = i;
}
if ((colr_back == DEFAULTCOLOR) || (colr_back == DEFAULTCOLOR_EXT)) if ((colr_back == DEFAULTCOLOR) || (colr_back == DEFAULTCOLOR_EXT)) {
*mark_back = SIZE - 1; *mark_back = SIZE - 1;
else } else {
for (i = 0; i < NBUSERCOLORS + 1; i++) for (i = 0; i < NBUSERCOLORS + 1; i++)
if (colr_back == colr[NBUSERCOLORS + 1 + i]) if (colr_back == colr[NBUSERCOLORS + 1 + i])
*mark_back = NBUSERCOLORS + 1 + i; *mark_back = NBUSERCOLORS + 1 + i;
} }
} }
}
/* color boxes */ /* color boxes */
for (i = 0; i < SIZE - 1; i++) { for (i = 0; i < SIZE - 1; i++) {
@ -976,8 +978,9 @@ void custom_keys_config(void)
LINESPERKEY); LINESPERKEY);
wins_scrollwin_display(&kwin); wins_scrollwin_display(&kwin);
continue; continue;
} else } else {
not_recognized = 0; not_recognized = 0;
}
/* Is the binding used by this action already? If so, just end the reassignment */ /* Is the binding used by this action already? If so, just end the reassignment */
if (selrow == keys_get_action(keyval)) { if (selrow == keys_get_action(keyval)) {
@ -1041,9 +1044,9 @@ void custom_config_main(void)
switch (ch) { switch (ch) {
case 'C': case 'C':
case 'c': case 'c':
if (has_colors()) if (has_colors()) {
custom_color_config(); custom_color_config();
else { } else {
colorize = 0; colorize = 0;
wins_erase_status_bar(); wins_erase_status_bar();
mvwaddstr(win[STA].p, 0, 0, no_color_support); mvwaddstr(win[STA].p, 0, 0, no_color_support);

View File

@ -72,10 +72,11 @@ static int day_cmp_start(struct day_item *a, struct day_item *b)
return 0; return 0;
else else
return -1; return -1;
} else if (b->type <= EVNT) } else if (b->type <= EVNT) {
return 1; return 1;
else } else {
return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1); return a->start < b->start ? -1 : (a->start == b->start ? 0 : 1);
}
} }
/* Add an item to the current day list. */ /* Add an item to the current day list. */
@ -446,9 +447,9 @@ display_item(struct day_item *day, int incolor, int width, int y, int x)
ch_note = day_item_get_note(day) ? '>' : ' '; ch_note = day_item_get_note(day) ? '>' : ' ';
if (incolor == 0) if (incolor == 0)
custom_apply_attr(win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
if (utf8_strwidth(mesg) < width) if (utf8_strwidth(mesg) < width) {
mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, mesg); mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, mesg);
else { } else {
for (i = 0; mesg[i] && width > 0; i++) { for (i = 0; mesg[i] && width > 0; i++) {
if (!UTF8_ISCONT(mesg[i])) if (!UTF8_ISCONT(mesg[i]))
width -= utf8_width(&mesg[i]); width -= utf8_width(&mesg[i]);

View File

@ -193,8 +193,9 @@ enum getstr getstring(WINDOW * win, char *str, int l, int x, int y)
if (st.pos > 0) { if (st.pos > 0) {
st.pos--; st.pos--;
getstr_del_char(&st); getstr_del_char(&st);
} else } else {
bell(); bell();
}
break; break;
case CTRL('D'): /* delete next character */ case CTRL('D'): /* delete next character */
if (st.pos < st.len) if (st.pos < st.len)
@ -212,8 +213,9 @@ enum getstr getstring(WINDOW * win, char *str, int l, int x, int y)
st.pos--; st.pos--;
getstr_del_char(&st); getstr_del_char(&st);
} }
} else } else {
bell(); bell();
}
break; break;
case CTRL('K'): /* delete to end-of-line */ case CTRL('K'): /* delete to end-of-line */
st.s[st.ci[st.pos].offset] = 0; st.s[st.ci[st.pos].offset] = 0;

View File

@ -114,8 +114,9 @@ static void ical_export_recur_events(FILE * stream)
if (rev->rpt->until != 0) { if (rev->rpt->until != 0) {
date_sec2date_fmt(rev->rpt->until, ICALDATEFMT, ical_date); date_sec2date_fmt(rev->rpt->until, ICALDATEFMT, ical_date);
fprintf(stream, ";UNTIL=%s\n", ical_date); fprintf(stream, ";UNTIL=%s\n", ical_date);
} else } else {
fputc('\n', stream); fputc('\n', stream);
}
if (LLIST_FIRST(&rev->exc)) { if (LLIST_FIRST(&rev->exc)) {
fputs("EXDATE:", stream); fputs("EXDATE:", stream);
@ -172,8 +173,9 @@ static void ical_export_recur_apoints(FILE * stream)
if (rapt->rpt->until != 0) { if (rapt->rpt->until != 0) {
date_sec2date_fmt(rapt->rpt->until + HOURINSEC, ICALDATEFMT, ical_date); date_sec2date_fmt(rapt->rpt->until + HOURINSEC, ICALDATEFMT, ical_date);
fprintf(stream, ";UNTIL=%s\n", ical_date); fprintf(stream, ";UNTIL=%s\n", ical_date);
} else } else {
fputc('\n', stream); fputc('\n', stream);
}
if (LLIST_FIRST(&rapt->exc)) { if (LLIST_FIRST(&rapt->exc)) {
fputs("EXDATE:", stream); fputs("EXDATE:", stream);
@ -481,9 +483,9 @@ static long ical_durtime2long(char *timestr)
long timelong; long timelong;
char *p; char *p;
if ((p = strchr(timestr, 'T')) == NULL) if ((p = strchr(timestr, 'T')) == NULL) {
timelong = 0; timelong = 0;
else { } else {
int nbmatch; int nbmatch;
struct { struct {
unsigned hour, min, sec; unsigned hour, min, sec;
@ -535,18 +537,18 @@ static long ical_dur2long(char *durstr)
} date; } date;
memset(&date, 0, sizeof date); memset(&date, 0, sizeof date);
if ((p = strchr(durstr, 'P')) == NULL) if ((p = strchr(durstr, 'P')) == NULL) {
durlong = NOTFOUND; durlong = NOTFOUND;
else { } else {
p++; p++;
if (*p == '-') if (*p == '-')
return NOTFOUND; return NOTFOUND;
else if (*p == '+') else if (*p == '+')
p++; p++;
if (*p == 'T') /* dur-time */ if (*p == 'T') { /* dur-time */
durlong = ical_durtime2long(p); durlong = ical_durtime2long(p);
else if (strchr(p, 'W')) { /* dur-week */ } else if (strchr(p, 'W')) { /* dur-week */
if (sscanf(p, "%u", &date.week) == 1) if (sscanf(p, "%u", &date.week) == 1)
durlong = date.week * WEEKINDAYS * DAYINSEC; durlong = date.week * WEEKINDAYS * DAYINSEC;
else else
@ -556,12 +558,14 @@ static long ical_dur2long(char *durstr)
if (sscanf(p, "%uD", &date.day) == 1) { if (sscanf(p, "%uD", &date.day) == 1) {
durlong = date.day * DAYINSEC; durlong = date.day * DAYINSEC;
durlong += ical_durtime2long(p); durlong += ical_durtime2long(p);
} else } else {
durlong = NOTFOUND; durlong = NOTFOUND;
} else }
} else {
durlong = NOTFOUND; durlong = NOTFOUND;
} }
} }
}
return durlong; return durlong;
} }
@ -663,15 +667,15 @@ static ical_rpt_t *ical_read_rrule(FILE * log, char *rrulestr,
mem_free(rpt); mem_free(rpt);
return NULL; return NULL;
} else { } else {
if (strncmp(freqstr, daily, sizeof(daily) - 1) == 0) if (strncmp(freqstr, daily, sizeof(daily) - 1) == 0) {
rpt->type = RECUR_DAILY; rpt->type = RECUR_DAILY;
else if (strncmp(freqstr, weekly, sizeof(weekly) - 1) == 0) } else if (strncmp(freqstr, weekly, sizeof(weekly) - 1) == 0) {
rpt->type = RECUR_WEEKLY; rpt->type = RECUR_WEEKLY;
else if (strncmp(freqstr, monthly, sizeof(monthly) - 1) == 0) } else if (strncmp(freqstr, monthly, sizeof(monthly) - 1) == 0) {
rpt->type = RECUR_MONTHLY; rpt->type = RECUR_MONTHLY;
else if (strncmp(freqstr, yearly, sizeof(yearly) - 1) == 0) } else if (strncmp(freqstr, yearly, sizeof(yearly) - 1) == 0) {
rpt->type = RECUR_YEARLY; rpt->type = RECUR_YEARLY;
else { } else {
ical_log(log, ICAL_VEVENT, itemline, ical_log(log, ICAL_VEVENT, itemline,
_("recurrence frequence not recognized.")); _("recurrence frequence not recognized."));
(*noskipped)++; (*noskipped)++;
@ -706,9 +710,10 @@ static ical_rpt_t *ical_read_rrule(FILE * log, char *rrulestr,
} else { } else {
rpt->count = cnt; rpt->count = cnt;
} }
} else } else {
rpt->until = 0; rpt->until = 0;
} }
}
if ((p = strstr(rrulestr, interv)) != NULL) { if ((p = strstr(rrulestr, interv)) != NULL) {
p += sizeof(interv) - 1; p += sizeof(interv) - 1;
@ -810,8 +815,9 @@ static char *ical_read_summary(char *line)
p++; p++;
summary = ical_unformat_line(p); summary = ical_unformat_line(p);
return summary; return summary;
} else } else {
return NULL; return NULL;
}
} }
static void static void

View File

@ -531,8 +531,9 @@ void io_load_app(void)
} else if (c == '}') { } else if (c == '}') {
while ((c = getc(data_file)) == ' ') ; while ((c = getc(data_file)) == ' ') ;
ungetc(c, data_file); ungetc(c, data_file);
} else } else {
io_load_error(path_apts, line, _("syntax error in item repetition")); io_load_error(path_apts, line, _("syntax error in item repetition"));
}
} else if (c == '!') { /* endless item with exceptions */ } else if (c == '!') { /* endless item with exceptions */
ungetc(c, data_file); ungetc(c, data_file);
recur_exc_scan(&exc, data_file); recur_exc_scan(&exc, data_file);
@ -544,8 +545,9 @@ void io_load_app(void)
_("wrong format in the appointment or event")); _("wrong format in the appointment or event"));
/* NOTREACHED */ /* NOTREACHED */
} }
} else } else {
ungetc(c, data_file); ungetc(c, data_file);
}
/* Check if a note is attached to the item. */ /* Check if a note is attached to the item. */
c = getc(data_file); c = getc(data_file);
@ -571,8 +573,9 @@ void io_load_app(void)
state = 0L; state = 0L;
while ((c = getc(data_file)) == ' ') ; while ((c = getc(data_file)) == ' ') ;
ungetc(c, data_file); ungetc(c, data_file);
} else } else {
io_load_error(path_apts, line, _("syntax error in item repetition")); io_load_error(path_apts, line, _("syntax error in item repetition"));
}
if (is_recursive) { if (is_recursive) {
recur_apoint_scan(data_file, start, end, recur_apoint_scan(data_file, start, end,
type, freq, until, notep, &exc, state); type, freq, until, notep, &exc, state);
@ -610,9 +613,9 @@ void io_load_todo(void)
for (;;) { for (;;) {
line++; line++;
c = getc(data_file); c = getc(data_file);
if (c == EOF) if (c == EOF) {
break; break;
else if (c == '[') { /* new style with id */ } else if (c == '[') { /* new style with id */
if (fscanf(data_file, " %d ", &id) != 1 || getc(data_file) != ']') if (fscanf(data_file, " %d ", &id) != 1 || getc(data_file) != ']')
io_load_error(path_todo, line, _("syntax error in item identifier")); io_load_error(path_todo, line, _("syntax error in item identifier"));
while ((c = getc(data_file)) == ' ') ; while ((c = getc(data_file)) == ' ') ;
@ -623,9 +626,9 @@ void io_load_todo(void)
} }
/* Now read the attached note, if any. */ /* Now read the attached note, if any. */
c = getc(data_file); c = getc(data_file);
if (c == '>') if (c == '>') {
note_read(note, data_file); note_read(note, data_file);
else { } else {
note[0] = '\0'; note[0] = '\0';
ungetc(c, data_file); ungetc(c, data_file);
} }
@ -772,9 +775,10 @@ void io_load_keys(const char *pager)
(void)snprintf(already_assigned, BUFSIZ, (void)snprintf(already_assigned, BUFSIZ,
_("\"%s\" assigned multiple times!"), key_ch); _("\"%s\" assigned multiple times!"), key_ch);
io_log_print(log, line, already_assigned); io_log_print(log, line, already_assigned);
} else } else {
assigned++; assigned++;
} }
}
p += strlen(key_ch) + 1; p += strlen(key_ch) + 1;
} else { } else {
if (assigned) if (assigned)
@ -826,8 +830,7 @@ unsigned io_file_exist(const char *file)
if (file && (fd = fopen(file, "r")) != NULL) { if (file && (fd = fopen(file, "r")) != NULL) {
fclose(fd); fclose(fd);
return 1; return 1;
} } else {
else {
return 0; return 0;
} }
} }
@ -1163,9 +1166,10 @@ void io_set_lock(void)
fclose(lock); fclose(lock);
if (kill(pid, 0) != 0 && errno == ESRCH) if (kill(pid, 0) != 0 && errno == ESRCH)
lock = NULL; lock = NULL;
} else } else {
fclose(lock); fclose(lock);
} }
}
if (lock != NULL) { if (lock != NULL) {
fprintf(stderr, fprintf(stderr,
@ -1264,9 +1268,10 @@ int io_file_cp(const char *src, const char *dst)
if (bytes_read > 0) { if (bytes_read > 0) {
if (fwrite(buffer, 1, bytes_read, fp_dst) != bytes_read) if (fwrite(buffer, 1, bytes_read, fp_dst) != bytes_read)
return 0; return 0;
} else } else {
return 0; return 0;
} }
}
fclose(fp_dst); fclose(fp_dst);
fclose(fp_src); fclose(fp_src);

View File

@ -199,11 +199,9 @@ enum key keys_getch(WINDOW * win, int *count, int *reg)
ch = wgetch(win); ch = wgetch(win);
if (ch >= '1' && ch <= '9') { if (ch >= '1' && ch <= '9') {
*reg = ch - '1' + 1; *reg = ch - '1' + 1;
} } else if (ch >= 'a' && ch <= 'z') {
else if (ch >= 'a' && ch <= 'z') {
*reg = ch - 'a' + 10; *reg = ch - 'a' + 10;
} } else if (ch == '_') {
else if (ch == '_') {
*reg = REG_BLACK_HOLE; *reg = REG_BLACK_HOLE;
} }
ch = wgetch(win); ch = wgetch(win);
@ -230,9 +228,9 @@ static void add_key_str(enum key action, int key)
int keys_assign_binding(int key, enum key action) int keys_assign_binding(int key, enum key action)
{ {
if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF) if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF) {
return 1; return 1;
else { } else {
actions[key] = action; actions[key] = action;
add_key_str(action, key); add_key_str(action, key);
} }
@ -281,9 +279,9 @@ int keys_str2int(const char *key)
if (!key) if (!key)
return -1; return -1;
if (strlen(key) == 1) if (strlen(key) == 1) {
return (int)key[0]; return (int)key[0];
else { } else {
if (key[0] == '^') if (key[0] == '^')
return CTRL((int)key[1]); return CTRL((int)key[1]);
else if (!strncmp(key, CONTROL_KEY, sizeof(CONTROL_KEY) - 1)) else if (!strncmp(key, CONTROL_KEY, sizeof(CONTROL_KEY) - 1))
@ -390,9 +388,9 @@ static char *keys_format_label(char *key, int keylen)
return NULL; return NULL;
memset(fmtkey, 0, sizeof(fmtkey)); memset(fmtkey, 0, sizeof(fmtkey));
if (len == 0) if (len == 0) {
strncpy(fmtkey, "?", sizeof(fmtkey)); strncpy(fmtkey, "?", sizeof(fmtkey));
else if (len <= keylen) { } else if (len <= keylen) {
for (i = 0; i < keylen - len; i++) for (i = 0; i < keylen - len; i++)
fmtkey[i] = ' '; fmtkey[i] = ' ';
strncat(fmtkey, key, keylen); strncat(fmtkey, key, keylen);
@ -594,9 +592,10 @@ void keys_fill_missing(void)
"\"%s\" was already assigned!"), "\"%s\" was already assigned!"),
keydef[i].label, key_ch); keydef[i].label, key_ch);
p += strlen(key_ch) + 1; p += strlen(key_ch) + 1;
} else } else {
break; break;
} }
} }
} }
}
} }

View File

@ -140,9 +140,9 @@ void llist_add(llist_t * l, void *data)
o->data = data; o->data = data;
o->next = NULL; o->next = NULL;
if (!l->head) if (!l->head) {
l->head = l->tail = o; l->head = l->tail = o;
else { } else {
l->tail->next = o; l->tail->next = o;
l->tail = o; l->tail = o;
} }
@ -161,9 +161,9 @@ void llist_add_sorted(llist_t * l, void *data, llist_fn_cmp_t fn_cmp)
o->data = data; o->data = data;
o->next = NULL; o->next = NULL;
if (!l->head) if (!l->head) {
l->head = l->tail = o; l->head = l->tail = o;
else if (fn_cmp(o->data, l->tail->data) >= 0) { } else if (fn_cmp(o->data, l->tail->data) >= 0) {
l->tail->next = o; l->tail->next = o;
l->tail = o; l->tail = o;
} else if (fn_cmp(o->data, l->head->data) < 0) { } else if (fn_cmp(o->data, l->head->data) < 0) {
@ -186,9 +186,9 @@ void llist_remove(llist_t * l, llist_item_t * i)
{ {
llist_item_t *j = NULL; llist_item_t *j = NULL;
if (l->head && i == l->head) if (l->head && i == l->head) {
l->head = i->next; l->head = i->next;
else { } else {
for (j = l->head; j && j->next != i; j = j->next) ; for (j = l->head; j && j->next != i; j = j->next) ;
} }

View File

@ -94,9 +94,9 @@ void edit_note(char **note, const char *editor)
wins_launch_external(tmppath, editor); wins_launch_external(tmppath, editor);
if (io_file_is_empty(tmppath) > 0) if (io_file_is_empty(tmppath) > 0) {
erase_note(note); erase_note(note);
else if ((fp = fopen(tmppath, "r"))) { } else if ((fp = fopen(tmppath, "r"))) {
sha1_stream(fp, sha1); sha1_stream(fp, sha1);
fclose(fp); fclose(fp);
*note = sha1; *note = sha1;

View File

@ -140,9 +140,9 @@ static void extract_aptsfile(void)
char *file; char *file;
file = strrchr(path_apts, '/'); file = strrchr(path_apts, '/');
if (!file) if (!file) {
notify.apts_file = path_apts; notify.apts_file = path_apts;
else { } else {
notify.apts_file = file; notify.apts_file = file;
notify.apts_file++; notify.apts_file++;
} }
@ -455,8 +455,9 @@ void notify_check_added(char *mesg, long start, char state)
update_notify = 1; update_notify = 1;
} else if (start < notify_app.time && start >= current_time) { } else if (start < notify_app.time && start >= current_time) {
update_notify = 1; update_notify = 1;
} else if (start == notify_app.time && state != notify_app.state) } else if (start == notify_app.time && state != notify_app.state) {
update_notify = 1; update_notify = 1;
}
if (update_notify) { if (update_notify) {
notify_update_app(start, state, mesg); notify_update_app(start, state, mesg);
@ -482,9 +483,10 @@ void notify_check_repeated(struct recur_apoint *i)
update_notify = 1; update_notify = 1;
} else if (real_app_time < notify_app.time && real_app_time >= current_time) { } else if (real_app_time < notify_app.time && real_app_time >= current_time) {
update_notify = 1; update_notify = 1;
} else if (real_app_time == notify_app.time && i->state != notify_app.state) } else if (real_app_time == notify_app.time && i->state != notify_app.state) {
update_notify = 1; update_notify = 1;
} }
}
if (update_notify) { if (update_notify) {
notify_update_app(real_app_time, i->state, i->mesg); notify_update_app(real_app_time, i->state, i->mesg);
} }
@ -548,9 +550,9 @@ print_option(WINDOW * win, unsigned x, unsigned y, char *name,
maxlen = MAXCOL - x_opt - 2; maxlen = MAXCOL - x_opt - 2;
custom_apply_attr(win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
if (len < maxlen) if (len < maxlen) {
mvwaddstr(win, y, x_opt, valstr); mvwaddstr(win, y, x_opt, valstr);
else { } else {
char buf[BUFSIZ]; char buf[BUFSIZ];
strncpy(buf, valstr, maxlen - 1); strncpy(buf, valstr, maxlen - 1);
@ -558,8 +560,9 @@ print_option(WINDOW * win, unsigned x, unsigned y, char *name,
mvwprintw(win, y, x_opt, "%s...", buf); mvwprintw(win, y, x_opt, "%s...", buf);
} }
custom_remove_attr(win, ATTR_HIGHEST); custom_remove_attr(win, ATTR_HIGHEST);
} else } else {
print_bool_option_incolor(win, valbool, y, x_opt); print_bool_option_incolor(win, valbool, y, x_opt);
}
mvwaddstr(win, y + 1, x, desc); mvwaddstr(win, y + 1, x, desc);
} }

View File

@ -203,8 +203,9 @@ struct recur_apoint *recur_apoint_new(char *mesg, char *note, long start,
if (except) { if (except) {
exc_dup(&rapt->exc, except); exc_dup(&rapt->exc, except);
free_exc_list(except); free_exc_list(except);
} else } else {
LLIST_INIT(&rapt->exc); LLIST_INIT(&rapt->exc);
}
LLIST_TS_LOCK(&recur_alist_p); LLIST_TS_LOCK(&recur_alist_p);
LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start); LLIST_TS_ADD_SORTED(&recur_alist_p, rapt, recur_apoint_cmp_start);
@ -231,8 +232,9 @@ struct recur_event *recur_event_new(char *mesg, char *note, long day, int id,
if (except) { if (except) {
exc_dup(&rev->exc, except); exc_dup(&rev->exc, except);
free_exc_list(except); free_exc_list(except);
} else } else {
LLIST_INIT(&rev->exc); LLIST_INIT(&rev->exc);
}
LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day); LLIST_ADD_SORTED(&recur_elist, rev, recur_event_cmp_day);
@ -627,8 +629,9 @@ recur_item_find_occurrence(long item_start, long item_dur, llist_t * item_exc,
} }
return 1; return 1;
} else } else {
return 0; return 0;
}
} }
unsigned unsigned

View File

@ -197,8 +197,9 @@ void sha1_update(sha1_ctx_t * ctx, const uint8_t * data, unsigned int len)
for (; i + 63 < len; i += 64) for (; i + 63 < len; i += 64)
sha1_transform(ctx->state, &data[i]); sha1_transform(ctx->state, &data[i]);
j = 0; j = 0;
} else } else {
i = 0; i = 0;
}
memcpy(&ctx->buffer[j], &data[i], len - i); memcpy(&ctx->buffer[j], &data[i], len - i);
} }

View File

@ -260,9 +260,9 @@ static int date_change(struct tm *date, int delta_month, int delta_day)
t.tm_mon += delta_month; t.tm_mon += delta_month;
t.tm_mday += delta_day; t.tm_mday += delta_day;
if (mktime(&t) == -1) if (mktime(&t) == -1) {
return 1; return 1;
else { } else {
*date = t; *date = t;
return 0; return 0;
} }
@ -338,8 +338,7 @@ draw_monthly_view(struct window *cwin, struct date *current_day,
/* check if the day contains an event or an appointment */ /* check if the day contains an event or an appointment */
if (monthly_view_cache_valid) { if (monthly_view_cache_valid) {
item_this_day = monthly_view_cache[c_day - 1]; item_this_day = monthly_view_cache[c_day - 1];
} } else {
else {
item_this_day = monthly_view_cache[c_day - 1] = item_this_day = monthly_view_cache[c_day - 1] =
day_check_if_item(check_day); day_check_if_item(check_day);
} }
@ -625,9 +624,9 @@ void ui_calendar_change_day(int datefmt)
while (wrong_day) { while (wrong_day) {
snprintf(outstr, BUFSIZ, request_date, DATEFMT_DESC(datefmt)); snprintf(outstr, BUFSIZ, request_date, DATEFMT_DESC(datefmt));
status_mesg(outstr, ""); status_mesg(outstr, "");
if (getstring(win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC) if (getstring(win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC) {
return; return;
else { } else {
if (strlen(selected_day) == 0) { if (strlen(selected_day) == 0) {
wrong_day = 0; wrong_day = 0;
ui_calendar_goto_today(); ui_calendar_goto_today();

View File

@ -227,9 +227,9 @@ display_todo_item(int incolor, char *msg, int prio, int note, int width, int y,
if (incolor == 0) if (incolor == 0)
custom_apply_attr(w, ATTR_HIGHEST); custom_apply_attr(w, ATTR_HIGHEST);
if (utf8_strwidth(msg) < width) if (utf8_strwidth(msg) < width) {
mvwprintw(w, y, x, "%s%c %s", priostr, ch_note, msg); mvwprintw(w, y, x, "%s%c %s", priostr, ch_note, msg);
else { } else {
for (i = 0; msg[i] && width > 0; i++) { for (i = 0; msg[i] && width > 0; i++) {
if (!UTF8_ISCONT(msg[i])) if (!UTF8_ISCONT(msg[i]))
width -= utf8_width(&msg[i]); width -= utf8_width(&msg[i]);

View File

@ -313,9 +313,10 @@ int utf8_width(char *s)
return utf8_widthtab[cur].width; return utf8_widthtab[cur].width;
else else
low = cur + 1; low = cur + 1;
} else } else {
high = cur - 1; high = cur - 1;
} }
}
while (low <= high); while (low <= high);
return 1; return 1;

View File

@ -77,8 +77,9 @@ void exit_calcurse(int status)
endwin(); endwin();
ui_mode = UI_CMDLINE; ui_mode = UI_CMDLINE;
was_interactive = 1; was_interactive = 1;
} else } else {
was_interactive = 0; was_interactive = 0;
}
ui_calendar_stop_date_thread(); ui_calendar_stop_date_thread();
io_stop_psave_thread(); io_stop_psave_thread();
@ -379,9 +380,9 @@ char *date_sec2date_str(long sec, const char *datefmt)
struct tm lt; struct tm lt;
char *datestr = (char *)mem_calloc(BUFSIZ, sizeof(char)); char *datestr = (char *)mem_calloc(BUFSIZ, sizeof(char));
if (sec == 0) if (sec == 0) {
strncpy(datestr, "0", BUFSIZ); strncpy(datestr, "0", BUFSIZ)
else { } else {
localtime_r((time_t *)&sec, &lt); localtime_r((time_t *)&sec, &lt);
strftime(datestr, BUFSIZ, datefmt, &lt); strftime(datestr, BUFSIZ, datefmt, &lt);
} }
@ -574,8 +575,9 @@ print_bool_option_incolor(WINDOW * win, unsigned option, int pos_y, int pos_x)
} else if (option == 0) { } else if (option == 0) {
color = ATTR_FALSE; color = ATTR_FALSE;
option_value = _("no"); option_value = _("no");
} else } else {
EXIT(_("option not defined")); EXIT(_("option not defined"));
}
custom_apply_attr(win, color); custom_apply_attr(win, color);
mvwaddstr(win, pos_y, pos_x, option_value); mvwaddstr(win, pos_y, pos_x, option_value);
@ -660,11 +662,12 @@ parse_date(const char *date_string, enum datefmt datefmt, int *year,
if (*p == sep) { if (*p == sep) {
if ((++n) > 2) if ((++n) > 2)
return 0; return 0;
} else if ((*p >= '0') && (*p <= '9')) } else if ((*p >= '0') && (*p <= '9')) {
in[n] = in[n] * 10 + (int)(*p - '0'); in[n] = in[n] * 10 + (int)(*p - '0');
else } else {
return 0; return 0;
} }
}
if ((!slctd_date && n < 2) || in[n] == 0) if ((!slctd_date && n < 2) || in[n] == 0)
return 0; return 0;
@ -741,9 +744,10 @@ int parse_time(const char *string, unsigned *hour, unsigned *minute)
if ((n == 0) && (p == (string + 2)) && *(p + 1)) if ((n == 0) && (p == (string + 2)) && *(p + 1))
n++; n++;
in[n] = in[n] * 10 + (int)(*p - '0'); in[n] = in[n] * 10 + (int)(*p - '0');
} else } else {
return 0; return 0;
} }
}
if (n != 1 || in[0] >= DAYINHOURS || in[1] >= HOURINMIN) if (n != 1 || in[0] >= DAYINHOURS || in[1] >= HOURINMIN)
return 0; return 0;
@ -804,8 +808,9 @@ int parse_duration(const char *string, unsigned *duration)
} else if (*p == 'm') { } else if (*p == 'm') {
dur += in; dur += in;
state = STATE_DONE; state = STATE_DONE;
} else } else {
return 0; return 0;
}
break; break;
case STATE_DDHHMM_HH: case STATE_DDHHMM_HH:
if (*p == 'h') { if (*p == 'h') {
@ -814,15 +819,17 @@ int parse_duration(const char *string, unsigned *duration)
} else if (*p == 'm') { } else if (*p == 'm') {
dur += in; dur += in;
state = STATE_DONE; state = STATE_DONE;
} else } else {
return 0; return 0;
}
break; break;
case STATE_DDHHMM_MM: case STATE_DDHHMM_MM:
if (*p == 'm') { if (*p == 'm') {
dur += in; dur += in;
state = STATE_DONE; state = STATE_DONE;
} else } else {
return 0; return 0;
}
break; break;
case STATE_HHMM_MM: case STATE_HHMM_MM:
return 0; return 0;
@ -1015,8 +1022,9 @@ static void print_notefile(FILE * out, const char *filename, int nbtab)
for (i = 0; i < nbtab; i++) for (i = 0; i < nbtab; i++)
linestarter[i] = '\t'; linestarter[i] = '\t';
linestarter[nbtab] = '\0'; linestarter[nbtab] = '\0';
} else } else {
linestarter[0] = '\0'; linestarter[0] = '\0';
}
snprintf(path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename); snprintf(path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
notefile = fopen(path_to_notefile, "r"); notefile = fopen(path_to_notefile, "r");
@ -1168,9 +1176,9 @@ static void print_date(long date, long day, const char *extformat)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
if (!strcmp(extformat, "epoch")) if (!strcmp(extformat, "epoch")) {
printf("%ld", date); printf("%ld", date);
else { } else {
time_t t = date; time_t t = date;
struct tm lt; struct tm lt;
@ -1227,11 +1235,12 @@ void print_apoint(const char *format, long day, struct apoint *apt)
putchar('?'); putchar('?');
break; break;
} }
} else if (*p == '\\') } else if (*p == '\\') {
p += print_escape(p); p += print_escape(p);
else } else {
putchar(*p); putchar(*p);
} }
}
} }
/* Print a formatted event to stdout. */ /* Print a formatted event to stdout. */
@ -1263,11 +1272,12 @@ void print_event(const char *format, long day, struct event *ev)
putchar('?'); putchar('?');
break; break;
} }
} else if (*p == '\\') } else if (*p == '\\') {
p += print_escape(p); p += print_escape(p);
else } else {
putchar(*p); putchar(*p);
} }
}
} }
/* Print a formatted recurrent appointment to stdout. */ /* Print a formatted recurrent appointment to stdout. */
@ -1328,9 +1338,10 @@ void print_todo(const char *format, struct todo *todo)
putchar('?'); putchar('?');
break; break;
} }
} else if (*p == '\\') } else if (*p == '\\') {
p += print_escape(p); p += print_escape(p);
else } else {
putchar(*p); putchar(*p);
} }
}
} }

View File

@ -175,9 +175,9 @@ void wins_set_layout(int nb)
/* Get the current side bar width. */ /* Get the current side bar width. */
unsigned wins_sbar_width(void) unsigned wins_sbar_width(void)
{ {
if (sbarwidth_perc > SBARMAXWIDTHPERC) if (sbarwidth_perc > SBARMAXWIDTHPERC) {
return col * SBARMAXWIDTHPERC / 100; return col * SBARMAXWIDTHPERC / 100;
else { } else {
unsigned sbarwidth = (unsigned)(col * sbarwidth_perc / 100); unsigned sbarwidth = (unsigned)(col * sbarwidth_perc / 100);
return (sbarwidth < SBARMINWIDTH) ? SBARMINWIDTH : sbarwidth; return (sbarwidth < SBARMINWIDTH) ? SBARMINWIDTH : sbarwidth;
} }