struct kcs_sm_op *config_parser_setup_mod(struct katcp_dispatch *d, struct kcs_sm_state *s) { struct kcs_sm_op *op; op = create_sm_op_kcs(&config_parser_mod, NULL); if (op == NULL) return NULL; #ifdef DEBUG fprintf(stderr, "mod_config_parser: created op %s (%p)\n", KATCP_OPERATION_CONF_PARSE, op); #endif return op; }
struct kcs_sm_op *spawn_setup_statemachine_kcs(struct katcp_dispatch *d, struct kcs_sm_state *s) { struct katcp_tobject *o; char *node, *str[2]; node = arg_string_katcp(d, 4); if (node == NULL) return NULL; str[0] = node; str[1] = NULL; o = create_named_tobject_katcp(d, parse_string_type_katcp(d, str), KATCP_TYPE_STRING, 1); if (o == NULL) return NULL; return create_sm_op_kcs(&spawn_statemachine_kcs, o); }
int parse_csv_mod(struct katcp_dispatch *d, struct katcp_stack *stack, struct katcp_tobject *o) { #if 0 struct config_setting *cs; #endif struct katcp_type *strtype; char *str, c, *temp[2]; int len, pos, i, count; void *data; strtype = find_name_type_katcp(d, KATCP_TYPE_STRING); if (strtype == NULL || strtype->t_parse == NULL) return -1; #if 0 cs = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_CONFIG_SETTING); if (cs == NULL) return -1; #endif str = pop_data_type_stack_katcp(stack, strtype); if (str == NULL) return -1; len = strlen(str); pos = 0; temp[1] = NULL; count = 0; for (i=0; i<=len; i++){ c = str[i]; switch(c){ case EOL: case CR: case LF: case VALUE: temp[0] = strndup(str + pos, i-pos); if (temp[0] != NULL){ #ifdef DEBUG fprintf(stderr, "csv: <%s>\n", temp[0]); #endif data = search_type_katcp(d, strtype, temp[0], (*strtype->t_parse)(d, temp)); #if 0 if (push_named_stack_katcp(d, stack, data, KATCP_TYPE_STRING) < 0){ #endif if (push_stack_katcp(stack, data, strtype) < 0){ #ifdef DEBUG fprintf(stderr, "csv: push named stack katcp error\n"); #endif } count++; free(temp[0]); } pos = i+1; break; } } #if 0 if (count > 1){ inttype = find_name_type_katcp(d, KATCP_TYPE_INTEGER); if (inttype == NULL || inttype->t_getkey == NULL) return -1; data = create_integer_type_kcs(count); if (data == NULL) return -1; str = (*inttype->t_getkey)(data); if (str == NULL) return -1; #ifdef DEBUG fprintf(stderr, "csv: <%s>\n", str); #endif data = search_type_katcp(d, inttype, str, data); push_named_stack_katcp(d, stack, data, KATCP_TYPE_INTEGER); free(str); } #endif return 0; } struct kcs_sm_op *parse_csv_setup_mod(struct katcp_dispatch *d, struct kcs_sm_state *s) { return create_sm_op_kcs(&parse_csv_mod, NULL); } #if 0 struct config_setting *search_config_settings_mod(struct katcp_dispatch *d, void *data) { char *str; str = data; return get_key_data_type_katcp(d, KATCP_TYPE_CONFIG_SETTING, str); }
struct kcs_sm_op *get_values_setup_dbase_katcp(struct katcp_dispatch *d, struct kcs_sm_state *s) { return create_sm_op_kcs(&get_values_dbase_katcp, NULL); }
struct kcs_sm_op *print_stack_setup_statemachine_kcs(struct katcp_dispatch *d, struct kcs_sm_state *s) { return create_sm_op_kcs(&print_stack_statemachine_kcs, NULL); }
struct kcs_sm_op *pushstack_setup_statemachine_kcs(struct katcp_dispatch *d, struct kcs_sm_state *s) { #define ARG_BASE 5 struct katcp_type *t; struct katcp_tobject *o; struct kcs_sm_op *op; char **data, *type; void *ptemp, *stemp; int num, i; stemp = NULL; type = arg_string_katcp(d, 4); if (type == NULL || s == NULL) return NULL; t = find_name_type_katcp(d, type); if (t == NULL){ log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "invalid type: %s\n", type); return NULL; } num = arg_count_katcp(d) - ARG_BASE; data = malloc(sizeof(char *) * (num + 1)); if (data == NULL) return NULL; for (i=0; i<num; i++){ data[i] = arg_string_katcp(d, ARG_BASE + i); #ifdef DEBUG fprintf(stderr, "statemachine: pushsetup data[%d of %d]: %s\n", i+1, num, data[i]); #endif } data[num] = NULL; #ifdef DEBUG fprintf(stderr, "statemachine: call type parse function\n"); #endif ptemp = (*t->t_parse)(d, data); if (data[0] != NULL) stemp = search_type_katcp(d, t, data[0], ptemp); free(data); if (ptemp == NULL){ #ifdef DEBUG fprintf(stderr, "statemachine: type parse fn failed\n"); #endif //return NULL; } if (stemp == NULL){ #ifdef DEBUG fprintf(stderr, "statemachine: type search fn failed\n"); #endif (*t->t_free)(ptemp); return NULL; } o = create_tobject_katcp(stemp, t, 0); if (o == NULL){ (*t->t_free)(stemp); #ifdef DEBUG fprintf(stderr, "statemachine: pushsetup could not create stack obj\n"); #endif return NULL; } op = create_sm_op_kcs(&pushstack_statemachine_kcs, o); if (op == NULL){ (*t->t_free)(stemp); destroy_tobject_katcp(o); return NULL; } #ifdef DEBUG fprintf(stderr, "statemachine: pushsetup created op (%p)\n", op); #endif return op; #undef ARG_BASE }