Miscellaneous small code cleanups

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2012-04-06 23:21:18 +02:00
parent d0b0ed3c20
commit 1c442e6aef
8 changed files with 24 additions and 29 deletions

View File

@ -264,7 +264,6 @@ apoint_add (void)
void
apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
{
char *choices = "[y/n] ";
const char *del_app_str = _("Do you really want to delete this item ?");
long date;
int nb_items = *nb_apoints + *nb_events;
@ -277,7 +276,7 @@ apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
if (conf.confirm_delete)
{
status_mesg (del_app_str, choices);
status_mesg_yesno (del_app_str);
if (wgetch (win[STA].p) != 'y')
{
wins_erase_status_bar ();
@ -375,11 +374,7 @@ apoint_paste (unsigned *nb_events, unsigned *nb_apoints, int cut_item_type)
unsigned
apoint_inday (struct apoint *i, long start)
{
if (i->start <= start + DAYINSEC && i->start + i->dur > start)
{
return 1;
}
return 0;
return (i->start <= start + DAYINSEC && i->start + i->dur > start);
}
void

View File

@ -65,11 +65,8 @@ int
main (int argc, char **argv)
{
struct day_items_nb inday;
int non_interactive;
int no_data_file = 1;
int cut_item = 0;
const char *quit_message = _("Do you really want to quit ?");
char choices[] = "[y/n] ";
int count;
#if ENABLE_NLS
@ -90,9 +87,11 @@ main (int argc, char **argv)
* Begin by parsing and handling command line arguments.
* The data path is also initialized here.
*/
non_interactive = parse_args (argc, argv);
if (non_interactive)
exit_calcurse (EXIT_SUCCESS);
if (parse_args (argc, argv))
{
/* Non-interactive mode. */
exit_calcurse (EXIT_SUCCESS);
}
else
{
no_data_file = io_check_data_files ();
@ -136,7 +135,6 @@ main (int argc, char **argv)
init_pair (COLR_DEFAULT, foreground, background);
init_pair (COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
init_pair (COLR_CUSTOM, COLOR_RED, background);
}
else
{
@ -543,7 +541,7 @@ main (int argc, char **argv)
if (conf.confirm_quit)
{
status_mesg (_(quit_message), choices);
status_mesg_yesno (_("Do you really want to quit ?"));
key = wgetch (win[STA].p);
if (key == 'y')
exit_calcurse (EXIT_SUCCESS);

View File

@ -895,6 +895,7 @@ void free_user_data (void);
void fatalbox (const char *);
void warnbox (const char *);
void status_mesg (const char *, const char *);
void status_mesg_yesno (const char *);
void erase_window_part (WINDOW *, int, int, int, int);
WINDOW *popup (int, int, int, int, char *, char *, int);
void print_in_middle (WINDOW *, int, int, int, const char *);

View File

@ -115,11 +115,7 @@ event_new (char *mesg, char *note, long day, int id)
unsigned
event_inday (struct event *i, long start)
{
if (i->day < start + DAYINSEC && i->day >= start)
{
return 1;
}
return 0;
return (i->day < start + DAYINSEC && i->day >= start);
}
/* Write to file the event in user-friendly format */

View File

@ -1239,13 +1239,12 @@ io_log_print (struct io_file *log, int line, const char *msg)
void
io_log_display (struct io_file *log, const char *msg, char *pager)
{
char *choices = "[y/n] ";
int ans;
RETURN_IF (log == NULL, _("No log file to display!"));
if (ui_mode == UI_CMDLINE)
{
printf ("\n%s %s", msg, choices);
printf ("\n%s [y/n] ", msg);
ans = fgetc (stdin);
if (ans == 'y')
{
@ -1258,7 +1257,7 @@ io_log_display (struct io_file *log, const char *msg, char *pager)
}
else
{
status_mesg (msg, choices);
status_mesg_yesno (msg);
do
{
ans = wgetch (win[STA].p);

View File

@ -611,7 +611,7 @@ diff_years (struct tm lt_start, struct tm lt_end)
static int
exc_inday (struct excp *exc, long day_start)
{
return exc->st >= day_start && exc->st < day_start + DAYINSEC;
return (exc->st >= day_start && exc->st < day_start + DAYINSEC);
}
/*

View File

@ -242,7 +242,6 @@ todo_flag (void)
void
todo_delete (void)
{
char *choices = "[y/n] ";
const char *del_todo_str = _("Do you really want to delete this task ?");
const char *erase_warning =
_("This item has a note attached to it. "
@ -252,7 +251,7 @@ todo_delete (void)
if (conf.confirm_delete)
{
status_mesg (del_todo_str, choices);
status_mesg_yesno (del_todo_str);
answer = wgetch (win[STA].p);
if ((answer != 'y') || (todos <= 0))
{

View File

@ -160,15 +160,22 @@ warnbox (const char *msg)
* Message texts for first line and second line are to be provided.
*/
void
status_mesg (const char *mesg_line1, const char *mesg_line2)
status_mesg (const char *msg1, const char *msg2)
{
wins_erase_status_bar ();
custom_apply_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, 0, mesg_line1);
mvwprintw (win[STA].p, 1, 0, mesg_line2);
mvwprintw (win[STA].p, 0, 0, msg1);
mvwprintw (win[STA].p, 1, 0, msg2);
custom_remove_attr (win[STA].p, ATTR_HIGHEST);
}
/* Print a status message, followed by a "[y/n]" prompt. */
void
status_mesg_yesno (const char *msg)
{
status_mesg (msg, "[y/n] ");
}
/* Erase part of a window. */
void
erase_window_part (WINDOW *win, int first_col, int first_row, int last_col,