Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / tools.c
index e2637cc84737ab7d32f485158767fec240b87efd..c802bbeaf165e4f3762a5b11dd1560db0acb53b9 100644 (file)
@@ -1,5 +1,5 @@
-/* tools.c - NeonServ v5.1
- * 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();
 }