File: ioecall.c

package info (click to toggle)
kinput2 3.1-10.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,012 kB
  • ctags: 5,584
  • sloc: ansic: 49,959; makefile: 106; sh: 68
file content (113 lines) | stat: -rw-r--r-- 2,334 bytes parent folder | download | duplicates (9)
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
#ifndef lint
static char *rcsid = "$Id: ioecall.c,v 1.2 1996/09/30 09:19:52 ishisone Exp $";
#endif
/*
 * Copyright (C) 1994  Software Research Associates, Inc.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Software Research Associates not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  Software Research
 * Associates makes no representations about the suitability of this software
 * for any purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * Author:  Makoto Ishisone, Software Research Associates, Inc., Japan
 */

/*
 *	X I/O error callback
 */

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xfuncproto.h>
#include "IOECall.h"

#ifndef NULL
#define NULL	0
#endif

typedef struct ioe_cb_desc_ {
    void (*callback)();
    XPointer client_data;
    struct ioe_cb_desc_ *next;
} CBDesc;

static CBDesc *cb_list;

static int (*original_handler)();

static int
XIOEHandler(dpy)
Display *dpy;
{
    CBDesc *cb;

    cb = cb_list;
    while (cb != NULL) {
	(*cb->callback)(cb->client_data);
	cb = cb->next;
    }
    return (*original_handler)(dpy);
}

void
XIOEInit()
{
    int (*oldhandler)() = XSetIOErrorHandler(XIOEHandler);

    if (oldhandler != XIOEHandler) original_handler = oldhandler;
}

XIOEHandle
XIOESet(handler, client_data)
void (*handler)();
XPointer client_data;
{
    CBDesc *cb;

    cb = (CBDesc *)malloc(sizeof(CBDesc));
    if (cb == NULL) return NULL;

    cb->callback = handler;
    cb->client_data = client_data;
    cb->next = NULL;

    if (cb_list == NULL) {
	cb_list = cb;
    } else {
	CBDesc *p = cb_list;

	while (p->next != NULL) p = p->next;
	p->next = cb;
    }

    return cb;
}

void
XIOEUnset(handle)
XIOEHandle handle;
{
    CBDesc *cb, *cb0;

    cb = cb_list;
    cb0 = NULL;

    while (cb != NULL) {
	if (cb == handle) {
	    if (cb0 == NULL) {
		cb_list = cb->next;
	    } else {
		cb0->next = cb->next;
	    }
	    (void)free((char *)cb);
	    return;
	}
	cb = cb->next;
    }
}