1 #include <stdio.h> 2 3 #include "../api/api.h" 4 #include "apilib.h" 5 #include "../ctlr/oia.h" 6 7 static char mybuffer[2000]; 8 9 api_perror(string) 10 char *string; 11 { 12 fprintf(stderr, "Error: [0x%x/0x%x:0x%x/0x%x] from %s.\n", 13 api_sup_fcn_id, api_sup_errno, 14 api_fcn_fcn_id, api_fcn_errno, string); 15 } 16 17 18 char * 19 session_type(type) 20 int type; 21 { 22 switch (type) { 23 case TYPE_WSCTL: 24 return "work station control"; 25 case TYPE_DFT: 26 return "distributed function terminal"; 27 case TYPE_CUT: 28 return "control unit terminal"; 29 case TYPE_NOTEPAD: 30 return "notepad"; 31 case TYPE_PC: 32 return "personal computer"; 33 default: 34 return "(UNKNOWN)"; 35 } 36 } 37 38 39 main() 40 { 41 register int i; 42 int session_id; 43 OIA oia; 44 QuerySessionIdParms id; 45 QuerySessionParametersParms pa; 46 QuerySessionCursorParms cu; 47 ConnectToKeyboardParms conn; 48 DisconnectFromKeyboardParms disc; 49 WriteKeystrokeParms wr; 50 DisableInputParms disable; 51 EnableInputParms enable; 52 CopyStringParms copy; 53 ReadOiaGroupParms re; 54 NameArray namearray; 55 56 if (api_init() == 0) { 57 fprintf(stderr, "API function not available.\n"); 58 return 1; 59 } 60 61 id.rc = 0; 62 id.function_id = 0; 63 id.option_code = ID_OPTION_BY_NAME; 64 id.data_code = 'E'; 65 id.name_array = &namearray; 66 namearray.length = sizeof namearray; 67 if (api_query_session_id(&id)) { 68 api_perror("api_query_session_id"); 69 } else if (namearray.number_matching_session == 0) { 70 fprintf(stderr, "query_session_id: No matching sessions!\n"); 71 } else { 72 printf("Session short name 0x%x, type is ", 73 namearray.name_array_element.short_name); 74 printf("%s", session_type(namearray.name_array_element.type)); 75 printf(", session ID is: 0x%x\n", 76 namearray.name_array_element.session_id); 77 } 78 session_id = namearray.name_array_element.session_id; 79 80 pa.rc = pa.function_id = 0; 81 pa.session_id = session_id; 82 if (api_query_session_parameters(&pa) == -1) { 83 api_perror("api_query_session_parameters"); 84 } else { 85 printf("Session type %s, ", session_type(pa.session_type)); 86 if (pa.session_characteristics&CHARACTERISTIC_EAB) { 87 printf(" has EAB, "); 88 } 89 if (pa.session_characteristics&CHARACTERISTIC_PSS) { 90 printf(" has PSS, "); 91 } 92 printf("%d rows, %d columns ", pa.rows, pa.columns); 93 if (pa.presentation_space) { 94 printf("presentation space at 0x%x:0x%x.\n", 95 FP_SEG(pa.presentation_space), FP_OFF(pa.presentation_space)); 96 } else { 97 printf("(no direct presentation space access).\n"); 98 } 99 } 100 101 cu.rc = cu.function_id = 0; 102 cu.session_id = session_id; 103 if (api_query_session_cursor(&cu) == -1) { 104 api_perror("api_query_session_cursor"); 105 } else { 106 printf("cursor"); 107 if (cu.cursor_type&CURSOR_INHIBITED_AUTOSCROLL) { 108 printf(" inhibited autoscroll"); 109 } 110 if (cu.cursor_type&CURSOR_INHIBITED) { 111 printf(" inhibited"); 112 } 113 if (cu.cursor_type&CURSOR_BLINKING) { 114 printf(" blinking"); 115 } else { 116 printf(" not blinking"); 117 } 118 if (cu.cursor_type&CURSOR_BOX) { 119 printf(" box "); 120 } else { 121 printf(" not box "); 122 } 123 printf("at row %d, column %d.\n", cu.row_address, cu.column_address); 124 } 125 126 re.rc = re.function_id = 0; 127 re.session_id = session_id; 128 re.oia_buffer = (char far *) &oia; 129 re.oia_group_number = API_OIA_ALL_GROUPS; 130 if (api_read_oia_group(&re) == -1) { 131 api_perror("api_read_oia_group"); 132 } else { 133 if (IsOiaReady3274(&oia)) { 134 printf("3274 ready, "); 135 } 136 if (IsOiaMyJob(&oia)) { 137 printf("my job, "); 138 } 139 if (IsOiaInsert(&oia)) { 140 printf("insert mode, "); 141 } 142 if (IsOiaSystemLocked(&oia)) { 143 printf("system locked, "); 144 } 145 if (IsOiaTWait(&oia)) { 146 printf("terminal wait, "); 147 } 148 printf("are some bits from the OIA.\n"); 149 } 150 151 conn.rc = conn.function_id = 0; 152 conn.session_id = session_id; 153 conn.event_queue_id = conn.input_queue_id = 0; 154 conn.intercept_options = 0; 155 if (api_connect_to_keyboard(&conn) == -1) { 156 api_perror("api_connect_to_keyboard"); 157 } else { 158 if (conn.first_connection_identifier) { 159 printf("First keyboard connection.\n"); 160 } else { 161 printf("Not first keyboard connection.\n"); 162 } 163 } 164 165 disable.rc = disable.function_id = 0; 166 disable.session_id = session_id; 167 disable.connectors_task_id = 0; 168 if (api_disable_input(&disable) == -1) { 169 api_perror("api_disable_input"); 170 } else { 171 printf("Disabled.\n"); 172 } 173 174 wr.rc = wr.function_id = 0; 175 wr.session_id = session_id; 176 wr.connectors_task_id = 0; 177 wr.options = OPTION_SINGLE_KEYSTROKE; 178 wr.number_of_keys_sent = 0; 179 wr.keystroke_specifier.keystroke_entry.scancode = 0x3a; 180 wr.keystroke_specifier.keystroke_entry.shift_state = 0; 181 if (api_write_keystroke(&wr) == -1) { 182 api_perror("api_write_keystroke"); 183 } else { 184 if (wr.number_of_keys_sent != 1) { 185 fprintf(stderr, 186 "write_keystroke claims to have sent %d keystrokes.\n", 187 wr.number_of_keys_sent); 188 } else { 189 printf("Keystroke sent.\n"); 190 } 191 } 192 193 enable.rc = enable.function_id = 0; 194 enable.session_id = session_id; 195 enable.connectors_task_id = 0; 196 if (api_enable_input(&enable) == -1) { 197 api_perror("api_enable"); 198 } else { 199 printf("Enabled.\n"); 200 } 201 202 disc.rc = disc.function_id = 0; 203 disc.session_id = session_id; 204 disc.connectors_task_id = 0; 205 if (api_disconnect_from_keyboard(&disc) == -1) { 206 api_perror("api_disconnect_from_keyboard"); 207 } else { 208 printf("Disconnected from keyboard.\n"); 209 } 210 /* Time copy services */ 211 212 for (i = 0; i < 100; i++) { 213 copy.copy_mode = 0; 214 copy.rc = copy.function_id = 0; 215 copy.source.session_id = session_id; 216 copy.source.characteristics = 0; 217 copy.source.session_type = TYPE_DFT; 218 copy.source.begin = 0; 219 220 copy.source_end = 1920; 221 222 copy.target.session_id = 0; 223 copy.target.buffer = mybuffer; 224 copy.target.characteristics = 0; 225 copy.target.session_type = TYPE_DFT; 226 227 if (api_copy_string(©) == -1) { 228 api_perror("api_copy_string"); 229 break; 230 } 231 } 232 printf("Copied data out.\n"); 233 234 (void) api_finish(); 235 236 return 0; 237 } 238