75 lines
1.6 KiB
C
75 lines
1.6 KiB
C
![]() |
/* libiso8601/src/tests/parser.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"
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
|
||
|
|
||
|
int do_date(const char* str)
|
||
|
{
|
||
|
struct iso8601_date earliest, latest;
|
||
|
struct iso8601_details details;
|
||
|
char buf[100], buf2[100];
|
||
|
|
||
|
if(iso8601_parse(str, &earliest, &latest, &details)) {
|
||
|
perror("iso8601_parse");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
iso8601_print(buf, sizeof(buf), &earliest, &details);
|
||
|
iso8601_print(buf2, sizeof(buf2), &latest, &details);
|
||
|
|
||
|
printf("Results for ``%s'':\n"
|
||
|
" Earliest: day=%d, sec=%05d, nsec=%09d; %s\n"
|
||
|
" Latest : day=%d, sec=%05d, nsec=%09d; %s\n"
|
||
|
" Details : date_prec=%d, time_prec=%d, extended=%d, tz_sec=%d\n"
|
||
|
"\n",
|
||
|
str,
|
||
|
earliest.day, earliest.sec, earliest.nsec, buf,
|
||
|
latest.day, latest.sec, latest.nsec, buf2,
|
||
|
details.date_prec, details.time_prec, details.extended, details.tz_sec);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
int main(int argc, char* argv[])
|
||
|
{
|
||
|
int ret = 0, i;
|
||
|
char buf[100];
|
||
|
|
||
|
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||
|
printf("One line summary.\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if(argc == 1) {
|
||
|
while(!feof(stdin)) {
|
||
|
printf("date >> ");
|
||
|
scanf("%s", buf);
|
||
|
do_date(buf);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
for(i = 1; i < argc; ++i) {
|
||
|
ret |= do_date(argv[i]);
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
/* options for text editors
|
||
|
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||
|
vim: expandtab:ts=4:sw=4
|
||
|
*/
|