1126 Commits

Author SHA1 Message Date
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
Lukas Fleischer
120f434967 src/io.c: Null-terminate the ical_readline() buffer
Ensure we always return with a null-terminated buffer, even if we read
more than BUFSIZ characters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-11 12:16:35 +01:00
Lukas Fleischer
6f01c7af97 Remove parentheses from return statements
No reason to use "return (x);" here. Refer to the GNU coding guidelines
for details. Created using following semantic patch:

    @@
    expression expr;
    @@

    - return (expr);
    + return expr;

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-02 19:38:38 +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
9aa9fde504 src/recur.c: Speed up recur_item_find_occurrence()
Bail out early if we check for a date beyond the item's repetition end
date.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-02 18:31:10 +01:00
Lukas Fleischer
2bf0249338 Avoid unnecessary start time calculations
Rename recur_*_inday() to recur_*_find_occurrence() and use the new
functions whenever we actually care about the start time of an
occurrence.

Reintroduce recur_*_inday() as wrappers to recur_*_find_occurrence() and
pass NULL as start time buffer (which means "skip start time
calculation"). Keep using these when we only want to know if a recurrent
item belongs to a specific day but do not care about the actual start
time.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:54 +02:00
Lukas Fleischer
28c98f7d01 src/day.c: Allow editing an item's duration
We have the option to enter either an end time or a duration when
creating an item - the same choice should be available when editing an
item.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:53 +02:00
Lukas Fleischer
e9b4f82fbf src/day.c: Allow cancelling an edit
Once the user picked any property to edit, we didn't give him any chance
to cancel editing. Abort if the user presses the escape key or enters an
empty string.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:53 +02:00
Lukas Fleischer
1fb897feae src/recur.c: Remove diff_weeks()
After our recur_item_inday() rewrite, this function is no longer used.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:53 +02:00
Lukas Fleischer
0d51e61f3d src/recur.c: Support recurrent multi-day appointments
Completely rewrite our inday algorithm in recur_item_inday() and be more
fine-grained. This version can deal with recurrent multi-day
appointments unless they overlap.

In case of overlapping appointments, only the last appointment that
starts before the current day is shown. We will need to rewrite the
whole recur_item_inday() interface in order to fix this - this
relatively trivial patch is only the first step.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:53 +02:00
Lukas Fleischer
2d89d33668 src/apoint.c: Format recurrent multi-day items properly
Enable "..:.." formatting for recurrent appointments that last beyond
midnight. Apart from our recurrent item handler being a tad broken,
there is no reason not to do the same thing we already do with regular
appointments here.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:53 +02:00
Lukas Fleischer
b0a6e1d448 Pass item durations to recur_item_inday()
Having item's durations eventually allows for better parsing of
recurrent appointments as we might be interested in how many days are
covered by a multi-day appointment.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:53 +02:00
Lukas Fleischer
3e84074ae5 Make events start on 00:00 (12:00 a.m.)
There is absolutely no reason to make events start on noon, 12:00.
Switching to 00:00 seems totally reasonable here, and makes event
handling a bit easier, also.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:53 +02:00
Lukas Fleischer
50ad339a22 src/event.c: Fix event_inday()
Nasty off-by-one error here. An event should be associated with a day if
it starts at 12:00 a.m. and shouldn't be associated if it enters the
next day.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:52 +02:00
Lukas Fleischer
a2ec9bbf0d TODO: Remove the duration format improvement suggestion
This has been implemented in the last couple of patches.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-21 08:58:47 +02:00
Lukas Fleischer
9fa0507ef2 src/help.c: Update messages referring to durations
Fix help texts to vaguely match the new duration string formats.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:07 +02:00
Lukas Fleischer
6e5ae6562d src/apoint.c: Resize duration input field
Now that we support more powerful duration strings, we should also
resize the input field for duration strings. Twelve characters is enough
space for "+999d23h59m".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:07 +02:00
Lukas Fleischer
4ff3bb9d4f src/utils.c: Support more powerful duration strings
Add support for "1d23h42m"-like duration strings to parse_duration().

Also, switch to using a deterministic finite automaton to parse duration
strings, as things tend to get unclear.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:07 +02:00
Lukas Fleischer
a7489b916e src/utils.c: Remove check_time()
Now that parse_time() and parse_duration() do all the validation work,
this isn't used (nor needed) any longer.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:07 +02:00
Lukas Fleischer
39dd3c251d Use parse_{time,duration}() where appropriate
Make use of these new helpers at various places. Note that this patch
implies a few behavioural changes:

* Short forms such as "23:" and ":45" are allowed when entering times.

* Durations always need to be prefixed with a plus sign ("+"), with the
  nice side effect that you can now use "+3:30" to declare an
  appointment that lasts three hours and thirty minutes (that's much
  more convenient than "+210").

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:06 +02:00
Lukas Fleischer
0acbc06c43 src/utils.c: Introduce parse_{time,duration}()
These helpers can be used in a fashion similar to parse_date(). In
addition to check_time(), parse_time() and parse_duration() support
short forms such as "23:" (instead of "23:00") and ":45" (instead of
"00:45").

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:06 +02:00
Lukas Fleischer
d874f7ff97 src/calcurse.h: Rework date manipulation constants
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:06 +02:00
Lukas Fleischer
162c6aebdd src/utils.c: Mark input string of parse_date() const
We don't mess about with the date string here, so it should be declared
const.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-06 12:37:06 +02:00