40 Commits

Author SHA1 Message Date
Lukas Fleischer
9ef427693b Update copyright ranges
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2015-02-07 11:42:20 +01:00
Lukas Fleischer
0a2c4d20fe Retain comments in descriptions and config values
Comments should only be stripped if they start at the beginning of a
line. We do not want to chop off an TODO item description or a
configuration value.

Reported-by: Håkan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-08-18 12:27:22 +02:00
Lukas Fleischer
f52ca8fe12 config.c: Rework configuration serialization
Avoid preallocating buffers on the stack, use dynamic memory allocation
instead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-22 12:08:41 +02: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
a32f6b008a Make sure that tmppath is always NULL-terminated
Fixes GitHub issue #5.

Reported-by: dcb314
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2014-07-08 13:24:25 +02:00
Lukas Fleischer
ce93fa8adb Use a macro to determine the size of arrays
Use following macro instead of "sizeof(x) / sizeof(x[0])" everywhere:

    #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2013-05-04 20:32:26 +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
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
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
4d0c095947 Add compact panels support
Add a configuration option that allows for switching to compact panel
mode. In this mode, all window labels are hidden, so that there's more
space for actual information.

This patch doesn't add a configuration menu entry and doesn't add any
documentation.

Implements FR#7.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-11-25 18:33:29 +01:00
Lukas Fleischer
660eef88e4 Add configuration option to set a default panel
This allows for customizing the panel that is selected by default when
calcurse is started.

Note that this patch doesn't add any documentation. Also, this
configuration option currently cannot be configured using the
configuration menu.

Implements FR#19.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-11-25 18:13:37 +01:00
Lukas Fleischer
41f70382bd src/config.c: Fix parsing an unset color theme
If color support is disabled, the color theme configuration value is set
to "0" or "none", which is a value we no longer accepted since commit
a5486605696f92a749277d49c77bb5b194dc67a5. Re-introduce the branch that
checks for an unset color theme before actually parsing it.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-30 13:25:49 +02:00
Baptiste Jonglez
2c5235cca7 Make appearance.calendarview more explicit in config file
Instead of using 0 or 1 as a value for `appearance.calendarview`,
introduce the more explicit "monthly" and "weekly".

Also update `scripts/calcurse-upgrade.sh` to reflect the change.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-31 20:45:42 +02:00
Baptiste Jonglez
9e1185f526 Give a meaning to DATE_FORMATS
It's a bit weird to consider DATE_FORMATS as part of the date input
format enum, all the more so as it does not even represent the number
of available formats (since those are numbered from 1).

Turn DATE_FORMATS into the number of available date input formats.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-31 20:42:15 +02:00
Lukas Fleischer
bc7c0be84c src/config.c: Bail out on incomplete directive
Fixes a segmentation fault that arose if a line in the configuration
file didn't contain a value/key separator ("="). Instead of operating on
a NULL pointer, throw an error message containing the erroneous
directive and bail out.

Reported-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-29 21:00:39 +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
Lukas Fleischer
6c11b8985c Fix data type of "general.firstdayofweek"
This option wasn't converted to a proper data type when it was renamed
from "week_begins_on_monday" to "general.firstdayofweek". Convert the
boolean option into an enumeration type that can take the values
"monday" and "sunday". Also, update the documentation, add a conversion
rule to the upgrade script and convert the configuration file used in
the test suite.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-17 22:08:00 +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
315b33540a Mark several functions static
These are not needed outside of the corresponding compilation units.
Spotted with "-Wmissing-prototypes".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-20 23:10:56 +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
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
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
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
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
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
a548660569 src/config.c: Drop support for legacy color schemes
We used different naming schemes in versions prior to 1.8. Given that
calcurse 1.8 has been released more than 4.5 years ago, remove the
legacy code that still handles these. Users upgrading from <1.8 to 3.0.0
might need to convert the appropriate config file variable manually.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-12 12:12:13 +01:00
Lukas Fleischer
4f4891bdb8 src/config.c: Remove map for configuration variables
This patch kind of reverts what we did in commit
6377582841118688aee13aff98c9216403582e45. We were a tad off-base there
since using a map doesn't improve maintainability, really. Using
strcmp() at a central location seems perfectly fine and doesn't have the
overhead of the map scanning algorithm.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-09 22:35:12 +01:00
Lukas Fleischer
093b28ac39 Extract config file handlers into a separate file
We used custom_load_conf() to load the configuration file and
io_save_conf() to save configuration. Move these functions, including
all helpers, to a central location.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-09 20:54:20 +01:00