File: wordwrap.patch

package info (click to toggle)
netkit-ntalk 0.17-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 292 kB
  • ctags: 264
  • sloc: ansic: 2,222; makefile: 99; sh: 78
file content (122 lines) | stat: -rw-r--r-- 3,066 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
This patch is not applied because it implements wordwrap in a way that
makes the local screen (where both your text and the other guy's text
get wordwrapped) differ from the remote screen (where they don't). I'm
not convinced this is a good idea.

However, because the patch might be useful, it is included here.

(The diffs were modified by dholland to fix some minor bugs.)


Date: Fri, 17 Apr 1998 18:21:17 -0500
From: Dale Osowski <dosowski0474@VAX2.WINONA.MSUS.EDU>
Subject: talk program

I have added a word wrap feature to "talk" today.  I have attached the
diffs to this email.

I hope there isn't a problem with how I did it.  I added to members to
the xwin_t struct in order to keep track of where a word starts.

--
Dale Osowski
dosowski0474@vax2.winona.msus.edu
http://web.winona.msus.edu/~dosowski

--- display.c	1998/11/27 11:30:43	1.7
+++ display.c	1998/11/27 12:03:08
@@ -40,8 +40,9 @@
 /*
  * The window 'manager', initializes curses and handles the actual
  * displaying of text
  */
+#include <stdlib.h>
 #include "talk.h"
 
 static void xscroll(xwin_t *win, int flag);
 static int readwin(WINDOW *win, int line, int col);
@@ -62,8 +63,37 @@
 
 	return (a > b ? a : b);
 }
 
+
+/* 
+ * Wordwrap added by Dale Osowski (dosowski0474@vax2.winona.msus.edu)
+ * on 4/17/98
+ */
+static void
+wordwrap(xwin_t *win)
+{
+	int oldline = win->x_lspaceline;
+	int oldcol = win->x_lspacecol;
+	int i, n = COLS-1-oldcol-1;
+        char *tomovedown = malloc(n);
+
+	wmove(win->x_win, oldline, oldcol+1);
+	for (i=0; i<n; i++) {
+		tomovedown[i] = readwin(win->x_win, oldline, i+oldcol+1);
+	}
+
+	wmove(win->x_win, oldline, oldcol+1);
+	wclrtoeol(win->x_win);
+	wmove(win->x_win, oldline, oldcol+1);
+	xscroll(win, 0);
+	for (i=0; i<n; i++) {
+		waddch(win->x_win, tomovedown[i]);
+	}
+	free(tomovedown);
+}
+
+
 /*
  * Display some text on somebody's window, processing some control
  * characters while we are at it.
  */
@@ -79,8 +109,14 @@
 			text++;
 			continue;
 		}
 
+                /* Mark position of last space.  For wordwrap */
+		if (*text == ' ')
+		{
+			getyx(win->x_win, win->x_lspaceline, win->x_lspacecol);
+		}
+
 		/* someday erase characters will work properly in unix */
 		if (*text == '\b' || *text == 127) *text = win->cerase;
 
 		/* erase character */
@@ -142,10 +178,16 @@
 			text++;
 			continue;
 		}
 		if (win->x_col == COLS-1) {
-			/* check for wraparound */
-			xscroll(win, 0);
+			/* check for wraparound -- wordwrap */
+			if (win->x_lspaceline == win->x_line && 
+			    win->x_lspacecol > 1) {
+				wordwrap(win);
+			}
+			else {
+				xscroll(win, 0);
+			}
 		}
 		if ((*text & 0x7F) < ' ' && *text != '\t') {
 			waddch(win->x_win, '^');
 			getyx(win->x_win, win->x_line, win->x_col);
--- talk.h	1998/11/27 10:55:58	1.13
+++ talk.h	1998/11/27 11:55:52
@@ -55,8 +55,10 @@
 	int	x_col;
 	char	kill;
 	char	cerase;
 	char	werase;
+	int     x_lspacecol;   /* column of last space character */
+	int     x_lspaceline;  /* line of last space character   */
 } xwin_t;
 
 extern	xwin_t my_win;
 extern	xwin_t his_win;