/*1Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2010, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical ALgorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435#include <stdlib.h>36#include "openaxiom-c-macros.h"3738#include "cursor.h"3940/*41* This routine changes the shape of the cursor. it is a modified version of42* a program by SMWatt, called cursor.c. JMW 6/22/8943*/4445/* this stuff can only be done on AIX <AND> the right terminal (aixterm,hft) */46#if (defined(RIOSplatform) || defined(RTplatform)) && !defined(_AIX41)47#include "edible.h"48/* the HFT stuff requires ioctl's and termio's */49#include <termio.h>50#include <stdio.h>51#include <fcntl.h>52#include <sys/hft.h>5354int55Cursor_shape(int shape)56{57int hftfd;58char hftpath[16], s[100];59int chno;60int i;61struct termio oldterm, newterm;62struct hftgetid hftgid;63char *termVal;6465termVal = oa_getenv("TERM");66if (strcmp("hft", termVal) && strncmp("aixterm", termVal, 7))67return;68697071/* determine the desired shape */72if (shape < 0 || shape > 5) {73fprintf(stderr, "%d - Invalid cursor number\n");74return (-1);75}76/* change the shape */77s[0] = 033; /* hf_intro.hf_esc */78s[1] = '['; /* hf_intro.hf_lbr */79s[2] = 'x'; /* hf_intro.hf_ex */80s[3] = 0; /* hf_intro.hf_len[0] */81s[4] = 0; /* hf_intro.hf_len[1] */82s[5] = 0; /* hf_intro.hf_len[2] */83s[6] = 10; /* hf_intro.hf_len[3] */84s[7] = 2; /* hf_intro.hf_typehi */85s[8] = 8; /* hf_intro.hf_typelo */86s[9] = 2; /* hf_sublen */87s[10] = 0; /* hf_subtype */88s[11] = 0; /* hf_rsvd */89s[12] = shape; /* hf_shape */9091if (ioctl(0, HFTGETID, &hftgid) < 0) {92/* perror("ioctl: HFTGETID"); */93chno = -1;94}95else96chno = hftgid.hf_chan;97if (chno == -1) {98/** try being moronic and just writing what I want to99standard output ****/100101if (((ioctl(2, TCGETA, &oldterm)) == -1) ||102((ioctl(2, TCGETA, &newterm)) == -1)) {103perror("Getting termio");104exit(0);105}106newterm.c_oflag = newterm.c_lflag = newterm.c_iflag = 0;107newterm.c_cc[0] = -1;108for (i = 1; i <= 5; i++)109newterm.c_cc[i] = 0;110if ((ioctl(2, TCSETAF, &newterm)) == -1) {111perror("Setting to raw mode");112exit(0);113}114write(2, s, 13);115read(0, s, 1024);116if ((ioctl(2, TCSETAF, &oldterm)) == -1) {117perror("Resetting terminal");118exit(0);119}120}121else {122/* open the currently active virtual terminal on the hft */123sprintf(hftpath, "/dev/hft/%d", chno);124if ((hftfd = open(hftpath, O_RDWR)) == -1) {125perror("Could not open hft channel\n");126exit(0);127}128write(hftfd, s, 13);129}130}131#else132133int134Cursor_shape(int shape)135{136return shape;137}138#endif139140141142143144145146