mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-28 18:21:52 +00:00
neaten
This commit is contained in:
parent
b241f6c263
commit
436d7ad4d9
4 changed files with 21 additions and 19 deletions
|
|
@ -69,7 +69,7 @@ typedef struct _lrec_reader_csv_state_t {
|
|||
} lrec_reader_csv_state_t;
|
||||
|
||||
static slls_t* lrec_reader_csv_get_fields(lrec_reader_csv_state_t* pstate);
|
||||
static lrec_t* paste_header_and_data(lrec_reader_csv_state_t* pstate, slls_t* pdata_fields);
|
||||
static lrec_t* paste_header_and_data(lrec_reader_csv_state_t* pstate, slls_t* pdata_fields, context_t* pctx);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static lrec_t* lrec_reader_csv_process(void* pvstate, void* pvhandle, context_t* pctx) {
|
||||
|
|
@ -107,7 +107,7 @@ static lrec_t* lrec_reader_csv_process(void* pvstate, void* pvhandle, context_t*
|
|||
//lrec_t* prec = paste_header_and_data(pstate, pdata_fields);
|
||||
//slls_free(pdata_fields);
|
||||
//return prec;
|
||||
return paste_header_and_data(pstate, pdata_fields);
|
||||
return paste_header_and_data(pstate, pdata_fields, pctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,19 +239,22 @@ static slls_t* lrec_reader_csv_get_fields(lrec_reader_csv_state_t* pstate) {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static lrec_t* paste_header_and_data(lrec_reader_csv_state_t* pstate, slls_t* pdata_fields) {
|
||||
static lrec_t* paste_header_and_data(lrec_reader_csv_state_t* pstate, slls_t* pdata_fields, context_t* pctx) {
|
||||
if (pstate->pheader_keeper->pkeys->length != pdata_fields->length) {
|
||||
// xxx get the pctx->filename in there as well
|
||||
fprintf(stderr, "%s: Header/data length mismatch: %d != %d at line %lld.\n",
|
||||
MLR_GLOBALS.argv0, pstate->pheader_keeper->pkeys->length, pdata_fields->length, pstate->ilno);
|
||||
fprintf(stderr, "%s: Header/data length mismatch (%d != %d) at file \"%s\" line %lld.\n",
|
||||
MLR_GLOBALS.argv0, pstate->pheader_keeper->pkeys->length, pdata_fields->length,
|
||||
pctx->filename, pstate->ilno);
|
||||
exit(1);
|
||||
}
|
||||
lrec_t* prec = lrec_unbacked_alloc();
|
||||
sllse_t* ph = pstate->pheader_keeper->pkeys->phead;
|
||||
sllse_t* pd = pdata_fields->phead;
|
||||
for ( ; ph != NULL && pd != NULL; ph = ph->pnext, pd = pd->pnext) {
|
||||
// Need to deal with heap-fragmentation among other things ...
|
||||
// https://github.com/johnkerl/miller/issues/66
|
||||
//
|
||||
// lrec_put(prec, ph->value, pd->value, LREC_FREE_ENTRY_VALUE);
|
||||
lrec_put_no_free(prec, ph->value, pd->value);
|
||||
//lrec_put(prec, ph->value, pd->value, LREC_FREE_ENTRY_VALUE);
|
||||
}
|
||||
return prec;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ void sb_init(string_builder_t* psb, int alloc_length) {
|
|||
}
|
||||
psb->used_length = 0;
|
||||
psb->alloc_length = alloc_length;
|
||||
psb->buffer = mlr_malloc_or_die(alloc_length); // xxx malloc ...
|
||||
psb->buffer = mlr_malloc_or_die(alloc_length);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ static void mapper_filter_free(void* pvstate) {
|
|||
//hss_free(pstate->pevaluator);
|
||||
}
|
||||
|
||||
// xxx comment me ...
|
||||
static mapper_t* mapper_filter_alloc(mlr_dsl_ast_node_t* past) {
|
||||
mapper_filter_state_t* pstate = mlr_malloc_or_die(sizeof(mapper_filter_state_t));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
#include "lib/mlrutil.h"
|
||||
#include "containers/lrec.h"
|
||||
#include "containers/sllv.h"
|
||||
#include "containers/lhmsi.h"
|
||||
#include "containers/hss.h"
|
||||
#include "mapping/mappers.h"
|
||||
#include "cli/argparse.h"
|
||||
|
||||
typedef struct _mapper_having_fields_state_t {
|
||||
slls_t* pfield_names;
|
||||
lhmsi_t* pfield_name_set; // xxx make this a true set now that i wrote one :/ ;)
|
||||
int criterion;
|
||||
slls_t* pfield_names;
|
||||
hss_t* pfield_name_set;
|
||||
int criterion;
|
||||
} mapper_having_fields_state_t;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
|
@ -20,7 +20,7 @@ static sllv_t* mapper_having_fields_at_least_process(lrec_t* pinrec, context_t*
|
|||
mapper_having_fields_state_t* pstate = (mapper_having_fields_state_t*)pvstate;
|
||||
int num_found = 0;
|
||||
for (lrece_t* pe = pinrec->phead; pe != NULL; pe = pe->pnext) {
|
||||
if (lhmsi_has_key(pstate->pfield_name_set, pe->key)) {
|
||||
if (hss_has(pstate->pfield_name_set, pe->key)) {
|
||||
num_found++;
|
||||
if (num_found == pstate->pfield_name_set->num_occupied)
|
||||
return sllv_single(pinrec);
|
||||
|
|
@ -39,7 +39,7 @@ static sllv_t* mapper_having_fields_which_are_process(lrec_t* pinrec, context_t*
|
|||
return NULL;
|
||||
}
|
||||
for (lrece_t* pe = pinrec->phead; pe != NULL; pe = pe->pnext) {
|
||||
if (!lhmsi_has_key(pstate->pfield_name_set, pe->key)) {
|
||||
if (!hss_has(pstate->pfield_name_set, pe->key)) {
|
||||
lrec_free(pinrec);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ static sllv_t* mapper_having_fields_at_most_process(lrec_t* pinrec, context_t* p
|
|||
return sllv_single(NULL); // xxx cmt all of these, in all mappers
|
||||
mapper_having_fields_state_t* pstate = (mapper_having_fields_state_t*)pvstate;
|
||||
for (lrece_t* pe = pinrec->phead; pe != NULL; pe = pe->pnext) {
|
||||
if (!lhmsi_has_key(pstate->pfield_name_set, pe->key)) {
|
||||
if (!hss_has(pstate->pfield_name_set, pe->key)) {
|
||||
lrec_free(pinrec);
|
||||
return NULL; // xxx cmt all of these, in all mappers
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ static void mapper_having_fields_free(void* pvstate) {
|
|||
mapper_having_fields_state_t* pstate = (mapper_having_fields_state_t*)pvstate;
|
||||
if (pstate->pfield_names != NULL)
|
||||
slls_free(pstate->pfield_names);
|
||||
lhmsi_free(pstate->pfield_name_set);
|
||||
hss_free(pstate->pfield_name_set);
|
||||
}
|
||||
|
||||
static mapper_t* mapper_having_fields_alloc(slls_t* pfield_names, int criterion) {
|
||||
|
|
@ -74,9 +74,9 @@ static mapper_t* mapper_having_fields_alloc(slls_t* pfield_names, int criterion)
|
|||
|
||||
mapper_having_fields_state_t* pstate = mlr_malloc_or_die(sizeof(mapper_having_fields_state_t));
|
||||
pstate->pfield_names = pfield_names;
|
||||
pstate->pfield_name_set = lhmsi_alloc();
|
||||
pstate->pfield_name_set = hss_alloc();
|
||||
for (sllse_t* pe = pfield_names->phead; pe != NULL; pe = pe->pnext)
|
||||
lhmsi_put(pstate->pfield_name_set, pe->value, 0);
|
||||
hss_add(pstate->pfield_name_set, pe->value);
|
||||
pstate->criterion = criterion;
|
||||
|
||||
pmapper->pvstate = (void*)pstate;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue