void printline(struct session *ses, char **str, int prompt) { char *out; push_call("printline(%p,%p,%d)",ses,*str,prompt); if (ses->scroll_line != -1 && HAS_BIT(ses->flags, SES_FLAG_SCROLLLOCK)) { pop_call(); return; } if (HAS_BIT(ses->flags, SES_FLAG_SCAN) && !HAS_BIT(ses->flags, SES_FLAG_VERBOSE)) { pop_call(); return; } out = str_alloc(strlen(*str) * 2); if (HAS_BIT(ses->flags, SES_FLAG_CONVERTMETA)) { convert_meta(*str, out); str_cpy(str, out); } if (HAS_BIT(ses->flags, SES_FLAG_WORDWRAP)) { word_wrap(ses, *str, out, TRUE); } else { strcpy(out, *str); } if (prompt) { printf("%s", out); } else { printf("%s\n", out); } str_free(out); pop_call(); return; }
void read_line() { char buffer[STRING_SIZE]; struct listnode *node; struct listroot *root; int len, cnt, match; gtd->input_buf[gtd->input_len] = 0; len = read(0, buffer, 1); buffer[len] = 0; if (HAS_BIT(gtd->ses->flags, SES_FLAG_CONVERTMETA) || HAS_BIT(gtd->flags, TINTIN_FLAG_CONVERTMETACHAR)) { convert_meta(buffer, >d->macro_buf[strlen(gtd->macro_buf)]); } else { strcat(gtd->macro_buf, buffer); } if (!HAS_BIT(gtd->ses->flags, SES_FLAG_CONVERTMETA)) { match = 0; root = gtd->ses->list[LIST_MACRO]; for (root->update = 0; root->update < root->used; root->update++) { node = root->list[root->update]; if (!strcmp(gtd->macro_buf, node->pr)) { script_driver(gtd->ses, LIST_MACRO, node->right); gtd->macro_buf[0] = 0; return; } else if (!strncmp(gtd->macro_buf, node->pr, strlen(gtd->macro_buf))) { match = 1; } } for (cnt = 0; *cursor_table[cnt].fun != NULL; cnt++) { if (!strcmp(gtd->macro_buf, cursor_table[cnt].code)) { cursor_table[cnt].fun(""); gtd->macro_buf[0] = 0; return; } else if (!strncmp(gtd->macro_buf, cursor_table[cnt].code, strlen(gtd->macro_buf))) { match = 1; } } if (match) { return; } } if (gtd->macro_buf[0] == ESCAPE) { strcpy(buffer, gtd->macro_buf); convert_meta(buffer, gtd->macro_buf); } for (cnt = 0; gtd->macro_buf[cnt]; cnt++) { switch (gtd->macro_buf[cnt]) { case 10: cursor_enter(""); break; default: if (HAS_BIT(gtd->flags, TINTIN_FLAG_INSERTINPUT) && gtd->input_len != gtd->input_cur) { if (!HAS_BIT(gtd->ses->flags, SES_FLAG_UTF8) || (gtd->macro_buf[cnt] & 192) != 128) { cursor_delete(""); } } ins_sprintf(>d->input_buf[gtd->input_cur], "%c", gtd->macro_buf[cnt]); gtd->input_len++; gtd->input_cur++; if (!HAS_BIT(gtd->ses->flags, SES_FLAG_UTF8) || (gtd->macro_buf[cnt] & 192) != 128) { gtd->input_pos++; } if (gtd->input_len != gtd->input_cur) { if (HAS_BIT(gtd->ses->flags, SES_FLAG_UTF8) && (gtd->macro_buf[cnt] & 192) == 128) { input_printf("%c", gtd->macro_buf[cnt]); } else { input_printf("\033[1@%c", gtd->macro_buf[cnt]); } } else { input_printf("%c", gtd->macro_buf[cnt]); } gtd->macro_buf[0] = 0; gtd->input_tmp[0] = 0; gtd->input_buf[gtd->input_len] = 0; cursor_check_line_modified(""); DEL_BIT(gtd->flags, TINTIN_FLAG_HISTORYBROWSE); kill_list(gtd->ses->list[LIST_TABCYCLE]); if (HAS_BIT(gtd->flags, TINTIN_FLAG_HISTORYSEARCH)) { cursor_history_find(""); } break; } } }
void read_key(void) { char buffer[BUFFER_SIZE]; struct listnode *node; struct listroot *root; int len, cnt, match; if (gtd->input_buf[0] == gtd->tintin_char) { read_line(); return; } len = read(0, buffer, 1); buffer[len] = 0; if (HAS_BIT(gtd->ses->flags, SES_FLAG_CONVERTMETA) || HAS_BIT(gtd->flags, TINTIN_FLAG_CONVERTMETACHAR)) { convert_meta(buffer, >d->macro_buf[strlen(gtd->macro_buf)]); } else { strcat(gtd->macro_buf, buffer); } if (!HAS_BIT(gtd->ses->flags, SES_FLAG_CONVERTMETA)) { match = 0; root = gtd->ses->list[LIST_MACRO]; for (root->update = 0; root->update < root->used; root->update++) { node = root->list[root->update]; if (!strcmp(gtd->macro_buf, node->pr)) { script_driver(gtd->ses, LIST_MACRO, node->right); gtd->macro_buf[0] = 0; return; } else if (!strncmp(gtd->macro_buf, node->pr, strlen(gtd->macro_buf))) { match = 1; } } if (match) { return; } } for (cnt = 0; gtd->macro_buf[cnt]; cnt++) { switch (gtd->macro_buf[cnt]) { case '\n': gtd->input_buf[0] = 0; gtd->macro_buf[0] = 0; gtd->input_len = 0; if (HAS_BIT(gtd->ses->flags, SES_FLAG_RUN)) { socket_printf(gtd->ses, 1, "%c", '\r'); } else { socket_printf(gtd->ses, 2, "%c%c", '\r', '\n'); } break; default: if (gtd->macro_buf[cnt] == gtd->tintin_char && gtd->input_buf[0] == 0) { if (gtd->input_len != gtd->input_cur) { printf("\033[1@%c", gtd->macro_buf[cnt]); } else { printf("%c", gtd->macro_buf[cnt]); } gtd->input_buf[0] = gtd->tintin_char; gtd->input_buf[1] = 0; gtd->macro_buf[0] = 0; gtd->input_len = 1; gtd->input_cur = 1; gtd->input_pos = 1; } else { socket_printf(gtd->ses, 1, "%c", gtd->macro_buf[cnt]); gtd->input_buf[0] = 127; gtd->macro_buf[0] = 0; gtd->input_len = 0; } break; } } }
static PyObject *Decoder_put(PyObject *self, PyObject *args) { GSList *l; PyObject *py_data, *py_res; struct srd_decoder_inst *di, *next_di; struct srd_pd_output *pdo; struct srd_proto_data *pdata; uint64_t start_sample, end_sample; int output_id; struct srd_pd_callback *cb; if (!(di = srd_inst_find_by_obj(NULL, self))) { /* Shouldn't happen. */ srd_dbg("put(): self instance not found."); return NULL; } if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample, &output_id, &py_data)) { /* * This throws an exception, but by returning NULL here we let * Python raise it. This results in a much better trace in * controller.c on the decode() method call. */ return NULL; } if (!(l = g_slist_nth(di->pd_output, output_id))) { srd_err("Protocol decoder %s submitted invalid output ID %d.", di->decoder->name, output_id); return NULL; } pdo = l->data; srd_spew("Instance %s put %" PRIu64 "-%" PRIu64 " %s on oid %d.", di->inst_id, start_sample, end_sample, OUTPUT_TYPES[pdo->output_type], output_id); if (!(pdata = g_try_malloc0(sizeof(struct srd_proto_data)))) { srd_err("Failed to g_malloc() struct srd_proto_data."); return NULL; } pdata->start_sample = start_sample; pdata->end_sample = end_sample; pdata->pdo = pdo; switch (pdo->output_type) { case SRD_OUTPUT_ANN: /* Annotations are only fed to callbacks. */ if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) { /* Convert from PyDict to srd_proto_data_annotation. */ if (convert_annotation(di, py_data, pdata) != SRD_OK) { /* An error was already logged. */ break; } cb->cb(pdata, cb->cb_data); } break; case SRD_OUTPUT_PYTHON: for (l = di->next_di; l; l = l->next) { next_di = l->data; srd_spew("Sending %d-%d to instance %s", start_sample, end_sample, next_di->inst_id); if (!(py_res = PyObject_CallMethod( next_di->py_inst, "decode", "KKO", start_sample, end_sample, py_data))) { srd_exception_catch("Calling %s decode(): ", next_di->inst_id); } Py_XDECREF(py_res); } if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) { /* Frontends aren't really supposed to get Python * callbacks, but it's useful for testing. */ pdata->data = py_data; cb->cb(pdata, cb->cb_data); } break; case SRD_OUTPUT_BINARY: if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) { /* Convert from PyDict to srd_proto_data_binary. */ if (convert_binary(di, py_data, pdata) != SRD_OK) { /* An error was already logged. */ break; } cb->cb(pdata, cb->cb_data); } break; case SRD_OUTPUT_META: if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) { /* Annotations need converting from PyObject. */ if (convert_meta(pdata, py_data) != SRD_OK) { /* An exception was already set up. */ break; } cb->cb(pdata, cb->cb_data); } break; default: srd_err("Protocol decoder %s submitted invalid output type %d.", di->decoder->name, pdo->output_type); break; } g_free(pdata); Py_RETURN_NONE; }