[CF-Devel] patch: Repeated line supression for the gtk client.

crossfire-devel-admin at archives.real-time.com crossfire-devel-admin at archives.real-time.com
Tue Jul 29 06:32:31 CDT 2003


Hi there.

I've made a patch to the gtk client that changes repeated lines in
the info window into lines prefixed with number saying how many times
it has been repeated. Ie:

Instead of:
You pray.
You pray.
You pray.
You pray.

it says:
(4) You pray.

There is a new command line option: -repeat that tells how many lines
back it should look for repeated info, default is ten, zero turns off the
feature. The code also has a hard limit set (ten in this patch, just
change MAX_LINES). If a line is found to be repeated, the code will
only prefix/change the line to have the new "(X) " string in front of
it, it will not move the old line to the bottom. I found that to be
easier to read compared to having the messages move around.

Please commit it to CVS if it is acceptable.

----------------8<----------------
Index: common/client.h
===================================================================
RCS file: /cvsroot/crossfire/client/common/client.h,v
retrieving revision 1.12
diff -u -r1.12 client.h
--- common/client.h	8 Jul 2003 12:52:35 -0000	1.12
+++ common/client.h	29 Jul 2003 11:16:39 -0000
@@ -163,7 +163,8 @@
 #define CONFIG_RESISTS      27
 #define CONFIG_SMOOTH       28
 #define CONFIG_SPLASH	    29
-#define CONFIG_NUMS	    30
+#define CONFIG_REPEAT	    30
+#define CONFIG_NUMS	    31
 
 /* CONFIG_LIGHTING can have several possible values - set them accordingly */
 #define CFG_LT_TILE	    1
Index: common/init.c
===================================================================
RCS file: /cvsroot/crossfire/client/common/init.c,v
retrieving revision 1.12
diff -u -r1.12 init.c
--- common/init.c	25 Jun 2003 17:13:58 -0000	1.12
+++ common/init.c	29 Jul 2003 11:16:39 -0000
@@ -42,7 +42,7 @@
 "mapscale", "popups", "sdl", "showicon", "tooltips", "sound", "splitinfo",
 "split", "show_grid", "lighting", "trim_info_window",
 "map_width", "map_height", "foodbeep", "darkness", "port",
-"grad_color_bars", "resists", "smoothing", "nosplash"
+"grad_color_bars", "resists", "smoothing", "nosplash", "repeat"
 };
 
 sint16 want_config[CONFIG_NUMS], use_config[CONFIG_NUMS];
@@ -192,6 +192,7 @@
     want_config[CONFIG_RESISTS] = 0;
     want_config[CONFIG_SMOOTH] = 0;
     want_config[CONFIG_SPLASH] = TRUE;
+    want_config[CONFIG_REPEAT] = 10;
     for (i=0; i<CONFIG_NUMS; i++) 
 	use_config[i] = want_config[i];
 
Index: gtk/gx11.c
===================================================================
RCS file: /cvsroot/crossfire/client/gtk/gx11.c,v
retrieving revision 1.32
diff -u -r1.32 gx11.c
--- gtk/gx11.c	25 Jun 2003 17:13:58 -0000	1.32
+++ gtk/gx11.c	29 Jul 2003 11:16:42 -0000
@@ -1895,19 +1895,106 @@
  * good - otherewise, performance slowly degrades.
  */
 
+#define MAX_LINES (10)
+
+struct s_old_lines {
+    char str[MAXSOCKBUF];
+    guint start;
+    int length;
+    int num;
+    int color;
+};
+
 void draw_info(const char *str, int color) {
     int ncolor = color;
-  
+    static struct s_old_lines old_lines[MAX_LINES];
+    GtkWidget *info_text = NULL;
+    int i;
+
     if (ncolor==NDI_WHITE) {
 	ncolor=NDI_BLACK;
     }
 
+    if(use_config[CONFIG_REPEAT] > MAX_LINES) {
+      use_config[CONFIG_REPEAT] = MAX_LINES;
+    }
+
     strcpy (last_str, str);
+
+    /* Freeze it */
+
     if (use_config[CONFIG_SPLITINFO] && color != NDI_BLACK) {
-	if (!draw_info_freeze2){
-	    gtk_text_freeze (GTK_TEXT (gtkwin_info_text2));
-	    draw_info_freeze2=TRUE;
+        info_text = gtkwin_info_text2;
+        if (!draw_info_freeze2) {
+            gtk_text_freeze (GTK_TEXT (gtkwin_info_text2));
+            draw_info_freeze2=TRUE;
+        }
+    } else {
+        info_text = gtkwin_info_text;
+	if (!draw_info_freeze1) {
+	    gtk_text_freeze (GTK_TEXT (gtkwin_info_text));
+	    draw_info_freeze1=TRUE;
 	}
+    }
+
+    /* Less then five characters is probably a prompt... */
+    if (use_config[CONFIG_REPEAT]) {
+        if(strlen(str) > 5 && !strchr(str, '\n')) {
+            for(i = 0; i < use_config[CONFIG_REPEAT]; i++) {
+                if (!strcmp(str, old_lines[i].str)) {
+                    char small_buffer[10];
+                    int old_size;
+
+                    gtk_text_set_point(GTK_TEXT(info_text),old_lines[i].start);
+
+                    if(old_lines[i].num == 1) {
+                        old_size = 0;
+                    } else {
+                        sprintf(small_buffer, "(%i) ", old_lines[i].num);
+                        old_size = strlen(small_buffer);
+                        gtk_text_forward_delete(GTK_TEXT(info_text), old_size);
+                    }
+
+                    sprintf(small_buffer, "(%i) ", ++(old_lines[i].num));
+                    gtk_text_insert (GTK_TEXT (info_text), NULL,
+                                     &root_color[old_lines[i].color], NULL,
+                                     small_buffer , -1);
+                    if(strlen(small_buffer) != old_size) {
+                        int j;
+                        for(j = i+1; j < use_config[CONFIG_REPEAT]; j++) {
+                            old_lines[j].start +=
+                                strlen(small_buffer) - old_size;
+                        }
+                    }
+
+                    info2_num_chars = gtk_text_get_length(GTK_TEXT(info_text));
+                    gtk_text_set_point(GTK_TEXT(info_text), info2_num_chars);
+                    return;
+                }
+            }
+
+            memmove(&old_lines[0], &old_lines[1],
+                    sizeof(old_lines[1]) * (use_config[CONFIG_REPEAT]-1));
+            strcpy(old_lines[use_config[CONFIG_REPEAT]-1].str, str);
+            old_lines[use_config[CONFIG_REPEAT]-1].length = strlen(str);
+            old_lines[use_config[CONFIG_REPEAT]-1].start =
+                gtk_text_get_length(GTK_TEXT(info_text));
+            old_lines[use_config[CONFIG_REPEAT]-1].color = ncolor;
+            old_lines[use_config[CONFIG_REPEAT]-1].num = 1;
+        } else {
+            /* Move the oldest line out of the buffer anyway */
+            memmove(&old_lines[0], &old_lines[1],
+                    sizeof(old_lines[1]) * (use_config[CONFIG_REPEAT]-1));
+            *old_lines[use_config[CONFIG_REPEAT]-1].str = 0;
+            old_lines[use_config[CONFIG_REPEAT]-1].length = strlen(str);
+            old_lines[use_config[CONFIG_REPEAT]-1].start =
+                gtk_text_get_length(GTK_TEXT(info_text));
+            old_lines[use_config[CONFIG_REPEAT]-1].color = ncolor;
+            old_lines[use_config[CONFIG_REPEAT]-1].num = 1;
+        }
+    }
+
+    if (use_config[CONFIG_SPLITINFO] && color != NDI_BLACK) {
 	if (use_config[CONFIG_TRIMINFO]) {
 	    info2_num_chars += strlen(str) + 1;
 	    /* Limit size of scrollback buffer. To be more efficient, delete a good
@@ -1917,20 +2004,16 @@
 	    if (info2_num_chars > info2_max_chars ) {
 		gtk_text_set_point(GTK_TEXT(gtkwin_info_text2),0);
 		gtk_text_forward_delete(GTK_TEXT(gtkwin_info_text2), (info2_num_chars - info2_max_chars) + 5000);
+                for(i=0; i < use_config[CONFIG_REPEAT]; i++) {
+                    old_lines[i].start -= (info2_num_chars - info2_max_chars) + 5000;
+                }
 		info2_num_chars = gtk_text_get_length(GTK_TEXT(gtkwin_info_text2));
 		gtk_text_set_point(GTK_TEXT(gtkwin_info_text2), info2_num_chars);
 		fprintf(stderr,"reduced output buffer2 to %d chars\n", info1_num_chars);
 	    }
 	}
-	gtk_text_insert (GTK_TEXT (gtkwin_info_text2), NULL, &root_color[ncolor], NULL, str , -1);
-	gtk_text_insert (GTK_TEXT (gtkwin_info_text2), NULL, &root_color[ncolor], NULL, "\n" , -1);
-
     } else {
 	/* all nootes in the above section apply here also */
-	if (!draw_info_freeze1){
-	    gtk_text_freeze (GTK_TEXT (gtkwin_info_text));
-	    draw_info_freeze1=TRUE;
-	}
 	if (use_config[CONFIG_TRIMINFO]) {
 	    info1_num_chars += strlen(str) + 1;
 	    if (info1_num_chars > info1_max_chars ) {
@@ -1941,6 +2024,9 @@
 		    to_delete++;
 		gtk_text_set_point(GTK_TEXT(gtkwin_info_text),0);
 		gtk_text_forward_delete(GTK_TEXT(gtkwin_info_text), to_delete);
+                for(i=0; i < use_config[CONFIG_REPEAT]; i++) {
+                    old_lines[i].start -= (info2_num_chars - info2_max_chars) + 5000;
+                }
 		info1_num_chars = gtk_text_get_length(GTK_TEXT(gtkwin_info_text));
 		gtk_text_set_point(GTK_TEXT(gtkwin_info_text), info1_num_chars);
 		fprintf(stderr,"trim_info_window, deleted %d characters, %d remaining\n", to_delete, info1_num_chars);
@@ -1955,10 +2041,10 @@
 	    }
 	    
 	}
-
-	gtk_text_insert (GTK_TEXT (gtkwin_info_text), NULL, &root_color[ncolor], NULL, str , -1);
-	gtk_text_insert (GTK_TEXT (gtkwin_info_text), NULL, &root_color[ncolor], NULL, "\n" , -1);
     }
+    gtk_text_insert (GTK_TEXT (info_text), NULL, &root_color[ncolor], NULL, str , -1);
+    gtk_text_insert (GTK_TEXT (info_text), NULL, &root_color[ncolor], NULL, "\n" , -1);
+
 }
 
 
@@ -5121,6 +5207,7 @@
     puts("-triminfowindow  - Trims size of information window(s)");
     puts("-notriminfowindow  - Do not trims size of information window(s) (default)");
     puts("-updatekeycodes  - Update the saved bindings for this keyboard.");
+    puts("-repeat <num>    - How many lines back we look for repeated text.");
 
     exit(0);
 }
@@ -5353,6 +5440,14 @@
 	}
 	else if (!strcmp(argv[on_arg],"-nosplash")) {
 	    want_config[CONFIG_SPLASH] = FALSE;
+	    continue;
+        }
+        else if (!strcmp(argv[on_arg],"-repeat")) {
+	    if (++on_arg == argc) {
+		fprintf(stderr,"-repeat requires a value\n");
+		return 1;
+	    }
+	    want_config[CONFIG_REPEAT]=atoi(argv[on_arg]);
 	    continue;
 	}
 	else {
----------------8<----------------

/Sebastian
-- 
                             .oooO o,o Oooo.
                             (   ) \_/ (   )      (o_
"Life is not fair, but root   \ (  /|\  ) / (o_   //\
password helps!" -- The BOFH   \_)     (_/  (/)_  V_/_

_______________________________________________
crossfire-devel mailing list
     
     crossfire-devel at lists.real-time.com
     
     
     https://mailman.real-time.com/mailman/listinfo/crossfire-devel
     
     
    


More information about the crossfire mailing list