summaryrefslogtreecommitdiffstats
path: root/src/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* calendar.c: Rename to "ui-calendar.c"Lukas Fleischer2013-02-141-1/+1
| | | | | | | | | This unit belongs to the presentation layer -- rename the file accordingly. Also, rename calendar_*() to ui_calendar_*(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Rename appointment/event-related UI functionsLukas Fleischer2013-02-141-1/+1
| | | | | | | | | * Rename "interaction.c" to "ui-day.c" since it no longer contains todo-related UI functions. * Rename appointment/event-related UI functions to ui_day_*(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Merge branch 'maint'Lukas Fleischer2013-02-041-1/+1
|\
| * Update copyright rangesLukas Fleischer2013-02-041-1/+1
| | | | | | | | | | | | | | Add 2013 to the copyright range for all source and documentation files. Reported-by: Frederic Culot <frederic@culot.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Use strncasecmp() for case-insensitive comparisonLukas Fleischer2013-01-301-8/+0
| | | | | | | | | | | | | | Instead of converting everything to upper case and then using strncmp(), use strncasecmp() which does case-insensitive comparison out of the box. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Remove unused function mystrtol()Lukas Fleischer2013-01-301-15/+0
|/ | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add hidden key handler windowLukas Fleischer2012-12-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | After BUG#6 had apparently been closed with the screen locks introduced in commit a80f8dcf2c6eb3b54658218bc081ee9694204dd5, some people still had problems with random characters appearing in the notification bar. This was obviously caused by wgetch() refreshing the screen if the status panel was changed. From wgetch(3): If the window is not a pad, and it has been moved or modified since the last call to wrefresh, wrefresh will be called before another character is read. Since the wgetch(3) isn't thread-safe, there were race conditions between the notification bar thread drawing to the notification bar and wgetch() updating the screen. Introduce a (hidden) window that handles all key presses and never gets changed in order to avoid this. Also, call wins_wrefresh() explicitly in status_mesg(), since we can no longer rely on wgetch() updating windows automatically. Fixes reopened BUG#6. Note that this is a hotfix -- FR#26 has been opened to ensure we fix this properly in the next major release. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Merge branch 'maint'Lukas Fleischer2012-11-231-34/+47
|\ | | | | | | | | | | Conflicts: src/day.c src/recur.c
| * Replace localtime() with localtime_r()Lukas Fleischer2012-11-221-34/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Since the result of localtime() is stored in a statically allocated structure, data was overwritten when a context switch occurred during (or shortly after) the execution of localtime(), potentially resulting in critical data corruption. BUG#7 and BUG#8 are likely related. This patch converts all usages of localtime() with localtime_r(), which is thread-safe. Reported-by: Baptiste Jonglez <baptiste@jonglez.org> Reported-by: Erik Saule <esaule@bmi.osu.edu> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Add support for entering times in 24 hour formatWilliam Pettersson2012-11-181-2/+4
| | | | | | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Add support for copy/paste registersLukas Fleischer2012-07-071-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds support for vim-style copy/paste registers which allows cutting and copying multiple items without having to overwrite the copy/paste buffer. Registers can be specified using the quote key ('"'). To access a register, type '"x' before a command where "x" is the name of a register. If you want to copy the currently selected item into register 1, type '"1c'. Valid registers are 0-9, a-z, "-" and "_". Note that the latter is the so-called black hole register, which works similar to the black hole register in vim. The register prefix key is currently hardcoded and cannot be configured. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Revise cut/pastingLukas Fleischer2012-06-301-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Remove the need for the "day_saved_item" structLukas Fleischer2012-06-301-5/+5
|/ | | | | | | 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>
* Fix compilation with NLS disabledLukas Fleischer2012-06-301-0/+4
| | | | | | | * 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>
* Use mvwaddstr() instead of mvwprintw()Baptiste Jonglez2012-05-311-15/+12
| | | | | | | | | | | | | 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>
* Fix incorrect i18n usage for some stringsBaptiste Jonglez2012-05-251-1/+1
| | | | | | | | | | | 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>
* Merge branch 'maint'Lukas Fleischer2012-05-231-1/+8
|\ | | | | | | | | | | | | Conflicts: src/io.c src/notify.c src/utils.c
| * Do not localize dates in pcal exportsLukas Fleischer2012-05-191-0/+7
| | | | | | | | | | | | | | | | | | * 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>
* | Fix default time format for multi-day appointmentsLukas Fleischer2012-05-211-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Switch to Linux kernel coding styleLukas Fleischer2012-05-211-783/+655
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | src/utils.c: Disable canonical mode in press_any_key()Lukas Fleischer2012-05-201-0/+10
| | | | | | | | | | | | | | | | | | 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>
* | Allow passing additional parameters to shell_exec()Lukas Fleischer2012-05-161-3/+40
| | | | | | | | | | | | | | | | 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>
* | Allow resize events while prompting the userBaptiste Jonglez2012-05-141-1/+6
| | | | | | | | | | | | | | | | | | | | 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>
* | Various fixes.Baptiste Jonglez2012-05-141-2/+2
| | | | | | | | | | | | | | 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>
* | Factorize boolean user prompting.Baptiste Jonglez2012-05-141-7/+11
| | | | | | | | | | | | | | | | | | | | | | 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>
* | src/utils.c: Add a status_ask_simplechoice() functionBaptiste Jonglez2012-05-141-0/+33
| | | | | | | | | | | | | | | | | | | | 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>
* | src/utils.c: Add a status_ask_choice() functionBaptiste Jonglez2012-05-141-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Declare several parameters/variables constantLukas Fleischer2012-05-081-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* | src/utils.c: Get rid of "semantic range checks" when parsing durationBaptiste Jonglez2012-05-021-13/+0
| | | | | | | | | | | | | | | | | | | | 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>
* | Merge "%(start"{,str}")" and "%(end"{,str}")"Lukas Fleischer2012-04-171-21/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Support extended date formatsLukas Fleischer2012-04-171-2/+19
| | | | | | | | | | | | | | Add support for appending a strftime()-style format string to "%(start)" and "%(end)". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Allow passing extended formatsLukas Fleischer2012-04-171-5/+24
| | | | | | | | | | | | | | | | | | 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>
* | Add support for long format specifiersLukas Fleischer2012-04-171-5/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | src/utils.c: Break out format specifier parsingLukas Fleischer2012-04-171-24/+72
| | | | | | | | | | | | | | 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>
* | Miscellaneous small code cleanupsLukas Fleischer2012-04-061-3/+10
| | | | | | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Mark some more variables/parameters constantLukas Fleischer2012-04-051-1/+1
| | | | | | | | | | | | Fixes a couple of warnings seen with GCC 4.7. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Mark localized string literals constantLukas Fleischer2012-04-051-3/+3
| | | | | | | | | | | | | | Translated strings returned by gettext() are statically allocated and shouldn't be modified. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Update copyright rangesLukas Fleischer2012-03-261-1/+1
| | | | | | | | | | | | Add 2012 to the copyright range for all source and documentation files. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | Do not strncpy() strings returned by gettext()Lukas Fleischer2012-03-121-4/+5
| | | | | | | | | | | | | | | | 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>
* | Use strcmp() instead of strncmp()Lukas Fleischer2012-03-121-1/+1
| | | | | | | | | | | | | | | | | | 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>
* | Avoid redundant virtual screen updatesLukas Fleischer2012-03-121-2/+0
| | | | | | | | | | | | | | | | | | | | 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>
* | Fix POSIX complianceLukas Fleischer2012-02-191-0/+2
| | | | | | | | | | | | | | | | | | | | | | * "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>
* | src/utils.c: Mark is_all_digit() parameter constLukas Fleischer2011-12-091-1/+1
| | | | | | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | src/utils.c: Support escape sequences in format stringsLukas Fleischer2011-11-221-0/+55
| | | | | | | | | | | | | | 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>
* | src/utils.c: Support printing '%' in format stringsLukas Fleischer2011-11-141-0/+9
| | | | | | | | | | | | This allows using "%%" to print the '%' character. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* | print_*(): Add format specifier to print notesLukas Fleischer2011-11-141-0/+61
| | | | | | | | | | | | | | | | | | | | | | | | * 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>
* | Use a dynamic method to print todo items to stdoutLukas Fleischer2011-11-141-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Use a dynamic method to print recurrent items to stdoutLukas Fleischer2011-11-141-0/+27
| | | | | | | | | | | | | | | | | | 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>
* | Use a dynamic method to print events to stdoutLukas Fleischer2011-11-141-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Use a dynamic method to print appointments to stdoutLukas Fleischer2011-11-141-0/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>