Lines 62-67
static const char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93";
Link Here
|
62 |
#include <time.h> |
62 |
#include <time.h> |
63 |
#include <unistd.h> |
63 |
#include <unistd.h> |
64 |
#include <utmpx.h> |
64 |
#include <utmpx.h> |
|
|
65 |
#include <wchar.h> |
66 |
#include <wctype.h> |
65 |
|
67 |
|
66 |
#include "ttymsg.h" |
68 |
#include "ttymsg.h" |
67 |
|
69 |
|
Lines 185-198
void
Link Here
|
185 |
makemsg(char *fname) |
187 |
makemsg(char *fname) |
186 |
{ |
188 |
{ |
187 |
int cnt; |
189 |
int cnt; |
188 |
unsigned char ch; |
190 |
wchar_t ch; |
189 |
struct tm *lt; |
191 |
struct tm *lt; |
190 |
struct passwd *pw; |
192 |
struct passwd *pw; |
191 |
struct stat sbuf; |
193 |
struct stat sbuf; |
192 |
time_t now; |
194 |
time_t now; |
193 |
FILE *fp; |
195 |
FILE *fp; |
194 |
int fd; |
196 |
int fd; |
195 |
char *p, hostname[MAXHOSTNAMELEN], lbuf[256], tmpname[64]; |
197 |
char hostname[MAXHOSTNAMELEN], tmpname[64]; |
|
|
198 |
wchar_t *p, *tmp, lbuf[256], codebuf[13]; |
196 |
const char *tty; |
199 |
const char *tty; |
197 |
const char *whom; |
200 |
const char *whom; |
198 |
gid_t egid; |
201 |
gid_t egid; |
Lines 220-297
makemsg(char *fname)
Link Here
|
220 |
* Which means that we may leave a non-blank character |
223 |
* Which means that we may leave a non-blank character |
221 |
* in column 80, but that can't be helped. |
224 |
* in column 80, but that can't be helped. |
222 |
*/ |
225 |
*/ |
223 |
(void)fprintf(fp, "\r%79s\r\n", " "); |
226 |
(void)fwprintf(fp, L"\r%79s\r\n", " "); |
224 |
(void)snprintf(lbuf, sizeof(lbuf), |
227 |
(void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t), |
225 |
"Broadcast Message from %s@%s", |
228 |
L"Broadcast Message from %s@%s", |
226 |
whom, hostname); |
229 |
whom, hostname); |
227 |
(void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf); |
230 |
(void)fwprintf(fp, L"%-79.79S\007\007\r\n", lbuf); |
228 |
(void)snprintf(lbuf, sizeof(lbuf), |
231 |
(void)swprintf(lbuf, sizeof(lbuf)/sizeof(wchar_t), |
229 |
" (%s) at %d:%02d %s...", tty, |
232 |
L" (%s) at %d:%02d %s...", tty, |
230 |
lt->tm_hour, lt->tm_min, lt->tm_zone); |
233 |
lt->tm_hour, lt->tm_min, lt->tm_zone); |
231 |
(void)fprintf(fp, "%-79.79s\r\n", lbuf); |
234 |
(void)fwprintf(fp, L"%-79.79S\r\n", lbuf); |
232 |
} |
235 |
} |
233 |
(void)fprintf(fp, "%79s\r\n", " "); |
236 |
(void)fwprintf(fp, L"%79s\r\n", " "); |
234 |
|
237 |
|
235 |
if (fname) { |
238 |
if (fname) { |
236 |
egid = getegid(); |
239 |
egid = getegid(); |
237 |
setegid(getgid()); |
240 |
setegid(getgid()); |
238 |
if (freopen(fname, "r", stdin) == NULL) |
241 |
if (freopen(fname, "r", stdin) == NULL) |
239 |
err(1, "can't read %s", fname); |
242 |
err(1, "can't read %s", fname); |
240 |
setegid(egid); |
243 |
setegid(egid); |
241 |
} |
244 |
} |
242 |
cnt = 0; |
245 |
cnt = 0; |
243 |
while (fgets(lbuf, sizeof(lbuf), stdin)) { |
246 |
while (fgetws(lbuf, sizeof(lbuf)/sizeof(wchar_t), stdin)) { |
244 |
for (p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) { |
247 |
for (p = lbuf; (ch = *p) != L'\0'; ++p, ++cnt) { |
245 |
if (ch == '\r') { |
248 |
if (ch == L'\r') { |
246 |
putc('\r', fp); |
249 |
putwc(L'\r', fp); |
247 |
cnt = 0; |
250 |
cnt = 0; |
248 |
continue; |
251 |
continue; |
249 |
} else if (ch == '\n') { |
252 |
} else if (ch == L'\n') { |
250 |
for (; cnt < 79; ++cnt) |
253 |
for (; cnt < 79; ++cnt) |
251 |
putc(' ', fp); |
254 |
putwc(L' ', fp); |
252 |
putc('\r', fp); |
255 |
putwc(L'\r', fp); |
253 |
putc('\n', fp); |
256 |
putwc(L'\n', fp); |
254 |
break; |
257 |
break; |
255 |
} |
258 |
} |
256 |
if (cnt == 79) { |
259 |
if (cnt == 79) { |
257 |
putc('\r', fp); |
260 |
putwc(L'\r', fp); |
258 |
putc('\n', fp); |
261 |
putwc(L'\n', fp); |
259 |
cnt = 0; |
262 |
cnt = 0; |
260 |
} |
263 |
} |
261 |
if (((ch & 0x80) && ch < 0xA0) || |
264 |
if (iswprint(ch) || iswspace(ch) || ch == L'\a' || ch == L'\b') { |
262 |
/* disable upper controls */ |
265 |
putwc(ch, fp); |
263 |
(!isprint(ch) && !isspace(ch) && |
266 |
} else { |
264 |
ch != '\a' && ch != '\b') |
267 |
(void)swprintf(codebuf, sizeof(codebuf)/sizeof(wchar_t), L"<0x%X>", ch); |
265 |
) { |
268 |
for (tmp = codebuf; *tmp != L'\0'; ++tmp) { |
266 |
if (ch & 0x80) { |
269 |
putwc(*tmp, fp); |
267 |
ch &= 0x7F; |
|
|
268 |
putc('M', fp); |
269 |
if (++cnt == 79) { |
270 |
if (++cnt == 79) { |
270 |
putc('\r', fp); |
271 |
putwc(L'\r', fp); |
271 |
putc('\n', fp); |
272 |
putwc(L'\n', fp); |
272 |
cnt = 0; |
|
|
273 |
} |
274 |
putc('-', fp); |
275 |
if (++cnt == 79) { |
276 |
putc('\r', fp); |
277 |
putc('\n', fp); |
278 |
cnt = 0; |
279 |
} |
280 |
} |
281 |
if (iscntrl(ch)) { |
282 |
ch ^= 040; |
283 |
putc('^', fp); |
284 |
if (++cnt == 79) { |
285 |
putc('\r', fp); |
286 |
putc('\n', fp); |
287 |
cnt = 0; |
273 |
cnt = 0; |
288 |
} |
274 |
} |
289 |
} |
275 |
} |
|
|
276 |
--cnt; |
290 |
} |
277 |
} |
291 |
putc(ch, fp); |
|
|
292 |
} |
278 |
} |
293 |
} |
279 |
} |
294 |
(void)fprintf(fp, "%79s\r\n", " "); |
280 |
(void)fwprintf(fp, L"%79s\r\n", " "); |
295 |
rewind(fp); |
281 |
rewind(fp); |
296 |
|
282 |
|
297 |
if (fstat(fd, &sbuf)) |
283 |
if (fstat(fd, &sbuf)) |