1450 Commits

Author SHA1 Message Date
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
Lukas Fleischer
cb69a4c087 test/: Add test cases for "-a" and "-n"
* appointment-001.sh: Compare output of "-a" with hardcoded data.
* next-001.sh: Compare output of "-n" with hardcoded data.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-22 16:40:00 +01:00
Lukas Fleischer
dbb19b7c25 test/: Add test cases for "-d" and "-s"/"-r"
* day-001.sh: Compare output of "-d<date>" with hardcoded data.
* day-002.sh: Compare output of "-d<num>" with hardcoded data.
* day-003.sh: Compare output of "-d<num>" with "-s<date> -r<num>".
* range-001.sh: Compare output of "-r" with hardcoded data.
* range-002.sh: Compare output of "-r<num>" with hardcoded data.
* range-003.sh: Compare output of "-r<num>" with "-s<date> -r<num>".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-22 01:03:31 +01:00
Lukas Fleischer
32530f0e50 test/: Add generic tests for todo operations
* todo-001.sh: Tests the "-t" command line option (calculates expected
  output by parsing the todo data file).

* todo-002.sh: Tests "-t<num>" in a way similar to todo-001.sh.

* todo-003.sh: Tests "-t0" in a way similar to todo-001.sh.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-22 00:13:35 +01:00
Lukas Fleischer
31b4c71eb2 test/: Add three basic self tests
* true-001.sh: Always returns true - this should never ever fail.

* run-test-001.sh: Invokes run-test, passing itself as a parameter.
  Subsequently, it outputs the very same (hardcoded) expected and actual
  values.

* run-test-002.sh: Tests run-test's negative assertion feature in a way
  similar to run-test-001.sh. However, output different (hardcoded)
  expected and actual values and invoke run-test with the negative test
  prefix ('!').

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-22 00:13:35 +01:00
Lukas Fleischer
d34e6502e9 test/: Add initial configuration file
As a preparation for our test cases (needed for date formatting etc.)

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-22 00:13:35 +01:00
Lukas Fleischer
9cba56ac0a test/run-test.c: Support negative assertions
Sometimes, we might want to make negative assertions (tests where
expected and actual output are expected/known to be different). A test
can be marked negative by prefixing it with an exclamation mark ('!'):

    $ ./run-test !test-negative
    Running test-negative... ok

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-21 23:06:32 +01:00
Lukas Fleischer
e66e2d4277 Add a minimal test suite
Introduce a new "test/" sub-directory that contains tests for calcurse.
Right now, it only includes the quick-and-dirty "run-test" helper that
can be used to run and verify tests:

    $ ./run-test test-1 test-2 test-3 test-4
    Running test-1... ok
    Running test-2... ok
    Running test-3... FAIL

Each argument passed to run-test must be a test script located in the
current directory. run-test invokes each script twice and passes the
command line argument "expected" and "actual", respectively. A test case
succeeds if both "expected" and "actual" instances return with a zero
exit status and produce exactly the same output. It fails otherwise.

run-test terminates with a non-zero exit status as soon as one of the
test fails.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-21 23:06:32 +01:00
Lukas Fleischer
7a230fa76a src/calendar.c: Fix range check in calendar_move()
We added count prefix support to motion commands in commit
59e006e56d9f893506af56a4ca114fe53b537e49 but obviously forgot to check
whether the range checks in calendar_move() still work correctly.

Refactor out range checks and replace them by a single check that is
performed *after* the new date is computed, but before we assign the new
value to the actual selected date. This ensures we won't have to bother
about these again when changing/adding functionality in/to
calendar_move(), while keeping performance (date_change() is pretty
cheap and range violations are corner cases anyway).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-21 23:06:12 +01:00
Lukas Fleischer
a79a33e8f4 Split note file generation into separate function
We currently use this in one place only but might reuse this a couple of
times later (when migrating to libical).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-17 00:52:39 +01:00
Lukas Fleischer
5dc443fc3d Break out different import/export formats
Extract iCal and pcal import/export routines into separate files. This
reduces complexity of the super huge "io.c" source file and makes it
easier to follow changes that affect the iCal and pcal routines only
(commits affecting both formats are very uncommon).

Before:

    $ wc -l src/io.c
    2938 src/io.c

After:

    $ wc -l src/{io,ical,pcal}.c
     1445 src/io.c
     1263 src/ical.c
      317 src/pcal.c
     3025 total

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-07 12:41:51 +01:00
Baptiste Jonglez
7850f6ddf1 src/apoint.c: Update in-notify-bar help for new duration syntax
Signed-off-by: Baptiste Jonglez <baptiste@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-07 12:30:56 +01:00
Baptiste Jonglez
71e05b1dcf src/apoint.c: Fix a length bug introduced by new duration format
Commit 4ff3bb9d introduced a new format for parsing durations, thus
allowing a larger string to be retrieved from user input.

However, the string used is still declared with the old length,
leading to crashes when compiling with stack-smashing protection
features (the default on Archlinux). Inputting a duration string of
more than 8 characters (such as "+1d11h11m") would crash calcurse with
a *** stack smashing detected *** message.

Using a larger string from the start fixes the bug.

Signed-off-by: Baptiste Jonglez <baptiste@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-07 12:30:56 +01:00
Lukas Fleischer
af9bdd018a Merge branch 'maint'
Conflicts:
	src/io.c
2011-12-16 15:18:32 +01:00
Jérôme Pinot
9a85b790aa Format "DURATION" field properly on ical export
Use days/hours/minutes/seconds instead of seconds in the DURATION field.
It fixes interaction with other softwares like phpicalendar.

Lukas: Remove use of dur-week. RFC 5545 states that you cannot use this
in conjunction with dur-day. Also, fix formatting and use proper
constants.

Signed-off-by: Jerome Pinot <ngc891@gmail.com>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-16 15:12:17 +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
27368d4ee6 src/utils.c: Mark is_all_digit() parameter const
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-09 22:35:53 +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
Lukas Fleischer
ef716e4a92 src/day.c: Nuke unneeded variable
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-09 01:20:06 +01:00
Lukas Fleischer
a01cbe0c36 src/todo.c: Remove several unneeded variables
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-09 01:14:05 +01:00
Lukas Fleischer
dfe835190f src/apoint.c: Remove several unneeded variables
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-12-05 00:48:47 +01:00
Lukas Fleischer
fc9cd6149b src/utils.c: Support escape sequences in format strings
We support all simple escape sequences listed in the ANSI C standard,
plus "\0" to allow for printing null characters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-22 14:55:15 +01:00
Lukas Fleischer
1ff6f39c86 Merge branch 'maint' 2011-11-15 21:37:37 +01:00
Lukas Fleischer
adf769078c src/utils.c: Support printing '%' in format strings
This allows using "%%" to print the '%' character.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:09:48 +01:00
Lukas Fleischer
6b95f7b67d src/args.c: Remove obsolete "-N" flag
This is superseded by custom format strings.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:15 +01:00
Lukas Fleischer
7f0c3003ac src/args.c: Allow for specifying custom format strings
Following long command line options can be used to override the default
format strings:

* --format-apt
* --format-recur-apt
* --format-event
* --format-recur-event
* --format-todo

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:15 +01:00
Lukas Fleischer
f77f4647d1 print_*(): Add format specifier to print notes
* Move print_notefile() from "src/args.c" to "src/utils.c".

* Add a "%N" format specifier to print_*(). This invokes
  print_notefile() and prints the content of an item's note file.

* src/args.c: Use the new format specifier instead of print_notefile()
  everywhere.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:15 +01:00
Lukas Fleischer
349bd3f88b Use a dynamic method to print todo items to stdout
This goes in line with the other commits adding print_*() support.

Following format specifiers are allowed:

* p: Print the priority of the item
* m: Print the description of the item
* n: Print the name of the note file belonging to the item

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:14 +01:00
Lukas Fleischer
d32d811623 src/apoint.c: Remove apoint_recur_s2apoint_s()
This one is hackish, obsolete and no longer used by any other function.
Drop it!

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:14 +01:00
Lukas Fleischer
3c59faa925 Use a dynamic method to print recurrent items to stdout
Add print_recur_apoint() and print_recur_event() helper functions to
print recurrent items to stdout and use them everywhere. Currently,
these are only wrapper functions to print_apoint() and print_event()
that create temporary, non-recurrent items.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:14 +01:00
Lukas Fleischer
a9b820abbe Use a dynamic method to print events to stdout
Add a flexible helper function print_event() and use it whenever we
print events to stdout. This reduces the number of copy-pasted code and
eventually allows for specifying custom format strings.

Following format specifiers are supported:

* m: Print the description of the item
* n: Print the name of the note file belonging to the item

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:14 +01:00
Lukas Fleischer
330ca4d3cb Use a dynamic method to print appointments to stdout
Add a flexible helper function print_apoint() and use it whenever we
print appointments to stdout. This reduces the number of copy-pasted
code and eventually allows for specifying custom format strings.

Following format specifiers are supported:

* s: Print the start time of the appointment as UNIX time stamp
* S: Print the start time of the appointment using the "hh:mm" format
* d: Print the duration of the appointment in seconds
* e: Print the end time of the appointment as UNIX time stamp
* E: Print the end time of the appointment using the "hh:mm" format
* m: Print the description of the item
* n: Print the name of the note file belonging to the item

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:14 +01:00
Lukas Fleischer
edad2f39db Removed unused parameter from apoint_sec2str()
This is no longer needed as of commit 2d89d336.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:14 +01:00
Lukas Fleischer
41c33eeb44 Use a global configuration variable
This is one of the few valid use cases for a global variable. No need to
make it pseudo-local and pass it from one function to another.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14 11:08:14 +01:00
Lukas Fleischer
14b6ae79a2 Merge branch 'maint'
Conflicts:
	src/calcurse.h
	src/io.c
2011-11-11 12:29:48 +01:00
Lukas Fleischer
5e4db62662 src/io.c: Avoid use of memcpy()
Use strncpy() and a proper limit, which ensures we never read more
characters than the buffer can hold. Also, ensure we always
null-terminate strings here.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-11 12:18:16 +01:00