diff --git a/src/libiso8601/TopHeader.h b/src/libiso8601/000_TopHeader.h similarity index 77% rename from src/libiso8601/TopHeader.h rename to src/libiso8601/000_TopHeader.h index 5f20f12..2953dca 100644 --- a/src/libiso8601/TopHeader.h +++ b/src/libiso8601/000_TopHeader.h @@ -1,4 +1,4 @@ -/* libiso8601/src/libiso8601/TopHeader.h +/* libiso8601/src/libiso8601/000_TopHeader.h * * (c)2006, Laurence Withers, . * Released under the GNU GPLv2. See file COPYING or @@ -8,7 +8,7 @@ #ifndef HEADER_libiso8601 #define HEADER_libiso8601 -// standard includes, or includes needed for type declarations +/* standard includes, or includes needed for type declarations */ #include #include diff --git a/src/libiso8601/TopSource.c b/src/libiso8601/000_TopSource.c similarity index 85% rename from src/libiso8601/TopSource.c rename to src/libiso8601/000_TopSource.c index 102cc8d..5f154b1 100644 --- a/src/libiso8601/TopSource.c +++ b/src/libiso8601/000_TopSource.c @@ -1,4 +1,4 @@ -/* libiso8601/src/libiso8601/TopSource.c +/* libiso8601/src/libiso8601/000_TopSource.c * * (c)2006, Laurence Withers, . * Released under the GNU GPLv2. See file COPYING or @@ -13,6 +13,7 @@ #include #include +/* Useful define to alleviate typos */ #define BILLION (1000000000L) /* options for text editors diff --git a/src/libiso8601/calc.c b/src/libiso8601/100_calc.c similarity index 99% rename from src/libiso8601/calc.c rename to src/libiso8601/100_calc.c index 577563d..5f3e620 100644 --- a/src/libiso8601/calc.c +++ b/src/libiso8601/100_calc.c @@ -1,4 +1,4 @@ -/* libiso8601/src/libiso8601/calc.c +/* libiso8601/src/libiso8601/100_calc.c * * (c)2006, Laurence Withers, . * Released under the GNU GPLv2. See file COPYING or diff --git a/src/libiso8601/100_types.h b/src/libiso8601/100_types.h new file mode 100644 index 0000000..f0d38d0 --- /dev/null +++ b/src/libiso8601/100_types.h @@ -0,0 +1,109 @@ +/* libiso8601/src/libiso8601/100_types.h + * + * (c)2006, Laurence Withers, . + * Released under the GNU GPLv2. See file COPYING or + * http://www.gnu.org/copyleft/gpl.html for details. +*/ + + + +/*! \brief Date/time point. + +This structure contains the details to represent a specific instant on the UTC timescale. It uses +Jan 1, year 0000 as the origin (when \a day will be 0). \a sec is the number of seconds elapsed +since start of day, and \a nsec is the number of nanoseconds elapsed since the start of the current +second. + +We correctly deal with leap seconds by encoding 23:59:60 as having a \a sec field of 86400. + +*/ +struct iso8601_date { + /*! \brief Number of nanoseconds elapsed since start of second. */ + int32_t nsec; + + /*! \brief Number of days elapsed since Jan 1, year 0000. May be negative. */ + int32_t day; + + /*! \brief Number of seconds elapsed since start of day. */ + int32_t sec; +}; + + + +/*! \brief Date (day portion) precision. + +This enumeration will record how precisely the date was specified, as well as the format in use. It +allows the library to determine the earliest and latest dates that could possibly be represented +with the given input and also allows the output format to match the input format. + +*/ +enum iso8601_date_prec { + /*! \brief Only year specified. */ + iso8601_prec_year, + + /*! \brief Year and month specified (calendar format). */ + iso8601_prec_month, + + /*! \brief Year, month and day specified (calendar format). */ + iso8601_prec_day, + + /*! \brief Year and ordinal day specified (ordinal format). */ + iso8601_prec_ord, + + /*! \brief Year and week specified (week format). */ + iso8601_prec_week, + + /*! \brief Year, week and weekday specified (week format). */ + iso8601_prec_wday +}date_prec; + + + +/*! \brief Time precision. + +This enumeration records how precisely the time was specified as well as its format. The fractional +format will record whether it was the hour, minute or second that was specified with a fractional +part, allowing a processed date/time to be presented to the user in the format it was originally +encountered. + +*/ +enum iso8601_time_prec { + iso8601_prec_none, + iso8601_prec_hour, + iso8601_prec_min, + iso8601_prec_sec, + iso8601_prec_hourfrac, + iso8601_prec_minfrac, + iso8601_prec_secfrac +}time_prec; + + + +/*! \brief Date/time formatting details. + +This structure simply records details related to the formatting (and precision) of a date/time +structure. The structure can be filled out by the parser so that a program's output can match +the format of its input. Alternatively it can be controlled by the program to provide a consistent +output format. + +*/ +struct iso8601_details { + /*! \brief Date precision (enum iso8601_date_prec). */ + uint8_t date_prec; + + /*! \brief Time precision (enum iso8601_time_prec). */ + uint8_t time_prec; + + /*! \brief Flag: non-zero if extended format should be used. */ + uint8_t extended; + + /*! \brief Time zone offset in seconds. */ + int32_t tz_sec; +}; + + + +/* options for text editors +kate: replace-trailing-space-save true; space-indent true; tab-width 4; +vim: expandtab:ts=4:sw=4 +*/ diff --git a/src/libiso8601/parser.c b/src/libiso8601/200_parser.c similarity index 99% rename from src/libiso8601/parser.c rename to src/libiso8601/200_parser.c index 5a9b2ef..14de0a6 100644 --- a/src/libiso8601/parser.c +++ b/src/libiso8601/200_parser.c @@ -1,4 +1,4 @@ -/* libiso8601/src/libiso8601/parser.c +/* libiso8601/src/libiso8601/200_parser.c * * (c)2006, Laurence Withers, . * Released under the GNU GPLv2. See file COPYING or diff --git a/src/libiso8601/200_parser.h b/src/libiso8601/200_parser.h new file mode 100644 index 0000000..7bf7cf0 --- /dev/null +++ b/src/libiso8601/200_parser.h @@ -0,0 +1,58 @@ +/* libiso8601/src/libiso8601/200_parser.h + * + * (c)2006, Laurence Withers, . + * Released under the GNU GPLv2. See file COPYING or + * http://www.gnu.org/copyleft/gpl.html for details. +*/ + + + +/*! \defgroup parser Parsing and validation routines. + +These routines are used for parsing an ISO8601 date/time string into the internal structure used +to represent them, and for validating such dates/times. + +*/ +/*!@{*/ + +/*! \brief Parse ISO8601 date/time. + +\param str The input string. +\param[out] earliest The earliest possible time the string could represent. May be 0. +\param[out] latest The latest possible time the string could represent. May be 0. +\param[out] details Stores details such as the precision to which the time/date were specified. May + be 0. +\retval -1 on error (and see \a errno). +\retval 0 on success. + +Parses a string containing the ISO8601 date/time. Deals with any format of date, optionally storing +the details in \a details. The time may be partial, in which case this function returns the earliest +and latest times that could possibly be represented by the string. + +Note that this function will accept leap seconds (23:59:60) on days on which they occurred. + +\todo Strip whitespace. + +*/ +int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601_date* latest, + struct iso8601_details* details); + + + +/*! \brief Validate ISO8601 date/time. + +\param date The date to validate. +\retval -1 if not valid. +\retval 0 if valid. + +*/ +int iso8601_valid(const struct iso8601_date* date); + + + +/*!@}*/ + +/* options for text editors +kate: replace-trailing-space-save true; space-indent true; tab-width 4; +vim: expandtab:ts=4:sw=4 +*/ diff --git a/src/libiso8601/functions.h b/src/libiso8601/400_functions.h similarity index 63% rename from src/libiso8601/functions.h rename to src/libiso8601/400_functions.h index 7238fd1..d1ca921 100644 --- a/src/libiso8601/functions.h +++ b/src/libiso8601/400_functions.h @@ -7,43 +7,6 @@ -/*! \defgroup parse Parsing and validation routines. - -These routines are used for parsing an ISO8601 date/time string into the internal structure used -to represent them, and for validating such dates/times. - -*/ -/*!@{*/ - -/*! \brief Parse ISO8601 date/time. - -\param str The input string. -\param[out] earliest ... -\param[out] latest The latest possible time the string could represent. May be 0. -\param[out] details Stores details such as the precision to which the time/date were specified. May - be 0. -\retval -1 on error (and see \a errno). -\retval 0 on success. - -Parses a string containing the ISO8601 date/time. Deals with any format of date, optionally storing -the details in \a details. The time may be partial, in which case this function returns the earliest -and latest times that could possibly be represented by the string. - -Note that this function will accept leap seconds (23:59:60) on days on which they occurred. It will -also accept the 24:00:00 representation of midnight (end of day). - -\todo Strip whitespace. - -*/ -int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601_date* latest, - struct iso8601_details* details); - -int iso8601_valid(const struct iso8601_date* date); - -/*!@}*/ - - - /* c_library.c */ void iso8601_now(struct iso8601_date* date, struct iso8601_details* details); void iso8601_from_ts(struct iso8601_date* date, const struct timespec* ts); diff --git a/src/libiso8601/BottomHeader.h b/src/libiso8601/999_BottomHeader.h similarity index 86% rename from src/libiso8601/BottomHeader.h rename to src/libiso8601/999_BottomHeader.h index f0b842a..091ffa7 100644 --- a/src/libiso8601/BottomHeader.h +++ b/src/libiso8601/999_BottomHeader.h @@ -1,4 +1,4 @@ -/* libiso8601/src/libiso8601/BottomHeader.h +/* libiso8601/src/libiso8601/999_BottomHeader.h * * (c)2006, Laurence Withers, . * Released under the GNU GPLv2. See file COPYING or diff --git a/src/libiso8601/build.monolithic b/src/libiso8601/build.monolithic index 99c8327..3e4337e 100644 --- a/src/libiso8601/build.monolithic +++ b/src/libiso8601/build.monolithic @@ -8,10 +8,10 @@ MONOLITHIC_TESTS="src/libiso8601/build.lib src/libiso8601/build.monolithic" if [ -z "${libiso8601_MONOLITHIC}" ] then - MONOLITHIC_SOURCE="$(echo src/libiso8601/{TopHeader,types,functions,BottomHeader}.h)" + MONOLITHIC_SOURCE="$(echo src/libiso8601/*.h)" make_monolithic ${HDR} Ch || return 1 - MONOLITHIC_SOURCE="$(echo src/libiso8601/{TopSource,leap,c_library,calc,parser,print,manip}.c)" + MONOLITHIC_SOURCE="$(echo src/libiso8601/*.c)" make_monolithic ${SRC} C || return 1 libiso8601_MONOLITHIC=1 diff --git a/src/libiso8601/types.h b/src/libiso8601/types.h deleted file mode 100644 index 3bfe496..0000000 --- a/src/libiso8601/types.h +++ /dev/null @@ -1,45 +0,0 @@ -/* libiso8601/src/libiso8601/types.h - * - * (c)2006, Laurence Withers, . - * Released under the GNU GPLv2. See file COPYING or - * http://www.gnu.org/copyleft/gpl.html for details. -*/ - - - -struct iso8601_date { - int32_t nsec; - int32_t day; - int32_t sec; // special value: 86400 == leap second 23:59:60 -}; - -enum iso8601_date_prec { - iso8601_prec_year, - iso8601_prec_month, - iso8601_prec_day, - iso8601_prec_ord, - iso8601_prec_week, - iso8601_prec_wday -}date_prec; - -enum iso8601_time_prec { - iso8601_prec_none, - iso8601_prec_hour, - iso8601_prec_min, - iso8601_prec_sec, - iso8601_prec_hourfrac, - iso8601_prec_minfrac, - iso8601_prec_secfrac -}time_prec; - -struct iso8601_details { - uint8_t date_prec, time_prec, extended; - int32_t tz_sec; -}; - - - -/* options for text editors -kate: replace-trailing-space-save true; space-indent true; tab-width 4; -vim: expandtab:ts=4:sw=4 -*/