-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch-antiidle
340 lines (330 loc) · 8.58 KB
/
patch-antiidle
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
diff -ur ___ansi.c ansi.c
--- ___ansi.c Wed Mar 31 00:29:37 2004
+++ ansi.c Wed Mar 31 00:29:55 2004
@@ -306,7 +306,7 @@
cols = curr->w_width;
rows = curr->w_height;
- if (curr->w_silence)
+ if (curr->w_silence && curr->w_antiidle_str[0] == '\0')
SetTimeout(&curr->w_silenceev, curr->w_silencewait * 1000);
if (curr->w_monitor == MON_ON)
diff -ur ___comm.c comm.c
--- ___comm.c Mon Sep 8 22:25:08 2003
+++ comm.c Wed Mar 31 00:29:55 2004
@@ -53,6 +53,7 @@
#endif
{ "allpartial", NEED_DISPLAY|ARGS_1 },
{ "altscreen", ARGS_01 },
+ { "antiidle_str", NEED_FORE | ARGS_01 },
{ "at", NEED_DISPLAY|ARGS_2|ARGS_ORMORE },
#ifdef COLOR
{ "attrcolor", ARGS_12 },
@@ -124,6 +125,7 @@
{ "crlf", ARGS_01 },
#endif
{ "debug", ARGS_01 },
+ { "defantiidle_str", ARGS_01 },
#ifdef AUTO_NUKE
{ "defautonuke", ARGS_1 },
#endif
@@ -278,7 +280,7 @@
{ "setsid", ARGS_1 },
{ "shell", ARGS_1 },
{ "shelltitle", ARGS_1 },
- { "silence", NEED_FORE|ARGS_01 },
+ { "silence", NEED_FORE|ARGS_012 },
{ "silencewait", ARGS_1 },
{ "sleep", ARGS_1 },
{ "slowpaste", NEED_FORE|ARGS_01 },
diff -ur ___process.c process.c
--- ___process.c Thu Sep 18 20:53:54 2003
+++ process.c Wed Mar 31 00:29:55 2004
@@ -89,6 +89,7 @@
#ifdef POW_DETACH
extern char *BufferFile, *PowDetachString;
#endif
+extern char *AntiidleString;
#ifdef MULTIUSER
extern struct acluser *EffectiveAclUser; /* acl.c */
#endif
@@ -1018,6 +1019,94 @@
return i;
}
+void ParseStr(char dst[], char src[], int maxl)
+{
+ char *sp, *sp2;
+ char *dp;
+ unsigned long ul;
+ char c;
+ int sl;
+ int pre, base, nl;
+ int backslash = 0;
+
+ sp = src;
+ dp = dst;
+ sl = strlen(src);
+ while(*sp != '\0' && (int)(dp - dst) < maxl)
+ {
+ if(!backslash)
+ {
+ if(*sp == '\\')
+ {
+ backslash = 1;
+ sp ++;
+ }
+ else
+ *(dp ++) = *(sp ++);
+ }
+ else
+ {
+ switch(*sp)
+ {
+ case '\\':
+ *(dp ++) = '\\';
+ break;
+ case 'a':
+ *(dp ++) = '\a';
+ break;
+ case 'b':
+ *(dp ++) = '\b';
+ break;
+ case 'f':
+ *(dp ++) = '\f';
+ break;
+ case 'n':
+ *(dp ++) = '\n';
+ break;
+ case 'r':
+ *(dp ++) = '\r';
+ break;
+ case 't':
+ *(dp ++) = '\t';
+ break;
+ case 'v':
+ *(dp ++) = '\v';
+ break;
+ case '\'':
+ *(dp ++) = '\'';
+ break;
+ case '"':
+ *(dp ++) = '"';
+ break;
+ default:
+ if(*sp == 'x') /* base 16, 2 digits max */
+ pre = 1, base = 16, nl = 2;
+ else if(*sp >= '0' && *sp <= '9') /* base 8, 3 digits max */
+ pre = 0, base = 8, nl = 3;
+ else
+ break;
+
+ sp += pre;
+ if((int)(sp - src) + nl > sl)
+ nl = sl - (int)(sp - src);
+ c = *(sp + nl);
+ *(sp + nl) = '\0';
+ if((ul = strtoul(sp, &sp2, base)), sp2 > sp)
+ *(dp ++) = (char)ul;
+ else
+ sp2 = sp - pre;
+ *(sp + nl) = c;
+ sp = sp2 - 1;
+ break;
+ }
+ sp ++;
+ backslash = 0;
+ }
+ }
+ *dp = '\0';
+ dst[maxl - 1] = '\0';
+}
+
/*ARGSUSED*/
void
DoAction(act, key)
@@ -2794,13 +2883,61 @@
WindowChanged((struct win *)0, 0);
}
break;
+ case RC_DEFANTIIDLE_STR:
+ if(argc == 1 && args[0] != NULL)
+ {
+ char buf[MAXSTR];
+
+ ParseStr(buf, args[0], MAXSTR);
+ if(AntiidleString != NULL)
+ free(AntiidleString);
+ AntiidleString = SaveStr(buf);
+ }
+ else if(AntiidleString != NULL)
+ {
+ free(AntiidleString);
+ AntiidleString = NULL;
+ }
+ break;
+ case RC_ANTIIDLE_STR:
+ if(argc == 1 && args[0] != NULL)
+ {
+ ParseStr(fore->w_antiidle_str, args[0], MAXSTR);
+ Msg(0, "Set antiidle_str.");
+ }
+ else if(fore->w_silence)
+ {
+ fore->w_antiidle_str[0] = '\0';
+ SetTimeout(&fore->w_silenceev, fore->w_silencewait * 1000);
+ evenq(&fore->w_silenceev);
+
+ if (!msgok)
+ break;
+ Msg(0, "The window is now being monitored for %d sec. silence.", fore->w_silencewait);
+ }
+ else
+ {
+ fore->w_antiidle_str[0] = '\0';
+ Msg(0, "Unset antiidle_str.");
+ }
+ break;
case RC_SILENCE:
n = fore->w_silence != 0;
i = fore->w_silencewait;
+ if(argc == 2 && args[1] != NULL && args[1][0] != '\0')
+ {
+ ParseStr(fore->w_antiidle_str, args[1], MAXSTR);
+ }
if (args[0] && (args[0][0] == '-' || (args[0][0] >= '0' && args[0][0] <= '9')))
{
+ s = args[1];
+ args[1] = NULL;
if (ParseNum(act, &i))
+ {
+ args[1] = s;
break;
+ }
+ args[1] = s;
n = i > 0;
}
else if (ParseSwitch(act, &n))
@@ -2821,7 +2958,10 @@
if (!msgok)
break;
- Msg(0, "The window is now being monitored for %d sec. silence.", fore->w_silencewait);
+ if(fore->w_antiidle_str[0] == '\0')
+ Msg(0, "The window is now being monitored for %d sec. silence.", fore->w_silencewait);
+ else
+ Msg(0, "The window is now being monitored for %d sec. anti-idle.", fore->w_silencewait);
}
else
{
@@ -2843,7 +2983,10 @@
}
if (!msgok)
break;
- Msg(0, "The window is no longer being monitored for silence.");
+ if(fore->w_antiidle_str[0] == '\0')
+ Msg(0, "The window is no longer being monitored for silence.");
+ else
+ Msg(0, "The window is no longer being monitored for anti-idle.");
}
break;
#ifdef COPY_PASTE
@@ -4467,7 +4610,7 @@
#ifdef MULTIUSER
ReleaseAutoWritelock(display, p);
#endif
- if (p->w_silence)
+ if (p->w_silence && p->w_antiidle_str[0] == '\0')
{
SetTimeout(&p->w_silenceev, p->w_silencewait * 1000);
evenq(&p->w_silenceev);
diff -ur ___screen.c screen.c
--- ___screen.c Mon Sep 8 22:26:41 2003
+++ screen.c Wed Mar 31 00:29:55 2004
@@ -190,6 +190,7 @@
#ifdef POW_DETACH
char *PowDetachString;
#endif
+char *AntiidleString;
char *hstatusstring;
char *captionstring;
char *timestring;
@@ -447,6 +448,7 @@
#ifdef POW_DETACH
PowDetachString = 0;
#endif
+ AntiidleString = NULL;
default_startup = (ac > 1) ? 0 : 1;
adaptflag = 0;
VBellWait = VBELLWAIT * 1000;
diff -ur ___window.c window.c
--- ___window.c Fri Dec 5 21:45:41 2003
+++ window.c Wed Mar 31 00:30:02 2004
@@ -60,6 +60,7 @@
extern char *zmodem_sendcmd;
extern char *zmodem_recvcmd;
#endif
+extern char *AntiidleString;
#if defined(TIOCSWINSZ) || defined(TIOCGWINSZ)
extern struct winsize glwz;
@@ -241,6 +242,8 @@
int l2 = 0, f, *ilen, l = *lenp, trunc;
char *ibuf;
+ if (fore->w_silence && fore->w_antiidle_str[0] != '\0' && !InInput())
+ SetTimeout(&fore->w_silenceev, fore->w_silencewait * 1000);
debug1("WinProcess: %d bytes\n", *lenp);
fore = (struct win *)flayer->l_data;
@@ -668,6 +671,13 @@
*/
p->w_silence = nwin.silence;
p->w_silencewait = SilenceWait;
+ if(AntiidleString == NULL)
+ p->w_antiidle_str[0] = '\0';
+ else
+ {
+ strncpy(p->w_antiidle_str, AntiidleString, MAXSTR);
+ p->w_antiidle_str[MAXSTR - 1] = '\0';
+ }
#ifdef MULTIUSER
if (p->w_silence == SILENCE_ON)
{
@@ -1989,8 +1999,32 @@
if (!(ACLBYTE(p->w_lio_notify, D_user->u_id) & ACLBIT(D_user->u_id)))
continue;
#endif
- Msg(0, "Window %d: silence for %d seconds", p->w_number, p->w_silencewait);
+ if(p->w_antiidle_str[0] == '\0')
+ Msg(0, "Window %d: silence for %d seconds", p->w_number, p->w_silencewait);
+ else
+ Msg(0, "Window %d: idle for %d seconds, send antiidle_str", p->w_number, p->w_silencewait);
}
+ if(p->w_antiidle_str[0] != '\0')
+ {
+ struct paster *pa;
+ struct win *old_fore;
+ struct layer *old_flayer;
+
+ pa = &p->w_paster;
+ FreePaster(pa);
+ pa->pa_pasteptr = p->w_antiidle_str;
+ pa->pa_pastelen = strlen(p->w_antiidle_str);
+ pa->pa_pastelayer = &p->w_layer;
+ old_fore = fore;
+ old_flayer = flayer;
+ fore = p;
+ flayer = &p->w_layer;
+ DoProcess(p, &pa->pa_pasteptr, &pa->pa_pastelen, pa);
+ fore = old_fore;
+ flayer = old_flayer;
+ SetTimeout(&p->w_silenceev, p->w_silencewait * 1000);
+ evenq(&p->w_silenceev);
+ }
}
#ifdef ZMODEM
diff -ur ___window.h window.h
--- ___window.h Thu Aug 21 22:57:30 2003
+++ window.h Wed Mar 31 00:29:55 2004
@@ -273,6 +273,8 @@
struct mline *w_alt_hlines;
int w_alt_histidx;
#endif
+
+ char w_antiidle_str[MAXSTR];
};