1440 Commits

Author SHA1 Message Date
Lars Henriksen
ddc3fda5f1 Initialize variables in non-interactive mode in all cases
The changed handling of thread ids implies that they must be initialized
before exit of calcurse where they are used. Hence the function
vars_init() is now called irrespective of command line arguments.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-19 09:10:06 +02:00
Quentin Hibon
e9611ce3a6 Use a path instead of a file for -C option
Allows to specify a configuration directory containing:
* conf
* keys
* hooks

When used in combination with -D $ddir, $ddir contains all the other
files not mentioned above.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-05 18:36:25 +02:00
Lars Henriksen
3788df6d78 Fix multiple, simultaneous periodic saves
A new save thread was started every time a positive periodic save value
was input in the general options configuration menu. And only one thread
can be stopped by entering 0, also when done repeatedly.

Always stop the old thread before (possibly) starting a new.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-28 14:21:38 +02:00
Lars Henriksen
5e53708648 Solve deadlock in notification bar
calcurse deadlocks when

1) an upcoming appointment is on display in the notification bar,
2) an external command (like help) is started,
3) the time for the upcoming appointment arrives, and
4) the external command is exited.

The notification bar thread is stopped while the external command is
running. Upon exit from the external command, the n-bar thread is
restarted and calcurse locks.

The cause is the way in which the main notification bar thread is
stopped:

static pthread_t notify_t_main;
void notify_stop_main_thread(void)
{
	if (notify_t_main) {
		pthread_cancel(notify_t_main);
		pthread_join(notify_t_main, NULL);
	}
}

Objects of type pthread_t are opaque and should not be accessed
directly.  Initially notify_t_main is an uninitialised static variable
(0), but later it has a value, which may or may not be the thread id of
the notification main thread.

Note that the thread id after exit of a thread may become the thread id
of a new thread. Thus the variable set when the thread is created, is
invalid after exit of the thread.

Specifically, the first time notify_stop_main_thread() is called (by
notify_start_main_thread() before the thread is created) is harmless
(because notify_t_main is 0). Calling notify_stop_main_thread() later
may be either

OK
    because the main thread is running, or
harmless
    because no thread with id notify_t_main is running: the two
    functions will fail with return value ESRCH (no such process), or
fatal
    because an unrelated thread with this thread id is running: it will
    be cancelled, and the join may or may not succeed depending on
    whether the thread is joinable or detached.

The "unrelated thread" could be the next-appointment thread,
notify_thread_app, launched by notify_check_next_app().

Always calling notify_stop_main_thread() before starting the main thread
becomes fatal when notify_check_next_app() is called shortly before
notify_start_main_thread(). This is the case in the scenario described.
The next-app-thread is then running when notify_stop_main_thread() is
called, and apparently it has the thread id of the old main thread
(confirmed by logging the return values from pthread_cancel() and
pthread_join(); the first succeeds while the second fails with EINVALID
which means that the thread is not joinable). The next-app-thread will
therefore exit without unlocking mutexes.

Ensure that notify_t_main, in case the notify main thread is not
running, has a value that it will never have when it is running. A
possibility is the thread id of the main() calcurse process (returned by
pthread_self()).

Check for this condition in notify_stop_main_thread() and set
notify_t_main when the thread is stopped.

Similar changes have been introduced for the periodic save thread and
the calendar date thread.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-28 14:06:15 +02:00
Lars Henriksen
163730cabf Fix end-before-start inconsistency
Due to deficient validation, it is possible to get an inconsistent
database with an appointment that ends before it begins. Edit an
existing one and specify an end time by a date that precedes the start
date, or create a new one and give a date as end time that precedes the
start. Then exit calcurse; on restart it will report a data error and
exit.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-05 05:52:39 +02:00
Lars Henriksen
40eb6f809e Fix appointment becoming event
You try to enter an appointment, but enter an invalid start time (by
mistake). Calcurse rejects the input. You enter the correct start time
and calcurse asks for the description, not the end time, i.e. you get an
event.

The check for an event must only be performed on valid input.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-05 05:52:30 +02:00
Lars Henriksen
500b0c080e Support UTF-8 encoded characters in user choices
Translations (in po-files) of texts that are used for alternative
choices (e.g. [dwmy]), may use UTF-8 encoded Unicode characters (e.g.
[éãüå]).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 11:28:46 +02:00
Lars Henriksen
7078556f9d Key bindings for UTF-8 encoded characters
Internally characters (keys) have two representations: integers and key
names. Key names are characters strings, usually the name of the
character; e.g., the character A has the representations 65 and "A", and
the tab character the representations 9 and "TAB".

The function keys_int2str() turns the integer representation of a
key/character into the key name.

For display purposes the key names are usually confined to have display
width at most three. Some curses pseudo-keys have longer key names;
e.g., the back-tab character is "KEY_BTAB". A long key name makes a
character difficult to recognize in the status bar menu.

The key name of a multibyte, UTF-8 encoded character is the conventional
Unicode name of the code point; e.g., the character ü has key name
"U+00FC" because ü is the code point 0xFC. Most of these look alike in
the status bar menu.

The patch makes the key name of a multibyte character look like that of
a singlebyte character: the character itself, i.e. the key name of the
character ü is "ü".

The main tool is implementation of a utf8_encode() routine.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 11:26:12 +02:00
Lars Henriksen
431e4a00e7 Rename utf8_ord() to utf8_decode()
Purely for readability and in preparation for the counterpart utf8_encode().

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 11:24:37 +02:00
Lukas Fleischer
30f411257a Do not stop already cancelled notification thread
Add a static state variable to indicate whether the notification thread
is already running or not. Only start the thread if the notification
thread is paused. Only stop the thread if the notification thread is
actually running.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 10:28:28 +02:00
Lukas Fleischer
e55aead126 Only lock save mutex as short as possible
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 10:28:28 +02:00
Lars Henriksen
d5961baa13 Check for empty string in config_parse_int()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-28 17:31:06 +02:00
Quentin Hibon
407d5abd23 Add option to specify the configuration file used
The configuration file (~/.calcurse/conf by default) can now be
specified with -C or --conf.

Workaround for GitHub issue #86.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-28 06:29:09 +02:00
Lukas Fleischer
574156be7c Always NUL-terminate buffer in note_gc()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 12:05:50 +02:00
Lukas Fleischer
68cac7345c Always NUL-terminate buffer in keys_fill_missing()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 12:05:41 +02:00
Lukas Fleischer
7efe03cf05 Fix buffer overflow in keys_action_allkeys()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 12:03:03 +02:00
Lukas Fleischer
2cd60c78cf Always NUL-terminate buffer in io_load_keys()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:52:41 +02:00
Lukas Fleischer
65c2b6d9b8 notify.c: fix several buffer overflows
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:51:38 +02:00
Lukas Fleischer
8abb1a93ad Properly NUL-terminate the day heading after editing
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:47:01 +02:00
Lukas Fleischer
7e5f8ed7bc Avoid buffer overrun in config_parse_str()
The previous implementation only read a prefix from the configuration
file if the configuration value was too long and forgot to terminate the
string with a NUL character.

Return 0 if the string is too long instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:44:30 +02:00
Lars Henriksen
bb7381765c Scrollbar and right window border (corrected)
When a scrollbar is on display in APP or TOD windows, the right
vertical border (outside the scrollbar) is not highlighted
when the window is selected.

The scrollbar is always highlighted:
- when APP or TOD is deselected
- in configuration windows where borders otherwise are not

The patch moves the scrollbar parameters (except highlight)
from arguments of draw_scrollbar() to the function itself.
The highlight argument was 1; instead it is set higher in
the call hierarchy (wins_update_panels()) and passed on down.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:31:43 +02:00
Lars Henriksen
a5cc46cd55 Transparent cursor fix
Commit f8e6e0d (Fix no-colour theme, 2017-12-10) partly destroyed the
cursor in getstring() by turning it into a solid block. The fix
reintroduces wchgat() which requires a color pair argument. When no
colors are wanted, color pair 0 is used.

A similar problem exists in the layout and colour customization windows
and is fixed in the same way: move to the position and apply the reverse
video attribute.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:30:03 +02:00
Lars Henriksen
65dd82a626 Fix end-of-string calculation
In keys_fill_missing() a pointer is walked through a string of
space-separated character names, but misses the string-terminating null
character.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-24 16:23:23 +02:00
Lukas Fleischer
912124bcdc Run pre-load hook before testing for modifications
The pre-load hook is often used to manipulate the data files before
loading, such as by synchronizing with a remote calendar. Make sure we
always execute the pre-load hook upon reloads, even if the data files
have not been modified.

Fixes GitHub issue #98.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-23 17:52:05 +02:00
Lukas Fleischer
2d19605ba8 Unlock the save mutex as early as possible
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-19 10:34:19 +02:00
Lukas Fleischer
1418e40793 Use dummy variables to ignore return values of pair_content()
This prevents from segmentation faults with recent ncurses
implementations. See commit 5722d2e (Fix segmentation fault when
changing colors, 2017-07-28) for details.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-10 14:05:43 +02:00
Quentin Hibon
01142891a7 ical: use the VALUE parameter in DTSTART
According to RFC5545 3.3 (Property Value Data Types):

"If the value type of a property is one of the alternate valid types, then it
MUST be explicitly specified with the "VALUE" parameter."

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-10 14:03:29 +02:00
Lukas Fleischer
b82a3b9276 Allow for passing negative arguments to -d
When specifying date ranges using -d, allow for passing negative values
to indicate that the date range should start a certain number of days
ago.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-13 09:06:32 +01:00
Lars Henriksen
f8e6e0d691 Fix no-colour theme
In colour customization, pressing cancel ('ESC' by default) will
deselect all colours and put calcurse in no-color mode. For this
to work, all colour changes must be performed with the routines
custom_apply_attr()/custom_remove_attr(). Fixed for the getstring
cursor, the scroll window border and the week number.

In addition, the week number is unconditionally coloured as the
rest of the calendar contents whether CAL is selected or not.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-10 14:33:31 +01:00
Lars Henriksen
9e060b96c2 Scrollbar and right window border
When a scrollbar is on display in APP or TOD windows, the right
vertical border (outside the scrollbar) is not highlighted
when the window is selected.

The scrollbar itself is always highlighted:
- when APP or TOD is deselected
- in configuration windows where borders otherwise are not

The patch moves the scrollbar parameters from arguments of
draw_scrollbar() to the function itself.

The highlight argument to draw_scrollbar() was always 1.
Instead call circumstances are figured out and highlight set
accordingly.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-10 14:33:31 +01:00
Lars Henriksen
e733d09ea0 Default colour as foreground colour
In the default colour setup (white on black), white could only
with great difficulty be used as customized foreground colour,
because the colour pair COLR_CUSTOM then was identical to
COLR_DEFAULT (default on default). This made it impossible to
distinguish the selected element in lists.

The patch turns on the video attribute bold when default is chosen
as foreground colour.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-10 14:33:31 +01:00
Lars Henriksen
95c5d576fa Update UTF-8 base code
UTF-8 encodes characters in one to four bytes (since 2003).

Because 0 is a valid code point, the decode function utf8_ord()
should return -1, not 0, on error. As a consequence utf8_width()
should return 0 for a continuation byte (as it did previously).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-12-07 09:02:58 +01:00
Lukas Fleischer
16e7aecd29 Do not prompt when non-interactive import fails
When running calcurse in non-interactive mode, we should not expect any
user input. This is even more important in the case of iCal imports
which are used by calcurse-caldav to import events from CalDAV servers.

Partly fixes GitHub issue #73.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-23 08:57:45 +01:00
Lars Henriksen
691d6b33ee Check for the year span 1902-2037
Reintroduce year check for systems with a 32-bit time_t type. Remove the
lower limit (1902) for systems with a 64-bit time_t. This limits
movements in the calendar (for 32-bit systems) and in no way ensures
constistency of data.

Commit a12833e (Handle dates past January 19th, 2038, 2015-01-19)
removed the upper limit (2037) on dates but left the lower limit (1902).
It did not ensure the support of the target system.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-23 08:56:38 +01:00
Lars Henriksen
97c3e7f957 Function cleanup in custom.c
Remove two remnants: custom_color_theme_name() and custom_set_swsiz().
Make static and rename custom_confwin_init() into confwin_init().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-23 08:56:06 +01:00
Lars Henriksen
aca4e06c5f Fix help for nine actions
Seven actions were absent from display_help(). This meant that
commands like ':help ^P' did not work. They now refer to
general.txt, but are not all described there.

For two actions, generic-copy/paste, the file name was misspelled.

This solves Github issue #44.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-15 06:35:17 +01:00
Lars Henriksen
9443de4783 Remove unused argument from wins_other_status_page
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-11-03 21:41:28 +01:00
Lars Henriksen
aee9099a44 Detect error on character input
Previously an error from the character input routine wgetch() was
silently ignored. It should still be ignored, but must explicitly be
detected in order to be ignored. The issue came up in connection with
terminal window resize. For whatever reasons ncurses returns ERR (as
well as KEY_RESIZE) when wgetch() asks for input after a resize.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-29 08:42:03 +01:00
Lars Henriksen
012a0e6670 Fix multiple popup windows
The window was not deleted if an "already in use"-key was detected,
and a new one was created as the loop was reentered.

Create/delete of the popup are moved outside the loop.
A redrawwin() call is needed to have the window displayed again.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-29 08:42:03 +01:00
Lukas Fleischer
e9bddf38e8 Parse time before date in parse_datetime()
Make sure that in cases when the date and time formats conflict, such as
is the case with "0030", the input is interpreted as a time value, not a
date.

Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-27 08:40:10 +02:00
Lukas Fleischer
301f240881 Make parsing of date-time more strict
In parse_datetime() it was possible to enter any number of dates and
times in any order. Allow just date or time or date followed by time.

Time must be looked for before date because of conflicting time and date
formats.

Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-26 20:49:30 +02:00
Lukas Fleischer
760c297027 Add parse_date_interactive()
Add a wrapper around parse_date() which picks the current input date
format as well as the currently selected day and passes both values to
parse_date(), alongside with the parameters passed to
parse_date_interactive() itself.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-26 20:49:30 +02:00
Lars Henriksen
2b8d4e983f Remove recognized keys check
All keys known by ncurses can be bound. Thus the check for not
recognized keys in custom_keys_config() becomes superfluous.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-26 08:35:18 +02:00
Lars Henriksen
c0644d5aaf Fix spelling of "frequency"
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-23 21:18:07 +02:00
Lars Henriksen
61e577bf8a Support key bindings for all escape keys
All key names for ordinary ASCII keys as well as for escape keys (pseudo
keys) are cached in a lookup-table, keynames[], at startup. Mapping
between key names (strings) and key codes (integers) in keys_str2int and
keys_int2str) is performed through this table.

The key names used are those returned by the keyname() function of
ncurses. But to accommodate some of the names to the three-letter space
available in the status menu, four ordinary keys and the most common
escape keys have calcurse abbreviated names: ESC, TAB, RET, SPC and LFT,
HOM, PgU, INS, F1, etc.

All keys known by ncurses can be bound. Thus the check for not
recognized keys in the key configuration menu becomes superfluous. The
only keys that cannot be bound, are those escape keys not known to
ncurses, i.e. not described by the terminfo database for the terminal
type in use.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-23 08:40:25 +02:00
Lars Henriksen
dd5af2f7f4 Updates for UTF-8 key bindings
Code point mapping adjusted for multibyte characters to avoid the
ncurses range 0-KEY_MAX.

This includes three fixes:

1) test sequence in keys_assign_binding(),
2) reassemble multi-byte character in keys_wgetch(),
3) check for already in use in keys_assign_binding().

Rearrangement of code. The introduction of allocated memory in
keys_int2str() has as a consequence that check for recognized ncurses
pseudo characters now are in two places: keys_str2int() and
custom_keys_config(). The latter was moved from keys_wgetch() to improve
user information.

More informative warning messages in custom_keys_config().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-23 08:39:11 +02:00
nobody
164d6efcb7 Make delete key act as delete instead of backspace
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-19 06:11:59 +02:00
Quentin Hibon
debf0f84e0 Add CTRL-G readline shortcut to getstring()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-19 06:11:14 +02:00
Lars Henriksen
eeb7038c13 Do not tie ISO 8601 week numbering to Monday
The week number in the calendar panel is calculated according to
ISO 8601. Hence, Monday is the first day of the week and the
week number changes from Sunday to Monday.

However, calcurse ties the week number not to Monday, but to the
first day of the week as configured for display. Thus, when Sunday
is shown as first day of the week, the week number is correct for
Sunday, but wrong for the rest of the week (one behind).

With this patch the week number always follows the mon-sun week as
required by ISO 8601. A side effect is that when Sunday is displayed
as first day of the week, and Sunday is the selected day, the week
number displayed is invalid for the rest of the week (but changes
to the correct one when the selected day moves forward).

This raises the question whether the week numbering scheme should
follow the "first day of the week" choice and use the American week
numbering scheme instead of ISO 8601 when Sunday is the first day
of the week. But that is for the future.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-10-17 08:42:40 +02:00
Lukas Fleischer
2fe9c7efce Reload data after resolving save conflict
After resolving a save conflict with the merge tool, we need to reload
the data files to import the result of the conflict resolution.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-08 21:23:25 +02:00