t_input *shift_or_input(t_execution *exec, t_input *input) { t_input *tmp; tmp = input; if (!exec->r_value) { while (tmp->flag == 3 || tmp->flag == 2) { tmp = tmp->next; input_free(tmp); } } if (!tmp->flag) { tab_free(tmp->text); free(tmp); return (NULL); } else { tmp = tmp->next; input_free(tmp); exec->input = tmp; } set_ids((input = tmp)); return (input); }
/* * A simple test for the binary embedding */ int test_embed_tfidf() { int i, j, n, err = 0; string_t strs[10]; config_set_string(&cfg, "features.vect_norm", "none"); config_set_string(&cfg, "features.tfidf_file", TEST_TFIDF); unlink(TEST_TFIDF); char *test_file = getenv("TEST_FILE"); idf_create(test_file); test_printf("Testing TFIDF embedding"); input_config("lines"); n = input_open(test_file); input_read(strs, n); /* Compute IDF manually */ config_set_string(&cfg, "features.vect_embed", "bin"); fvec_t *w = fvec_zero(); for (i = 0, err = 0; i < n; i++) { fvec_t *fv = fvec_extract(strs[i].str, strs[i].len); fvec_add(w, fv); fvec_destroy(fv); } fvec_invert(w); fvec_mul(w, n); fvec_log2(w); if (!idf_check(w)) { err++; test_error("(%d) internal idf values seem to be wrong", i); } /* Invert w for multiplying out IDFs */ fvec_invert(w); config_set_string(&cfg, "features.vect_embed", "tfidf"); for (i = 0, err = 0; i < n; i++) { fvec_t *fv = fvec_extract(strs[i].str, strs[i].len); fvec_times(fv, w); /* Check if rest tf */ double d = 0; for (j = 0; j < fv->len; j++) d += fv->val[j]; err += fabs(d - 1.0) > 1e-6; fvec_destroy(fv); } test_return(err, n); fvec_destroy(w); input_free(strs, n); input_close(); idf_destroy(); unlink(TEST_TFIDF); return err; }
static void pin_callback(GtkWidget *dialog, gint response, gpointer user_data) { input_data *input = user_data; if (response == GTK_RESPONSE_OK) { const char *text; text = gtk_entry_get_text(GTK_ENTRY(input->entry)); if (input->numeric == TRUE) { guint pin = atoi(text); dbus_g_method_return(input->context, pin); } else { dbus_g_method_return(input->context, text); } } else { GError *error; error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, "Pairing request rejected"); dbus_g_method_return_error(input->context, error); } input_free(input); }
static gboolean cancel_request(DBusGMethodInvocation *context, gpointer user_data) { DBusGProxy *adapter = user_data; GList *list; GError *result; input_data *input; input = g_new0(input_data, 1); input->path = g_strdup(dbus_g_proxy_get_path(adapter)); list = g_list_find_custom(input_list, input, input_compare); g_free(input->path); g_free(input); if (!list || !list->data) return FALSE; input = list->data; close_notification(); result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, "Agent callback cancelled"); dbus_g_method_return_error(input->context, result); input_free(input); return TRUE; }
void rdp_free(rdpRdp* rdp) { if (rdp) { crypto_rc4_free(rdp->rc4_decrypt_key); crypto_rc4_free(rdp->rc4_encrypt_key); crypto_des3_free(rdp->fips_encrypt); crypto_des3_free(rdp->fips_decrypt); crypto_hmac_free(rdp->fips_hmac); freerdp_settings_free(rdp->settings); freerdp_settings_free(rdp->settingsCopy); transport_free(rdp->transport); license_free(rdp->license); input_free(rdp->input); update_free(rdp->update); fastpath_free(rdp->fastpath); nego_free(rdp->nego); mcs_free(rdp->mcs); redirection_free(rdp->redirection); autodetect_free(rdp->autodetect); heartbeat_free(rdp->heartbeat); multitransport_free(rdp->multitransport); bulk_free(rdp->bulk); free(rdp); } }
static int position_proc(struct menu_item *item, enum menu_callback_reason reason, void *data) { struct member_data *member_data = data; struct menu_item *watch = menu_userwatch_watch(member_data->userwatch); if (!member_data->position_set) { member_data->position_set = 1; member_data->x = watch->pxoffset; member_data->y = watch->pyoffset; } int dist = 2; if (input_pad() & BUTTON_Z) dist *= 2; switch (reason) { case MENU_CALLBACK_ACTIVATE: input_reserve(BUTTON_Z); break; case MENU_CALLBACK_DEACTIVATE: input_free(BUTTON_Z); break; case MENU_CALLBACK_NAV_UP: member_data->y -= dist; break; case MENU_CALLBACK_NAV_DOWN: member_data->y += dist; break; case MENU_CALLBACK_NAV_LEFT: member_data->x -= dist; break; case MENU_CALLBACK_NAV_RIGHT: member_data->x += dist; break; default: break; } watch->pxoffset = member_data->x; watch->pyoffset = member_data->y; return 0; }
/* * A simple test for the l2 norm */ int test_norm_l2() { int i, j, n, err = 0; string_t strs[10]; input_config("lines"); char *test_file = getenv("TEST_FILE"); n = input_open(test_file); input_read(strs, n); test_printf("Testing L2 normalization"); config_set_string(&cfg, "features.vect_norm", "l2"); for (i = 0, err = 0; i < n; i++) { fvec_t *fv = fvec_extract(strs[i].str, strs[i].len); double n = 0; for (j = 0; j < fv->len; j++) n += fv->val[j] * fv->val[j]; err += fabs(sqrt(n) - 1.0) > 1e-6; fvec_destroy(fv); } test_return(err, n); input_free(strs, n); input_close(); return err; }
/* * A simple test for the binary embedding */ int test_embed_bin() { int i, j, n, err = 0; string_t strs[10]; input_config("lines"); char *test_file = getenv("TEST_FILE"); n = input_open(test_file); input_read(strs, n); test_printf("Testing binary embedding"); config_set_string(&cfg, "features.vect_embed", "bin"); config_set_string(&cfg, "features.vect_norm", "none"); for (i = 0, err = 0; i < n; i++) { fvec_t *fv = fvec_extract(strs[i].str, strs[i].len); double n = 0; for (j = 0; j < fv->len; j++) n += fv->val[j]; err += fabs(n - fv->len) > 1e-6; fvec_destroy(fv); } test_return(err, n); input_free(strs, n); input_close(); return err; }
static int leave_proc(struct menu_item *item, enum menu_switch_reason reason) { input_free(BUTTON_D_UP | BUTTON_D_DOWN | BUTTON_D_LEFT | BUTTON_D_RIGHT | BUTTON_Z); input_bind_set_disable(COMMAND_PREVROOM, 1); input_bind_set_disable(COMMAND_NEXTROOM, 1); return 0; }
void product_clear_inputs(Product *p_product){ for(int i=0;i<p_product->nb_input_amount;i++){ input_free(p_product->input_amount_list[i].p_input); } p_product->nb_input_amount = 0; p_product->input_amount_list = NULL; }
t_input *get_exec_end(t_execution *exec, t_input *input) { while (input->id != exec->id.j) { input_free(input); input = input->next; } return (input); }
void shell_free(Shell *shell) { vTaskDelete(shell->task); input_free(shell->input); cli_free(shell->cli); vt102_free(shell->vt102); }
/** * Main processing routine of Sally. This function processes chunks of * strings. It might be suitable for OpenMP support in a later version. */ static void sally_process() { long read, i, j; int chunk; const char *hash_file; /* Check if a hash file is set */ config_lookup_string(&cfg, "features.hash_file", &hash_file); /* Get chunk size */ config_lookup_int(&cfg, "input.chunk_size", &chunk); /* Allocate space */ fvec_t **fvec = malloc(sizeof(fvec_t *) * chunk); string_t *strs = malloc(sizeof(string_t) * chunk); if (!fvec || !strs) fatal("Could not allocate memory for embedding"); info_msg(1, "Processing %d strings in chunks of %d.", entries, chunk); for (i = 0, read = 0; i < entries; i += read) { read = input_read(strs, chunk); if (read <= 0) fatal("Failed to read strings from input '%s'", input); /* Generic preprocessing of input */ input_preproc(strs, read); #ifdef ENABLE_OPENMP #pragma omp parallel for #endif for (j = 0; j < read; j++) { fvec[j] = fvec_extract(strs[j].str, strs[j].len); fvec_set_label(fvec[j], strs[j].label); fvec_set_source(fvec[j], strs[j].src); } if (!output_write(fvec, read)) fatal("Failed to write vectors to output '%s'", output); /* Free memory */ input_free(strs, read); output_free(fvec, read); /* Reset hash if enabled but no hash file is set */ if (fhash_enabled() && !strlen(hash_file) > 0) fhash_reset(); prog_bar(0, entries, i + read); } free(fvec); free(strs); }
static void close_input(void) { input_free(input.input); assert(input.file != NULL); fclose(input.file); input.input = NULL; input.file = NULL; input.bufend = NULL; input.bufpos = NULL; input.c = EOF; }
void rdp_free(rdpRdp* rdp) { if (rdp != NULL) { settings_free(rdp->settings); transport_free(rdp->transport); license_free(rdp->license); input_free(rdp->input); update_free(rdp->update); mcs_free(rdp->mcs); xfree(rdp); } }
static void confirm_callback (GtkWidget *dialog, gint response, gpointer user_data) { input_data *input = user_data; if (response != GTK_RESPONSE_ACCEPT) { GError *error; error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, "Confirmation request rejected"); dbus_g_method_return_error(input->context, error); } else dbus_g_method_return(input->context); input_free(input); }
void free_graphic(void) { window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW); hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER); camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA); input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT); shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE); text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT); debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW); window_free(&window_handle); hl_render_free(&hl_render_handle); camera_free(&camera_handle); input_free(&input_handle); shader_free(&shader_texture_handle); text_free(&text_handle); debug_draw_free(&debug_draw_handle); }
void rdp_free(rdpRdp* rdp) { if (rdp != NULL) { settings_free(rdp->settings); transport_free(rdp->transport); license_free(rdp->license); input_free(rdp->input); update_free(rdp->update); fastpath_free(rdp->fastpath); nego_free(rdp->nego); mcs_free(rdp->mcs); redirection_free(rdp->redirection); mppc_free(rdp); xfree(rdp); } }
void engine_replay_journal(Engine *engine) { if(!engine->data_dir) return; glob_t g; char *pattern; asprintf(&pattern, "%.*s/[0-9]*.log", engine->data_dir->len, engine->data_dir->val); int status = glob(pattern, 0, NULL, &g); if(status || !g.gl_pathc) { INFO("Can't glob: %d", status); return; } pstring nl = {"\n", 1}; Input *input = input_new(engine, BUF_SIZE); input->output = malloc(sizeof(Output)); input->output->write = _log_write; ProtocolParser *pparser = line_input_protocol_new(input); pstring *pstr = pstring_new(BUF_SIZE); for(int i = 0; i < g.gl_pathc; i++) { char *path = g.gl_pathv[i]; DEBUG("found %s", path); FILE *file = fopen(path, "r"); if(!file) { ERR("can't open %s", path); } else { int nread =0; while ((pstr->len = fread(pstr->val, 1, BUF_SIZE, file))) { pparser->consume(pparser, pstr); } fclose(file); } } pstring_free(pstr); line_input_protocol_free(pparser); free(input->output); input_free(input); }
t_input *shift_sc_input(t_execution *exec, t_input *input) { t_input *tmp; tmp = input; if (!tmp->flag) { tab_free(tmp->text); free(tmp); return (NULL); } else { tmp = tmp->next; input_free(input); exec->input = tmp; } set_ids((input = tmp)); return (input); }
void rdp_free(rdpRdp* rdp) { if (rdp != NULL) { crypto_rc4_free(rdp->rc4_decrypt_key); crypto_rc4_free(rdp->rc4_encrypt_key); crypto_des3_free(rdp->fips_encrypt); crypto_des3_free(rdp->fips_decrypt); crypto_hmac_free(rdp->fips_hmac); extension_free(rdp->extension); settings_free(rdp->settings); transport_free(rdp->transport); license_free(rdp->license); input_free(rdp->input); update_free(rdp->update); fastpath_free(rdp->fastpath); nego_free(rdp->nego); mcs_free(rdp->mcs); redirection_free(rdp->redirection); mppc_free(rdp); xfree(rdp); } }
static int runtest(char *filename, char *ironout) { struct input *input = input_open(filename); char current_line[MAXLINELEN]; char cmd[128]; char *line; if (!input) return 1; while ((line = input_line(input))) { int result = -1; strcpy(current_line, line); nthtoken(cmd, line, " \n", 2); if (!strcmp(cmd, "comment") || !strcmp(cmd, "#") || !*cmd) result = read_comment(input); if (!strcmp(cmd, "write") || !strcmp(cmd, ">")) result = write_file(input); if (!strcmp(cmd, "read") || !strcmp(cmd, "<")) result = read_file(input); if (!strcmp(cmd, "ironout")) result = exec_ironout(input, ironout); if (result == -1) { printf("unknown cmd: %s\n", cmd); return 1; } if (result > 0) { char *testname = filename; if (strchr(testname, '/')) testname = strrchr(testname, '/') + 1; printf("%s:%d %s", testname, input->lineno, current_line); return 1; } } input_free(input); return 0; }
static void teardown_cb(void *data) { free_rows(&pi); input_free(&ds); }
rdpRdp* rdp_new(rdpContext* context) { rdpRdp* rdp; DWORD flags; BOOL newSettings = FALSE; rdp = (rdpRdp*) calloc(1, sizeof(rdpRdp)); if (!rdp) return NULL; rdp->context = context; rdp->instance = context->instance; flags = 0; if (context->ServerMode) flags |= FREERDP_SETTINGS_SERVER_MODE; if (!context->settings) { context->settings = freerdp_settings_new(flags); if (!context->settings) goto out_free; newSettings = TRUE; } rdp->settings = context->settings; rdp->settings->instance = context->instance; if (context->instance) context->instance->settings = rdp->settings; rdp->transport = transport_new(rdp->settings); if (!rdp->transport) goto out_free_settings; rdp->transport->rdp = rdp; rdp->license = license_new(rdp); if (!rdp->license) goto out_free_transport; rdp->input = input_new(rdp); if (!rdp->input) goto out_free_license; rdp->update = update_new(rdp); if (!rdp->update) goto out_free_input; rdp->fastpath = fastpath_new(rdp); if (!rdp->fastpath) goto out_free_update; rdp->nego = nego_new(rdp->transport); if (!rdp->nego) goto out_free_fastpath; rdp->mcs = mcs_new(rdp->transport); if (!rdp->mcs) goto out_free_nego; rdp->redirection = redirection_new(); if (!rdp->redirection) goto out_free_mcs; rdp->autodetect = autodetect_new(); if (!rdp->autodetect) goto out_free_redirection; rdp->heartbeat = heartbeat_new(); if (!rdp->heartbeat) goto out_free_autodetect; rdp->multitransport = multitransport_new(); if (!rdp->multitransport) goto out_free_heartbeat; rdp->bulk = bulk_new(context); if (!rdp->bulk) goto out_free_multitransport; return rdp; out_free_multitransport: multitransport_free(rdp->multitransport); out_free_heartbeat: heartbeat_free(rdp->heartbeat); out_free_autodetect: autodetect_free(rdp->autodetect); out_free_redirection: redirection_free(rdp->redirection); out_free_mcs: mcs_free(rdp->mcs); out_free_nego: nego_free(rdp->nego); out_free_fastpath: fastpath_free(rdp->fastpath); out_free_update: update_free(rdp->update); out_free_input: input_free(rdp->input); out_free_license: license_free(rdp->license); out_free_transport: transport_free(rdp->transport); out_free_settings: if (newSettings) freerdp_settings_free(rdp->settings); out_free: free(rdp); return NULL; }