summaryrefslogtreecommitdiffstats
path: root/src/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* Add command line option to suppress dialogsLukas Fleischer2016-01-131-0/+5
| | | | | | | Implement a -q/--quiet command line option to disable system dialogs temporarily. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add an option to filter by object hashLukas Fleischer2016-01-131-0/+12
| | | | | | | | | Implement a new --filter-hash option to filter by object identifiers. Each object having an identifier that has the specified pattern as a prefix is matched. Patterns starting with an exclamation mark (!) are interpreted as negative patterns. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add long format specifiers "raw" and "hash"Lukas Fleischer2016-01-131-5/+55
| | | | | | | Add new format specifiers to print the raw item representation or an object's hash value. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Reimplement asprintf() using dynamic stringsLukas Fleischer2016-01-131-26/+4
| | | | | | Use the new string implementation to simplify asprintf(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Split out code for drawing week numbersLukas Fleischer2015-04-101-2/+9
| | | | | | | This allows for easily adding week numbers to other panel modes, such as the monthly view. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Simplify code in status_ask_choice()Lukas Fleischer2015-02-241-7/+5
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use time_t instead of long in several placesLukas Fleischer2015-02-241-16/+10
| | | | | | | Start converting some variables and return values to store times from long to time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Introduce starts_with() and starts_with_ci()Lukas Fleischer2015-02-241-0/+12
| | | | | | | | Create user-defined functions to check whether a string contains a certain prefix instead of messing around with strncmp() and strncasecmp(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add support for UTC times in iCal importsLukas Fleischer2015-02-231-0/+25
| | | | | | | | | | | | | | According to the iCal standard (4.3.12 Time): UTC time, or absolute time, is identified by a LATIN CAPITAL LETTER Z suffix character (US-ASCII decimal 90), the UTC designator, appended to the time value. Parse such time values properly when importing iCal files. Fixes GitHub issue #3. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use date_sec_change() for adding day deltasLukas Fleischer2015-02-221-6/+5
| | | | | | Fixes tests range-002.sh and search-001.sh. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Support weekday names as date specifiersLukas Fleischer2015-02-111-5/+51
| | | | | | Allow for using shorthands like "Monday" as date specifiers. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Update copyright rangesLukas Fleischer2015-02-071-1/+1
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add a couple of shorthands to parse_date()Lukas Fleischer2015-02-071-0/+25
| | | | | | | We now understand the shorthands "today", "yesterday", "tomorrow" and "now" which might come in useful sometimes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Handle dates past January 19th, 2038Lukas Fleischer2015-02-071-4/+2
| | | | | | Try to support dates past year 2038 on systems with 64-bit time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Refactor new_tempfile()Lukas Fleischer2014-07-221-10/+7
| | | | | | | | Avoid preallocating buffers on the stack, use dynamic memory allocation instead. Also, change the semantics of new_tempfile() so that it returns the full name of the temporary file and fix all call sites. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Replace several uses of snprintf() by asprintf()Lukas Fleischer2014-07-221-9/+10
| | | | | | | | Use asprintf() in some cold code paths. While allocating memory on the heap is a bit slower, using asprintf() is a bit more memory efficient and less prone to buffer overflow errors. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add vasprintf() and asprintf()Lukas Fleischer2014-07-221-0/+38
| | | | | | | | | The new utils.c functions vasprintf() and asprintf() are analogs to sprintf() and vsprintf(). However, instead of requiring a buffer that is large enough to hold the output data, the functions allocate a string and return a pointer to it. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add default cases to some switch statementsLukas Fleischer2014-05-181-0/+2
| | | | | | This squelches several compiler warnings. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Store appointments for the current day in a vectorLukas Fleischer2014-05-181-1/+1
| | | | | | This allows for more efficient access to items at specific positions. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Rework scroll window implementationLukas Fleischer2014-05-181-1/+1
| | | | | | | | | | This complete rewrite of the scroll window implementation decouples scroll windows from every other window abstraction layer we use. Note that this leads to some code duplication. The long-term purpose of this rewrite, however, is to eventually make every panel use scroll windows. This makes for a huge cleanup of the UI code. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add a short format specifier for "%(remaining)"Lukas Fleischer2013-07-171-0/+2
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Allow extended formats for durationsLukas Fleischer2013-07-171-1/+5
| | | | | | | Use print_datediff() to print durations. This allows for using something like "%(duration:%EH:%M)". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* print_datediff(): Actually print a date differenceLukas Fleischer2013-07-171-5/+3
| | | | | | | | | Instead of passing a date and printing the date difference between that date and the current date, pass an actual date difference. This allows for using the function in other places, such as for printing item durations. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Add %(remaining) style formattingWilliam Pettersson2013-07-171-0/+83
| | | | | | | | Adds %(remaining) style formatting, with parameter substitution for %d, %H, %M, %S with E and - variables. Signed-off-by: William Pettersson <william.pettersson@gmail.com> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use tabs instead of spaces for indentationLukas Fleischer2013-04-141-935/+954
| | | | | | | | | | | This completes our switch to the Linux kernel coding style. Note that we still use deeply nested constructs at some places which need to be fixed up later. Converted using the `Lindent` script from the Linux kernel code base, along with some manual fixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* parse_{date,time}(): Split out date/time validationLukas Fleischer2013-02-271-3/+23
| | | | | | | | Split date/time validation into separate functions check_date() and check_time(). These will be used to validate date/time information when reading items from the appointments file. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* date_sec2date_str(): Add missing semicolonLukas Fleischer2013-02-191-1/+1
| | | | | | Regression introduced in a363cb9b9111aed22d105adb0e7a8e9caab9bbe3. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Fix braces in if-else statementsLukas Fleischer2013-02-171-20/+31
| | | | | | | | | | From the Linux kernel coding guidelines: Do not unnecessarily use braces where a single statement will do. [...] This does not apply if one branch of a conditional statement is a single statement. Use braces in both branches. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* parse_duration(): Bail out early in final stateLukas Fleischer2013-02-141-6/+4
| | | | | | | Bail out early if we are reading a character while being in a final state. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* 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>