* Holy war on strlen: use IsEmptyStr where apropriate.
[citadel.git] / citadel / citadel.c
index b18eb2e92278070a5ebbf3976f333834c65a0a1f..920f06cc402b1ce1537991109cdfb85f2cf71d39 100644 (file)
@@ -45,7 +45,7 @@
 #include "client_passwords.h"
 #include "citadel_decls.h"
 #include "tools.h"
-#include "acconfig.h"
+#include "sysdep.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
@@ -223,7 +223,7 @@ void userlist(CtdlIPC *ipc, char *patn)
 
        pprintf("       User Name           Num  L  LastCall  Calls Posts\n");
        pprintf("------------------------- ----- - ---------- ----- -----\n");
-       if (listing != NULL) while (strlen(listing) > 0) {
+       if (listing != NULL) while (!IsEmptyStr(listing)) {
                extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
 
@@ -420,7 +420,7 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
                        }
                }
 
-               if (strlen(bbb) == 0) {
+               if (IsEmptyStr(bbb)) {
                        scr_printf("No room '%s'.\n", towhere);
                        return;
                }
@@ -432,7 +432,7 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
        }
        safestrncpy(room_name, room->RRname, ROOMNAMELEN);
        room_flags = room->RRflags;
-       room_flags = room->RRflags2;
+       room_flags2 = room->RRflags2;
        from_floor = curr_floor;
        curr_floor = room->RRfloor;
 
@@ -484,7 +484,7 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
                                        newmailcount);
                }
                color(DIM_WHITE);
-               if (strlen(rc_gotmail_cmd) > 0) {
+               if (!IsEmptyStr(rc_gotmail_cmd)) {
                        system(rc_gotmail_cmd);
                }
        }
@@ -659,7 +659,7 @@ void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
                        mptr = tmp;
                }
        }
-       if (strlen(targ) > 0) {
+       if (!IsEmptyStr(targ)) {
                gf_toroom(ipc, targ, mode);
                return;
        }
@@ -681,7 +681,7 @@ void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
                        mptr = tmp;
                }
        }
-       if (strlen(targ) > 0) {
+       if (!IsEmptyStr(targ)) {
                gf_toroom(ipc, targ, mode);
        } else {
                scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
@@ -950,7 +950,7 @@ void read_config(CtdlIPC *ipc)
            scr_printf("Enable color support: ");                              color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_COLOR)? "Yes" : "No");       color(DIM_WHITE);
        }
        scr_printf("Be unlisted in userlog: ");                                color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_UNLISTED)? "Yes" : "No");    color(DIM_WHITE);
-       if (strlen(editor_paths[0]) > 0) {
+       if (!IsEmptyStr(editor_paths[0])) {
        scr_printf("Always enter messages with the full-screen editor: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXTEDIT)? "Yes" : "No");     color(DIM_WHITE);
        }
        free(user);
@@ -1076,7 +1076,7 @@ int set_password(CtdlIPC *ipc)
        char pass2[20];
        char buf[SIZ];
 
-       if (strlen(rc_password) > 0) {
+       if (!IsEmptyStr(rc_password)) {
                strcpy(pass1, rc_password);
                strcpy(pass2, rc_password);
        } else {
@@ -1212,14 +1212,18 @@ void who_is_online(CtdlIPC *ipc, int longlist)
 
        if (!longlist) {
                color(BRIGHT_WHITE);
-               pprintf("           User Name               Room           Idle        From host\n");
+               pprintf("           User Name               Room          ");
+               if (screenwidth >= 80) pprintf(" Idle        From host");
+               pprintf("\n");
                color(DIM_WHITE);
-               pprintf("   ------------------------- -------------------- ---- ------------------------\n");
+               pprintf("   ------------------------- --------------------");
+               if (screenwidth >= 80) pprintf(" ---- ------------------------");
+               pprintf("\n");
        }
        r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
        listing = SortOnlineUsers(listing);
        if (r / 100 == 1) {
-               while (strlen(listing) > 0) {
+               while (!IsEmptyStr(listing)) {
                        int isidle = 0;
                        
                        /* Get another line */
@@ -1238,14 +1242,9 @@ void who_is_online(CtdlIPC *ipc, int longlist)
                        idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
 
                        if (idletime > rc_idle_threshold) {
-                               /*
-                               while (strlen(roomname) < 20) {
-                                       strcat(roomname, " ");
-                               }
-                               strcpy(&roomname[14], "[idle]");
-                               */
-                               if (skipidle)
+                               if (skipidle) {
                                        isidle = 1;
+                               }
                        }
 
                        if (longlist) {
@@ -1264,57 +1263,64 @@ void who_is_online(CtdlIPC *ipc, int longlist)
                                        (long) idlemins,
                                        (long) idlesecs);
 
-                               if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
+                               if ( (!IsEmptyStr(actual_user)&&
+                                     !IsEmptyStr(actual_room)&&
+                                     !IsEmptyStr(actual_host))) {
                                        pprintf("(really ");
-                                       if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
-                                       if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
-                                       if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
+                                       if (!IsEmptyStr(actual_user)) pprintf("<%s> ", actual_user);
+                                       if (!IsEmptyStr(actual_room)) pprintf("in <%s> ", actual_room);
+                                       if (!IsEmptyStr(actual_host)) pprintf("from <%s> ", actual_host);
                                        pprintf(")\n");
                                }
                                pprintf("\n");
 
                        } else {
-                   if (isidle == 0) {
-                               if (extract_int(buf, 0) == last_session) {
-                                       pprintf("        ");
-                               } else {
+                               if (isidle == 0) {
+                                       if (extract_int(buf, 0) == last_session) {
+                                               pprintf("        ");
+                                       }
+                                       else {
+                                               color(BRIGHT_MAGENTA);
+                                               pprintf("%-3s", flags);
+                                       }
+                                       last_session = extract_int(buf, 0);
+                                       color(BRIGHT_CYAN);
+                                       pprintf("%-25s ", username);
                                        color(BRIGHT_MAGENTA);
-                                       pprintf("%-3s", flags);
-                               }
-                               last_session = extract_int(buf, 0);
-                               color(BRIGHT_CYAN);
-                               pprintf("%-25s ", username);
-                               color(BRIGHT_MAGENTA);
-                               roomname[20] = 0;
-                               pprintf("%-20s ", roomname);
-                               if (idletime > rc_idle_threshold) {
-                                       /* over 1000d, must be gone fishing */
-                                       if (idlehours > 23999) {
-                                               pprintf("fish");
-                                       /* over 10 days */
-                                       } else if (idlehours > 239) {
-                                               pprintf("%3ldd",
-                                                       idlehours / 24);
-                                       /* over 10 hours */
-                                       } else if (idlehours > 9) {
-                                               pprintf("%1ldd%02ld",
-                                                       idlehours / 24,
-                                                       idlehours % 24);
-                                       /* less than 10 hours */
-                                       } else {
-                                               pprintf("%1ld:%02ld",
-                                                       idlehours, idlemins);
+                                       roomname[20] = 0;
+                                       pprintf("%-20s", roomname);
+
+                                       if (screenwidth >= 80) {
+                                               pprintf(" ");
+                                               if (idletime > rc_idle_threshold) {
+                                                       /* over 1000d, must be gone fishing */
+                                                       if (idlehours > 23999) {
+                                                               pprintf("fish");
+                                                       /* over 10 days */
+                                                       } else if (idlehours > 239) {
+                                                               pprintf("%3ldd", idlehours / 24);
+                                                       /* over 10 hours */
+                                                       } else if (idlehours > 9) {
+                                                               pprintf("%1ldd%02ld",
+                                                                       idlehours / 24,
+                                                                       idlehours % 24);
+                                                       /* less than 10 hours */
+                                                       }
+                                                       else {
+                                                               pprintf("%1ld:%02ld", idlehours, idlemins);
+                                                       }
+                                               }
+                                               else {
+                                                       pprintf("    ");
+                                               }
+                                               pprintf(" ");
+                                               color(BRIGHT_CYAN);
+                                               fromhost[24] = '\0';
+                                               pprintf("%-24s", fromhost);
                                        }
-                               }
-                               else {
-                                       pprintf("    ");
-                               }
-                               pprintf(" ");
-                               color(BRIGHT_CYAN);
-                               fromhost[24] = '\0';
-                               pprintf("%-24s\n", fromhost);
-                               color(DIM_WHITE);
-                       }
+                                       pprintf("\n");
+                                       color(DIM_WHITE);
+                               }
                        }
                }
        }
@@ -1368,7 +1374,7 @@ int main(int argc, char **argv)
        int home=0;
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
-    
+    int lp; 
 
 
        calc_dirs_n_files(relh, home, relhome, ctdldir);
@@ -1553,7 +1559,7 @@ int main(int argc, char **argv)
  GSTA: /* See if we have a username and password on disk */
        if (rc_remember_passwords) {
                get_stored_password(hostbuf, portbuf, fullname, password);
-               if (strlen(fullname) > 0) {
+               if (!IsEmptyStr(fullname)) {
                        r = CtdlIPCTryLogin(ipc, fullname, aaa);
                        if (r / 100 == 3) {
                                if (*nonce) {
@@ -1576,7 +1582,7 @@ int main(int argc, char **argv)
        termn8 = 0;
        newnow = 0;
        do {
-               if (strlen(rc_username) > 0) {
+               if (!IsEmptyStr(rc_username)) {
                        strcpy(fullname, rc_username);
                } else {
                        newprompt("Enter your name: ", fullname, 29);
@@ -1588,7 +1594,7 @@ int main(int argc, char **argv)
        } while (
                 (!strcasecmp(fullname, "bbs"))
                 || (!strcasecmp(fullname, "new"))
-                || (strlen(fullname) == 0));
+                || (IsEmptyStr(fullname)));
 
        if (!strcasecmp(fullname, "off")) {
                mcmd = 29;
@@ -1600,7 +1606,7 @@ int main(int argc, char **argv)
                goto NEWUSR;
 
        /* password authentication */
-       if (strlen(rc_password) > 0) {
+       if (!IsEmptyStr(rc_password)) {
                strcpy(password, rc_password);
        } else {
                newprompt("\rPlease enter your password: ", password, -19);
@@ -1620,11 +1626,11 @@ int main(int argc, char **argv)
                goto PWOK;
        }
        scr_printf("<< wrong password >>\n");
-       if (strlen(rc_password) > 0)
+       if (!IsEmptyStr(rc_password))
                logoff(ipc, 2);
        goto GSTA;
 
-NEWUSR:        if (strlen(rc_password) == 0) {
+NEWUSR:        if (IsEmptyStr(rc_password)) {
                scr_printf("'%s' not found.\n", fullname);
                scr_printf("Type 'off' if you would like to exit.\n");
                if (ipc->ServInfo.newuser_disabled == 1) {
@@ -1679,7 +1685,7 @@ NEWUSR:   if (strlen(rc_password) == 0) {
                        if (b > 1)
                                scr_printf("*** You have %d new private messages in Mail>\n", b);
                        color(DIM_WHITE);
-                       if (strlen(rc_gotmail_cmd) > 0) {
+                       if (!IsEmptyStr(rc_gotmail_cmd)) {
                                system(rc_gotmail_cmd);
                        }
                }
@@ -1780,13 +1786,13 @@ NEWUSR: if (strlen(rc_password) == 0) {
                                dotgoto(ipc, "_MAIL_", 1, 0);
                                break;
                        case 20:
-                               if (strlen(argbuf) > 0) {
+                               if (!IsEmptyStr(argbuf)) {
                                        updatels(ipc);
                                        dotgoto(ipc, argbuf, 0, 0);
                                }
                                break;
                        case 52:
-                               if (strlen(argbuf) > 0) {
+                               if (!IsEmptyStr(argbuf)) {
                                        if (rc_alt_semantics) {
                                                updatelsa(ipc);
                                        }
@@ -2261,6 +2267,11 @@ TERMN8:  scr_printf("%s logged out.", fullname);
                formout(ipc, "goodbye");
                logoff(ipc, 0);
        }
+       /* Free the ungoto list */
+       for (lp = 0; lp < uglistsize; lp++) {
+               free(uglist[lp]);
+       }
+    uglistsize = 0;
        goto GSTA;
 
 }      /* end main() */