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"},
8 {"TIME_YEAR", "%d year"},
9 {"TIME_YEARS", "%d years"},
10 {"TIME_DAY", "%d day"},
11 {"TIME_DAYS", "%d days"},
12 {"TIME_HOUR", "%d hour"},
13 {"TIME_HOURS", "%d hours"},
14 {"TIME_MINUTE", "%d minute"},
15 {"TIME_MINUTES", "%d minutes"},
16 {"TIME_SECOND", "%d second"},
17 {"TIME_SECONDS", "%d seconds"},
21 /* copied from IRCU 2.10.12 match.c */
23 * Compare if a given string (name) matches the given
24 * mask (which can contain wild cards: '*' - match any
25 * number of chars, '?' - match any single character.
30 * Originally by Douglas A Lewis (dalewis@acsu.buffalo.edu)
31 * Rewritten by Timothy Vogelsang (netski), net@astrolink.org
33 int match(const char *mask, const char *name)
35 const char *m = mask, *n = name;
36 const char *m_tmp = mask, *n_tmp = name;
39 for (;;) switch (*m) {
53 /* allow escaping to force capitalization */
58 for (star_p = 0; ; m++) {
69 else if (*m == '\\') {
73 for (n_tmp = n; *n && *n != *m; n++) ;
76 for (n_tmp = n; *n && tolower(*n) != tolower(*m); n++) ;
79 /* and fall through */
83 if (tolower(*m) != tolower(*n))
93 struct Table *table_init(int width, int length, int flags) {
95 struct Table *table = malloc(sizeof(*table));
96 table->contents = malloc(length * sizeof(*table->contents));
97 for(row = 0; row < length; row++) {
98 table->contents[row] = calloc(width, sizeof(*table->contents[row]));
100 table->length = length;
101 table->width = width;
102 table->flags = flags;
103 table->col_flags = calloc(length, sizeof(int));
105 table->maxwidth = calloc(length, sizeof(int));
106 table->table_lines = NULL;
110 int table_add(struct Table *table, char **entry) {
112 if(table->entrys == table->length) return 0;
113 for(col = 0; col < table->width; col++) {
114 table->contents[table->entrys][col] = ((table->flags & TABLE_FLAG_USE_POINTER) ? entry[col] : strdup(entry[col]));
115 if(strlen(entry[col]) > table->maxwidth[col])
116 table->maxwidth[col] = strlen(entry[col]);
122 int table_set_bold(struct Table *table, int collum, int bold) {
124 table->col_flags[collum] |= TABLE_FLAG_COL_BOLD;
126 table->col_flags[collum] &= ~TABLE_FLAG_COL_BOLD;
130 char **table_end(struct Table *table) {
131 int row, col, tablewidth = 0, pos,i;
132 if(!table->entrys) return NULL;
133 for(col = 0; col < table->width; col++) {
134 tablewidth += table->maxwidth[col]+1;
135 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
138 table->table_lines = malloc(table->entrys * sizeof(table->table_lines));
139 for(row = 0; row < table->entrys; row++) {
140 table->table_lines[row] = malloc(tablewidth * sizeof(*table->table_lines[row]));
142 for(col = 0; col < table->width; col++) {
143 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
144 table->table_lines[row][pos++] = '\002';
145 for(i = 0; i < strlen(table->contents[row][col]); i++) {
146 table->table_lines[row][pos++] = table->contents[row][col][i];
148 for(;i < table->maxwidth[col]; i++) {
149 table->table_lines[row][pos++] = ' ';
151 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
152 table->table_lines[row][pos++] = '\002';
153 if(col < table->width-1)
154 table->table_lines[row][pos++] = ' ';
156 table->table_lines[row][pos++] = '\0';
159 return table->table_lines;
162 void table_free(struct Table *table) {
164 for(row = 0; row < table->length; row++) {
165 if(!(table->flags & TABLE_FLAG_USE_POINTER) && table->entrys > row) {
166 for(col = 0; col < table->width; col++) {
167 free(table->contents[row][col]);
170 free(table->contents[row]);
172 free(table->contents);
173 free(table->col_flags);
174 free(table->maxwidth);
175 if(table->table_lines) {
176 for(row = 0; row < table->entrys; row++) {
177 free(table->table_lines[row]);
179 free(table->table_lines);
184 int timeToStr(struct UserNode *user, int seconds, int items, char *buf) {
187 if(citem != items && seconds >= 31536000) { //60*60*24*365 = 31536000
189 tmp = seconds / 31536000;
190 item[citem++] = build_language_string(user, NULL, (tmp == 1 ? "TIME_YEAR" : "TIME_YEARS"), tmp);
191 seconds -= tmp * 31536000;
193 if(citem != items && seconds >= 86400) { //60*60*24 = 86400
194 tmp = seconds / 86400;
195 item[citem++] = build_language_string(user, NULL, (tmp == 1 ? "TIME_DAY" : "TIME_DAYS"), tmp);
196 seconds -= tmp * 86400;
198 if(citem != items && seconds >= 3600) { //60*60 = 86400
199 tmp = seconds / 3600;
200 item[citem++] = build_language_string(user, NULL, (tmp == 1 ? "TIME_HOUR" : "TIME_HOURS"), tmp);
201 seconds -= tmp * 3600;
203 if(citem != items && seconds >= 60) {
205 item[citem++] = build_language_string(user, NULL, (tmp == 1 ? "TIME_MINUTE" : "TIME_MINUTES"), tmp);
208 if(citem != items && seconds >= 1) {
209 item[citem++] = build_language_string(user, NULL, (seconds == 1 ? "TIME_SECOND" : "TIME_SECONDS"), seconds);
212 build_language_string(user, buf, "TIME_MASK_2_ITEMS", item[0], item[1]);
213 } else if(items == 3) {
214 build_language_string(user, buf, "TIME_MASK_3_ITEMS", item[0], item[1], item[2]);
217 for(i = 0; i < items; i++) {
218 for(ii = 0; ii < strlen(item[i]); ii++) {
219 buf[p++] = item[i][ii];
232 register_default_language_table(msgtab);