X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2Ftools.c;h=71cd40d756b6858f272bb5d123cc60a8c8d4d821;hp=43f27cd35ac052148a7c39247aaeea4dbf78a0b2;hb=c575e458c6257e75b97884847143b20965a5dfda;hpb=4c155eb74b522f6e751ce7a484154fb467600174 diff --git a/src/tools.c b/src/tools.c index 43f27cd..71cd40d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1,3 +1,19 @@ +/* tools.c - NeonServ v5.2 + * Copyright (C) 2011 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "tools.h" #include "UserNode.h" #include "ChanNode.h" @@ -106,9 +122,9 @@ struct Table *table_init(int width, int length, int flags) { table->length = length; table->width = width; table->flags = flags; - table->col_flags = calloc(length, sizeof(int)); + table->col_flags = calloc(width, sizeof(int)); table->entrys = 0; - table->maxwidth = calloc(length, sizeof(int)); + table->maxwidth = calloc(width, sizeof(int)); table->table_lines = NULL; return table; } @@ -179,16 +195,11 @@ char **table_end(struct Table *table) { if(!(table->col_flags[col] & TABLE_FLAG_COL_CONTENTS)) continue; if(table->col_flags[col] & TABLE_FLAG_COL_BOLD) table->table_lines[row][pos++] = '\002'; + i = 0; if(table->contents[row][col]) { - for(i = 0; i < strlen(table->contents[row][col]); i++) { + for(; i < strlen(table->contents[row][col]); i++) { table->table_lines[row][pos++] = table->contents[row][col][i]; } - } else { - i = 4; - table->table_lines[row][pos++] = 'N'; - table->table_lines[row][pos++] = 'U'; - table->table_lines[row][pos++] = 'L'; - table->table_lines[row][pos++] = 'L'; } if(col < table->width-1) { for(;i < table->maxwidth[col]; i++) { @@ -383,6 +394,7 @@ void flushModeBuffer(struct ModeBuffer *modeBuf) { char modeStr[MAXMODES+3]; int modePos = 0; char paramStr[MAXLEN]; + *paramStr = '\0'; int paramPos = 0; int i; if(modeBuf->addCount) { @@ -501,6 +513,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(); }