Index: client/climisc.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v retrieving revision 1.94 diff -u -r1.94 climisc.c --- client/climisc.c 2002/04/27 03:58:36 1.94 +++ client/climisc.c 2002/05/21 20:28:03 @@ -1162,3 +1162,20 @@ handle_chat_msg(&packet); } + +/************************************************************************** + Writes the supplied string into the file civgame.log. +**************************************************************************/ +void write_chatline_content(const char *txt) +{ + FILE *fp = fopen("civgame.log", "w"); /* should allow choice of name? */ + + append_output_window(_("Exporting output window to civgame.log ...")); + if (fp) { + fputs(txt, fp); + fclose(fp); + append_output_window(_("Export complete.")); + } else { + append_output_window(_("Export failed, couldn't write to file.")); + } +} Index: client/climisc.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v retrieving revision 1.34 diff -u -r1.34 climisc.h --- client/climisc.h 2002/03/17 10:48:50 1.34 +++ client/climisc.h 2002/05/21 20:28:03 @@ -109,8 +109,8 @@ int num_supported_units_in_city(struct city* pcity); char *get_spaceship_descr(struct player_spaceship *pship); - void create_event(int x, int y, int event, const char *format, ...) fc__attribute((format (printf, 4, 5))); +void write_chatline_content(const char *txt); #endif /* FC__CLIMISC_H */ Index: client/gui-gtk/chatline.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/chatline.c,v retrieving revision 1.15 diff -u -r1.15 chatline.c --- client/gui-gtk/chatline.c 2001/11/30 12:50:36 1.15 +++ client/gui-gtk/chatline.c 2002/05/21 20:28:03 @@ -23,6 +23,7 @@ #include "packets.h" #include "support.h" +#include "climisc.h" #include "clinet.h" #include "gui_main.h" #include "gui_stuff.h" @@ -82,18 +83,10 @@ the are somewhat related and append_output_window is already here. --dwp **************************************************************************/ void log_output_window(void) -{ - char *theoutput; - FILE *fp; - - append_output_window(_("Exporting output window to civgame.log ...")); - theoutput = gtk_editable_get_chars(GTK_EDITABLE(main_message_area), 0, -1); - fp = fopen("civgame.log", "w"); /* should allow choice of name? */ - fprintf(fp, "%s", theoutput); - fclose(fp); - append_output_window(_("Export complete.")); +{ + write_chatline_content(gtk_editable_get_chars + (GTK_EDITABLE(main_message_area), 0, -1)); } - /************************************************************************** ... **************************************************************************/ Index: client/gui-gtk-2.0/chatline.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/chatline.c,v retrieving revision 1.2 diff -u -r1.2 chatline.c --- client/gui-gtk-2.0/chatline.c 2002/03/11 23:19:24 1.2 +++ client/gui-gtk-2.0/chatline.c 2002/05/21 20:28:03 @@ -25,6 +25,7 @@ #include "packets.h" #include "support.h" +#include "climisc.h" #include "clinet.h" #include "gui_main.h" #include "gui_stuff.h" @@ -91,16 +92,9 @@ the are somewhat related and append_output_window is already here. --dwp **************************************************************************/ void log_output_window(void) -{ - char *theoutput; - FILE *fp; - - append_output_window(_("Exporting output window to civgame.log ...")); - theoutput = gtk_editable_get_chars(GTK_EDITABLE(main_message_area), 0, -1); - fp = fopen("civgame.log", "w"); /* should allow choice of name? */ - fprintf(fp, "%s", theoutput); - fclose(fp); - append_output_window(_("Export complete.")); +{ + write_chatline_content(gtk_editable_get_chars + (GTK_EDITABLE(main_message_area), 0, -1)); } /************************************************************************** Index: client/gui-mui/chatline.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/chatline.c,v retrieving revision 1.3 diff -u -r1.3 chatline.c --- client/gui-mui/chatline.c 2001/01/19 11:18:17 1.3 +++ client/gui-mui/chatline.c 2002/05/21 20:28:03 @@ -24,6 +24,7 @@ #include #include +#include "climisc.h" #include "fcintl.h" #include "gui_main.h" #include "muistuff.h" @@ -40,22 +41,24 @@ the are somewhat related and append_output_window is already here. --dwp **************************************************************************/ void log_output_window(void) -{ - char *str; - int i,entries = xget(main_output_listview, MUIA_NList_Entries); - FILE *fp; - - append_output_window(_("Exporting output window to civgame.log ...")); - fp = fopen("civgame.log", "w"); /* should allow choice of name? */ +{ + /* for terminating '\0' byte */ + size_t size = 1; + char *mem = fc_malloc(size); + int i, entries = xget(main_output_listview, MUIA_NList_Entries); - for (i=0;i