~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to crm/admin/test.iso8601.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * Copyright (C) 2005 Andrew Beekhof <andrew@beekhof.net>
3
 
 * 
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public
6
 
 * License as published by the Free Software Foundation; either
7
 
 * version 2.1 of the License, or (at your option) any later version.
8
 
 * 
9
 
 * This software is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 * General Public License for more details.
13
 
 * 
14
 
 * You should have received a copy of the GNU General Public
15
 
 * License along with this library; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
 */
18
 
 
19
 
#include <lha_internal.h>
20
 
#include <crm/common/iso8601.h>
21
 
 
22
 
#define OPTARGS "V?d:p:D:WOLn"
23
 
 
24
 
char command = 0;
25
 
 
26
 
static void
27
 
usage(int rc) 
28
 
{
29
 
        fprintf(stderr, "Usage: iso8601 [-(O|W|L)] -(n|d|p|D) <string> \n");
30
 
        fprintf(stderr, "Input Options:\n");
31
 
        fprintf(stderr, "\t-n Display the current date/time\n");
32
 
        fprintf(stderr, "\t-d Parse an ISO8601 date/time.  Eg. '2005-01-20 00:30:00 +01:00' or '2005-040'\n");
33
 
        fprintf(stderr, "\t-p Parse an ISO8601 date/time interval/period (wth start time).  Eg. '2005-040/2005-043'\n");
34
 
        fprintf(stderr, "\t-D Parse an ISO8601 date/time duration (wth start time). Eg. '2005-040/P1M'\n");
35
 
        fprintf(stderr, "\nOutput Options:\n");
36
 
        fprintf(stderr, "\tBy default, shows the result in 'universal' date/time\n");
37
 
        fprintf(stderr, "\t-L  Show result as a 'local' date/time\n");
38
 
        fprintf(stderr, "\t-O  Show result as an 'ordinal' date/time\n");
39
 
        fprintf(stderr, "\t-W  Show result as an 'calendar week' date/time\n");
40
 
        fprintf(stderr, "\nFor more information on the ISO8601 standard, see: http://en.wikipedia.org/wiki/ISO_8601\n");
41
 
        exit(rc);
42
 
}
43
 
 
44
 
int
45
 
main(int argc, char **argv)
46
 
{
47
 
        int argerr = 0;
48
 
        int flag;
49
 
        int print_options = 0;
50
 
        char *input_s = NULL;
51
 
        char *mutable_s = NULL;
52
 
        
53
 
        crm_log_init("iso8601", LOG_INFO, FALSE, TRUE, 0, NULL);
54
 
        
55
 
        if(argc < 2) {
56
 
                argerr++;
57
 
        }
58
 
 
59
 
        while (1) {
60
 
                flag = getopt(argc, argv, OPTARGS);
61
 
                if (flag == -1)
62
 
                        break;
63
 
 
64
 
                switch(flag) {
65
 
                        case 'V':
66
 
                                cl_log_enable_stderr(TRUE);
67
 
                                alter_debug(DEBUG_INC);
68
 
                                break;
69
 
                        case '?':
70
 
                                usage(0);
71
 
                                break;
72
 
                        case 'n':
73
 
                                command = flag;
74
 
                                break;
75
 
                        case 'd':
76
 
                        case 'p':
77
 
                        case 'D':
78
 
                                command = flag;
79
 
                                input_s = crm_strdup(optarg);
80
 
                                break;
81
 
                        case 'W':
82
 
                                print_options |= ha_date_weeks;
83
 
                                break;
84
 
                        case 'O':
85
 
                                print_options |= ha_date_ordinal;
86
 
                                break;
87
 
                        case 'L':
88
 
                                print_options |= ha_log_local;
89
 
                                break;
90
 
                }
91
 
        }
92
 
 
93
 
        if(input_s == NULL && command != 'n') {
94
 
                usage(1);
95
 
        }
96
 
        
97
 
        mutable_s = input_s;
98
 
 
99
 
        if(command == 'd') {
100
 
                ha_time_t *date_time = parse_date(&mutable_s);
101
 
                if(date_time == NULL) {
102
 
                        fprintf(stderr, "Invalid date/time specified: %s\n", input_s);
103
 
                        usage(1);
104
 
                }
105
 
                log_date(LOG_INFO, "parsed", date_time,
106
 
                         print_options|ha_log_date|ha_log_time);
107
 
                
108
 
        } else if(command == 'p') {
109
 
                ha_time_period_t *interval = parse_time_period(&mutable_s);
110
 
                if(interval == NULL) {
111
 
                        fprintf(stderr, "Invalid interval specified: %s\n", input_s);
112
 
                        usage(1);
113
 
                }
114
 
                log_time_period(LOG_INFO, interval,
115
 
                                print_options|ha_log_date|ha_log_time);
116
 
                
117
 
        } else if(command == 'D') {
118
 
                ha_time_t *duration = parse_time_duration(&mutable_s);
119
 
                if(duration == NULL) {
120
 
                        fprintf(stderr, "Invalid duration specified: %s\n", input_s);
121
 
                        usage(1);
122
 
                }
123
 
                log_date(LOG_INFO, "Duration", duration,
124
 
                         print_options|ha_log_date|ha_log_time|ha_log_local);
125
 
 
126
 
        } else if(command == 'n') {
127
 
                ha_time_t *now = new_ha_date(TRUE);
128
 
                if(now == NULL) {
129
 
                        fprintf(stderr, "Internal error: couldnt determin 'now' !\n");
130
 
                        usage(1);
131
 
                }
132
 
                log_date(LOG_INFO, "Current date/time", now,
133
 
                         print_options|ha_log_date|ha_log_time);
134
 
        }
135
 
        
136
 
        return 0;
137
 
}