]> jfr.im git - irc/quakenet/newserv.git/blobdiff - lib/irc_string.c
BUILD: add require-all build mode
[irc/quakenet/newserv.git] / lib / irc_string.c
index 688c466de3f22979a91d2e98912b2d5ce0badb25..56e6b7b85d06fd802b665567bdc73165ecd1c217 100644 (file)
@@ -122,7 +122,7 @@ int match2patterns(const char *patrn, const char *string) {
 /*  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or      */
 /*  code or tables extracted from it, as desired without restriction.    */
 /* Modified by Fox: no more length parameter, always does the whole string */
-unsigned long crc32(const char *s) {
+unsigned long irc_crc32(const char *s) {
   const char *cp;
   unsigned long crc32val;
   
@@ -134,7 +134,7 @@ unsigned long crc32(const char *s) {
 }
 
 /* Case insensitive version of the above */
-unsigned long crc32i(const char *s) {
+unsigned long irc_crc32i(const char *s) {
   const char *cp;
   unsigned long crc32val;
   
@@ -232,12 +232,14 @@ const char *IPlongtostr(unsigned long IP) {
 /*
  * longtoduration: 
  *  Converts a specified number of seconds into a duration string.  
- *  format: 0 for the "/stats u" compatible output, 1 for more human-friendly output.
+ *  format: 0 for the "/stats u" compatible output, 1 for more
+ *  human-friendly output (that is sometimes format 0), and
+ *  2 for a different human-friendly output.
  */
 
 const char *longtoduration(unsigned long interval, int format) {
   int days,hours,minutes,seconds;
-  static char outstring[50];
+  static char outstring[100];
   int pos=0;
 
   seconds=interval%60;
@@ -245,18 +247,35 @@ const char *longtoduration(unsigned long interval, int format) {
   hours=(interval%(3600*24))/3600;
   days=interval/(3600*24);
 
-  if (days>0 || format==0) {
-    sprintf(outstring,"%d day%s, %02d:%02d:%02d",
-            days,(days==1)?"":"s",hours,minutes,seconds);
+  if(format<2) {
+    if (format==0 || (days>0 && (hours||minutes||seconds))) {
+      sprintf(outstring,"%d day%s, %02d:%02d:%02d",
+              days,(days==1)?"":"s",hours,minutes,seconds);
+    } else if (days>0) {
+      sprintf(outstring, "%d day%s",days,(days==1)?"":"s");
+    } else {
+      if (hours>0) {
+        pos += sprintf(outstring+pos,"%d hour%s ",hours,hours==1?"":"s");
+      }
+      if (minutes>0 || (hours>0 && seconds>0)) {
+        pos += sprintf(outstring+pos,"%d minute%s ",minutes,minutes==1?"":"s");
+      }
+      if (seconds>0 || !interval) {
+        sprintf(outstring+pos,"%d second%s ",seconds,seconds==1?"":"s");
+      }
+    }
   } else {
-    if (hours>0) {
-      pos += sprintf(outstring+pos,"%d hour%s ",hours,hours==1?"":"s");
+    if (days>0) {
+      pos += sprintf(outstring+pos, "%dd ",days);
+    }
+    if (hours>0 || (days>0 && (minutes>0 || seconds>0))) {
+      pos += sprintf(outstring+pos, "%dh ",hours);
     }
-    if (minutes>0 || (hours>0 && seconds>0)) {
-      pos += sprintf(outstring+pos,"%d minute%s ",minutes,minutes==1?"":"s");
+    if (minutes>0 || ((days>0 || hours>0) && seconds>0)) {
+      pos += sprintf(outstring+pos, "%dm ",minutes);
     }
-    if (seconds>0) {
-      pos += sprintf(outstring+pos,"%d second%s ",seconds,seconds==1?"":"s");
+    if (seconds>0 || !interval) {
+      sprintf(outstring+pos, "%ds ",seconds);
     }
   }
 
@@ -504,9 +523,10 @@ break_while:
   if (!ch)
     return 0;                   /* mask ends with '*', we got it */
   ch = ToLower(ch);
-  while (ToLower(*s++) != ch)
+  do {
     if (!*s)
       return 1;
+  } while (ToLower(*s++) != ch);
   bs = s;                       /* Next try start from here */
 
   /* Check the rest of the "chunk" */