712 Commits

Author SHA1 Message Date
Lukas Fleischer
b0b994896c Add press_any_key() function
Displays "Press any key to continue..." in shell terminal mode and waits
for a key stroke.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-05 16:04:33 +02:00
Lukas Fleischer
2f8a425756 Move endwin() down in wins_prepare_external()
Invoke endwin() *after* calling any other curses functions, such as
refresh(). Calling refresh() after endwin() might restore curses mode
which is a bad thing for a terminal mode initialization routine.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-05 16:04:33 +02:00
Lukas Fleischer
233980622f Refactor wins_launch_external()
* Do window preparation and restoring in separate functions
  wins_prepare_external() and wins_unprepare_external().

* Use fork_exec() and child_wait() instead of system().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:15:36 +02:00
Lukas Fleischer
7982c98be4 Add shell_exec() function
Can be used to execute an external program in a shell.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:15:36 +02:00
Lukas Fleischer
7e61b3de06 Add child_wait() function
Can be used to wait for the termination of a child process.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:15:36 +02:00
Lukas Fleischer
6e2b00096d Add fork_exec() function
Can be used to execute an external program. Provides the possibility to
optionally create a pipe to the new process.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:15:36 +02:00
Lukas Fleischer
003431880e Make recur_*_write() public
This allows one to serialize and send recurrent items to arbitrary
output streams.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:15:35 +02:00
Lukas Fleischer
3076670a76 Refactor out todo item serialization
Add a todo_write() function that allows one to serialize todo items and
write serialized data to an output stream in a fashion similar to
apoint_write() and event_write().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:15:35 +02:00
Lukas Fleischer
496f0d98f8 utf8_width() performance improvements
* Sort character width lookup table by character ranges.

* Use binary search instead of linear search for UTF-8 character width
  lookups which will speed up utf8_width() (O(log n) instead of O(n)).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:09:18 +02:00
Lukas Fleischer
33ce6cd8f8 Avoid segfault in getstr_fixscr()
Avoid a segfault that may occur if getstr_fixscr() changes the scroll
offset to something outside the input boundaries (e.g. if a word that is
only partly visible is killed via backward-kill-word).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:09:17 +02:00
Lukas Fleischer
e85501e5ef Use constant for maximum UTF-8 character size
Introduce a UTF8_MAXLEN constant instead of using the literal value "6"
at various places.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:09:13 +02:00
Lukas Fleischer
c8029a5a13 Refactor getstring code
* Rename static showstring() function to getstr_print(), rename
  ins_char() to getstr_ins_char() and del_char() to getstr_del_char().

* Refactor out getstring data structure initialization and window
  scrolling routines.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:08:46 +02:00
Lukas Fleischer
c4246779ff Make display_todo_item() UTF-8 compatible
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02 10:08:46 +02:00
Lukas Fleischer
c8a745fe23 Make display_item() UTF-8 compatible
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29 18:48:47 +02:00
Lukas Fleischer
39d2671495 Make getstring() UTF-8 compatible
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29 15:43:44 +02:00
Lukas Fleischer
edc20ba443 Split line editing functions into separate file
Move getstring() related stuff into a separate file as a first step on
our way to UTF-8 support for line editing helpers.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29 15:43:44 +02:00
Lukas Fleischer
271457b7a4 Add basic UTF-8 helper functions
Add utf8_width() and utf8_strwidth() which can be used to calculate the
display width of a single character or a string, respectively. A lookup
table is used to spot double width characters, as well as composing
characters. There currently isn't any code to deal with ambigious
characters.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29 15:43:44 +02:00
Lukas Fleischer
7f5fc0c62f src/calcurse.h: Add UTF-8 related macros
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29 15:43:44 +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
0827e00247 Handle resize properly in the sidebar config menu
There used to be no resize handler in custom_sidebar_config() which
resulted in a messed up screen if the terminal was resized during
sidebar configuration. Doing a simple wins_reset() if the terminal was
resized works around this problem.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29 15:21:05 +02:00
Lukas Fleischer
bc2bead505 Do not try to display items with negative width
Don't display anything rather than segfault if the appointment panel
becomes too small (e.g. during a terminal resize).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-28 18:28:21 +02:00
Lukas Fleischer
6c6c7d5ec0 Always work with new window dimensions on resize
This one came up after improving resizing behaviour in commit
fec37db06bbbdff79bc9816046a76e0b29e173b4. We used to use outdated width
and height values at various places without noticing it due to the
resize algorithm being called several times on every resize.

This patch ensures we retrieve the new window dimensions *before* doing
any layout calculations.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-28 18:27:52 +02:00
Lukas Fleischer
fec37db06b Avoid redundant redraws on resize
Use a global flag to record whether the terminal was resized instead of
redrawing everything each time a KEY_RESIZE is read.

Add some additional checks to help_write_pad() as invalid actions may be
passed now due to using signals instead of virtual key presses.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-28 18:22:43 +02:00
Lukas Fleischer
9c3a8a5a49 src/llist.c: Use stable insertion algorithm
Ensure the relative order of elements with equal keys is maintained when
inserting into a sorted list.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-20 19:01:30 +02:00
Lukas Fleischer
b2645847a0 Fix whitespace issues
Strip trailing whitespaces in all source files.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-09 21:37:22 +02:00
Lukas Fleischer
4e6e3a9c97 src/utils.c: Make bell() static
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-07 09:33:50 +02:00
Lukas Fleischer
0f03e80d03 Add missing llist header files to "_SOURCES".
We forgot to add those to the "_SOURCES" variable in commit
0eb1da8dd7fa3ae9d95e12df6058fb41a5ec1c11 and
d668963e2056027526374098efe2869a0d389b92. Spotted by `make distcheck`.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-05-17 10:16:32 +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
79353a625c Ignore daemon lock file if the daemon process died.
Do this in a fashion similar to what was done in commit
6ff95238766656c5ea9d5c65c35d3aef93499f60.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22 02:47:38 +02:00
Lukas Fleischer
621b335179 Return -1 in io_file_is_empty() if file cannot be accessed.
Ensure files don't appear as empty if fopen() fails (e.g. on temporary
EACCES failures).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22 02:47:38 +02:00
Lukas Fleischer
cbd66b13b1 Use "event" structure when iterating over events in app_arg().
Regression introduced in commit
5b174ba5d46c256f41c1cfb952d46f49a088db8a.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22 02:47:37 +02:00
Lukas Fleischer
20c84c3003 Add comments to linked list functions.
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22 02:47:37 +02:00
Lukas Fleischer
112fbe00a4 llist.c: Nullify pointers after free()'ing.
* Set all data members to "NULL" in llist_free_inner() after freeing
  them. Altough we normally shouldn't continue working with a list that
  already went through llist_free_inner(), this will protect against
  dangling pointer bugs in case anyone will ever come up with the idea
  of doing so.

* Set list head to "NULL" in llist_free(), basically to put the list
  into an initialized state.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22 02:47:36 +02:00
Lukas Fleischer
fb5f9d0155 Use generic lists for recurring item exceptions.
Rename "days" structure to "excp" which seems to be a better name here.
Use generic linked lists of excp structures instead of using the "days"
structure which again contains a linked list implementation. Do some
cleanups and invocation fixes.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22 02:47:36 +02:00
Lukas Fleischer
0ad23c7a8f Remove "next" member from "recur_apoint" structure.
Field seems to be unused. Verify using following spatch:

----
@@ struct recur_apoint *rapt; @@

* rapt->next
----

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:36 +02:00
Lukas Fleischer
9fab24818a Use generic lists for recurring apointments and events.
Use them instead of "recur_apoint_list" and "next" pointers in
"recur_event" type variables. Includes some code simplifications and
cleanups.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:35 +02:00
Lukas Fleischer
2438470fd3 Add recur_apoint_inday() and recur_event_inday().
To be used with llist_fn_match_t callbacks later.

I feel a bit ill adding those functions. This definitely is a hack.
Ultimately, there should be some generic recur_item_inday() function
that accepts both recurring apointments and events (or some wrapper
structure) instead of parameter galeere. This is not the right place to
fix that tho.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:35 +02:00
Lukas Fleischer
153c638d1d Use generic lists for generic day items.
Use the new generic list implementation instead of "next" pointers in
day_item type variables. Includes some cleanups and fixes.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:35 +02:00
Lukas Fleischer
bf431d6cd9 Use generic lists for todo items.
Use the new generic list implementation instead of "next" pointers in
todo items.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:34 +02:00
Lukas Fleischer
6f883c0f3f Use generic lists for events.
Use the new generic list implementation instead of those insane "next"
pointers in events. Includes some cleanups.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:34 +02:00
Lukas Fleischer
1de34587ab Remove "next" member from "apoint" structure.
Field seems to be unused. Verify using following spatch:

----
@@ struct apoint *apt; @@

* apt->next
----

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:34 +02:00
Lukas Fleischer
77ef3fe76e Use generic lists for appointments.
Use the new generic list implementation instead of "apoint_list"
everywhere. Simplify stuff and drop unused variables as well.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:33 +02:00
Lukas Fleischer
d668963e20 Add macros to use for thread-safe linked lists.
Add LLIST_TS_* macros in a fashion similar to the already existing
LLIST_* macros. Unlike the non-thread-safe version, these include
LLIST_TS_LOCK and LLIST_TS_UNLOCK which can be used to lock (and unlock)
a list (hence the thread-safety).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:33 +02:00
Lukas Fleischer
612204a60a Add macros for linked list operations.
Mostly in preparation to the pending thread-safe list macros. This way,
we have a similar interface to thead-safe and non-thread-safe lists.

This also adds LLIST_FOREACH and LLIST_FIND_FOREACH macros which can be
used as shortcuts when iterating over all list items or a subset of list
items that is accepted by a callback function.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:33 +02:00
Lukas Fleischer
0eb1da8dd7 Add linked lists implementation.
As discussed on the mailing lists, the various linked list
implementations we currently use at a dozen of different places in the
calcurse source tree are inconvenient and should be replaced by a single
generic solution.

This is a first approach to introduce such a generic implemetation. It
provides following functions:

* llist_init(): Initialize a list.

* llist_free_inner(): Loop through a list and free all items.

* llist_free(): Free the list itself (but not the individual items).

* llist_first(): Get the first item of a list.

* llist_nth(): Get the nth item of a list.

* llist_next(): Get the successor of a list item.

* llist_find_first(): Find an item using a callback function.

* llist_find_next(): Find the next match using a callback function.

* llist_find_nth(): Find the nth item in a list (using a callback).

* llist_get_data(): Get a pointer to the actual data of a list item.

* llist_add(): Add an item at the end of a list.

* llist_add_sorted(): Add an item to a sorted list (using a comparison
                      callback function).

* llist_remove(): Remove an item from a list.

Linked lists are stored in "llist_t" structures, list items are to be
stored in "llist_item_t" structs.

All of the llist_*() functions either expect a pointer to a llist_t
structure (in case the function operates on the list itself) or a
pointer to a llist_item_t (llist_*_next() and llist_get_data()).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-19 11:42:32 +02:00
Lukas Fleischer
7758a41851 Use mem_free() instead of xfree() in check_time().
xfree() should never be used directly and only be called by one of the
mem_*() wrappers.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-17 20:42:47 +02:00
Lukas Fleischer
cc49f1e262 Fix io_file_is_empty() behaviour when file starts with a newline.
Read second byte if the first byte is a newline character to ensure the
file doesn't contain any further data.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-12 18:31:48 +02:00
Lukas Fleischer
57b62a1e49 Use do-while loops when reading start time and duration in apoint_add().
Using do-while loops seems more appropriate here as "item_time" hasn't
even been read when either of the loops are entered. Spotted by
clang-analyzer.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-12 12:02:39 +02:00
Lukas Fleischer
3a4431e568 Fix null pointer dereference in parse_date().
Passing a date in format "mm-dd-yy" where short forms are not allowed
would lead to a null pointer dereference here. This one fixes that.
Spotted by clang-analyzer.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-12 12:02:39 +02:00
Lukas Fleischer
5fc6d92866 Remove some more dead assignments spotted by clang-analyzer.
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-12 12:02:38 +02:00