mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-20 18:10:07 +00:00
UDF iterate
This commit is contained in:
parent
a5082e1457
commit
4378317c28
3 changed files with 23 additions and 19 deletions
|
|
@ -582,7 +582,9 @@ static void main_usage_help_options(FILE* o, char* argv0) {
|
|||
}
|
||||
|
||||
static void main_usage_functions(FILE* o, char* argv0, char* leader) {
|
||||
rval_evaluator_list_functions(o, leader);
|
||||
fmgr_t* pfmgr = fmgr_alloc();
|
||||
fmgr_list_functions(pfmgr, o, leader);
|
||||
fmgr_free(pfmgr);
|
||||
fprintf(o, "Please use \"%s --help-function {function name}\" for function-specific help.\n", argv0);
|
||||
fprintf(o, "Please use \"%s --help-all-functions\" or \"%s -f\" for help on all functions.\n", argv0, argv0);
|
||||
fprintf(o, "Please use \"%s --help-all-keywords\" or \"%s -k\" for help on all keywords.\n", argv0, argv0);
|
||||
|
|
@ -1143,14 +1145,20 @@ static int handle_terminal_usage(char** argv, int argc, int argi) {
|
|||
return TRUE;
|
||||
|
||||
} else if (streq(argv[argi], "--list-all-functions-raw")) {
|
||||
rval_evaluator_list_all_functions_raw(stdout);
|
||||
fmgr_t* pfmgr = fmgr_alloc();
|
||||
fmgr_list_all_functions_raw(pfmgr, stdout);
|
||||
fmgr_free(pfmgr);
|
||||
return TRUE;
|
||||
} else if (streq(argv[argi], "--help-all-functions") || streq(argv[argi], "-f")) {
|
||||
rval_evaluator_function_usage(stdout, NULL);
|
||||
fmgr_t* pfmgr = fmgr_alloc();
|
||||
fmgr_function_usage(pfmgr, stdout, NULL);
|
||||
fmgr_free(pfmgr);
|
||||
return TRUE;
|
||||
} else if (streq(argv[argi], "--help-function") || streq(argv[argi], "--hf")) {
|
||||
check_arg_count(argv, argi, argc, 2);
|
||||
rval_evaluator_function_usage(stdout, argv[argi+1]);
|
||||
fmgr_t* pfmgr = fmgr_alloc();
|
||||
fmgr_function_usage(pfmgr, stdout, argv[argi+1]);
|
||||
fmgr_free(pfmgr);
|
||||
return TRUE;
|
||||
|
||||
} else if (streq(argv[argi], "--list-all-keywords-raw")) {
|
||||
|
|
|
|||
|
|
@ -25,19 +25,15 @@ static rval_evaluator_t* rval_evaluator_alloc_from_zary_func_name(char* function
|
|||
static rval_evaluator_t* rval_evaluator_alloc_from_unary_func_name(char* fnnm, rval_evaluator_t* parg1);
|
||||
|
||||
static rval_evaluator_t* rval_evaluator_alloc_from_binary_func_name(char* fnnm,
|
||||
|
||||
rval_evaluator_t* parg1, rval_evaluator_t* parg2);
|
||||
|
||||
static rval_evaluator_t* rval_evaluator_alloc_from_binary_regex_arg2_func_name(char* fnnm,
|
||||
|
||||
rval_evaluator_t* parg1, char* regex_string, int ignore_case);
|
||||
|
||||
static rval_evaluator_t* rval_evaluator_alloc_from_ternary_func_name(char* fnnm,
|
||||
|
||||
rval_evaluator_t* parg1, rval_evaluator_t* parg2, rval_evaluator_t* parg3);
|
||||
|
||||
static rval_evaluator_t* rval_evaluator_alloc_from_ternary_regex_arg2_func_name(char* fnnm,
|
||||
|
||||
rval_evaluator_t* parg1, char* regex_string, int ignore_case, rval_evaluator_t* parg3);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
|
@ -298,7 +294,7 @@ static char* function_class_to_desc(func_class_t function_class) {
|
|||
}
|
||||
}
|
||||
|
||||
void rval_evaluator_list_functions(FILE* o, char* leader) {
|
||||
void fmgr_list_functions(fmgr_t* pfmgr, FILE* output_stream, char* leader) {
|
||||
char* separator = " ";
|
||||
int leaderlen = strlen(leader);
|
||||
int separatorlen = strlen(separator);
|
||||
|
|
@ -306,28 +302,28 @@ void rval_evaluator_list_functions(FILE* o, char* leader) {
|
|||
int j = 0;
|
||||
|
||||
for (int i = 0; ; i++) {
|
||||
function_lookup_t* plookup = &FUNCTION_LOOKUP_TABLE[i];
|
||||
function_lookup_t* plookup = &FUNCTION_LOOKUP_TABLE[i]; // xxx rm global eveywhere
|
||||
char* fname = plookup->function_name;
|
||||
if (fname == NULL)
|
||||
break;
|
||||
int fnamelen = strlen(fname);
|
||||
linelen += separatorlen + fnamelen;
|
||||
if (linelen >= 80) {
|
||||
fprintf(o, "\n");
|
||||
fprintf(output_stream, "\n");
|
||||
linelen = 0;
|
||||
linelen = leaderlen + separatorlen + fnamelen;
|
||||
j = 0;
|
||||
}
|
||||
if (j == 0)
|
||||
fprintf(o, "%s", leader);
|
||||
fprintf(o, "%s%s", separator, fname);
|
||||
fprintf(output_stream, "%s", leader);
|
||||
fprintf(output_stream, "%s%s", separator, fname);
|
||||
j++;
|
||||
}
|
||||
fprintf(o, "\n");
|
||||
fprintf(output_stream, "\n");
|
||||
}
|
||||
|
||||
// Pass function_name == NULL to get usage for all functions.
|
||||
void rval_evaluator_function_usage(FILE* output_stream, char* function_name) {
|
||||
void fmgr_function_usage(fmgr_t* pfmgr, FILE* output_stream, char* function_name) {
|
||||
int found = FALSE;
|
||||
char* fmt = "%s (class=%s #args=%d): %s\n";
|
||||
|
||||
|
|
@ -355,7 +351,7 @@ void rval_evaluator_function_usage(FILE* output_stream, char* function_name) {
|
|||
}
|
||||
}
|
||||
|
||||
void rval_evaluator_list_all_functions_raw(FILE* output_stream) {
|
||||
void fmgr_list_all_functions_raw(fmgr_t* pfmgr, FILE* output_stream) {
|
||||
for (int i = 0; ; i++) {
|
||||
function_lookup_t* plookup = &FUNCTION_LOOKUP_TABLE[i];
|
||||
if (plookup->function_name == NULL) // end of table
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ void fmgr_install_UDF(fmgr_t* pfmgr, char* name, rval_evaluator_t* pevaluator);
|
|||
rval_evaluator_t* fmgr_alloc_evaluator(fmgr_t* pfmgr, char* name);
|
||||
|
||||
// xxx morph these into methods:
|
||||
void rval_evaluator_list_functions(FILE* output_stream, char* leader);
|
||||
void fmgr_list_functions(fmgr_t* pfmgr, FILE* output_stream, char* leader);
|
||||
// Pass function_name == NULL to get usage for all functions:
|
||||
void rval_evaluator_function_usage(FILE* output_stream, char* function_name);
|
||||
void rval_evaluator_list_all_functions_raw(FILE* output_stream);
|
||||
void fmgr_function_usage(fmgr_t* pfmgr, FILE* output_stream, char* function_name);
|
||||
void fmgr_list_all_functions_raw(fmgr_t* pfmgr, FILE* output_stream);
|
||||
void check_arity_with_report(function_lookup_t fcn_lookup_table[], char* function_name,
|
||||
int user_provided_arity);
|
||||
rval_evaluator_t* rval_evaluator_alloc_from_operator_or_function(mlr_dsl_ast_node_t* pnode,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue