Sync usage with man page.
[netbsd-mini2440.git] / usr.sbin / wsmoused / action.c
blobb7b18afb7b27454749171c1aa203f2ac6dac15c0
1 /* $NetBSD: action.c,v 1.1 2003/08/06 22:11:49 jmmv Exp $ */
3 /*
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name authors may not be used to endorse or promote products
16 * derived from this software without specific prior written
17 * permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 #ifndef lint
35 __RCSID("$NetBSD: action.c,v 1.1 2003/08/06 22:11:49 jmmv Exp $");
36 #endif /* not lint */
38 #include <sys/ioctl.h>
39 #include <sys/time.h>
40 #include <sys/types.h>
41 #include <sys/tty.h>
42 #include <dev/wscons/wsconsio.h>
44 #include <err.h>
45 #include <stdio.h>
46 #include <stdlib.h>
48 #include "pathnames.h"
49 #include "wsmoused.h"
51 /* ---------------------------------------------------------------------- */
54 * Public interface exported by the `action' mode.
57 int action_startup(struct mouse *m);
58 int action_cleanup(void);
59 void action_wsmouse_event(struct wscons_event);
61 struct mode_bootstrap Action_Mode = {
62 "action",
63 action_startup,
64 action_cleanup,
65 action_wsmouse_event,
66 NULL,
67 NULL
70 /* ---------------------------------------------------------------------- */
73 * Global variables.
76 static int Initialized = 0;
78 /* ---------------------------------------------------------------------- */
81 * Prototypes for functions private to this module.
84 static void run_action(int, const char *);
86 /* ---------------------------------------------------------------------- */
88 /* Initializes the action mode. Does nothing, aside from checking it is
89 * not initialized twice. */
90 /* ARGSUSED */
91 int
92 action_startup(struct mouse *m)
95 if (Initialized) {
96 log_warnx("action mode already initialized");
97 return 1;
100 Initialized = 1;
102 return 1;
105 /* ---------------------------------------------------------------------- */
107 /* Mode cleanup. */
109 action_cleanup(void)
112 return 1;
115 /* ---------------------------------------------------------------------- */
117 /* Parses wsmouse events. Only button events are picked. */
118 void
119 action_wsmouse_event(struct wscons_event evt)
122 if (IS_BUTTON_EVENT(evt.type)) {
123 switch (evt.type) {
124 case WSCONS_EVENT_MOUSE_UP:
125 run_action(evt.value, "up");
126 break;
128 case WSCONS_EVENT_MOUSE_DOWN:
129 run_action(evt.value, "down");
130 break;
132 default:
133 log_warnx("unknown button event");
138 /* ---------------------------------------------------------------------- */
140 /* Executes a command. `button' specifies the number of the button that
141 * was pressed or released. `ud' contains the word `up' or `down', which
142 * specify the type of event received. */
143 static void
144 run_action(int button, const char *ud)
146 char buf[20];
147 const char *cmd;
148 struct block *conf;
150 (void)snprintf(buf, sizeof(buf), "button_%d_%s", button, ud);
152 conf = config_get_mode("action");
153 cmd = block_get_propval(conf, buf, NULL);
154 if (cmd != NULL) {
155 log_info("running command `%s'", cmd);
156 system(cmd);