3 /* copied from IRCU 2.10.12 match.c */
5 * Compare if a given string (name) matches the given
6 * mask (which can contain wild cards: '*' - match any
7 * number of chars, '?' - match any single character.
12 * Originally by Douglas A Lewis (dalewis@acsu.buffalo.edu)
13 * Rewritten by Timothy Vogelsang (netski), net@astrolink.org
15 int match(const char *mask, const char *name)
17 const char *m = mask, *n = name;
18 const char *m_tmp = mask, *n_tmp = name;
21 for (;;) switch (*m) {
35 /* allow escaping to force capitalization */
40 for (star_p = 0; ; m++) {
51 else if (*m == '\\') {
55 for (n_tmp = n; *n && *n != *m; n++) ;
58 for (n_tmp = n; *n && tolower(*n) != tolower(*m); n++) ;
61 /* and fall through */
65 if (tolower(*m) != tolower(*n))
75 struct Table *table_init(int width, int length, int flags) {
77 struct Table *table = malloc(sizeof(*table));
78 table->contents = malloc(length * sizeof(*table->contents));
79 for(row = 0; row < length; row++) {
80 table->contents[row] = calloc(width, sizeof(*table->contents));
82 table->length = length;
85 table->col_flags = calloc(length, sizeof(int));
87 table->maxwidth = calloc(length, sizeof(int));
91 int table_add(struct Table *table, char **entry) {
93 for(col = 0; col < table->width; col++) {
94 table->contents[table->c_entry][col] = ((table->flags & TABLE_FLAG_USE_POINTER) ? entry[col] : strdup(entry[col]));
95 if(strlen(entry[col]) > table->maxwidth[col])
96 table->maxwidth[col] = strlen(entry[col]);
101 int table_set_bold(struct Table *table, int collum, int bold) {
103 table->col_flags[collum] |= TABLE_FLAG_COL_BOLD;
105 table->col_flags[collum] &= ~TABLE_FLAG_COL_BOLD;
108 char **table_end(struct Table *table) {
109 int row, col, tablewidth, pos,i;
110 if(table->table) return table->table;
111 table->table = malloc(table->length * sizeof(*table->table));
112 for(col = 0; col < table->width; col++) {
113 tablewidth += table->maxwidth[col]+1;
114 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
117 for(row = 0; row < table->row; row++) {
118 table->table[row] = malloc(tablewidth * sizeof(*table->table[row]))
120 for(col = 0; col < table->width; col++) {
121 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
122 table->table[row][pos++] = '\002';
123 for(i = 0; i < strlen(table->contents[row][col]); i++) {
124 table->table[row][pos++] = table->contents[row][col][i];
126 for(;i < table->maxwidth[col]; i++) {
127 table->table[row][pos++] = ' ';
129 if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
130 table->table[row][pos++] = '\002';
131 if(col < table->width-1)
132 table->table[row][pos++] = ' ';
134 table->table[row][pos++] = '\0';
140 void table_free(struct Table *table) {
142 for(row = 0; row < length; row++) {
143 if(!(table->flags & TABLE_FLAG_USE_POINTER)) {
144 for(col = 0; col < table->width; col++) {
145 free(table->contents[row][col]);
148 free(table->contents[row]);
150 free(table->contents);
151 free(table->col_flags);
152 free(table->maxwidth);
154 for(row = 0; row < length; row++) {
155 free(table->table[row]);