File: hodie.c

package info (click to toggle)
hodie 1.4-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 144 kB
  • ctags: 104
  • sloc: ansic: 1,132; makefile: 75
file content (156 lines) | stat: -rw-r--r-- 3,034 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "includes.h"

const char* AUC[3]={"ab urbe condita","AUC","ab urbe condita"};

int
main(int argc, char** argv)
{
    char sec[16],min[16],hrs[16],day[16],mon[16],year[16],verbose[80];
    struct tm* p_ts;
    time_t t;
    int i, auc_base;
    short numerals, auc, leap, custom, ad;
    mode m;
    verb_struct verbosity;

    verbosity.year=0;
    verbosity.day=0;
    numerals=1;
    auc=0;
    leap=0;
    custom=0;
    auc_base=0;
    ad=0;

    t=time(NULL);
    p_ts=localtime(&t);

    if(argc!=1)
    {
	for(i=1; i<argc; i++)
	{
	    if(strcmp(argv[i],"-h")==0 || strcmp(argv[i],"--help")==0)
	    {
		print_usage();
		return 0;
	    }
	    else if(strcmp(argv[i],"--version")==0)
	    {
		print_version();
		exit(0);
	    }
	    else if(strcmp(argv[i],"-ad")==0 || strcmp(argv[i],"--ante-diem")==0)
		ad=1;
	    else if(strcmp(argv[i],"-n")==0 || strcmp(argv[i],"--numerals")==0)
		numerals=0;
	    else if((strcmp(argv[i],"-v")==0
		     || strcmp(argv[i],"--verbose")==0))
	    {
		if(verbosity.day==1)
		    verbosity.year=1;
		else
		    verbosity.day=1;
	    }
	    else if(strcmp(argv[i],"-vv")==0 || 
		    strcmp(argv[i],"--extremely-verbose")==0)
	    {
		verbosity.day=1;
		verbosity.year=1;
	    }
	    else if(strcmp(argv[i],"-c")==0 || 
		    strcmp(argv[i],"--classic")==0 ||
		    strcmp(argv[i],"--auc")==0)
	    {
		    auc=1;
		    auc_base=753;
	    }
	    else if(strcmp(argv[i],"-r")==0 ||
		     strcmp(argv[i],"--republican")==0)
	    {
		if(
		    (i+1<argc) &&
		    (
			isdigit(*(argv[i])) || 
			(
			    (*(argv[i])=='-') && 
			    isdigit(*(argv[i+1]))
			    )
			)
		    )
		{
		    i++;
		    auc_base=-atoi(argv[i]);
		    auc=1;
		}
		else
		{
		    fprintf(stderr,"%s\n",ERR_NO_REP);
		    exit(-1);
		}
	    }
	    else if(strcmp(argv[i],"-d")==0 || strcmp(argv[i],"--date")==0)
	    {
		i=parse_date(argc,argv,i,p_ts);
		custom=1;
	    }
	    else if(strcmp(argv[i],"-x")==0 || 
		    strcmp(argv[i],"--force-numerals")==0)
		numerals=-1;
	    else
	    {
		print_usage();
		return 0;
	    }
	}
    }    

    if(hodie_isleap(p_ts->tm_year)==1)
       leap=1;

    if(custom==0)
    {
	p_ts->tm_year=p_ts->tm_year+auc_base+1900;
    }
    
    p_ts->tm_mon++;


/* Setup the mode struct */
    m.numeral=1;
    
    to_roman(p_ts->tm_sec,sec,m);
    to_roman(p_ts->tm_min,min,m);
    to_roman(p_ts->tm_hour,hrs,m);
    to_roman(p_ts->tm_mday,day,m);
    to_roman(p_ts->tm_mon,mon,m);
    to_roman(p_ts->tm_year,year,m);

    date_to_roman(p_ts, verbose, verbosity, ad, leap);

    if(numerals!=0 && auc!=0)
    {
	printf("Hodie %s %s est\n",verbose,AUC[verbosity.day+1]);
    }
    else if(numerals!=0)
    {
	printf("Hodie %s est\n",verbose);
    }

    if(numerals==-1) /* The only case where both numerals and text exist */
	printf("\n");

    if(numerals < 1)
    {
	if(auc!=0)
	    printf("%s/%s-%s %s\n%s:%s:%s\n", 
		   day,mon,year,AUC[verbosity.day+1],hrs,min,sec);
	else
	    printf("%s/%s-%s\n%s:%s:%s\n", 
		   day,mon,year,hrs,min,sec);
    }	
    return 0;
}