From 2cccc1c0a32e9c693e13519537d23c58e20aca32 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 4 Mar 2000 22:36:24 +0000 Subject: [PATCH] * Remove nulls appended to editor files during replace, edit, and print operations. Truncate temp files during same operations. Closes bugs #6 and #7. --- citadel/ChangeLog | 6 ++++++ citadel/client_chat.c | 1 - citadel/client_icq.c | 1 - citadel/messages.c | 16 +++++++++------- citadel/messages.h | 1 + citadel/rooms.c | 4 ++-- citadel/routines2.c | 1 - 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 83a4ac804..db126f049 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,9 @@ $Log$ +Revision 1.477 2000/03/04 22:36:23 ajc +* Remove nulls appended to editor files during replace, edit, and print + operations. Truncate temp files during same operations. + Closes bugs #6 and #7. + Revision 1.476 2000/03/04 05:29:18 ajc * Relax restrictions on editing of base rooms. Renaming is not allowed but all other attributes can be edited. Closes feature request #21. @@ -1691,3 +1696,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/client_chat.c b/citadel/client_chat.c index 97805d157..e38f64976 100644 --- a/citadel/client_chat.c +++ b/citadel/client_chat.c @@ -40,7 +40,6 @@ extern struct CtdlServInfo serv_info; extern char temp[]; -void citedit(FILE *fp, long int base_pos); void getline(char *, int); void chatmode(void) { diff --git a/citadel/client_icq.c b/citadel/client_icq.c index 176eefd4f..66a3cf27d 100644 --- a/citadel/client_icq.c +++ b/citadel/client_icq.c @@ -33,7 +33,6 @@ extern struct CtdlServInfo serv_info; extern char temp[]; -void citedit(FILE *fp, long int base_pos); void getline(char *, int); struct icq_contact { diff --git a/citadel/messages.c b/citadel/messages.c index aa9dd081e..42a048bae 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -186,9 +186,9 @@ void add_word(struct cittext *textlist, char *wordbuf) /* - * begin editing of an opened file pointed to by fp, beginning at position pos. + * begin editing of an opened file pointed to by fp */ -void citedit(FILE *fp, long int base_pos) +void citedit(FILE *fp) { int a,prev,finished,b,last_space; int appending = 0; @@ -206,7 +206,7 @@ void citedit(FILE *fp, long int base_pos) time(&last_server_msg); /* first, load the text into the buffer */ - fseek(fp,base_pos,0); + fseek(fp, 0L, 0); textlist = (struct cittext *)malloc(sizeof(struct cittext)); textlist->next = NULL; strcpy(textlist->text,""); @@ -314,12 +314,13 @@ void citedit(FILE *fp, long int base_pos) } while (finished==0); /* write the buffer back to disk */ - fseek(fp,base_pos,0); + fseek(fp, 0L, 0); for (ptr=textlist; ptr!=NULL; ptr=ptr->next) { fprintf(fp,"%s",ptr->text); } putc(10,fp); - putc(0,fp); + fflush(fp); + ftruncate(fileno(fp), ftell(fp)); /* and deallocate the memory we used */ while (textlist!=NULL) { @@ -569,8 +570,9 @@ void replace_string(char *filename, long int startpos) } fseek(fp,wpos,0); if (strlen(buf)>0) fwrite((char *)buf,strlen(buf),1,fp); - putc(0,fp); + wpos = ftell(fp); fclose(fp); + truncate(filename, wpos); printf("eplace made %d substitution(s).\n\n",substitutions); } @@ -626,7 +628,7 @@ ME1: switch(mode) { case 0: fp=fopen(filename,"r+"); - citedit(fp, beg); + citedit(fp); fclose(fp); goto MECR; diff --git a/citadel/messages.h b/citadel/messages.h index aa43c472d..887915ff8 100644 --- a/citadel/messages.h +++ b/citadel/messages.h @@ -12,3 +12,4 @@ int make_message(char *filename, /* temporary file name */ int anon_type, /* see MES_ types in header file */ int format_type, int mode); +void citedit(FILE *); diff --git a/citadel/rooms.c b/citadel/rooms.c index 2e50e99a8..0f334ebab 100644 --- a/citadel/rooms.c +++ b/citadel/rooms.c @@ -18,6 +18,7 @@ #include "rooms.h" #include "commands.h" #include "tools.h" +#include "messages.h" #ifndef HAVE_SNPRINTF #include "snprintf.h" #endif @@ -36,7 +37,6 @@ void serv_read(char *buf, int bytes); void formout(char *name); int inkey(void); int fmout(int width, FILE *fp, char pagin, int height, int starting_lp, char subst); -void citedit(FILE *fp, long int base_pos); void progress(long int curr, long int cmax); int pattern(char *search, char *patn); int file_checksum(char *filename); @@ -960,7 +960,7 @@ void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd) printf("Entering %s. ",desc); printf("Press return twice when finished.\n"); fp=fopen(temp,"r+"); - citedit(fp,0); + citedit(fp); fclose(fp); } diff --git a/citadel/routines2.c b/citadel/routines2.c index 7efce58b4..d2629cd36 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -36,7 +36,6 @@ int inkey(void); void serv_write(char *buf, int nbytes); int haschar(char *st, int ch); void progress(long int curr, long int cmax); -void citedit(FILE * fp, long int base_pos); int yesno(void); extern char temp[]; -- 2.39.2