X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Ftools.c;h=c802bbeaf165e4f3762a5b11dd1560db0acb53b9;hb=bb5692b9cbff069abbf9573c81e86c3cd2061ceb;hp=cce88797ec697c70cc847f352178ed546304c8a3;hpb=47cf5beaf09ce7f94a099ae5907537a2c9bf2c11;p=NeonServV5.git diff --git a/src/tools.c b/src/tools.c index cce8879..c802bbe 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1,5 +1,5 @@ -/* tools.c - NeonServ v5.0 - * Copyright (C) 2011 Philipp Kreil (pk910) +/* tools.c - NeonServ v5.3 + * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -180,7 +180,7 @@ int table_set_bold(struct Table *table, int collum, int bold) { } char **table_end(struct Table *table) { - int row, col, tablewidth = 0, pos,i; + int row, col, tablewidth = 0, pos,i,j,k; if(!table->entrys) return NULL; for(col = 0; col < table->width; col++) { tablewidth += table->maxwidth[col]+1; @@ -196,11 +196,23 @@ char **table_end(struct Table *table) { if(table->col_flags[col] & TABLE_FLAG_COL_BOLD) table->table_lines[row][pos++] = '\002'; i = 0; + j = 0; if(table->contents[row][col]) { for(; i < strlen(table->contents[row][col]); i++) { table->table_lines[row][pos++] = table->contents[row][col][i]; + if(table->contents[row][col][i] == '\002') j++; + else if(table->contents[row][col][i] == '\003') { + j++; + for(k = 1; k < 2; k++) { + if(isdigit(table->contents[row][col][i+k])) + j++; + else + break; + } + } } } + i -= j; if(col < table->width-1) { for(;i < table->maxwidth[col]; i++) { table->table_lines[row][pos++] = ' '; @@ -513,6 +525,32 @@ int isFakeHost(char *host) { return (strlen(p2+1) > 4); } +static unsigned long crc_table[256]; + +static void crc32_init() { + unsigned long crc; + int i, j; + for(i = 0; i < 256; i++) { + crc = i; + for(j = 8; j > 0; j--) { + if(crc & 1) + crc = (crc >> 1) ^ 0xEDB88320L; + else + crc >>= 1; + } + crc_table[i] = crc; + } +} + +unsigned long crc32(const char *text) { + register unsigned long crc = 0xFFFFFFFF; + unsigned int c, i = 0; + while((c = (unsigned int)text[i++]) != 0) + crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_table[(crc^c) & 0xFF]; + return (crc^0xFFFFFFFF); +} + void init_tools() { register_default_language_table(msgtab); + crc32_init(); }