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) 2007-2010, 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 <stdlib.h>
37
#include "openaxiom-c-macros.h"
38
39
#include "cursor.h"
40
41
/*
42
* This routine changes the shape of the cursor. it is a modified version of
43
* a program by SMWatt, called cursor.c. JMW 6/22/89
44
*/
45
46
/* this stuff can only be done on AIX <AND> the right terminal (aixterm,hft) */
47
#if (defined(RIOSplatform) || defined(RTplatform)) && !defined(_AIX41)
48
#include "edible.h"
49
/* the HFT stuff requires ioctl's and termio's */
50
#include <termio.h>
51
#include <stdio.h>
52
#include <fcntl.h>
53
#include <sys/hft.h>
54
55
int
56
Cursor_shape(int shape)
57
{
58
int hftfd;
59
char hftpath[16], s[100];
60
int chno;
61
int i;
62
struct termio oldterm, newterm;
63
struct hftgetid hftgid;
64
char *termVal;
65
66
termVal = oa_getenv("TERM");
67
if (strcmp("hft", termVal) && strncmp("aixterm", termVal, 7))
68
return;
69
70
71
72
/* determine the desired shape */
73
if (shape < 0 || shape > 5) {
74
fprintf(stderr, "%d - Invalid cursor number\n");
75
return (-1);
76
}
77
/* change the shape */
78
s[0] = 033; /* hf_intro.hf_esc */
79
s[1] = '['; /* hf_intro.hf_lbr */
80
s[2] = 'x'; /* hf_intro.hf_ex */
81
s[3] = 0; /* hf_intro.hf_len[0] */
82
s[4] = 0; /* hf_intro.hf_len[1] */
83
s[5] = 0; /* hf_intro.hf_len[2] */
84
s[6] = 10; /* hf_intro.hf_len[3] */
85
s[7] = 2; /* hf_intro.hf_typehi */
86
s[8] = 8; /* hf_intro.hf_typelo */
87
s[9] = 2; /* hf_sublen */
88
s[10] = 0; /* hf_subtype */
89
s[11] = 0; /* hf_rsvd */
90
s[12] = shape; /* hf_shape */
91
92
if (ioctl(0, HFTGETID, &hftgid) < 0) {
93
/* perror("ioctl: HFTGETID"); */
94
chno = -1;
95
}
96
else
97
chno = hftgid.hf_chan;
98
if (chno == -1) {
99
/** try being moronic and just writing what I want to
100
standard output ****/
101
102
if (((ioctl(2, TCGETA, &oldterm)) == -1) ||
103
((ioctl(2, TCGETA, &newterm)) == -1)) {
104
perror("Getting termio");
105
exit(0);
106
}
107
newterm.c_oflag = newterm.c_lflag = newterm.c_iflag = 0;
108
newterm.c_cc[0] = -1;
109
for (i = 1; i <= 5; i++)
110
newterm.c_cc[i] = 0;
111
if ((ioctl(2, TCSETAF, &newterm)) == -1) {
112
perror("Setting to raw mode");
113
exit(0);
114
}
115
write(2, s, 13);
116
read(0, s, 1024);
117
if ((ioctl(2, TCSETAF, &oldterm)) == -1) {
118
perror("Resetting terminal");
119
exit(0);
120
}
121
}
122
else {
123
/* open the currently active virtual terminal on the hft */
124
sprintf(hftpath, "/dev/hft/%d", chno);
125
if ((hftfd = open(hftpath, O_RDWR)) == -1) {
126
perror("Could not open hft channel\n");
127
exit(0);
128
}
129
write(hftfd, s, 13);
130
}
131
}
132
#else
133
134
int
135
Cursor_shape(int shape)
136
{
137
return shape;
138
}
139
#endif
140
141
142
143
144
145
146