]> code.citadel.org Git - citadel.git/blobdiff - citadel/messages.c
* Changed the comments at the beginning of each file to a consistent format
[citadel.git] / citadel / messages.c
index 9d26571101452e6c002fb479026faa42b024f408..27ff4968bc01a6c9963f857af969584c2dba8f65 100644 (file)
@@ -1,7 +1,8 @@
 /*
+ * $Id$
+ *
  * Citadel/UX message support routines
  * see copyright.txt for copyright information
- * $Id$
  */
 
 #include "sysdep.h"
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
-#include <time.h>
 #include <signal.h>
 #include <errno.h>
 #include <limits.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <stdarg.h>
 #include "citadel.h"
 #include "messages.h"
@@ -37,7 +38,6 @@ struct cittext {
        };
 
 void sttybbs(int cmd);
-int struncmp(char *lstr, char *rstr, int len);
 int fmout(int width, FILE *fp, char pagin, int height, int starting_lp, char subst);
 int haschar(char *st, int ch);
 int checkpagin(int lp, int pagin, int height);
@@ -75,8 +75,6 @@ extern int rc_force_mail_prompts;
 
 extern int editor_pid;
 
-int lines_printed;
-
 void ka_sigcatch(int signum) {
        char buf[256];
        alarm(S_KEEPALIVE);
@@ -213,18 +211,18 @@ void citedit(FILE *fp)
                                add_word(textlist,"\n");
                                add_newline(textlist);
                                add_word(textlist,"");
-                               }
                        }
+               }
                else {
                        wordbuf[strlen(wordbuf)+1] = 0;
                        wordbuf[strlen(wordbuf)] = a;
-                       }
+               }
                if (strlen(wordbuf)+3 > screenwidth) {
                        add_word(textlist,wordbuf);
                        strcpy(wordbuf,"");
-                       }
-               prev = a;
                }
+               prev = a;
+       }
 
        /* get text */
        finished = 0;
@@ -236,18 +234,28 @@ void citedit(FILE *fp)
                if (a==10) a=13;
                if (a==9) a=32;
                if (a==127) a=8;
+
+
+       /******* new ***********/
+               if ((a>32)&&(a<127)&&(prev==13)) {
+                       add_word(textlist,"\n");
+                       printf(" ");
+               }
+       /***********************/
+
                if ((a==32)&&(prev==13)) {
                        add_word(textlist,"\n");
                        add_newline(textlist);
-                       }
+               }
+
                if (a==8) {
                        if (strlen(wordbuf)>0) {
                                wordbuf[strlen(wordbuf)-1] = 0;
                                putc(8,stdout);
                                putc(32,stdout);
                                putc(8,stdout);
-                               }
                        }
+               }
                else if (a==13) {
                        printf("\n");
                        if (strlen(wordbuf)==0) finished = 1;
@@ -258,16 +266,16 @@ void citedit(FILE *fp)
                                        add_word(textlist,wordbuf);
                                        strcpy(wordbuf,&wordbuf[b+1]);
                                        b=0;
-                                       }
+                               }
                                add_word(textlist,wordbuf);
                                strcpy(wordbuf,"");
-                               }
                        }
+               }
                else {
                        putc(a,stdout);
                        wordbuf[strlen(wordbuf)+1] = 0;
                        wordbuf[strlen(wordbuf)] = a;
-                       }
+               }
                if ((strlen(wordbuf)+3) > screenwidth) {
                        last_space = (-1);
                        for (b=0; b<strlen(wordbuf); ++b)
@@ -279,22 +287,22 @@ void citedit(FILE *fp)
                                        add_word(textlist,wordbuf);
                                        strcpy(wordbuf,&wordbuf[b+1]);
                                        b=0;
-                                       }
+                               }
                                for (b=0; b<strlen(wordbuf); ++b) {
                                        putc(8,stdout);
                                        putc(32,stdout);
                                        putc(8,stdout);
-                                       }
-                               printf("\n%s",wordbuf);
                                }
+                               printf("\n%s",wordbuf);
+                       }
                        else {
                                add_word(textlist,wordbuf);
                                strcpy(wordbuf,"");
                                printf("\n");
-                               }
                        }
+               }
                prev = a;
-               } while (finished==0);
+       } while (finished==0);
        async_ka_end();
 
        /* write the buffer back to disk */
@@ -311,8 +319,8 @@ void citedit(FILE *fp)
                ptr=textlist->next;
                free(textlist);
                textlist=ptr;
-               }
        }
+}
 
 
 int read_message(long int num, char pagin) /* Read a message from the server */
@@ -322,8 +330,7 @@ int read_message(long int num, char pagin) /* Read a message from the server */
        char buf[256];
        char m_subject[256];
        char from[256], node[256], rfca[256];
-       time_t now;
-       struct tm *tm;
+       char now[256];
        int format_type = 0;
        int fr = 0;
        int nhdr = 0;
@@ -368,15 +375,15 @@ int read_message(long int num, char pagin) /* Read a message from the server */
                return(0);
                }
 
-       while(serv_gets(buf), struncmp(buf,"text",4)) {
-               if (!struncmp(buf,"nhdr=yes",8)) nhdr=1;
-               if (!struncmp(buf,"from=",5)) {
+       while(serv_gets(buf), strncasecmp(buf,"text",4)) {
+               if (!strncasecmp(buf,"nhdr=yes",8)) nhdr=1;
+               if (!strncasecmp(buf,"from=",5)) {
                        strcpy(from,&buf[5]);
                        }
                if (nhdr==1) buf[0]='_';
-               if (!struncmp(buf,"type=",5))
+               if (!strncasecmp(buf,"type=",5))
                        format_type=atoi(&buf[5]);
-               if ((!struncmp(buf,"msgn=",5))&&(rc_display_message_numbers)) {
+               if ((!strncasecmp(buf,"msgn=",5))&&(rc_display_message_numbers)) {
                        color(DIM_WHITE);
                        printf("[");
                        color(BRIGHT_WHITE);
@@ -384,16 +391,16 @@ int read_message(long int num, char pagin) /* Read a message from the server */
                        color(DIM_WHITE);
                        printf("] ");
                        }
-               if (!struncmp(buf,"from=",5)) {
+               if (!strncasecmp(buf,"from=",5)) {
                        color(DIM_WHITE);
                        printf("from ");
                        color(BRIGHT_CYAN);
                        printf("%s ",&buf[5]);
                        }
-               if (!struncmp(buf,"subj=",5))
+               if (!strncasecmp(buf,"subj=",5))
                        strcpy(m_subject,&buf[5]);
 
-               if (!struncmp(buf,"rfca=",5)) {
+               if (!strncasecmp(buf,"rfca=",5)) {
                        safestrncpy(rfca, &buf[5], sizeof(rfca) - 5);
                        color(DIM_WHITE);
                        printf("<");
@@ -402,8 +409,8 @@ int read_message(long int num, char pagin) /* Read a message from the server */
                        color(DIM_WHITE);
                        printf("> ");
                        }
-               if ((!struncmp(buf,"hnod=",5)) 
-                  && (strucmp(&buf[5],serv_info.serv_humannode))
+               if ((!strncasecmp(buf,"hnod=",5)) 
+                  && (strcasecmp(&buf[5],serv_info.serv_humannode))
                   && (strlen(rfca) == 0) ) {
                        color(DIM_WHITE);
                        printf("(");
@@ -412,8 +419,8 @@ int read_message(long int num, char pagin) /* Read a message from the server */
                        color(DIM_WHITE);
                        printf(") ");
                        }
-               if ((!struncmp(buf,"room=",5))
-                  && (strucmp(&buf[5],room_name)) 
+               if ((!strncasecmp(buf,"room=",5))
+                  && (strcasecmp(&buf[5],room_name)) 
                   && (strlen(rfca) == 0)) {
                        color(DIM_WHITE);
                        printf("in ");
@@ -421,11 +428,11 @@ int read_message(long int num, char pagin) /* Read a message from the server */
                        printf("%s> ",&buf[5]);
                        }
 
-               if (!struncmp(buf,"node=",5)) {
+               if (!strncasecmp(buf,"node=",5)) {
                        safestrncpy(node, &buf[5], sizeof(buf) - 5);
                        if ( (room_flags&QR_NETWORK)
-                          || ((strucmp(&buf[5],serv_info.serv_nodename)
-                          &&(strucmp(&buf[5],serv_info.serv_fqdn)))) ) 
+                          || ((strcasecmp(&buf[5],serv_info.serv_nodename)
+                          &&(strcasecmp(&buf[5],serv_info.serv_fqdn)))) ) 
                                {
                                if (strlen(rfca) == 0) {
                                        color(DIM_WHITE);
@@ -436,19 +443,15 @@ int read_message(long int num, char pagin) /* Read a message from the server */
                        }
                }
 
-               if (!struncmp(buf,"rcpt=",5)) {
+               if (!strncasecmp(buf,"rcpt=",5)) {
                        color(DIM_WHITE);
                        printf("to ");
                        color(BRIGHT_CYAN);
                        printf("%s ",&buf[5]);
                        }
-               if (!struncmp(buf,"time=",5)) {
-                       now=atol(&buf[5]);
-                       tm=(struct tm *)localtime(&now);
-                       strcpy(buf,asctime(tm)); buf[strlen(buf)-1]=0;
-                       strcpy(&buf[16],&buf[19]);
-                       color(BRIGHT_MAGENTA);
-                       printf("%s ",&buf[4]);
+               if (!strncasecmp(buf,"time=",5)) {
+                       fmt_date(now, atol(&buf[5]));
+                       printf("%s ", now);
                        }
                }
 
@@ -539,7 +542,7 @@ void replace_string(char *filename, long int startpos)
                buf[strlen(buf)] = a;
                if ( strlen(buf) >= strlen(srch_str) ) {
                        ptr=&buf[strlen(buf)-strlen(srch_str)];
-                       if (!struncmp(ptr,srch_str,strlen(srch_str))) {
+                       if (!strncasecmp(ptr,srch_str,strlen(srch_str))) {
                                strcpy(ptr,rplc_str);
                                ++substitutions;
                                }
@@ -570,7 +573,6 @@ int make_message(char *filename,    /* temporary file name */
 { 
        FILE *fp;
        int a,b,e_ex_code;
-       time_t now;
        long beg;
        char datestr[64];
        int cksum = 0;
@@ -580,9 +582,7 @@ int make_message(char *filename,    /* temporary file name */
                mode=0;
                }
 
-       time(&now);
-       strcpy(datestr,asctime(localtime(&now)));
-       datestr[strlen(datestr)-1] = 0;
+       fmt_date(datestr, time(NULL));
 
        if (room_flags & QR_ANONONLY) {
                printf(" ****");
@@ -1064,8 +1064,7 @@ RMSGREAD: fflush(stdout);
                        color(DIM_WHITE);
                        printf(") ");
 
-                       if (is_mail==1) keyopt("<R>eply ");
-                       keyopt("<B>ack <A>gain <Q>uote <N>ext <S>top ");
+                       keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top ");
                        if (rc_url_cmd[0] && num_urls) keyopt("<U>RL View ");
                        keyopt("<?>Help/others -> ");
                        
@@ -1079,7 +1078,6 @@ RMSGREAD: fflush(stdout);
                                        if ((e=='d')||(e=='m')||(e=='c')) e=0;
                                        }
 /* print only if available */  if ((e=='p')&&(strlen(printcmd)==0)) e=0;
-/* can't reply in public rms */        if ((e=='r')&&(is_mail!=1)) e=0;
 /* can't file if not allowed */        if ((e=='f')&&(rc_allow_attachments==0)) e=0;
 /* link only if browser avail*/        if ((e=='u')&&(strlen(rc_url_cmd)==0)) e=0;
                                } while((e!='a')&&(e!='n')&&(e!='s')