aboutsummaryrefslogtreecommitdiff
path: root/lib/roken/parse_time.cat3
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2023-01-06 20:48:22 +0000
committerCy Schubert <cy@FreeBSD.org>2023-01-06 20:48:22 +0000
commit6f4e10db3298f6d65e1e646fe52aaafc3682b788 (patch)
tree0a8de0ec1173c00886bcde1c3b18e0963e5f2b83 /lib/roken/parse_time.cat3
parentd5d1e8b157da7410fe13e6302f8e1bee81320bb5 (diff)
Diffstat (limited to 'lib/roken/parse_time.cat3')
-rw-r--r--lib/roken/parse_time.cat361
1 files changed, 30 insertions, 31 deletions
diff --git a/lib/roken/parse_time.cat3 b/lib/roken/parse_time.cat3
index ca1c51ff4916..5aab1da9ca05 100644
--- a/lib/roken/parse_time.cat3
+++ b/lib/roken/parse_time.cat3
@@ -1,40 +1,39 @@
-
PARSE_TIME(3) BSD Library Functions Manual PARSE_TIME(3)
-NNAAMMEE
- ppaarrssee__ttiimmee, pprriinntt__ttiimmee__ttaabbllee, uunnppaarrssee__ttiimmee, uunnppaarrssee__ttiimmee__aapppprrooxx, -- parse
+NAME
+ parse_time, print_time_table, unparse_time, unparse_time_approx, -- parse
and unparse time intervals
-LLIIBBRRAARRYY
+LIBRARY
The roken library (libroken, -lroken)
-SSYYNNOOPPSSIISS
- ##iinncclluuddee <<ppaarrssee__ttiimmee..hh>>
+SYNOPSIS
+ #include <parse_time.h>
- _i_n_t
- ppaarrssee__ttiimmee(_c_o_n_s_t _c_h_a_r _*_t_i_m_e_s_p_e_c, _c_o_n_s_t _c_h_a_r _*_d_e_f___u_n_i_t);
+ int
+ parse_time(const char *timespec, const char *def_unit);
- _v_o_i_d
- pprriinntt__ttiimmee__ttaabbllee(_F_I_L_E _*_f);
+ void
+ print_time_table(FILE *f);
- _s_i_z_e___t
- uunnppaarrssee__ttiimmee(_i_n_t _s_e_c_o_n_d_s, _c_h_a_r _*_b_u_f, _s_i_z_e___t _l_e_n);
+ size_t
+ unparse_time(int seconds, char *buf, size_t len);
- _s_i_z_e___t
- uunnppaarrssee__ttiimmee__aapppprrooxx(_i_n_t _s_e_c_o_n_d_s, _c_h_a_r _*_b_u_f, _s_i_z_e___t _l_e_n);
+ size_t
+ unparse_time_approx(int seconds, char *buf, size_t len);
-DDEESSCCRRIIPPTTIIOONN
- The ppaarrssee__ttiimmee() function converts the period of time specified into a
- number of seconds. The _t_i_m_e_s_p_e_c can be any number of <number unit> pairs
+DESCRIPTION
+ The parse_time() function converts the period of time specified into a
+ number of seconds. The timespec can be any number of <number unit> pairs
separated by comma and whitespace. The number can be negative. Numbers
- without explicit units are taken as being _d_e_f___u_n_i_t.
+ without explicit units are taken as being def_unit.
- The uunnppaarrssee__ttiimmee() and uunnppaarrssee__ttiimmee__aapppprrooxx() do the opposite of
- ppaarrssee__ttiimmee(), that is they take a number of seconds and express that as
- human readable strings. _u_n_p_a_r_s_e___t_i_m_e produces an exact time, while
- _u_n_p_a_r_s_e___t_i_m_e___a_p_p_r_o_x restricts the result to include only one unit.
+ The unparse_time() and unparse_time_approx() do the opposite of
+ parse_time(), that is they take a number of seconds and express that as
+ human readable strings. unparse_time produces an exact time, while
+ unparse_time_approx restricts the result to include only one unit.
- pprriinntt__ttiimmee__ttaabbllee() prints a descriptive list of available units on the
+ print_time_table() prints a descriptive list of available units on the
passed file descriptor.
The possible units include:
@@ -48,14 +47,14 @@ DDEESSCCRRIIPPTTIIOONN
Units names can be arbitrarily abbreviated (as long as they are unique).
-RREETTUURRNN VVAALLUUEESS
- ppaarrssee__ttiimmee() returns the number of seconds that represents the expression
- in _t_i_m_e_s_p_e_c or -1 on error. uunnppaarrssee__ttiimmee() and uunnppaarrssee__ttiimmee__aapppprrooxx()
- return the number of characters written to _b_u_f. if the return value is
- greater than or equal to the _l_e_n argument, the string was too short and
+RETURN VALUES
+ parse_time() returns the number of seconds that represents the expression
+ in timespec or -1 on error. unparse_time() and unparse_time_approx() re-
+ turn the number of characters written to buf. if the return value is
+ greater than or equal to the len argument, the string was too short and
some of the printed characters were discarded.
-EEXXAAMMPPLLEESS
+EXAMPLES
#include <stdio.h>
#include <parse_time.h>
@@ -103,8 +102,8 @@ EEXXAAMMPPLLEESS
unparse_time = 12 months 4 days 23 hours 59 minutes 59 seconds
unparse_time_approx = 12 months
-BBUUGGSS
- Since ppaarrssee__ttiimmee() returns -1 on error there is no way to parse "minus
+BUGS
+ Since parse_time() returns -1 on error there is no way to parse "minus
one second". Currently "s" at the end of units is ignored. This is a
hack for English plural forms. If these functions are ever localised,
this scheme will have to change.