Begin cleanup of source files

This commit is contained in:
Laurence Withers 2007-07-23 13:47:53 +00:00
parent 5643e388ee
commit e9d29f4792
10 changed files with 176 additions and 90 deletions

View File

@ -1,4 +1,4 @@
/* libiso8601/src/libiso8601/TopHeader.h
/* libiso8601/src/libiso8601/000_TopHeader.h
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* 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 <time.h>
#include <stdint.h>

View File

@ -1,4 +1,4 @@
/* libiso8601/src/libiso8601/TopSource.c
/* libiso8601/src/libiso8601/000_TopSource.c
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or
@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
/* Useful define to alleviate typos */
#define BILLION (1000000000L)
/* options for text editors

View File

@ -1,4 +1,4 @@
/* libiso8601/src/libiso8601/calc.c
/* libiso8601/src/libiso8601/100_calc.c
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or

109
src/libiso8601/100_types.h Normal file
View File

@ -0,0 +1,109 @@
/* libiso8601/src/libiso8601/100_types.h
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* 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
*/

View File

@ -1,4 +1,4 @@
/* libiso8601/src/libiso8601/parser.c
/* libiso8601/src/libiso8601/200_parser.c
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or

View File

@ -0,0 +1,58 @@
/* libiso8601/src/libiso8601/200_parser.h
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* 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
*/

View File

@ -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);

View File

@ -1,4 +1,4 @@
/* libiso8601/src/libiso8601/BottomHeader.h
/* libiso8601/src/libiso8601/999_BottomHeader.h
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or

View File

@ -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

View File

@ -1,45 +0,0 @@
/* libiso8601/src/libiso8601/types.h
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* 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
*/