170 Commits

Author SHA1 Message Date
Lukas Fleischer
6907ae73e7 Revise cut/pasting
Instead of calling type-specific duplication handlers and inserting
clones of the original items when pasting, save the generic day item and
remove the actual item from the linked list, so that it can be inserted
anywhere else later.

The cut/paste buffer is moved to the interaction unit, item-specific cut
operations are changed to remove the item from the linked list only
instead of copying and freeing it. An item is only freed if another item
is cut before the current cut/paste buffer is pasted. All paste
operations are changed and reinsert the actual item instead of creating
a clone.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-30 14:34:36 +02:00
Lukas Fleischer
75d0c4dc17 Remove the need for the "day_saved_item" struct
Do not store the currently selected item in day_write_pad() -- use
day_get_item() and apoint_hilt() in day_popup_item() instead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-30 14:34:34 +02:00
Lukas Fleischer
82d86ad7c7 Fix compilation with NLS disabled
* src/utils.c: Only call setlocale() if NLS is enabled.
* src/calcurse.h: Define a fallback macro ngettext() if NLS is disabled.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-06-30 12:34:54 +02:00
Baptiste Jonglez
4c4d4d3eb3 Use mvwaddstr() instead of mvwprintw()
When we only want to display a string at a specific place of the
screen, there's no need to use the more complex mvwprintw(), use
mvwaddstr() instead.

This should be slightly more efficient, and, above all, it prevents
weird things to happen if our string contains a '%', being interpreted
as an unwanted format string.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-31 20:27:43 +02:00
Baptiste Jonglez
b5a911421f Fix incorrect i18n usage for some strings
Some strings are initialized without wrapping them in _(); instead,
_() is applied on the variable when it is used.

This is incorrect, since these strings don't get added to the catalog.
Fix that by applying _() only once, when the string is declared.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-25 13:28:26 +02:00
Lukas Fleischer
f5efea85a6 Merge branch 'maint'
Conflicts:
	src/io.c
	src/notify.c
	src/utils.c
2012-05-23 22:26:05 +02:00
Lukas Fleischer
94a5d4cb1b Fix default time format for multi-day appointments
As of commit 0791eaabca0fb1ef8a8675e47d701bbcde4d4a3f, we use strftime()
instead of apoint_sec2str() to format start and end dates of
appointments. "%H:%M" is the default strftime() format string used to
simulate apoint_sec2str(). However, apoint_sec2str() additionally checks
for intersection with the current day and displays "..:.." instead of
the actual time if the item doesn't start (end) at the current day. Add
an additional check to the new default time format and recreate the old
behavior for items starting before or ending after the current day.

Fixes BUG#3.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-21 12:10:51 +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
47c52ae7bb src/utils.c: Disable canonical mode in press_any_key()
Use tcsetattr() to disable canonical mode in press_any_key() before
waiting for a key press. This makes sure that input is available
immediately (instead of line by line). Also, disable echoing until a key
is pressed.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-20 17:22:13 +02:00
Lukas Fleischer
b4cefe2db9 Do not localize dates in pcal exports
* Do not localize the word "week" in pcal export headers.
* Reset current locale before formatting dates in pcal export data.

Addresses BUG#1.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-19 14:32:43 +02:00
Lukas Fleischer
ce13b70c5a Allow passing additional parameters to shell_exec()
This allows for specifying multiple command line parameters to be passed
on to the command in a way similar to fork_exec(). This is useful if we
want to wrap editor or pager invocations in a shell.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-16 19:31:47 +02:00
Baptiste Jonglez
d6e551c1a5 Allow resize events while prompting the user
When asking the user to choose between multiple alternatives, properly
handle resize events.

Note that we would also need to do so in getstring()...

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-14 19:32:18 +02:00
Baptiste Jonglez
b17475128d Various fixes.
Use snprintf(3) instead of sprintf(3) and fix a missing i18n tag.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-14 19:32:18 +02:00
Baptiste Jonglez
13d6f8703b Factorize boolean user prompting.
Introduce a new `status_ask_bool()` function, and use it where
applicable.

This greatly reduces code duplication, and will allow handling special
events (resize, user escape) much more uniformely.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-14 19:31:13 +02:00
Baptiste Jonglez
b2c92b2eb4 src/utils.c: Add a status_ask_simplechoice() function
We need a simpler version, based on the previously defined
`status_ask_choice()` function, that asks to choose amongst a number
of alternatives that can simply enumerated, without needing to bind
keys on them.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-14 19:31:12 +02:00
Baptiste Jonglez
f5dd276edb src/utils.c: Add a status_ask_choice() function
This function allows the user to choose between various alternatives,
each one being associated to a given key.

This will allow a great deal of factorisation, which will make it
easier to handle special events (like resizing, user escape...) in an
uniform manner.

The cool part of the approach taken here is that it allows full i18n
(i.e. the key bound to an alternative can be different depending on
the language), at the expense of a somewhat less readable code on the
caller side.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-14 19:31:12 +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
Baptiste Jonglez
0a352fe519 src/utils.c: Get rid of "semantic range checks" when parsing duration
Don't restrict ranges when entering durations. We now accept duration
like "+1d42h600m". This might not seem very logical, but it's
perfectly valid, and being able to enter "+36h" is useful when you
don't want to do the maths yourself.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-05-02 17:11:13 +02:00
Lukas Fleischer
0791eaabca Merge "%(start"{,str}")" and "%(end"{,str}")"
Add "default" and "epoch" extended formats for dates. "default" is the
same as "%H:%M", "epoch" prints the number of seconds since January 1,
1970.

Also, change the semantics of "%(start)" to return dates in default
format (same format that "%(startstr)" used to use before this patch).
The old "%(start)" behavior can be emulated by using "%(start:epoch)".
The same applies to "%(end)" and "%(endstr)".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-17 11:10:11 +02:00
Lukas Fleischer
b80c1f6364 Support extended date formats
Add support for appending a strftime()-style format string to "%(start)"
and "%(end)".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-17 11:10:11 +02:00
Lukas Fleischer
68b26ff854 Allow passing extended formats
Extended formats can be specified by adding custom format strings to the
end of a long format specifier, separated by a colon (":"). This feature
is currently unused. Extended format support for several format
specifiers will be added in following patches.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-17 11:10:11 +02:00
Lukas Fleischer
b73ce859db Add support for long format specifiers
Adds following long format specifiers for each short format specifier:

* s: (start)
* S: (startstr)
* d: (duration)
* e: (end)
* E: (endstr)
* m: (message)
* n: (noteid)
* N: (note)
* p: (priority)

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-17 11:10:11 +02:00
Lukas Fleischer
cd4f8bb68f src/utils.c: Break out format specifier parsing
Move the format specifier parser to a separate function. This is done in
preparation for supporting long format specifiers.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-17 11:10:11 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Lukas Fleischer
6c7edfbb86 Do not unlink() note files on note removal
Now that we use hash-based note file names, note files should never be
unlinked as a note file might be shared.

Also, remove the ERASE_FORCE_KEEP_NOTE flag that no longer makes any
sense.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-05 12:25:47 +02:00
Lukas Fleischer
87664095cd Refactor out note functions
* Add new note_edit() and note_view() helper functions. Use these
  instead of copy-pasted code in *_note_edit().

* Move all note-related functions (note_edit(), note_view(),
  note_erase()) to a new source file "note.c".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-21 18:13:40 +02:00
Lukas Fleischer
160f12687e Merge branch 'maint' 2011-07-10 19:04:49 +02:00