aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright ranges for 2023Lukas Fleischer2023-04-111-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright ranges for 2022Lukas Fleischer2022-03-111-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Backend changes for first day of weekMorgan Seltzer2021-08-071-0/+36
| | | | | | | | | | | | | Previously only Sunday and Monday were allowed for the first day of the week, and was internally treated as a binary variable. This patch changes the backend so all days are accepted, a future patch will allow users to actually select other days. Addresses GitHub feature request #321. Signed-off-by: Morgan Seltzer <MorganSeltzer000@gmail.com> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Call setsid() for hook/notification commandsLukas Fleischer2021-04-041-5/+12
| | | | | | | | | We do not want hook or notification commands to interact with the terminal in any way. Create a new session for them. Addresses GitHub issue #326. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add parameter to redirect stderr to shell_exec()Lukas Fleischer2021-04-041-7/+26
| | | | | | | Add a function parameter to allows redirecting stderr in addition to stdin and stdout. The parameter will be used with a follow-up change. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Introduce macro DAYLars Henriksen2020-12-191-3/+2
| | | | | | | DAY(t) is midnight (the day) of time_t t. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove SIGCHLD signal handlerLars Henriksen2020-07-261-2/+4
| | | | | | | | | | | | | | The purpose is to make child_wait() reliable. The handler is meant for the notify main thread, but signal handlers are shared by all threads. In the calcurse main thread and the periodic save thread (hooks) the handler and child_wait() will compete (if the signal handler kicks in first, the waitpid() call in child_wait() will fail with errno ECHILD). All child processes in the main thread, the notify thread, the periodic save thread and the notify demon are explicitly waited for. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove systemdialogs option from configurationLars Henriksen2020-06-131-5/+0
| | | | | | | | | The option controls the welcome window and the export/import result messages. The former is dropped. The latter are now always displayed unless calcurse is invoked with the "quiet" option (-q). Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Allow repeat count input (for until) in interactive UILars Henriksen2020-06-131-11/+11
| | | | | | | | | | Shortened repetition type text. Avoid "duration" in until-contexts (reserve it for appointment duration): "duration" changed to "increment" in user texts as well as source. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Extend import of recurrence rulesLars Henriksen2020-06-131-1/+1
| | | | | | | | Support has been implemented for recurrence rule parts BYMONTH, BYMONTHDAY and BYDAY. A new test has been added. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support import of time zones (RFC 5545)Lars Henriksen2020-06-131-10/+13
| | | | | | | | | The property parameter time zone identifier (TZID) is recognized in DTSTART, DTEND and EXDATE and the DATE-TIME value converted to a local time. The time zone identifier is logged in the note file. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Let RETURN set frequency type to current value in repeat command UILars Henriksen2020-05-241-0/+2
| | | | | | | In addition, the prompt text is shortened. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Include start day in error message for recurrence ruleLars Henriksen2020-05-241-0/+16
| | | | | Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Recurrence rule extensionsLars Henriksen2020-04-281-0/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Terms and concepts are from RFC 5545 (the iCalendar specification). Overall design -------------- Calcurse is extended with full support for BYMONTH, BYDAY and BYMONTHDAY recurrence rule (rrule) parts. The three rule parts are lists of, respectively, months, weekdays and monthdays. The lists are added to 'struct rpt' as linked lists of integers, and the data file format is extended accordingly (details below). Load and save of the lists follow the pattern of the existing list of exception dates, also in 'struct rpt'. The function recur_item_find_occurence() is split into a front-end and a back-end. The back-end, called find_occurrence(), is the original function extended with rrule reductions; the front-end retains the original name and performs rrule expansions. Front-end plus back-end are backwards compatible and require no changes in calling functions. There is no user interface in this patch. Data file extensions -------------------- The BYMONTH, BYDAY and BYMONTHDAY lists are added to that part of an item line which describes the recurrence rule (the "{...}" part). Each list is - like the list of exception days - a space-separated string of values identified by the initial character. Each list is optional and, if present, must follow the until date and precede the exception day list. The lists must appear in order BYMONTHDAY list, BYDAY list and BYMONTH list. The possible list values are - BYMONTH: m1, m2, ..., m12 - BYDAY: w0, w1, ..., w6, w7, w-7, w8, w-8, ..., w377, w-377 - BYMONTHDAY: d1, d2, ..., d31, d-1, d-2, ..., d-31 which are interpreted as (cf. RFC 5545) - BYMONTH: January, February, ..., December. - BYDAY: SU, MO, ..., SA, +1SU, -1SU, +1MO, -1MO, ..., +53SA, -53SA - BYMONTHDAY: the first, the second, ..., the 31st, the last, the last but one, ..., the last but 30 day of the month Examples: Thursday, TH, is w4; Saturday, SA, is w6. The seventh Thursday, +7TH, is w53 (7 * 7 + 4 = 53); the last but second Saturday, -2SA, is w-20 (2 * 7 + 6 = 20); the last day of the month is d-1. Note that the values w-1, w-2, ..., w-6 are not used. A recurrent appointment with a BYDAY rule part: 06/23/2019 @ 12:00 -> 06/23/2019 @ 13:00 {1W w0 w6} |every week on Sunday and Saturday An event with a BYDAY and a BYMONTH rule part: 10/27/2019 [1] {1Y w-7 m10} every year on last Sunday in October An event with until date, a BYMONTH rule part and an exception day: 06/23/2019 [1] {1Y -> 08/31/2021 m5 m6 m7 !07/23/2020} every year on the 23rd in May, June and July for three years, starting on Sunday, 23 June 2019, but not on 23 July 2020. Recurrence set expansion and reduction --------------------------------------- In calcurse a recurrence rule is a quadruple (s, d, r, e) consisting of start, duration, repetition pattern and exception days and is implemented as: (time_t start, long dur, struct rpt *rpt, llist_t *exc) In RFC 5545 parlance, a recurrence rule defines a recurrence set consisting of all recurrence instances (occurrences) not earlier than start which match the rule pattern. With this concept in mind, recur_item_find_occurremce() may be thought of as a membership function for a recurrence set. The call recur_item_find_occurrence(s, d, r, e, day, occurrence) returns true if day belongs to the recurrence set of (s, d, r, e); if so occurrence points to the recurrence instance (the set member). For a recurrence rule with only the basic DAYLY, WEEKLY, MONTHLY or YEARLY type and frequency the recurrence set consists of periodically repeated instances. The BYxxx rule parts modify the recurrence set by reducing or expanding it as specified by RFC 5545. Expansion is implemented in the front-end by modifications of start and/or frequency of the rule (s, d, r, e), often several times, in such a way that the desired recurrence instances are included in the recurrence set. This is possible because the front-end as the very first thing checks for early days (day < s). When day is known not to be early, start (s) can safely be moved backwards. Likewise, if frequency must be changed, the front-end checks whether the frequency repetition applies to the week, month or year of day. Reduction is easier and is performed in the back-end along with the existing validity checks. It consists in checking whether month, day of month or weekday of a found occurrence is on the appropriate list. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2020-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Refactor cut and paste registersLars Henriksen2020-01-131-1/+1
| | | | | | | | | | Register REG_BLACK_HOLE can neither be copied into nor pasted from and has been removed from the input routine. Register 36 was not used. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* DST: fix date_change() thoroughlyLars Henriksen2019-09-061-1/+2
| | | | | | | | Explicit setting of Daylight Saving Time should be avoided before as well as after the mktime() call. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use empty end date instead of 0 when editing repetitionsLukas Fleischer2019-06-061-16/+8
| | | | | | | | | Since commit 987fa9d (Allow to omit end date in repetitions, 2019-06-03), one can provide an empty date instead of using the value 0 to omit the end date of a repetition. Use this as default value when editing repetitions without an end date. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove appointments panel scrollbar in multiple days modeLars Henriksen2019-05-281-0/+4
| | | | | | | | | | A scrollbar gives the impression of a fixed list. But the list on display is automatically and silently changed as needed for movements in the panel or the calendar, thus creating the illusion of an endless list. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Derive selected day from selected itemLars Henriksen2019-05-221-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, with only one day visible at a time, the appointments panel displayed the details of the day selected in the calendar (slctd_day); information required for operations on items (day_items) can often be derived from the selected day. The items available are derived from the selected day. In particular, the selected item is derived from the selected day. With multiple days in the APP panel, the relation between selected day (in the calendar) and the selected item (in the APP panel) has, in a way, been turned around. The selected item may now be moved between days without explicitly changing the selected day. Implicitly it is changed when the target day of a move is unavailable. This commit draws the full consequence: the selected day in the calendar is always (set to) the day of the selected item in the APP panel. The static variable 'struct date slctd_day' lives in ui_calendar.c and is accessible through various public functions. To these are added ui_calendar_set_slctd_day() which sets slctd_day directly. The selected day retains its significance for load of the day vector (in day_store_items()): the range of loaded days begins with the selected day. Movements (up/down) in the APP panel will change the selected day as the selected item moves among the already loaded days. Only when the target of a movement is unreachable, will further days be loaded. On the other hand, if the same range of days must be reloaded because of a changed item, the selected item - and with it the selected day - must be reset to the first day item (see do_storage()). Movements in the calendar (generic-next-day, etc.) are not affected and behave as previously, i.e. they will cause a range of days to be loaded with the selected day as the first and the selected item as the first of the selected day. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add week numbers in the calendar and full first and last weekLars Henriksen2019-05-221-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | Much in the calendar is based on the selected day, struct date slctd_day, in ui-calendar.c. On the screen it is highlighted with a deviating colour. The highlight effect has been changed to a pair of red square brackets that do not obscure the day colour. The week number (in the frame) used to be that of the selected day, but has no obvious relation to the days in the APP panel. It has been replaced by the year day number of the selected day. The week numbers of all visible weeks are displayed to the left of the calendar. Dates are displayed also for the overlapping parts of the first and last week of the month (which do not belong to the month). Days are accessible in the appointments panel as well as in the calendar. Hence, validation of days (= inside UNIX time limits) must be extended from the calendar (in ui_calendar_move()) to include loaded days (in day_store_items()). Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Simplify day storageLars Henriksen2019-05-221-0/+6
| | | | | | | | | | | The function day_process_storage() is a wrapper for day_store_items(). It has an unused second argument, and is only used twice to load the selected day. It has been removed. A new function, get_slctd_day(), is the equivalant of get_today() and replaces the very awkwardly named ui_calendar_get_slctd_day_sec(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Overflow check for 32-bit types onlyLars Henriksen2019-01-181-10/+16
| | | | | | | Included is a check of the 'until' date for pasted recurrent items. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use time_t for system time valuesLukas Fleischer2019-01-141-20/+20
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix print_date()Lars Henriksen2019-01-071-5/+8
| | | | | | | | In print_date(date, day, ...) it is silently assumed that day is midnight (beginning) of the day to be printed. Assume only that it belongs to the day. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* DST fix: adjusting time in appointmentsLars Henriksen2018-11-101-5/+23
| | | | | | | | | | | | | | | | | | | | | | | | | Calcurse saves time and date information on disk as local time in readable text file format. When loaded from disk or when entered by the user, local time is converted to Unix time (seconds since 00:00:00, 1 January 1970). When displayed, and later when saved to disk, the Unix time is converted back to readable local time. Both conversions depend on DST. Hence, if midnight for a day with DST in effect (i.e. local time) is converted, increased with an amount and converted back, the amount has changed if DST is _not_ in effect for the resulting time. In general, calculations on Unix time variables should be used with caution because of the DST-dependent conversions. Instead, the calculations should be performed on local time data with the help of mktime(). The commit fixes start time for pasted appointments (ordinary and recurrent) and the 'until'-date of recurrent appointments, pasted as well as new and edited. The latter problem is slightly different in that the adjustment is a number of days, as it is for exception dates. Update of the date in parse_datetime() has been corrected to be similar to update of the time, although no problem has been identified. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* DST fix: adding appointments on the day when DST starts or stopsLars Henriksen2018-11-101-11/+7
| | | | | | | | | | A new apppoint inserted on the day when the clock is adjusted backward by an hour got a wrong start time (an hour late). Reason: mktime() must not use the Daylight Saving Time information returned by localtime_r(). Also editorial simplifications. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Minor merge adjustmentsLars Henriksen2018-08-251-36/+43
| | | | | | | | Comments inserted. Slightly different implementations of parse_time() and parse_datetime(). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Start and end time validation.Lars Henriksen2018-08-251-5/+44
| | | | | | | | | | All appointment times are checked for validity. Overflow by time arithmetic is detected. End times are checked when appointments are moved. Three functions are involved: parse_datetime(), parse_duration() and parse_date_duration(); they all have a new argument for validation purposes. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* New support functions for input validation.Lars Henriksen2018-08-251-0/+36
| | | | | | check_sec(), overflow_add(), overflow_mul() Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Only stop threads when exiting from interactive modeLukas Fleischer2018-08-251-3/+3
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support UTF-8 encoded characters in user choicesLars Henriksen2018-06-031-12/+23
| | | | | | | | Translations (in po-files) of texts that are used for alternative choices (e.g. [dwmy]), may use UTF-8 encoded Unicode characters (e.g. [éãüå]). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Scrollbar and right window border (corrected)Lars Henriksen2018-05-261-15/+8
| | | | | | | | | | | | | | | | | When a scrollbar is on display in APP or TOD windows, the right vertical border (outside the scrollbar) is not highlighted when the window is selected. The scrollbar is always highlighted: - when APP or TOD is deselected - in configuration windows where borders otherwise are not The patch moves the scrollbar parameters (except highlight) from arguments of draw_scrollbar() to the function itself. The highlight argument was 1; instead it is set higher in the call hierarchy (wins_update_panels()) and passed on down. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Scrollbar and right window borderLars Henriksen2017-12-101-8/+27
| | | | | | | | | | | | | | | | | | | When a scrollbar is on display in APP or TOD windows, the right vertical border (outside the scrollbar) is not highlighted when the window is selected. The scrollbar itself is always highlighted: - when APP or TOD is deselected - in configuration windows where borders otherwise are not The patch moves the scrollbar parameters from arguments of draw_scrollbar() to the function itself. The highlight argument to draw_scrollbar() was always 1. Instead call circumstances are figured out and highlight set accordingly. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Default colour as foreground colourLars Henriksen2017-12-101-0/+6
| | | | | | | | | | | | | In the default colour setup (white on black), white could only with great difficulty be used as customized foreground colour, because the colour pair COLR_CUSTOM then was identical to COLR_DEFAULT (default on default). This made it impossible to distinguish the selected element in lists. The patch turns on the video attribute bold when default is chosen as foreground colour. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Check for the year span 1902-2037Lars Henriksen2017-11-231-6/+8
| | | | | | | | | | | | | Reintroduce year check for systems with a 32-bit time_t type. Remove the lower limit (1902) for systems with a 64-bit time_t. This limits movements in the calendar (for 32-bit systems) and in no way ensures constistency of data. Commit a12833e (Handle dates past January 19th, 2038, 2015-01-19) removed the upper limit (2037) on dates but left the lower limit (1902). It did not ensure the support of the target system. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Parse time before date in parse_datetime()Lukas Fleischer2017-10-271-2/+2
| | | | | | | | | Make sure that in cases when the date and time formats conflict, such as is the case with "0030", the input is interpreted as a time value, not a date. Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Make parsing of date-time more strictLukas Fleischer2017-10-261-15/+20
| | | | | | | | | | | In parse_datetime() it was possible to enter any number of dates and times in any order. Allow just date or time or date followed by time. Time must be looked for before date because of conflicting time and date formats. Suggested-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add parse_date_interactive()Lukas Fleischer2017-10-261-0/+7
| | | | | | | | | Add a wrapper around parse_date() which picks the current input date format as well as the currently selected day and passes both values to parse_date(), alongside with the parameters passed to parse_date_interactive() itself. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Remove phase of moon featureLars Henriksen2017-09-081-2/+0
| | | | | | | | | | The computation never really worked before and it seems like the feature is not very helpful, sometimes even confusing (see GitHub issue #21). The macro ISLEAP is moved to calcurse.h. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Replace remaining uses of wgetch() by keys_wgetch()Lukas Fleischer2017-09-031-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add a function to wait for any key pressLukas Fleischer2017-09-031-3/+3
| | | | | | | Introduce a new function keys_wait_for_any_key() and use it instead of wgetch() whenever the return value is discarded. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix empty warning box when key is already in useLars Henriksen2017-08-121-0/+2
| | | | | | | | | | | | When adding a key already in use for another action, a warning box is displayed. The text length is limited by the window width through the use of strncpy(). If the limit is exceeded, the string will have no null termination, resulting in unpredictable behaviour. A similar problem in fatalbox() is fixed as well. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Include stdarg.h when using variable argument listsLukas Fleischer2017-07-281-0/+1
| | | | | | Fixes GitHub issue #36. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2017-01-121-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Replace parse_datetime() constants by named flagsLukas Fleischer2016-10-101-2/+2
| | | | | | | Remove the magic constants used in the return value of parse_datetime() and use named flags instead. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support dates when specifying start/end timesLukas Fleischer2016-10-091-2/+6
| | | | | | | | | | Add support for combined date/time or date-only strings when specifying the start or end time of a new item. This is a follow-up to 1f39b5c (Add support for moving items to another day, 2016-09-30). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Factor out parse_datetime()Lukas Fleischer2016-10-091-0/+39
| | | | | | | | Create a new function that takes a time stamp and updates the date or time components of that time stamp according to a given date/time string. Use that function for updating the start time of an item. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Stop all threads before leaving curses modeLukas Fleischer2016-09-131-2/+4
| | | | | | | This prevents from notification bar artifacts being drawn after leaving interactive mode. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Do not assume that days always have 86400 secondsLukas Fleischer2016-03-271-0/+24
| | | | | | | | Make that date membership is computed correctly, even if a day has less than 86400 seconds (e.g. after changing clocks). Reported-by: Hakan Jerning <jerning@home.se> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>