]> jfr.im git - irc/blitzed-org/bopm.git/commitdiff
misc.c, misc.h:
authorandy <redacted>
Tue, 30 Apr 2002 22:41:05 +0000 (22:41 +0000)
committerandy <redacted>
Tue, 30 Apr 2002 22:41:05 +0000 (22:41 +0000)
Reformatting.

misc.c
misc.h

diff --git a/misc.c b/misc.c
index 9751917507602f03f9707f880b09141df7ce962b..abf6596771cad70ef10502f24e3c31bc0183186b 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -32,120 +32,111 @@ along with this program; if not, write to the Free Software
 #include "config.h"
 #include "extern.h"
 
-/* split a time_t into an English-language explanation of how
- * much time it represents, e.g. "2 hours 45 minutes 8 seconds" */
+/*
+ * Split a time_t into an English-language explanation of how
+ * much time it represents, e.g. "2 hours 45 minutes 8 seconds"
+ */
 char *dissect_time(time_t time)
 {
-   static char buf[64];
-   int years, weeks, days, hours, minutes, seconds;
-
-   years = weeks = days = hours = minutes = seconds = 0;
-
-   while(time >= 60 * 60 * 24 * 365)
-    {
-      time -= 60 * 60 * 24 * 365;
-      years++;
-    }
-
-   while(time >= 60 * 60 * 24 * 7)
-    {
-      time -= 60 * 60 * 24 * 7;
-      weeks++;
-    }
-
-   while(time >= 60 * 60 * 24)
-    {
-      time -= 60 * 60 * 24;
-      days++;
-    }
-
-   while(time >= 60 * 60)
-    {
-      time -= 60 * 60;
-      hours++;
-    }
-
-   while (time >= 60)
-    {
-      time -= 60;
-      minutes++;
-    }
-
-   seconds = time;
-
-   if(years)
-    {
-      snprintf(buf, sizeof(buf),
-              "%d year%s, %d week%s, %d day%s, %02d:%02d:%02d", years,
-              years == 1 ? "" : "s", weeks, weeks == 1 ? "" : "s", days,
-              days == 1 ? "" : "s", hours, minutes, seconds);
-    }
-   else if(weeks)
-    {
-      snprintf(buf, sizeof(buf),
-              "%d week%s, %d day%s, %02d:%02d:%02d", weeks,
-              weeks == 1 ? "" : "s", days, days == 1 ? "" : "s", hours,
-              minutes, seconds);
-    }
-   else if(days)
-    {
-      snprintf(buf, sizeof(buf), "%d day%s, %02d:%02d:%02d", days,
-              days == 1 ? "" : "s", hours, minutes, seconds);
-    }
-   else if(hours)
-    {
-      if(minutes || seconds)
-       {
-         snprintf(buf, sizeof(buf), "%d hour%s, %d minute%s, %d second%s",
-                 hours, hours == 1 ? "" : "s", minutes,
-                 minutes == 1 ? "" : "s", seconds, seconds == 1 ? "" : "s");
-       }
-      else
-       {
-         snprintf(buf, sizeof(buf), "%d hour%s", hours,
-                 hours == 1 ? "" : "s");
-       }
-    }
-   else if(minutes)
-    {
-      snprintf(buf, sizeof(buf), "%d minute%s, %d second%s", minutes,
-              minutes == 1 ? "" : "s", seconds, seconds == 1 ? "" : "s");
-    }
-   else
-    {
-      snprintf(buf, sizeof(buf), "%d second%s", seconds,
-              seconds == 1 ? "" : "s");
-    }
-
-   return(buf);
+       static char buf[64];
+       unsigned int years, weeks, days, hours, minutes, seconds;
+
+       years = weeks = days = hours = minutes = seconds = 0;
+
+       while (time >= 60 * 60 * 24 * 365) {
+               time -= 60 * 60 * 24 * 365;
+               years++;
+       }
+
+       while (time >= 60 * 60 * 24 * 7) {
+               time -= 60 * 60 * 24 * 7;
+               weeks++;
+       }
+
+       while (time >= 60 * 60 * 24) {
+               time -= 60 * 60 * 24;
+               days++;
+       }
+
+       while (time >= 60 * 60) {
+               time -= 60 * 60;
+               hours++;
+       }
+
+       while (time >= 60) {
+               time -= 60;
+               minutes++;
+       }
+
+       seconds = time;
+
+       if (years) {
+               snprintf(buf, sizeof(buf),
+                   "%d year%s, %d week%s, %d day%s, %02d:%02d:%02d",
+                   years, years == 1 ? "" : "s", weeks,
+                   weeks == 1 ? "" : "s", days, days == 1 ? "" : "s",
+                   hours, minutes, seconds);
+       } else if (weeks) {
+               snprintf(buf, sizeof(buf),
+                   "%d week%s, %d day%s, %02d:%02d:%02d", weeks,
+                   weeks == 1 ? "" : "s", days, days == 1 ? "" : "s",
+                   hours, minutes, seconds);
+       } else if (days) {
+               snprintf(buf, sizeof(buf), "%d day%s, %02d:%02d:%02d",
+                   days, days == 1 ? "" : "s", hours, minutes, seconds);
+       } else if (hours) {
+               if (minutes || seconds) {
+                       snprintf(buf, sizeof(buf),
+                           "%d hour%s, %d minute%s, %d second%s", hours,
+                           hours == 1 ? "" : "s", minutes,
+                           minutes == 1 ? "" : "s", seconds,
+                           seconds == 1 ? "" : "s");
+               } else {
+                       snprintf(buf, sizeof(buf), "%d hour%s", hours,
+                           hours == 1 ? "" : "s");
+               }
+       } else if (minutes) {
+               snprintf(buf, sizeof(buf), "%d minute%s, %d second%s",
+                   minutes, minutes == 1 ? "" : "s", seconds,
+                   seconds == 1 ? "" : "s");
+       } else {
+               snprintf(buf, sizeof(buf), "%d second%s", seconds,
+                   seconds == 1 ? "" : "s");
+       }
+
+       return(buf);
 }
 
-/*  Strip leading/tailing characters from
- *  null terminated str and return a pointer
- *  to the new string.
+/*
+ * Strip leading/tailing characters from null terminated str and return a
+ * pointer to the new string.
  */
 
 char *clean(char *str)
 {
-
-    size_t i;
-    int lastnon;  /* Position of last non space */
-    int firstnon; /* Position of first non space */
-
-    lastnon = 0;
-    firstnon = 0;
-    
-    if(strlen(str) <= 1) /* Dont need to deal with 1 character */
-       return str;
-
-    for(i = 0; i < strlen(str);i++)
-     {
-         if(firstnon == 0 && str[i] != ' ')           
-                 firstnon = i;
-         if(str[i] != ' ')
-                 lastnon = i;  
-     }
-    
-    str[lastnon + 1] = 0;    /* Null terminate before the tailing spaces */
-    return (str + (firstnon - 1)); /* Return pointer to point after leading spaces */
-}         
+       size_t i;
+       /* Position of last non space. */
+       int lastnon;
+       /* Position of first non space. */
+       int firstnon;
+
+       lastnon = 0;
+       firstnon = 0;
+
+       /* Dont need to deal with 1 character */ 
+       if (strlen(str) <= 1)
+               return str;
+
+       for (i = 0; i < strlen(str); i++) {
+               if (firstnon == 0 && str[i] != ' ')           
+                       firstnon = i;
+               if (str[i] != ' ')
+                       lastnon = i;  
+       }
+
+       /* Null terminate before the tailing spaces. */ 
+       str[lastnon + 1] = 0;
+       
+       /* Return pointer to point after leading spaces. */
+       return(str + (firstnon - 1));
+}
diff --git a/misc.h b/misc.h
index c9abd2e4d85ba98aa208b4137b0de0cbbae467cb..ac00a82e29dfc47c11ae4a680ec6770060aeef9c 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -1,6 +1,7 @@
 #ifndef MISC_H
 #define MISC_H
 
-       char *dissect_time(time_t time);
-        char *clean(char *str);
+extern char *dissect_time(time_t time);
+extern char *clean(char *str);
+
 #endif