]> jfr.im git - irc/quakenet/newserv.git/blobdiff - helpmod2/hgen.c
nickwatch: Implement hook for messages/notices.
[irc/quakenet/newserv.git] / helpmod2 / hgen.c
index d2c9e3718ce6c97d352e32aef9972cb30a597e49..0e9c33f00f6af49b4869f8a3bf6ad75fc11f3079 100644 (file)
@@ -74,17 +74,21 @@ int strregexp(const char * str, const char * pattern)
 #define TIME_PRINT(elem,marker)\
 if (elem)\
 {\
-    sprintf(buf, " %d%s%n", elem, marker, &tmp);\
-    buf+=tmp;\
+    buf+=sprintf(buf, " %d%s", elem, marker);\
 }\
 
-
+/* This implementation might look a little evil but it does work */
 const char *helpmod_strtime(int total_seconds)
 {
-    static char buffer[64];
-    char *buf = buffer;
+    static int buffer_index = 0;
+    static char buffers[3][64];
+
+    char *buf = buffers[buffer_index];
+    char *buffer = buf;
+
+    int years, months, days, hours, minutes, seconds;
 
-    int years, months, days, hours, minutes, seconds, tmp;
+    buffer_index = (buffer_index+1) % 3;
 
     /* trivial case */
     if (!total_seconds)
@@ -92,8 +96,8 @@ const char *helpmod_strtime(int total_seconds)
 
     if (total_seconds < 0)
     {
-        *buf = '-';
-        buf++;
+       *buf = '-';
+       buf++;
         total_seconds = -total_seconds;
     }
 
@@ -110,7 +114,7 @@ const char *helpmod_strtime(int total_seconds)
     total_seconds %= HDEF_h;
 
     minutes = total_seconds / HDEF_m;
-    total_seconds %= 60;
+    total_seconds %= HDEF_m;
 
     seconds = total_seconds;
 
@@ -121,15 +125,15 @@ const char *helpmod_strtime(int total_seconds)
     TIME_PRINT(minutes, "m");
     TIME_PRINT(seconds, "s");
 
-    return buffer+1;
+    if (*buffer != '-')
+       return buffer+1;
+    else
+        return buffer;
 }
 
 int helpmod_read_strtime(const char *str)
 {
-    int sum = 0;
-    int tmp_sum;
-    int tmp;
-
+    int sum = 0, tmp_sum, tmp;
 
     while (*str)
     {
@@ -196,17 +200,8 @@ int helpmod_is_lame_line(const char *line)
     const char lamechars[] = {(char)2, (char)3, (char)22, (char)31, (char)0};
     if (strpbrk(line, lamechars) != NULL)
         return 1;
-    /*
-     if (strchr(line, (char)2))  bold
-     return 1;
-     if (strchr(line, (char)3))  colour
-        return 1;
-    if (strchr(line, (char)22)) reverse
-        return 1;
-    if (strchr(line, (char)31)) underline
-        return 1;
-*/
-    return 0;
+    else
+       return 0;
 }
 
 int strislower(const char *str)
@@ -241,3 +236,25 @@ int strnumcount(const char *str)
             count++;
     return count;
 }
+
+float helpmod_percentage(int larger, int smaller)
+{
+    if (larger == 0)
+       return 0.0;
+
+    return 100.0 * ((float)smaller / (float)larger);
+}
+
+int helpmod_select(const char *str, const char **strs, int *enums, int count)
+{
+    int i;
+
+    if (count == 0)
+       return -1;
+
+    for (i = 0;i < count;i++)
+       if (!ci_strcmp(strs[i], str))
+            return enums[i];
+
+    return -1;
+}