summaryrefslogtreecommitdiff
path: root/src/utils.c
AgeCommit message (Collapse)Author
2012-06-30Revise cut/pastingLukas Fleischer
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-30Remove the need for the "day_saved_item" structLukas Fleischer
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-30Fix compilation with NLS disabledLukas Fleischer
* 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-05-31Use mvwaddstr() instead of mvwprintw()Baptiste Jonglez
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-25Fix incorrect i18n usage for some stringsBaptiste Jonglez
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-23Merge branch 'maint'Lukas Fleischer
Conflicts: src/io.c src/notify.c src/utils.c
2012-05-21Fix default time format for multi-day appointmentsLukas Fleischer
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-21Switch to Linux kernel coding styleLukas Fleischer
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-20src/utils.c: Disable canonical mode in press_any_key()Lukas Fleischer
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-19Do not localize dates in pcal exportsLukas Fleischer
* 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-16Allow passing additional parameters to shell_exec()Lukas Fleischer
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-14Allow resize events while prompting the userBaptiste Jonglez
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-14Various fixes.Baptiste Jonglez
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-14Factorize boolean user prompting.Baptiste Jonglez
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-14src/utils.c: Add a status_ask_simplechoice() functionBaptiste Jonglez
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-14src/utils.c: Add a status_ask_choice() functionBaptiste Jonglez
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-08Declare several parameters/variables constantLukas Fleischer
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-02src/utils.c: Get rid of "semantic range checks" when parsing durationBaptiste Jonglez
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-04-17Merge "%(start"{,str}")" and "%(end"{,str}")"Lukas Fleischer
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-17Support extended date formatsLukas Fleischer
Add support for appending a strftime()-style format string to "%(start)" and "%(end)". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-17Allow passing extended formatsLukas Fleischer
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-17Add support for long format specifiersLukas Fleischer
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-17src/utils.c: Break out format specifier parsingLukas Fleischer
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-06Miscellaneous small code cleanupsLukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-05Mark some more variables/parameters constantLukas Fleischer
Fixes a couple of warnings seen with GCC 4.7. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-04-05Mark localized string literals constantLukas Fleischer
Translated strings returned by gettext() are statically allocated and shouldn't be modified. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-26Update copyright rangesLukas Fleischer
Add 2012 to the copyright range for all source and documentation files. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-03-12Do not strncpy() strings returned by gettext()Lukas Fleischer
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-12Use strcmp() instead of strncmp()Lukas Fleischer
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-12Avoid redundant virtual screen updatesLukas Fleischer
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-02-19Fix POSIX complianceLukas Fleischer
* "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>
2011-12-09src/utils.c: Mark is_all_digit() parameter constLukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-22src/utils.c: Support escape sequences in format stringsLukas Fleischer
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-14src/utils.c: Support printing '%' in format stringsLukas Fleischer
This allows using "%%" to print the '%' character. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-14print_*(): Add format specifier to print notesLukas Fleischer
* 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-14Use a dynamic method to print todo items to stdoutLukas Fleischer
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-14Use a dynamic method to print recurrent items to stdoutLukas Fleischer
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-14Use a dynamic method to print events to stdoutLukas Fleischer
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-14Use a dynamic method to print appointments to stdoutLukas Fleischer
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-02Remove parentheses from return statementsLukas Fleischer
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-02Make use of the NULL macroLukas Fleischer
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-02Do not cast unused return values to voidLukas Fleischer
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-02Avoid use of printf()/fprintf()Lukas Fleischer
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-10-06src/utils.c: Support more powerful duration stringsLukas Fleischer
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-06src/utils.c: Remove check_time()Lukas Fleischer
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-06src/utils.c: Introduce parse_{time,duration}()Lukas Fleischer
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-06src/utils.c: Mark input string of parse_date() constLukas Fleischer
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-05Do not unlink() note files on note removalLukas Fleischer
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-07-21Refactor out note functionsLukas Fleischer
* 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-10Merge branch 'maint'Lukas Fleischer