#include <apilib/apilib.h>
#include "../ctlr/function.h"
#include "../ctlr/hostctlr.h"
#include "../ctlr/screen.h"
#include "../apilib/disp_asc.h"
#include "../apilib/astosc.h"
#include "../general/general.h"
ScreenImage Host
[MAXSCREENSIZE
];
a_send_sequence
[SEND_SEQUENCE_LENGTH
+1],
a_ack_sequence
[ACK_SEQUENCE_LENGTH
+1],
a_checksum
[CHECKSUM_LENGTH
+1],
data_array
[DATA_LENGTH
+1];
fprintf(stderr
, "Error: [0x%x/0x%x:0x%x/0x%x] from %s.\n",
api_sup_fcn_id
, api_sup_errno
,
api_fcn_fcn_id
, api_fcn_errno
, string
);
return "work station control";
return "distributed function terminal";
return "control unit terminal";
return "personal computer";
return api_ps_or_oia_modified();
#endif /* defined(unix) */
static char zeroes
[sizeof oia
.input_inhibited
] = { 0 };
re
.rc
= re
.function_id
= 0;
re
.session_id
= session_id
;
re
.oia_buffer
= (char far
*) &oia
;
re
.oia_group_number
= API_OIA_ALL_GROUPS
;
if (api_read_oia_group(&re
) == -1) {
api_perror("api_read_oia_group");
if (IsOiaReady3274(&oia
)) {
if (IsOiaSystemLocked(&oia
)) {
printf("system locked, ");
printf("terminal wait, ");
printf("are some bits from the OIA.\n");
/* We turned this on, so turn it off now */
ResetOiaApiInhibit(&oia
);
if (memcmp(zeroes
, oia
.input_inhibited
, sizeof oia
.input_inhibited
)) {
if (wait_for_ps_or_oia() == -1) {
} while (memcmp(zeroes
, oia
.input_inhibited
, sizeof oia
.input_inhibited
));
QuerySessionParametersParms pa
;
QuerySessionCursorParms cu
;
ConnectToKeyboardParms conn
;
DisableInputParms disable
;
fprintf(stderr
, "API function not available.\n");
id
.option_code
= ID_OPTION_BY_NAME
;
id
.name_array
= &namearray
;
namearray
.length
= sizeof namearray
;
if (api_query_session_id(&id
)) {
api_perror("api_query_session_id");
} else if (namearray
.number_matching_session
== 0) {
fprintf(stderr
, "query_session_id: No matching sessions!\n");
printf("Session short name 0x%x, type is ",
namearray
.name_array_element
.short_name
);
printf("%s", session_type(namearray
.name_array_element
.type
));
printf(", session ID is: 0x%x\n",
namearray
.name_array_element
.session_id
);
session_id
= namearray
.name_array_element
.session_id
;
pa
.rc
= pa
.function_id
= 0;
pa
.session_id
= session_id
;
if (api_query_session_parameters(&pa
) == -1) {
api_perror("api_query_session_parameters");
printf("Session type %s, ", session_type(pa
.session_type
));
if (pa
.session_characteristics
&CHARACTERISTIC_EAB
) {
if (pa
.session_characteristics
&CHARACTERISTIC_PSS
) {
printf("%d rows, %d columns ", pa
.rows
, pa
.columns
);
if (pa
.presentation_space
) {
printf("presentation space at 0x%x:0x%x.\n",
FP_SEG(pa
.presentation_space
), FP_OFF(pa
.presentation_space
));
printf("(no direct presentation space access).\n");
ScreenSize
= pa
.rows
*pa
.columns
;
if (pa
.session_characteristics
&CHARACTERISTIC_EAB
) {
"tncomp utilities not designed to work with extended attribute buffers.\n");
cu
.rc
= cu
.function_id
= 0;
cu
.session_id
= session_id
;
if (api_query_session_cursor(&cu
) == -1) {
api_perror("api_query_session_cursor");
if (cu
.cursor_type
&CURSOR_INHIBITED_AUTOSCROLL
) {
printf(" inhibited autoscroll");
if (cu
.cursor_type
&CURSOR_INHIBITED
) {
if (cu
.cursor_type
&CURSOR_BLINKING
) {
if (cu
.cursor_type
&CURSOR_BOX
) {
printf("at row %d, column %d.\n",
cu
.row_address
, cu
.column_address
);
conn
.rc
= conn
.function_id
= 0;
conn
.session_id
= session_id
;
conn
.event_queue_id
= conn
.input_queue_id
= 0;
conn
.intercept_options
= 0;
if (api_connect_to_keyboard(&conn
) == -1) {
api_perror("api_connect_to_keyboard");
if (conn
.first_connection_identifier
) {
printf("First keyboard connection.\n");
printf("Not first keyboard connection.\n");
disable
.rc
= disable
.function_id
= 0;
disable
.session_id
= session_id
;
disable
.connectors_task_id
= 0;
if (api_disable_input(&disable
) == -1) {
api_perror("api_disable_input");
if ((enter_index
= ascii_to_index("ENTER")) == -1) {
if ((clear_index
= ascii_to_index("CLEAR")) == -1) {
extern struct astosc astosc
[];
wr
.rc
= wr
.function_id
= 0;
wr
.session_id
= session_id
;
wr
.connectors_task_id
= 0;
wr
.options
= OPTION_SINGLE_KEYSTROKE
;
wr
.number_of_keys_sent
= 0;
wr
.keystroke_specifier
.keystroke_entry
.scancode
= astosc
[index
].scancode
;
wr
.keystroke_specifier
.keystroke_entry
.shift_state
= astosc
[index
].shiftstate
;
if (api_write_keystroke(&wr
) == -1) {
api_perror("api_write_keystroke");
} else if (wr
.number_of_keys_sent
!= 1) {
fprintf(stderr
, "write_keystroke claims to have sent %d keystrokes.\n",
printf("Keystroke sent.\n");
if (wait_for_ps_or_oia() == -1) {
DisconnectFromKeyboardParms disc
;
enable
.rc
= enable
.function_id
= 0;
enable
.session_id
= session_id
;
enable
.connectors_task_id
= 0;
if (api_enable_input(&enable
) == -1) {
api_perror("api_enable");
disc
.rc
= disc
.function_id
= 0;
disc
.session_id
= session_id
;
disc
.connectors_task_id
= 0;
if (api_disconnect_from_keyboard(&disc
) == -1) {
api_perror("api_disconnect_from_keyboard");
printf("Disconnected from keyboard.\n");
copy
.rc
= copy
.function_id
= 0;
copy
.source
.session_id
= session_id
;
copy
.source
.characteristics
= 0;
copy
.source
.session_type
= TYPE_DFT
;
copy
.source_end
= ScreenSize
;
copy
.target
.session_id
= 0;
copy
.target
.buffer
= (char *) &Host
[0];
copy
.target
.characteristics
= 0;
copy
.target
.session_type
= TYPE_DFT
;
if (api_copy_string(©
) == -1) {
api_perror("api_copy_string");
put_at(offset
, from
, length
, attribute
)
copy
.rc
= copy
.function_id
= 0;
copy
.source
.session_id
= 0;
copy
.source
.buffer
= from
;
copy
.source
.characteristics
= 0;
copy
.source
.session_type
= TYPE_DFT
;
copy
.source_end
= length
-1;
copy
.target
.session_id
= session_id
;
copy
.target
.characteristics
= 0;
copy
.target
.session_type
= TYPE_DFT
;
copy
.target
.begin
= offset
;
if (api_copy_string(©
) == -1) {
api_perror("api_copy_string");
translate(input
, output
, table
, length
)
char *input
, *output
, table
[];
unsigned char *indices
= (unsigned char *) input
;
*output
++ = table
[*indices
++];
#define FieldDec(p) (0) /* We don't really use this */
for (i
= from
; i
< MAXSCREENSIZE
; ) {
attr
= FieldAttributes(i
);
if (!IsProtectedAttr(i
, attr
)) {
getascii(offset
, to
, length
)
int offset
; /* Where in screen */
char *to
; /* Where it goes to */
int length
; /* Where to put it */
translate(Host
+offset
, to
, disp_asc
, length
);
putascii(offset
, from
, length
, before
)
int offset
; /* Where in screen */
char *from
; /* Where it comes from */
int length
; /* Where to put it */
int before
; /* How much else should go */
translate(from
, Host
+offset
, asc_disp
, length
);
if (put_at(offset
-before
,
(char *) Host
+offset
-before
, length
+before
) == -1) {
static char ack_blanks
[sizeof a_ack_sequence
] = {0};
if (ack_blanks
[0] == 0) {
for (i
= 0; i
< sizeof ack_blanks
; i
++) {
memcpy(a_ack_sequence
, ack_blanks
, sizeof a_ack_sequence
);
sprintf(a_ack_sequence
, "%d", ack_sequence
);
a_ack_sequence
[strlen(a_ack_sequence
)] = ' ';
Host
[ACK_SEQUENCE
-1] |= ATTR_MDT
;
if (putascii(ACK_SEQUENCE
, a_ack_sequence
, ACK_SEQUENCE_LENGTH
, 1) == -1) {
if ((find_input_area(SEND_SEQUENCE
-1) != SEND_SEQUENCE
) ||
(find_input_area(SEND_SEQUENCE
) != ACK_SEQUENCE
) ||
(find_input_area(ACK_SEQUENCE
) != CHECKSUM
) ||
(find_input_area(CHECKSUM
) != DATA
)) {
int data_length
, input_length
;
char ascii
[8]; /* Lots of room */
while (argv
[0][0] == '-') {
fprintf(stderr
, "usage: %s local.file remote.file [remote.options]\n");
/* Open the local file */
if ((outfile
= fopen(argv
[0], "w")) == NULL
) {
if (initialize() == -1) {
/* build the command line */
strcpy(data
, "TNCOMP SEND");
printf("%s\n", data_array
);
if (get_screen() == -1) {
data_length
= strlen(data_array
);
if ((i
= find_input_area()) == -1) { /* Get an input area */
if (send_key(clear_index
) == -1) {
if ((i
= find_input_area(0)) == -1) { /* Try again */
fprintf(stderr
, "Unable to enter command line.\n");
Host
[ScreenSize
-1] |= ATTR_MDT
;
if (putascii(i
, data_array
, data_length
, 1) == -1) {
if (send_key(enter_index
) == -1) {
if (get_screen() == -1) {
} while (formatted_correct() == -1);
if (get_screen() == -1) {
if (formatted_correct() == -1) {
fprintf(stderr
, "Bad screen written by host.\n");
/* If MDT isn't reset in the sequence number, go around again */
if (Host
[ACK_SEQUENCE
-1]&ATTR_MDT
) {
if (wait_for_ps_or_oia() == -1) {
getascii(SEND_SEQUENCE
, a_send_sequence
, SEND_SEQUENCE_LENGTH
);
send_sequence
= atoi(a_send_sequence
);
getascii(CHECKSUM
, a_checksum
, CHECKSUM_LENGTH
);
checksum
= atoi(a_checksum
);
getascii(DATA
, data_array
, DATA_LENGTH
);
if (send_sequence
!= (ack_sequence
+1)) {
data
= "1234"; /* Keep loop from failing */
if (send_key(enter_index
) == -1) {
if (get_screen() == -1) {
data_length
= DATA_LENGTH
;
while (data_length
&& memcmp(data
, " EOF", 4)
&& memcmp(data
, " ", 4)) {
input_length
= atoi(ascii
);
/* CMS can't live with zero length records */
if ((input_length
> 1) ||
((input_length
== 1) && (data
[0] != ' '))) {
if (fwrite(data
, sizeof (char),
input_length
, outfile
) == 0) {
data_length
-= input_length
;
ack_sequence
= send_sequence
;
if (send_key(enter_index
) == -1) {
} while (memcmp(data
, " EOF", 4));