// ---------------------------------------------------------------- static int stdio_byte_reader_open_func(struct _byte_reader_t* pbr, char* prepipe, char* filename) { stdio_byte_reader_state_t* pstate = mlr_malloc_or_die(sizeof(stdio_byte_reader_state_t)); pstate->filename = mlr_strdup_or_die(filename); if (prepipe == NULL) { if (streq(pstate->filename, "-")) { pstate->fp = stdin; } else { pstate->fp = fopen(filename, "r"); if (pstate->fp == NULL) { perror("fopen"); fprintf(stderr, "%s: Couldn't fopen \"%s\" for read.\n", MLR_GLOBALS.argv0, filename); exit(1); } } } else { char* command = mlr_malloc_or_die(strlen(prepipe) + 3 + strlen(filename) + 1); if (streq(filename, "-")) sprintf(command, "%s", prepipe); else sprintf(command, "%s < %s", prepipe, filename); pstate->fp = popen(command, "r"); if (pstate->fp == NULL) { fprintf(stderr, "%s: Couldn't popen \"%s\" for read.\n", MLR_GLOBALS.argv0, command); perror(command); exit(1); } free(command); } pbr->pvstate = pstate; return TRUE; }
// ---------------------------------------------------------------- lrec_reader_t* lrec_reader_stdio_json_alloc(char* input_json_flatten_separator, json_array_ingest_t json_array_ingest, char* line_term, comment_handling_t comment_handling, char* comment_string) { lrec_reader_t* plrec_reader = mlr_malloc_or_die(sizeof(lrec_reader_t)); lrec_reader_stdio_json_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_reader_stdio_json_state_t)); pstate->ptop_level_json_objects = sllv_alloc(); pstate->precords = sllv_alloc(); pstate->input_json_flatten_separator = input_json_flatten_separator; pstate->json_array_ingest = json_array_ingest; pstate->specified_line_term = line_term; pstate->do_auto_line_term = FALSE; pstate->detected_line_term = "\n"; // xxx adapt to MLR_GLOBALS/ctx-const for Windows port pstate->comment_handling = comment_handling; pstate->comment_string = comment_string; if (streq(line_term, "auto")) { pstate->do_auto_line_term = TRUE; } plrec_reader->pvstate = (void*)pstate; plrec_reader->popen_func = file_ingestor_stdio_vopen; plrec_reader->pclose_func = file_ingestor_stdio_nop_vclose; plrec_reader->pprocess_func = lrec_reader_stdio_json_process; plrec_reader->psof_func = lrec_reader_stdio_json_sof; plrec_reader->pfree_func = lrec_reader_stdio_json_free; return plrec_reader; }
// ---------------------------------------------------------------- lrec_reader_t* lrec_reader_mmap_csvlite_alloc(char* irs, char* ifs, int allow_repeat_ifs) { lrec_reader_t* plrec_reader = mlr_malloc_or_die(sizeof(lrec_reader_t)); lrec_reader_mmap_csvlite_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_reader_mmap_csvlite_state_t)); pstate->ifnr = 0LL; pstate->irs = irs; pstate->ifs = ifs; pstate->irslen = strlen(irs); pstate->ifslen = strlen(ifs); pstate->allow_repeat_ifs = allow_repeat_ifs; pstate->expect_header_line_next = TRUE; pstate->pheader_keeper = NULL; pstate->pheader_keepers = lhmslv_alloc(); // xxx get rid of func-ptr ampersands throughout the tree plrec_reader->pvstate = (void*)pstate; plrec_reader->popen_func = file_reader_mmap_vopen; plrec_reader->pclose_func = file_reader_mmap_vclose; plrec_reader->pprocess_func = (pstate->irslen == 1 && pstate->ifslen == 1) ? lrec_reader_mmap_csvlite_process_single_seps : lrec_reader_mmap_csvlite_process_multi_seps; plrec_reader->psof_func = lrec_reader_mmap_csvlite_sof; plrec_reader->pfree_func = NULL; return plrec_reader; }
lrec_reader_t* lrec_reader_stdio_dkvp_alloc(char* irs, char* ifs, char* ips, int allow_repeat_ifs) { lrec_reader_t* plrec_reader = mlr_malloc_or_die(sizeof(lrec_reader_t)); lrec_reader_stdio_dkvp_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_reader_stdio_dkvp_state_t)); pstate->irs = irs; pstate->ifs = ifs; pstate->ips = ips; pstate->irslen = strlen(irs); pstate->ifslen = strlen(ifs); pstate->ipslen = strlen(ips); pstate->allow_repeat_ifs = allow_repeat_ifs; plrec_reader->pvstate = (void*)pstate; plrec_reader->popen_func = &file_reader_stdio_vopen; plrec_reader->pclose_func = &file_reader_stdio_vclose; if (pstate->irslen == 1) { plrec_reader->pprocess_func = (pstate->ifslen == 1 && pstate->ipslen == 1) ? &lrec_reader_stdio_dkvp_process_single_irs_single_others : &lrec_reader_stdio_dkvp_process_single_irs_multi_others; } else { plrec_reader->pprocess_func = (pstate->ifslen == 1 && pstate->ipslen == 1) ? &lrec_reader_stdio_dkvp_process_multi_irs_single_others : &lrec_reader_stdio_dkvp_process_multi_irs_multi_others; } plrec_reader->psof_func = &lrec_reader_stdio_dkvp_sof; plrec_reader->pfree_func = &lrec_reader_stdio_dkvp_free; return plrec_reader; }
// ---------------------------------------------------------------- lrec_writer_t* lrec_writer_csv_alloc(char* ors, char* ofs, int oquoting, int headerless_csv_output) { lrec_writer_t* plrec_writer = mlr_malloc_or_die(sizeof(lrec_writer_t)); lrec_writer_csv_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_writer_csv_state_t)); pstate->onr = 0; pstate->ors = ors; pstate->ofs = ofs; pstate->orslen = strlen(pstate->ors); pstate->ofslen = strlen(pstate->ofs); pstate->headerless_csv_output = headerless_csv_output; switch(oquoting) { case QUOTE_ALL: pstate->pquoted_output_func = quote_all_output_func; break; case QUOTE_NONE: pstate->pquoted_output_func = quote_none_output_func; break; case QUOTE_MINIMAL: pstate->pquoted_output_func = quote_minimal_output_func; break; case QUOTE_NUMERIC: pstate->pquoted_output_func = quote_numeric_output_func; break; default: fprintf(stderr, "%s: internal coding error: output-quoting style 0x%x unrecognized.\n", MLR_GLOBALS.argv0, oquoting); exit(1); } pstate->num_header_lines_output = 0LL; pstate->plast_header_output = NULL; plrec_writer->pvstate = (void*)pstate; plrec_writer->pprocess_func = lrec_writer_csv_process; plrec_writer->pfree_func = lrec_writer_csv_free; return plrec_writer; }
// xxx cmt mem-mgt // xxx put "alloc" in the name char* mt_format_val(mv_t* pval) { char* string = NULL; switch(pval->type) { case MT_NULL: return strdup(""); break; case MT_ERROR: return strdup("(error)"); break; case MT_BOOL: return strdup(pval->u.boolv ? "true" : "false"); break; case MT_DOUBLE: // xxx what is worst-case here ... string = mlr_malloc_or_die(32); sprintf(string, MLR_GLOBALS.ofmt, pval->u.dblv); return string; break; case MT_INT: // log10(2**64) is < 20 so this is plenty. string = mlr_malloc_or_die(32); sprintf(string, "%lld", pval->u.intv); return string; break; case MT_STRING: return strdup(pval->u.strv); break; default: return strdup("???"); break; } }
// ---------------------------------------------------------------- lrec_reader_t* lrec_reader_mmap_xtab_alloc(char* ifs, char* ips, int allow_repeat_ips) { lrec_reader_t* plrec_reader = mlr_malloc_or_die(sizeof(lrec_reader_t)); lrec_reader_mmap_xtab_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_reader_mmap_xtab_state_t)); pstate->ifs = ifs; pstate->ips = ips; pstate->ifslen = strlen(pstate->ifs); pstate->ipslen = strlen(pstate->ips); pstate->allow_repeat_ips = allow_repeat_ips; plrec_reader->pvstate = (void*)pstate; plrec_reader->popen_func = file_reader_mmap_vopen; plrec_reader->pclose_func = file_reader_mmap_vclose; if (pstate->ifslen == 1) { plrec_reader->pprocess_func = (pstate->ipslen == 1) ? lrec_reader_mmap_xtab_process_single_ifs_single_ips : lrec_reader_mmap_xtab_process_single_ifs_multi_ips; } else { plrec_reader->pprocess_func = (pstate->ipslen == 1) ? lrec_reader_mmap_xtab_process_multi_ifs_single_ips : lrec_reader_mmap_xtab_process_multi_ifs_multi_ips; } plrec_reader->psof_func = lrec_reader_mmap_xtab_sof; plrec_reader->pfree_func = lrec_reader_mmap_xtab_free; return plrec_reader; }
// ---------------------------------------------------------------- percentile_keeper_t* percentile_keeper_alloc() { int capacity = INITIAL_CAPACITY; percentile_keeper_t* ppercentile_keeper = mlr_malloc_or_die(sizeof(percentile_keeper_t)); ppercentile_keeper->data = mlr_malloc_or_die(capacity*sizeof(double)); ppercentile_keeper->size = 0; ppercentile_keeper->capacity = capacity; ppercentile_keeper->sorted = FALSE; return ppercentile_keeper; }
// ---------------------------------------------------------------- lrec_reader_t* lrec_reader_csvex_alloc(byte_reader_t* pbr, char irs, char ifs) { lrec_reader_t* plrec_reader = mlr_malloc_or_die(sizeof(lrec_reader_t)); lrec_reader_csvex_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_reader_csvex_state_t)); pstate->ilno = 0LL; pstate->irs = "\r\n"; // xxx multi-byte the cli irs/ifs/etc, and integrate here pstate->ifs = ","; // xxx multi-byte the cli irs/ifs/etc, and integrate here pstate->dquote_irs = mlr_paste_2_strings("\"", pstate->irs); pstate->dquote_ifs = mlr_paste_2_strings("\"", pstate->ifs); pstate->dquote_eof = "\"\xff"; pstate->dquote = "\""; pstate->dquote_dquote = "\"\""; pstate->ifs_eof = mlr_paste_2_strings(pstate->ifs, "\xff"); pstate->irs_len = strlen(pstate->irs); pstate->ifs_len = strlen(pstate->ifs); pstate->dquote_irs_len = strlen(pstate->dquote_irs); pstate->dquote_ifs_len = strlen(pstate->dquote_ifs); pstate->dquote_eof_len = strlen(pstate->dquote_eof); pstate->dquote_len = strlen(pstate->dquote); pstate->dquote_dquote_len = strlen(pstate->dquote_dquote); pstate->ifs_eof_len = strlen(pstate->ifs_eof); pstate->peek_buf_len = pstate->irs_len; pstate->peek_buf_len = mlr_imax2(pstate->peek_buf_len, pstate->ifs_len); pstate->peek_buf_len = mlr_imax2(pstate->peek_buf_len, pstate->dquote_irs_len); pstate->peek_buf_len = mlr_imax2(pstate->peek_buf_len, pstate->dquote_ifs_len); pstate->peek_buf_len = mlr_imax2(pstate->peek_buf_len, pstate->dquote_eof_len); pstate->peek_buf_len = mlr_imax2(pstate->peek_buf_len, pstate->dquote_len); pstate->peek_buf_len = mlr_imax2(pstate->peek_buf_len, pstate->dquote_dquote_len); pstate->peek_buf_len = mlr_imax2(pstate->peek_buf_len, pstate->ifs_eof_len); pstate->peek_buf_len += 2; sb_init(&pstate->sb, STRING_BUILDER_INIT_SIZE); pstate->psb = &pstate->sb; pstate->pbr = pbr; pstate->pfr = NULL; // xxx allocate the parse-tries here -- one for dquote only, // the second for non-dquote-after-that, the third for dquoted-after-that. pstate->expect_header_line_next = TRUE; pstate->pheader_keeper = NULL; pstate->pheader_keepers = lhmslv_alloc(); plrec_reader->pvstate = (void*)pstate; plrec_reader->popen_func = &file_reader_stdio_vopen; plrec_reader->pclose_func = &file_reader_stdio_vclose; plrec_reader->pprocess_func = &lrec_reader_csvex_process; plrec_reader->psof_func = &lrec_reader_csvex_sof; plrec_reader->pfree_func = &lrec_reader_csvex_free; return plrec_reader; }
rval_evaluator_t* rval_evaluator_alloc_from_x_z_func(mv_zary_func_t* pfunc) { rval_evaluator_x_z_state_t* pstate = mlr_malloc_or_die(sizeof(rval_evaluator_x_z_state_t)); pstate->pfunc = pfunc; rval_evaluator_t* pevaluator = mlr_malloc_or_die(sizeof(rval_evaluator_t)); pevaluator->pvstate = pstate; pevaluator->pprocess_func = rval_evaluator_x_z_func; pevaluator->pfree_func = rval_evaluator_x_z_free; return pevaluator; }
static step_t* step_rsum_alloc(char* input_field_name) { step_t* pstep = mlr_malloc_or_die(sizeof(step_t)); step_rsum_state_t* pstate = mlr_malloc_or_die(sizeof(step_rsum_state_t)); pstate->rsum = 0.0; pstate->output_field_name = mlr_paste_2_strings(input_field_name, "_rsum"); pstep->pvstate = (void*)pstate; pstep->psprocess_func = NULL; pstep->pdprocess_func = &step_rsum_dprocess; return pstep; }
static acc_t* acc_count_alloc() { acc_t* pacc = mlr_malloc_or_die(sizeof(acc_t)); acc_count_state_t* pstate = mlr_malloc_or_die(sizeof(acc_count_state_t)); pstate->count = 0LL; pacc->pvstate = (void*)pstate; pacc->psingest_func = &acc_count_singest; pacc->pdingest_func = NULL; pacc->pemit_func = &acc_count_emit; return pacc; }
static step_t* step_counter_alloc(char* input_field_name) { step_t* pstep = mlr_malloc_or_die(sizeof(step_t)); step_counter_state_t* pstate = mlr_malloc_or_die(sizeof(step_counter_state_t)); pstate->counter = 0LL; pstate->output_field_name = mlr_paste_2_strings(input_field_name, "_counter"); pstep->pvstate = (void*)pstate; pstep->psprocess_func = &step_counter_sprocess; pstep->pdprocess_func = NULL; return pstep; }
static acc_t* acc_percentile_alloc() { acc_t* pacc = mlr_malloc_or_die(sizeof(acc_t)); acc_percentile_state_t* pstate = mlr_malloc_or_die(sizeof(acc_percentile_state_t)); pstate->ppercentile_keeper = percentile_keeper_alloc(); pacc->pvstate = (void*)pstate; pacc->psingest_func = NULL; pacc->pdingest_func = &acc_percentile_dingest; pacc->pemit_func = &acc_percentile_emit; return pacc; }
static acc_t* acc_mode_alloc() { acc_t* pacc = mlr_malloc_or_die(sizeof(acc_t)); acc_mode_state_t* pstate = mlr_malloc_or_die(sizeof(acc_mode_state_t)); pstate->pcounts_for_value = lhmsi_alloc(); pacc->pvstate = (void*)pstate; pacc->psingest_func = &acc_mode_singest; pacc->pdingest_func = NULL; pacc->pemit_func = &acc_mode_emit; return pacc; }
static acc_t* acc_max_alloc() { acc_t* pacc = mlr_malloc_or_die(sizeof(acc_t)); acc_max_state_t* pstate = mlr_malloc_or_die(sizeof(acc_max_state_t)); pstate->have_max = FALSE; pstate->max = -999.0; pacc->pvstate = (void*)pstate; pacc->psingest_func = NULL; pacc->pdingest_func = &acc_max_dingest; pacc->pemit_func = &acc_max_emit; return pacc; }
rval_evaluator_t* rval_evaluator_alloc_from_b_bb_xor_func(rval_evaluator_t* parg1, rval_evaluator_t* parg2) { rval_evaluator_b_bb_state_t* pstate = mlr_malloc_or_die(sizeof(rval_evaluator_b_bb_state_t)); pstate->parg1 = parg1; pstate->parg2 = parg2; rval_evaluator_t* pevaluator = mlr_malloc_or_die(sizeof(rval_evaluator_t)); pevaluator->pvstate = pstate; pevaluator->pprocess_func = rval_evaluator_b_bb_xor_func; pevaluator->pfree_func = rval_evaluator_b_bb_free; return pevaluator; }
static mapper_t* mapper_group_like_alloc() { mapper_t* pmapper = mlr_malloc_or_die(sizeof(mapper_t)); mapper_group_like_state_t* pstate = mlr_malloc_or_die(sizeof(mapper_group_like_state_t)); pstate->precords_by_key_field_names = lhmslv_alloc(); pmapper->pvstate = pstate; pmapper->pprocess_func = mapper_group_like_process; pmapper->pfree_func = mapper_group_like_free; return pmapper; }
lrec_writer_t* lrec_writer_xtab_alloc() { lrec_writer_t* plrec_writer = mlr_malloc_or_die(sizeof(lrec_writer_t)); lrec_writer_xtab_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_writer_xtab_state_t)); pstate->record_count = 0LL; plrec_writer->pvstate = pstate; plrec_writer->pprocess_func = &lrec_writer_xtab_process; plrec_writer->pfree_func = &lrec_writer_xtab_free; return plrec_writer; }
static mapper_t* mapper_regularize_alloc() { mapper_t* pmapper = mlr_malloc_or_die(sizeof(mapper_t)); mapper_regularize_state_t* pstate = mlr_malloc_or_die(sizeof(mapper_regularize_state_t)); pstate->psorted_to_original = lhmslv_alloc(); pmapper->pvstate = (void*)pstate; pmapper->pprocess_func = mapper_regularize_process; pmapper->pfree_func = mapper_regularize_free; return pmapper; }
rval_evaluator_t* rval_evaluator_alloc_from_i_s_func(mv_unary_func_t* pfunc, rval_evaluator_t* parg1) { rval_evaluator_i_s_state_t* pstate = mlr_malloc_or_die(sizeof(rval_evaluator_i_s_state_t)); pstate->pfunc = pfunc; pstate->parg1 = parg1; rval_evaluator_t* pevaluator = mlr_malloc_or_die(sizeof(rval_evaluator_t)); pevaluator->pvstate = pstate; pevaluator->pprocess_func = rval_evaluator_i_s_func; pevaluator->pfree_func = rval_evaluator_i_s_free; return pevaluator; }
static step_t* step_delta_alloc(char* input_field_name) { step_t* pstep = mlr_malloc_or_die(sizeof(step_t)); step_delta_state_t* pstate = mlr_malloc_or_die(sizeof(step_delta_state_t)); pstate->prev = -999.0; pstate->have_prev = FALSE; pstate->output_field_name = mlr_paste_2_strings(input_field_name, "_delta"); pstep->pvstate = (void*)pstate; pstep->psprocess_func = NULL; pstep->pdprocess_func = &step_delta_dprocess; return pstep; }
// ---------------------------------------------------------------- lrec_reader_t* lrec_reader_mmap_xtab_alloc(char* ifs, char* ips, int allow_repeat_ips, comment_handling_t comment_handling, char* comment_string) { // lrec_reader_alloc should have shunted away from us in this case. // (Interleaving blank-line handling, line-term autodetect, and comment-handling all in // the byte-at-a-time logic turned out to be a mess in this file. In the stdio implementation, // by constrast, it falls out rather easily.) if (comment_string != NULL) { fprintf(stderr, "%s: internal coding error detected in file %s at line %d.\n", MLR_GLOBALS.bargv0, __FILE__, __LINE__); exit(1); } lrec_reader_t* plrec_reader = mlr_malloc_or_die(sizeof(lrec_reader_t)); lrec_reader_mmap_xtab_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_reader_mmap_xtab_state_t)); pstate->ifs = ifs; pstate->ips = ips; pstate->ifslen = strlen(pstate->ifs); pstate->ipslen = strlen(pstate->ips); pstate->allow_repeat_ips = allow_repeat_ips; pstate->do_auto_line_term = FALSE; plrec_reader->pvstate = (void*)pstate; plrec_reader->popen_func = file_reader_mmap_vopen; plrec_reader->pclose_func = file_reader_mmap_vclose; if (streq(ifs, "auto")) { // Auto means either lines end in "\n" or "\r\n" (LF or CRLF). In // either case the final character is "\n". Then for autodetect we // simply check if there's a character in the line before the '\n', and // if that is '\r'. pstate->do_auto_line_term = TRUE; pstate->ifs = "\n"; pstate->ifslen = 1; plrec_reader->pprocess_func = (pstate->ipslen == 1) ? lrec_reader_mmap_xtab_process_single_ifs_single_ips : lrec_reader_mmap_xtab_process_single_ifs_multi_ips; } else if (pstate->ifslen == 1) { plrec_reader->pprocess_func = (pstate->ipslen == 1) ? lrec_reader_mmap_xtab_process_single_ifs_single_ips : lrec_reader_mmap_xtab_process_single_ifs_multi_ips; } else { plrec_reader->pprocess_func = (pstate->ipslen == 1) ? lrec_reader_mmap_xtab_process_multi_ifs_single_ips : lrec_reader_mmap_xtab_process_multi_ifs_multi_ips; } plrec_reader->psof_func = lrec_reader_mmap_xtab_sof; plrec_reader->pfree_func = lrec_reader_mmap_xtab_free; return plrec_reader; }
// ---------------------------------------------------------------- loop_stack_t* loop_stack_alloc() { loop_stack_t* pstack = mlr_malloc_or_die(sizeof(loop_stack_t)); // Guard zone of one. As noted in the header file, set/get are intentionally not bounds-checked. // If set is called without push, or after final pop, we can at least not corrupt other code. pstack->num_used_minus_one = 0; pstack->num_allocated = INITIAL_SIZE; pstack->pframes = mlr_malloc_or_die(pstack->num_allocated * sizeof(int)); memset(pstack->pframes, 0, pstack->num_allocated * sizeof(int)); return pstack; }
static acc_t* acc_stddev_var_meaneb_alloc(int do_which) { acc_t* pacc = mlr_malloc_or_die(sizeof(acc_t)); acc_stddev_var_meaneb_state_t* pstate = mlr_malloc_or_die(sizeof(acc_stddev_var_meaneb_state_t)); pstate->count = 0LL; pstate->sumx = 0.0; pstate->sumx2 = 0.0; pstate->do_which = do_which; pacc->pvstate = (void*)pstate; pacc->psingest_func = NULL; pacc->pdingest_func = &acc_stddev_var_meaneb_dingest; pacc->pemit_func = &acc_stddev_var_meaneb_emit; return pacc; }
rval_evaluator_t* rval_evaluator_alloc_from_ternop(rval_evaluator_t* parg1, rval_evaluator_t* parg2, rval_evaluator_t* parg3) { rval_evaluator_ternop_state_t* pstate = mlr_malloc_or_die(sizeof(rval_evaluator_ternop_state_t)); pstate->parg1 = parg1; pstate->parg2 = parg2; pstate->parg3 = parg3; rval_evaluator_t* pevaluator = mlr_malloc_or_die(sizeof(rval_evaluator_t)); pevaluator->pvstate = pstate; pevaluator->pprocess_func = rval_evaluator_ternop_func; pevaluator->pfree_func = rval_evaluator_ternop_free; return pevaluator; }
stats1_acc_t* stats1_max_alloc(char* value_field_name, char* stats1_acc_name, int allow_int_float) { stats1_acc_t* pstats1_acc = mlr_malloc_or_die(sizeof(stats1_acc_t)); stats1_max_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_max_state_t)); pstate->max = mv_from_null(); pstate->output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); pstats1_acc->pvstate = (void*)pstate; pstats1_acc->pdingest_func = NULL; pstats1_acc->pningest_func = stats1_max_ningest; pstats1_acc->psingest_func = NULL; pstats1_acc->pemit_func = stats1_max_emit; pstats1_acc->pfree_func = stats1_max_free; return pstats1_acc; }
// ---------------------------------------------------------------- lrec_writer_t* lrec_writer_dkvp_alloc(char* ors, char* ofs, char* ops) { lrec_writer_t* plrec_writer = mlr_malloc_or_die(sizeof(lrec_writer_t)); lrec_writer_dkvp_state_t* pstate = mlr_malloc_or_die(sizeof(lrec_writer_dkvp_state_t)); pstate->ors = ors; pstate->ofs = ofs; pstate->ops = ops; plrec_writer->pvstate = (void*)pstate; plrec_writer->pprocess_func = lrec_writer_dkvp_process; plrec_writer->pfree_func = lrec_writer_dkvp_free; return plrec_writer; }
stats1_acc_t* stats1_mode_alloc(char* value_field_name, char* stats1_acc_name, int allow_int_float) { stats1_acc_t* pstats1_acc = mlr_malloc_or_die(sizeof(stats1_acc_t)); stats1_mode_state_t* pstate = mlr_malloc_or_die(sizeof(stats1_mode_state_t)); pstate->pcounts_for_value = lhmsi_alloc(); pstate->output_field_name = mlr_paste_3_strings(value_field_name, "_", stats1_acc_name); pstats1_acc->pvstate = (void*)pstate; pstats1_acc->pdingest_func = NULL; pstats1_acc->pningest_func = NULL; pstats1_acc->psingest_func = stats1_mode_singest; pstats1_acc->pemit_func = stats1_mode_emit; pstats1_acc->pfree_func = stats1_mode_free; return pstats1_acc; }
rval_evaluator_t* rval_evaluator_alloc_from_variadic_func(mv_variadic_func_t* pfunc, rval_evaluator_t** pargs, int nargs) { rval_evaluator_variadic_state_t* pstate = mlr_malloc_or_die(sizeof(rval_evaluator_variadic_state_t)); pstate->pfunc = pfunc; pstate->pargs = pargs; pstate->nargs = nargs; pstate->pmvs = mlr_malloc_or_die(nargs * sizeof(mv_t)); rval_evaluator_t* pevaluator = mlr_malloc_or_die(sizeof(rval_evaluator_t)); pevaluator->pvstate = pstate; pevaluator->pprocess_func = rval_evaluator_variadic_func; pevaluator->pfree_func = rval_evaluator_variadic_free; return pevaluator; }