unuseful headers removed and some functions became static

This commit is contained in:
Frederic Culot 2007-07-28 13:11:42 +00:00
parent fdc325acd8
commit 4b987f70ac
28 changed files with 1021 additions and 1115 deletions

View File

@ -1,4 +1,4 @@
/* $calcurse: apoint.c,v 1.12 2007/07/21 19:35:14 culot Exp $ */ /* $calcurse: apoint.c,v 1.13 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,7 +24,6 @@
* *
*/ */
#include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -403,7 +402,8 @@ void display_item_date(WINDOW *win, int incolor, apoint_llist_node_t *i,
* the appointment panel. This is to help the appointment scroll function * the appointment panel. This is to help the appointment scroll function
* to place beggining of the pad correctly. * to place beggining of the pad correctly.
*/ */
int get_item_line(int item_nb, int nb_events_inday) static int
get_item_line(int item_nb, int nb_events_inday)
{ {
int separator = 2; int separator = 2;
int line = 0; int line = 0;

View File

@ -1,4 +1,4 @@
/* $calcurse: apoint.h,v 1.7 2007/07/21 19:35:14 culot Exp $ */ /* $calcurse: apoint.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,8 +27,6 @@
#ifndef CALCURSE_APOINT_H #ifndef CALCURSE_APOINT_H
#define CALCURSE_APOINT_H #define CALCURSE_APOINT_H
#include <ncurses.h>
#include "notify.h" #include "notify.h"
#include "recur.h" #include "recur.h"
#include "vars.h" #include "vars.h"
@ -67,7 +65,6 @@ apoint_llist_node_t *apoint_scan(FILE *, struct tm, struct tm, char);
void apoint_delete_bynum(long, unsigned); void apoint_delete_bynum(long, unsigned);
void display_item_date(WINDOW *, int, apoint_llist_node_t *, void display_item_date(WINDOW *, int, apoint_llist_node_t *,
int, long, int, int); int, long, int, int);
int get_item_line(int, int);
void scroll_pad_down(int, int, int); void scroll_pad_down(int, int, int);
void scroll_pad_up(int, int); void scroll_pad_up(int, int);
struct notify_app_s *apoint_check_next(struct notify_app_s *, long); struct notify_app_s *apoint_check_next(struct notify_app_s *, long);

View File

@ -1,4 +1,4 @@
/* $calcurse: args.c,v 1.22 2007/07/21 19:34:42 culot Exp $ */ /* $calcurse: args.c,v 1.23 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,12 +24,9 @@
* *
*/ */
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdbool.h>
#include <sys/types.h> #include <sys/types.h>
#include <getopt.h> #include <getopt.h>
#include <time.h> #include <time.h>
@ -40,11 +37,341 @@
#include "args.h" #include "args.h"
#include "event.h" #include "event.h"
#include "apoint.h" #include "apoint.h"
#include "recur.h"
#include "day.h" #include "day.h"
#include "todo.h" #include "todo.h"
#include "io.h" #include "io.h"
#include "notify.h"
/*
* Print Calcurse usage and exit.
*/
static void
usage()
{
char *arg_usage =
_("Usage: calcurse [-h|-v] [-x] [-an] [-t[num]] [-d date|num] [-c file]\n");
fputs(arg_usage, stdout);
}
static void
usage_try()
{
char *arg_usage_try =
_("Try 'calcurse -h' for more information.\n");
fputs(arg_usage_try, stdout);
}
/*
* Print Calcurse version with a short copyright text and exit.
*/
static void
version_arg()
{
char vtitle[BUFSIZ];
char *vtext =
_("\nCopyright (c) 2004-2007 Frederic Culot.\n"
"This is free software; see the source for copying conditions.\n");
snprintf(vtitle, BUFSIZ,
_("Calcurse %s - text-based organizer\n"), VERSION);
fputs(vtitle, stdout);
fputs(vtext, stdout);
}
/*
* Print the command line options and exit.
*/
static void
help_arg()
{
char htitle[BUFSIZ];
char *htext =
_("\nMiscellaneous:\n"
" -h, --help\n"
" print this help and exit.\n"
"\n -v, --version\n"
" print calcurse version and exit.\n"
"\nFiles:\n"
" -c <file>, --calendar <file>\n"
" specify the calendar <file> to use.\n"
"\nNon-interactive:\n"
" -a, --appointment\n"
" print events and appointments for current day and exit.\n"
"\n -d <date|num>, --day <date|num>\n"
" print events and appointments for <date> or <num> upcoming days and"
"\n\texit. Possible formats are: 'mm/dd/yyyy' or 'n'.\n"
"\n -n, --next\n"
" print next appointment within upcoming 24 hours "
"and exit. Also given\n\tis the remaining time before this "
"next appointment.\n"
"\n -t[num], --todo[=num]\n"
" print todo list and exit. If the optional number [num] is given,\n"
"\tthen only todos having a priority equal to [num] will be returned.\n"
"\tnote: priority number must be between 1 (highest) and 9 (lowest).\n"
"\n -x, --export\n"
" export user data to iCalendar format. Events, appointments and\n"
"\ttodos are converted and echoed to stdout.\n"
"\tnote: redirect standard output to export data to a file,\n"
"\tby issuing a command such as: calcurse --export > my_data.ics\n"
"\nFor more information, type '?' from within Calcurse, "
"or read the manpage.\n"
"Mail bug reports and suggestions to <calcurse@culot.org>.\n");
snprintf(htitle, BUFSIZ,
_("Calcurse %s - text-based organizer\n"), VERSION);
fputs(htitle, stdout);
usage();
fputs(htext, stdout);
}
/*
* Print todo list and exit. If a priority number is given (say not equal to
* zero), then only todo items that have this priority will be displayed.
*/
static void
todo_arg(int priority)
{
struct todo_s *i;
int nb_tod, title = 1;
char priority_str[BUFSIZ] = "";
nb_tod = io_load_todo();
for (i = todolist; i != 0; i = i->next) {
if (priority == 0 || i->id == priority) {
if (title) {
fputs(_("to do:\n"),stdout);
title = 0;
}
snprintf(priority_str, BUFSIZ, "%d. ", i->id);
fputs(priority_str,stdout);
fputs(i->mesg,stdout);
fputs("\n",stdout);
}
}
}
/* Print the next appointment within the upcoming 24 hours. */
static void
next_arg(void)
{
struct notify_app_s *next_app;
long current_time;
int time_left, hours_left, min_left;
char mesg[BUFSIZ];
current_time = now();
next_app = (struct notify_app_s *) malloc(sizeof(struct notify_app_s));
next_app->time = current_time + DAYINSEC;
next_app->got_app = 0;
next_app = recur_apoint_check_next(next_app, current_time, get_today());
next_app = apoint_check_next(next_app, current_time);
time_left = next_app->time - current_time;
if (time_left > 0 && time_left < DAYINSEC) {
hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs(_("next appointment:\n"), stdout);
snprintf(mesg, BUFSIZ, " [%02d:%02d] %s\n",
hours_left, min_left, next_app->txt);
fputs(mesg, stdout);
}
free(next_app->txt);
free(next_app);
}
/*
* Print the date on stdout.
*/
static void
arg_print_date(long date)
{
char date_str[BUFSIZ];
time_t t;
struct tm *lt;
t = date;
lt = localtime(&t);
snprintf(date_str, BUFSIZ, "%02u/%02u/%04u",
lt->tm_mon+1, lt->tm_mday, 1900+lt->tm_year);
fputs(date_str,stdout);
fputs(":\n",stdout);
}
/*
* Print appointments for given day and exit.
* If no day is given, the given date is used.
* If there is also no date given, current date is considered.
*/
static int
app_arg(int add_line, date_t day, long date)
{
struct recur_event_s *re;
struct event_s *j;
recur_apoint_llist_node_t *ra;
apoint_llist_node_t *i;
long today;
bool print_date = true;
int app_found = 0;
char apoint_start_time[100];
char apoint_end_time[100];
if (date == 0)
today = get_sec_date(day);
else
today = date;
/*
* Calculate and print the selected date if there is an event for
* that date and it is the first one, and then print all the events for
* that date.
*/
for (re = recur_elist; re != 0; re = re->next) {
if (recur_item_inday(re->day, re->exc, re->rpt->type,
re->rpt->freq, re->rpt->until, today)) {
app_found = 1;
if (add_line) {
fputs("\n", stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
fputs(" o ", stdout);
fputs(re->mesg, stdout); fputs("\n", stdout);
}
}
for (j = eventlist; j != 0; j = j->next) {
if (event_inday(j, today)) {
app_found = 1;
if (add_line) {
fputs("\n",stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
fputs(" o ",stdout);
fputs(j->mesg,stdout); fputs("\n",stdout);
}
}
/* Same process is performed but this time on the appointments. */
pthread_mutex_lock(&(recur_alist_p->mutex));
for (ra = recur_alist_p->root; ra != 0; ra = ra->next) {
if (recur_item_inday(ra->start, ra->exc, ra->rpt->type,
ra->rpt->freq, ra->rpt->until, today)) {
app_found = 1;
if (add_line) {
fputs("\n",stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
apoint_sec2str(apoint_recur_s2apoint_s(ra),
RECUR_APPT, today, apoint_start_time,
apoint_end_time);
fputs(" - ",stdout);
fputs(apoint_start_time,stdout);
fputs(" -> ",stdout);
fputs(apoint_end_time,stdout); fputs("\n\t",stdout);
fputs(ra->mesg,stdout); fputs("\n",stdout);
}
}
pthread_mutex_unlock(&(recur_alist_p->mutex));
pthread_mutex_lock(&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next) {
if (apoint_inday(i, today)) {
app_found = 1;
if (add_line) {
fputs("\n",stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
apoint_sec2str(i, APPT, today, apoint_start_time,
apoint_end_time);
fputs(" - ",stdout);
fputs(apoint_start_time,stdout);
fputs(" -> ",stdout);
fputs(apoint_end_time,stdout); fputs("\n\t",stdout);
fputs(i->mesg,stdout); fputs("\n",stdout);
}
}
pthread_mutex_unlock(&(alist_p->mutex));
return app_found;
}
/*
* Print appointment for the given date or for the given n upcoming
* days.
*/
static void
date_arg(char *ddate, int add_line)
{
int i;
date_t day;
int numdays = 0, num_digit = 0;
int arg_len = 0, app_found = 0;
int date_valid = 0;
long today, ind;
int sec_in_day = 86400;
day.dd = 0;
day.mm = 0;
day.yyyy = 0;
/*
* Check (with the argument length) if a date or a number of days
* was entered, and then call app_arg() to print appointments
*/
arg_len = strlen(ddate);
if (arg_len <= 4) { /* a number of days was entered */
for (i = 0; i <= arg_len-1; i++) {
if (isdigit(ddate[i]))
num_digit++;
}
if (num_digit == arg_len)
numdays = atoi(ddate);
/*
* Get current date, and print appointments for each day
* in the chosen interval. app_found and add_line are used
* to format the output correctly.
*/
today = get_sec_date(day);
ind = today;
for (i = 0; i < numdays; i++) {
app_found = app_arg(add_line, day, ind);
add_line = app_found;
ind = ind + sec_in_day;
}
} else { /* a date was entered */
date_valid = check_date(ddate);
if (date_valid) {
sscanf(ddate, "%d / %d / %d", &day.mm, &day.dd, &day.yyyy);
app_found = app_arg(add_line, day, 0);
} else {
fputs(_("Argument to the '-d' flag is not valid\n"),
stdout);
fputs(_("Possible argument formats are : 'mm/dd/yyyy' or 'n'\n"),
stdout);
fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"),
stdout);
fputs
(_("Mail bug reports and suggestions to <calcurse@culot.org>.\n"),
stdout);
}
}
}
/* /*
* Parse the command-line arguments and call the appropriate * Parse the command-line arguments and call the appropriate
@ -161,9 +488,9 @@ parse_args(int argc, char **argv, conf_t *conf)
} else if (multiple_flag) { } else if (multiple_flag) {
if (load_data) { if (load_data) {
io_init(cfile); io_init(cfile);
no_file = check_data_files(); no_file = io_check_data_files();
if (dflag || aflag || nflag || xflag) if (dflag || aflag || nflag || xflag)
load_app(); io_load_app();
} }
if (xflag) { if (xflag) {
notify_init_vars(); notify_init_vars();
@ -192,369 +519,8 @@ parse_args(int argc, char **argv, conf_t *conf)
} else { } else {
non_interactive = 0; non_interactive = 0;
io_init(cfile); io_init(cfile);
no_file = check_data_files(); no_file = io_check_data_files();
} }
return (non_interactive); return (non_interactive);
} }
} }
/*
* Print Calcurse version with a short copyright text and exit.
*/
void version_arg()
{
char vtitle[BUFSIZ];
char *vtext =
_("\nCopyright (c) 2004-2007 Frederic Culot.\n"
"This is free software; see the source for copying conditions.\n");
snprintf(vtitle, BUFSIZ,
_("Calcurse %s - text-based organizer\n"), VERSION);
fputs(vtitle, stdout);
fputs(vtext, stdout);
}
/*
* Print the command line options and exit.
*/
void help_arg()
{
char htitle[BUFSIZ];
char *htext =
_("\nMiscellaneous:\n"
" -h, --help\n"
" print this help and exit.\n"
"\n -v, --version\n"
" print calcurse version and exit.\n"
"\nFiles:\n"
" -c <file>, --calendar <file>\n"
" specify the calendar <file> to use.\n"
"\nNon-interactive:\n"
" -a, --appointment\n"
" print events and appointments for current day and exit.\n"
"\n -d <date|num>, --day <date|num>\n"
" print events and appointments for <date> or <num> upcoming days and"
"\n\texit. Possible formats are: 'mm/dd/yyyy' or 'n'.\n"
"\n -n, --next\n"
" print next appointment within upcoming 24 hours "
"and exit. Also given\n\tis the remaining time before this "
"next appointment.\n"
"\n -t[num], --todo[=num]\n"
" print todo list and exit. If the optional number [num] is given,\n"
"\tthen only todos having a priority equal to [num] will be returned.\n"
"\tnote: priority number must be between 1 (highest) and 9 (lowest).\n"
"\n -x, --export\n"
" export user data to iCalendar format. Events, appointments and\n"
"\ttodos are converted and echoed to stdout.\n"
"\tnote: redirect standard output to export data to a file,\n"
"\tby issuing a command such as: calcurse --export > my_data.ics\n"
"\nFor more information, type '?' from within Calcurse, "
"or read the manpage.\n"
"Mail bug reports and suggestions to <calcurse@culot.org>.\n");
snprintf(htitle, BUFSIZ,
_("Calcurse %s - text-based organizer\n"), VERSION);
fputs(htitle, stdout);
usage();
fputs(htext, stdout);
}
/*
* Print todo list and exit. If a priority number is given (say not equal to
* zero), then only todo items that have this priority will be displayed.
*/
void todo_arg(int priority)
{
struct todo_s *i;
int nb_tod, title = 1;
char priority_str[BUFSIZ] = "";
nb_tod = load_todo();
for (i = todolist; i != 0; i = i->next) {
if (priority == 0 || i->id == priority) {
if (title) {
fputs(_("to do:\n"),stdout);
title = 0;
}
snprintf(priority_str, BUFSIZ, "%d. ", i->id);
fputs(priority_str,stdout);
fputs(i->mesg,stdout);
fputs("\n",stdout);
}
}
}
/* Print the next appointment within the upcoming 24 hours. */
void
next_arg(void)
{
struct notify_app_s *next_app;
long current_time;
int time_left, hours_left, min_left;
char mesg[BUFSIZ];
current_time = now();
next_app = (struct notify_app_s *) malloc(sizeof(struct notify_app_s));
next_app->time = current_time + DAYINSEC;
next_app->got_app = 0;
next_app = recur_apoint_check_next(next_app, current_time, get_today());
next_app = apoint_check_next(next_app, current_time);
time_left = next_app->time - current_time;
if (time_left > 0 && time_left < DAYINSEC) {
hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs(_("next appointment:\n"), stdout);
snprintf(mesg, BUFSIZ, " [%02d:%02d] %s\n",
hours_left, min_left, next_app->txt);
fputs(mesg, stdout);
}
free(next_app->txt);
free(next_app);
}
/*
* Print appointments for given day and exit.
* If no day is given, the given date is used.
* If there is also no date given, current date is considered.
*/
int app_arg(int add_line, date_t day, long date)
{
struct recur_event_s *re;
struct event_s *j;
recur_apoint_llist_node_t *ra;
apoint_llist_node_t *i;
long today;
bool print_date = true;
int app_found = 0;
char apoint_start_time[100];
char apoint_end_time[100];
if (date == 0)
today = get_sec_date(day);
else
today = date;
/*
* Calculate and print the selected date if there is an event for
* that date and it is the first one, and then print all the events for
* that date.
*/
for (re = recur_elist; re != 0; re = re->next) {
if (recur_item_inday(re->day, re->exc, re->rpt->type,
re->rpt->freq, re->rpt->until, today)) {
app_found = 1;
if (add_line) {
fputs("\n", stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
fputs(" o ", stdout);
fputs(re->mesg, stdout); fputs("\n", stdout);
}
}
for (j = eventlist; j != 0; j = j->next) {
if (event_inday(j, today)) {
app_found = 1;
if (add_line) {
fputs("\n",stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
fputs(" o ",stdout);
fputs(j->mesg,stdout); fputs("\n",stdout);
}
}
/* Same process is performed but this time on the appointments. */
pthread_mutex_lock(&(recur_alist_p->mutex));
for (ra = recur_alist_p->root; ra != 0; ra = ra->next) {
if (recur_item_inday(ra->start, ra->exc, ra->rpt->type,
ra->rpt->freq, ra->rpt->until, today)) {
app_found = 1;
if (add_line) {
fputs("\n",stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
apoint_sec2str(apoint_recur_s2apoint_s(ra),
RECUR_APPT, today, apoint_start_time,
apoint_end_time);
fputs(" - ",stdout);
fputs(apoint_start_time,stdout);
fputs(" -> ",stdout);
fputs(apoint_end_time,stdout); fputs("\n\t",stdout);
fputs(ra->mesg,stdout); fputs("\n",stdout);
}
}
pthread_mutex_unlock(&(recur_alist_p->mutex));
pthread_mutex_lock(&(alist_p->mutex));
for (i = alist_p->root; i != 0; i = i->next) {
if (apoint_inday(i, today)) {
app_found = 1;
if (add_line) {
fputs("\n",stdout);
add_line = 0;
}
if (print_date) {
arg_print_date(today);
print_date = false;
}
apoint_sec2str(i, APPT, today, apoint_start_time,
apoint_end_time);
fputs(" - ",stdout);
fputs(apoint_start_time,stdout);
fputs(" -> ",stdout);
fputs(apoint_end_time,stdout); fputs("\n\t",stdout);
fputs(i->mesg,stdout); fputs("\n",stdout);
}
}
pthread_mutex_unlock(&(alist_p->mutex));
return app_found;
}
/*
* Print appointment for the given date or for the given n upcoming
* days.
*/
void date_arg(char *ddate, int add_line)
{
int i;
date_t day;
int numdays = 0, num_digit = 0;
int arg_len = 0, app_found = 0;
int date_valid = 0;
long today, ind;
int sec_in_day = 86400;
day.dd = 0;
day.mm = 0;
day.yyyy = 0;
/*
* Check (with the argument length) if a date or a number of days
* was entered, and then call app_arg() to print appointments
*/
arg_len = strlen(ddate);
if (arg_len <= 4) { /* a number of days was entered */
for (i = 0; i <= arg_len-1; i++) {
if (isdigit(ddate[i]))
num_digit++;
}
if (num_digit == arg_len)
numdays = atoi(ddate);
/*
* Get current date, and print appointments for each day
* in the chosen interval. app_found and add_line are used
* to format the output correctly.
*/
today = get_sec_date(day);
ind = today;
for (i = 0; i < numdays; i++) {
app_found = app_arg(add_line, day, ind);
add_line = app_found;
ind = ind + sec_in_day;
}
} else { /* a date was entered */
date_valid = check_date(ddate);
if (date_valid) {
sscanf(ddate, "%d / %d / %d", &day.mm, &day.dd, &day.yyyy);
app_found = app_arg(add_line, day, 0);
} else {
fputs(_("Argument to the '-d' flag is not valid\n"),
stdout);
fputs(_("Possible argument formats are : 'mm/dd/yyyy' or 'n'\n"),
stdout);
fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"),
stdout);
fputs
(_("Mail bug reports and suggestions to <calcurse@culot.org>.\n"),
stdout);
}
}
}
/*
* Check if the entered date is of a valid format.
* First check the format by itself, and then check the
* numbers correctness.
*/
int
check_date(char *date)
{
int ok = 0;
char month[3] = "";
char day[3] = "";
char year[5] = "";
if (
(strlen(date) == 10) &
(isdigit(date[0]) != 0) &
(isdigit(date[1]) != 0) &
(date[2] == '/') &
(isdigit(date[3]) != 0) &
(isdigit(date[4]) != 0) &
(date[5] == '/') &
(isdigit(date[6])!=0) & (isdigit(date[7])!=0) &
(isdigit(date[8])!=0) & (isdigit(date[9])!=0)
) {
strncpy(month, date, 2);
strncpy(day, date + 3, 2);
strncpy(year, date + 6, 4);
if ( (atoi(month) <= 12) &
(atoi(month) >= 1) &
(atoi(day) <= 31) &
(atoi(day) >= 1) &
(atoi(year) <= 9999) &
(atoi(year) > 1))
ok = 1;
}
return ok;
}
/*
* Print the date on stdout.
*/
void arg_print_date(long date)
{
char date_str[BUFSIZ];
time_t t;
struct tm *lt;
t = date;
lt = localtime(&t);
snprintf(date_str, BUFSIZ, "%02u/%02u/%04u",
lt->tm_mon+1, lt->tm_mday, 1900+lt->tm_year);
fputs(date_str,stdout);
fputs(":\n",stdout);
}
/*
* Print Calcurse usage and exit.
*/
void usage()
{
char *arg_usage =
_("Usage: calcurse [-h|-v] [-x] [-an] [-t[num]] [-d date|num] [-c file]\n");
fputs(arg_usage, stdout);
}
void usage_try()
{
char *arg_usage_try =
_("Try 'calcurse -h' for more information.\n");
fputs(arg_usage_try, stdout);
}

View File

@ -1,4 +1,4 @@
/* $calcurse: args.h,v 1.7 2007/07/01 17:56:08 culot Exp $ */ /* $calcurse: args.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,18 +27,6 @@
#ifndef CALCURSE_ARGS_H #ifndef CALCURSE_ARGS_H
#define CALCURSE_ARGS_H #define CALCURSE_ARGS_H
#include "vars.h" int parse_args(int, char **, conf_t *);
void usage();
void usage_try();
int parse_args(int argc, char **argv, conf_t *conf);
void version_arg();
void help_arg();
void todo_arg(int priority);
void next_arg(void);
int app_arg(int add_line, date_t day, long date);
void date_arg(char *ddate, int add_line);
int check_date(char *date);
void arg_print_date(long date);
#endif /* CALCURSE_ARGS_H */ #endif /* CALCURSE_ARGS_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: calcurse.c,v 1.50 2007/07/26 20:35:58 culot Exp $ */ /* $calcurse: calcurse.c,v 1.51 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -160,11 +160,11 @@ main(int argc, char **argv)
* configuration (the display is then updated), and then * configuration (the display is then updated), and then
* the todo list, appointments and events. * the todo list, appointments and events.
*/ */
no_data_file = check_data_files(); no_data_file = io_check_data_files();
custom_load_conf(&conf, background); custom_load_conf(&conf, background);
erase_status_bar(); erase_status_bar();
nb_tod = load_todo(); nb_tod = io_load_todo();
load_app(); io_load_app();
if (notify_bar()) { if (notify_bar()) {
notify_start_main_thread(); notify_start_main_thread();
notify_check_next_app(); notify_check_next_app();
@ -175,7 +175,7 @@ main(int argc, char **argv)
&win[TODO], &win[CALENDAR], &win[NOTIFY]); &win[TODO], &win[CALENDAR], &win[NOTIFY]);
wins_update(&conf, &win[STATUS], &win[APPOINTMENT], &win[TODO], wins_update(&conf, &win[STATUS], &win[APPOINTMENT], &win[TODO],
hilt_app, hilt_tod, nb_tod, first_todo_onscreen, &saved_t_mesg); hilt_app, hilt_tod, nb_tod, first_todo_onscreen, &saved_t_mesg);
startup_screen(conf.skip_system_dialogs, no_data_file); io_startup_screen(conf.skip_system_dialogs, no_data_file);
inday = *day_process_storage(0, day_changed, &inday); inday = *day_process_storage(0, day_changed, &inday);
wins_slctd_set(CALENDAR); wins_slctd_set(CALENDAR);
wins_update(&conf, &win[STATUS], &win[APPOINTMENT], &win[TODO], wins_update(&conf, &win[STATUS], &win[APPOINTMENT], &win[TODO],

View File

@ -1,4 +1,4 @@
/* $calcurse: calendar.c,v 1.8 2007/07/01 17:48:50 culot Exp $ */ /* $calcurse: calendar.c,v 1.9 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,13 +24,10 @@
* *
*/ */
#include <ncurses.h>
#include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdbool.h>
#include <time.h> #include <time.h>
#include "i18n.h" #include "i18n.h"

View File

@ -1,4 +1,4 @@
/* $calcurse: calendar.h,v 1.4 2007/07/21 19:39:23 culot Exp $ */ /* $calcurse: calendar.h,v 1.5 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,8 +27,8 @@
#ifndef CALCURSE_CALENDAR_H #ifndef CALCURSE_CALENDAR_H
#define CALCURSE_CALENDAR_H #define CALCURSE_CALENDAR_H
#include <stdbool.h>
#include <ncurses.h> #include <ncurses.h>
#include <stdbool.h>
#define CALHEIGHT 12 #define CALHEIGHT 12
#define CALWIDTH 30 #define CALWIDTH 30

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.c,v 1.14 2007/07/21 19:34:07 culot Exp $ */ /* $calcurse: custom.c,v 1.15 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,16 +24,12 @@
* *
*/ */
#include <ncurses.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include "calendar.h"
#include "custom.h" #include "custom.h"
#include "i18n.h" #include "i18n.h"
#include "io.h" #include "io.h"
#include "wins.h"
#include "utils.h" #include "utils.h"
#include "apoint.h" #include "apoint.h"
@ -53,6 +49,111 @@ fill_config_var(char *string)
} }
} }
/*
* Load user color theme from file.
* Need to handle calcurse versions prior to 1.8, where colors where handled
* differently (number between 1 and 8).
*/
static void
custom_load_color(char *color, int background)
{
#define AWAITED_COLORS 2
int i, len, color_num;
char c[AWAITED_COLORS][BUFSIZ];
int colr[AWAITED_COLORS];
const char *wrong_color_number =
_("FATAL ERROR in custom_load_color: wrong color number.\n");
const char *wrong_color_name =
_("FATAL ERROR in custom_load_color: wrong color name.\n");
const char *wrong_variable_format =
_("FATAL ERROR in custom_load_color: "
"wrong configuration variable format.\n");
len = strlen(color);
if (len > 1) {
/* New version configuration */
if (sscanf(color, "%s on %s", c[0], c[1]) != AWAITED_COLORS) {
fputs(_("FATAL ERROR in custom_load_color: "
"missing colors in config file.\n"), stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
};
for (i = 0; i < AWAITED_COLORS; i++) {
if (!strncmp(c[i], "black", 5))
colr[i] = COLOR_BLACK;
else if (!strncmp(c[i], "red", 3))
colr[i] = COLOR_RED;
else if (!strncmp(c[i], "green", 5))
colr[i] = COLOR_GREEN;
else if (!strncmp(c[i], "yellow", 6))
colr[i] = COLOR_YELLOW;
else if (!strncmp(c[i], "blue", 4))
colr[i] = COLOR_BLUE;
else if (!strncmp(c[i], "magenta", 7))
colr[i] = COLOR_MAGENTA;
else if (!strncmp(c[i], "cyan", 4))
colr[i] = COLOR_CYAN;
else if (!strncmp(c[i], "white", 5))
colr[i] = COLOR_WHITE;
else if (!strncmp(c[i], "default", 7))
colr[i] = background;
else {
fputs(wrong_color_name, stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
}
}
init_pair(COLR_CUSTOM, colr[0], colr[1]);
} else if (len > 0 && len < 2) {
/* Old version configuration */
color_num = atoi(color);
switch (color_num) {
case 0:
colorize = false;
break;
case 1:
init_pair(COLR_CUSTOM, COLOR_RED, background);
break;
case 2:
init_pair(COLR_CUSTOM, COLOR_GREEN, background);
break;
case 3:
init_pair(COLR_CUSTOM, COLOR_BLUE, background);
break;
case 4:
init_pair(COLR_CUSTOM, COLOR_CYAN, background);
break;
case 5:
init_pair(COLR_CUSTOM, COLOR_YELLOW, background);
break;
case 6:
init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_GREEN);
break;
case 7:
init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_YELLOW);
break;
case 8:
init_pair(COLR_CUSTOM, COLOR_RED, COLR_BLUE);
break;
default:
fputs(wrong_color_number, stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
}
} else {
fputs(wrong_variable_format, stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
}
}
/* /*
* Define window attributes (for both color and non-color terminals): * Define window attributes (for both color and non-color terminals):
* ATTR_HIGHEST are for window titles * ATTR_HIGHEST are for window titles
@ -488,111 +589,6 @@ custom_color_config(int notify_bar)
delwin(conf_win); delwin(conf_win);
} }
/*
* Load user color theme from file.
* Need to handle calcurse versions prior to 1.8, where colors where handled
* differently (number between 1 and 8).
*/
void
custom_load_color(char *color, int background)
{
#define AWAITED_COLORS 2
int i, len, color_num;
char c[AWAITED_COLORS][BUFSIZ];
int colr[AWAITED_COLORS];
const char *wrong_color_number =
_("FATAL ERROR in custom_load_color: wrong color number.\n");
const char *wrong_color_name =
_("FATAL ERROR in custom_load_color: wrong color name.\n");
const char *wrong_variable_format =
_("FATAL ERROR in custom_load_color: "
"wrong configuration variable format.\n");
len = strlen(color);
if (len > 1) {
/* New version configuration */
if (sscanf(color, "%s on %s", c[0], c[1]) != AWAITED_COLORS) {
fputs(_("FATAL ERROR in custom_load_color: "
"missing colors in config file.\n"), stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
};
for (i = 0; i < AWAITED_COLORS; i++) {
if (!strncmp(c[i], "black", 5))
colr[i] = COLOR_BLACK;
else if (!strncmp(c[i], "red", 3))
colr[i] = COLOR_RED;
else if (!strncmp(c[i], "green", 5))
colr[i] = COLOR_GREEN;
else if (!strncmp(c[i], "yellow", 6))
colr[i] = COLOR_YELLOW;
else if (!strncmp(c[i], "blue", 4))
colr[i] = COLOR_BLUE;
else if (!strncmp(c[i], "magenta", 7))
colr[i] = COLOR_MAGENTA;
else if (!strncmp(c[i], "cyan", 4))
colr[i] = COLOR_CYAN;
else if (!strncmp(c[i], "white", 5))
colr[i] = COLOR_WHITE;
else if (!strncmp(c[i], "default", 7))
colr[i] = background;
else {
fputs(wrong_color_name, stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
}
}
init_pair(COLR_CUSTOM, colr[0], colr[1]);
} else if (len > 0 && len < 2) {
/* Old version configuration */
color_num = atoi(color);
switch (color_num) {
case 0:
colorize = false;
break;
case 1:
init_pair(COLR_CUSTOM, COLOR_RED, background);
break;
case 2:
init_pair(COLR_CUSTOM, COLOR_GREEN, background);
break;
case 3:
init_pair(COLR_CUSTOM, COLOR_BLUE, background);
break;
case 4:
init_pair(COLR_CUSTOM, COLOR_CYAN, background);
break;
case 5:
init_pair(COLR_CUSTOM, COLOR_YELLOW, background);
break;
case 6:
init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_GREEN);
break;
case 7:
init_pair(COLR_CUSTOM, COLOR_BLACK, COLR_YELLOW);
break;
case 8:
init_pair(COLR_CUSTOM, COLOR_RED, COLR_BLUE);
break;
default:
fputs(wrong_color_number, stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
}
} else {
fputs(wrong_variable_format, stderr);
exit(EXIT_FAILURE);
/* NOTREACHED */
}
}
/* /*
* Return a string defining the color theme in the form: * Return a string defining the color theme in the form:
* foreground color 'on' background color * foreground color 'on' background color

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.h,v 1.7 2007/07/21 19:34:07 culot Exp $ */ /* $calcurse: custom.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -73,7 +73,6 @@ void custom_load_conf(conf_t *, int);
void config_bar(void); void config_bar(void);
int layout_config(int); int layout_config(int);
void custom_color_config(int); void custom_color_config(int);
void custom_load_color(char *, int);
void custom_color_theme_name(char *); void custom_color_theme_name(char *);
void custom_general_config(conf_t *); void custom_general_config(conf_t *);

493
src/day.c
View File

@ -1,4 +1,4 @@
/* $calcurse: day.c,v 1.24 2007/07/20 19:05:19 culot Exp $ */ /* $calcurse: day.c,v 1.25 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,26 +24,235 @@
* *
*/ */
#include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <ctype.h> #include <ctype.h>
#include <stdbool.h>
#include <time.h> #include <time.h>
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "apoint.h" #include "apoint.h"
#include "event.h" #include "event.h"
#include "recur.h"
#include "day.h" #include "day.h"
#include "vars.h"
#include "args.h"
static struct day_item_s *day_items_ptr; static struct day_item_s *day_items_ptr;
static struct day_saved_item_s *day_saved_item = NULL; static struct day_saved_item_s *day_saved_item = NULL;
/* Free the current day linked list containing the events and appointments. */
static void
day_free_list(void)
{
struct day_item_s *p, *q;
for (p = day_items_ptr; p != 0; p = q) {
q = p->next;
free(p->mesg);
free(p);
}
day_items_ptr = NULL;
}
/* Add an event in the current day list */
static struct day_item_s *
day_add_event(int type, char *mesg, long day, int id)
{
struct day_item_s *o, **i;
o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
o->mesg = (char *) malloc(strlen(mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1);
o->type = type;
o->appt_dur = 0;
o->appt_pos = 0;
o->start = day;
o->evnt_id = id;
i = &day_items_ptr;
for (;;) {
if (*i == 0) {
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
}
/* Add an appointment in the current day list. */
static struct day_item_s *
day_add_apoint(int type, char *mesg, long start, long dur, char state,
int real_pos)
{
struct day_item_s *o, **i;
int insert_item = 0;
o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
o->mesg = (char *) malloc(strlen(mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1);
o->start = start;
o->appt_dur = dur;
o->appt_pos = real_pos;
o->state = state;
o->type = type;
o->evnt_id = 0;
i = &day_items_ptr;
for (;;) {
if (*i == 0) {
insert_item = 1;
} else if ( ((*i)->start > start) &&
((*i)->type > EVNT) ) {
insert_item = 1;
}
if (insert_item) {
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
}
/*
* Store the events for the selected day in structure pointed
* by day_items_ptr. This is done by copying the events
* from the general structure pointed by eventlist to the structure
* dedicated to the selected day.
* Returns the number of events for the selected day.
*/
static int
day_store_events(long date)
{
struct event_s *j;
struct day_item_s *ptr;
int e_nb = 0;
for (j = eventlist; j != 0; j = j->next) {
if (event_inday(j, date)) {
e_nb++;
ptr = day_add_event(EVNT, j->mesg, j->day, j->id);
}
}
return e_nb;
}
/*
* Store the recurrent events for the selected day in structure pointed
* by day_items_ptr. This is done by copying the recurrent events
* from the general structure pointed by recur_elist to the structure
* dedicated to the selected day.
* Returns the number of recurrent events for the selected day.
*/
static int
day_store_recur_events(long date)
{
struct recur_event_s *j;
struct day_item_s *ptr;
int e_nb = 0;
for (j = recur_elist; j != 0; j = j->next) {
if (recur_item_inday(j->day, j->exc, j->rpt->type, j->rpt->freq,
j->rpt->until, date)) {
e_nb++;
ptr = day_add_event(RECUR_EVNT, j->mesg, j->day, j->id);
}
}
return e_nb;
}
/*
* Store the apoints for the selected day in structure pointed
* by day_items_ptr. This is done by copying the appointments
* from the general structure pointed by alist_p->root to the
* structure dedicated to the selected day.
* Returns the number of appointments for the selected day.
*/
static int
day_store_apoints(long date)
{
apoint_llist_node_t *j;
struct day_item_s *ptr;
int a_nb = 0;
pthread_mutex_lock(&(alist_p->mutex));
for (j = alist_p->root; j != 0; j = j->next) {
if (apoint_inday(j, date)) {
a_nb++;
ptr = day_add_apoint(APPT, j->mesg, j->start, j->dur,
j->state, 0);
}
}
pthread_mutex_unlock(&(alist_p->mutex));
return a_nb;
}
/*
* Store the recurrent apoints for the selected day in structure pointed
* by day_items_ptr. This is done by copying the appointments
* from the general structure pointed by recur_alist_p->root to the
* structure dedicated to the selected day.
* Returns the number of recurrent appointments for the selected day.
*/
static int
day_store_recur_apoints(long date)
{
recur_apoint_llist_node_t *j;
struct day_item_s *ptr;
long real_start;
int a_nb = 0, n = 0;
pthread_mutex_lock(&(recur_alist_p->mutex));
for (j = recur_alist_p->root; j != 0; j = j->next) {
if ((real_start = recur_item_inday(j->start, j->exc,
j->rpt->type, j->rpt->freq, j->rpt->until, date)) ){
a_nb++;
ptr = day_add_apoint(
RECUR_APPT, j->mesg, real_start, j->dur,
j->state, n);
n++;
}
}
pthread_mutex_unlock(&(recur_alist_p->mutex));
return a_nb;
}
/*
* Store all of the items to be displayed for the selected day.
* Items are of four types: recursive events, normal events,
* recursive appointments and normal appointments.
* The items are stored in the linked list pointed by *day_items_ptr
* and the length of the new pad to write is returned.
* The number of events and appointments in the current day are also updated.
*/
static int
day_store_items(long date, int *pnb_events, int *pnb_apoints)
{
int pad_length;
int nb_events, nb_recur_events;
int nb_apoints, nb_recur_apoints;
pad_length = nb_events = nb_apoints = 0;
nb_recur_events = nb_recur_apoints = 0;
if (day_items_ptr != 0)
day_free_list();
nb_recur_events = day_store_recur_events(date);
nb_events = day_store_events(date);
*pnb_events = nb_events;
nb_recur_apoints = day_store_recur_apoints(date);
nb_apoints = day_store_apoints(date);
*pnb_apoints = nb_apoints;
pad_length = nb_recur_events + nb_events + 1 +
3*(nb_recur_apoints + nb_apoints);
*pnb_apoints += nb_recur_apoints;
*pnb_events += nb_recur_events;
return pad_length;
}
/* /*
* Store the events and appointments for the selected day, and write * Store the events and appointments for the selected day, and write
@ -80,210 +289,21 @@ day_process_storage(date_t *slctd_date, bool day_changed, day_items_nb_t *inday)
} }
/* /*
* Store all of the items to be displayed for the selected day. * Returns a structure of type apoint_llist_node_t given a structure of type
* Items are of four types: recursive events, normal events, * day_item_s
* recursive appointments and normal appointments.
* The items are stored in the linked list pointed by *day_items_ptr
* and the length of the new pad to write is returned.
* The number of events and appointments in the current day are also updated.
*/ */
int day_store_items(long date, int *pnb_events, int *pnb_apoints) static apoint_llist_node_t *
day_item_s2apoint_s(struct day_item_s *p)
{ {
int pad_length; apoint_llist_node_t *a;
int nb_events, nb_recur_events;
int nb_apoints, nb_recur_apoints;
pad_length = nb_events = nb_apoints = 0; a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
nb_recur_events = nb_recur_apoints = 0; a->mesg = (char *) malloc(strlen(p->mesg) + 1);
a->state = p->state;
if (day_items_ptr != 0) a->start = p->start;
day_free_list(); a->dur = p->appt_dur;
nb_recur_events = day_store_recur_events(date); a->mesg = p->mesg;
nb_events = day_store_events(date); return a;
*pnb_events = nb_events;
nb_recur_apoints = day_store_recur_apoints(date);
nb_apoints = day_store_apoints(date);
*pnb_apoints = nb_apoints;
pad_length = nb_recur_events + nb_events + 1 +
3*(nb_recur_apoints + nb_apoints);
*pnb_apoints += nb_recur_apoints;
*pnb_events += nb_recur_events;
return pad_length;
}
/* Free the current day linked list containing the events and appointments. */
void day_free_list(void)
{
struct day_item_s *p, *q;
for (p = day_items_ptr; p != 0; p = q) {
q = p->next;
free(p->mesg);
free(p);
}
day_items_ptr = NULL;
}
/*
* Store the recurrent events for the selected day in structure pointed
* by day_items_ptr. This is done by copying the recurrent events
* from the general structure pointed by recur_elist to the structure
* dedicated to the selected day.
* Returns the number of recurrent events for the selected day.
*/
int day_store_recur_events(long date)
{
struct recur_event_s *j;
struct day_item_s *ptr;
int e_nb = 0;
for (j = recur_elist; j != 0; j = j->next) {
if (recur_item_inday(j->day, j->exc, j->rpt->type, j->rpt->freq,
j->rpt->until, date)) {
e_nb++;
ptr = day_add_event(RECUR_EVNT, j->mesg, j->day, j->id);
}
}
return e_nb;
}
/*
* Store the events for the selected day in structure pointed
* by day_items_ptr. This is done by copying the events
* from the general structure pointed by eventlist to the structure
* dedicated to the selected day.
* Returns the number of events for the selected day.
*/
int day_store_events(long date)
{
struct event_s *j;
struct day_item_s *ptr;
int e_nb = 0;
for (j = eventlist; j != 0; j = j->next) {
if (event_inday(j, date)) {
e_nb++;
ptr = day_add_event(EVNT, j->mesg, j->day, j->id);
}
}
return e_nb;
}
/*
* Store the recurrent apoints for the selected day in structure pointed
* by day_items_ptr. This is done by copying the appointments
* from the general structure pointed by recur_alist_p->root to the
* structure dedicated to the selected day.
* Returns the number of recurrent appointments for the selected day.
*/
int day_store_recur_apoints(long date)
{
recur_apoint_llist_node_t *j;
struct day_item_s *ptr;
long real_start;
int a_nb = 0, n = 0;
pthread_mutex_lock(&(recur_alist_p->mutex));
for (j = recur_alist_p->root; j != 0; j = j->next) {
if ((real_start = recur_item_inday(j->start, j->exc,
j->rpt->type, j->rpt->freq, j->rpt->until, date)) ){
a_nb++;
ptr = day_add_apoint(
RECUR_APPT, j->mesg, real_start, j->dur,
j->state, n);
n++;
}
}
pthread_mutex_unlock(&(recur_alist_p->mutex));
return a_nb;
}
/*
* Store the apoints for the selected day in structure pointed
* by day_items_ptr. This is done by copying the appointments
* from the general structure pointed by alist_p->root to the
* structure dedicated to the selected day.
* Returns the number of appointments for the selected day.
*/
int day_store_apoints(long date)
{
apoint_llist_node_t *j;
struct day_item_s *ptr;
int a_nb = 0;
pthread_mutex_lock(&(alist_p->mutex));
for (j = alist_p->root; j != 0; j = j->next) {
if (apoint_inday(j, date)) {
a_nb++;
ptr = day_add_apoint(APPT, j->mesg, j->start, j->dur,
j->state, 0);
}
}
pthread_mutex_unlock(&(alist_p->mutex));
return a_nb;
}
/* Add an event in the current day list */
struct day_item_s *day_add_event(int type, char *mesg, long day, int id)
{
struct day_item_s *o, **i;
o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
o->mesg = (char *) malloc(strlen(mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1);
o->type = type;
o->appt_dur = 0;
o->appt_pos = 0;
o->start = day;
o->evnt_id = id;
i = &day_items_ptr;
for (;;) {
if (*i == 0) {
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
}
/* Add an appointment in the current day list. */
struct day_item_s *day_add_apoint(int type, char *mesg, long start, long dur,
char state, int real_pos)
{
struct day_item_s *o, **i;
int insert_item = 0;
o = (struct day_item_s *) malloc(sizeof(struct day_item_s));
o->mesg = (char *) malloc(strlen(mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1);
o->start = start;
o->appt_dur = dur;
o->appt_pos = real_pos;
o->state = state;
o->type = type;
o->evnt_id = 0;
i = &day_items_ptr;
for (;;) {
if (*i == 0) {
insert_item = 1;
} else if ( ((*i)->start > start) &&
((*i)->type > EVNT) ) {
insert_item = 1;
}
if (insert_item) {
o->next = *i;
*i = o;
break;
}
i = &(*i)->next;
}
return o;
} }
/* /*
@ -355,23 +375,6 @@ day_write_pad(long date, int width, int length, int incolor)
} }
} }
/*
* Returns a structure of type apoint_llist_node_t given a structure of type
* day_item_s
*/
apoint_llist_node_t *day_item_s2apoint_s(struct day_item_s *p)
{
apoint_llist_node_t *a;
a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
a->mesg = (char *) malloc(strlen(p->mesg) + 1);
a->state = p->state;
a->start = p->start;
a->dur = p->appt_dur;
a->mesg = p->mesg;
return a;
}
/* Display an item inside a popup window. */ /* Display an item inside a popup window. */
void day_popup_item(void) void day_popup_item(void)
{ {
@ -431,6 +434,27 @@ void day_popup_item(void)
return 0; return 0;
} }
/* Request the user to enter a new time. */
static char *
day_edit_time(long time) {
char *timestr;
char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
char *enter_str = _("Press [Enter] to continue");
char *fmt_msg =
_("You entered an invalid time, should be [h:mm] or [hh:mm]");
while (1) {
status_mesg(msg_time, "");
timestr = date_sec2hour_str(time);
updatestring(swin, &timestr, 0, 1);
if (check_time(timestr) != 1 || strlen(timestr) == 0) {
status_mesg(fmt_msg, enter_str);
wgetch(swin);
} else
return timestr;
}
}
/* Edit an already existing item. */ /* Edit an already existing item. */
void void
day_edit_item(int item_num) day_edit_item(int item_num)
@ -644,27 +668,6 @@ day_edit_item(int item_num)
} }
} }
/* Request the user to enter a new time. */
char *
day_edit_time(long time) {
char *timestr;
char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : ");
char *enter_str = _("Press [Enter] to continue");
char *fmt_msg =
_("You entered an invalid time, should be [h:mm] or [hh:mm]");
while (1) {
status_mesg(msg_time, "");
timestr = date_sec2hour_str(time);
updatestring(swin, &timestr, 0, 1);
if (check_time(timestr) != 1 || strlen(timestr) == 0) {
status_mesg(fmt_msg, enter_str);
wgetch(swin);
} else
return timestr;
}
}
/* /*
* In order to erase an item, we need to count first the number of * In order to erase an item, we need to count first the number of
* items for each type (in order: recurrent events, events, * items for each type (in order: recurrent events, events,

View File

@ -1,4 +1,4 @@
/* $calcurse: day.h,v 1.13 2007/07/20 19:07:02 culot Exp $ */ /* $calcurse: day.h,v 1.14 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,10 +27,7 @@
#ifndef CALCURSE_DAY_H #ifndef CALCURSE_DAY_H
#define CALCURSE_DAY_H #define CALCURSE_DAY_H
#include <stdio.h>
#include "calendar.h" #include "calendar.h"
#include "apoint.h"
#define MAX_TYPES 4 #define MAX_TYPES 4
@ -64,20 +61,10 @@ struct day_saved_item_s {
}; };
day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *); day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *);
int day_store_items(long, int *, int *);
void day_free_list(void);
int day_store_recur_events(long);
int day_store_events(long);
int day_store_recur_apoints(long);
int day_store_apoints(long);
struct day_item_s *day_add_event(int, char *, long, int);
struct day_item_s *day_add_apoint(int, char *, long, long, char, int);
void day_write_pad(long, int, int, int); void day_write_pad(long, int, int, int);
apoint_llist_node_t *day_item_s2apoint_s(struct day_item_s *);
void day_popup_item(void); void day_popup_item(void);
int day_check_if_item(date_t); int day_check_if_item(date_t);
void day_edit_item(int); void day_edit_item(int);
char *day_edit_time(long);
int day_erase_item(long, int, int); int day_erase_item(long, int, int);
struct day_item_s *day_get_item(int); struct day_item_s *day_get_item(int);
int day_item_nb(long, int, int); int day_item_nb(long, int, int);

View File

@ -1,4 +1,4 @@
/* $calcurse: event.c,v 1.3 2007/04/04 19:37:14 culot Exp $ */ /* $calcurse: event.c,v 1.4 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,7 +24,6 @@
* *
*/ */
#include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -33,7 +32,6 @@
#include "vars.h" #include "vars.h"
#include "i18n.h" #include "i18n.h"
#include "event.h" #include "event.h"
#include "utils.h"
struct event_s *eventlist; struct event_s *eventlist;

View File

@ -1,4 +1,4 @@
/* $calcurse: event.h,v 1.1 2006/07/31 21:00:03 culot Exp $ */ /* $calcurse: event.h,v 1.2 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -40,9 +40,9 @@ struct event_s {
extern struct event_s *eventlist; extern struct event_s *eventlist;
struct event_s *event_new(char *, long, int); struct event_s *event_new(char *, long, int);
unsigned event_inday(struct event_s *o, long start); unsigned event_inday(struct event_s *, long);
void event_write(struct event_s *o, FILE * f); void event_write(struct event_s *, FILE *);
struct event_s *event_scan(FILE * f, struct tm start, int id); struct event_s *event_scan(FILE *, struct tm, int);
void event_delete_bynum(long start, unsigned num); void event_delete_bynum(long, unsigned);
#endif /* CALCURSE_EVENT_H */ #endif /* CALCURSE_EVENT_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: help.c,v 1.18 2007/07/23 19:29:34 culot Exp $ */ /* $calcurse: help.c,v 1.19 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,28 +24,35 @@
* *
*/ */
#include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#include "i18n.h" #include "i18n.h"
#include "help.h" #include "help.h"
#include "custom.h" #include "custom.h"
#include "vars.h"
#include "utils.h" #include "utils.h"
#include "apoint.h"
#include "notify.h" #include "notify.h"
#include "wins.h"
/* Returns the number of lines in an help text. */
static int
get_help_lines(char *text)
{
int i;
int nl = 0;
for (i = 0; text[i]; i++) {
if (text[i] == '\n') nl++;
}
return nl + 1;
}
/* /*
* Write the desired help text inside the help pad, and return the number * Write the desired help text inside the help pad, and return the number
* of lines that were written. * of lines that were written.
* */ */
int static int
write_help_pad(WINDOW *win, char *title, char *text, int pad_width) write_help_pad(WINDOW *win, char *title, char *text, int pad_width)
{ {
int nl_title = 0; int nl_title = 0;
@ -61,18 +68,6 @@ write_help_pad(WINDOW *win, char *title, char *text, int pad_width)
return nl_text + nl_title; return nl_text + nl_title;
} }
int
get_help_lines(char *text)
{
int i;
int nl = 0;
for (i = 0; text[i]; i++) {
if (text[i] == '\n') nl++;
}
return nl + 1;
}
/* Draws the help screen */ /* Draws the help screen */
void void
help_screen(void) help_screen(void)

View File

@ -1,4 +1,4 @@
/* $calcurse: help.h,v 1.3 2007/07/23 19:29:34 culot Exp $ */ /* $calcurse: help.h,v 1.4 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,15 +27,11 @@
#ifndef CALCURSE_HELP_H #ifndef CALCURSE_HELP_H
#define CALCURSE_HELP_H #define CALCURSE_HELP_H
#include <ncurses.h>
typedef struct { typedef struct {
char *title; char *title;
char *text; char *text;
} help_page_t; } help_page_t;
int write_help_pad(WINDOW *, char *, char *, int);
int get_help_lines(char *);
void help_screen(void); void help_screen(void);
#endif /* CALCURSE_HELP_H */ #endif /* CALCURSE_HELP_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.17 2007/07/01 17:57:57 culot Exp $ */ /* $calcurse: io.c,v 1.18 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,13 +24,8 @@
* *
*/ */
#include <ncurses.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
@ -42,9 +37,7 @@
#include "todo.h" #include "todo.h"
#include "event.h" #include "event.h"
#include "apoint.h" #include "apoint.h"
#include "recur.h"
#include "io.h" #include "io.h"
#include "calendar.h"
typedef enum { typedef enum {
PROGRESS_BAR_SAVE, PROGRESS_BAR_SAVE,
@ -548,7 +541,7 @@ io_save_cal(conf_t *conf)
* recursive item (which can also be either an event or an appointment). * recursive item (which can also be either an event or an appointment).
*/ */
void void
load_app(void) io_load_app(void)
{ {
FILE *data_file; FILE *data_file;
int c, is_appointment, is_event, is_recursive; int c, is_appointment, is_event, is_recursive;
@ -559,7 +552,7 @@ load_app(void)
int freq; int freq;
char type, state; char type, state;
char *error = char *error =
_("FATAL ERROR in load_app: wrong format in the appointment or event\n"); _("FATAL ERROR in io_load_app: wrong format in the appointment or event\n");
t = time(NULL); t = time(NULL);
lt = localtime(&t); lt = localtime(&t);
@ -578,7 +571,7 @@ load_app(void)
*/ */
if (fscanf(data_file, "%u / %u / %u ", if (fscanf(data_file, "%u / %u / %u ",
&start.tm_mon, &start.tm_mday, &start.tm_year) != 3) { &start.tm_mon, &start.tm_mday, &start.tm_year) != 3) {
fputs(_("FATAL ERROR in load_app: " fputs(_("FATAL ERROR in io_load_app: "
"syntax error in the item date\n"), stderr); "syntax error in the item date\n"), stderr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -593,7 +586,7 @@ load_app(void)
else if (c == '[') else if (c == '[')
is_event = 1; is_event = 1;
else { else {
fputs(_("FATAL ERROR in load_app: " fputs(_("FATAL ERROR in io_load_app: "
"no event nor appointment found\n"), stderr); "no event nor appointment found\n"), stderr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -689,7 +682,7 @@ load_app(void)
/* Load the todo data */ /* Load the todo data */
int int
load_todo(void) io_load_todo(void)
{ {
FILE *data_file; FILE *data_file;
char *mesg_line1 = _("Failed to open todo file"); char *mesg_line1 = _("Failed to open todo file");
@ -729,7 +722,7 @@ load_todo(void)
/* Checks if data files exist. If not, create them */ /* Checks if data files exist. If not, create them */
int int
check_data_files(void) io_check_data_files(void)
{ {
FILE *data_file; FILE *data_file;
int no_data_file; int no_data_file;
@ -775,7 +768,7 @@ check_data_files(void)
/* Draw the startup screen */ /* Draw the startup screen */
void void
startup_screen(bool skip_dialogs, int no_data_file) io_startup_screen(bool skip_dialogs, int no_data_file)
{ {
char *welcome_mesg = char *welcome_mesg =
_("Welcome to Calcurse. Missing data files were created."); _("Welcome to Calcurse. Missing data files were created.");

View File

@ -1,4 +1,4 @@
/* $calcurse: io.h,v 1.6 2007/05/06 13:32:42 culot Exp $ */ /* $calcurse: io.h,v 1.7 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -35,13 +35,13 @@ typedef enum {
IO_EXPORT_NBMODES IO_EXPORT_NBMODES
} export_mode_t; } export_mode_t;
void io_init(char *cfile); void io_init(char *);
void io_extract_data(char *dst_data, const char *org, int len); void io_extract_data(char *, const char *, int);
void io_save_cal(conf_t *conf); void io_save_cal(conf_t *);
void load_app(void); void io_load_app(void);
int load_todo(void); int io_load_todo(void);
int check_data_files(void); int io_check_data_files(void);
void startup_screen(bool skip_dialogs, int no_data_file); void io_startup_screen(bool, int);
void io_export_data(export_mode_t mode, conf_t *conf); void io_export_data(export_mode_t, conf_t *);
#endif /* CALCURSE_IO_H */ #endif /* CALCURSE_IO_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: notify.c,v 1.15 2007/07/21 19:36:45 culot Exp $ */ /* $calcurse: notify.c,v 1.16 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,22 +24,15 @@
* *
*/ */
#include <ncurses.h>
#include <pthread.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "custom.h" #include "custom.h"
#include "vars.h"
#include "apoint.h"
#include "notify.h" #include "notify.h"
#include "recur.h"
#include "wins.h"
static struct notify_vars_s *notify = NULL; static struct notify_vars_s *notify = NULL;
static struct notify_app_s *notify_app = NULL; static struct notify_app_s *notify_app = NULL;
@ -78,6 +71,14 @@ notify_init_vars(void)
nbar->shell = "/bin/sh"; nbar->shell = "/bin/sh";
} }
/* Extract the appointment file name from the complete file path. */
static void
extract_aptsfile(void)
{
notify->apts_file = strrchr(path_apts, '/');
notify->apts_file++;
}
/* /*
* Create the notification bar, by initializing all the variables and * Create the notification bar, by initializing all the variables and
* creating the notification window (l is the number of lines, c the * creating the notification window (l is the number of lines, c the
@ -93,7 +94,7 @@ notify_init_bar(window_t *win)
pthread_mutex_init(&notify_app->mutex, NULL); pthread_mutex_init(&notify_app->mutex, NULL);
notify_app->got_app = 0; notify_app->got_app = 0;
notify->win = newwin(win->h, win->w, win->y, win->x); notify->win = newwin(win->h, win->w, win->y, win->x);
notify_extract_aptsfile(); extract_aptsfile();
} }
/* Stop the notify-bar main thread. */ /* Stop the notify-bar main thread. */
@ -115,6 +116,26 @@ notify_reinit_bar(int l, int c, int y, int x)
notify->win = newwin(l, c, y, x); notify->win = newwin(l, c, y, x);
} }
/* Launch user defined command as a notification. */
static void
launch_cmd(char *cmd, char *shell)
{
int pid;
pid = fork();
if (pid < 0) {
fputs(_("FATAL ERROR in launch_cmd: could not fork\n"),
stderr);
exit(EXIT_FAILURE);
} else if (pid == 0) { /* Child: launch user defined command */
if (execlp(shell, shell, "-c", cmd, (char *)NULL) < 0)
fputs(_("FATAL ERROR in launch_cmd: could not "
"launch user command\n"), stderr);
exit(EXIT_FAILURE);
}
}
/* /*
* Update the notification bar. This is useful when changing color theme * Update the notification bar. This is useful when changing color theme
* for example. * for example.
@ -180,7 +201,7 @@ notify_update_bar(void)
if (blinking && if (blinking &&
!(notify_app->state & APOINT_NOTIFIED)) { !(notify_app->state & APOINT_NOTIFIED)) {
notify_app->state |= APOINT_NOTIFIED; notify_app->state |= APOINT_NOTIFIED;
notify_launch_cmd(nbar->cmd, nbar->shell); launch_cmd(nbar->cmd, nbar->shell);
} }
pthread_mutex_unlock(&nbar->mutex); pthread_mutex_unlock(&nbar->mutex);
} else { } else {
@ -200,14 +221,6 @@ notify_update_bar(void)
pthread_mutex_unlock(&notify->mutex); pthread_mutex_unlock(&notify->mutex);
} }
/* Extract the appointment file name from the complete file path. */
void
notify_extract_aptsfile(void)
{
notify->apts_file = strrchr(path_apts, '/');
notify->apts_file++;
}
/* Update the notication bar content */ /* Update the notication bar content */
static void * static void *
notify_main_thread(void *arg) notify_main_thread(void *arg)
@ -380,26 +393,6 @@ notify_same_recur_item(recur_apoint_llist_node_t *i)
return same; return same;
} }
/* Launch user defined command as a notification. */
void
notify_launch_cmd(char *cmd, char *shell)
{
int pid;
pid = fork();
if (pid < 0) {
fputs(_("FATAL ERROR in notify_launch_cmd: could not fork\n"),
stderr);
exit(EXIT_FAILURE);
} else if (pid == 0) { /* Child: launch user defined command */
if (execlp(shell, shell, "-c", cmd, (char *)NULL) < 0)
fputs(_("FATAL ERROR in notify_launch_cmd: could not "
"launch user command\n"), stderr);
exit(EXIT_FAILURE);
}
}
/* Launch the notify-bar main thread. */ /* Launch the notify-bar main thread. */
void void
notify_start_main_thread(void) notify_start_main_thread(void)

View File

@ -1,4 +1,4 @@
/* $calcurse: notify.h,v 1.10 2007/07/23 19:30:04 culot Exp $ */ /* $calcurse: notify.h,v 1.11 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,9 +27,6 @@
#ifndef CALCURSE_NOTIFY_H #ifndef CALCURSE_NOTIFY_H
#define CALCURSE_NOTIFY_H #define CALCURSE_NOTIFY_H
#include <ncurses.h>
#include <pthread.h>
#include "wins.h" #include "wins.h"
#include "apoint.h" #include "apoint.h"
#include "recur.h" #include "recur.h"
@ -60,14 +57,11 @@ void notify_start_main_thread(void);
void notify_stop_main_thread(void); void notify_stop_main_thread(void);
void notify_reinit_bar(int, int, int, int); void notify_reinit_bar(int, int, int, int);
void notify_update_bar(void); void notify_update_bar(void);
void notify_extract_aptsfile(void);
void notify_check_next_app(void); void notify_check_next_app(void);
void notify_check_added(char *, long, char); void notify_check_added(char *, long, char);
void notify_check_repeated(recur_apoint_llist_node_t *); void notify_check_repeated(recur_apoint_llist_node_t *);
int notify_same_item(long); int notify_same_item(long);
int notify_same_recur_item(recur_apoint_llist_node_t *); int notify_same_recur_item(recur_apoint_llist_node_t *);
void notify_launch_cmd(char *, char *);
void notify_catch_children(void);
void notify_config_bar(void); void notify_config_bar(void);
#endif /* CALCURSE_NOTIFY_H */ #endif /* CALCURSE_NOTIFY_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: recur.c,v 1.26 2007/07/01 17:53:42 culot Exp $ */ /* $calcurse: recur.c,v 1.27 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,9 +24,7 @@
* *
*/ */
#include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
@ -34,13 +32,9 @@
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "apoint.h"
#include "event.h"
#include "recur.h"
#include "notify.h" #include "notify.h"
#include "args.h"
#include "day.h" #include "day.h"
#include "vars.h" #include "recur.h"
recur_apoint_llist_t *recur_alist_p; recur_apoint_llist_t *recur_alist_p;
struct recur_event_s *recur_elist; struct recur_event_s *recur_elist;
@ -170,7 +164,8 @@ int recur_char2def(char type){
} }
/* Write days for which recurrent items should not be repeated. */ /* Write days for which recurrent items should not be repeated. */
void recur_write_exc(struct days_s *exc, FILE *f) { static void
recur_write_exc(struct days_s *exc, FILE *f) {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
int st_mon, st_day, st_year; int st_mon, st_day, st_year;
@ -186,78 +181,6 @@ void recur_write_exc(struct days_s *exc, FILE *f) {
} }
} }
/* Writting of a recursive appointment into file. */
void
recur_apoint_write(recur_apoint_llist_node_t *o, FILE *f)
{
struct tm *lt;
time_t t;
t = o->start;
lt = localtime(&t);
fprintf(f, "%02u/%02u/%04u @ %02u:%02u",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min);
t = o->start + o->dur;
lt = localtime(&t);
fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min);
t = o->rpt->until;
if (t == 0) { /* We have an endless recurrent appointment. */
fprintf(f, " {%d%c", o->rpt->freq,
recur_def2char(o->rpt->type));
} else {
lt = localtime(&t);
fprintf(f, " {%d%c -> %02u/%02u/%04u",
o->rpt->freq, recur_def2char(o->rpt->type),
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
}
if (o->exc != 0)
recur_write_exc(o->exc, f);
if (o->state & APOINT_NOTIFY)
fprintf(f, "} !");
else
fprintf(f, "} |");
fprintf(f, "%s\n", o->mesg);
}
/* Writting of a recursive event into file. */
void recur_event_write(struct recur_event_s *o, FILE *f)
{
struct tm *lt;
time_t t;
int st_mon, st_day, st_year;
int end_mon, end_day, end_year;
t = o->day;
lt = localtime(&t);
st_mon = lt->tm_mon + 1;
st_day = lt->tm_mday;
st_year = lt->tm_year + 1900;
t = o->rpt->until;
if (t == 0) { /* We have an endless recurrent event. */
fprintf(f, "%02u/%02u/%04u [%d] {%d%c",
st_mon, st_day, st_year, o->id, o->rpt->freq,
recur_def2char(o->rpt->type));
if (o->exc != 0) recur_write_exc(o->exc, f);
fprintf(f,"} %s\n", o->mesg);
} else {
lt = localtime(&t);
end_mon = lt->tm_mon + 1;
end_day = lt->tm_mday;
end_year = lt->tm_year + 1900;
fprintf(f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u",
st_mon, st_day, st_year, o->id,
o->rpt->freq, recur_def2char(o->rpt->type),
end_mon, end_day, end_year);
if (o->exc != 0) recur_write_exc(o->exc, f);
fprintf(f, "} %s\n", o->mesg);
}
}
/* Load the recursive appointment description */ /* Load the recursive appointment description */
recur_apoint_llist_node_t * recur_apoint_llist_node_t *
recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type, recur_apoint_scan(FILE * f, struct tm start, struct tm end, char type,
@ -348,6 +271,79 @@ struct recur_event_s *recur_event_scan(FILE * f, struct tm start, int id,
freq, tuntil, exc); freq, tuntil, exc);
} }
/* Writting of a recursive appointment into file. */
static void
recur_apoint_write(recur_apoint_llist_node_t *o, FILE *f)
{
struct tm *lt;
time_t t;
t = o->start;
lt = localtime(&t);
fprintf(f, "%02u/%02u/%04u @ %02u:%02u",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min);
t = o->start + o->dur;
lt = localtime(&t);
fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u",
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
lt->tm_hour, lt->tm_min);
t = o->rpt->until;
if (t == 0) { /* We have an endless recurrent appointment. */
fprintf(f, " {%d%c", o->rpt->freq,
recur_def2char(o->rpt->type));
} else {
lt = localtime(&t);
fprintf(f, " {%d%c -> %02u/%02u/%04u",
o->rpt->freq, recur_def2char(o->rpt->type),
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year);
}
if (o->exc != 0)
recur_write_exc(o->exc, f);
if (o->state & APOINT_NOTIFY)
fprintf(f, "} !");
else
fprintf(f, "} |");
fprintf(f, "%s\n", o->mesg);
}
/* Writting of a recursive event into file. */
static void
recur_event_write(struct recur_event_s *o, FILE *f)
{
struct tm *lt;
time_t t;
int st_mon, st_day, st_year;
int end_mon, end_day, end_year;
t = o->day;
lt = localtime(&t);
st_mon = lt->tm_mon + 1;
st_day = lt->tm_mday;
st_year = lt->tm_year + 1900;
t = o->rpt->until;
if (t == 0) { /* We have an endless recurrent event. */
fprintf(f, "%02u/%02u/%04u [%d] {%d%c",
st_mon, st_day, st_year, o->id, o->rpt->freq,
recur_def2char(o->rpt->type));
if (o->exc != 0) recur_write_exc(o->exc, f);
fprintf(f,"} %s\n", o->mesg);
} else {
lt = localtime(&t);
end_mon = lt->tm_mon + 1;
end_day = lt->tm_mday;
end_year = lt->tm_year + 1900;
fprintf(f, "%02u/%02u/%04u [%d] {%d%c -> %02u/%02u/%04u",
st_mon, st_day, st_year, o->id,
o->rpt->freq, recur_def2char(o->rpt->type),
end_mon, end_day, end_year);
if (o->exc != 0) recur_write_exc(o->exc, f);
fprintf(f, "} %s\n", o->mesg);
}
}
/* Write recursive items to file. */ /* Write recursive items to file. */
void recur_save_data(FILE *f) void recur_save_data(FILE *f)
{ {

View File

@ -1,4 +1,4 @@
/* $calcurse: recur.h,v 1.12 2007/07/01 17:53:42 culot Exp $ */ /* $calcurse: recur.h,v 1.13 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,10 +27,6 @@
#ifndef CALCURSE_RECUR_H #ifndef CALCURSE_RECUR_H
#define CALCURSE_RECUR_H #define CALCURSE_RECUR_H
#include "apoint.h"
#include "notify.h"
#include "vars.h"
typedef enum { RECUR_NO, typedef enum { RECUR_NO,
RECUR_DAILY, RECUR_DAILY,
RECUR_WEEKLY, RECUR_WEEKLY,
@ -84,11 +80,6 @@ struct recur_event_s *recur_event_new(char *, long, int, int, int,
long, struct days_s *); long, struct days_s *);
char recur_def2char(int); char recur_def2char(int);
int recur_char2def(char); int recur_char2def(char);
void recur_write_exc(struct days_s *, FILE *);
void recur_apoint_write(recur_apoint_llist_node_t *,
FILE *);
void recur_event_write(struct recur_event_s *,
FILE *);
recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm, recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm,
char, int, struct tm, struct days_s *, char, int, struct tm, struct days_s *,
char); char);

View File

@ -1,4 +1,4 @@
/* $Id: sigs.c,v 1.1 2007/07/23 19:31:12 culot Exp $ */ /* $Id: sigs.c,v 1.2 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -26,14 +26,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <signal.h> #include <signal.h>
#include "i18n.h" #include "i18n.h"
#include "utils.h"
#include "wins.h"
#include "vars.h" #include "vars.h"
/* /*

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.c,v 1.12 2007/07/21 19:35:40 culot Exp $ */ /* $calcurse: todo.c,v 1.13 2007/07/28 13:11:42 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,11 +24,9 @@
* *
*/ */
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "vars.h"
#include "utils.h" #include "utils.h"
#include "i18n.h" #include "i18n.h"
#include "todo.h" #include "todo.h"
@ -80,6 +78,30 @@ todo_add(char *mesg, int id)
return o; return o;
} }
/* Delete an item from the todo linked list. */
static void
todo_delete_bynum(unsigned num)
{
unsigned n;
struct todo_s *i, **iptr;
n = 0;
iptr = &todolist;
for (i = todolist; i != 0; i = i->next) {
if (n == num) {
*iptr = i->next;
free(i->mesg);
free(i);
return;
}
iptr = &i->next;
n++;
}
/* NOTREACHED */
fputs(_("FATAL ERROR in todo_delete_bynum: no such todo\n"), stderr);
exit(EXIT_FAILURE);
}
/* Delete an item from the ToDo list. */ /* Delete an item from the ToDo list. */
void void
todo_delete(conf_t *conf, int *nb_tod, int *hilt_tod) todo_delete(conf_t *conf, int *nb_tod, int *hilt_tod)
@ -112,51 +134,11 @@ todo_delete(conf_t *conf, int *nb_tod, int *hilt_tod)
} }
} }
/* Delete an item from the todo linked list. */
void
todo_delete_bynum(unsigned num)
{
unsigned n;
struct todo_s *i, **iptr;
n = 0;
iptr = &todolist;
for (i = todolist; i != 0; i = i->next) {
if (n == num) {
*iptr = i->next;
free(i->mesg);
free(i);
return;
}
iptr = &i->next;
n++;
}
/* NOTREACHED */
fputs(_("FATAL ERROR in todo_delete_bynum: no such todo\n"), stderr);
exit(EXIT_FAILURE);
}
/* Returns a structure containing the selected item. */
struct todo_s *
todo_get_item(int item_number)
{
struct todo_s *o;
int i;
o = todolist;
for (i = 1; i < item_number; i++) {
o = o->next;
}
return o;
}
/* /*
* Returns the position into the linked list corresponding to the * Returns the position into the linked list corresponding to the
* given todo_s item. * given todo_s item.
*/ */
int static int
todo_get_position(struct todo_s *i) todo_get_position(struct todo_s *i)
{ {
struct todo_s *o; struct todo_s *o;
@ -178,6 +160,20 @@ todo_get_position(struct todo_s *i)
} }
} }
/* Returns a structure containing the selected item. */
static struct todo_s *
todo_get_item(int item_number)
{
struct todo_s *o;
int i;
o = todolist;
for (i = 1; i < item_number; i++) {
o = o->next;
}
return o;
}
/* Change an item priority by pressing '+' or '-' inside TODO panel. */ /* Change an item priority by pressing '+' or '-' inside TODO panel. */
int int
todo_chg_priority(int action, int item_num) todo_chg_priority(int action, int item_num)

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.h,v 1.7 2007/07/23 19:30:17 culot Exp $ */ /* $calcurse: todo.h,v 1.8 2007/07/28 13:11:43 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -40,9 +40,6 @@ extern struct todo_s *todolist;
int todo_new_item(int); int todo_new_item(int);
struct todo_s *todo_add(char *, int); struct todo_s *todo_add(char *, int);
void todo_delete(conf_t *, int *, int *); void todo_delete(conf_t *, int *, int *);
void todo_delete_bynum(unsigned);
struct todo_s *todo_get_item(int);
int todo_get_position(struct todo_s *);
int todo_chg_priority(int, int); int todo_chg_priority(int, int);
void todo_edit_item(int); void todo_edit_item(int);
void todo_update_panel(window_t *, int, int, int, int, char **); void todo_update_panel(window_t *, int, int, int, int, char **);

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.c,v 1.32 2007/07/23 19:26:38 culot Exp $ */ /* $calcurse: utils.c,v 1.33 2007/07/28 13:11:43 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,21 +24,17 @@
* *
*/ */
#include <ncurses.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <stdbool.h>
#include <sys/types.h> #include <sys/types.h>
#include <math.h> #include <math.h>
#include "i18n.h" #include "i18n.h"
#include "utils.h"
#include "wins.h" #include "wins.h"
#include "custom.h" #include "custom.h"
#include "vars.h" #include "utils.h"
static unsigned status_page; static unsigned status_page;
@ -135,34 +131,13 @@ print_in_middle(WINDOW * win, int starty, int startx, int width, char *string)
custom_remove_attr(win, ATTR_HIGHEST); custom_remove_attr(win, ATTR_HIGHEST);
} }
/* Delete a character at the given position in string. */
void del_char(int pos, char *str)
{
int len;
str += pos;
len = strlen(str) + 1;
memmove(str, str + 1, len);
}
/* Add a character at the given position in string. */
char *add_char(int pos, int ch, char *str)
{
int len;
str += pos;
len = strlen(str) + 1;
memmove(str + 1, str, len);
*str = ch;
return (str += len);
}
/* /*
* Draw the cursor at the correct position in string. * Draw the cursor at the correct position in string.
* As echoing is not set, we need to know the string we are working on to * As echoing is not set, we need to know the string we are working on to
* handle display correctly. * handle display correctly.
*/ */
void showcursor(WINDOW *win, int y, int pos, char *str, int l, int offset) static void
showcursor(WINDOW *win, int y, int pos, char *str, int l, int offset)
{ {
char *nc; char *nc;
@ -172,7 +147,8 @@ void showcursor(WINDOW *win, int y, int pos, char *str, int l, int offset)
} }
/* Print the string at the desired position. */ /* Print the string at the desired position. */
void showstring(WINDOW *win, int y, int x, char *str, int len, int pos) static void
showstring(WINDOW *win, int y, int x, char *str, int len, int pos)
{ {
const int rec = 30, border = 3; const int rec = 30, border = 3;
const int max_col = col - border, max_len = max_col - rec; const int max_col = col - border, max_len = max_col - rec;
@ -198,6 +174,30 @@ void showstring(WINDOW *win, int y, int x, char *str, int len, int pos)
showcursor(win, y, pos, orig, len, offset); showcursor(win, y, pos, orig, len, offset);
} }
/* Delete a character at the given position in string. */
static void
del_char(int pos, char *str)
{
int len;
str += pos;
len = strlen(str) + 1;
memmove(str, str + 1, len);
}
/* Add a character at the given position in string. */
static char *
add_char(int pos, int ch, char *str)
{
int len;
str += pos;
len = strlen(str) + 1;
memmove(str + 1, str, len);
*str = ch;
return (str += len);
}
/* /*
* Getstring allows to get user input and to print it on a window, * Getstring allows to get user input and to print it on a window,
* even if noecho() is on. This function is also used to modify an existing * even if noecho() is on. This function is also used to modify an existing
@ -338,54 +338,6 @@ int is_all_digit(char *string)
return all_digit; return all_digit;
} }
/* draw panel border in color */
void
border_color(WINDOW *window)
{
int color_attr = A_BOLD;
int no_color_attr = A_BOLD;
if (colorize) {
wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
box(window, 0, 0);
} else {
wattron(window, no_color_attr);
box(window, 0, 0);
}
if (colorize) {
wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
} else {
wattroff(window, no_color_attr);
}
wnoutrefresh(window);
}
/* draw panel border without any color */
void
border_nocolor(WINDOW *window)
{
int color_attr = A_BOLD;
int no_color_attr = A_DIM;
if (colorize) {
wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattron(window, no_color_attr);
}
box(window, 0, 0);
if (colorize) {
wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattroff(window, no_color_attr);
}
wnoutrefresh(window);
}
/* /*
* Draws the status bar. * Draws the status bar.
* To add a keybinding, insert a new binding_t item, add it in the *binding * To add a keybinding, insert a new binding_t item, add it in the *binding
@ -617,6 +569,43 @@ get_sec_date(date_t date)
return long_date; return long_date;
} }
/*
* Check if the entered date is of a valid format.
* First check the format by itself, and then check the
* numbers correctness.
*/
int
check_date(char *date)
{
int ok = 0;
char month[3] = "";
char day[3] = "";
char year[5] = "";
if (
(strlen(date) == 10) &
(isdigit(date[0]) != 0) &
(isdigit(date[1]) != 0) &
(date[2] == '/') &
(isdigit(date[3]) != 0) &
(isdigit(date[4]) != 0) &
(date[5] == '/') &
(isdigit(date[6])!=0) & (isdigit(date[7])!=0) &
(isdigit(date[8])!=0) & (isdigit(date[9])!=0)
) {
strncpy(month, date, 2);
strncpy(day, date + 3, 2);
strncpy(year, date + 6, 4);
if ( (atoi(month) <= 12) &
(atoi(month) >= 1) &
(atoi(day) <= 31) &
(atoi(day) >= 1) &
(atoi(year) <= 9999) &
(atoi(year) > 1))
ok = 1;
}
return ok;
}
long long
min2sec(unsigned minutes) min2sec(unsigned minutes)
{ {

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.h,v 1.21 2007/07/23 19:26:38 culot Exp $ */ /* $calcurse: utils.h,v 1.22 2007/07/28 13:11:43 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -28,7 +28,6 @@
#define CALCURSE_UTILS_H #define CALCURSE_UTILS_H
#include "calendar.h" #include "calendar.h"
#include "vars.h"
#define MAX(x,y) ((x)>(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y))
@ -59,15 +58,9 @@ void erase_status_bar(void);
void erase_window_part(WINDOW *, int, int, int, int); void erase_window_part(WINDOW *, int, int, int, int);
WINDOW *popup(int, int, int, int, char *); WINDOW *popup(int, int, int, int, char *);
void print_in_middle(WINDOW *, int, int, int, char *); void print_in_middle(WINDOW *, int, int, int, char *);
void del_char(int, char *);
char *add_char(int, int, char *);
void showcursor(WINDOW *, int, int, char *, int, int);
void showstring(WINDOW *, int, int, char *, int, int);
int getstring(WINDOW *, char *, int, int, int); int getstring(WINDOW *, char *, int, int, int);
int updatestring(WINDOW *, char **, int, int); int updatestring(WINDOW *, char **, int, int);
int is_all_digit(char *); int is_all_digit(char *);
void border_color(WINDOW *);
void border_nocolor(WINDOW *);
void status_bar(void); void status_bar(void);
long date2sec(date_t, unsigned, unsigned); long date2sec(date_t, unsigned, unsigned);
char *date_sec2hour_str(long); char *date_sec2hour_str(long);
@ -76,6 +69,7 @@ void date_sec2ical_date(long, char *);
void date_sec2ical_datetime(long, char *); void date_sec2ical_datetime(long, char *);
long update_time_in_date(long, unsigned, unsigned); long update_time_in_date(long, unsigned, unsigned);
long get_sec_date(date_t); long get_sec_date(date_t);
int check_date(char *);
long min2sec(unsigned); long min2sec(unsigned);
int check_time(char *); int check_time(char *);
void draw_scrollbar(WINDOW *, int, int, int, int, int, bool); void draw_scrollbar(WINDOW *, int, int, int, int, int, bool);

View File

@ -1,4 +1,4 @@
/* $calcurse: vars.h,v 1.14 2007/07/23 19:27:28 culot Exp $ */ /* $calcurse: vars.h,v 1.15 2007/07/28 13:11:43 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -30,7 +30,6 @@
#include <ncurses.h> #include <ncurses.h>
#include <pthread.h> #include <pthread.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#define DIR_NAME ".calcurse" #define DIR_NAME ".calcurse"
#define TODO_PATH ".calcurse/todo" #define TODO_PATH ".calcurse/todo"

View File

@ -1,4 +1,4 @@
/* $Id: wins.c,v 1.2 2007/07/23 19:28:37 culot Exp $ */ /* $Id: wins.c,v 1.3 2007/07/28 13:11:43 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,15 +24,13 @@
* *
*/ */
#include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include "i18n.h" #include "i18n.h"
#include "vars.h"
#include "calendar.h"
#include "notify.h" #include "notify.h"
#include "utils.h" #include "utils.h"
#include "todo.h" #include "todo.h"
#include "custom.h"
#include "wins.h" #include "wins.h"
static window_e slctd_win; static window_e slctd_win;
@ -245,6 +243,54 @@ wins_get_config(conf_t *conf, window_t *status, window_t *notify,
} }
} }
/* draw panel border in color */
static void
border_color(WINDOW *window)
{
int color_attr = A_BOLD;
int no_color_attr = A_BOLD;
if (colorize) {
wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
box(window, 0, 0);
} else {
wattron(window, no_color_attr);
box(window, 0, 0);
}
if (colorize) {
wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
} else {
wattroff(window, no_color_attr);
}
wnoutrefresh(window);
}
/* draw panel border without any color */
static void
border_nocolor(WINDOW *window)
{
int color_attr = A_BOLD;
int no_color_attr = A_DIM;
if (colorize) {
wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattron(window, no_color_attr);
}
box(window, 0, 0);
if (colorize) {
wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
} else {
wattroff(window, no_color_attr);
}
wnoutrefresh(window);
}
/* /*
* Update all of the three windows and put a border around the * Update all of the three windows and put a border around the
* selected window. * selected window.