]> code.citadel.org Git - citadel.git/blobdiff - citadel/rooms.c
* Variable names, comments, documentation, etc... removed the acronym 'BBS'
[citadel.git] / citadel / rooms.c
index 25565344620ab644df6b6b158414038a283de74b..4659176509c0e7c25629236e4345c307ac12402c 100644 (file)
 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
 
 
-void sttybbs(int cmd);
-void hit_any_key(void);
+void stty_ctdl(int cmd);
 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
-void progress(unsigned long curr, unsigned long cmax);
+void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
 int pattern(char *search, char *patn);
 int file_checksum(char *filename);
 int nukedir(char *dirname);
@@ -80,9 +79,9 @@ void load_floorlist(CtdlIPC *ipc)
                return;
        }
        while (*listing && strlen(listing)) {
-               extract_token(buf, listing, 0, '\n');
+               extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
-               extract(floorlist[extract_int(buf, 0)], buf, 1);
+               extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
        }
        free(listing);
 }
@@ -313,7 +312,7 @@ void knrooms(CtdlIPC *ipc, int kn_floor_mode)
        };
 
        color(DIM_WHITE);
-       IFNEXPERT hit_any_key();
+       IFNEXPERT hit_any_key(ipc);
 }
 
 
@@ -344,7 +343,7 @@ void listzrooms(CtdlIPC *ipc)
        };
 
        color(DIM_WHITE);
-       IFNEXPERT hit_any_key();
+       IFNEXPERT hit_any_key(ipc);
 }
 
 
@@ -702,7 +701,7 @@ int save_buffer(void *file, size_t filelen, const char *pathname)
                return 0;
        }
        do {
-               block = fwrite(file + bytes_written, 1,
+               block = fwrite((char *)file + bytes_written, 1,
                                filelen - bytes_written, fp);
                bytes_written += block;
        } while (errno == EINTR && bytes_written < filelen);
@@ -722,16 +721,34 @@ int save_buffer(void *file, size_t filelen, const char *pathname)
  */
 void destination_directory(char *dest, const char *supplied_filename)
 {
-       scr_printf("Enter the name of the directory to save '%s'\n"
-               "to, or press return for the current directory.\n",
-               supplied_filename);
-       newprompt("Directory: ", dest, PATH_MAX);
-       if (strlen(dest) == 0) {
-               dest[0] = '.';
-               dest[1] = 0;
-       }
-       strcat(dest, "/");
-       strcat(dest, supplied_filename);
+       static char save_dir[SIZ] = { 0 };
+
+       if (strlen(save_dir) == 0) {
+               if (getenv("HOME") == NULL) {
+                       strcpy(save_dir, ".");
+               }
+               else {
+                       sprintf(save_dir, "%s/Desktop", getenv("HOME"));
+                       if (access(save_dir, W_OK) != 0) {
+                               sprintf(save_dir, "%s", getenv("HOME"));
+                               if (access(save_dir, W_OK) != 0) {
+                                       sprintf(save_dir, ".");
+                               }
+                       }
+               }
+       }
+
+       sprintf(dest, "%s/%s", save_dir, supplied_filename);
+       strprompt("Save as", dest, PATH_MAX);
+
+       /* Remember the directory for next time */
+       strcpy(save_dir, dest);
+       if (strrchr(save_dir, '/') != NULL) {
+               strcpy(strrchr(save_dir, '/'), "");
+       }
+       else {
+               strcpy(save_dir, ".");
+       }
 }
 
 
@@ -808,9 +825,9 @@ void download(CtdlIPC *ipc, int proto)
                snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
 
        screen_reset();
-       sttybbs(SB_RESTORE);
+       stty_ctdl(SB_RESTORE);
        system(transmit_cmd);
-       sttybbs(SB_NO_INTR);
+       stty_ctdl(SB_NO_INTR);
        screen_set();
 
        /* clean up the temporary directory */
@@ -824,26 +841,30 @@ void download(CtdlIPC *ipc, int proto)
  */
 void roomdir(CtdlIPC *ipc)
 {
-       char flnm[SIZ];
+       char flnm[256];
        char flsz[32];
-       char comment[SIZ];
-       char buf[SIZ];
+       char comment[256];
+       char buf[256];
+       char *listing = NULL;   /* Returned directory listing */
+       int r;
 
-       CtdlIPC_putline(ipc, "RDIR");
-       CtdlIPC_getline(ipc, buf);
-       if (buf[0] != '1') {
-               pprintf("%s\n", &buf[4]);
+       r = CtdlIPCReadDirectory(ipc, &listing, buf);
+       if (r / 100 != 1) {
+               pprintf("%s\n", buf);
                return;
        }
 
-       extract(comment, &buf[4], 0);
-       extract(flnm, &buf[4], 1);
+       extract_token(comment, buf, 0, '|', sizeof comment);
+       extract_token(flnm, buf, 1, '|', sizeof flnm);
        pprintf("\nDirectory of %s on %s\n", flnm, comment);
        pprintf("-----------------------\n");
-       while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
-               extract(flnm, buf, 0);
-               extract(flsz, buf, 1);
-               extract(comment, buf, 2);
+       while (*listing && strlen(listing)) {
+               extract_token(buf, listing, 0, '\n', sizeof buf);
+               remove_token(listing, 0, '\n');
+
+               extract_token(flnm, buf, 0, '|', sizeof flnm);
+               extract_token(flsz, buf, 1, '|', sizeof flsz);
+               extract_token(comment, buf, 2, '|', sizeof comment);
                if (strlen(flnm) <= 14)
                        pprintf("%-14s %8s %s\n", flnm, flsz, comment);
                else
@@ -1055,7 +1076,7 @@ void readinfo(CtdlIPC *ipc)
  */
 void whoknows(CtdlIPC *ipc)
 {
-       char buf[SIZ];
+       char buf[256];
        char *listing = NULL;
        int r;
 
@@ -1065,7 +1086,7 @@ void whoknows(CtdlIPC *ipc)
                return;
        }
        while (strlen(listing) > 0) {
-               extract_token(buf, listing, 0, '\n');
+               extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
                if (sigcaught == 0)
                        pprintf("%s\n", buf);
@@ -1090,19 +1111,19 @@ void do_edit(CtdlIPC *ipc,
        fp = fopen(temp, "w");
        fclose(fp);
 
-       CtdlIPC_putline(ipc, check_cmd);
-       CtdlIPC_getline(ipc, cmd);
+       CtdlIPC_chat_send(ipc, check_cmd);
+       CtdlIPC_chat_recv(ipc, cmd);
        if (cmd[0] != '2') {
                scr_printf("%s\n", &cmd[4]);
                return;
        }
 
        if (strlen(editor_paths[0]) > 0) {
-               CtdlIPC_putline(ipc, read_cmd);
-               CtdlIPC_getline(ipc, cmd);
+               CtdlIPC_chat_send(ipc, read_cmd);
+               CtdlIPC_chat_recv(ipc, cmd);
                if (cmd[0] == '1') {
                        fp = fopen(temp, "w");
-                       while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
+                       while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
                                fprintf(fp, "%s\n", cmd);
                        }
                        fclose(fp);
@@ -1117,7 +1138,7 @@ void do_edit(CtdlIPC *ipc,
                snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
                putenv(tmp);
                screen_reset();
-               sttybbs(SB_RESTORE);
+               stty_ctdl(SB_RESTORE);
                editor_pid = fork();
                if (editor_pid == 0) {
                        chmod(temp, 0600);
@@ -1131,7 +1152,7 @@ void do_edit(CtdlIPC *ipc,
                        } while ((b != editor_pid) && (b >= 0));
                editor_pid = (-1);
                scr_printf("Executed %s\n", editor_paths[0]);
-               sttybbs(0);
+               stty_ctdl(0);
                screen_set();
        } else {
                scr_printf("Entering %s.  "
@@ -1146,8 +1167,8 @@ void do_edit(CtdlIPC *ipc,
        }
 
        else {
-               CtdlIPC_putline(ipc, write_cmd);
-               CtdlIPC_getline(ipc, cmd);
+               CtdlIPC_chat_send(ipc, write_cmd);
+               CtdlIPC_chat_recv(ipc, cmd);
                if (cmd[0] != '4') {
                        scr_printf("%s\n", &cmd[4]);
                        return;
@@ -1156,10 +1177,10 @@ void do_edit(CtdlIPC *ipc,
                fp = fopen(temp, "r");
                while (fgets(cmd, SIZ - 1, fp) != NULL) {
                        cmd[strlen(cmd) - 1] = 0;
-                       CtdlIPC_putline(ipc, cmd);
+                       CtdlIPC_chat_send(ipc, cmd);
                }
                fclose(fp);
-               CtdlIPC_putline(ipc, "000");
+               CtdlIPC_chat_send(ipc, "000");
        }
 
        unlink(temp);
@@ -1196,7 +1217,7 @@ void create_floor(CtdlIPC *ipc)
        }
 
        newprompt("Name for new floor: ", newfloorname, 255);
-       if (!*newprompt) return;
+       if (!*newfloorname) return;
        r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
        if (r / 100 == 2) {
                scr_printf("Floor has been created.\n");