72 Commits

Author SHA1 Message Date
Lukas Fleischer
53f0f1d2e3 Add a function to wait for any key press
Introduce a new function keys_wait_for_any_key() and use it instead of
wgetch() whenever the return value is discarded.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 16:37:35 +02:00
Lukas Fleischer
578091f051 Add support for UTF-8 key bindings
A new function keys_wgetch() reads full UTF-8 characters instead of
single ASCII characters only.

Key bindings for regular ASCII characters are stored in a hash map while
the actions of keys with higher code points are stored in a linked list
for space efficiency.

The key serialization methods are updated to handle UTF-8 characters as
well; extended UTF-8 characters (characters not in the ASCII range) are
serialized by using the hexadecimal representation of the corresponding
code points (e.g. "U+00E4").

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:39:23 +02:00
Lukas Fleischer
8544e4a570 Rename keys_getch() to keys_get()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:26:10 +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
978d24a9d2 Update copyright ranges
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-01-30 11:21:53 +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
9ef427693b Update copyright ranges
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-07 11:42:20 +01:00
Lukas Fleischer
919a40f561 Use wins_set_bindings() for the configuration menu
Make use of the general key binding context switching implementation for
the configuration main menu.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-18 10:26:36 +02:00
Lukas Fleischer
035faa883b Make bindings always fill the whole status bar
Compute padding for key bindings in the status bar such that they use
all available space (without exceeding the given page size).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-18 09:51:13 +02:00
Lukas Fleischer
0ad6ff74df keys.c: Merge keydef and binding_labels
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-17 21:16:33 +02:00
Lukas Fleischer
76563c9b90 Rework key binding context switching
Store key binding contexts using another data structure to optimize
space usage and execution time.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-17 21:08:55 +02:00
Lukas Fleischer
6550591b08 Add a key binding to reload appointments and todos
This allows for reloading the appointment and todo item files without
having to restart calcurse.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-16 16:03:26 +02:00
Lukas Fleischer
c4dae80dd2 Add command prompt
This adds support for vim-style command mode. The command mode can be
entered with pressing ":" (by default, the key binding is configurable).

Currently, no command is supported. Support for various commands will be
added later.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-07-17 14:03:53 +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
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
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
db51503b64 keys.c: Remove several unneeded assertions
Seen when compiling with clang and "-Wtautological-compare".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-12-06 20:32:41 +01:00
Lukas Fleischer
db8886a34c keys_save_bindings(): Skip unset key bindings
Saving unset key bindings currently results in a segmentation fault or
invalid key specifiers being stored. Skip these entries to avoid this.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-12-05 15:57:29 +01:00
Lukas Fleischer
8311f14dea Add new default key binding for generic-paste
Use "p" as an additional (vim-style) default binding for generic-paste.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-07-07 21:42:24 +02:00
Lukas Fleischer
13c21ac280 Merge cut/delete
Remove the cut function and merge it into the del-item command. This
allows for vim-style cutting/pasting.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-07-07 21:39:35 +02: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
Lukas Fleischer
dd059ca812 Add a key binding for generic-copy
This finally adds full copy-paste support. Implements FR#15.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-07-06 01:59:24 +02:00
Lukas Fleischer
a9efce76f3 Do not bind "c" to "generic-config-menu" by default
The "c" key will be used for the generic-copy command in the future. The
configuration menu isn't needed a lot, so binding it to "C" only seems
legit.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-07-06 01:57:03 +02:00
Lukas Fleischer
78c460a246 src/keys.c: Fix help strings for generic-{cut,paste}
Reported-by: rafael ff1 <rafael.f.f1@gmail.com>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-18 00:09:40 +02:00
Lukas Fleischer
1d74966a60 src/keys.c: Add vim-style default bindings for generic-*
Add vim-style key bindings for generic-prev-day, generic-next-day,
generic-prev-week and generic-next-week in a fashion similar to what we
use for generic-*-month and generic-*-year. The key "t"/"T" for
generic-prev-day/generic-next-day is somewhat less than perfect but this
is okay given that we're running out of keys...

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-13 00:16:55 +02:00
Lukas Fleischer
cabc22e032 Add key bindings to go to the previous/next month/year
In addition to generic key bindings for moving one day (week)
forward/backward, define similar bindings for moving a month or a year.
Of course, count prefixes are allowed here as well.

Also add status bar hints and help texts.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-13 00:12:32 +02:00
Lukas Fleischer
42c486d30d Rename displacement enumeration elements
* Rename "LEFT" to "DAY_PREV", "RIGHT" to "DAY_NEXT", "UP" to
  "WEEK_PREV" and "DOWN" to "WEEK_NEXT" to reflect the semantics of
  these operations. Remove the unneeded "MOVES" element.

* Reorder code to improve consistency.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-13 00:12:27 +02:00
Baptiste Jonglez
4c4d4d3eb3 Use mvwaddstr() instead of mvwprintw()
When we only want to display a string at a specific place of the
screen, there's no need to use the more complex mvwprintw(), use
mvwaddstr() instead.

This should be slightly more efficient, and, above all, it prevents
weird things to happen if our string contains a '%', being interpreted
as an unwanted format string.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-31 20:27:43 +02:00
Lukas Fleischer
cfd8ede2b3 Switch to Linux kernel coding style
Convert our code base to adhere to Linux kernel coding style using
Lindent, with the following exceptions:

* Use spaces, instead of tabs, for indentation.
* Use 2-character indentations (instead of 8 characters).

Rationale: We currently have too much levels of indentation. Using
8-character tabs would make huge code parts unreadable. These need to be
cleaned up before we can switch to 8 characters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-21 10:13:05 +02:00
Baptiste Jonglez
2951cf8320 Add dummy help for cut and paste
It looks like cutting and pasting are only half-implemented: this only
avoids a segfault when trying to get help on these functions.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-14 19:32:18 +02:00
Lukas Fleischer
6da787a5cc Declare several parameters/variables constant
Add the "const" keyword to parameters and variables that are never
modified. Most of these were spotted by "-Wwrite-strings".

We cast the second parameter to execvp() explicitly as it expects a
"char *const[]" where it should expect a "const char *const[]"
(according to the documentation, this is due to compatibility reasons).
This should be changed once we come up with a better solution.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-08 21:50:05 +02:00
Lukas Fleischer
d0b0ed3c20 src/keys.c: Use generic list implementation
Be consistent and replace the custom linked list implementation we used
here by the generic list implementation we use everywhere else. This
reduces code complexity, while slightly improving memory overhead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-05 23:47:14 +02:00
Lukas Fleischer
80f7e8ead5 Mark localized string literals constant
Translated strings returned by gettext() are statically allocated and
shouldn't be modified.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-05 22:18:46 +02:00
Lukas Fleischer
d31cda5424 Revert a bunch of strncmp() conversions
All strncmp() usages were replaced by (evidently) equivalent strcmp()
invocations in commit 2c9499bf272e06a62902711c6c20621ef3f80e64. However,
some of the strncmp() calls were perfectly justified and we actually
broke iCal import and "C-"-style key bindings by converting them to
strcmp(). Fix this by reverting all affected conversions.

Reported-by: Baptiste Jonglez <baptiste@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-30 15:50:27 +02:00
Lukas Fleischer
c9aff6d213 Update copyright ranges
Add 2012 to the copyright range for all source and documentation files.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-26 14:38:16 +02:00
Lukas Fleischer
0f4b45e624 Get rid of string structures
These were only used to construct constant strings with additional
length fields. However, we can just use standard constant character
arrays instead and let the compiler calculate the string length.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-12 20:36:22 +01:00
Lukas Fleischer
2c9499bf27 Use strcmp() instead of strncmp()
strncmp() isn't intended to be a secure strcmp() replacement, it is
designed to be used if you want to compare the first n characters of two
strings. Since we always compare character pointers with string
literals, switch to using strcmp() everywhere.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-12 20:36:22 +01:00
Lukas Fleischer
b5c1981842 Revamp key bindings display
Refactor the logic inside keys_display_bindings_bar() and remove the
need to place the "show next page" key binding at the right positions.

This used to be a pain to maintain, since we always had to move key
bindings around when introducing a new key. Fix this by passing the
actual key bindings in an array and using a separate parameter for the
"show next page" key binding (which is automatically inserted at the
right places from now on).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-02 09:43:04 +01:00
Lukas Fleischer
8892bb3625 Remove all usages of bzero() and bcopy()
The bzero() and bcopy() functions are deprecated and were removed from
the POSIX standard in IEEE Std. 1003.1-2008. Remove all usages of
bzero()/bcopy() and replace them by appropriate memset()/memmove()
calls.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-19 01:41:01 +01:00
Lukas Fleischer
c17b535a33 Fix up strncat() usage
The last argument to strncat() should not be the total buffer length; it
should be the space remaining:

    The strncat() function shall append not more than n bytes (a null
    byte and bytes that follow it are not appended) from the array
    pointed to by s2 to the end of the string pointed to by s1. The
    initial byte of s2 overwrites the null byte at the end of s1. A
    terminating null byte is always appended to the result.

This patch fixes a couple of potential buffer overflow vulnerabilities.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-18 16:00:18 +01:00
Lukas Fleischer
ce3f0ce76f Make use of the NULL macro
Use this constant everywhere when referring to a null pointer instead of
casting 0 to various types of pointers. Created using following semantic
patch:

    @@
    type type;
    @@

    - (type *)0
    + NULL

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-02 19:33:23 +01:00
Lukas Fleischer
7cc6305588 Do not cast unused return values to void
A small style fix that removes all remaining "(void)" casts. Using these
isn't encouraged in GNU coding guidelines and doesn't serve a certain
purpose, except for satisfying a few static code analysis tools. We
already nuked some of these in previous patches, but this semantic patch
should fix what's left:

    @@
    identifier func;
    @@

    - (void)func (
    + func (
    ...);

Long lines were re-formatted manually.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-02 18:32:17 +01:00
Lukas Fleischer
44bc9605d6 Avoid use of printf()/fprintf()
Use one of the following functions where appropriate:

* puts() (whenever we print hard coded strings to stdout)
* fputs() (whenever we print hard coded strings to a stream)
* putchar() (whenever we print a single character to stdout)
* fputc() (whenever we print a single character to a stream)
* strncpy() (whenever we copy hard coded strings to a buffer)

This removes the overhead introduced by the format string parser and
reduces the number of false positive C-format strings spotted by
xgettext(1)'s heuristics.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-02 18:31:10 +01:00
Lukas Fleischer
98651a549f Add count buffer to keys_getch()
Key commands can be prefixed with a natural number - keys_getch() will
store this number in the buffer pointed to by the second parameter. Set
this parameter to NULL to disable count prefixes.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:06 +02:00
Lukas Fleischer
309fa84cb7 Add key binding for pipe-item command
This removes the need of reading the whole data file and find matching
entries if we want to parse appointments in external programs.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-07 07:05:48 +02:00
Lukas Fleischer
470f05cd38 Enable arrow key navigation by default
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29 15:40:38 +02:00
Lukas Fleischer
38865b8e48 Update copyright notices in source files, documentation and "COPYING".
* Update copyright dates (use 2004-2011 as date range everywhere).

* Change copyright holder from "Frederic Culot" to "calcurse Development
  Team".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22 07:26:05 +02:00
Lukas Fleischer
6fb0f6f4c6 Compare pointers to "NULL" instead of "0".
"bad_zero.cocci" spatch from http://coccinelle.lip6.fr/impact_linux.php.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-05 09:27:04 +02:00
Lukas Fleischer
9c9fd5da15 Overall indentation fixes.
Use spaces instead of tabs for source code indentation only, strip
trailing whitespaces from lines.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-14 19:03:53 +01:00
Lukas Fleischer
355687b644 Ensure key descriptions in status bar are always null-terminated.
Key descriptions are just strncpy()'ed to key[], with KEYS_KEYLEN as
maximum character count. This leads to a non-null-terminated string if
the source pointer actually points to a string with a length of
KEYS_KEYLEN bytes. Always appending a null character fixes this.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-05 15:39:01 +01:00