Fix more warnings; output errors to the users.
[citadel.git] / citadel / textclient / messages.c
index 111bac6c47b7cf51958a344909010ddf2412230e..3935355cc042e7a73e80bf58ae9a8e89f41d7aa7 100644 (file)
@@ -363,7 +363,10 @@ void citedit(FILE *fp)
        putc(10, fp);
        fflush(fp);
        rv = ftruncate(fileno(fp), ftell(fp));
+       if (rv < 0)
+               scr_printf("failed to set message buffer: %s\n", strerror(errno));
 
+       
        /* and deallocate the memory we used */
        while (textlist != NULL) {
                ptr = textlist->next;
@@ -801,6 +804,10 @@ void replace_string(char *filename, long int startpos)
                        rpos = ftell(fp);
                        fseek(fp, wpos, 0);
                        rv = fwrite((char *) buf, 128, 1, fp);
+                       if (rv < 0) {
+                               scr_printf("failed to replace string: %s\n", strerror(errno));
+                               break; /*whoopsi! */
+                       }
                        strcpy(buf, &buf[128]);
                        wpos = ftell(fp);
                        fseek(fp, rpos, 0);
@@ -877,8 +884,6 @@ int client_make_message(CtdlIPC *ipc,
                newprompt("Subject: ", subject, 70);
        }
 
-       beg = 0L;
-
        if (mode == 1) {
                scr_printf("(Press ctrl-d when finished)\n");
        }
@@ -888,6 +893,9 @@ int client_make_message(CtdlIPC *ipc,
                if (fp != NULL) {
                        fmout(screenwidth, fp, NULL, NULL, 0);
                        beg = ftell(fp);
+                       if (beg < 0)
+                               scr_printf("failed to get stream position %s\n", 
+                                          strerror(errno));
                        fclose(fp);
                } else {
                        fp = fopen(filename, "w");
@@ -1000,7 +1008,11 @@ MECR:    if (mode >= 2) {
                fp = fopen(filename, "r");
                if (fp != NULL) {
                        fmout(screenwidth, fp, NULL, NULL, 0);
+                       /* TODO: why ftell if we ignore the result? */
                        beg = ftell(fp);
+                       if (beg < 0)
+                               scr_printf("failed to get stream position %s\n", 
+                                          strerror(errno));
                        fclose(fp);
                }
                goto MECR;
@@ -1117,6 +1129,37 @@ int entmsg(CtdlIPC *ipc,
                newprompt("Display name for this message: ", message.author, 40);
        }
 
+       if (is_reply) {
+
+               if (!IsEmptyStr(reply_subject)) {
+                       if (!strncasecmp(reply_subject,
+                          "Re: ", 3)) {
+                               strcpy(message.subject, reply_subject);
+                       }
+                       else {
+                               snprintf(message.subject,
+                                       sizeof message.subject,
+                                       "Re: %s",
+                                       reply_subject);
+                       }
+               }
+
+               /* Trim down excessively long lists of thread references.  We eliminate the
+                * second one in the list so that the thread root remains intact.
+                */
+               int rrtok = num_tokens(reply_references, '|');
+               int rrlen = strlen(reply_references);
+               if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
+                       remove_token(reply_references, 1, '|');
+               }
+
+               snprintf(message.references, sizeof message.references, "%s%s%s",
+                       reply_references,
+                       (IsEmptyStr(reply_references) ? "" : "|"),
+                       reply_inreplyto
+               );
+       }
+
        r = CtdlIPCPostMessage(ipc, 0, &subject_required, &message, buf);
 
        if (r / 100 != 2 && r / 10 != 57) {
@@ -1154,37 +1197,6 @@ int entmsg(CtdlIPC *ipc,
        }
        strcpy(message.recipient, buf);
 
-       if (is_reply) {
-
-               if (!IsEmptyStr(reply_subject)) {
-                       if (!strncasecmp(reply_subject,
-                          "Re: ", 3)) {
-                               strcpy(message.subject, reply_subject);
-                       }
-                       else {
-                               snprintf(message.subject,
-                                       sizeof message.subject,
-                                       "Re: %s",
-                                       reply_subject);
-                       }
-               }
-
-               /* Trim down excessively long lists of thread references.  We eliminate the
-                * second one in the list so that the thread root remains intact.
-                */
-               int rrtok = num_tokens(reply_references, '|');
-               int rrlen = strlen(reply_references);
-               if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
-                       remove_token(reply_references, 1, '|');
-               }
-
-               snprintf(message.references, sizeof message.references, "%s%s%s",
-                       reply_references,
-                       (IsEmptyStr(reply_references) ? "" : "|"),
-                       reply_inreplyto
-               );
-       }
-
        if (room_flags & QR_ANONOPT) {
                scr_printf("Anonymous (Y/N)? ");
                if (yesno() == 1)
@@ -1362,6 +1374,8 @@ void list_urls(CtdlIPC *ipc)
 
        snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
        rv = system(cmd);
+       if (rv != 0) 
+               scr_printf("failed to '%s' by %d\n", cmd, rv);
        scr_printf("\n");
 }
 
@@ -1497,7 +1511,7 @@ void readmsgs(CtdlIPC *ipc,
        enum MessageDirection rdir,     /* 1=Forward (-1)=Reverse */
        int q           /* Number of msgs to read (if c==3) */
 ) {
-       int a, b, e, f, g, start;
+       int a, e, f, g, start;
        int savedpos;
        int hold_sw = 0;
        char arcflag = 0;
@@ -1515,11 +1529,6 @@ void readmsgs(CtdlIPC *ipc,
        static int att_seq = 0;         /* Attachment download sequence number */
        int rv = 0;                     /* silence the stupid warn_unused_result warnings */
 
-       if (c < 0)
-               b = (num_msgs - 1);
-       else
-               b = 0;
-
        CtdlMakeTempFileName(prtfile, sizeof prtfile);
 
        if (msg_arr) {
@@ -1579,7 +1588,7 @@ RAGAIN:           pagin = ((arcflag == 0)
                if ((quotflag) || (arcflag)) {
                        screenwidth = hold_sw;
                }
-RMSGREAD:      scr_flush();
+RMSGREAD:
                highest_msg_read = msg_arr[a];
                if (quotflag) {
                        fclose(dest);
@@ -1729,7 +1738,6 @@ RMSGREAD: scr_flush();
                                scr_printf("\r%79s\r", "");
                        else
                                scr_printf("\n");
-                       scr_flush();
                }
 DONE_QUOTING:  switch (e) {
                case '?':
@@ -1827,6 +1835,8 @@ DONE_QUOTING:     switch (e) {
                                        save_buffer(attachment, extract_unsigned_long(cmd, 0), save_to);
                                        snprintf(cmd, sizeof cmd, rc_open_cmd, save_to);
                                        rv = system(cmd);
+                                       if (rv != 0)
+                                               scr_printf("failed to save %s Reason %d\n", cmd, rv);
                                }
                                else {                  /* save attachment to disk */
                                        destination_directory(save_to, filename);