Annotation of src/usr.bin/mg/bell.c, Revision 1.7
1.7 ! guenther 1: /* $OpenBSD: bell.c,v 1.6 2021/05/06 12:44:21 lum Exp $ */
1.1 lum 2:
3: /*
4: * This file is in the public domain.
5: *
6: * Author: Mark Lumsden <mark@showcomplex.com>
7: *
8: */
9:
10: /*
11: * Control how mg communicates with the user.
12: */
1.3 bcallah 13:
14: #include <sys/queue.h>
15: #include <signal.h>
16: #include <stdio.h>
17: #include <unistd.h>
1.1 lum 18:
19: #include "def.h"
1.4 lum 20: #include "macro.h"
1.1 lum 21:
22: void
23: bellinit(void)
24: {
25: doaudiblebell = 1;
26: dovisiblebell = 0;
1.6 lum 27: }
28:
29: int
30: dobeep_num(const char *msg, int n)
31: {
32: ewprintf("%s %d", msg, n);
33: dobeep();
34: return (FALSE);
1.5 lum 35: }
36:
37: int
38: dobeep_msgs(const char *msg, const char *s)
39: {
40: ewprintf("%s %s", msg, s);
41: dobeep();
42: return (FALSE);
43: }
44:
45: int
46: dobeep_msg(const char *msg)
47: {
48: ewprintf("%s", msg);
49: dobeep();
50: return (FALSE);
1.1 lum 51: }
52:
53: void
54: dobeep(void)
55: {
56: if (doaudiblebell) {
57: ttbeep();
58: }
59: if (dovisiblebell) {
60: sgarbf = TRUE;
61: update(CNONE);
1.4 lum 62: if (inmacro) /* avoid delaying macro execution. */
63: return;
1.1 lum 64: usleep(50000);
65: }
66: }
67:
68: int
69: toggleaudiblebell(int f, int n)
70: {
71: if (f & FFARG)
72: doaudiblebell = n > 0;
73: else
74: doaudiblebell = !doaudiblebell;
75:
76: return (TRUE);
77: }
78:
79: int
80: togglevisiblebell(int f, int n)
81: {
82: if (f & FFARG)
83: dovisiblebell = n > 0;
84: else
85: dovisiblebell = !dovisiblebell;
86:
87: return (TRUE);
88: }