Compare commits
110 Commits
Author | SHA1 | Date |
---|---|---|
|
82aa0f2f20 | |
|
2e610c4db3 | |
|
dd3fe182af | |
![]() |
0d5c2078b3 | |
![]() |
6b25293f35 | |
|
dcb15f2081 | |
|
4c470ec1e9 | |
|
ba81c458e1 | |
![]() |
49536349f7 | |
![]() |
c7b38eab5a | |
![]() |
c198eaf34b | |
![]() |
b622223b64 | |
![]() |
81df4e8a05 | |
![]() |
7a5f30bfcd | |
![]() |
d910e88bc3 | |
![]() |
2aa3d5aaac | |
![]() |
d013bff263 | |
![]() |
8cc71fb069 | |
![]() |
2d9621e0a5 | |
![]() |
944331702f | |
![]() |
0d56edd890 | |
![]() |
65fe613272 | |
![]() |
64e06d17c4 | |
![]() |
cd9a2d252a | |
|
ed05b5c872 | |
|
bd4ddd7621 | |
|
420df40a5b | |
|
9f3fbd4116 | |
|
6285d214aa | |
![]() |
e504a722f5 | |
![]() |
1a0553e083 | |
![]() |
7ba82a2988 | |
![]() |
b7d039a32c | |
![]() |
dcfc699af0 | |
![]() |
47ccc537b8 | |
![]() |
1d9447dcd2 | |
![]() |
d09e55e8ae | |
![]() |
3309803b9e | |
![]() |
076d215860 | |
![]() |
6937f2f12b | |
![]() |
c4679ded38 | |
![]() |
557c7e1efb | |
![]() |
711872660b | |
![]() |
ddaa9a8f8d | |
![]() |
394dc40b97 | |
![]() |
73df6f836d | |
![]() |
a0f747067d | |
![]() |
e908febba2 | |
![]() |
2c016208f2 | |
![]() |
849744bb07 | |
![]() |
2d51d09c83 | |
![]() |
cad2283f6a | |
![]() |
d431f68054 | |
![]() |
0d504baaee | |
![]() |
93efb6294d | |
![]() |
6246f8ebcd | |
![]() |
048196532e | |
![]() |
1f43445813 | |
![]() |
69628be83e | |
![]() |
a4e99696a1 | |
![]() |
21adf7acf0 | |
![]() |
64c5ce0d65 | |
![]() |
07a31fd8f7 | |
![]() |
c47e0e241f | |
![]() |
2a51412ade | |
![]() |
7d35697775 | |
![]() |
f49b80de01 | |
![]() |
4deda83c58 | |
![]() |
6ae62fb796 | |
![]() |
ec6c9a41f7 | |
![]() |
e59586b265 | |
![]() |
124df16711 | |
![]() |
1a92252640 | |
![]() |
6d9df9927d | |
![]() |
1f44765f0b | |
![]() |
a46057ef49 | |
![]() |
35c4455bc2 | |
![]() |
603b067310 | |
![]() |
f82859fa78 | |
![]() |
d08f81a6cf | |
![]() |
5d73f2f004 | |
![]() |
8d7988a0c4 | |
![]() |
a0bc1e3d06 | |
![]() |
47f35dc992 | |
![]() |
674e705d05 | |
![]() |
1b6343e474 | |
![]() |
e9d29f4792 | |
![]() |
5643e388ee | |
![]() |
0cb46591e9 | |
![]() |
5c358ce21d | |
![]() |
a0800d0ed2 | |
![]() |
20a7d92d1c | |
![]() |
16e76a257f | |
![]() |
728d0b6151 | |
![]() |
be475c5dc1 | |
![]() |
f90b0ea300 | |
![]() |
b6f832ebea | |
![]() |
7aace3d8e3 | |
![]() |
4bd50f62e2 | |
![]() |
db23c34449 | |
![]() |
9d5e4dd3c6 | |
![]() |
81564487a4 | |
![]() |
1fc5324e73 | |
![]() |
298775a047 | |
![]() |
665fcc484c | |
![]() |
af480a6476 | |
![]() |
3ed9be011a | |
![]() |
a24c6ae302 | |
![]() |
994a28d35b | |
![]() |
6a55a63695 |
|
@ -1,2 +1,3 @@
|
|||
obj
|
||||
html
|
||||
.*.swp
|
||||
|
|
846
COPYING
846
COPYING
|
@ -1,278 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
0. Definitions.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
1. Source Code.
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
14. Revised Versions of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
NO WARRANTY
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
|
15
README
15
README
|
@ -1,7 +1,7 @@
|
|||
libiso8601
|
||||
========================================================================
|
||||
(c)2006, Laurence Withers, <l@lwithers.me.uk>.
|
||||
Released under the GNU GPLv2. See file COPYING or
|
||||
(c)2007, Laurence Withers, <l@lwithers.me.uk>.
|
||||
Released under the GNU GPLv3. See file COPYING or
|
||||
http://www.gnu.org/copyleft/gpl.html for details.
|
||||
|
||||
Really Quick Instructions
|
||||
|
@ -9,6 +9,15 @@ Really Quick Instructions
|
|||
|
||||
To build: ./make.sh
|
||||
To install: ./make.sh install
|
||||
(you might want to set PREFIX, by default it's /usr/local)
|
||||
|
||||
You might want to edit 'config' first. You might also want to set
|
||||
'INSTALL_PREFIX', which is prepended onto the destination of any
|
||||
installed file.
|
||||
|
||||
Thanks
|
||||
------
|
||||
|
||||
Robert Dunlop, <rjd@xyzzy.org.uk>
|
||||
* found null terminating bug with iso8601_print()
|
||||
|
||||
@TODO@
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
# libiso8601/config
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
||||
#
|
||||
# (c)2007, Laurence Withers, <l@lwithers.me.uk>.
|
||||
# Released under the GNU GPLv3. See file COPYING or
|
||||
# http://www.gnu.org/copyleft/gpl.html for details.
|
||||
#
|
||||
# This file contains options used to build libiso8601.
|
||||
|
||||
|
||||
# PREFIX is the most important option. Many other paths are derived from it, as follows:
|
||||
#
|
||||
# PREFIX | / | /usr | /usr/local | /opt/*
|
||||
# ------------+-------------------+-------------------+-------------------+-----------------
|
||||
# BINDIR | /bin | /usr/bin | /usr/local/bin | /opt/*/bin
|
||||
# SBINDIR | /sbin | /usr/sbin | /usr/local/sbin | /opt/*/sbin
|
||||
# LIBDIR | /lib | /usr/lib | /usr/local/lib | /opt/*/lib
|
||||
# INCLUDEDIR | /usr/include | /usr/include | /usr/local/include| /opt/*/include
|
||||
# CONFIGDIR | /etc | /etc | /usr/local/etc | /etc/opt/*
|
||||
# VARDIR | /var | /var | /var | /var/opt/*
|
||||
# SHAREDIR | /usr/share | /usr/share | /usr/local/share | /opt/*/share
|
||||
# DOCSDIR | /usr/share/doc | /usr/share/doc | /usr/local/share/doc, /opt/*/doc
|
||||
# WEBDIR | /srv/http | /srv/http | /srv/http | /opt/*/http
|
||||
#
|
||||
# Specific notes:
|
||||
# When installing, all paths are prepended with INSTALL_PREFIX.
|
||||
# Any parameter can be overridden by setting an environment variable.
|
||||
# CGIDIR is set to ${WEBDIR}/cgi-bin .
|
||||
#
|
||||
[ -z "${PREFIX}" ] && PREFIX="/usr/local"
|
||||
source "scripts/paths"
|
||||
|
||||
# Project-specific variables below.
|
||||
[ -z "${DEFAULT_LEAP_TABLE}" ] && DEFAULT_LEAP_TABLE="${SHAREDIR}/libiso8601/leap-table"
|
||||
|
||||
[ -z "${CC}" ] && CC="gcc"
|
||||
[ -z "${CFLAGS}" ] && CFLAGS="-g -O2 -W -Wall"
|
|
@ -1,168 +0,0 @@
|
|||
<?xml version = '1.0'?>
|
||||
<kdevelop>
|
||||
<general>
|
||||
<author>Laurence Withers</author>
|
||||
<email>l@lwithers.me.uk</email>
|
||||
<version>$VERSION$</version>
|
||||
<projectmanagement>KDevCustomProject</projectmanagement>
|
||||
<primarylanguage>C++</primarylanguage>
|
||||
<ignoreparts/>
|
||||
<projectdirectory>.</projectdirectory>
|
||||
<absoluteprojectpath>false</absoluteprojectpath>
|
||||
<description/>
|
||||
<versioncontrol/>
|
||||
</general>
|
||||
<kdevcustomproject>
|
||||
<run>
|
||||
<mainprogram>/bin/true</mainprogram>
|
||||
<directoryradio>executable</directoryradio>
|
||||
<customdirectory>/</customdirectory>
|
||||
<programargs/>
|
||||
<terminal>false</terminal>
|
||||
<autocompile>true</autocompile>
|
||||
<envvars/>
|
||||
</run>
|
||||
<build>
|
||||
<buildtool>make</buildtool>
|
||||
<builddir/>
|
||||
</build>
|
||||
<make>
|
||||
<abortonerror>false</abortonerror>
|
||||
<numberofjobs>1</numberofjobs>
|
||||
<prio>0</prio>
|
||||
<dontact>false</dontact>
|
||||
<makebin>./make.sh</makebin>
|
||||
<defaulttarget>default</defaulttarget>
|
||||
<makeoptions/>
|
||||
<selectedenvironment>default</selectedenvironment>
|
||||
<environments>
|
||||
<default/>
|
||||
</environments>
|
||||
</make>
|
||||
<general>
|
||||
<activedir/>
|
||||
</general>
|
||||
</kdevcustomproject>
|
||||
<kdevdebugger>
|
||||
<general>
|
||||
<dbgshell/>
|
||||
<programargs/>
|
||||
<gdbpath/>
|
||||
<configGdbScript/>
|
||||
<runShellScript/>
|
||||
<runGdbScript/>
|
||||
<breakonloadinglibs>true</breakonloadinglibs>
|
||||
<separatetty>false</separatetty>
|
||||
<floatingtoolbar>false</floatingtoolbar>
|
||||
</general>
|
||||
<display>
|
||||
<staticmembers>false</staticmembers>
|
||||
<demanglenames>true</demanglenames>
|
||||
<outputradix>10</outputradix>
|
||||
</display>
|
||||
</kdevdebugger>
|
||||
<kdevdoctreeview>
|
||||
<ignoretocs>
|
||||
<toc>ada</toc>
|
||||
<toc>ada_bugs_gcc</toc>
|
||||
<toc>bash</toc>
|
||||
<toc>bash_bugs</toc>
|
||||
<toc>clanlib</toc>
|
||||
<toc>fortran_bugs_gcc</toc>
|
||||
<toc>gnome1</toc>
|
||||
<toc>gnustep</toc>
|
||||
<toc>gtk</toc>
|
||||
<toc>gtk_bugs</toc>
|
||||
<toc>haskell</toc>
|
||||
<toc>haskell_bugs_ghc</toc>
|
||||
<toc>java_bugs_gcc</toc>
|
||||
<toc>java_bugs_sun</toc>
|
||||
<toc>kde2book</toc>
|
||||
<toc>opengl</toc>
|
||||
<toc>pascal_bugs_fp</toc>
|
||||
<toc>php</toc>
|
||||
<toc>php_bugs</toc>
|
||||
<toc>perl</toc>
|
||||
<toc>perl_bugs</toc>
|
||||
<toc>python</toc>
|
||||
<toc>python_bugs</toc>
|
||||
<toc>qt-kdev3</toc>
|
||||
<toc>ruby</toc>
|
||||
<toc>ruby_bugs</toc>
|
||||
<toc>sdl</toc>
|
||||
<toc>sw</toc>
|
||||
<toc>w3c-dom-level2-html</toc>
|
||||
<toc>w3c-svg</toc>
|
||||
<toc>w3c-uaag10</toc>
|
||||
<toc>wxwidgets_bugs</toc>
|
||||
</ignoretocs>
|
||||
<ignoreqt_xml>
|
||||
<toc>Guide to the Qt Translation Tools</toc>
|
||||
<toc>Qt Assistant Manual</toc>
|
||||
<toc>Qt Designer Manual</toc>
|
||||
<toc>Qt Reference Documentation</toc>
|
||||
<toc>qmake User Guide</toc>
|
||||
</ignoreqt_xml>
|
||||
<ignoredoxygen>
|
||||
<toc>KDE Libraries (Doxygen)</toc>
|
||||
</ignoredoxygen>
|
||||
</kdevdoctreeview>
|
||||
<kdevfilecreate>
|
||||
<filetypes/>
|
||||
<useglobaltypes>
|
||||
<type ext="cpp" />
|
||||
<type ext="h" />
|
||||
</useglobaltypes>
|
||||
</kdevfilecreate>
|
||||
<cppsupportpart>
|
||||
<filetemplates>
|
||||
<interfacesuffix>.h</interfacesuffix>
|
||||
<implementationsuffix>.cpp</implementationsuffix>
|
||||
</filetemplates>
|
||||
</cppsupportpart>
|
||||
<kdevcppsupport>
|
||||
<codecompletion>
|
||||
<includeGlobalFunctions>true</includeGlobalFunctions>
|
||||
<includeTypes>true</includeTypes>
|
||||
<includeEnums>true</includeEnums>
|
||||
<includeTypedefs>false</includeTypedefs>
|
||||
<automaticCodeCompletion>true</automaticCodeCompletion>
|
||||
<automaticArgumentsHint>true</automaticArgumentsHint>
|
||||
<automaticHeaderCompletion>true</automaticHeaderCompletion>
|
||||
<codeCompletionDelay>1</codeCompletionDelay>
|
||||
<argumentsHintDelay>1</argumentsHintDelay>
|
||||
<headerCompletionDelay>250</headerCompletionDelay>
|
||||
</codecompletion>
|
||||
<creategettersetter>
|
||||
<prefixGet/>
|
||||
<prefixSet>set</prefixSet>
|
||||
<prefixVariable>m_,_</prefixVariable>
|
||||
<parameterName>theValue</parameterName>
|
||||
<inlineGet>true</inlineGet>
|
||||
<inlineSet>true</inlineSet>
|
||||
</creategettersetter>
|
||||
<references/>
|
||||
</kdevcppsupport>
|
||||
<kdevdocumentation>
|
||||
<projectdoc>
|
||||
<docsystem/>
|
||||
<docurl/>
|
||||
<usermanualurl/>
|
||||
</projectdoc>
|
||||
</kdevdocumentation>
|
||||
<kdevfileview>
|
||||
<groups>
|
||||
<hidenonprojectfiles>false</hidenonprojectfiles>
|
||||
<hidenonlocation>false</hidenonlocation>
|
||||
</groups>
|
||||
<tree>
|
||||
<hidepatterns>*.o,*.lo,CVS</hidepatterns>
|
||||
<hidenonprojectfiles>false</hidenonprojectfiles>
|
||||
<showvcsfields>false</showvcsfields>
|
||||
</tree>
|
||||
</kdevfileview>
|
||||
<ctagspart>
|
||||
<customArguments/>
|
||||
<customTagfilePath/>
|
||||
</ctagspart>
|
||||
</kdevelop>
|
|
@ -1,4 +0,0 @@
|
|||
# KDevelop Custom Project File List
|
||||
src/lib/BottomHeader.h
|
||||
src/lib/TopHeader.h
|
||||
src/lib/TopSource.cpp
|
83
make.sh
83
make.sh
|
@ -1,48 +1,33 @@
|
|||
#!/bin/bash
|
||||
# libiso8601/make.sh
|
||||
#
|
||||
# (c)2006, Laurence Withers, <l@lwithers.me.uk>.
|
||||
# Released under the GNU GPLv2. See file COPYING or
|
||||
# (c)2009, Laurence Withers, <l@lwithers.me.uk>.
|
||||
# Released under the GNU GPLv3. See file COPYING or
|
||||
# http://www.gnu.org/copyleft/gpl.html for details.
|
||||
#
|
||||
|
||||
|
||||
# This file is the script used to build libiso8601. There are some
|
||||
# options that can be edited; these are set below (or you can pass them
|
||||
# in as variables).
|
||||
[ -z "${CC}" ] && CC="gcc"
|
||||
[ -z "${CXX}" ] && CXX="g++"
|
||||
[ -z "${CFLAGS}" ] && CFLAGS="-g -O2 -W -Wall"
|
||||
[ -z "${PREFIX}" ] && PREFIX="/usr/local"
|
||||
[ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
|
||||
[ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
|
||||
[ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
|
||||
[ -z "${DOCSDIR}" ] && DOCSDIR="${PREFIX}/share/doc/libiso8601"
|
||||
|
||||
# for pkg-config
|
||||
[ -z "${PKGCONFDIR}" ] && PKGCONFDIR="${LIBDIR}/pkgconfig"
|
||||
[ -z "${FINALLIBDIR}" ] && FINALLIBDIR="${LIBDIR}"
|
||||
[ -z "${FINALINCLUDEDIR}" ] && FINALINCLUDEDIR="${INCLUDEDIR}"
|
||||
|
||||
# for SDCC-built firmware
|
||||
[ -z "${HEXDIR}" ] && HEXDIR="${PREFIX}/share/firmware"
|
||||
[ -z "${SDCC}" ] && SDCC="sdcc"
|
||||
# options that can be edited; these are set in the file 'config' (or you
|
||||
# can pass them in as environment variables).
|
||||
if [ ! -e "config" ]
|
||||
then
|
||||
echo "Configuration file not found???"
|
||||
exit 1
|
||||
fi
|
||||
source "./config" # don't fail on error, since last command in config might return false
|
||||
|
||||
|
||||
|
||||
# Get version information
|
||||
source version || exit 1
|
||||
source "./version" || exit 1
|
||||
VERSION="${VERMAJOR}.${VERMINOR}.${VERMICRO}"
|
||||
if [ ! -z "${VEREXTRA}" ]
|
||||
then
|
||||
VERSION="${VERSION}-${VEREXTRA}"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# Get standard functions
|
||||
[ -z "${VERBOSE}" ] && VERBOSE="0"
|
||||
source scripts/functions.sh || exit 1
|
||||
source "./scripts/functions.sh" || exit 1
|
||||
|
||||
|
||||
# List of directories which will be emptied by clean.
|
||||
|
@ -59,6 +44,8 @@ OUTPUT_DIRS="obj html"
|
|||
# MONOLITHIC_TESTS if any file mentioned in this list is newer
|
||||
# than the output file, then we recreate it
|
||||
# MONOLITHIC_SOURCE a list (in order) of the source files
|
||||
# MONOLITHIC_OPTIONS will #define the options to match the respective
|
||||
# environment variables.
|
||||
#
|
||||
# Recognised formats are:
|
||||
# none no special processing happens before each file
|
||||
|
@ -79,18 +66,21 @@ make_monolithic() {
|
|||
# extract options
|
||||
HASHLINE=0
|
||||
VERDEFINE=0
|
||||
HASHDEFINE=0
|
||||
if [ "$2" == "C" ]
|
||||
then
|
||||
HASHLINE=1
|
||||
VERDEFINE=1
|
||||
HASHDEFINE=1
|
||||
elif [ "$2" == "Ch" ]
|
||||
then
|
||||
HASHLINE=1
|
||||
HASHDEFINE=1
|
||||
elif [ "$2" == "none" ]
|
||||
then
|
||||
HASHLINE=0 # dummy command
|
||||
HASHLINE=0 # dummy command
|
||||
else
|
||||
print_failure "make_monolithic() called with unknown format $2"
|
||||
print_failure "make_monolithic() called with unknown format $2"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -126,6 +116,14 @@ make_monolithic() {
|
|||
do_cmd_redir ${MONOLITHIC_OUT} echo "#define VEREXTRA \"${VEREXTRA}\"" || return 1
|
||||
fi
|
||||
|
||||
if [ ${HASHDEFINE} -ne 0 ]
|
||||
then
|
||||
for opt in ${MONOLITHIC_OPTIONS}
|
||||
do
|
||||
do_cmd_redir ${MONOLITHIC_OUT} echo "#define ${opt} ${!opt}" || return 1
|
||||
done
|
||||
fi
|
||||
|
||||
for FILE in ${MONOLITHIC_SOURCE}
|
||||
do
|
||||
if [ ${HASHLINE} -ne 0 ]
|
||||
|
@ -153,6 +151,10 @@ build_dir_tree() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
build_dir_tree_recurse "${INSTALL_PREFIX}$1"
|
||||
}
|
||||
|
||||
build_dir_tree_recurse() {
|
||||
local DIR="$1"
|
||||
|
||||
# if the directory already exists, return success
|
||||
|
@ -171,8 +173,9 @@ build_dir_tree() {
|
|||
mkdir "${DIR}" >& /dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
build_dir_tree $(dirname "${DIR}") || return 1
|
||||
mkdir "${DIR}"
|
||||
build_dir_tree_recurse $(dirname "${DIR}") || return 1
|
||||
echo " Creating directory '${DIR}'"
|
||||
do_cmd mkdir "${DIR}"
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
print_failure "Failed to create directory '${DIR}'"
|
||||
|
@ -191,10 +194,10 @@ build_dir_tree() {
|
|||
# second is the destination. The third is the octal mode.
|
||||
install_file() {
|
||||
# figure out if $2 is a directory or not
|
||||
DEST_FILE="$2"
|
||||
[ -d "$2" ] && DEST_FILE="$2/$(basename $1)"
|
||||
DEST_FILE="${INSTALL_PREFIX}$2"
|
||||
[ -d "${DEST_FILE}" ] && DEST_FILE="${INSTALL_PREFIX}$2/$(basename $1)"
|
||||
|
||||
echo " Installing: '$1' -> '$2'"
|
||||
echo " Installing: '$1' -> '${DEST_FILE}'"
|
||||
do_cmd cp -fP "$1" "${DEST_FILE}" || return 1
|
||||
do_cmd chmod "$3" "${DEST_FILE}" || return 1
|
||||
|
||||
|
@ -206,10 +209,10 @@ install_file() {
|
|||
# This will install a header file. It is basically similar to
|
||||
# install_file(), only we strip out the #line directives.
|
||||
install_header() {
|
||||
DEST_FILE="$2"
|
||||
[ -d "$2" ] && DEST_FILE="$2/$(basename $1)"
|
||||
DEST_FILE="${INSTALL_PREFIX}$2"
|
||||
[ -d "${DEST_FILE}" ] && DEST_FILE="${INSTALL_PREFIX}$2/$(basename $1)"
|
||||
|
||||
echo " Installing header: '$1' -> '$2'"
|
||||
echo " Installing: '$1' -> '${DEST_FILE}'"
|
||||
do_cmd rm -f ${DEST_FILE} || exit 1
|
||||
do_cmd_redir ${DEST_FILE} sed -e "s,^#line.*,," $1 || exit 1
|
||||
do_cmd chmod "$3" "${DEST_FILE}" || return 1
|
||||
|
@ -223,9 +226,9 @@ install_header() {
|
|||
# second the symlink's source filename, and the third is the directory
|
||||
# in which to create the symlink.
|
||||
install_symlink() {
|
||||
echo " Installing symlink: '$3/$2' -> '$1'"
|
||||
echo " Installing symlink: '${INSTALL_PREFIX}$3/$1' -> '$2'"
|
||||
|
||||
( do_cmd cd $3; ln -sf $2 $1 ) || return 1
|
||||
( do_cmd ln -sf $2 ${INSTALL_PREFIX}$3/$1 ) || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
@ -272,6 +275,7 @@ do
|
|||
echo "Cleaning..."
|
||||
rm -rf ${OUTPUT_DIRS}
|
||||
print_success "Done"
|
||||
true
|
||||
;;
|
||||
|
||||
# bad Kdevelop! bad!
|
||||
|
@ -288,5 +292,4 @@ done
|
|||
|
||||
exit 0
|
||||
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
|
|
18
run-test.sh
18
run-test.sh
|
@ -1,9 +1,9 @@
|
|||
#!/bin/bash
|
||||
# libiso8601/test.sh
|
||||
#
|
||||
# (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.
|
||||
# Copyright: ©2009–2011, Güralp Systems Ltd.
|
||||
# Author: Laurence Withers <lwithers@guralp.com>
|
||||
# License: GPLv3
|
||||
#
|
||||
|
||||
# Running this script on its own will display a summary of all the
|
||||
|
@ -21,7 +21,7 @@ run_test() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
LD_LIBRARY_PATH="obj" ${EXE} "$@" || return 1
|
||||
LD_LIBRARY_PATH="obj:${LD_LIBRARY_PATH}" "${EXE}" "$@" || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -33,14 +33,15 @@ print_tests() {
|
|||
echo "---------------------------------------------------------------------"
|
||||
for EXE in obj/tests/*
|
||||
do
|
||||
[ -x ${EXE} ] || continue
|
||||
NAME=$(echo ${EXE} | sed 's,obj/tests/,,')
|
||||
[ -x "${EXE}" ] || continue
|
||||
NAME="$(echo "${EXE}" | sed 's,obj/tests/,,')"
|
||||
echo -ne "${NAME}\t"
|
||||
LD_LIBRARY_PATH="obj" ${EXE} --print-summary
|
||||
LD_LIBRARY_PATH="obj:${LD_LIBRARY_PATH}" "${EXE}" --print-summary
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Main script
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
|
@ -48,7 +49,6 @@ then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
run_test $*
|
||||
run_test "$@"
|
||||
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
build.c++.app
|
||||
build.c++.lib
|
||||
build.c++.qtapp
|
||||
build.c++.tests
|
||||
build.c.app
|
||||
build.c.lib
|
||||
build.c.tests
|
||||
build.doxygen.docs
|
||||
build.none.files
|
||||
build.sdcc.firmware
|
||||
build.app.c
|
||||
build.app.c++
|
||||
build.app.c++-qt
|
||||
build.app.sh
|
||||
build.docs.doxygen
|
||||
build.docs.none
|
||||
build.files.none
|
||||
build.firmware.gpasm
|
||||
build.firmware.sdcc
|
||||
build.header.c
|
||||
build.lib.c
|
||||
build.lib.c++
|
||||
build.make.none
|
||||
build.module.c
|
||||
build.tests.c
|
||||
build.tests.c++
|
||||
|
||||
config-printflags.sh
|
||||
module-create.sh
|
||||
release.sh
|
||||
version.sh
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#!/bin/bash
|
||||
# libiso8601/scripts/functions.sh
|
||||
#
|
||||
# (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.
|
||||
# Copyright: ©2007–2011, Güralp Systems Ltd.
|
||||
# Author: Laurence Withers, <lwithers@guralp.com>
|
||||
# License: GPLv3
|
||||
#
|
||||
|
||||
# Common functions
|
||||
|
@ -64,5 +63,4 @@ do_cmd_redir() {
|
|||
fi
|
||||
}
|
||||
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
# libiso8601/scripts/paths
|
||||
#
|
||||
# Copyright: ©2011, Güralp Systems Ltd.
|
||||
# Author: Laurence Withers, <lwithers@guralp.com>
|
||||
# License: GPLv3
|
||||
#
|
||||
# Default path setup. Not meant for editing; use environment variables
|
||||
# to override values if needed.
|
||||
#
|
||||
|
||||
MY_PREFIX="${PREFIX}"
|
||||
[ "${MY_PREFIX}" == "/" ] && MY_PREFIX=""
|
||||
|
||||
[ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
|
||||
[ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
|
||||
[ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
|
||||
|
||||
if [ -z "${INCLUDEDIR}" ]
|
||||
then
|
||||
case "${PREFIX}" in
|
||||
/) INCLUDEDIR="/usr/include" ;;
|
||||
*) INCLUDEDIR="${PREFIX}/include" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -z "${CONFIGDIR}" ]
|
||||
then
|
||||
case "${PREFIX}" in
|
||||
/ | /usr) CONFIGDIR="/etc" ;;
|
||||
/opt*) CONFIGDIR="/etc${PREFIX}" ;;
|
||||
*) CONFIGDIR="${PREFIX}/etc" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -z "${VARDIR}" ]
|
||||
then
|
||||
case "${PREFIX}" in
|
||||
/ | /usr | /usr/local) VARDIR="/var" ;;
|
||||
/opt*) VARDIR="/var${PREFIX}" ;;
|
||||
*) VARDIR="${PREFIX}/var" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -z "${SHAREDIR}" ]
|
||||
then
|
||||
case "${PREFIX}" in
|
||||
/) SHAREDIR="/usr/share" ;;
|
||||
*) SHAREDIR="${PREFIX}/share" ;;
|
||||
esac
|
||||
fi
|
||||
[ -z "${DOCSDIR}" ] && DOCSDIR="${SHAREDIR}/doc"
|
||||
|
||||
if [ -z "${SRVDIR}" ]
|
||||
then
|
||||
case "${PREFIX}" in
|
||||
/ | /usr | /usr/local) SRVDIR="/srv" ;;
|
||||
*) SRVDIR="${PREFIX}/srv" ;;
|
||||
esac
|
||||
fi
|
||||
[ -z "${WEBDIR}" ] && WEBDIR="${SRVDIR}/http"
|
||||
[ -z "${CGIDIR}" ] && CGIDIR="${WEBDIR}/cgi-bin"
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -0,0 +1 @@
|
|||
docs doxygen docs
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,20 @@
|
|||
/* libiso8601/src/docs/MainPage.dox
|
||||
*
|
||||
* (c)2007-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
/*! \mainpage Library for manipulating ISO8601-format dates and times
|
||||
|
||||
\c libiso8601 is a library containing conversion routines for ISO8601-format
|
||||
dates and times and a set of associated date/time manipulation routines. It has
|
||||
support for leap seconds and nanosecond accuracy and is intended for use in
|
||||
e.g. physical science applications.
|
||||
|
||||
*/
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4:syntax=doxygen
|
||||
*/
|
|
@ -0,0 +1 @@
|
|||
source src/docs/build.docs
|
|
@ -0,0 +1,42 @@
|
|||
# These are external variables, and shouldn't clash with anything else
|
||||
# docs_BUILT
|
||||
#
|
||||
|
||||
MONOLITHIC_DOC="${MONOLITHIC_DOC} $(echo src/docs/*.dox)"
|
||||
build_target monolithic
|
||||
|
||||
if [ -z ${docs_BUILT} ]
|
||||
then
|
||||
echo "Building documentation with Doxygen..."
|
||||
|
||||
DOXYFILE=obj/Doxyfile.docs
|
||||
|
||||
if [ ! -e ${DOXYFILE} ]
|
||||
then
|
||||
do_cmd cp src/docs/Doxyfile.in ${DOXYFILE} || return 1
|
||||
echo "INPUT = ${MONOLITHIC_DOC}" >> ${DOXYFILE}
|
||||
echo "PROJECT_NUMBER = ${VERSION}" >> ${DOXYFILE}
|
||||
fi
|
||||
|
||||
MODIFIED=0
|
||||
for file in ${MONOLITHIC_DOC}
|
||||
do
|
||||
if [ ${file} -nt html/index.html ]
|
||||
then
|
||||
MODIFIED=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${MODIFIED} -ne 0 ]
|
||||
then
|
||||
do_cmd doxygen ${DOXYFILE} || return 1
|
||||
print_success "Documentation built"
|
||||
else
|
||||
print_success "Documentation is up to date"
|
||||
fi
|
||||
|
||||
docs_BUILT=1
|
||||
fi
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -0,0 +1 @@
|
|||
source src/docs/build.install-docs
|
|
@ -0,0 +1,20 @@
|
|||
build_target docs
|
||||
|
||||
# create documentation directories
|
||||
echo "Installing documentation into ${DOCSDIR}"
|
||||
build_dir_tree "${DOCSDIR}/html" || return 1
|
||||
|
||||
# copy across the Doxygen-generated documentation
|
||||
for file in html/*
|
||||
do
|
||||
install_file ${file} ${DOCSDIR}/html 0644 || return 1
|
||||
done
|
||||
|
||||
# copy across the generic files
|
||||
for file in COPYING README
|
||||
do
|
||||
install_file ${file} ${DOCSDIR} 0644 || return 1
|
||||
done
|
||||
|
||||
print_success "Documentation installed"
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -0,0 +1 @@
|
|||
app c isodate bin
|
|
@ -0,0 +1,147 @@
|
|||
/* libiso8601/src/isodate/000_TopSource.c
|
||||
*
|
||||
* (c)2007, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv2. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
/* Below are all the includes used throughout the application. */
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include "iso8601.h"
|
||||
|
||||
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fputs("Usage:\n\n"
|
||||
" isodate [options] [date ...]\n\n"
|
||||
"Valid options:\n"
|
||||
" -h, --help Display this screen.\n"
|
||||
" -e, --extended Use extended display format.\n"
|
||||
" -y, --year Only display year.\n"
|
||||
" -n, --month Display year, month.\n"
|
||||
" -d, --day Display year, month, day [default].\n"
|
||||
" -o, --ordinal Display year, ordinal day.\n"
|
||||
" -w, --week Display ISO year, ISO week.\n"
|
||||
" -W, --week-day Display ISO year, ISO week, ISO weekday.\n"
|
||||
" -r, --hour Display hour.\n"
|
||||
" -R, --hour-fraction Display hour and fraction of hour.\n"
|
||||
" -m, --minute Display hour, minute.\n"
|
||||
" -M, --minute-fraction Display hour, minute and fraction of\n"
|
||||
" minute.\n"
|
||||
" -s, --second Display hour, minute, second.\n"
|
||||
" -S, --second-fraction Display hour, minute, second and fraction\n"
|
||||
" of second [default].\n"
|
||||
" -U, --utc-offset <n> Display time as if timezone offset was\n"
|
||||
" <n> seconds.\n"
|
||||
" -Z, --utc Display time in UTC.\n"
|
||||
"\n"
|
||||
"If specified, one or more ISO8601 dates will be parsed and displayed\n"
|
||||
"in the format given. Otherwise, the system clock will be queried and\n"
|
||||
"its time displayed.\n"
|
||||
"\n", stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct option options[] = {
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "extended", no_argument, 0, 'e' },
|
||||
{ "year", no_argument, 0, 'y' },
|
||||
{ "month", no_argument, 0, 'n' },
|
||||
{ "day", no_argument, 0, 'd' },
|
||||
{ "ordinal", no_argument, 0, 'o' },
|
||||
{ "week", no_argument, 0, 'w' },
|
||||
{ "week-day", no_argument, 0, 'W' },
|
||||
{ "hour", no_argument, 0, 'r' },
|
||||
{ "hour-fraction", no_argument, 0, 'R' },
|
||||
{ "minute", no_argument, 0, 'm' },
|
||||
{ "minute-fraction", no_argument, 0, 'M' },
|
||||
{ "second", no_argument, 0, 's' },
|
||||
{ "second-fraction", no_argument, 0, 'S' },
|
||||
{ "utc-offset", required_argument, 0, 'U' },
|
||||
{ "utc", no_argument, 0, 'Z' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct iso8601_details det = {
|
||||
.date_prec = iso8601_prec_day,
|
||||
.time_prec = iso8601_prec_secfrac,
|
||||
.extended = 0,
|
||||
.tz_sec = 0
|
||||
};
|
||||
int override_tz = 0, ret = 0;
|
||||
char* endp, datestr[100];
|
||||
struct iso8601_date date;
|
||||
struct iso8601_details det2;
|
||||
|
||||
while(1) {
|
||||
switch(getopt_long(argc, argv, "heyndowWrRmMsSU:Z", options, 0)) {
|
||||
case -1: goto opts_done;
|
||||
case '?': return 1;
|
||||
case 'h': usage(); return 0;
|
||||
case 'e': det.extended = 1; break;
|
||||
case 'y': det.date_prec = iso8601_prec_year; break;
|
||||
case 'n': det.date_prec = iso8601_prec_month; break;
|
||||
case 'd': det.date_prec = iso8601_prec_day; break;
|
||||
case 'o': det.date_prec = iso8601_prec_ord; break;
|
||||
case 'w': det.date_prec = iso8601_prec_week; break;
|
||||
case 'W': det.date_prec = iso8601_prec_wday; break;
|
||||
case 'r': det.time_prec = iso8601_prec_hour; break;
|
||||
case 'R': det.time_prec = iso8601_prec_hourfrac; break;
|
||||
case 'm': det.time_prec = iso8601_prec_min; break;
|
||||
case 'M': det.time_prec = iso8601_prec_minfrac; break;
|
||||
case 's': det.time_prec = iso8601_prec_sec; break;
|
||||
case 'S': det.time_prec = iso8601_prec_secfrac; break;
|
||||
case 'Z': det.tz_sec = 0; override_tz = 1; break;
|
||||
case 'U':
|
||||
endp = 0;
|
||||
det.tz_sec = strtol(optarg, &endp, 0);
|
||||
if(!endp || *endp || det.tz_sec <= -86400 || det.tz_sec >= 86400) {
|
||||
fputs("Invalid UTC offset. Must be an integral number of seconds\n"
|
||||
"between -86400 and 86400, exclusive.\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
override_tz = 1;
|
||||
}
|
||||
}
|
||||
|
||||
opts_done:
|
||||
if(optind == argc) {
|
||||
iso8601_now(&date, &det2);
|
||||
if(!override_tz) det.tz_sec = det2.tz_sec;
|
||||
|
||||
iso8601_print(datestr, sizeof(datestr), &date, &det);
|
||||
fputs(datestr, stdout);
|
||||
putc('\n', stdout);
|
||||
} else {
|
||||
for(; optind != argc; ++optind) {
|
||||
if(iso8601_parse(argv[optind], &date, 0, &det2)) {
|
||||
fputs("Couldn't parse date.\n", stderr);
|
||||
ret = 1;
|
||||
continue;
|
||||
}
|
||||
if(!override_tz) det.tz_sec = det2.tz_sec;
|
||||
|
||||
iso8601_print(datestr, sizeof(datestr), &date, &det);
|
||||
fputs(datestr, stdout);
|
||||
putc('\n', stdout);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,43 @@
|
|||
# These are external variables, and shouldn't clash with anything else
|
||||
# isodate
|
||||
# isodate_BUILT
|
||||
#
|
||||
|
||||
build_target libiso8601
|
||||
|
||||
if [ -z ${isodate_BUILT} ]
|
||||
then
|
||||
isodate="obj/isodate"
|
||||
EXTRAS="-std=gnu99 -D_GNU_SOURCE -DAPP_NAME=\"isodate\" \
|
||||
${libiso8601} ${libiso8601_DEP_CFLAGS} ${libiso8601_DEP_LIBS}"
|
||||
|
||||
echo "Building application ${isodate}..."
|
||||
|
||||
do_cmd source src/isodate/build.monolithic || return 1
|
||||
|
||||
MODIFIED=0
|
||||
for test in ${MONOLITHIC_TESTS} ${SRC}
|
||||
do
|
||||
if [ ${test} -nt ${isodate} ]
|
||||
then
|
||||
MODIFIED=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${MODIFIED} -ne 0 ]
|
||||
then
|
||||
echo " Compiling..."
|
||||
|
||||
do_cmd ${CC} ${CFLAGS} -I obj -o "${isodate}" ${SRC} ${EXTRAS} || return 1
|
||||
|
||||
print_success "Application built"
|
||||
else
|
||||
print_success "Application up to date"
|
||||
fi
|
||||
|
||||
isodate_BUILT=1
|
||||
|
||||
fi
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -0,0 +1 @@
|
|||
source src/isodate/build.app
|
|
@ -0,0 +1 @@
|
|||
source src/isodate/build.install-app
|
|
@ -0,0 +1,11 @@
|
|||
build_target isodate
|
||||
|
||||
# make paths (this is for Gentoo in particular)
|
||||
build_dir_tree "${BINDIR}" || return 1
|
||||
|
||||
# install binary
|
||||
echo "Installing binaries into '${BINDIR}'"
|
||||
install_file "${isodate}" "${BINDIR}" 0755 || return 1
|
||||
print_success "Done"
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -0,0 +1,17 @@
|
|||
# These are external variables, and shouldn't clash with anything else
|
||||
# isodate_MONOLITHIC
|
||||
#
|
||||
|
||||
SRC="obj/isodate.c"
|
||||
MONOLITHIC_TESTS="src/isodate/build.app src/isodate/build.monolithic"
|
||||
|
||||
if [ -z "${isodate_MONOLITHIC}" ]
|
||||
then
|
||||
MONOLITHIC_SOURCE="$(find src/isodate/ -name '*.c' | sort)"
|
||||
make_monolithic ${SRC} C || return 1
|
||||
|
||||
isodate_MONOLITHIC=1
|
||||
MONOLITHIC_DOC="${MONOLITHIC_DOC} ${SRC}"
|
||||
fi
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -1 +1 @@
|
|||
c lib libiso8601 iso8601.h
|
||||
lib c libiso8601 iso8601.h
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/* libiso8601/src/libiso8601/000_TopHeader.h
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_libiso8601
|
||||
#define HEADER_libiso8601
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* standard includes, or includes needed for type declarations */
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,27 @@
|
|||
/* libiso8601/src/libiso8601/000_TopSource.c
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
#include "iso8601.h"
|
||||
|
||||
/* Below are all the includes used throughout the library. */
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* Useful define to alleviate typos */
|
||||
#define BILLION (1000000000L)
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,445 @@
|
|||
/* libiso8601/src/libiso8601/100_calc.c
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* CALCULATION ROUTINES ********************************************************
|
||||
|
||||
This file contains calculation routines used internally in the library. Our
|
||||
date format is the number of days elapsed since 0000-001 (so that date would be
|
||||
0, -0001-365 would be -1, etc.). Time is represented as the number of seconds
|
||||
elapsed since midnight at the start of the day. It is a value between 0 and
|
||||
86399 (or 86400 for leap seconds).
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#define DAYS_IN_400_YEARS (146097)
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_isleap(int year)
|
||||
{
|
||||
if(year % 4) return 0;
|
||||
if(year % 100) return 1;
|
||||
if(!(year % 400)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* struct monthcount, _days_in_month_common[], _days_in_month_leap[]
|
||||
*
|
||||
* Tables of the number of days in each month, and the number of days elapsed
|
||||
* since the start of the year for each month.
|
||||
*/
|
||||
struct monthcount {
|
||||
int elapsed, days;
|
||||
};
|
||||
|
||||
static const struct monthcount
|
||||
_days_in_month_common[] = {
|
||||
{ 0, 31 },
|
||||
{ 31, 28 },
|
||||
{ 59, 31 },
|
||||
{ 90, 30 },
|
||||
{ 120, 31 },
|
||||
{ 151, 30 },
|
||||
{ 181, 31 },
|
||||
{ 212, 31 },
|
||||
{ 243, 30 },
|
||||
{ 273, 31 },
|
||||
{ 304, 30 },
|
||||
{ 334, 31 }
|
||||
};
|
||||
|
||||
static const struct monthcount
|
||||
_days_in_month_leap[] = {
|
||||
{ 0, 31 },
|
||||
{ 31, 29 },
|
||||
{ 60, 31 },
|
||||
{ 91, 30 },
|
||||
{ 121, 31 },
|
||||
{ 152, 30 },
|
||||
{ 182, 31 },
|
||||
{ 213, 31 },
|
||||
{ 244, 30 },
|
||||
{ 274, 31 },
|
||||
{ 305, 30 },
|
||||
{ 335, 31 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int
|
||||
_days_in_month(int year, int month)
|
||||
{
|
||||
const struct monthcount* mc;
|
||||
|
||||
if(month < 1 || month > 12) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mc = iso8601_isleap(year) ? _days_in_month_leap : _days_in_month_common;
|
||||
return mc[month - 1].days;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
_to_year(int* year, int* days_left, const struct iso8601_date* date)
|
||||
{
|
||||
div_t qr;
|
||||
int ndays = date->day;
|
||||
|
||||
/* Each 400 years have 97 leap days, giving 365*400+97 = DAYS_IN_400_YEARS
|
||||
days in 400 years */
|
||||
qr = div(ndays, DAYS_IN_400_YEARS);
|
||||
*year = qr.quot * 400;
|
||||
ndays = qr.rem;
|
||||
|
||||
/* ensure that we always end up with between 0 and 146096 days remaining */
|
||||
if(ndays < 0) {
|
||||
ndays += DAYS_IN_400_YEARS;
|
||||
*year -= 400;
|
||||
}
|
||||
|
||||
/* we insert `fake' leap days for years 101, 201, 301 */
|
||||
if(ndays >= 36890) ++ndays;
|
||||
if(ndays >= 73415) ++ndays;
|
||||
if(ndays >= 109940) ++ndays;
|
||||
|
||||
/* each remaining 100 year block has 24 leap days, giving 365*100+24 = 36524
|
||||
days */
|
||||
qr = div(ndays, 36525);
|
||||
*year += qr.quot * 100;
|
||||
ndays = qr.rem;
|
||||
|
||||
/* each 4-year block has 1 leap day, giving 365*4 + 1 = 1461 days */
|
||||
qr = div(ndays, 1461);
|
||||
*year += qr.quot * 4;
|
||||
ndays = qr.rem;
|
||||
|
||||
/* the first year of a 4-year block has 1 leap day, 366 days */
|
||||
if(ndays >= 366) {
|
||||
--ndays; /* pretend to have dealt with leap day */
|
||||
|
||||
/* 365 days per remaining year */
|
||||
qr = div(ndays, 365);
|
||||
*year += qr.quot;
|
||||
ndays = qr.rem;
|
||||
}
|
||||
|
||||
*days_left = ndays;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_to_cal(int* year, int* month, int* day, const struct iso8601_date* date)
|
||||
{
|
||||
const struct monthcount* mc;
|
||||
int ndays;
|
||||
|
||||
/* perform year calulation */
|
||||
_to_year(year, &ndays, date);
|
||||
|
||||
/* now we simply have number of days elapsed since day 001 in `year'. */
|
||||
mc = iso8601_isleap(*year) ? _days_in_month_leap : _days_in_month_common;
|
||||
*month = 1;
|
||||
while(ndays >= mc->days) {
|
||||
*month += 1;
|
||||
ndays -= mc->days;
|
||||
++mc;
|
||||
}
|
||||
*day = ndays + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_to_ord(int* year, int* oday, const struct iso8601_date* date)
|
||||
{
|
||||
int ndays;
|
||||
|
||||
/* perform year calcutation */
|
||||
_to_year(year, &ndays, date);
|
||||
|
||||
/* now we simply have number of days elapsed since day 001 in `year'. */
|
||||
*oday = ndays + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
_weekday_of_year(int year)
|
||||
{
|
||||
int w = 6;
|
||||
|
||||
/* Algorithm notes:
|
||||
* • 0 = sun, 1 = mon, ..., 6 = sat
|
||||
* • 0000-001 is a Saturday, day 6
|
||||
* • every year we pass gives us one additional day (364 is divisible by 7)
|
||||
* • but of course every leap year we pass gives us a further day
|
||||
* • so for every 400 years, we add 497 (400 common years, 97 leap years);
|
||||
* 497 % 7 = 0
|
||||
*/
|
||||
year %= 400;
|
||||
if(year < 0) year += 400; /* end up with between 0-399 years left */
|
||||
w += year; /* excluding leap years, we increase by 1 day a year */
|
||||
w += (year + 3) / 4; /* there is one leap year for every four years */
|
||||
w -= (year - 1) / 100; /* but one less for every century over 0 */
|
||||
w %= 7;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_to_week(int* year, int* week, int* wday,
|
||||
const struct iso8601_date* date)
|
||||
{
|
||||
int ndays, w, has53 = 0;
|
||||
div_t d;
|
||||
|
||||
/* perform year and weekday calculation */
|
||||
_to_year(year, &ndays, date);
|
||||
w = _weekday_of_year(*year);
|
||||
|
||||
/* find out what day jan 1 was; from there, we can find the ISO week and
|
||||
year number */
|
||||
switch(w) {
|
||||
case 4: /* W01 starts XXXY-12-28 */
|
||||
w += 7;
|
||||
has53 = 1; /* years starting Thursday have 53 weeks */
|
||||
break;
|
||||
|
||||
case 5: /* W01 starts XXXZ-01-03 */
|
||||
case 6: /* W01 starts XXXZ-01-02 */
|
||||
break;
|
||||
|
||||
case 0: /* W01 starts XXXZ-01-01 */
|
||||
case 1: /* W01 starts XXXY-12-31 */
|
||||
case 2: /* W01 starts XXXY-12-30 */
|
||||
w += 7; /* for week calculation */
|
||||
break;
|
||||
|
||||
case 3: /* W01 starts XXXY-12-29 */
|
||||
w += 7;
|
||||
if(iso8601_isleap(*year)) has53 = 1; /* leap years starting Wednesday
|
||||
have 53 weeks */
|
||||
}
|
||||
|
||||
/* now we simply add the number of days elapsed since the start of the
|
||||
year, and % 7 */
|
||||
w += ndays;
|
||||
d = div(w, 7); /* w can never be 0 */
|
||||
|
||||
/* do Sunday correction */
|
||||
if(!d.rem) {
|
||||
d.rem = 7;
|
||||
--d.quot;
|
||||
}
|
||||
|
||||
*wday = d.rem;
|
||||
if(d.quot) {
|
||||
if(d.quot == 53 && !has53) {
|
||||
d.quot = 1;
|
||||
*year += 1;
|
||||
}
|
||||
*week = d.quot;
|
||||
} else {
|
||||
*year -= 1;
|
||||
switch(_weekday_of_year(*year)) {
|
||||
case 3:
|
||||
*week = iso8601_isleap(*year) ? 53 : 52;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
*week = 53;
|
||||
break;
|
||||
|
||||
default:
|
||||
*week = 52;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
_from_year(struct iso8601_date* date, int year)
|
||||
{
|
||||
div_t qr;
|
||||
|
||||
/* check for range errors */
|
||||
if(year < -5879609 || year > 5879609) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Each 400 years have 97 leap days, giving 365*400+97 = DAYS_IN_400_YEARS
|
||||
days in 400 years */
|
||||
qr = div(year, 400);
|
||||
date->day = qr.quot * DAYS_IN_400_YEARS;
|
||||
year = qr.rem;
|
||||
|
||||
/* ensure we have between 0 and 399 years */
|
||||
if(year < 0) {
|
||||
date->day -= DAYS_IN_400_YEARS;
|
||||
year += 400;
|
||||
}
|
||||
|
||||
/* excluding leap days, there are 365 days per year */
|
||||
date->day += 365 * year;
|
||||
date->day += (year + 3) / 4; /* one leap year for every four years */
|
||||
date->day -= (year - 1) / 100; /* but one less for every century over 0 */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_from_cal(struct iso8601_date* date, int year, int month, int day)
|
||||
{
|
||||
const struct monthcount* mc;
|
||||
|
||||
/* check for domain errors */
|
||||
mc = iso8601_isleap(year) ? _days_in_month_leap : _days_in_month_common;
|
||||
if(month < 1 || month > 12 || day < 1 || day > mc[month - 1].days) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* perform year calculation */
|
||||
if(_from_year(date, year)) return -1;
|
||||
|
||||
/* now get number of days elapsed up to start of month */
|
||||
date->day += mc[month - 1].elapsed;
|
||||
|
||||
/* and add number of days elapsed sinced start of month */
|
||||
date->day += day - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_from_ord(struct iso8601_date* date, int year, int oday)
|
||||
{
|
||||
/* check for domain errors */
|
||||
if(oday < 1 || oday > (iso8601_isleap(year) ? 366 : 365)) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* perform year calculation */
|
||||
if(_from_year(date, year)) return -1;
|
||||
|
||||
/* now simply add number of days elapsed this year */
|
||||
date->day += oday - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_from_week(struct iso8601_date* date, int isoyear, int week, int wday)
|
||||
{
|
||||
int day1off, maxwk;
|
||||
|
||||
/* compute year part */
|
||||
_from_year(date, isoyear);
|
||||
|
||||
/* 400-year cycle; ensure we're between 0-400 years */
|
||||
isoyear %= 400;
|
||||
if(isoyear < 0) isoyear += 400;
|
||||
|
||||
/* domain check */
|
||||
maxwk = (((isoyear % 7) == 52) || ((isoyear % 28) == 24)) ? 53 : 52;
|
||||
if(wday < 1 || wday > 7 || week < 1 || week > maxwk) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Algorithm notes:
|
||||
* We now compute the offset between the start day of the ISO year and
|
||||
* the start day of the real year. Year 0000 starts on a Saturday, meaning
|
||||
* the ISO year 0000 starts on 0000-003 (offset of +2 days). Each year
|
||||
* reduces the offset by one day, and each leap year reduces it by a
|
||||
* further day; the offset wraps from -3 to +3.
|
||||
*/
|
||||
day1off = 2 - isoyear; /* reduce offset by 1 for each year */
|
||||
day1off += (isoyear - 1) / 100; /* cancel out 1 leap year for each century
|
||||
past the first */
|
||||
day1off -= (isoyear + 3) / 4; /* 1 leap year every 4 years */
|
||||
day1off %= 7;
|
||||
if(day1off < -3) day1off += 7;
|
||||
|
||||
/* now simply add in the day offset and days/weeks elapsed */
|
||||
date->day += day1off + (week - 1) * 7 + wday - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_to_clocktime(int* hour, int* min, int* sec,
|
||||
const struct iso8601_date* date)
|
||||
{
|
||||
div_t qr;
|
||||
|
||||
/* special case: leap second */
|
||||
if(date->sec == 86400) {
|
||||
*hour = 23;
|
||||
*min = 59;
|
||||
*sec = 60;
|
||||
return;
|
||||
}
|
||||
|
||||
/* normal case */
|
||||
qr = div(date->sec, 3600);
|
||||
*hour = qr.quot;
|
||||
qr = div(qr.rem, 60);
|
||||
*min = qr.quot;
|
||||
*sec = qr.rem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_from_clocktime(struct iso8601_date* date, int hour, int min, int sec)
|
||||
{
|
||||
/* special case: leap second */
|
||||
if(hour == 23 && min == 59 && sec == 60) {
|
||||
date->sec = 86400;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* domain check */
|
||||
if(hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 || sec > 59) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* normal calculation */
|
||||
date->sec = hour * 3600 + min * 60 + sec;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,216 @@
|
|||
/* libiso8601/src/libiso8601/100_leap.c
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* leap_second_days_table[]
|
||||
* This is a sorted array of days (in libiso8601 format) on which a positive
|
||||
* leap second occurred. This table is built in to the library, but may be
|
||||
* overridden at runtime by changing what ‘leap_second_days’ points to. There
|
||||
* should be no other references to this table, therefore.
|
||||
*/
|
||||
static int
|
||||
leap_second_days_table[] = {
|
||||
720439, /* 1972-06-30 */
|
||||
720623, /* 1972-12-31 */
|
||||
720988, /* 1973-12-31 */
|
||||
721353, /* 1974-12-31 */
|
||||
721718, /* 1975-12-31 */
|
||||
722084, /* 1976-12-31 */
|
||||
722449, /* 1977-12-31 */
|
||||
722814, /* 1978-12-31 */
|
||||
723179, /* 1979-12-31 */
|
||||
723726, /* 1981-06-30 */
|
||||
724091, /* 1982-06-30 */
|
||||
724456, /* 1983-06-30 */
|
||||
725187, /* 1985-06-30 */
|
||||
726101, /* 1987-12-31 */
|
||||
726832, /* 1989-12-31 */
|
||||
727197, /* 1990-12-31 */
|
||||
727744, /* 1992-06-30 */
|
||||
728109, /* 1993-06-30 */
|
||||
728474, /* 1994-06-30 */
|
||||
729023, /* 1995-12-31 */
|
||||
729570, /* 1997-06-30 */
|
||||
730119, /* 1998-12-31 */
|
||||
732676, /* 2005-12-31 */
|
||||
733772, /* 2008-12-31 */
|
||||
735049, /* 2012-06-30 */
|
||||
736144, /* 2015-06-30 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* leap_second_days[], leap_second_days_num
|
||||
* Pointer to an array (and number of elements in the array) representing the
|
||||
* table of positive leap seconds. The array is sorted and contains libiso8601
|
||||
* day numbers of days with positive leap seconds.
|
||||
*/
|
||||
static int*
|
||||
leap_second_days = leap_second_days_table;
|
||||
static int
|
||||
leap_second_days_num = sizeof(leap_second_days_table) / sizeof(int);
|
||||
|
||||
|
||||
|
||||
/* iso8601_seconds_leap()
|
||||
* Returns the number of seconds that elapse on a given date, which requires us
|
||||
* to search the table of leap seconds to see if we need to return a special
|
||||
* case.
|
||||
*/
|
||||
int
|
||||
iso8601_seconds_leap(const struct iso8601_date* date)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < leap_second_days_num; ++i) {
|
||||
if(leap_second_days[i] == date->day) return 86401;
|
||||
}
|
||||
return 86400;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* _leap_elapsed_day()
|
||||
* Returns the number of leap seconds that have elapsed between ‘sday’ (start
|
||||
* day) and ‘eday’ (end day), both in libiso8601 format.
|
||||
*/
|
||||
static int
|
||||
_leap_elapsed_day(int sday, int eday)
|
||||
{
|
||||
int spos, epos;
|
||||
|
||||
for(spos = 0; spos < leap_second_days_num; ++spos) {
|
||||
if(sday <= leap_second_days[spos]) break;
|
||||
}
|
||||
for(epos = 0; epos < leap_second_days_num; ++epos) {
|
||||
if(eday <= leap_second_days[epos]) break;
|
||||
}
|
||||
|
||||
return epos - spos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* iso8601_leap_elapsed()
|
||||
* Wrapper around _leap_elapsed_day().
|
||||
*/
|
||||
int
|
||||
iso8601_leap_elapsed(const struct iso8601_date* start,
|
||||
const struct iso8601_date* end)
|
||||
{
|
||||
return _leap_elapsed_day(start->day, end->day);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* leap_table_free_old
|
||||
* If set, then when we update the leap table, we should free the old array.
|
||||
* Initially clear so that we don't free our static built-in table.
|
||||
*/
|
||||
static int leap_table_free_old = 0;
|
||||
|
||||
|
||||
|
||||
/* iso8601_leap_table_set()
|
||||
* Switch to using a new table of leap seconds, possibly freeing the old one.
|
||||
*/
|
||||
void
|
||||
iso8601_leap_table_set(int* new_table, int new_size)
|
||||
{
|
||||
if(leap_table_free_old) free(leap_second_days);
|
||||
leap_table_free_old = 0;
|
||||
|
||||
leap_second_days = new_table;
|
||||
leap_second_days_num = new_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* leap_table_signature
|
||||
* The first 8 bytes of a leap second table must match this string, otherwise
|
||||
* the file is taken not to be of the correct format.
|
||||
*/
|
||||
static const char*
|
||||
leap_table_signature = "/O9PdPZI";
|
||||
|
||||
|
||||
|
||||
/* iso8601_leap_table_load()
|
||||
* Loads a new table of leap seconds from disk. Ensures the signature of the
|
||||
* given file matches ‘leap_table_signature’, and does some basic sanity
|
||||
* checking (file in sorted order etc.).
|
||||
*/
|
||||
int
|
||||
iso8601_leap_table_load(const char* fname)
|
||||
{
|
||||
struct stat st;
|
||||
int fd, saved_errno, i, new_size, * days = 0;
|
||||
char buf[12];
|
||||
|
||||
if(!fname) fname = DEFAULT_LEAP_TABLE;
|
||||
|
||||
if(stat(fname, &st)) return -1;
|
||||
if(st.st_size < 12) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if(fd == -1) return -1;
|
||||
|
||||
if(TEMP_FAILURE_RETRY( read(fd, buf, 12) ) != 12) goto outerr;
|
||||
if(memcmp(buf, leap_table_signature, 8)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define GET_UINT32(_from) ( \
|
||||
( ((uint8_t*)_from)[0] << 24 ) | \
|
||||
( ((uint8_t*)_from)[1] << 16 ) | \
|
||||
( ((uint8_t*)_from)[2] << 8 ) | \
|
||||
( ((uint8_t*)_from)[3] ) \
|
||||
)
|
||||
|
||||
new_size = GET_UINT32(buf + 8);
|
||||
if((12 + new_size * 4) != st.st_size) {
|
||||
errno = EINVAL;
|
||||
goto outerr;
|
||||
}
|
||||
|
||||
days = malloc(sizeof(int) * new_size);
|
||||
if(!days) goto outerr;
|
||||
|
||||
for(i = 0; i < new_size; ++i) {
|
||||
if(TEMP_FAILURE_RETRY( read(fd, buf, 4) ) != 4) goto outerr;
|
||||
days[i] = GET_UINT32(buf);
|
||||
if(i && days[i] <= days[i - 1]) {
|
||||
errno = EINVAL;
|
||||
goto outerr;
|
||||
}
|
||||
}
|
||||
|
||||
TEMP_FAILURE_RETRY( close(fd) );
|
||||
iso8601_leap_table_set(days, new_size);
|
||||
leap_table_free_old = 1;
|
||||
return 0;
|
||||
|
||||
#undef GET_UINT32
|
||||
|
||||
outerr:
|
||||
saved_errno = errno;
|
||||
free(days);
|
||||
TEMP_FAILURE_RETRY( close(fd) );
|
||||
errno = saved_errno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,138 @@
|
|||
/* libiso8601/src/libiso8601/100_types.h
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. 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.
|
||||
\ingroup parser
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*! \brief Time precision.
|
||||
\ingroup parser
|
||||
|
||||
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 {
|
||||
/*! \brief Don't display date. */
|
||||
iso8601_prec_none,
|
||||
/*! \brief Display integer part of hour. */
|
||||
iso8601_prec_hour,
|
||||
/*! \brief Display hour and integer part of minute. */
|
||||
iso8601_prec_min,
|
||||
/*! \brief Display hour, minute and integer part of second. */
|
||||
iso8601_prec_sec,
|
||||
/*! \brief Display hour and fractional part of hour. */
|
||||
iso8601_prec_hourfrac,
|
||||
/*! \brief Display hour, minute and fractional part of minute. */
|
||||
iso8601_prec_minfrac,
|
||||
/*! \brief Display hour, minute, second and nanoseconds. */
|
||||
iso8601_prec_secfrac
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*! \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 (\ref iso8601_date_prec). */
|
||||
uint8_t date_prec;
|
||||
|
||||
/*! \brief Time precision (\ref 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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*! \brief Short period elapsed time.
|
||||
|
||||
This structure contains the details of an elapsed time period, split into
|
||||
seconds and nanoseconds. None of its components can ever be negative. This is
|
||||
only capable of representing short (compared to struct iso8601_date's range)
|
||||
periods of up to approximately 136 years.
|
||||
|
||||
*/
|
||||
struct iso8601_elapsed {
|
||||
/*! \brief Number of seconds. */
|
||||
uint32_t sec;
|
||||
/*! \brief Number of nanoseconds (0 to 999999999). */
|
||||
uint32_t nsec;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4:syntax=ch.doxygen
|
||||
*/
|
|
@ -1,24 +1,25 @@
|
|||
/* 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
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601_date* latest,
|
||||
struct iso8601_details* details)
|
||||
int
|
||||
iso8601_parse(const char* str, struct iso8601_date* earliest,
|
||||
struct iso8601_date* latest, struct iso8601_details* details)
|
||||
{
|
||||
enum {
|
||||
state_none,
|
||||
state_year, // e.g. `2006' or `2006123'
|
||||
state_date2, // 2nd component of date, e.g. `2006-' or `2006-1'
|
||||
state_day, // e.g. `2006-01-' or `2006-01-01'
|
||||
state_week_basic, // e.g. `2006W' or `2006W123'
|
||||
state_week_extended, // e.g. `2006-W' or `2006-W31'
|
||||
state_week_day, // e.g. `2006-W31-'
|
||||
state_week_done, // `2006-W31-1'
|
||||
state_year, /* e.g. `2006' or `2006123' */
|
||||
state_date2, /* 2nd component of date, e.g. `2006-' or `2006-1' */
|
||||
state_day, /* e.g. `2006-01-' or `2006-01-01' */
|
||||
state_week_basic, /* e.g. `2006W' or `2006W123' */
|
||||
state_week_extended, /* e.g. `2006-W' or `2006-W31' */
|
||||
state_week_day, /* e.g. `2006-W31-' */
|
||||
state_week_done, /* `2006-W31-1' */
|
||||
state_time_basic,
|
||||
state_time_hour,
|
||||
state_time_min,
|
||||
|
@ -34,37 +35,41 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
|
||||
div_t qr;
|
||||
char ch;
|
||||
int num = 0, neg = 0, dig = 0, tz_neg = 0, nsec = -1, nsec_dig = -1;
|
||||
int y = 0, m = -1, d = -1, w = -1, wd = -1, hour = -1, min = -1, sec = -1, tz_sec = 0;
|
||||
int num = 0, neg = 0, dig = 0, tz_neg = 0, nsec = -1, nsec_dig = -1,
|
||||
leap_sec_req = 0, y = 0, m = -1, d = -1, w = -1, wd = -1, hour = -1,
|
||||
min = -1, sec = -1, tz_sec = 0;
|
||||
double frac;
|
||||
struct iso8601_elapsed elapsed;
|
||||
|
||||
if(earliest) memset(earliest, 0, sizeof(struct iso8601_date));
|
||||
if(latest) memset(latest, 0, sizeof(struct iso8601_date));
|
||||
if(details) memset(details, 0, sizeof(struct iso8601_details));
|
||||
|
||||
#define ERROR_IF(x) do { \
|
||||
if(x) { \
|
||||
return -1; \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#define INCNUM() do { \
|
||||
++dig; \
|
||||
num *= 10; \
|
||||
num += ch - '0'; \
|
||||
if(num > 1000000000) { \
|
||||
errno = EDOM; \
|
||||
return -1; \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#define ERROR_IF(x) do { \
|
||||
if(x) { \
|
||||
errno = EILSEQ; \
|
||||
return -1; \
|
||||
} \
|
||||
ERROR_IF(num > BILLION); \
|
||||
}while(0)
|
||||
|
||||
while(1) {
|
||||
ch = *str++;
|
||||
if(isspace(ch)) ch = 0; /* simplify switch */
|
||||
|
||||
switch(state) {
|
||||
case state_none:
|
||||
switch(ch) {
|
||||
case 0:
|
||||
/* ignore whitespace */
|
||||
ERROR_IF(!*(str - 1));
|
||||
break;
|
||||
|
||||
case '0' ... '9':
|
||||
state = state_year;
|
||||
num = ch - '0';
|
||||
|
@ -77,8 +82,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
break;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -88,6 +92,50 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
INCNUM();
|
||||
break;
|
||||
|
||||
case 0:
|
||||
case 'T':
|
||||
switch(dig) {
|
||||
case 4: /* YYYY */
|
||||
y = num;
|
||||
break;
|
||||
|
||||
case 6: /* YYYYMM */
|
||||
qr = div(num, 100);
|
||||
y = qr.quot;
|
||||
m = qr.rem;
|
||||
break;
|
||||
|
||||
case 7: /* YYYYJJJ */
|
||||
qr = div(num, 1000);
|
||||
y = qr.quot;
|
||||
d = qr.rem;
|
||||
break;
|
||||
|
||||
case 8: /* YYYYMMDD */
|
||||
qr = div(num, 10000);
|
||||
y = qr.quot;
|
||||
qr = div(qr.rem, 100);
|
||||
m = qr.quot;
|
||||
d = qr.rem;
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_IF(1);
|
||||
}
|
||||
|
||||
switch(ch) {
|
||||
case 0:
|
||||
goto done;
|
||||
|
||||
case 'T':
|
||||
ERROR_IF(!d);
|
||||
state = state_time_basic;
|
||||
num = 0;
|
||||
dig = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
ERROR_IF(!dig);
|
||||
y = num;
|
||||
|
@ -97,52 +145,15 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
if(details) details->extended = 1;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
case 'T':
|
||||
switch(dig) {
|
||||
case 4:
|
||||
ERROR_IF(ch);
|
||||
y = num;
|
||||
goto done;
|
||||
|
||||
case 6:
|
||||
ERROR_IF(ch);
|
||||
qr = div(num, 100);
|
||||
y = qr.quot;
|
||||
m = qr.rem;
|
||||
goto done;
|
||||
|
||||
case 7:
|
||||
qr = div(num, 1000);
|
||||
y = qr.quot;
|
||||
d = qr.rem;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
qr = div(num, 10000);
|
||||
y = qr.quot;
|
||||
qr = div(qr.rem, 100);
|
||||
m = qr.quot;
|
||||
d = qr.rem;
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
if(!ch) goto done;
|
||||
|
||||
state = state_time_basic;
|
||||
num = 0;
|
||||
dig = 0;
|
||||
break;
|
||||
|
||||
case 'W':
|
||||
y = num;
|
||||
num = 0;
|
||||
dig = 0;
|
||||
state = state_week_basic;
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -161,20 +172,18 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
break;
|
||||
|
||||
case 'W':
|
||||
if(dig) {
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
ERROR_IF(dig);
|
||||
state = state_week_extended;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
switch(dig) {
|
||||
case 2: m = num; goto done;
|
||||
case 3: d = num; goto done;
|
||||
case 2: m = num; break;
|
||||
case 3: d = num; break;
|
||||
default: ERROR_IF(1);
|
||||
}
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
|
||||
goto done;
|
||||
|
||||
case 'T':
|
||||
ERROR_IF(dig != 3);
|
||||
|
@ -185,8 +194,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
break;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -200,16 +208,21 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
case 'T':
|
||||
ERROR_IF(dig != 2);
|
||||
d = num;
|
||||
if(!ch) goto done;
|
||||
|
||||
num = 0;
|
||||
dig = 0;
|
||||
state = state_time_hour;
|
||||
switch(ch) {
|
||||
case 0:
|
||||
goto done;
|
||||
|
||||
case 'T':
|
||||
num = 0;
|
||||
dig = 0;
|
||||
state = state_time_hour;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -223,17 +236,19 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
switch(dig) {
|
||||
case 2:
|
||||
w = num;
|
||||
goto done;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
qr = div(num, 10);
|
||||
w = qr.quot;
|
||||
wd = qr.rem;
|
||||
goto done;
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_IF(1);
|
||||
}
|
||||
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
goto done;
|
||||
|
||||
case 'T':
|
||||
ERROR_IF(dig != 3);
|
||||
|
@ -247,8 +262,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
break;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -264,8 +278,10 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
w = num;
|
||||
num = 0;
|
||||
dig = 0;
|
||||
if(!ch) goto done;
|
||||
state = state_week_day;
|
||||
switch(ch) {
|
||||
case 0: goto done;
|
||||
case '-': state = state_week_day; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -277,12 +293,19 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
break;
|
||||
|
||||
case state_week_done:
|
||||
if(!ch) goto done;
|
||||
ERROR_IF(ch != 'T');
|
||||
switch(ch) {
|
||||
case 0:
|
||||
goto done;
|
||||
|
||||
num = 0;
|
||||
dig = 0;
|
||||
state = state_time_hour;
|
||||
case 'T':
|
||||
num = 0;
|
||||
dig = 0;
|
||||
state = state_time_hour;
|
||||
break;
|
||||
|
||||
default:
|
||||
ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case state_time_basic:
|
||||
|
@ -311,8 +334,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
break;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
ERROR_IF(1);
|
||||
}
|
||||
|
||||
num = 0;
|
||||
|
@ -324,7 +346,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
case 'Z': state = state_tz_utc; break;
|
||||
case '+': state = state_tz_basic; break;
|
||||
case '-': tz_neg = 1; state = state_tz_basic; break;
|
||||
default: errno = EILSEQ; return -1;
|
||||
default: ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -346,7 +368,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
case 'Z': state = state_tz_utc; break;
|
||||
case '+': state = state_tz_hour; break;
|
||||
case '-': tz_neg = 1; state = state_tz_hour; break;
|
||||
default: errno = EILSEQ; return -1;
|
||||
default: ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -368,7 +390,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
case 'Z': state = state_tz_utc; break;
|
||||
case '+': state = state_tz_hour; break;
|
||||
case '-': tz_neg = 1; state = state_tz_hour; break;
|
||||
default: errno = EILSEQ; return -1;
|
||||
default: ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -389,7 +411,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
case 'Z': state = state_tz_utc; break;
|
||||
case '+': state = state_tz_hour; break;
|
||||
case '-': tz_neg = 1; state = state_tz_hour; break;
|
||||
default: errno = EILSEQ; return -1;
|
||||
default: ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -416,7 +438,8 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
case '-':
|
||||
tz_neg = -1;
|
||||
case '+':
|
||||
state = (state == state_time_nsec_basic) ? state_tz_basic : state_tz_hour;
|
||||
state = (state == state_time_nsec_basic) ?
|
||||
state_tz_basic : state_tz_hour;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -450,14 +473,13 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
break;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
ERROR_IF(1);
|
||||
}
|
||||
|
||||
goto done;
|
||||
|
||||
default:
|
||||
errno = EILSEQ;
|
||||
return -1;
|
||||
ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -479,7 +501,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
switch(ch) {
|
||||
case ':': state = state_tz_min; break;
|
||||
case 0: goto done;
|
||||
default: errno = EILSEQ; return -1;
|
||||
default: ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -497,7 +519,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
switch(ch) {
|
||||
case ':': state = state_tz_sec; break;
|
||||
case 0: goto done;
|
||||
default: errno = EILSEQ; return -1;
|
||||
default: ERROR_IF(1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -515,47 +537,48 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
|||
}
|
||||
}
|
||||
|
||||
#undef ERROR_IF
|
||||
#undef INCNUM
|
||||
|
||||
done:
|
||||
--str;
|
||||
while(*str) ERROR_IF(!isspace(*str++));
|
||||
|
||||
if(neg) y *= -1;
|
||||
if(tz_neg) tz_sec *= -1;
|
||||
|
||||
if(m != -1) {
|
||||
if(d == -1) {
|
||||
if(earliest && iso8601_from_cal(earliest, y, m, 1)) return -1;
|
||||
if(latest && iso8601_from_cal(latest, y, m, _days_in_month(y, m))) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_cal(earliest, y, m, 1));
|
||||
ERROR_IF(latest && iso8601_from_cal(latest, y, m,
|
||||
_days_in_month(y, m)));
|
||||
if(details) details->date_prec = iso8601_prec_month;
|
||||
|
||||
} else {
|
||||
if(earliest && iso8601_from_cal(earliest, y, m, d)) return -1;
|
||||
if(latest && iso8601_from_cal(latest, y, m, d)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_cal(earliest, y, m, d));
|
||||
ERROR_IF(latest && iso8601_from_cal(latest, y, m, d));
|
||||
if(details) details->date_prec = iso8601_prec_day;
|
||||
|
||||
}
|
||||
|
||||
} else if(d != -1) {
|
||||
if(earliest && iso8601_from_ord(earliest, y, d)) return -1;
|
||||
if(latest && iso8601_from_ord(latest, y, d)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_ord(earliest, y, d));
|
||||
ERROR_IF(latest && iso8601_from_ord(latest, y, d));
|
||||
if(details) details->date_prec = iso8601_prec_ord;
|
||||
|
||||
} else if(w != -1) {
|
||||
if(wd == -1) {
|
||||
if(earliest && iso8601_from_week(earliest, y, w, 1)) return -1;
|
||||
if(latest && iso8601_from_week(latest, y, w, 7)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_week(earliest, y, w, 1));
|
||||
ERROR_IF(latest && iso8601_from_week(latest, y, w, 7));
|
||||
if(details) details->date_prec = iso8601_prec_week;
|
||||
|
||||
} else {
|
||||
if(earliest && iso8601_from_week(earliest, y, w, wd)) return -1;
|
||||
if(latest && iso8601_from_week(latest, y, w, wd)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_week(earliest, y, w, wd));
|
||||
ERROR_IF(latest && iso8601_from_week(latest, y, w, wd));
|
||||
if(details) details->date_prec = iso8601_prec_wday;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
if(earliest && iso8601_from_cal(earliest, y, 1, 1)) return -1;
|
||||
if(latest && iso8601_from_cal(latest, y, 12, 31)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_cal(earliest, y, 1, 1));
|
||||
ERROR_IF(latest && iso8601_from_cal(latest, y, 12, 31));
|
||||
if(details) details->date_prec = iso8601_prec_year;
|
||||
|
||||
}
|
||||
|
@ -563,13 +586,18 @@ done:
|
|||
if(nsec_dig != -1) while(nsec_dig++ < 9) nsec *= 10;
|
||||
|
||||
if(hour == -1) {
|
||||
if(earliest && iso8601_from_clocktime(earliest, 0, 0, 0)) return -1;
|
||||
if(latest && iso8601_from_clocktime(latest, 24, 0, 0)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_clocktime(earliest, 0, 0, 0));
|
||||
ERROR_IF(latest && iso8601_from_clocktime(latest, 23, 59, 59));
|
||||
if(details) details->time_prec = iso8601_prec_none;
|
||||
|
||||
} else if(sec != -1) {
|
||||
if(earliest && iso8601_from_clocktime(earliest, hour, min, sec)) return -1;
|
||||
if(latest && iso8601_from_clocktime(latest, hour, min, sec)) return -1;
|
||||
if(sec == 60) {
|
||||
leap_sec_req++;
|
||||
sec = 59;
|
||||
}
|
||||
|
||||
ERROR_IF(earliest && iso8601_from_clocktime(earliest, hour, min, sec));
|
||||
ERROR_IF(latest && iso8601_from_clocktime(latest, hour, min, sec));
|
||||
|
||||
if(nsec_dig == -1) {
|
||||
if(latest) latest->nsec = 999999999;
|
||||
|
@ -584,8 +612,9 @@ done:
|
|||
|
||||
} else if(min != -1) {
|
||||
if(nsec_dig == -1) {
|
||||
if(earliest && iso8601_from_clocktime(earliest, hour, min, 0)) return -1;
|
||||
if(latest && iso8601_from_clocktime(latest, hour, min, 59)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_clocktime(earliest,
|
||||
hour, min, 0));
|
||||
ERROR_IF(latest && iso8601_from_clocktime(latest, hour, min, 59));
|
||||
if(latest) latest->nsec = 999999999;
|
||||
if(details) details->time_prec = iso8601_prec_min;
|
||||
|
||||
|
@ -593,9 +622,10 @@ done:
|
|||
frac = nsec * 60.0 / 1e9;
|
||||
sec = (int)frac;
|
||||
nsec = (frac - sec) * 1e9;
|
||||
if(earliest && iso8601_from_clocktime(earliest, hour, min, sec)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_clocktime(earliest,
|
||||
hour, min, sec));
|
||||
if(earliest) earliest->nsec = nsec;
|
||||
if(latest && iso8601_from_clocktime(latest, hour, min, sec)) return -1;
|
||||
ERROR_IF(latest && iso8601_from_clocktime(latest, hour, min, sec));
|
||||
if(latest) latest->nsec = nsec;
|
||||
if(details) details->time_prec = iso8601_prec_minfrac;
|
||||
|
||||
|
@ -603,8 +633,8 @@ done:
|
|||
|
||||
} else {
|
||||
if(nsec_dig == -1) {
|
||||
if(earliest && iso8601_from_clocktime(earliest, hour, 0, 0)) return -1;
|
||||
if(latest && iso8601_from_clocktime(latest, hour, 59, 59)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_clocktime(earliest, hour, 0, 0));
|
||||
ERROR_IF(latest && iso8601_from_clocktime(latest, hour, 59, 59));
|
||||
if(latest) latest->nsec = 999999999;
|
||||
if(details) details->time_prec = iso8601_prec_hour;
|
||||
|
||||
|
@ -615,9 +645,10 @@ done:
|
|||
frac *= 60;
|
||||
sec = (int)frac;
|
||||
nsec = (frac - sec) * 1e9;
|
||||
if(earliest && iso8601_from_clocktime(earliest, hour, min, sec)) return -1;
|
||||
ERROR_IF(earliest && iso8601_from_clocktime(earliest,
|
||||
hour, min, sec));
|
||||
if(earliest) earliest->nsec = nsec;
|
||||
if(latest && iso8601_from_clocktime(latest, hour, min, sec)) return -1;
|
||||
ERROR_IF(latest && iso8601_from_clocktime(latest, hour, min, sec));
|
||||
if(latest) latest->nsec = nsec;
|
||||
if(details) details->time_prec = iso8601_prec_hourfrac;
|
||||
|
||||
|
@ -625,11 +656,41 @@ done:
|
|||
|
||||
}
|
||||
|
||||
/* correct for timezone offset (note trickery to end up at 23:59:60 iff a leap second was
|
||||
* requested), and ensure that any leap second requested was a valid leap second. */
|
||||
if(details) details->tz_sec = tz_sec;
|
||||
if(tz_sec && earliest) iso8601_add_seconds(earliest, -tz_sec);
|
||||
if(tz_sec && latest) iso8601_add_seconds(latest, -tz_sec);
|
||||
if(tz_sec && earliest) {
|
||||
elapsed.sec = leap_sec_req + tz_sec;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_subtract_elapsed(earliest, &elapsed);
|
||||
}
|
||||
if(tz_sec && latest) {
|
||||
elapsed.sec = leap_sec_req + tz_sec;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_subtract_elapsed(latest, &elapsed);
|
||||
}
|
||||
if(leap_sec_req) {
|
||||
ERROR_IF(earliest && earliest->sec != 86400);
|
||||
ERROR_IF(latest && latest->sec != 86400);
|
||||
}
|
||||
ERROR_IF(earliest && iso8601_invalid(earliest));
|
||||
ERROR_IF(latest && iso8601_invalid(latest));
|
||||
|
||||
return 0;
|
||||
#undef ERROR_IF
|
||||
#undef INCNUM
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_invalid(const struct iso8601_date* date)
|
||||
{
|
||||
return date->nsec < 0
|
||||
|| date->nsec >= BILLION
|
||||
|| date->sec < 0
|
||||
|| date->sec >= iso8601_seconds_leap(date)
|
||||
;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/* libiso8601/src/libiso8601/200_parser.h
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*! \defgroup parser Parsing, printing 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. Whitespace will be stripped.
|
||||
\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.
|
||||
\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.
|
||||
|
||||
*/
|
||||
int iso8601_parse(const char* str, struct iso8601_date* earliest,
|
||||
struct iso8601_date* latest, struct iso8601_details* details)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull(1),warn_unused_result))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Print ISO8601 date/time into string.
|
||||
|
||||
\param str Pointer to buffer into which result is written.
|
||||
\param amt Number of bytes in \a str.
|
||||
\param date Date to print.
|
||||
\param details Formatting details (may be 0).
|
||||
\returns Pointer to buffer (\a str).
|
||||
|
||||
Formats and prints an ISO8601 date, optionally using the details in \a details.
|
||||
Will always return a null-terminated result, even if that means truncating the
|
||||
output to fit the buffer.
|
||||
|
||||
*/
|
||||
char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||
const struct iso8601_details* details)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull(1,3)))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Validate ISO8601 date/time.
|
||||
|
||||
\param date The date to validate.
|
||||
\retval -1 if not valid.
|
||||
\retval 0 if valid.
|
||||
|
||||
Checks the details of \a date to ensure that they are sensible. This involves
|
||||
checking that \a sec is in the range 0 to 86399 (or 86400 if there is a leap
|
||||
second), and that \a nsec is in the range 0 to 999999999.
|
||||
|
||||
*/
|
||||
int iso8601_invalid(const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*!@}*/
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4:syntax=ch.doxygen
|
||||
*/
|
|
@ -1,13 +1,18 @@
|
|||
/* libiso8601/src/libiso8601/print.c
|
||||
/* libiso8601/src/libiso8601/200_print.c
|
||||
*
|
||||
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv2. See file COPYING or
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static const struct iso8601_details _default_details = {
|
||||
/* _default_details
|
||||
* If the user doesn't pass precision details to iso8601_print(), these are
|
||||
* used instead.
|
||||
*/
|
||||
static const struct iso8601_details
|
||||
_default_details = {
|
||||
iso8601_prec_day,
|
||||
iso8601_prec_sec,
|
||||
1,
|
||||
|
@ -16,21 +21,30 @@ static const struct iso8601_details _default_details = {
|
|||
|
||||
|
||||
|
||||
void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||
char*
|
||||
iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||
const struct iso8601_details* details)
|
||||
{
|
||||
int y, m, d, ret = 0, extended;
|
||||
struct iso8601_date dttz;
|
||||
double frac;
|
||||
char* str_orig;
|
||||
struct iso8601_elapsed elapsed;
|
||||
|
||||
// use default details if none provided
|
||||
str_orig = str;
|
||||
|
||||
/* use default details if none provided */
|
||||
if(!details) details = &_default_details;
|
||||
|
||||
// adjust output for timezone
|
||||
/* adjust output for timezone */
|
||||
dttz = *date;
|
||||
if(details->tz_sec) iso8601_add_seconds(&dttz, details->tz_sec);
|
||||
if(details->tz_sec) {
|
||||
elapsed.sec = details ? details->tz_sec : 0;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_add_elapsed(&dttz, &elapsed);
|
||||
}
|
||||
|
||||
// determine whether or not to force extended output
|
||||
/* determine whether or not to force extended output */
|
||||
iso8601_to_cal(&y, &m, &d, &dttz);
|
||||
extended = details->extended || y < 0 || y > 9999;
|
||||
|
||||
|
@ -38,40 +52,45 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
|||
case iso8601_prec_year:
|
||||
if(y < 0) snprintf(str, amt, "%05d", y);
|
||||
else snprintf(str, amt, "%04d", y);
|
||||
return;
|
||||
return str_orig;
|
||||
|
||||
case iso8601_prec_month:
|
||||
if(y < 0) snprintf(str, amt, "%05d-%02d", y, m);
|
||||
else snprintf(str, amt, extended ? "%04d-%02d" : "%04d%02d", y, m);
|
||||
return;
|
||||
return str_orig;
|
||||
|
||||
case iso8601_prec_day:
|
||||
if(y < 0) ret = snprintf(str, amt, "%05d-%02d-%02d", y, m, d);
|
||||
else ret = snprintf(str, amt, extended ? "%04d-%02d-%02d" : "%04d%02d%02d", y, m, d);
|
||||
else ret = snprintf(str, amt, extended ?
|
||||
"%04d-%02d-%02d" : "%04d%02d%02d", y, m, d);
|
||||
break;
|
||||
|
||||
case iso8601_prec_ord:
|
||||
iso8601_to_ord(&y, &d, &dttz);
|
||||
if(y < 0) ret = snprintf(str, amt, "%05d-%03d", y, d);
|
||||
else ret = snprintf(str, amt, extended ? "%04d-%03d" : "%04d%03d", y, d);
|
||||
else ret = snprintf(str, amt, extended ?
|
||||
"%04d-%03d" : "%04d%03d", y, d);
|
||||
break;
|
||||
|
||||
case iso8601_prec_week:
|
||||
iso8601_to_week(&y, &m, &d, &dttz);
|
||||
extended = y < 0 || y > 9999 || details->extended; // ISO year is different
|
||||
/* note: ISO year can differ, so recompute extended flag */
|
||||
extended = y < 0 || y > 9999 || details->extended;
|
||||
if(y < 0) snprintf(str, amt, "%05d-W%02d", y, m);
|
||||
else snprintf(str, amt, extended ? "%04d-W%02d" : "%04dW%02d", y, m);
|
||||
return;
|
||||
return str_orig;
|
||||
|
||||
case iso8601_prec_wday:
|
||||
iso8601_to_week(&y, &m, &d, &dttz);
|
||||
extended = y < 0 || y > 9999 || details->extended; // ISO year is different
|
||||
/* note: ISO year can differ, so recompute extended flag */
|
||||
extended = y < 0 || y > 9999 || details->extended;
|
||||
if(y < 0) ret = snprintf(str, amt, "%05d-W%02d-%d", y, m, d);
|
||||
else ret = snprintf(str, amt, extended ? "%04d-W%02d-%d" : "%04dW%02d%d", y, m, d);
|
||||
else ret = snprintf(str, amt, extended ?
|
||||
"%04d-W%02d-%d" : "%04dW%02d%d", y, m, d);
|
||||
break;
|
||||
}
|
||||
|
||||
if(ret < 1 || ret >= amt) return;
|
||||
if(ret < 1 || ret >= amt) return str_orig;
|
||||
str += ret;
|
||||
amt -= ret;
|
||||
|
||||
|
@ -82,12 +101,6 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
|||
d = 60;
|
||||
break;
|
||||
|
||||
case 86401:
|
||||
y = 24;
|
||||
m = 0;
|
||||
d = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
y = dttz.sec / 3600;
|
||||
dttz.sec -= y * 3600;
|
||||
|
@ -98,7 +111,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
|||
|
||||
switch(details->time_prec) {
|
||||
case iso8601_prec_none:
|
||||
return;
|
||||
return str_orig;
|
||||
|
||||
case iso8601_prec_hour:
|
||||
ret = snprintf(str, amt, "T%02d", y);
|
||||
|
@ -109,7 +122,8 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
|||
break;
|
||||
|
||||
case iso8601_prec_sec:
|
||||
ret = snprintf(str, amt, extended ? "T%02d:%02d:%02d" : "T%02d%02d%02d", y, m, d);
|
||||
ret = snprintf(str, amt, extended ?
|
||||
"T%02d:%02d:%02d" : "T%02d%02d%02d", y, m, d);
|
||||
break;
|
||||
|
||||
case iso8601_prec_hourfrac:
|
||||
|
@ -119,24 +133,22 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
|||
|
||||
case iso8601_prec_minfrac:
|
||||
frac = m + (d + date->nsec / 1e9) / 60.0;
|
||||
ret = snprintf(str, amt, extended ? "T%02d:%#012.9f" : "T%02d%#012.9f", y, frac);
|
||||
ret = snprintf(str, amt, extended ?
|
||||
"T%02d:%#012.9f" : "T%02d%#012.9f", y, frac);
|
||||
break;
|
||||
|
||||
case iso8601_prec_secfrac:
|
||||
frac = d + date->nsec / 1e9;
|
||||
ret = snprintf(str, amt, extended ? "T%02d:%02d:%#012.9f" : "T%02d%02d%#012.9f", y, m, frac);
|
||||
ret = snprintf(str, amt, extended ?
|
||||
"T%02d:%02d:%#012.9f" : "T%02d%02d%#012.9f", y, m, frac);
|
||||
break;
|
||||
}
|
||||
|
||||
if(ret < 1 || ret >= amt) return;
|
||||
if(ret < 1 || (ret + 1) >= amt) return str_orig;
|
||||
str += ret;
|
||||
amt -= ret;
|
||||
|
||||
if(details->tz_sec) {
|
||||
if(!--amt) {
|
||||
*str = 0;
|
||||
return;
|
||||
}
|
||||
if(details->tz_sec < 0) {
|
||||
*str++ = '-';
|
||||
ret = -details->tz_sec;
|
||||
|
@ -144,6 +156,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
|||
*str++ = '+';
|
||||
ret = details->tz_sec;
|
||||
}
|
||||
--amt;
|
||||
|
||||
y = ret / 3600;
|
||||
ret -= y * 3600;
|
||||
|
@ -151,13 +164,17 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
|||
ret -= m * 60;
|
||||
d = ret;
|
||||
|
||||
if(d) snprintf(str, amt, extended ? "%02d:%02d:%02d" : "%02d%02d%02d", y, m, d);
|
||||
else if(m) snprintf(str, amt, extended ? "%02d:%02d" : "%02d%02d", y, m);
|
||||
if(d) snprintf(str, amt, extended ?
|
||||
"%02d:%02d:%02d" : "%02d%02d%02d", y, m, d);
|
||||
else if(m) snprintf(str, amt, extended ?
|
||||
"%02d:%02d" : "%02d%02d", y, m);
|
||||
else snprintf(str, amt, "%02d", y);
|
||||
} else {
|
||||
*str++ = 'Z';
|
||||
if(amt > 1) *str = 0;
|
||||
*str++ = 0;
|
||||
}
|
||||
|
||||
return str_orig;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
/* libiso8601/src/libiso8601/400_c_library.c
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
/* days between 0000-001 and 1970-001 (the unix epoch) */
|
||||
#define EPOCH_GDAY (719528)
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_now(struct iso8601_date* date, struct iso8601_details* details)
|
||||
{
|
||||
static int use_gettimeofday = 0;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
struct tm tm;
|
||||
|
||||
/* not all systems have clock_gettime implemented */
|
||||
if(use_gettimeofday || clock_gettime(CLOCK_REALTIME, &ts)) {
|
||||
use_gettimeofday = 1;
|
||||
gettimeofday(&tv, 0);
|
||||
if(tv.tv_sec < 0) ts.tv_sec = 0;
|
||||
else ts.tv_sec = tv.tv_sec;
|
||||
ts.tv_nsec = tv.tv_usec * 1000L;
|
||||
}
|
||||
|
||||
/* populate the `struct iso8601_date' if it was passed */
|
||||
if(date) {
|
||||
iso8601_from_ts(date, &ts);
|
||||
}
|
||||
|
||||
/* populate the `struct iso8601_details' if it was passed */
|
||||
if(details) {
|
||||
memset(details, 0, sizeof(struct iso8601_details));
|
||||
details->date_prec = iso8601_prec_day;
|
||||
details->time_prec = iso8601_prec_secfrac;
|
||||
|
||||
/* this is silly, but it's the only way to recover the timezone */
|
||||
localtime_r(&ts.tv_sec, &tm);
|
||||
details->tz_sec = tm.tm_gmtoff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_set_sysclock(const struct iso8601_date* date)
|
||||
{
|
||||
static int use_settimeofday = 0;
|
||||
struct timeval tv;
|
||||
struct timespec ts;
|
||||
|
||||
/* not all systems have clock_settime implemented */
|
||||
if(use_settimeofday) goto try_settimeofday;
|
||||
|
||||
/* try setting clock */
|
||||
iso8601_to_ts(&ts, date);
|
||||
if(clock_settime(CLOCK_REALTIME, &ts)) {
|
||||
if(errno == EPERM) return -1;
|
||||
use_settimeofday = 1;
|
||||
goto try_settimeofday;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
/* fallback using settimeofday() */
|
||||
try_settimeofday:
|
||||
iso8601_to_tv(&tv, date);
|
||||
return settimeofday(&tv, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_from_ts(struct iso8601_date* date, const struct timespec* ts)
|
||||
{
|
||||
ldiv_t qr;
|
||||
|
||||
qr = ldiv(ts->tv_sec, 86400);
|
||||
if(ts->tv_sec < 0) {
|
||||
--qr.quot;
|
||||
qr.rem += 86400;
|
||||
}
|
||||
date->day = EPOCH_GDAY + qr.quot;
|
||||
date->sec = qr.rem;
|
||||
date->nsec = ts->tv_nsec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_to_ts(struct timespec* ts, const struct iso8601_date* date)
|
||||
{
|
||||
ts->tv_sec = 86400L * (date->day - EPOCH_GDAY) + date->sec;
|
||||
ts->tv_nsec = date->nsec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_from_tv(struct iso8601_date* date, const struct timeval* tv)
|
||||
{
|
||||
ldiv_t qr;
|
||||
|
||||
qr = ldiv(tv->tv_sec, 86400);
|
||||
if(tv->tv_sec < 0) {
|
||||
--qr.quot;
|
||||
qr.rem += 86400;
|
||||
}
|
||||
date->day = EPOCH_GDAY + qr.quot;
|
||||
date->sec = qr.rem;
|
||||
date->nsec = tv->tv_usec * 1000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_to_tv(struct timeval* tv, const struct iso8601_date* date)
|
||||
{
|
||||
tv->tv_sec = 86400L * (date->day - EPOCH_GDAY) + date->sec;
|
||||
tv->tv_usec = date->nsec / 1000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_from_time_t(struct iso8601_date* date, const time_t* t)
|
||||
{
|
||||
ldiv_t qr;
|
||||
|
||||
qr = ldiv(*t, 86400);
|
||||
if(*t < 0) {
|
||||
--qr.quot;
|
||||
qr.rem += 86400;
|
||||
}
|
||||
date->day = EPOCH_GDAY + qr.quot;
|
||||
date->sec = qr.rem;
|
||||
date->nsec = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_to_time_t(time_t* t, const struct iso8601_date* date)
|
||||
{
|
||||
*t = 86400L * (date->day - EPOCH_GDAY) + date->sec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,100 @@
|
|||
/* libiso8601/src/libiso8601/400_c_library.h
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*! \defgroup c_library C library integration.
|
||||
|
||||
These functions enable integration with the C library (system call wrappers and
|
||||
conversion).
|
||||
|
||||
*/
|
||||
/*!@{*/
|
||||
|
||||
|
||||
|
||||
/*! \brief Retrieve the current time.
|
||||
|
||||
\param[out] date Current date/time (may be 0), in UTC. May be 0.
|
||||
\param[out] details Details (may be 0), including timezone. May be 0.
|
||||
|
||||
Retrieves the current time from the system clock, storing it into \a date and
|
||||
\a details (both parameters optional).
|
||||
|
||||
*/
|
||||
void iso8601_now(struct iso8601_date* date, struct iso8601_details* details);
|
||||
|
||||
|
||||
|
||||
/*! \brief Set the system clock.
|
||||
|
||||
\param date Date to set.
|
||||
\retval 0 on success.
|
||||
\retval -1 on error (and see \a errno).
|
||||
|
||||
Attempts to set the system clock using \c clock_settime(), falling back to \c
|
||||
settimeofday(). The user will need the \c CAP_SYS_TIME capability to set the
|
||||
clock, otherwise \a errno will be set to \c EPERM.
|
||||
|
||||
*/
|
||||
int iso8601_set_sysclock(const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert from a struct timespec. */
|
||||
void iso8601_from_ts(struct iso8601_date* date, const struct timespec* ts)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
/*! \brief Convert to a struct timespec. */
|
||||
void iso8601_to_ts(struct timespec* ts, const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
/*! \brief Convert from a struct timeval. */
|
||||
void iso8601_from_tv(struct iso8601_date* date, const struct timeval* tv)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
/*! \brief Convert to a struct timeval. */
|
||||
void iso8601_to_tv(struct timeval* tv, const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
/*! \brief Convert from a time_t. */
|
||||
void iso8601_from_time_t(struct iso8601_date* date, const time_t* t)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
/*! \brief Convert to a time_t. */
|
||||
void iso8601_to_time_t(time_t* t, const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*!@}*/
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4:syntax=ch.doxygen
|
||||
*/
|
|
@ -0,0 +1,203 @@
|
|||
/* libiso8601/src/libiso8601/400_calc.h
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*! \defgroup calc Conversion and calculation routines.
|
||||
|
||||
This set of functions is useful for converting dates and times into formats
|
||||
understood by humans, and vice versa.
|
||||
|
||||
*/
|
||||
/*!@{*/
|
||||
|
||||
|
||||
|
||||
/*! \brief Is year a leap year?
|
||||
|
||||
\param year Year to examine.
|
||||
\retval 0 if not leap year.
|
||||
\retval non-0 if leap year.
|
||||
|
||||
Returns non-0 if \a year is a leap year.
|
||||
|
||||
*/
|
||||
int iso8601_isleap(int year);
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert date to calendar format.
|
||||
|
||||
\param[out] year Calendar year.
|
||||
\param[out] month Calendar month (1 to 12).
|
||||
\param[out] day Calendar day (starting from 1).
|
||||
\param date Date to convert.
|
||||
|
||||
*/
|
||||
void iso8601_to_cal(int* year, int* month, int* day,
|
||||
const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert date from calendar format.
|
||||
|
||||
\param[out] date Output date.
|
||||
\param year Calendar year.
|
||||
\param month Calendar month (1 to 12).
|
||||
\param day Calenday day (starting from 1).
|
||||
\retval 0 on success.
|
||||
\retval -1 on error (and see \a errno).
|
||||
|
||||
Converts the date specified in \a year, \a month and \a day into \a date.
|
||||
|
||||
\note Does not touch the \a sec or \a nsec time members of \a date. This means
|
||||
they will be unchanged after a call to this function. If this will lead to
|
||||
unexpected results, initialise the structure to 0 first.
|
||||
|
||||
*/
|
||||
int iso8601_from_cal(struct iso8601_date* date, int year, int month, int day)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert date to ordinal format.
|
||||
|
||||
\param[out] year Calendar year.
|
||||
\param[out] oday Ordinal day (from 1).
|
||||
\param date Date to convert.
|
||||
|
||||
*/
|
||||
void iso8601_to_ord(int* year, int* oday, const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert date from ordinal format.
|
||||
|
||||
\param[out] date Output date.
|
||||
\param year Calendar year.
|
||||
\param oday Ordinal day (from 1).
|
||||
\retval 0 on success.
|
||||
\retval -1 on error (and see \a errno).
|
||||
|
||||
Converts the date specified into \a year and \a oday into \a date.
|
||||
|
||||
\note Does not touch the \a sec or \a nsec time members of \a date. This means
|
||||
they will be unchanged after a call to this functoin. If this will lead to
|
||||
unexpected results, initialise the structure to 0 first.
|
||||
|
||||
*/
|
||||
int iso8601_from_ord(struct iso8601_date* date, int year, int oday)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert date to week format.
|
||||
|
||||
\param[out] year Calendar year.
|
||||
\param[out] week ISO week number (from 1).
|
||||
\param[out] wday ISO week day number (1 = Monday, 7 = Sunday).
|
||||
\param date Date to convert.
|
||||
|
||||
*/
|
||||
void iso8601_to_week(int* year, int* week, int* wday,
|
||||
const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert date from week format.
|
||||
|
||||
\param [out] date Output date.
|
||||
\param year Calendar year.
|
||||
\param week ISO week number (from 1).
|
||||
\param wday ISO week day number (1 = Monday, 7 = Sunday).
|
||||
\retval 0 on success.
|
||||
\retval -1 on error (and see \a errno).
|
||||
|
||||
Converts the date specified into \a year, \a week and \a wday into \a date.
|
||||
|
||||
\note Does not touch the \a sec or \a nsec time members of \a date. This means
|
||||
they will be unchanged after a call to this functoin. If this will lead to
|
||||
unexpected results, initialise the structure to 0 first.
|
||||
|
||||
*/
|
||||
int iso8601_from_week(struct iso8601_date* date, int year, int week, int wday)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert time to wall clock format.
|
||||
|
||||
\param[out] hour Output hour.
|
||||
\param[out] min Output minute.
|
||||
\param[out] sec Output second.
|
||||
\param date Date/time to convert.
|
||||
|
||||
Converts the time stored in \a date into wall clock format, storing the result
|
||||
in \a hour, \a min and \a sec.
|
||||
|
||||
*/
|
||||
void iso8601_to_clocktime(int* hour, int* min, int* sec,
|
||||
const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Convert time from wall clock format.
|
||||
|
||||
\param[out] date Output time.
|
||||
\param hour Hour.
|
||||
\param min Minute.
|
||||
\param sec Second.
|
||||
\retval 0 on success.
|
||||
\retval -1 on error (and see \a errno).
|
||||
|
||||
Converts the time as specified by \a hour, \a min and \a sec, storing the
|
||||
result in \a date.
|
||||
|
||||
\note Does not touch the \a day (date) member of \a date. This means it will be
|
||||
unchanged after a call to this function. If this will lead to unexpected
|
||||
results, initialise the structure to 0 first.
|
||||
|
||||
*/
|
||||
int iso8601_from_clocktime(struct iso8601_date* date, int hour, int min,
|
||||
int sec)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*!@}*/
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4:syntax=ch.doxygen
|
||||
*/
|
|
@ -0,0 +1,135 @@
|
|||
/* libiso8601/src/libiso8601/400_leap.h
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*! \defgroup leap Leap second support.
|
||||
|
||||
A set of functions for explicitly dealing with leap seconds. All library
|
||||
functions are implicitly leap second aware, but there are occasions when leap
|
||||
seconds must be dealt with explicitly. These functions permit this.
|
||||
|
||||
Internally, leap seconds are represented as a table of day numbers; each day
|
||||
number present in the table means that the corresponding day has 86401 seconds
|
||||
(a leap second).
|
||||
|
||||
\note The library does not (yet) have support for negative leap seconds. This
|
||||
support will be added should a day with a negative leap second ever come.
|
||||
This will need to addressed in the API as the current API does not support
|
||||
loading a table of negative leap seconds.
|
||||
|
||||
It is possible to create a disk file containing an updated table and to load
|
||||
that file using \ref iso8601_leap_table_load (or to explicitly use an existing
|
||||
in-memory table with \ref iso8601_leap_table_set). The format of the on-disk
|
||||
file is:
|
||||
|
||||
<pre># integers are stored big-endian
|
||||
[8*char] signature, "/O9PdPZI"
|
||||
[uint32] number of entries, 'n'
|
||||
|
||||
# entries are repeated 'n' times, and stored lowest day number first
|
||||
[uint32] day number of entry</pre>
|
||||
|
||||
*/
|
||||
/*!@{*/
|
||||
|
||||
|
||||
|
||||
/*! \brief Return number of seconds in day, taking leap seconds into account.
|
||||
|
||||
\param date The date to return the number of seconds for.
|
||||
\retval 86399 day with a negative leap second.
|
||||
\retval 86400 day with no leap second.
|
||||
\retval 86401 day with one leap second.
|
||||
|
||||
Returns the duration of a day \a date, in seconds. This function takes leap
|
||||
seconds into account and may be used to determine if a day contains a leap
|
||||
second or not.
|
||||
|
||||
\note There have not yet been any days requiring a negative leap second, so at
|
||||
present 86399 will never be returned.
|
||||
|
||||
*/
|
||||
int iso8601_seconds_leap(const struct iso8601_date* date)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Return number of leap seconds elapsed between two days.
|
||||
|
||||
\param start The start date.
|
||||
\param end The end date.
|
||||
\returns Number of leap seconds elapsed.
|
||||
|
||||
Computes the number of leap seconds that have elapsed between two days. Note
|
||||
that this is the sum of such leap seconds, so it will be 0 if (for example)
|
||||
there is one positive leap second and one negative leap second. The ordering of
|
||||
the dates is important; if \a start is after \a end, then the value returned
|
||||
will be negative (for positive leap seconds).
|
||||
|
||||
*/
|
||||
int iso8601_leap_elapsed(const struct iso8601_date* start,
|
||||
const struct iso8601_date* end)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Update table of leap seconds.
|
||||
|
||||
\param new_table Array of day numbers on which leap seconds occur.
|
||||
\param new_size Number of entries in array.
|
||||
|
||||
This function can be used to update the table of leap seconds at runtime. The
|
||||
\a new_table argument points to an array of integers, each entry being the day
|
||||
number containing a leap second. The array must be sorted so that lower day
|
||||
numbers appear towards the start of the array. \a new_size gives the number of
|
||||
entries in the array. \a new_table must persist in memory as long as library
|
||||
functions are in use.
|
||||
|
||||
\warning If negative leap seconds are ever used, this function will not support
|
||||
them. There may need to be an ABI change in future to solve this problem.
|
||||
|
||||
*/
|
||||
void iso8601_leap_table_set(int* new_table, int new_size)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Load new table of leap seconds from disk.
|
||||
|
||||
\param fname Filename. May be 0 for system default.
|
||||
\retval 0 on success.
|
||||
\retval -1 on error (and see \a errno).
|
||||
|
||||
This function attempts to load a new table of leap seconds from disk, using the
|
||||
filename \a fname. If \a fname is not specified, the system default (set at
|
||||
compile time) will be used.
|
||||
|
||||
If the table is loaded successfully, it will be set with \ref
|
||||
iso8601_leap_table_set(). On any error, -1 will be returned, and \a errno will
|
||||
be set appropriately. If \a errno is \c EINVAL, then the file does not contain
|
||||
a valid leap second table.
|
||||
|
||||
*/
|
||||
int iso8601_leap_table_load(const char* fname);
|
||||
|
||||
|
||||
|
||||
/*!@}*/
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4:syntax=ch.doxygen
|
||||
*/
|
|
@ -0,0 +1,204 @@
|
|||
/* libiso8601/src/libiso8601/400_manip.c
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_lt(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
{
|
||||
if(d1->day < d2->day) return 1;
|
||||
if(d1->day > d2->day) return 0;
|
||||
if(d1->sec < d2->sec) return 1;
|
||||
if(d1->sec > d2->sec) return 0;
|
||||
if(d1->nsec < d2->nsec) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_lte(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
{
|
||||
if(d1->day < d2->day) return 1;
|
||||
if(d1->day > d2->day) return 0;
|
||||
if(d1->sec < d2->sec) return 1;
|
||||
if(d1->sec > d2->sec) return 0;
|
||||
if(d1->nsec < d2->nsec) return 1;
|
||||
return d1->nsec == d2->nsec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_eq(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
{
|
||||
return (d1->day == d2->day) && (d1->sec == d2->sec)
|
||||
&& (d1->nsec == d2->nsec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_cmp(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
{
|
||||
if(d1->day < d2->day) return -1;
|
||||
if(d1->day > d2->day) return 1;
|
||||
if(d1->sec < d2->sec) return -1;
|
||||
if(d1->sec > d2->sec) return 1;
|
||||
if(d1->nsec < d2->nsec) return -1;
|
||||
if(d1->nsec > d2->nsec) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_add_elapsed(struct iso8601_date* date,
|
||||
const struct iso8601_elapsed* per)
|
||||
{
|
||||
div_t qr;
|
||||
int leapcorrect;
|
||||
|
||||
/* work out number to advance ‘day’ by */
|
||||
qr = div(per->sec, 86400);
|
||||
leapcorrect = _leap_elapsed_day(date->day, date->day + qr.quot);
|
||||
date->day += qr.quot;
|
||||
date->sec += qr.rem - leapcorrect;
|
||||
|
||||
date->nsec += per->nsec;
|
||||
if(date->nsec >= BILLION) {
|
||||
++date->sec;
|
||||
date->nsec -= BILLION;
|
||||
}
|
||||
|
||||
if(date->sec < 0) {
|
||||
--date->day;
|
||||
date->sec += iso8601_seconds_leap(date);
|
||||
}
|
||||
|
||||
if(date->sec >= iso8601_seconds_leap(date)) {
|
||||
date->sec -= iso8601_seconds_leap(date);
|
||||
++date->day;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_subtract_elapsed(struct iso8601_date* date,
|
||||
const struct iso8601_elapsed* per)
|
||||
{
|
||||
div_t qr;
|
||||
int leapcorrect;
|
||||
|
||||
/* work out number to advance ‘day’ by */
|
||||
qr = div(per->sec, 86400);
|
||||
leapcorrect = _leap_elapsed_day(date->day - qr.quot, date->day);
|
||||
date->day -= qr.quot;
|
||||
date->sec -= qr.rem - leapcorrect;
|
||||
date->nsec -= per->nsec;
|
||||
|
||||
if(date->nsec < 0) {
|
||||
--date->sec;
|
||||
date->nsec += BILLION;
|
||||
}
|
||||
|
||||
if(date->sec < 0) {
|
||||
--date->day;
|
||||
date->sec += iso8601_seconds_leap(date);
|
||||
}
|
||||
|
||||
if(date->sec >= iso8601_seconds_leap(date)) {
|
||||
date->sec -= iso8601_seconds_leap(date);
|
||||
++date->day;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_add_multiple(struct iso8601_date* date,
|
||||
const struct iso8601_elapsed* per, int n)
|
||||
{
|
||||
long long nsec;
|
||||
lldiv_t qr;
|
||||
struct iso8601_elapsed mult;
|
||||
|
||||
nsec = per->nsec * llabs(n);
|
||||
qr = lldiv(nsec, BILLION);
|
||||
mult.sec = qr.quot + per->sec * llabs(n);
|
||||
mult.nsec = qr.rem;
|
||||
|
||||
if(n < 0) iso8601_subtract_elapsed(date, &mult);
|
||||
else iso8601_add_elapsed(date, &mult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iso8601_difference(const struct iso8601_date* d1, const struct iso8601_date* d2,
|
||||
struct iso8601_elapsed* per, int* sign)
|
||||
{
|
||||
const struct iso8601_date* e1, * e2;
|
||||
|
||||
/* compute sign */
|
||||
if(iso8601_lt(d1, d2)) {
|
||||
if(sign) *sign = -1;
|
||||
e1 = d2;
|
||||
e2 = d1;
|
||||
} else {
|
||||
if(sign) *sign = 1;
|
||||
e1 = d1;
|
||||
e2 = d2;
|
||||
}
|
||||
|
||||
if(!per) return;
|
||||
|
||||
/* compute difference, knowing that e1 >= e2 */
|
||||
per->sec = (e1->day - e2->day) * 86400
|
||||
+ iso8601_leap_elapsed(e2, e1 /* start, end */)
|
||||
+ (e1->sec - e2->sec);
|
||||
if(e1->nsec < e2->nsec) {
|
||||
--per->sec;
|
||||
per->nsec = BILLION + e1->nsec - e2->nsec;
|
||||
} else {
|
||||
per->nsec = e1->nsec - e2->nsec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
iso8601_elapsed_div(const struct iso8601_elapsed* num,
|
||||
const struct iso8601_elapsed* denom, struct iso8601_elapsed* remain)
|
||||
{
|
||||
unsigned long long pnum, pdenom;
|
||||
lldiv_t val, v2;
|
||||
|
||||
pnum = num->sec;
|
||||
pnum *= BILLION;
|
||||
pnum += num->nsec;
|
||||
|
||||
pdenom = denom->sec;
|
||||
pdenom *= BILLION;
|
||||
pdenom += denom->nsec;
|
||||
|
||||
val = lldiv(pnum, pdenom);
|
||||
if(remain) {
|
||||
v2 = lldiv(val.rem, BILLION);
|
||||
remain->sec = v2.quot;
|
||||
remain->nsec = v2.rem;
|
||||
}
|
||||
return val.quot;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,182 @@
|
|||
/* libiso8601/src/libiso8601/400_manip.h
|
||||
*
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*! \defgroup manip Manipulation routines.
|
||||
|
||||
This set of functions is useful for performing arithmetic etc. on dates. It
|
||||
uses struct \ref iso8601_elapsed to represent the magnitude of time differences.
|
||||
|
||||
*/
|
||||
/*!@{*/
|
||||
|
||||
|
||||
|
||||
/*! \brief Comparison (less than).
|
||||
|
||||
\param d1 First date to compare.
|
||||
\param d2 Second date to compare.
|
||||
\retval non-0 if \a d1 < \a d2
|
||||
\retval 0 otherwise
|
||||
|
||||
*/
|
||||
int iso8601_lt(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Comparison (less than or equal to).
|
||||
|
||||
\param d1 First date to compare.
|
||||
\param d2 Second date to compare.
|
||||
\retval non-0 if \a d1 <= \a d2
|
||||
\retval 0 otherwise
|
||||
|
||||
*/
|
||||
int iso8601_lte(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Comparison (equality).
|
||||
|
||||
\param d1 First date to compare.
|
||||
\param d2 Second date to compare.
|
||||
\retval non-0 if \a d1 == \a d2
|
||||
\retval 0 otherwise
|
||||
|
||||
*/
|
||||
int iso8601_eq(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Comparison (for qsort et al.).
|
||||
|
||||
\param d1 First date to compare.
|
||||
\param d2 Second date to compare.
|
||||
\retval -1 if \a d1 < \a d2
|
||||
\retval 0 if \a d1 == \a d2
|
||||
\retval 1 if \a d1 > \a d2
|
||||
|
||||
*/
|
||||
int iso8601_cmp(const struct iso8601_date* d1, const struct iso8601_date* d2)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Add a period to a date.
|
||||
|
||||
\param[in,out] date Date to modify.
|
||||
\param per Period to advance date/time by.
|
||||
|
||||
*/
|
||||
void iso8601_add_elapsed(struct iso8601_date* date,
|
||||
const struct iso8601_elapsed* per)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Subtract a period from a date.
|
||||
|
||||
\param[in,out] date Date to modify.
|
||||
\param per Period to regress date/time by.
|
||||
|
||||
*/
|
||||
void iso8601_subtract_elapsed(struct iso8601_date* date,
|
||||
const struct iso8601_elapsed* per)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Add a multiple of a period to a date.
|
||||
|
||||
\param[in,out] date Date to modify.
|
||||
\param per Period to advance date/time by.
|
||||
\param n Multiple of \a per.
|
||||
|
||||
Adds \a n multiples of \a per to \a date. \a n may be 0 or negative. The result
|
||||
is stored in \a date. This is an efficient implementation which avoids loops,
|
||||
but it does use 64-bit arithmetic.
|
||||
|
||||
*/
|
||||
void iso8601_add_multiple(struct iso8601_date* date,
|
||||
const struct iso8601_elapsed* per, int n)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Find difference between dates.
|
||||
|
||||
\param d1 First date.
|
||||
\param d2 Second date.
|
||||
\param[out] per Magnitude of period elapsed between two dates. Pointer may be 0.
|
||||
\param[out] sign Set to sign of difference (-1 or +1). Pointer may be 0.
|
||||
|
||||
This function will perform the calculation <code>|d1 - d2|</code>, storing the
|
||||
result in \a per (if it is not a null pointer). The sign of the result is
|
||||
stored in \a sign (if it is not a null pointer), i.e. -1 if \a d2 > \a d1 or
|
||||
+1 if \a d2 <= \a d1.
|
||||
|
||||
*/
|
||||
void iso8601_difference(const struct iso8601_date* d1,
|
||||
const struct iso8601_date* d2, struct iso8601_elapsed* per, int* sign)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull(1,2)))
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*! \brief Divide one period by another.
|
||||
|
||||
\param num Numerator.
|
||||
\param denom Denominator (divisor).
|
||||
\param[out] remain Remainder. May be 0.
|
||||
\returns Number of times \a denom divides into \a num.
|
||||
|
||||
This function computes the number of times that \a denom can be divided into \a
|
||||
num, returning that number. If desired, the remaining period which could not be
|
||||
divided can be written into \a remain. Uses 64-bit arithmetic internally.
|
||||
|
||||
*/
|
||||
int iso8601_elapsed_div(const struct iso8601_elapsed* num,
|
||||
const struct iso8601_elapsed* denom, struct iso8601_elapsed* remain)
|
||||
#ifndef DOXYGEN
|
||||
__attribute__((nonnull(1,2)));
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
/*!@}*/
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4:syntax=ch.doxygen
|
||||
*/
|
|
@ -1,10 +1,14 @@
|
|||
/* 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
|
||||
* (c)2006-2010, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv3. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* options for text editors
|
|
@ -1,18 +0,0 @@
|
|||
/* libiso8601/src/libiso8601/TopHeader.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.
|
||||
*/
|
||||
|
||||
#ifndef HEADER_libiso8601
|
||||
#define HEADER_libiso8601
|
||||
|
||||
// standard includes, or includes needed for type declarations
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -1,21 +0,0 @@
|
|||
/* libiso8601/src/libiso8601/TopSource.c
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#include "iso8601.h"
|
||||
|
||||
// Below are all the includes used throughout the library.
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -2,35 +2,36 @@ build_target libiso8601
|
|||
|
||||
# make paths (this is for Gentoo in particular)
|
||||
build_dir_tree "${LIBDIR}" || return 1
|
||||
build_dir_tree "${PKGCONFDIR}" || return 1
|
||||
build_dir_tree "${BINDIR}" || return 1
|
||||
build_dir_tree "${INCLUDEDIR}" || return 1
|
||||
|
||||
# install library
|
||||
echo "Installing libraries into '${LIBDIR}'"
|
||||
source src/libiso8601/soversion
|
||||
install_file ${libiso8601} ${LIBDIR} 0755 || return 1
|
||||
BASE="${libiso8601_BASE}.so"
|
||||
MAJOR="${BASE}.${SOMAJOR}"
|
||||
MINOR="${MAJOR}.${SOMINOR}"
|
||||
MICRO="${MINOR}.${SOMICRO}"
|
||||
install_symlink "${MINOR}" "${MICRO}" "${LIBDIR}"
|
||||
install_symlink "${MAJOR}" "${MINOR}" "${LIBDIR}"
|
||||
install_symlink "${BASE}" "${MAJOR}" "${LIBDIR}"
|
||||
MICRO="${MAJOR}.${SOMICRO}"
|
||||
install_symlink "${BASE}" "${MICRO}" "${LIBDIR}"
|
||||
|
||||
# install header
|
||||
echo "Installing header file '${libiso8601_HEADER}' into ${INCLUDEDIR}"
|
||||
install_header ${libiso8601_HEADER} ${INCLUDEDIR} 0644 || return 1
|
||||
|
||||
# install pkgconfig file
|
||||
echo "Installing package config file into ${PKGCONFDIR}"
|
||||
PKGCONFFILE=${PKGCONFDIR}/libiso8601.pc
|
||||
do_cmd rm -f ${PKGCONFFILE}
|
||||
do_cmd_redir ${PKGCONFFILE} sed \
|
||||
# install config script
|
||||
echo "Installing config script into ${BINDIR}"
|
||||
CONFFILE="${INSTALL_PREFIX}${BINDIR}/libiso8601-config"
|
||||
|
||||
do_cmd rm -f "${CONFFILE}"
|
||||
do_cmd_redir "${CONFFILE}" sed \
|
||||
-e "s,@VERSION@,${VERSION}," \
|
||||
-e "s,@LIBDIR@,${FINALLIBDIR}," \
|
||||
-e "s,@INCLUDEDIR@,${FINALINCLUDEDIR}," \
|
||||
src/libiso8601/pkgconf.in
|
||||
do_cmd chmod 0644 ${PKGCONFFILE}
|
||||
-e "s,@DEP_CFLAGS@,${libiso8601_DEP_CFLAGS}," \
|
||||
-e "s,@DEP_LIBS@,${libiso8601_DEP_LIBS}," \
|
||||
-e "s,@LIB_DIR@,${LIBDIR}," \
|
||||
-e "s,@INCLUDE_DIR@,${INCLUDEDIR}," \
|
||||
src/libiso8601/config-script
|
||||
|
||||
do_cmd chmod 0755 "${CONFFILE}"
|
||||
print_success "Done"
|
||||
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
# libiso8601_BUILT
|
||||
# libiso8601_HEADER
|
||||
# libiso8601_BASE
|
||||
# libiso8601_DEP_CFLAGS
|
||||
# libiso8601_DEP_LIBS
|
||||
|
||||
if [ -z ${libiso8601_BUILT} ]
|
||||
then
|
||||
libiso8601_BASE=libiso8601
|
||||
source src/libiso8601/soversion
|
||||
|
||||
libiso8601="obj/${libiso8601_BASE}.so.${SOMAJOR}.${SOMINOR}.${SOMICRO}"
|
||||
SO_EXTRA="-lrt -lc"
|
||||
libiso8601="obj/${libiso8601_BASE}.so.${SOMAJOR}.${SOMICRO}"
|
||||
libiso8601_DEP_CFLAGS=""
|
||||
libiso8601_DEP_LIBS="-lrt"
|
||||
SO_EXTRA="${libiso8601_DEP_CFLAGS} ${libiso8601_DEP_LIBS} -lc \
|
||||
-D_GNU_SOURCE -std=gnu99 \
|
||||
-DDEFAULT_LEAP_TABLE=\"${DEFAULT_LEAP_TABLE}\""
|
||||
|
||||
echo "Building library ${libiso8601}..."
|
||||
|
||||
|
@ -30,13 +36,14 @@ then
|
|||
then
|
||||
echo " Compiling"
|
||||
|
||||
SONAME="${libiso8601_BASE}.so.${SOMAJOR}.${SOMINOR}"
|
||||
SONAME="${libiso8601_BASE}.so.${SOMAJOR}"
|
||||
do_cmd ${CC} ${CFLAGS} -Iobj -shared -fpic -o "${libiso8601}" \
|
||||
-Wl,-soname,${SONAME} \
|
||||
${SRC} ${SO_EXTRA} || return 1
|
||||
|
||||
# make tests work
|
||||
do_cmd ln -sf $(basename ${libiso8601}) obj/${SONAME} || return 1
|
||||
# make tests and linking work
|
||||
do_cmd ln -sf "$(basename "${libiso8601}")" "obj/${SONAME}" || return 1
|
||||
do_cmd ln -sf "$(basename "${libiso8601}")" "obj/${libiso8601_BASE}.so" || return 1
|
||||
|
||||
print_success "Library built"
|
||||
else
|
||||
|
@ -47,5 +54,4 @@ then
|
|||
libiso8601_HEADER=${HDR}
|
||||
|
||||
fi
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
||||
|
|
|
@ -8,14 +8,13 @@ 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="$(find src/libiso8601/ -name '*.h' | sort)"
|
||||
make_monolithic ${HDR} Ch || return 1
|
||||
|
||||
MONOLITHIC_SOURCE="$(echo src/libiso8601/{TopSource,c_library,calc,parser,print,manip}.c)"
|
||||
MONOLITHIC_SOURCE="$(find src/libiso8601/ -name '*.c' | sort)"
|
||||
make_monolithic ${SRC} C || return 1
|
||||
|
||||
libiso8601_MONOLITHIC=1
|
||||
MONOLITHIC_DOC="${MONOLITHIC_DOC} ${HDR}"
|
||||
fi
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/* libiso8601/src/libiso8601/c_library.c
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
// days between 0000-001 and 1970-001 (the unix epoch)
|
||||
#define EPOCH_GDAY (719528)
|
||||
|
||||
|
||||
|
||||
void iso8601_now(struct iso8601_date* date, struct iso8601_details* details)
|
||||
{
|
||||
struct timespec ts;
|
||||
struct tm tm;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
|
||||
// populate the `struct iso8601_date' if it was passed
|
||||
if(date) {
|
||||
iso8601_from_ts(date, &ts);
|
||||
}
|
||||
|
||||
// populate the `struct iso8601_details' if it was passed
|
||||
if(details) {
|
||||
memset(details, 0, sizeof(struct iso8601_details));
|
||||
details->date_prec = iso8601_prec_day;
|
||||
details->time_prec = iso8601_prec_secfrac;
|
||||
|
||||
// this is silly, but it's the only way to recover the timezone
|
||||
localtime_r(&ts.tv_sec, &tm);
|
||||
details->tz_sec = tm.tm_gmtoff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_from_ts(struct iso8601_date* date, const struct timespec* ts)
|
||||
{
|
||||
ldiv_t qr;
|
||||
|
||||
qr = ldiv(ts->tv_sec, 86400);
|
||||
date->day = EPOCH_GDAY + qr.quot;
|
||||
date->sec = qr.rem;
|
||||
date->nsec = ts->tv_nsec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_to_ts(struct timespec* ts, const struct iso8601_date* date)
|
||||
{
|
||||
ts->tv_sec = 86400L * (date->day - EPOCH_GDAY) + date->sec;
|
||||
ts->tv_nsec = date->nsec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_from_time_t(struct iso8601_date* date, const time_t* t)
|
||||
{
|
||||
ldiv_t qr;
|
||||
|
||||
qr = ldiv(*t, 86400);
|
||||
date->day = EPOCH_GDAY + qr.quot;
|
||||
date->sec = qr.rem;
|
||||
date->nsec = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_to_time_t(time_t* t, const struct iso8601_date* date)
|
||||
{
|
||||
*t = 86400L * (date->day - EPOCH_GDAY) + date->sec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -1,429 +0,0 @@
|
|||
/* libiso8601/src/libiso8601/calc.c
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* CALCULATION ROUTINES
|
||||
*
|
||||
* This file contains calculation routines used internally in the library. Our date format is the
|
||||
* number of days elapsed since 0000-001 (so that date would be 0, -0001-365 would be -1, etc.).
|
||||
* Time is represented as the number of seconds elapsed since midnight at the start of the day
|
||||
* (so 0 is 00:00:00 and 86400 is 24:00:00, which we take to be infinitesimally before the start
|
||||
* of the next day).
|
||||
*/
|
||||
|
||||
#define DAYS_IN_400_YEARS (146097)
|
||||
|
||||
|
||||
|
||||
int iso8601_isleap(int year)
|
||||
{
|
||||
if(year % 4) return 0;
|
||||
if(year % 100) return 1;
|
||||
if(!(year % 400)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* struct monthcount, _days_in_month_common[], _days_in_month_leap[]
|
||||
*
|
||||
* Tables of the number of days in each month, and the number of days elapsed since the start of
|
||||
* the year for each month.
|
||||
*/
|
||||
struct monthcount {
|
||||
int elapsed, days;
|
||||
};
|
||||
|
||||
static const struct monthcount _days_in_month_common[] = {
|
||||
{ 0, 31 },
|
||||
{ 31, 28 },
|
||||
{ 59, 31 },
|
||||
{ 90, 30 },
|
||||
{ 120, 31 },
|
||||
{ 151, 30 },
|
||||
{ 181, 31 },
|
||||
{ 212, 31 },
|
||||
{ 243, 30 },
|
||||
{ 273, 31 },
|
||||
{ 304, 30 },
|
||||
{ 334, 31 }
|
||||
};
|
||||
|
||||
static const struct monthcount _days_in_month_leap[] = {
|
||||
{ 0, 31 },
|
||||
{ 31, 29 },
|
||||
{ 60, 31 },
|
||||
{ 91, 30 },
|
||||
{ 121, 31 },
|
||||
{ 152, 30 },
|
||||
{ 182, 31 },
|
||||
{ 213, 31 },
|
||||
{ 244, 30 },
|
||||
{ 274, 31 },
|
||||
{ 305, 30 },
|
||||
{ 335, 31 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int _days_in_month(int year, int month)
|
||||
{
|
||||
const struct monthcount* mc;
|
||||
|
||||
if(month < 1 || month > 12) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mc = iso8601_isleap(year) ? _days_in_month_leap : _days_in_month_common;
|
||||
return mc[month - 1].days;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void _to_year(int* year, int* days_left, const struct iso8601_date* date)
|
||||
{
|
||||
div_t qr;
|
||||
int ndays = date->day;
|
||||
|
||||
// Each 400 years have 97 leap days, giving 365*400+97 = DAYS_IN_400_YEARS days in 400 years
|
||||
qr = div(ndays, DAYS_IN_400_YEARS);
|
||||
*year = qr.quot * 400;
|
||||
ndays = qr.rem;
|
||||
|
||||
// ensure that we always end up with between 0 and 146096 days remaining
|
||||
if(ndays < 0) {
|
||||
ndays += DAYS_IN_400_YEARS;
|
||||
*year -= 400;
|
||||
}
|
||||
|
||||
// we insert `fake' leap days for years 101, 201, 301
|
||||
if(ndays >= 36890) ++ndays;
|
||||
if(ndays >= 73415) ++ndays;
|
||||
if(ndays >= 109940) ++ndays;
|
||||
|
||||
// each remaining 100 year block has 24 leap days, giving 365*100+24 = 36524 days
|
||||
qr = div(ndays, 36525);
|
||||
*year += qr.quot * 100;
|
||||
ndays = qr.rem;
|
||||
|
||||
// each 4-year block has 1 leap day, giving 365*4 + 1 = 1461 days
|
||||
qr = div(ndays, 1461);
|
||||
*year += qr.quot * 4;
|
||||
ndays = qr.rem;
|
||||
|
||||
// the first year of a 4-year block has 1 leap day, 366 days
|
||||
if(ndays >= 366) {
|
||||
--ndays; // pretend to have dealt with leap day
|
||||
|
||||
// 365 days per remaining year
|
||||
qr = div(ndays, 365);
|
||||
*year += qr.quot;
|
||||
ndays = qr.rem;
|
||||
}
|
||||
|
||||
*days_left = ndays;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_to_cal(int* year, int* month, int* day, const struct iso8601_date* date)
|
||||
{
|
||||
const struct monthcount* mc;
|
||||
int ndays;
|
||||
|
||||
// perform year calulation
|
||||
_to_year(year, &ndays, date);
|
||||
|
||||
// now we simply have number of days elapsed since day 001 in `year'.
|
||||
mc = iso8601_isleap(*year) ? _days_in_month_leap : _days_in_month_common;
|
||||
*month = 1;
|
||||
while(ndays >= mc->days) {
|
||||
*month += 1;
|
||||
ndays -= mc->days;
|
||||
++mc;
|
||||
}
|
||||
*day = ndays + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_to_ord(int* year, int* oday, const struct iso8601_date* date)
|
||||
{
|
||||
int ndays;
|
||||
|
||||
// perform year calcutation
|
||||
_to_year(year, &ndays, date);
|
||||
|
||||
// now we simply have number of days elapsed since day 001 in `year'.
|
||||
*oday = ndays + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int _weekday_of_year(int year)
|
||||
{
|
||||
int w = 6;
|
||||
|
||||
/* Algorithm notes:
|
||||
* - 0 = sun, 1 = mon, ..., 6 = sat
|
||||
* - 0000-001 is a Saturday, day 6
|
||||
* - every year we pass gives us one additional day (364 is divisible by 7)
|
||||
* - but of course every leap year we pass gives us a further day
|
||||
* - so for every 400 years, we add 497 (400 common years, 97 leap years); 497 % 7 = 0
|
||||
*/
|
||||
year %= 400;
|
||||
if(year < 0) year += 400; // end up with between 0-399 years left
|
||||
w += year; // excluding leap years, we increase by 1 day a year
|
||||
w += (year + 3) / 4; // there is one leap year for every four years
|
||||
w -= (year - 1) / 100; // but one less for every century over 0
|
||||
w %= 7;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_to_week(int* year, int* week, int* wday, const struct iso8601_date* date)
|
||||
{
|
||||
int ndays, w, has53 = 0;
|
||||
div_t d;
|
||||
|
||||
// perform year and weekday calculation
|
||||
_to_year(year, &ndays, date);
|
||||
w = _weekday_of_year(*year);
|
||||
|
||||
// find out what day jan 1 was; from there, we can find the ISO week and year number
|
||||
switch(w) {
|
||||
case 4: // W01 starts XXXY-12-28
|
||||
w += 7;
|
||||
has53 = 1; // years starting Thursday have 53 weeks
|
||||
break;
|
||||
|
||||
case 5: // W01 starts XXXZ-01-03
|
||||
case 6: // W01 starts XXXZ-01-02
|
||||
break;
|
||||
|
||||
case 0: // W01 starts XXXZ-01-01
|
||||
case 1: // W01 starts XXXY-12-31
|
||||
case 2: // W01 starts XXXY-12-30
|
||||
w += 7; // for week calculation
|
||||
break;
|
||||
|
||||
case 3: // W01 starts XXXY-12-29
|
||||
w += 7;
|
||||
if(iso8601_isleap(*year)) has53 = 1; // leap years starting Wednesday have 53 weeks
|
||||
}
|
||||
|
||||
// now we simply add the number of days elapsed since the start of the year, and % 7
|
||||
w += ndays;
|
||||
d = div(w, 7); // w can never be 0
|
||||
|
||||
// do Sunday correction
|
||||
if(!d.rem) {
|
||||
d.rem = 7;
|
||||
--d.quot;
|
||||
}
|
||||
|
||||
*wday = d.rem;
|
||||
if(d.quot) {
|
||||
if(d.quot == 53 && !has53) {
|
||||
d.quot = 1;
|
||||
*year += 1;
|
||||
}
|
||||
*week = d.quot;
|
||||
} else {
|
||||
*year -= 1;
|
||||
switch(_weekday_of_year(*year)) {
|
||||
case 3:
|
||||
*week = iso8601_isleap(*year) ? 53 : 52;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
*week = 53;
|
||||
break;
|
||||
|
||||
default:
|
||||
*week = 52;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _from_year(struct iso8601_date* date, int year)
|
||||
{
|
||||
div_t qr;
|
||||
|
||||
// check for range errors
|
||||
if(year < -5879609 || year > 5879609) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Each 400 years have 97 leap days, giving 365*400+97 = DAYS_IN_400_YEARS days in 400 years
|
||||
qr = div(year, 400);
|
||||
date->day = qr.quot * DAYS_IN_400_YEARS;
|
||||
year = qr.rem;
|
||||
|
||||
// ensure we have between 0 and 399 years
|
||||
if(year < 0) {
|
||||
date->day -= DAYS_IN_400_YEARS;
|
||||
year += 400;
|
||||
}
|
||||
|
||||
// excluding leap days, there are 365 days per year
|
||||
date->day += 365 * year;
|
||||
date->day += (year + 3) / 4; // there is one leap year for every four years
|
||||
date->day -= (year - 1) / 100; // but one less for every century over 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int iso8601_from_cal(struct iso8601_date* date, int year, int month, int day)
|
||||
{
|
||||
const struct monthcount* mc;
|
||||
|
||||
// check for domain errors
|
||||
mc = iso8601_isleap(year) ? _days_in_month_leap : _days_in_month_common;
|
||||
if(month < 1 || month > 12 || day < 1 || day > mc[month - 1].days) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// perform year calculation
|
||||
if(_from_year(date, year)) return -1;
|
||||
|
||||
// now get number of days elapsed up to start of month
|
||||
date->day += mc[month - 1].elapsed;
|
||||
|
||||
// and add number of days elapsed sinced start of month
|
||||
date->day += day - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int iso8601_from_ord(struct iso8601_date* date, int year, int oday)
|
||||
{
|
||||
// check for domain errors
|
||||
if(oday < 1 || oday > (iso8601_isleap(year) ? 366 : 365)) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// perform year calculation
|
||||
if(_from_year(date, year)) return -1;
|
||||
|
||||
// now simply add number of days elapsed this year
|
||||
date->day += oday - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int iso8601_from_week(struct iso8601_date* date, int isoyear, int week, int wday)
|
||||
{
|
||||
int day1off, maxwk;
|
||||
|
||||
// compute year part
|
||||
_from_year(date, isoyear);
|
||||
|
||||
// 400-year cycle; ensure we're between 0-400 years
|
||||
isoyear %= 400;
|
||||
if(isoyear < 0) isoyear += 400;
|
||||
|
||||
// domain check
|
||||
maxwk = (((isoyear % 7) == 52) || ((isoyear % 28) == 24)) ? 53 : 52;
|
||||
if(wday < 1 || wday > 7 || week < 1 || week > maxwk) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Algorithm notes:
|
||||
* We now compute the offset between the start day of the ISO year and the start day of the
|
||||
* real year. Year 0000 starts on a Saturday, meaning the ISO year 0000 starts on 0000-003
|
||||
* (offset of +2 days). Each year reduces the offset by one day, and each leap year reduces it
|
||||
* by a further day; the offset wraps from -3 to +3.
|
||||
*/
|
||||
day1off = 2 - isoyear; // reduce offset by 1 for each year
|
||||
day1off += (isoyear - 1) / 100; // cancel out 1 leap year for each century past the first
|
||||
day1off -= (isoyear + 3) / 4; // 1 leap year every 4 years
|
||||
day1off %= 7;
|
||||
if(day1off < -3) day1off += 7;
|
||||
|
||||
// now simply add in the day offset and days/weeks elapsed
|
||||
date->day += day1off + (week - 1) * 7 + wday - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iso8601_to_clocktime(int* hour, int* min, int* sec, const struct iso8601_date* date)
|
||||
{
|
||||
div_t qr;
|
||||
|
||||
// two special cases: leap second and midnight
|
||||
switch(date->sec) {
|
||||
case 86400:
|
||||
*hour = 23;
|
||||
*min = 59;
|
||||
*sec = 60;
|
||||
return;
|
||||
|
||||
case 86401:
|
||||
*hour = 24;
|
||||
*min = 0;
|
||||
*sec = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// normal case
|
||||
qr = div(date->sec, 3600);
|
||||
*hour = qr.quot;
|
||||
qr = div(qr.rem, 60);
|
||||
*min = qr.quot;
|
||||
*sec = qr.rem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int iso8601_from_clocktime(struct iso8601_date* date, int hour, int min, int sec)
|
||||
{
|
||||
// two special cases: leap second and midnight
|
||||
if(hour == 23 && min == 59 && sec == 60) {
|
||||
date->sec = 86400;
|
||||
return 0;
|
||||
}
|
||||
if(hour == 24 && !min && !sec) {
|
||||
date->sec = 86401;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// domain check
|
||||
if(hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 || sec > 59) {
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// normal calculation
|
||||
date->sec = hour * 3600 + min * 60 + sec;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,97 @@
|
|||
#!/bin/bash
|
||||
# libiso8601/src/libiso8601/config-script
|
||||
#
|
||||
# libiso8601-config template. Variables are finalised at install time.
|
||||
#
|
||||
dep_cflags="@DEP_CFLAGS@"
|
||||
dep_libs="@DEP_LIBS@"
|
||||
include_dir="@INCLUDE_DIR@"
|
||||
include_dir_set="no"
|
||||
lib_dir="@LIB_DIR@"
|
||||
lib_dir_set="no"
|
||||
|
||||
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: libiso8601-config [options]
|
||||
Options:
|
||||
[--version]
|
||||
[--libs]
|
||||
[--libdir[=DIR]]
|
||||
[--cflags]
|
||||
[--includedir[=DIR]]
|
||||
EOF
|
||||
exit $1
|
||||
}
|
||||
|
||||
|
||||
|
||||
[ $# -eq 0 ] && usage 1 1>&2
|
||||
|
||||
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case "$1" in
|
||||
-*=*)
|
||||
optarg="$(echo "$1" | sed 's/[-_a-zA-Z0-9]*=//')"
|
||||
;;
|
||||
|
||||
*)
|
||||
optarg=""
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$1" in
|
||||
--libdir=*)
|
||||
lib_dir="${optarg}"
|
||||
lib_dir_set="yes"
|
||||
;;
|
||||
|
||||
--libdir)
|
||||
echo_lib_dir="yes"
|
||||
;;
|
||||
|
||||
--includedir=*)
|
||||
include_dir="${optarg}"
|
||||
include_dir_set="yes"
|
||||
;;
|
||||
|
||||
--includedir)
|
||||
echo_include_dir="yes"
|
||||
;;
|
||||
|
||||
--version)
|
||||
echo "@VERSION@"
|
||||
exit 0
|
||||
;;
|
||||
|
||||
--cflags)
|
||||
[ "${include_dir}" != "/usr/include" ] && includes="-I${include_dir}"
|
||||
echo_cflags="yes"
|
||||
;;
|
||||
|
||||
--libs)
|
||||
echo_libs="yes"
|
||||
;;
|
||||
|
||||
*)
|
||||
usage 1 1>&2
|
||||
;;
|
||||
esac
|
||||
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
|
||||
[ "${echo_prefix}" == "yes" ] && echo "${prefix}"
|
||||
[ "${echo_exec_prefix}" == "yes" ] && echo "${exec_prefix}"
|
||||
[ "${echo_cflags}" == "yes" ] && echo "${dep_cflags} ${includes}"
|
||||
[ "${echo_libs}" == "yes" ] && echo "${dep_libs} -L${lib_dir} -liso8601"
|
||||
true
|
||||
|
||||
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -1,40 +0,0 @@
|
|||
/* libiso8601/src/libiso8601/functions.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.
|
||||
*/
|
||||
|
||||
/* parse.c */
|
||||
int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601_date* latest,
|
||||
struct iso8601_details* details);
|
||||
|
||||
/* 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);
|
||||
void iso8601_to_ts(struct timespec* ts, const struct iso8601_date* date);
|
||||
void iso8601_from_time_t(struct iso8601_date* date, const time_t* t);
|
||||
void iso8601_to_time_t(time_t* t, const struct iso8601_date* date);
|
||||
|
||||
/* calc.c */
|
||||
int iso8601_isleap(int year);
|
||||
void iso8601_to_cal(int* year, int* month, int* day, const struct iso8601_date* date);
|
||||
int iso8601_from_cal(struct iso8601_date* date, int year, int month, int day);
|
||||
void iso8601_to_ord(int* year, int* oday, const struct iso8601_date* date);
|
||||
int iso8601_from_ord(struct iso8601_date* date, int year, int oday);
|
||||
void iso8601_to_week(int* year, int* week, int* wday, const struct iso8601_date* date);
|
||||
int iso8601_from_week(struct iso8601_date* date, int year, int week, int wday);
|
||||
void iso8601_to_clocktime(int* hour, int* min, int* sec, const struct iso8601_date* date);
|
||||
int iso8601_from_clocktime(struct iso8601_date* date, int hour, int min, int sec);
|
||||
|
||||
/* print.c */
|
||||
void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||
const struct iso8601_details* details);
|
||||
|
||||
/* manip.c */
|
||||
void iso8601_add_seconds(struct iso8601_date* date, long seconds);
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -1,35 +0,0 @@
|
|||
/* libiso8601/src/libiso8601/manip.c
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
void iso8601_add_seconds(struct iso8601_date* date, long seconds)
|
||||
{
|
||||
ldiv_t qr;
|
||||
|
||||
switch(date->sec) {
|
||||
case 86400:
|
||||
case 86401:
|
||||
--date->sec;
|
||||
break;
|
||||
}
|
||||
|
||||
qr = ldiv(seconds + date->sec, 86400);
|
||||
date->day += qr.quot;
|
||||
date->sec = qr.rem;
|
||||
if(date->sec < 0) {
|
||||
--date->day;
|
||||
date->sec += 86400;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -1,21 +0,0 @@
|
|||
# libiso8601/src/lib/clib/pkgconf.in
|
||||
#
|
||||
# Metadata file for pkg-config
|
||||
# ( http://www.freedesktop.org/software/pkgconfig/ )
|
||||
#
|
||||
# (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.
|
||||
#
|
||||
|
||||
# Name, description
|
||||
Name: @TODO@
|
||||
Description: @TODO@
|
||||
Version: @VERSION@
|
||||
|
||||
# Requirements
|
||||
Requires:
|
||||
|
||||
# Compilation information
|
||||
Libs: -L@LIBDIR@ -liso8601
|
||||
Cflags: -I@INCLUDEDIR@
|
|
@ -1,17 +1,15 @@
|
|||
# libiso8601/src/libiso8601/soversion
|
||||
#
|
||||
# (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.
|
||||
# Copyright: ©2007–2011, Güralp Systems Ltd.
|
||||
# Author: Laurence Withers <lwithers@guralp.com>
|
||||
# License: GPLv3
|
||||
#
|
||||
|
||||
|
||||
|
||||
# SOMAJOR and SOMINOR are included in the library's soname. They need to
|
||||
# be bumped on a binary-incompatible release. They are both single
|
||||
# integers.
|
||||
SOMAJOR=0
|
||||
SOMINOR=0
|
||||
# SOMAJOR is included in the library's soname, and needs to be bumped
|
||||
# after a binary-incompatible release. It is a single integer.
|
||||
SOMAJOR=1
|
||||
|
||||
# SOMICRO is bumped every time there is a binary-compatible release.
|
||||
SOMICRO=0
|
||||
SOMICRO=10
|
||||
|
|
|
@ -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 values: 86400 == leap second 23:59:60, 86401 == midnight 24:00:00
|
||||
};
|
||||
|
||||
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
|
||||
*/
|
|
@ -0,0 +1 @@
|
|||
app c setisodate sbin
|
|
@ -0,0 +1,45 @@
|
|||
/* libiso8601/src/setisodate/000_TopSource.c
|
||||
*
|
||||
* (c)2007, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv2. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
/* Below are all the includes used throughout the application. */
|
||||
#include <stdio.h>
|
||||
#include "iso8601.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct iso8601_date d;
|
||||
char str[100];
|
||||
|
||||
if(argc != 2) {
|
||||
fputs("Expecting one argument: date/time (in ISO8601 format) to set.\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(iso8601_parse(argv[1], &d, 0, 0)) {
|
||||
fputs("Cannot parse date.\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Setting date to %s.\n",
|
||||
iso8601_print(str, sizeof(str), &d, 0));
|
||||
|
||||
if(iso8601_set_sysclock(&d)) {
|
||||
perror("iso8601_set_sysclock");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,43 @@
|
|||
# These are external variables, and shouldn't clash with anything else
|
||||
# setisodate
|
||||
# setisodate_BUILT
|
||||
#
|
||||
|
||||
build_target libiso8601
|
||||
|
||||
if [ -z ${setisodate_BUILT} ]
|
||||
then
|
||||
setisodate="obj/setisodate"
|
||||
EXTRAS="-std=gnu99 -D_GNU_SOURCE -DAPP_NAME=\"setisodate\" \
|
||||
${libiso8601} ${libiso8601_DEP_CFLAGS} ${libiso8601_DEP_LIBS}"
|
||||
|
||||
echo "Building application ${setisodate}..."
|
||||
|
||||
do_cmd source src/setisodate/build.monolithic || return 1
|
||||
|
||||
MODIFIED=0
|
||||
for test in ${MONOLITHIC_TESTS} ${SRC}
|
||||
do
|
||||
if [ ${test} -nt ${setisodate} ]
|
||||
then
|
||||
MODIFIED=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${MODIFIED} -ne 0 ]
|
||||
then
|
||||
echo " Compiling..."
|
||||
|
||||
do_cmd ${CC} ${CFLAGS} -I obj -o "${setisodate}" ${SRC} ${EXTRAS} || return 1
|
||||
|
||||
print_success "Application built"
|
||||
else
|
||||
print_success "Application up to date"
|
||||
fi
|
||||
|
||||
setisodate_BUILT=1
|
||||
|
||||
fi
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -0,0 +1 @@
|
|||
source src/setisodate/build.app
|
|
@ -0,0 +1 @@
|
|||
source src/setisodate/build.install-app
|
|
@ -0,0 +1,11 @@
|
|||
build_target setisodate
|
||||
|
||||
# make paths (this is for Gentoo in particular)
|
||||
build_dir_tree "${SBINDIR}" || return 1
|
||||
|
||||
# install binary
|
||||
echo "Installing binaries into '${SBINDIR}'"
|
||||
install_file "${setisodate}" "${SBINDIR}" 0755 || return 1
|
||||
print_success "Done"
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -0,0 +1,17 @@
|
|||
# These are external variables, and shouldn't clash with anything else
|
||||
# setisodate_MONOLITHIC
|
||||
#
|
||||
|
||||
SRC="obj/setisodate.c"
|
||||
MONOLITHIC_TESTS="src/setisodate/build.app src/setisodate/build.monolithic"
|
||||
|
||||
if [ -z "${setisodate_MONOLITHIC}" ]
|
||||
then
|
||||
MONOLITHIC_SOURCE="$(find src/setisodate/ -name '*.c' | sort)"
|
||||
make_monolithic ${SRC} C || return 1
|
||||
|
||||
setisodate_MONOLITHIC=1
|
||||
MONOLITHIC_DOC="${MONOLITHIC_DOC} ${SRC}"
|
||||
fi
|
||||
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
|
@ -1 +1 @@
|
|||
c tests tests libiso8601
|
||||
tests c tests libiso8601
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
source src/tests/build.tests
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
|
|
|
@ -6,15 +6,15 @@ build_target libiso8601 || return 1
|
|||
|
||||
if [ -z ${tests_BUILT} ]
|
||||
then
|
||||
LIBS="${libiso8601} "
|
||||
EXTRAS="" # @TODO@ libs, cflags
|
||||
LIBS="${libiso8601} ${libiso8601_DEP_CFLAGS} ${libiso8601_DEP_LIBS} "
|
||||
EXTRAS="-lm"
|
||||
|
||||
echo "Building test programs..."
|
||||
do_cmd mkdir -p obj/tests || return 1
|
||||
|
||||
for SRC in src/tests/*.c
|
||||
do
|
||||
TEST="obj/tests/$(basename ${SRC} | sed -e 's,.c$,,')"
|
||||
TEST="obj/tests/$(basename "${SRC}" ".c")"
|
||||
MODIFIED=0
|
||||
for file in ${LIBS} ${SRC} src/tests/build.tests
|
||||
do
|
||||
|
@ -39,5 +39,4 @@ then
|
|||
tests_BUILT=1
|
||||
fi
|
||||
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
# vim: syntax=sh:expandtab:ts=4:sw=4
|
||||
|
|
|
@ -0,0 +1,285 @@
|
|||
/* libiso8601/src/tests/leap.c
|
||||
*
|
||||
* (c)2007, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv2. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
#include "iso8601.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
int leap_diff(const char* s1, const char* s2, int* diff)
|
||||
{
|
||||
struct iso8601_date d1, d2;
|
||||
|
||||
if(iso8601_parse(s1, &d1, 0, 0) || iso8601_parse(s2, &d2, 0, 0)) {
|
||||
fprintf(stderr, "Unable to parse ``%s'' or ``%s'' (%m).", s1, s2);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*diff = iso8601_leap_elapsed(&d1, &d2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int regression1(void)
|
||||
{
|
||||
struct iso8601_date d;
|
||||
struct iso8601_elapsed elapsed;
|
||||
char s1[30], s2[30], s3[30];
|
||||
int ret = 0, oday;
|
||||
|
||||
iso8601_from_cal(&d, 2005, 12, 31);
|
||||
oday = d.day;
|
||||
d.sec = 0;
|
||||
d.nsec = 0;
|
||||
iso8601_print(s1, sizeof(s1), &d, 0);
|
||||
|
||||
elapsed.sec = 86400;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_add_elapsed(&d, &elapsed);
|
||||
iso8601_print(s2, sizeof(s2), &d, 0);
|
||||
ret |= (d.day != oday) | (d.sec != 86400);
|
||||
|
||||
iso8601_add_elapsed(&d, &elapsed);
|
||||
iso8601_print(s3, sizeof(s3), &d, 0);
|
||||
ret |= (d.day != (oday + 1)) | (d.sec != 86399);
|
||||
|
||||
printf("%s -> %s -> %s\n", s1, s2, s3);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int regression2(void)
|
||||
{
|
||||
struct iso8601_date d;
|
||||
char s1[30], s2[30], s3[30];
|
||||
struct iso8601_elapsed elapsed;
|
||||
int ret = 0, oday;
|
||||
|
||||
iso8601_from_cal(&d, 2005, 12, 31);
|
||||
oday = d.day;
|
||||
d.sec = 86399;
|
||||
d.nsec = 0;
|
||||
iso8601_print(s1, sizeof(s1), &d, 0);
|
||||
|
||||
elapsed.sec = 86400;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_add_elapsed(&d, &elapsed);
|
||||
iso8601_print(s2, sizeof(s2), &d, 0);
|
||||
ret |= (d.day != (oday + 1)) | (d.sec != 86398);
|
||||
|
||||
iso8601_add_elapsed(&d, &elapsed);
|
||||
iso8601_print(s3, sizeof(s3), &d, 0);
|
||||
ret |= (d.day != (oday + 2)) | (d.sec != 86398);
|
||||
|
||||
printf("%s -> %s -> %s\n", s1, s2, s3);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int regression3(void)
|
||||
{
|
||||
struct iso8601_date d;
|
||||
char s1[30], s2[30], s3[30];
|
||||
struct iso8601_elapsed elapsed;
|
||||
int ret = 0, oday;
|
||||
|
||||
iso8601_from_cal(&d, 2005, 12, 31);
|
||||
oday = d.day;
|
||||
d.sec = 86400;
|
||||
d.nsec = 0;
|
||||
iso8601_print(s1, sizeof(s1), &d, 0);
|
||||
|
||||
elapsed.sec = 86400;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_add_elapsed(&d, &elapsed);
|
||||
iso8601_print(s2, sizeof(s2), &d, 0);
|
||||
ret |= (d.day != (oday + 1)) | (d.sec != 86399);
|
||||
|
||||
iso8601_add_elapsed(&d, &elapsed);
|
||||
iso8601_print(s3, sizeof(s3), &d, 0);
|
||||
ret |= (d.day != (oday + 2)) | (d.sec != 86399);
|
||||
|
||||
printf("%s -> %s -> %s\n", s1, s2, s3);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int regression4(void)
|
||||
{
|
||||
struct iso8601_date d;
|
||||
char s1[30], s2[30], s3[30];
|
||||
struct iso8601_elapsed elapsed;
|
||||
int ret = 0, oday;
|
||||
|
||||
iso8601_from_cal(&d, 2006, 1, 1);
|
||||
oday = d.day;
|
||||
d.sec = 86399;
|
||||
d.nsec = 0;
|
||||
iso8601_print(s1, sizeof(s1), &d, 0);
|
||||
|
||||
elapsed.sec = 86400;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_subtract_elapsed(&d, &elapsed);
|
||||
iso8601_print(s2, sizeof(s2), &d, 0);
|
||||
ret |= (d.day != (oday - 1)) | (d.sec != 86400);
|
||||
|
||||
iso8601_subtract_elapsed(&d, &elapsed);
|
||||
iso8601_print(s3, sizeof(s3), &d, 0);
|
||||
ret |= (d.day != (oday - 1)) | (d.sec != 0);
|
||||
|
||||
printf("%s -> %s -> %s\n", s1, s2, s3);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int regression5(void)
|
||||
{
|
||||
struct iso8601_date d;
|
||||
char s1[30], s2[30], s3[30];
|
||||
struct iso8601_elapsed elapsed;
|
||||
int ret = 0, oday;
|
||||
|
||||
iso8601_from_cal(&d, 2006, 1, 2);
|
||||
oday = d.day;
|
||||
d.sec = 86398;
|
||||
d.nsec = 0;
|
||||
iso8601_print(s1, sizeof(s1), &d, 0);
|
||||
|
||||
elapsed.sec = 86400;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_subtract_elapsed(&d, &elapsed);
|
||||
iso8601_print(s2, sizeof(s2), &d, 0);
|
||||
ret |= (d.day != (oday - 1)) | (d.sec != 86398);
|
||||
|
||||
iso8601_subtract_elapsed(&d, &elapsed);
|
||||
iso8601_print(s3, sizeof(s3), &d, 0);
|
||||
ret |= (d.day != (oday - 2)) | (d.sec != 86399);
|
||||
|
||||
printf("%s -> %s -> %s\n", s1, s2, s3);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int regression6(void)
|
||||
{
|
||||
struct iso8601_date d;
|
||||
char s1[30], s2[30], s3[30];
|
||||
struct iso8601_elapsed elapsed;
|
||||
int ret = 0, oday;
|
||||
|
||||
iso8601_from_cal(&d, 2006, 1, 2);
|
||||
oday = d.day;
|
||||
d.sec = 86399;
|
||||
d.nsec = 0;
|
||||
iso8601_print(s1, sizeof(s1), &d, 0);
|
||||
|
||||
elapsed.sec = 86400;
|
||||
elapsed.nsec = 0;
|
||||
iso8601_subtract_elapsed(&d, &elapsed);
|
||||
iso8601_print(s2, sizeof(s2), &d, 0);
|
||||
ret |= (d.day != (oday - 1)) | (d.sec != 86399);
|
||||
|
||||
iso8601_subtract_elapsed(&d, &elapsed);
|
||||
iso8601_print(s3, sizeof(s3), &d, 0);
|
||||
ret |= (d.day != (oday - 2)) | (d.sec != 86400);
|
||||
|
||||
printf("%s -> %s -> %s\n", s1, s2, s3);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct regression_test {
|
||||
const char* name;
|
||||
int (*func)(void);
|
||||
};
|
||||
|
||||
struct regression_test regression_tests[] = {
|
||||
{ "Start of leap day, +86400s", regression1 },
|
||||
{ "Near end of leap day, +86400s", regression2 },
|
||||
{ "End of leap day, +86400s", regression3 },
|
||||
{ "Start of post-leap day, -86400s", regression4 },
|
||||
{ "Near end of post-leap day, -86400s", regression5 },
|
||||
{ "End of post-leap day, -86400s", regression6 },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
int regression(void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct regression_test* test;
|
||||
|
||||
for(test = regression_tests; test->func; ++test) {
|
||||
if(test->func()) {
|
||||
fprintf(stderr, "%s failed.\n", test->name);
|
||||
++ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int ret = 0, diff;
|
||||
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
fputs("Leap second regression test.\n", stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(argc) {
|
||||
case 1:
|
||||
ret = regression();
|
||||
fputs("Alternative use: pass two dates on commandline to see elapsed leap seconds.\n",
|
||||
stdout);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
ret = leap_diff(argv[1], argv[2], &diff);
|
||||
if(!ret) printf("Leap second correction: %d\n", diff);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(!strcmp(argv[1], "--print-summary")) {
|
||||
printf("Leap second regression test.");
|
||||
return 0;
|
||||
}
|
||||
/* fall through */
|
||||
default:
|
||||
ret = 1;
|
||||
fputs("Either zero or two arguments expected.\n", stderr);
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -0,0 +1,369 @@
|
|||
/* libiso8601/src/tests/manip.c
|
||||
*
|
||||
* (c)2007, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv2. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
#include "iso8601.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
/* safe_strtod()
|
||||
* Converts `str' into a double, which it will store in `out'. If an error occurs, returns -1,
|
||||
* else 0 on success.
|
||||
*/
|
||||
int safe_strtod(const char* str, double* out)
|
||||
{
|
||||
char* endp = 0;
|
||||
|
||||
errno = 0;
|
||||
*out = strtod(str, &endp);
|
||||
if(errno || !endp || *endp) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* date_stack
|
||||
* We use a stack of dates and/or periods to implement effectively an RPN manipulator.
|
||||
*/
|
||||
enum date_stack_type {
|
||||
date_stack_type_date,
|
||||
date_stack_type_per
|
||||
};
|
||||
|
||||
struct date_stack {
|
||||
enum date_stack_type type;
|
||||
|
||||
union {
|
||||
struct {
|
||||
struct iso8601_date d;
|
||||
struct iso8601_details det;
|
||||
}date;
|
||||
|
||||
struct iso8601_elapsed per;
|
||||
}u;
|
||||
|
||||
struct date_stack* next;
|
||||
};
|
||||
|
||||
struct date_stack* date_stack_top = 0;
|
||||
int date_stack_size = 0;
|
||||
|
||||
|
||||
|
||||
/* date_stack_push_*()
|
||||
* Routines for pushing an object onto the date stack.
|
||||
*/
|
||||
void date_stack_push_date(const struct iso8601_date* d, const struct iso8601_details* det)
|
||||
{
|
||||
struct date_stack* s;
|
||||
|
||||
s = malloc(sizeof(struct date_stack));
|
||||
s->type = date_stack_type_date;
|
||||
s->u.date.d = *d;
|
||||
s->u.date.det = *det;
|
||||
s->next = date_stack_top;
|
||||
|
||||
date_stack_top = s;
|
||||
++date_stack_size;
|
||||
}
|
||||
|
||||
void date_stack_push_elapsed(const struct iso8601_elapsed* per)
|
||||
{
|
||||
struct date_stack* s;
|
||||
|
||||
s = malloc(sizeof(struct date_stack));
|
||||
s->type = date_stack_type_per;
|
||||
s->u.per = *per;
|
||||
s->next = date_stack_top;
|
||||
|
||||
date_stack_top = s;
|
||||
++date_stack_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* date_stack_pop()
|
||||
* Pops an element from the date stack.
|
||||
*/
|
||||
void date_stack_pop(void)
|
||||
{
|
||||
struct date_stack* next;
|
||||
|
||||
--date_stack_size;
|
||||
next = date_stack_top->next;
|
||||
free(date_stack_top);
|
||||
date_stack_top = next;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* date_stack_pop_date()
|
||||
* Pops a date from the stack, returning non-0 on error (underflow or type mismatch).
|
||||
*/
|
||||
int date_stack_pop_date(struct iso8601_date* d, struct iso8601_details* det)
|
||||
{
|
||||
if(!date_stack_top) {
|
||||
fputs("Stack underflow.\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
if(date_stack_top->type != date_stack_type_date) {
|
||||
fputs("Type mismatch.\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*d = date_stack_top->u.date.d;
|
||||
*det = date_stack_top->u.date.det;
|
||||
date_stack_pop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* date_stack_pop_elapsed()
|
||||
* Pops an elapsed period from the stack, returning non-0 on error (underflow or type mismatch).
|
||||
*/
|
||||
int date_stack_pop_elapsed(struct iso8601_elapsed* per)
|
||||
{
|
||||
if(!date_stack_top) {
|
||||
fputs("Stack underflow.\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
if(date_stack_top->type != date_stack_type_per) {
|
||||
fputs("Type mismatch.\n", stderr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*per = date_stack_top->u.per;
|
||||
date_stack_pop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* date_stack_dump()
|
||||
* Dumps and clears the contents of the date stack.
|
||||
*/
|
||||
void date_stack_dump(void)
|
||||
{
|
||||
while(date_stack_top) {
|
||||
switch(date_stack_top->type) {
|
||||
case date_stack_type_date:
|
||||
fprintf(stderr, "Date (day=%d, sec=%d, nsec=%d)\n",
|
||||
date_stack_top->u.date.d.day, date_stack_top->u.date.d.sec, date_stack_top->u.date.d.nsec);
|
||||
break;
|
||||
|
||||
case date_stack_type_per:
|
||||
fprintf(stderr, "Period (sec=%d, nsec=%d)\n",
|
||||
date_stack_top->u.per.sec, date_stack_top->u.per.nsec);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unknown type %d.\n", date_stack_top->type);
|
||||
break;
|
||||
}
|
||||
date_stack_pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* usage()
|
||||
* Displays help.
|
||||
*/
|
||||
void usage(void)
|
||||
{
|
||||
fputs("Push a date or elapsed time onto the stack by entering it, e.g.:\n"
|
||||
" 2007-07-29 12345.67\n"
|
||||
"Operators:\n"
|
||||
" + (date, period) Advance date by elapsed time, push date.\n"
|
||||
" - (date, period) Regress date by elapsed time, push date.\n"
|
||||
" +* (date, period, num) Advance date by elapsed time multiplied by num, push date.\n"
|
||||
" -* (date, period, num) Regress date by elapsed time multiplied by num, push date.\n"
|
||||
" dp (date, date) Compute difference, print elapsed time.\n"
|
||||
" < (date, date) Prints 1 if first date less than second.\n"
|
||||
" <= (date, date) Prints 1 if first date less than or equal to second.\n"
|
||||
" == (date, date) Prints 1 if dates equal.\n"
|
||||
" p (date) Prints a date.\n"
|
||||
" ds Dump stack.\n"
|
||||
"\n"
|
||||
"Type help for this screen at any point.\n"
|
||||
"\n", stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int parse_command(char* cmd)
|
||||
{
|
||||
struct iso8601_date date, date2;
|
||||
struct iso8601_details details, details2;
|
||||
struct iso8601_elapsed period, num;
|
||||
double period_d;
|
||||
char date_str[40];
|
||||
int ret = 0, sign;
|
||||
|
||||
cmd = strtok(cmd, " \n");
|
||||
while(cmd) {
|
||||
if(!iso8601_parse(cmd, &date, 0, &details)) {
|
||||
date_stack_push_date(&date, &details);
|
||||
|
||||
} else if(!safe_strtod(cmd, &period_d) && period_d >= 0) {
|
||||
period.sec = trunc(period_d);
|
||||
period.nsec = trunc((period_d - period.sec) * 1e9);
|
||||
date_stack_push_elapsed(&period);
|
||||
|
||||
} else if(!strcmp(cmd, "+")) {
|
||||
if(date_stack_pop_elapsed(&period) || date_stack_pop_date(&date, &details)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
iso8601_add_elapsed(&date, &period);
|
||||
date_stack_push_date(&date, &details);
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "-")) {
|
||||
if(date_stack_pop_elapsed(&period) || date_stack_pop_date(&date, &details)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
iso8601_subtract_elapsed(&date, &period);
|
||||
date_stack_push_date(&date, &details);
|
||||
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "+*") || !strcmp(cmd, "-*")) {
|
||||
if(date_stack_pop_elapsed(&num)) {
|
||||
ret = 1;
|
||||
|
||||
} else if(num.nsec) {
|
||||
ret = 1;
|
||||
fputs("Number cannot be fractional.\n", stderr);
|
||||
|
||||
} else {
|
||||
|
||||
if(date_stack_pop_elapsed(&period) || date_stack_pop_date(&date, &details)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
iso8601_add_multiple(&date, &period, ((cmd[0] == '-') ? -1 : 1) * num.sec);
|
||||
date_stack_push_date(&date, &details);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "dp")) {
|
||||
if(date_stack_pop_date(&date, &details) || date_stack_pop_date(&date2, &details2)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
iso8601_difference(&date2, &date, &period, &sign);
|
||||
printf("Difference: %c %lu.%09lu\n",
|
||||
(sign < 0) ? '-' : '+',
|
||||
(unsigned long)period.sec,
|
||||
(unsigned long)period.nsec);
|
||||
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "<")) {
|
||||
if(date_stack_pop_date(&date, &details) || date_stack_pop_date(&date2, &details2)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
printf("%d\n", iso8601_lt(&date2, &date));
|
||||
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "<=")) {
|
||||
if(date_stack_pop_date(&date, &details) || date_stack_pop_date(&date2, &details2)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
printf("%d\n", iso8601_lte(&date2, &date));
|
||||
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "==")) {
|
||||
if(date_stack_pop_date(&date, &details) || date_stack_pop_date(&date2, &details2)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
printf("%d\n", iso8601_eq(&date2, &date));
|
||||
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "p")) {
|
||||
if(date_stack_pop_date(&date, &details)) {
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
iso8601_print(date_str, sizeof(date_str), &date, &details);
|
||||
fputs(date_str, stdout);
|
||||
putc('\n', stdout);
|
||||
}
|
||||
|
||||
} else if(!strcmp(cmd, "ds")) {
|
||||
date_stack_dump();
|
||||
|
||||
} else {
|
||||
fputs("Unrecognised command or argument.\n", stderr);
|
||||
ret = 1;
|
||||
|
||||
}
|
||||
|
||||
cmd = strtok(0, " \n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
char* buf = 0;
|
||||
size_t buf_len = 0;
|
||||
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
printf("Interactive date manipulator. Also evaluates commandline.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* commandline -- evaluate arguments as though interactive */
|
||||
if(argc > 1) {
|
||||
for(ret = 1; ret < argc; ++ret) {
|
||||
if(parse_command(argv[ret])) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
usage();
|
||||
while(!feof(stdin)) {
|
||||
printf("%d >> ", date_stack_size);
|
||||
ret = getline(&buf, &buf_len, stdin);
|
||||
if(ret == -1) break;
|
||||
|
||||
parse_command(buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
|
@ -19,7 +19,7 @@ int do_date(const char* str)
|
|||
char buf[100], buf2[100], buf3[100], buf4[100];
|
||||
|
||||
if(iso8601_parse(str, &earliest, &latest, &details)) {
|
||||
perror("iso8601_parse");
|
||||
fputs("Failed to parse date.\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,8 @@ int do_date(const char* str)
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
int ret = 0, i;
|
||||
char buf[100];
|
||||
char* buf = 0;
|
||||
size_t buf_size;
|
||||
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
printf("One line summary.\n");
|
||||
|
@ -68,7 +69,7 @@ int main(int argc, char* argv[])
|
|||
if(argc == 1) {
|
||||
while(!feof(stdin)) {
|
||||
printf("date >> ");
|
||||
scanf("%s", buf);
|
||||
if(getline(&buf, &buf_size, stdin) < 1) continue;
|
||||
do_date(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ int main(int argc, char* argv[])
|
|||
int ret = 0;
|
||||
struct iso8601_date dt;
|
||||
struct iso8601_details details, details2;
|
||||
char buf[100], buf2[100];
|
||||
char buf[40], buf2[40];
|
||||
const struct test* test;
|
||||
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
|
@ -215,7 +215,11 @@ int main(int argc, char* argv[])
|
|||
iso8601_now(&dt, &details);
|
||||
printf("%-30s %-30s %s\n", "Name", "Basic format", "Extended format");
|
||||
for(test = tests; test->desc; ++test) {
|
||||
memset(buf, 'X', sizeof(buf));
|
||||
memset(buf2, 'X', sizeof(buf2)); /* test null-termination */
|
||||
|
||||
test->do_details(&details2, &details);
|
||||
|
||||
iso8601_print(buf, sizeof(buf), &dt, &details2);
|
||||
++details2.extended;
|
||||
iso8601_print(buf2, sizeof(buf2), &dt, &details2);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* libiso8601/src/tests/???.c
|
||||
/* libiso8601/src/tests/xxx.c
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
* Copyright: ©2007–2011, Güralp Systems Ltd.
|
||||
* Author: Laurence Withers <lwithers@guralp.com>
|
||||
* License: GPLv3
|
||||
*/
|
||||
|
||||
#include "iso8601.h"
|
||||
|
||||
|
@ -12,25 +12,27 @@
|
|||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
printf("One line summary.\n");
|
||||
fputs("One line summary.\n", stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(argc == 1) {
|
||||
// empty argument list
|
||||
/* empty argument list */
|
||||
}
|
||||
|
||||
// TODO
|
||||
/* TODO */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
||||
|
|
17
version
17
version
|
@ -1,19 +1,16 @@
|
|||
# libiso8601/version
|
||||
#
|
||||
# (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.
|
||||
# Copyright: ©2007–2011, Güralp Systems Ltd.
|
||||
# Author: Laurence Withers <lwithers@guralp.com>
|
||||
# License: GPLv3
|
||||
#
|
||||
|
||||
|
||||
|
||||
# VERSION contains the full version number of the library, which is
|
||||
# expected to be in 'major.minor.micro' format. It can optionally be
|
||||
# suffixed with a string.
|
||||
# expected to be in 'major.minor.micro' format.
|
||||
VERMAJOR=0
|
||||
VERMINOR=0
|
||||
VERMICRO=1
|
||||
VEREXTRA=""
|
||||
VERMINOR=3
|
||||
VERMICRO=15
|
||||
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
# vim: expandtab:ts=4:sw=4:syntax=sh
|
||||
|
|
Loading…
Reference in New Issue