Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#include "openaxiom-c-macros.h"
37
#include <unistd.h>
38
#include <sys/types.h>
39
#include <stdio.h>
40
#include <errno.h>
41
#include <stdlib.h>
42
#include <X11/Xlib.h>
43
#include <X11/Xutil.h>
44
#include "view.h"
45
#include "cfuns.h"
46
47
#include "util.H1"
48
49
50
/* FIXME: Remove this kludge */
51
using namespace OpenAxiom;
52
53
54
int
55
checker(int code, int lineNumber, const char* errorStr)
56
{
57
if (code < 0) {
58
fprintf(stderr, "Error occured during %s\n", errorStr);
59
fprintf(stderr, "Error code of %d\n", errno);
60
fprintf(stderr, "Error in line number %d of process %d\n", lineNumber, oa_getpid());
61
perror("");
62
}
63
return (code);
64
}
65
66
67
68
69
const char*
70
getmemWithLine(int nbytes, const char* str, int lineNum)
71
{
72
char *p;
73
74
p = (char *) malloc(nbytes);
75
if (!p) {
76
fprintf(stderr, "getmem: Could not get %d bytes for %s at line %d\n", nbytes, str, lineNum);
77
exit(99);
78
}
79
return p;
80
}
81
82
83
const char *
84
saymemWithLine(const char *str, int num, int size, int lineNum)
85
{
86
return getmemWithLine(num * size, str, lineNum);
87
}
88
89
90
void
91
myfree(void *p, int size)
92
{
93
free(p);
94
}
95
96
97
98
99
XPoint
100
getWindowPositionXY(Display *display, Window w)
101
{
102
XPoint position;
103
Window rootW, parentW, *childrenWs, tmpW;
104
unsigned int nChildren;
105
XWindowAttributes windowAttrib;
106
int screen, tmp = 1;
107
108
screen = DefaultScreen(display);
109
tmpW = w;
110
while (tmp) {
111
XQueryTree(display, tmpW, &rootW, &parentW, &childrenWs, &nChildren);
112
XFree((char *)childrenWs);
113
if (parentW == RootWindow(display, screen))
114
tmp = 0;
115
else
116
tmpW = parentW;
117
}
118
XGetWindowAttributes(display, tmpW, &windowAttrib);
119
position.x = (short) windowAttrib.x;
120
position.y = (short) windowAttrib.y;
121
122
return (position);
123
}
124
125
126
127
XPoint
128
getWindowSizeXY(Display *display,Window w)
129
{
130
XPoint size;
131
Window rootW, parentW, *childrenWs, tmpW;
132
unsigned int nChildren;
133
XWindowAttributes windowAttrib;
134
int screen, tmp = 1;
135
136
screen = DefaultScreen(display);
137
tmpW = w;
138
while (tmp) {
139
XQueryTree(display, tmpW, &rootW, &parentW, &childrenWs, &nChildren);
140
XFree((char *)childrenWs);
141
if (parentW == RootWindow(display, screen))
142
tmp = 0;
143
else
144
tmpW = parentW;
145
}
146
XGetWindowAttributes(display, tmpW, &windowAttrib);
147
size.x = (short) windowAttrib.width;
148
size.y = (short) windowAttrib.height;
149
150
return (size);
151
}
152
153