The encoding and decoding tables for Base64 are
[citadel.git] / citadel / whobbs.c
index 32386710379e225c37d011838839edba45e8e883..f4114bb55802da9686328108c23c7b765d6d2162 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
 #include "citadel_dirs.h"
-#include "tools.h"
 
 void logoff(int code)
 {
@@ -23,22 +23,30 @@ void logoff(int code)
 
 static void escapize(char *buf, size_t n) {
        char hold[512];
-       int i;
+       int i, len;
+       size_t tmp;
 
        strcpy(hold, buf);
        strcpy(buf, "");
-
-       for (i=0; i<strlen(hold); ++i) {
-               size_t tmp = strlen(buf);
-
-               if (hold[i]=='<')
+       tmp = 0;
+       len = strlen(hold);
+       for (i=0; i<len; ++i) {
+               if (hold[i]=='<') {
                        snprintf(&buf[tmp], n - tmp, "&lt;");
-               else if (hold[i]=='>')
+                       tmp += 4;
+               }
+               else if (hold[i]=='>'){
                        snprintf(&buf[tmp], n - tmp, "&gt;");
-               else if (hold[i]==34)
+                       tmp += 4;
+               }
+               else if (hold[i]==34){
                        snprintf(&buf[tmp], n - tmp, "&quot;");
-               else
+                       tmp += 6;
+               }
+               else{
                        snprintf(&buf[tmp], n - tmp, "%c", hold[i]);
+                       tmp ++;
+               }
        }
 }
 
@@ -67,8 +75,7 @@ int main(int argc, char **argv)
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
 
-
-       calc_dirs_n_files(relh, home, relhome, ctdldir);
+       calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
 
        /* If this environment variable is set, we assume that the program
         * is being called as a cgi-bin from a webserver and will output
@@ -135,7 +142,7 @@ int main(int argc, char **argv)
        }
 
 
-       while (strlen(listing) > 0) {
+       while (!IsEmptyStr(listing)) {
                extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');