summaryrefslogtreecommitdiff
path: root/src/utils.c
AgeCommit message (Collapse)Author
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
2011-07-09Honor "TMPDIR" environment variableLukas Fleischer
Replace all hardcoded paths referring to "/tmp" with a new function that honors the "TMPDIR" environment variable as well as P_tmpdir and uses "/tmp" as a fallback. Thanks-to: Erik Saule <esaule@bmi.osu.edu> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-05Add press_any_key() functionLukas Fleischer
Displays "Press any key to continue..." in shell terminal mode and waits for a key stroke. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02Add shell_exec() functionLukas Fleischer
Can be used to execute an external program in a shell. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02Add child_wait() functionLukas Fleischer
Can be used to wait for the termination of a child process. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-02Add fork_exec() functionLukas Fleischer
Can be used to execute an external program. Provides the possibility to optionally create a pipe to the new process. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-29Split line editing functions into separate fileLukas Fleischer
Move getstring() related stuff into a separate file as a first step on our way to UTF-8 support for line editing helpers. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-06-07src/utils.c: Make bell() staticLukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-22Update copyright notices in source files, documentation and "COPYING".Lukas Fleischer
* Update copyright dates (use 2004-2011 as date range everywhere). * Change copyright holder from "Frederic Culot" to "calcurse Development Team". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-17Use mem_free() instead of xfree() in check_time().Lukas Fleischer
xfree() should never be used directly and only be called by one of the mem_*() wrappers. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-12Fix null pointer dereference in parse_date().Lukas Fleischer
Passing a date in format "mm-dd-yy" where short forms are not allowed would lead to a null pointer dereference here. This one fixes that. Spotted by clang-analyzer. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-05Compare pointers to "NULL" instead of "0".Lukas Fleischer
"bad_zero.cocci" spatch from http://coccinelle.lip6.fr/impact_linux.php. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-04-03Avoid assignment of undefined value in parse_date().Lukas Fleischer
Spotted by clang-analyzer ("Assigned value is garbage or undefined"). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-15Try to stick to the GNU coding standards for the sake of consistency.Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-15Use upper case for macro names.Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-14Overall indentation fixes.Lukas Fleischer
Use spaces instead of tabs for source code indentation only, strip trailing whitespaces from lines. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-05Clean up updatestring() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-05Simplify date_sec2date_fmt() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-05Clean up and simplify line editing functions.Lukas Fleischer
This greatly simplifies all line editing functions - especially getstring() and showstring(). showcursor() is removed and integrated into showstring(). del_char() and add_char() are simplified as well. add_char() is renamed to ins_char(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Remove unnecessary casting variables from get_item_{hour,min}().Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Update website links to match the new URL.Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Update mail addresses to match the new mailing lists.Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Simplify date_sec2date_str() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Remove date_sec2hour_str() from "utils.c".Lukas Fleischer
date_sec2hour_str() is superseded by date_sec2date_str() with "%H:%M" as date format string, so replace all invocations and remove that function from "utils.c". Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Simplify date2sec() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Simplify check_time() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Simplify print_in_middle() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Reformat erase_window_part() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Simplify get_item_hour() and get_item_min() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Simplify str_toupper() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-03-04Simplify file_close() in "utils.c".Lukas Fleischer
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>