1336 Commits

Author SHA1 Message Date
Lukas Fleischer
691f8a6015 Refactor startup screen branch
Removes the pointless first parameter to io_startup_screen() and saves
one wins_update() call if system dialogs are disabled.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-12 23:43:20 +02:00
Lukas Fleischer
c65ccb0e77 Use percentage-based width for the sidebar
Use percentage-based widths internally. This slightly impairs (user)
feedback but brings the sidebar configuration menu closer to the actual
configuration format (the user now configures percentage-based widths,
not absolute width values). As a bonus, the sidebar is now resized
automatically on each window resize (based on the percentage values).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-12 23:11:33 +02:00
Lukas Fleischer
b4d5316125 src/mem.c: Fix putchar() parameter
putchar() expects a single character, not a string.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-06 23:51:13 +02:00
Lukas Fleischer
1c442e6aef Miscellaneous small code cleanups
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-06 23:23:58 +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
50be1a1772 Mark some more variables/parameters constant
Fixes a couple of warnings seen with GCC 4.7.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-05 22:18:51 +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
516a793375 Do not use LLIST_*_CONT for appointments
This no longer works since we allow appointments lasting longer than 24
hours. This means that there might be an appointment that starts after
another one and lasts until the selected day, even though the former
doesn't. A simple example, where the old LLIST_TS_FOREACH_CONT approach
fails, is:

    03/29/2012 @ 19:00 -> 03/30/2012 @ 10:00 |Long event
    03/29/2012 @ 21:00 -> 03/29/2012 @ 23:15 |Event 1 (shown)
    03/30/2012 @ 14:00 -> 03/30/2012 @ 15:00 |Event 2 (not shown)

Instead, allow incoherent appointments and only break if the current
appointment *starts after* the selected day.

Reported-by: Baptiste Jonglez <baptiste@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-30 21:46: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
f3ccc70e37 README: Update with recent changes
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-30 10:22:36 +02:00
Lukas Fleischer
c85c3cce55 Fix semantics of "general."{systemdialogs,progressbar}
These were renamed from "skip_"* to *. However, we only changed syntax
and didn't invert their semantic meaning. Fix this by negating the
semantics of those variables. Also, negate these in the configuration
file automatically when running `calcurse-upgrade`.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-29 17:06:56 +02:00
Lukas Fleischer
8916293a26 src/config.c: Detect legacy configuration files
Check configuration variable names against a list of pre-3.0.0
configuration keys and display a warning if such a variable is found.
This reduces the chance of users going wild due to the non-backwards
compatible configuration file changes.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-29 12:14:44 +02:00
Lukas Fleischer
573cccb778 test/data/conf: Update variable names
Update the default configuration file used in our test suite to match
the new configuration variable naming scheme.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-29 11:55:23 +02:00
Lukas Fleischer
afa57d77c0 Add a configuration file upgrade script
This isn't ready for distribution but allows users of the -git version
of calcurse to easily update their configuration files without having to
edit them manually.

Following things are still missing here:

* A command line parameter to specify a custom data directory.
* A backup file that is created automatically before upgrading.
* Debug output.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-29 11:52:07 +02:00
Lukas Fleischer
a5eea86a07 src/config.c: Reorder configuration variables
Sort configuration variables lexicographically. This makes changes
easier to locate.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-29 11:21:05 +02:00
Lukas Fleischer
7cb0fc4cd9 src/config.c: Rename configuration variables
Classify configuration options into different sections. Use consistent
names and formatting.

This was discussed on the mailing lists. A script that updates
configuration files will come in following patches.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-27 21:21:23 +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
481cb5524f Do not strncpy() strings returned by gettext()
Translated strings returned by gettext() are statically allocated.
There's no need to copy them to a buffer, we can use the pointers
returned by gettext() instead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-12 20:36:22 +01: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
7072c9c88a Avoid redundant window resets in config menu
There's no need to reset windows unless the layout was changed. Move
wins_reset() to a separate branch to reflect this.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-12 20:36:22 +01:00
Lukas Fleischer
03ed480654 Avoid redundant virtual screen updates
Remove some redundant wnoutrefresh() invocations. There's no need to
copy a window to the virtual screen unless doupdate() is invoked
immediately afterwards.

This reduces flicker when browsing in the calendar panel.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-12 20:36:22 +01:00
Lukas Fleischer
17aa73b73f Break out configuration main menu
This was the only big block of code left in our main loop. Move it to a
separate function, making the main loop a bit clearer.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-02 09:43:06 +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
80d882d03d test/: Run calcurse in read-only mode
We don't change any configuration nor do we modify items here, so we can
safely invoke calcurse in read-only mode. Fixes a couple of permission
errors seen with `make distcheck`.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-24 22:48:26 +01:00
Lukas Fleischer
3bc9497fc8 Add a read-only option
We don't save any configuration nor items if this is set. This should be
used with care, and hence there's no short option for this.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-24 22:48:26 +01:00
Lukas Fleischer
f76e1cce40 test/: Use correct calcurse binary and data dir
We really don't want to use the calcurse(1) binary from "$PATH" here.
Introduce an environment variable "$CALCURSE" which can be used specify
the binary to use and set this variable to the binary located in the
build directory by default. Similarly, add another environment variable
"$DATA_DIR" that can be used to specify a data directory.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-24 22:48:26 +01:00
Lukas Fleischer
423bfcc9ac test/Makefile.am: Add tests to "EXTRA_DIST"
Add tests and the dummy data directory to "EXTRA_DIST" since we want
these to be shipped in distribution tarballs. Spotted with `make
distcheck`.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-24 22:48:25 +01:00
Lukas Fleischer
fdee1f2a22 src/io.c: Remove C89 incompatible comment
Make commenting style consistent with everywhere else. Use "/* [...] */"
instead of "// [...]".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-20 02:48:19 +01:00
Lukas Fleischer
7c91248629 {src,test}/Makefile.am: Enable pedantic warnings
Now that we're fully POSIX compliant and fixed up some minor issues with
ISO C99, use "-std=c99 -pedantic -D_POSIX_C_SOURCE=200809L" as default
build flags for calcurse and the test suite.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-19 03:23:26 +01:00
Lukas Fleischer
030db26ad3 test/run-test.c: Check fgets() return value properly
Not sure what we were doing here. fgets() returns a pointer, not an
integer!

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-19 03:18:10 +01:00
Lukas Fleischer
2bc4deacdc Fix up fscanf() format strings
All members of the tm structure are signed integers. Stick to using the
correct fscanf() format specifiers for these.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-19 03:14:31 +01:00
Lukas Fleischer
2702a61b0e Fix hash table issues with ISO C99
ISO C99 forbids unnamed structs/unions and nested functions. Move the
"HTABLE_HEAD" and "HTABLE_GENERATE" parts out of the function body and
place them at the very top of the file (where function definitions are
allowed). Also, remove the unnamed struct from "htable.h" (which was
useless anyway).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-19 03:08:16 +01:00
Lukas Fleischer
136e5bc4f7 Fix POSIX compliance
* "WAIT_MYPGRP" isn't POSIX'ish. Relying on this caused compilation
  issues in certain environments (e.g. under Cygwin). As a workaround,
  define "WAIT_MYPGRP" explicitly if it's undefined.

* "P_tmpdir" is an XSI extension. Don't try use it if it isn't
  available.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-19 02:41:09 +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
9a8ea7ff91 src/io.c: Use fork_exec() instead of system()
Speeds up execution, prevents failures when pager or log file contains
spaces, fixes a warning seen with "-Wunused-result".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-18 16:00:18 +01:00
Lukas Fleischer
fb58416f45 Don't chomp on error in ical_readline_init()
Skip the newline check if fgets() returns a NULL string. Fixes another
warning seen with "-Wunused-result".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-18 16:00:18 +01:00
Lukas Fleischer
5130c4d028 Add stricter syntax checking to io_load_*()
Be more restrictive with what we allow in data files and bail out if a
line doesn't conform to our specification, especially in regard to
separators. This prevents unexpected behavior when a data file is edited
manually. As a bonus, this fixes a whole pile of compiler warnings
previously seen with "-Wunused-result".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-18 16:00:11 +01:00
Lukas Fleischer
894ac2d70d Trap fgets() failure in *_scan()
Ensure we don't read arbitrary data when fgets() returns a NULL string
(meaning that either the EOF is encountered or an error occurred). This
also fixes a couple of compiler warnings seen with "-Wunused-result".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-18 13:04:21 +01:00
Lukas Fleischer
47ceb96e13 src/config.c: Add missing configuration variables
Append missing configuration variables to the end of our configuration
file instead of keeping them undefined.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:06:54 +01:00
Lukas Fleischer
8aba3be1e8 src/config.c: Revamp configuration file parsing
Reintroduce a map for configuration variable parsing. We use a different
approach this time: Each map entry contains

* a key,
* a callback that can be used to parse that variable,
* a callback that can be used to serialize that variable and
* a target buffer that the parsed value is written to/read from.

Commits 4f4891bdb88410ae04225f3d6acfa31d73a3901a and
6377582841118688aee13aff98c9216403582e45 show that we are pretty
undecided on using a map or not. However, now that we use parser and
serialization wrappers for every variable, having a central map makes
everything much cleaner. The runtimes of config_load() and config_save()
are slightly increased (by a constant factor). This will also allow us
for implementing proper detection of missing configuration variables in
the configuration file.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:06:49 +01:00
Lukas Fleischer
fcd2c69dd4 src/config.c: Add more parser/serialization wrappers
Add convenience parser/serialization wrappers for all configuration
variables that don't use the default config_parse_*() and
config_serialize_*() helpers yet. This is nothing but a dirty hack and
should be refactored later (e.g. by separating configuration variable
parsing and validation or by adding optional validation functions). It
makes it easier to switch to a more generic configuration parser,
though.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:05:45 +01:00
Lukas Fleischer
b03b5694bc src/config.c: Introduce config_parse_str()
Be consistent with other parser helpers and with config_serialize_str().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:02:22 +01:00
Lukas Fleischer
2ecfe91e04 src/config.c: Keep formatting and comments
Switch to using the new config_file_walk() helper in config_save() and
update existing configuration variables instead of blindly overwriting
the existing configuration file.

Note: This breaks configuration setting storage if one or more settings
are missing in the configuration file. We need to refactor our parser
and serialization routines another time before this can be implemented
properly, though.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:02:22 +01:00
Lukas Fleischer
18efc06ff4 src/config.c: Add serialization helper
Add config_serialize_conf() which can be used to serialize the value of
a configuration setting (counterpart to config_parse_conf()).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-17 10:02:20 +01:00
Lukas Fleischer
b105bf8fab src/config.c: Add junk callback to config_file_walk()
This can be used if we care about junk, such as empty lines and
comments. Currently unused since we skip these when parsing
configuration settings. This makes sense if we want to make slight
modifications to the configuration file without losing formatting and
comments, though.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-16 10:45:09 +01:00
Lukas Fleischer
4c5d6fe612 src/config.c: Make config file reading more flexible
This adds one level of abstraction to config_load() by splitting out the
actual reading routine and the variable setter into two separate
functions. config_file_walk() can be used to read the configuration
file, strip comments and pass every key/value pair to a callback.
config_load_cb() is the new callback used in config_load().

Rationale: It makes sense to reuse the key/value parser to allow for a
much saner config_save() routine that changes single values only instead
of rewriting (and overwriting) the whole configuration file every time.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-16 10:39:14 +01:00
Lukas Fleischer
f73f500559 src/llist.c: Bail out early on negative indexes
Make sure we don't return bogus list elements if negative indexes are
used in llist_{,find_}nth(). Bail out early and return NULL instead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-16 08:44:55 +01:00
Lukas Fleischer
dfc98b5fa1 test/: Add test case for "-S" (pattern search)
* search-001.sh: Compare the output of "-S <regex>" (using a regular
  expression) with hardcoded data.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-22 17:00:19 +01:00