178 Commits

Author SHA1 Message Date
Lars Henriksen
ad183c61a9 CLI: do not start daemon if calcurse is running
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-01-07 16:57:53 +01:00
Lars Henriksen
4ba2cc46d7 CLI: time assignments for filter options
Explanation. There is an important difference between "to <date>" (e.g.
to 15/11/2018)  and "to <date time>" (e.g. to "15/11/2018 13:30"):
<date> is a time span (of 24 hours), while <date time> is a point in
time.

"To <date>" really means "to the end of <date>", while "before <date>"
means "before the beginning of <date>". There are 24 hours between the
two, whereas there is only one second between "before <date time>" and
"to <date time>".  Similar for from/after.

An earlier commit introduced parse_datearg() that only accepts a date
without a time. Hence, a date should be treated as a time span from
midnight to one second before next midnight.

The commit also fixes an error detection bug (filter.start_from/to and
filter.end_from/to were updated too early).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-01-07 16:57:51 +01:00
Lars Henriksen
42e296c840 CLI: long options to override configuration file settings
The input and output date formats may be set from the command line.
Intended for scripts that must be independent of the local user
configuration.

Cannot be used in interactive mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-01-07 16:57:49 +01:00
Lars Henriksen
3d7bb89c88 CLI: take input date format from configuration file, do not accept time
Before this patch the input date parsing accepts three formats:
yyyy/mm/dd, mm/dd/yyyy, yyyy-mm-dd. They are tried in sequence. It also
accepts an additional time (hh:mm), or a time without a date.

There are several issues with this:

- it is not documented
- the date format dd/mm/yyyy is not accepted
- print_date() and filter option settings (in parse_args()) can only
  handle midnight times (which are the result of a date without time)
- it is highly uncertain what happens if a time (without a date) is
  given; at least the -d option treats a time without colon (1215 for
  12:15) as a number

It seems that acceptance of time input is a by-product and not needed.
For these reasons the input date parsing has been changed:

- the format is taken from the configuration file (as is the case for
  the output date format)
- only a date, and no time, is accepted

Because the input date format is used during parsing of the command
line, the configuration file must be loaded first, i.e. the options -D
or -C must be parsed before the remaining ones. Loading the
configuration file may result in errors (e.g. caused by changes between
versions). For this reason config_load() has been made more tolerant and
issues warnings instead of exiting.

A followup patch will introduce two options to allow the configuration
file settings to be overridden for input and output date formats.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-01-07 16:57:48 +01:00
Lars Henriksen
215e90d348 Command line options: -P, option check, usage, help
Option -F/--filter renamed to -P/--purge; -F retained as deprecated.
Check for non-option arguments and for filter, format and query-range
options only.  Update of help and usage messages.

Fixed --status output when calcurse is not running.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-01-07 16:57:46 +01:00
Lars Henriksen
03880a82bf Fix day range for queries
In "--from a --to z", a is included in the range, z not. This is
non-intuitive and disagrees with the semantics of "to" in filter options
like --filter-start-to, where "to" (and "from") are used inclusively (as
opposed to "before" and "after"). It also has the effect that "--from
today --to tomorrow" has a range of 1 day, "--to z" a range of 0 days
(otherwise not allowed), and "--to today --days -1" is allowed and
displays yesterday!

The implementation has been fixed to agree with "inclusive" semantics.
Options --from and -days with negative range are allowed, while --to and
--days are disallowed also when the range is negative.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2019-01-07 16:57:43 +01:00
Lars Henriksen
4285e88593 Rewrite of io_init()
The introduction of the "-C <confdir>" option is an opportunity to
review the initialization of data paths. It lead to a rewrite.

Two "root" directories are used (data and configuration files); by
default they are identical. The statically allocated path buffers are
turned into dynamically allocated buffers.

Missing files/directories now include hooks.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-12-14 10:35:11 +01:00
Lars Henriksen
5ad0019b23 Only reload if data files were changed (replacement)
This is a replacement for commits 57dd3d6 and 912124b.

The idea is to move the check for modified files and the list initialization
into io_load_data(), and let io_load_data() decide what to load. A new
argument is used to force a load.

The return code from new_data() (the renamed version of
io_check_data_files_modified()) tells which files have changed.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
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
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
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
0df373f26a Check for optional argument to -s option
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-12 15:38:24 +02:00
Lukas Fleischer
9f6678bc49 Update copyright ranges
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-01-12 08:40:30 +01:00
Lukas Fleischer
0d74c14fd1 Do not start the daemon more than once
Avoid starting multiple daemon instances if the --daemon argument is
passed and the daemon is already running. Terminate the already running
instance before spawning a new one instead.

Suggested-by: Vlad Glagolev <scm@vaygr.net>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-19 18:19:02 +02:00
Lukas Fleischer
9ef5fe2191 Always use memory management wrappers
Use mem_*() wrappers instead of directly accessing libc functions when
allocating/deallocating memory.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-13 19:51:43 +02:00
Lukas Fleischer
07954626c6 Support format strings when dumping imported items
In commit 3eae7ce (Add --list-imported command line option, 2016-01-12),
we added an option to print the hashes of imported items to stdout.
Extend this command line option such that it dumps the items using the
specified formatting strings. With the new behavior it is, for example,
easier to check items for import errors.

Also, rename the option from --list-imported to --dump-imported (it is
not part of any official release yet so we do not need to care about
backwards compatibility).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-11 18:33:57 +01:00
Lukas Fleischer
62f04c3f9a Support format specifiers in grep mode
Honor --format-* parameters when using the -G operation. In the case of
recurring items, the first occurrence is used.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-05 19:09:36 +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
03c4465baf Fix behavior of --todo with an optional argument
The previous behavior of --todo was to always only list uncompleted
items, unless zero was specified as additional argument. Restore and
document this behavior.

Also, fix two tests that failed because the --todo output is now sorted.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-28 18:37:31 +01:00
Lukas Fleischer
41389abd55 args.c: Revise help/usage/version output
Remove obsolete options from the help text, add new options, clean
everything up, cut translatable strings into atomic chunks.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-28 08:55:54 +01:00
Lukas Fleischer
6061fec01d Add a --daemon command-line parameter
When specifying --daemon, calcurse immediately forks and runs the
notification daemon in the background.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-28 00:04:00 +01:00
Lukas Fleischer
caee34449c Export item UIDs upon request
Add a new --export-uid command line option that adds each item's hash to
the UID property when exporting.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-15 18:25:05 +01:00
Lukas Fleischer
3eae7ce828 Add --list-imported command line option
When this option is used together with -i/--import, the object
identifiers of imported objects are printed to stdout.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-13 17:39:44 +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
6d9129764b Implement filter mode
Add a new -F mode that is identical to -G but writes the result back to
the calcurse data files instead of stdout.

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
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
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
a6c73232a8 Use LONG_MAX for invalid dates in parse_datearg()
We cannot use -1 here since negative values are valid dates.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-22 11:34:11 +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
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
8553a99161 Add io_load_data() wrapper
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-10-10 01:38:25 +02:00
Lukas Fleischer
aca92e619d Fix parsing of times in parse_datetimearg()
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-09 15:43:08 +02:00
Lukas Fleischer
519107dc47 Extend date formats for filters
Allow for specifying both date and time in all dates and date ranges
used in filters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-09 12:56:13 +02:00
Lukas Fleischer
e1af76eb8d Add --filter-{start,end}-range
These are shorthands for --filter-start-from/--filter-start-to and
--filter-end-from/--filter-end-to.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-08 23:57:52 +02:00
Lukas Fleischer
c2a9292bf4 Add a grep mode
This allows for printing a subset of the items in the data files by
using filters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-07 16:34:48 +02:00
Lukas Fleischer
9f24adfded args.c: Reword error messages
Use the same error message if option arguments have the same data type
and always add the violating value.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 16:26:45 +02:00
Lukas Fleischer
f9208c0b3d Use backwards-compatible out format for queries
Print TODO items before appointments in query outputs and add an empty
line between the list of TODO items and the list of appointments. This
is how items were printed before the big parser refactoring.

Also, add a test to ensure we do not unintentionally change that format
in the future.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 15:48:02 +02:00
Lukas Fleischer
c2dc3109ae Do not use filters in GC or import mode
Filtering items when running garbage collection or when importing data
might result in data loss, so simply ignore filters here.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 12:08:14 +02:00
Lukas Fleischer
aa682f7a11 Rework command line argument handling
Add a new range query mode (--days) and refactor the command line
argument parser.

Note: This slightly changes the behavior of some command line
parameters, since date arguments no longer use the input date format
from the configuration file!

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 12:08:14 +02:00
Lukas Fleischer
1878b7c4b0 Allow for filtering TODO items
The item filters now apply to both appointments and TODO items. Also,
add a new type mask "todo" and the following new filter options:

* --filter-priority
* --filter-completed
* --filter-uncompleted

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 12:08:14 +02:00
Lukas Fleischer
86553f35fe Add a query mode
Add a new parameter -Q that can be used to print all appointments inside
a given query range, followed by all TODO items. The date range can be
specified using the --from and --to arguments. The start date defaults
to the current day, the end date defaults to the day after the start
date if not specified.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 12:08:14 +02:00
Lukas Fleischer
9ce5861468 Add pattern filter option
This adds a new item filter option --filter-pattern and removes the
whole -S parameter logic, while making -S an alias for --filter-pattern.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 12:08:14 +02:00
Lukas Fleischer
bfe73d0e5d Add item filters
This adds the following filter options that allow for restricting the
set of items that are read from the appointments file:

* --filter-type
* --filter-start-from
* --filter-start-to
* --filter-start-after
* --filter-start-before
* --filter-end-from
* --filter-end-to
* --filter-end-after
* --filter-end-before

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-06 12:08:14 +02:00
Lukas Fleischer
5aec540895 Allow for merging data files when reloading
This allows for merging the (unsaved) items with the items from the data
files when invoking the reload operation. To this end, an external merge
tool (defaults to vimdiff) is used.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-16 23:31:31 +02:00
Lukas Fleischer
0529b864b0 Fix segmentation fault
This adds some more accurate checks to avoid a segmentation fault that
occurred when accessing a nonexistent item.

Fixes GitHub issue #7.

Reported-by: Bromind <martin.vassor@hotmail.fr>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-06-25 12:35:43 +02:00
Lukas Fleischer
2a62351d25 Reintroduce heading and separator in appointments
This re-introduces the heading (showing the POM and the current date) as
well as the separating line between events and appointments.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:10:56 +02:00
Lukas Fleischer
35314dfdeb ui-day: Large-scale refactoring
Use the generic list box implementation for the appointments panel. This
results in some major changes to how the items are printed.

Note that this temporarily removes the heading showing the POM and the
date as well as the separating line between events and appointments.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-05-18 11:06:43 +02:00