Neale Pickett
·
2008-04-21
xbell.c
1/* xbell -- sound the X11 bell
2 * Copyright (C) 2008 Neale Pickett <neale@woozle.org>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20
21#include <X11/Xlib.h>
22
23#include "obj.h"
24
25int
26main(int argc, char *argv[])
27{
28 Display *display = NULL;
29 int percent = 100;
30
31 if (argc == 2) {
32 percent = (int)strtol(argv[1], NULL, 10);
33 }
34 if ((argc > 2) || (0 == percent)) {
35 (void)fprintf(stderr, "Usage: %s [PERCENT]\n", argv[0]);
36 return 64; /* EX_USAGE */
37 }
38
39 try {
40 if (! (display = XOpenDisplay(NULL))) raise("cannot open display");
41 if (! (XBell(display, percent))) break;
42 } while (0);
43
44 if (display) {
45 (void)XCloseDisplay(display);
46 }
47
48 except {
49 (void)fprintf(stderr, "Error: %s\n", exception);
50 return 69; /* EX_UNAVAILABLE */
51 }
52
53 return 0;
54}