aboutsummaryrefslogtreecommitdiffstats
path: root/find-lang.sh
Commit message (Expand)AuthorAgeFilesLines
* - importOlivier Thauvin2005-04-261-0/+134
esignWork Mageia Installer and base platform for many utilitiesThierry Vignaud [tv]
summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libugly/strftime.c
blob: b7e750ab1026cc07cd95ac8b40bf94b24836e555 (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <sys/types.h>
#include <time.h>

static char *sweekdays[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
static char *weekdays[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
static char *smonths[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
static char *months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
static char *ampm[]={"am","pm","AM","PM"};

static int i2a(char* dest,unsigned int x) {
  register unsigned int tmp=x;
  register int len=0;
  *dest++=tmp/10+'0'; tmp=tmp%10; ++len;
  *dest++=tmp+'0';
  return 2;
}

static int i2as(char* dest,unsigned int x) {
  int len=i2a(dest,x);
  if (*dest=='0') *dest=' ';
  return len;
}

size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) {
  char *t=s;
  const char *src;
  char buf[5];
  while (*format) {
    switch (*format) {
    case 0: break;
    case '%':
      switch (*++format) {
      case '%': *t='%'; ++t; break;
      case 'a': src=sweekdays[tm->tm_wday]; goto append;
      case 'A': src=weekdays[tm->tm_wday]; goto append;
      case 'h':
      case 'b': src=smonths[tm->tm_mon]; goto append;
      case 'B': src=months[tm->tm_mon]; goto append;
      case 'c': t+=strftime(t,max-(t-s),"%b %a %d %k:%M:%S %Z %Y",tm); break;
      case 'C': buf[i2a(buf,(tm->tm_year+1900)/100)]=0; src=buf; goto append;
      case 'd': buf[i2a(buf,tm->tm_mday)]=0; src=buf; goto append;
      case 'e': buf[i2as(buf,tm->tm_mday)]=0; src=buf; goto append;
      case 'H': buf[i2a(buf,tm->tm_hour)]=0; src=buf; goto append;
      case 'I': buf[i2a(buf,tm->tm_hour%12)]=0; src=buf; goto append;
      case 'j': buf[i2a(buf,tm->tm_yday)]=0; src=buf; goto append;
      case 'k': buf[i2as(buf,tm->tm_hour)]=0; src=buf; goto append;
      case 'l': buf[i2as(buf,tm->tm_hour%12)]=0; src=buf; goto append;
      case 'm': buf[i2a(buf,tm->tm_mon+1)]=0; src=buf; goto append;
      case 'M': buf[i2a(buf,tm->tm_min)]=0; src=buf; goto append;
      case 'n': *t='\n'; break;
      case 'p': src=ampm[tm->tm_hour>11?3:2]; goto append;
      case 'P': src=ampm[tm->tm_hour>11?1:0]; goto append;
      case 'r': t+=strftime(t,max-(t-s),"%I:%M:%S %p",tm); break;
      case 'R': t+=strftime(t,max-(t-s),"%H:%M",tm); break;
      case 'S': buf[i2a(buf,tm->tm_sec)]=0; src=buf; goto append;
      case 't': *t='\t'; break;
      case 'T': t+=strftime(t,max-(t-s),"%H:%M:%S",tm); break;
      case 'u': buf[i2a(buf,tm->tm_wday?tm->tm_wday:7)]=0; src=buf; goto append;
      case 'w': buf[i2a(buf,tm->tm_wday)]=0; src=buf; goto append;
      case 'x': t+=strftime(t,max-(t-s),"%b %a %d",tm); break;
      case 'X': t+=strftime(t,max-(t-s),"%k:%M:%S",tm); break;
      case 'y': buf[i2a(buf,tm->tm_year%100)]=0; src=buf; goto append;