220 Commits

Author SHA1 Message Date
Lukas Fleischer
007a73f7a2 Replace parse_datetime() constants by named flags
Remove the magic constants used in the return value of parse_datetime()
and use named flags instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-10 09:02:42 +02:00
Lukas Fleischer
adf29c8ee9 Support dates when specifying start/end times
Add support for combined date/time or date-only strings when specifying
the start or end time of a new item.

This is a follow-up to 1f39b5c (Add support for moving items to another
day, 2016-09-30).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-09 20:21:04 +02:00
Lukas Fleischer
343d68596d Factor out parse_datetime()
Create a new function that takes a time stamp and updates the date or
time components of that time stamp according to a given date/time
string. Use that function for updating the start time of an item.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-09 18:12:45 +02:00
Lukas Fleischer
55afda8a73 Stop all threads before leaving curses mode
This prevents from notification bar artifacts being drawn after leaving
interactive mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-09-13 08:28:24 +02:00
Lukas Fleischer
9e160fac16 Do not assume that days always have 86400 seconds
Make that date membership is computed correctly, even if a day has less
than 86400 seconds (e.g. after changing clocks).

Reported-by: Hakan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-03-27 13:06:18 +02:00
Lukas Fleischer
f5d8b5e021 Support durations in recurrence ending dates
When spending the end date of recurring items, allow date duration
specifiers such as "+5d" or "+3w2d".

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-26 09:14:40 +01:00
Lukas Fleischer
fe0621bafd Allow decimals in durations
Parse durations containing decimal numbers (such as "1.5h") gracefully.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-10 08:24:01 +01:00
Lukas Fleischer
4ada3deda2 Fix %(hash) formatting of events
Actually print the hash instead of raw object data.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-05 19:11:43 +01:00
Lukas Fleischer
e9c8197e4e Refactor grep mode
Split io_save_{apts,todo}() into functions that write raw data to a file
and functions that write formatted items to stdout such that one can
easily extend the grep mode for format string support in a follow-up
commit.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-05 19:06:54 +01:00
Lukas Fleischer
978d24a9d2 Update copyright ranges
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-30 11:21:53 +01:00
Lukas Fleischer
c58087d591 Add command line option to suppress dialogs
Implement a -q/--quiet command line option to disable system dialogs
temporarily.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-13 17:39:44 +01:00
Lukas Fleischer
7f8c62bf57 Add an option to filter by object hash
Implement a new --filter-hash option to filter by object identifiers.
Each object having an identifier that has the specified pattern as a
prefix is matched. Patterns starting with an exclamation mark (!) are
interpreted as negative patterns.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-13 17:39:44 +01:00
Lukas Fleischer
dd85a73746 Add long format specifiers "raw" and "hash"
Add new format specifiers to print the raw item representation or an
object's hash value.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-13 17:39:44 +01:00
Lukas Fleischer
ab54c861dc Reimplement asprintf() using dynamic strings
Use the new string implementation to simplify asprintf().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-13 17:39:44 +01:00
Lukas Fleischer
ebb8116056 Split out code for drawing week numbers
This allows for easily adding week numbers to other panel modes, such as
the monthly view.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-04-10 09:42:34 +02:00
Lukas Fleischer
8c82fc3f6d Simplify code in status_ask_choice()
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-24 14:04:30 +01:00
Lukas Fleischer
0145ba12ec Use time_t instead of long in several places
Start converting some variables and return values to store times from
long to time_t.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-24 13:57:47 +01:00
Lukas Fleischer
52779d2ec6 Introduce starts_with() and starts_with_ci()
Create user-defined functions to check whether a string contains a
certain prefix instead of messing around with strncmp() and
strncasecmp().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-24 11:17:38 +01:00
Lukas Fleischer
1ea97795be Add support for UTC times in iCal imports
According to the iCal standard (4.3.12 Time):

    UTC time, or absolute time, is identified by a LATIN CAPITAL LETTER
    Z suffix character (US-ASCII decimal 90), the UTC designator,
    appended to the time value.

Parse such time values properly when importing iCal files.

Fixes GitHub issue #3.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-23 10:46:16 +01:00
Lukas Fleischer
7a631b2b63 Use date_sec_change() for adding day deltas
Fixes tests range-002.sh and search-001.sh.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-22 11:34:11 +01:00
Lukas Fleischer
6a88bdf7cd Support weekday names as date specifiers
Allow for using shorthands like "Monday" as date specifiers.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-11 10:08:51 +01:00
Lukas Fleischer
9ef427693b Update copyright ranges
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-07 11:42:20 +01:00
Lukas Fleischer
4350494d3b Add a couple of shorthands to parse_date()
We now understand the shorthands "today", "yesterday", "tomorrow" and
"now" which might come in useful sometimes.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-07 11:37:15 +01:00
Lukas Fleischer
a12833ec08 Handle dates past January 19th, 2038
Try to support dates past year 2038 on systems with 64-bit time_t.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-07 09:52:36 +01:00
Lukas Fleischer
66ce00153b Refactor new_tempfile()
Avoid preallocating buffers on the stack, use dynamic memory allocation
instead. Also, change the semantics of new_tempfile() so that it returns
the full name of the temporary file and fix all call sites.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-22 11:47:18 +02:00
Lukas Fleischer
21fc7a4b74 Replace several uses of snprintf() by asprintf()
Use asprintf() in some cold code paths. While allocating memory on the
heap is a bit slower, using asprintf() is a bit more memory efficient
and less prone to buffer overflow errors.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-22 11:47:14 +02:00
Lukas Fleischer
6203966fbf Add vasprintf() and asprintf()
The new utils.c functions vasprintf() and asprintf() are analogs to
sprintf() and vsprintf(). However, instead of requiring a buffer that is
large enough to hold the output data, the functions allocate a string
and return a pointer to it.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-22 11:06:54 +02:00
Lukas Fleischer
4cd2fd36d5 Add default cases to some switch statements
This squelches several compiler warnings.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:22:22 +02:00
Lukas Fleischer
f513fa4627 Store appointments for the current day in a vector
This allows for more efficient access to items at specific positions.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:03:16 +02:00
Lukas Fleischer
7184da0fa3 Rework scroll window implementation
This complete rewrite of the scroll window implementation decouples
scroll windows from every other window abstraction layer we use. Note
that this leads to some code duplication. The long-term purpose of this
rewrite, however, is to eventually make every panel use scroll windows.
This makes for a huge cleanup of the UI code.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:02:32 +02:00
Lukas Fleischer
39dff3f685 Add a short format specifier for "%(remaining)"
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-07-17 14:00:25 +02:00
Lukas Fleischer
99b39e5d0d Allow extended formats for durations
Use print_datediff() to print durations. This allows for using something
like "%(duration:%EH:%M)".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-07-17 13:57:11 +02:00
Lukas Fleischer
ae93db284e print_datediff(): Actually print a date difference
Instead of passing a date and printing the date difference between that
date and the current date, pass an actual date difference. This allows
for using the function in other places, such as for printing item
durations.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-07-17 13:55:42 +02:00
William Pettersson
18b6e360b8 Add %(remaining) style formatting
Adds %(remaining) style formatting, with parameter substitution
for %d, %H, %M, %S with E and - variables.

Signed-off-by: William Pettersson <william.pettersson@gmail.com>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-07-17 12:55:29 +02:00
Lukas Fleischer
694d28eb78 Use tabs instead of spaces for indentation
This completes our switch to the Linux kernel coding style. Note that we
still use deeply nested constructs at some places which need to be fixed
up later.

Converted using the `Lindent` script from the Linux kernel code base,
along with some manual fixes.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-04-14 00:19:01 +02:00
Lukas Fleischer
43bdd12254 parse_{date,time}(): Split out date/time validation
Split date/time validation into separate functions check_date() and
check_time(). These will be used to validate date/time information when
reading items from the appointments file.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-27 11:36:28 +01:00
Lukas Fleischer
3d7fdaec58 date_sec2date_str(): Add missing semicolon
Regression introduced in a363cb9b9111aed22d105adb0e7a8e9caab9bbe3.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-19 00:57:24 +01:00
Lukas Fleischer
a363cb9b91 Fix braces in if-else statements
From the Linux kernel coding guidelines:

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

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-17 09:19:04 +01:00
Lukas Fleischer
8e16853201 parse_duration(): Bail out early in final state
Bail out early if we are reading a character while being in a final
state.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-14 12:22:34 +01:00
Lukas Fleischer
806673dd9b calendar.c: Rename to "ui-calendar.c"
This unit belongs to the presentation layer -- rename the file
accordingly.

Also, rename calendar_*() to ui_calendar_*().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-14 11:08:03 +01:00
Lukas Fleischer
c7f3888607 Rename appointment/event-related UI functions
* Rename "interaction.c" to "ui-day.c" since it no longer contains
  todo-related UI functions.

* Rename appointment/event-related UI functions to ui_day_*().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-14 10:34:00 +01:00
Lukas Fleischer
b30ccc6319 Merge branch 'maint' 2013-02-04 20:11:58 +01:00
Lukas Fleischer
a7944d335e Update copyright ranges
Add 2013 to the copyright range for all source and documentation files.

Reported-by: Frederic Culot <frederic@culot.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-02-04 20:10:14 +01:00
Lukas Fleischer
de73d96188 Use strncasecmp() for case-insensitive comparison
Instead of converting everything to upper case and then using strncmp(),
use strncasecmp() which does case-insensitive comparison out of the box.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-01-30 15:42:08 +01:00
Lukas Fleischer
ef961f4927 Remove unused function mystrtol()
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-01-30 15:39:58 +01:00
Lukas Fleischer
e492ac6f95 Add hidden key handler window
After BUG#6 had apparently been closed with the screen locks introduced
in commit a80f8dcf2c6eb3b54658218bc081ee9694204dd5, some people still
had problems with random characters appearing in the notification bar.
This was obviously caused by wgetch() refreshing the screen if the
status panel was changed. From wgetch(3):

    If the window is not a pad, and it has been moved or modified since
    the last call to wrefresh, wrefresh will be called before another
    character is read.

Since the wgetch(3) isn't thread-safe, there were race conditions
between the notification bar thread drawing to the notification bar and
wgetch() updating the screen. Introduce a (hidden) window that handles
all key presses and never gets changed in order to avoid this.

Also, call wins_wrefresh() explicitly in status_mesg(), since we can no
longer rely on wgetch() updating windows automatically.

Fixes reopened BUG#6. Note that this is a hotfix -- FR#26 has been
opened to ensure we fix this properly in the next major release.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-12-16 02:27:36 +01:00
Lukas Fleischer
1f0f05ecc1 Merge branch 'maint'
Conflicts:
	src/day.c
	src/recur.c
2012-11-23 19:03:57 +01:00
Lukas Fleischer
e269f09438 Replace localtime() with localtime_r()
Since the result of localtime() is stored in a statically allocated
structure, data was overwritten when a context switch occurred during
(or shortly after) the execution of localtime(), potentially resulting
in critical data corruption. BUG#7 and BUG#8 are likely related.

This patch converts all usages of localtime() with localtime_r(), which
is thread-safe.

Reported-by: Baptiste Jonglez <baptiste@jonglez.org>
Reported-by: Erik Saule <esaule@bmi.osu.edu>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-11-22 22:58:04 +01:00
William Pettersson
65dc584662 Add support for entering times in 24 hour format
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-11-18 20:10:45 +01:00
Lukas Fleischer
69345edd77 Add support for copy/paste registers
This adds support for vim-style copy/paste registers which allows
cutting and copying multiple items without having to overwrite the
copy/paste buffer. Registers can be specified using the quote key ('"').
To access a register, type '"x' before a command where "x" is the name
of a register. If you want to copy the currently selected item into
register 1, type '"1c'.

Valid registers are 0-9, a-z, "-" and "_". Note that the latter is the
so-called black hole register, which works similar to the black hole
register in vim.

The register prefix key is currently hardcoded and cannot be configured.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-07-07 21:27:01 +02:00