5 static const struct default_language_entry msgtab[] = {
6 {"TIME_MASK_2_ITEMS", "%s and %s"},
7 {"TIME_MASK_3_ITEMS", "%s, %s and %s"},
9 {"TIME_YEARS", "years"},
10 {"TIME_MONTH", "month"},
11 {"TIME_MONTHS", "months"},
12 {"TIME_WEEK", "week"},
13 {"TIME_WEEKS", "weeks"},
15 {"TIME_DAYS", "days"},
16 {"TIME_HOUR", "hour"},
17 {"TIME_HOURS", "hours"},
18 {"TIME_MINUTE", "minute"},
19 {"TIME_MINUTES", "minutes"},
20 {"TIME_SECOND", "second"},
21 {"TIME_SECONDS", "seconds"},
25 /* copied from IRCU 2.10.12 match.c */
27 * Compare if a given string (name) matches the given
28 * mask (which can contain wild cards: '*' - match any
29 * number of chars, '?' - match any single character.
34 * Originally by Douglas A Lewis (dalewis@acsu.buffalo.edu)
35 * Rewritten by Timothy Vogelsang (netski), net@astrolink.org
37 int match(const char *mask, const char *name)
39 const char *m = mask, *n = name;
40 const char *m_tmp = mask, *n_tmp = name;
43 for (;;) switch (*m) {
57 /* allow escaping to force capitalization */
62 for (star_p = 0; ; m++) {
73 else if (*m == '\\') {
77 for (n_tmp = n; *n && *n != *m; n++) ;
80 for (n_tmp = n; *n && tolower(*n) != tolower(*m); n++) ;
83 /* and fall through */
87 if (tolower(*m) != tolower(*n))
97 struct Table *table_init(int width, int length, int flags) {
99 struct Table *table = malloc(sizeof(*table));
100 table->contents = malloc(length * sizeof(*table->contents));
101 for(row = 0; row < length; row++) {
102 table->contents[row] = calloc(width, sizeof(*table->contents[row]));
104 table->length = length;
105 table->width = width;
106 table->flags = flags;
107 table->col_flags = calloc(length, sizeof(int));
109 table->maxwidth = calloc(length, sizeof(int));
110 table->table_lines = NULL;
114 int table_add(struct Table *table, char **entry) {
116 if(table->entrys == table->length) return 0;
117 for(col = 0; col < table->width; col++) {
118 table->contents[table->entrys][col] = ((table->flags & TABLE_FLAG_USE_POINTER) ? entry[col] : strdup(entry[col]));
119 if(strlen(entry[col]) > table->maxwidth[col])
120 table->maxwidth[col] = strlen(entry[col]);
126 int table_set_bold(struct Table *table, int collum, int bold) {
128 table->col_flags[collum] |= TABLE_FLAG_COL_BOLD;
130 table->col_flags[collum] &= ~TABLE_FLAG_COL_BOLD;
134 char **table_end(struct Table *table) {
135 int row, col, tablewidth = 0, pos,i;
136 if(!table->entrys) return NULL;
137 for(col = 0; col < table->width; col++) {
138 tablewidth += table->maxwidth[col]+1;
139 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
142 table->table_lines = malloc(table->entrys * sizeof(table->table_lines));
143 for(row = 0; row < table->entrys; row++) {
144 table->table_lines[row] = malloc(tablewidth * sizeof(*table->table_lines[row]));
146 for(col = 0; col < table->width; col++) {
147 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
148 table->table_lines[row][pos++] = '\002';
149 for(i = 0; i < strlen(table->contents[row][col]); i++) {
150 table->table_lines[row][pos++] = table->contents[row][col][i];
152 if(col < table->width-1) {
153 for(;i < table->maxwidth[col]; i++) {
154 table->table_lines[row][pos++] = ' ';
156 table->table_lines[row][pos++] = ' ';
158 table->table_lines[row][pos++] = '\0';
160 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
161 table->table_lines[row][pos++] = '\002';
164 return table->table_lines;
167 void table_free(struct Table *table) {
169 for(row = 0; row < table->length; row++) {
170 if(!(table->flags & TABLE_FLAG_USE_POINTER) && table->entrys > row) {
171 for(col = 0; col < table->width; col++) {
172 free(table->contents[row][col]);
175 free(table->contents[row]);
177 free(table->contents);
178 free(table->col_flags);
179 free(table->maxwidth);
180 if(table->table_lines) {
181 for(row = 0; row < table->entrys; row++) {
182 free(table->table_lines[row]);
184 free(table->table_lines);
189 char* timeToStr(struct UserNode *user, int seconds, int items, char *buf) {
190 char item[items][MAXLEN];
192 if(citem != items && seconds >= 31536000) { //60*60*24*365 = 31536000
194 tmp = seconds / 31536000;
195 sprintf(item[citem++], "%d %s", tmp, get_language_string(user, tmp == 1 ? "TIME_YEAR" : "TIME_YEARS"));
196 seconds -= tmp * 31536000;
198 if(citem != items && seconds >= 86400) { //60*60*24 = 86400
199 tmp = seconds / 86400;
200 sprintf(item[citem++], "%d %s", tmp, get_language_string(user, tmp == 1 ? "TIME_DAY" : "TIME_DAYS"));
201 seconds -= tmp * 86400;
203 if(citem != items && seconds >= 3600) { //60*60 = 3600
204 tmp = seconds / 3600;
205 sprintf(item[citem++], "%d %s", tmp, get_language_string(user, tmp == 1 ? "TIME_HOUR" : "TIME_HOURS"));
206 seconds -= tmp * 3600;
208 if(citem != items && seconds >= 60) {
210 sprintf(item[citem++], "%d %s", tmp, get_language_string(user, tmp == 1 ? "TIME_MINUTE" : "TIME_MINUTES"));
213 if(citem != items && seconds >= 1) {
214 sprintf(item[citem++], "%d %s", seconds, get_language_string(user, seconds == 1 ? "TIME_SECOND" : "TIME_SECONDS"));
217 build_language_string(user, buf, "TIME_MASK_2_ITEMS", item[0], item[1]);
218 } else if(citem == 3) {
219 build_language_string(user, buf, "TIME_MASK_3_ITEMS", item[0], item[1], item[2]);
222 for(i = 0; i < citem; i++) {
223 for(ii = 0; ii < strlen(item[i]); ii++) {
224 buf[p++] = item[i][ii];
233 int strToTime(struct UserNode *user, char *str) {
235 * y = year = 365 days
236 * M = month = 30 days
243 int total_time = 0, cvalue;
245 int unit_multiplikator;
248 while(*p && isdigit(*p)) //get the value
252 cvalue = isdigit(*str) ? atoi(str) : 0;
255 while(*p && !isdigit(*p)) //get the unit
259 if(p - str > 1) { //unit has more than one char
260 if(!stricmp(str, "year") || !stricmp(str, "year") || !stricmp(str, get_language_string(user, "TIME_YEAR")) || !stricmp(str, get_language_string(user, "TIME_YEARS")))
261 unit_multiplikator = 31536000; //60*60*24*365 = 31536000
262 else if(!stricmp(str, "month") || !stricmp(str, "months") || !stricmp(str, get_language_string(user, "TIME_MONTH")) || !stricmp(str, get_language_string(user, "TIME_MONTHS")))
263 unit_multiplikator = 2592000; //60*60*24*30 = 2592000
264 else if(!stricmp(str, "week") || !stricmp(str, "weeks") || !stricmp(str, get_language_string(user, "TIME_WEEK")) || !stricmp(str, get_language_string(user, "TIME_WEEKS")))
265 unit_multiplikator = 604800; //60*60*24*7 = 604800
266 else if(!stricmp(str, "day") || !stricmp(str, "days") || !stricmp(str, get_language_string(user, "TIME_DAY")) || !stricmp(str, get_language_string(user, "TIME_DAYS")))
267 unit_multiplikator = 86400; //60*60*24 = 86400
268 else if(!stricmp(str, "hour") || !stricmp(str, "hours") || !stricmp(str, get_language_string(user, "TIME_HOUR")) || !stricmp(str, get_language_string(user, "TIME_HOURS")))
269 unit_multiplikator = 3600; //60*60 = 3600
270 else if(!stricmp(str, "minute") || !stricmp(str, "minutes") || !stricmp(str, "min") || !stricmp(str, "mins") || !stricmp(str, get_language_string(user, "TIME_MINUTE")) || !stricmp(str, get_language_string(user, "TIME_MINUTES")))
271 unit_multiplikator = 60;
273 unit_multiplikator = 1;
277 unit_multiplikator = 31536000; //60*60*24*365 = 31536000
280 unit_multiplikator = 2592000; //60*60*24*30 = 2592000
283 unit_multiplikator = 604800; //60*60*24*7 = 604800
286 unit_multiplikator = 86400; //60*60*24 = 86400
289 unit_multiplikator = 3600; //60*60 = 3600
292 unit_multiplikator = 60;
295 unit_multiplikator = 1;
299 total_time += (cvalue * unit_multiplikator);
308 register_default_language_table(msgtab);