* support.c: removed an unused variable
authorArt Cancro <ajc@citadel.org>
Mon, 16 Jun 2003 04:39:45 +0000 (04:39 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 16 Jun 2003 04:39:45 +0000 (04:39 +0000)
* citadel.c: sort wholist by idle time (most recently active users first)

citadel/ChangeLog
citadel/citadel.c
citadel/support.c

index e972049721bec686a1371c4200ac7f53b8986eda..07b6ebb548b736ea3f52d2db16eab443eeb779cf 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 607.1  2003/06/16 04:39:45  ajc
+ * support.c: removed an unused variable
+ * citadel.c: sort wholist by idle time (most recently active users first)
+
  Revision 607.0  2003/06/10 04:15:39  ajc
  * THIS IS 6.07
 
@@ -4760,3 +4764,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 5b374218d1a9b4a0754721fbbc81bb0d548ba63e..78a9ccb2aeed7e003c3828ed0710823a8de45169 100644 (file)
@@ -773,6 +773,61 @@ void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
 
 
 
+/*
+ * Record compare function for SortOnlineUsers()
+ */
+int idlecmp(const void *rec1, const void *rec2) {
+       time_t i1, i2;
+
+       i1 = extract_long(rec1, 5);
+       i2 = extract_long(rec2, 5);
+
+       if (i1 < i2) return(1);
+       if (i1 > i2) return(-1);
+       return(0);
+}
+
+
+/*
+ * Sort the list of online users by idle time.
+ * This function frees the supplied buffer, and returns a new one
+ * to the caller.  The caller is responsible for freeing the returned buffer.
+ */
+char *SortOnlineUsers(char *listing) {
+       int rows;
+       char *sortbuf;
+       char *retbuf;
+       char buf[SIZ];
+       int i;
+
+       rows = num_tokens(listing, '\n');
+       sortbuf = malloc(rows * SIZ);
+       if (sortbuf == NULL) return(listing);
+       retbuf = malloc(rows * SIZ);
+       if (retbuf == NULL) {
+               free(sortbuf);
+               return(listing);
+       }
+
+       /* Copy the list into a fixed-record-size array for sorting */
+       for (i=0; i<rows; ++i) {
+               memset(buf, 0, SIZ);
+               extract_token(buf, listing, i, '\n');
+               memcpy(&sortbuf[i*SIZ], buf, SIZ);
+       }
+
+       /* Do the sort */
+       qsort(sortbuf, rows, SIZ, idlecmp);
+
+       /* Copy back to a \n delimited list */
+       strcpy(retbuf, "");
+       for (i=0; i<rows; ++i) {
+               strcat(retbuf, &sortbuf[i*SIZ]);
+               if (i<(rows-1)) strcat(retbuf, "\n");
+       }
+       return(retbuf);
+}
+
 
 
 /*
@@ -803,6 +858,7 @@ void who_is_online(CtdlIPC *ipc, int longlist)
                pprintf("--- --- ------------------------- -------------------- ------------------------\n");
        }
        r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
+       listing = SortOnlineUsers(listing);
        if (r / 100 == 1) {
                while (strlen(listing) > 0) {
                        int isidle = 0;
index 855c9ad4c3712fb596c51bc474592534f98fcbf5..f7f17f7f84e2c155ec96972b6ba304cb956abb4c 100644 (file)
@@ -112,7 +112,6 @@ void mesg_locate(char *targ, size_t n, const char *searchfor,
        int a;
        char buf[SIZ];
        struct stat test;
-       FILE *ls;
 
        for (a=0; a<numdirs; ++a) {
                snprintf(buf, sizeof buf, "%s/%s", dirs[a], searchfor);