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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
/****************************************************************
* *
* Copyright (c) 2001-2024 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
* the license, please stop and do not read further. *
* *
****************************************************************/
#include "mdef.h"
#include <errno.h>
#include "gtm_fcntl.h"
#include "gtm_string.h"
#include "gtm_stdlib.h"
#include "gtm_termios.h"
#include "io.h"
#include "iottdef.h"
#include "io_params.h"
#include "trmdef.h"
#include "gtmio.h"
#include "iott_setterm.h"
#include "stringpool.h"
#include "getcaps.h"
#include "gtm_isanlp.h"
#include "gtm_conv.h"
#include "gtmimagename.h"
#include "error.h"
#include "op.h"
#include "indir_enum.h"
GBLREF int COLUMNS, GTM_LINES, AUTO_RIGHT_MARGIN;
GBLREF uint4 gtm_principal_editing_defaults;
GBLREF io_pair io_std_device;
GBLREF boolean_t gtm_utf8_mode;
LITREF unsigned char io_params_size[];
error_def(ERR_BADCHSET);
error_def(ERR_NOTERMENTRY);
error_def(ERR_NOTERMENV);
error_def(ERR_NOTERMINFODB);
error_def(ERR_TCGETATTR);
error_def(ERR_ZINTRECURSEIO);
short iott_open(io_log_name *dev_name, mval *pp, int fd, mval *mspace, int4 timeout)
{
unsigned char ch;
d_tt_struct *tt_ptr;
io_desc *ioptr;
int status, chset_index;
int save_errno;
int p_offset;
mstr chset_mstr;
gtm_chset_t temp_chset, old_ichset, old_ochset;
boolean_t empt = FALSE, wrap_specified = FALSE, wrap_parm;
boolean_t ch_set;
DCL_THREADGBL_ACCESS;
SETUP_THREADGBL_ACCESS;
ioptr = dev_name->iod;
ESTABLISH_RET_GTMIO_CH(&ioptr->pair, -1, ch_set);
if (ioptr->state == dev_never_opened)
{
dev_name->iod->dev_sp = (void *)malloc(SIZEOF(d_tt_struct) + SIZEOF(struct termios));
memset(dev_name->iod->dev_sp, 0, SIZEOF(d_tt_struct) + SIZEOF(struct termios));
tt_ptr = (d_tt_struct *)dev_name->iod->dev_sp;
tt_ptr->ttio_struct = (struct termios *)((char *)tt_ptr + SIZEOF(d_tt_struct));
tt_ptr->in_buf_sz = TTDEF_BUF_SZ;
tt_ptr->enbld_outofbands.x = 0;
tt_ptr->term_ctrl &= (~TRM_NOECHO);
tt_ptr->ttybuff = (char *)malloc(IOTT_BUFF_LEN);
tt_ptr->default_mask_term = TRUE;
ioptr->ichset = ioptr->ochset = gtm_utf8_mode ? CHSET_UTF8 : CHSET_M; /* default */
}
assert(tt == dev_name->iod->type);
tt_ptr = (d_tt_struct *)dev_name->iod->dev_sp;
if (tt_ptr->mupintr)
RTS_ERROR_CSA_ABT(NULL, VARLSTCNT(1) ERR_ZINTRECURSEIO);
p_offset = 0;
old_ichset = ioptr->ichset;
old_ochset = ioptr->ochset;
while (*(pp->str.addr + p_offset) != iop_eol)
{
switch (ch = *(pp->str.addr + p_offset++))
{
case iop_exception:
DEF_EXCEPTION(pp, p_offset, ioptr);
break;
case iop_canonical:
tt_ptr->canonical = TRUE;
break;
case iop_nocanonical:
tt_ptr->canonical = FALSE;
break;
case iop_empterm:
empt = TRUE;
break;
case iop_noempterm:
empt = FALSE;
break;
case iop_wrap:
wrap_specified = TRUE;
wrap_parm = TRUE;
break;
case iop_nowrap:
wrap_specified = TRUE;
wrap_parm = FALSE;
break;
case iop_m:
ioptr->ichset = ioptr->ochset = CHSET_M;
break;
case iop_utf8:
if (gtm_utf8_mode)
ioptr->ichset = ioptr->ochset = CHSET_UTF8;
break;
case iop_ipchset:
case iop_opchset:
case iop_chset:
if (gtm_utf8_mode)
{
GET_ADDR_AND_LEN(chset_mstr.addr, chset_mstr.len);
SET_ENCODING(temp_chset, &chset_mstr);
if (IS_UTF16_CHSET(temp_chset)) /* Not allowed for terminals */
RTS_ERROR_CSA_ABT(NULL, VARLSTCNT(4) ERR_BADCHSET, 2, chset_mstr.len, chset_mstr.addr);
else if (ch == iop_ipchset)
ioptr->ichset = temp_chset;
else if (ch == iop_opchset)
ioptr->ochset = temp_chset;
else if (ch == iop_chset)
{
ioptr->ichset = temp_chset;
ioptr->ochset = temp_chset;
}
}
break;
}
p_offset += ((IOP_VAR_SIZE == io_params_size[ch]) ?
(unsigned char)*(pp->str.addr + p_offset) + 1 : io_params_size[ch]);
}
if (ioptr->state != dev_open)
{
int status;
char *env_term;
assert(fd >= 0);
tt_ptr->fildes = fd;
status = tcgetattr(tt_ptr->fildes, tt_ptr->ttio_struct);
if (0 != status)
{
save_errno = errno;
if (gtm_isanlp(tt_ptr->fildes) == 0)
RTS_ERROR_CSA_ABT(NULL, VARLSTCNT(4) ERR_TCGETATTR, 1, tt_ptr->fildes, save_errno);
}
if (IS_GTM_IMAGE)
/* Only the true runtime runs with the modified terminal settings */
iott_setterm(ioptr);
status = getcaps(tt_ptr->fildes);
if (1 != status)
{
if (status == 0)
{
env_term = GETENV("TERM");
if (!env_term)
{
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_NOTERMENV);
env_term = "unknown";
}
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_NOTERMENTRY, 2, LEN_AND_STR(env_term));
} else
rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_NOTERMINFODB);
}
ioptr->width = COLUMNS;
ioptr->length = GTM_LINES;
if (!wrap_specified)
ioptr->wrap = (0 == AUTO_RIGHT_MARGIN) ? FALSE : TRUE; /* defensive programming; till we are absolutely,
* positively certain there are no uses of wrap == TRUE */
else
ioptr->wrap = wrap_parm;
tt_ptr->tbuffp = tt_ptr->ttybuff; /* Buffer is now empty */
tt_ptr->discard_lf = FALSE;
if (!io_std_device.in || io_std_device.in == ioptr->pair.in) /* io_std_device.in not set yet in io_init */
{ /* $PRINCIPAL */
tt_ptr->ext_cap = gtm_principal_editing_defaults;
ioptr->ichset = ioptr->ochset = gtm_utf8_mode ? CHSET_UTF8 : CHSET_M; /* default */
} else
tt_ptr->ext_cap = 0;
if (empt && (ioptr == ioptr->pair.in))
tt_ptr->ext_cap |= TT_EMPTERM;
/* Set terminal mask on the terminal not open, if default_term or if CHSET changes */
if (tt_ptr->default_mask_term || (old_ichset != ioptr->ichset))
{
memset(&tt_ptr->mask_term.mask[0], 0, SIZEOF(io_termmask));
if (CHSET_M != ioptr->ichset)
{
tt_ptr->mask_term.mask[0] = TERM_MSK_UTF8_0;
tt_ptr->mask_term.mask[4] = TERM_MSK_UTF8_4;
} else
tt_ptr->mask_term.mask[0] = TERM_MSK;
tt_ptr->default_mask_term = TRUE;
}
ioptr->state = dev_open;
if ((TT_EDITING & tt_ptr->ext_cap) && !tt_ptr->recall_buff.addr)
{
assert(tt_ptr->in_buf_sz);
tt_ptr->recall_buff.addr = malloc(tt_ptr->in_buf_sz);
tt_ptr->recall_size = tt_ptr->in_buf_sz;
tt_ptr->recall_buff.len = 0; /* nothing in buffer */
tt_ptr->recall_width = 0;
}
} else
{
/* Set terminal mask on the already open terminal, if CHSET changes */
if (old_ichset != ioptr->ichset)
{
memset(&tt_ptr->mask_term.mask[0], 0, SIZEOF(io_termmask));
if (CHSET_M != ioptr->ichset)
{
tt_ptr->mask_term.mask[0] = TERM_MSK_UTF8_0;
tt_ptr->mask_term.mask[4] = TERM_MSK_UTF8_4;
} else
tt_ptr->mask_term.mask[0] = TERM_MSK;
tt_ptr->default_mask_term = TRUE;
}
}
REVERT_GTMIO_CH(&ioptr->pair, ch_set);
return TRUE;
}
|