-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwla_agent.c
146 lines (113 loc) · 4.15 KB
/
pwla_agent.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "pwla.h"
#include "ate_errors.h"
#include <stdio.h>
/**
* @brief Catalog of action implementations
*/
struct pwla_action_def pwla_actions[] = {
{"list_actions", "show list of available actions",
"ate list_actions",
pwla_list_actions },
{"show_action", "show usage information for a given action",
"ate show_action",
pwla_show_action },
{ "declare", "initialize a new handle",
"ate declare handle_name row_size [array_name]",
pwla_declare },
{ "append_data", "add data to the table",
"ate append_data handle_name [values ...]",
pwla_append_data },
{ "index_rows", "update index to table rows (after append_data)",
"ate index_rows handle_name",
pwla_index_rows },
{ "get_row_count", "get number of rows in the virtual table",
"ate get_row_count handle_name [-v result_name]",
pwla_get_row_count },
{ "get_row_size", "get number or elements in a virtual row",
"ate get_row_size handle_name [-v result_name]",
pwla_get_row_size },
{ "get_array_name", "get name of the hosted table array",
"ate get_array_name handle_name [-v result_name]",
pwla_get_array_name },
{ "get_field_sizes", "get table's max field sizes to an array",
"ate get_field_sizes handle_name [-a result_array_name]",
pwla_get_field_sizes },
{ "get_row", "get specified row's contents to an array",
"ate get_row handle_name row_number [-a result_array_name]",
pwla_get_row },
{ "put_row", "update a specified table row with an array's contents",
"ate put_row handle_name row_number array_name",
pwla_put_row },
{ "resize_rows", "change the number of elements in a virtual row",
"ate resize_rows handle_name new_row_size",
pwla_resize_rows },
{ "reindex_elements", "update the hosted array's contents to match index",
"ate reindex_elements handle_name",
pwla_reindex_elements },
{ "walk_rows", "invoke a callback with each of a table's rows",
"ate walk_rows handle_name function_name [-s start] [-c count] [extra ...]",
pwla_walk_rows },
{ "sort", "create a duplicate handle with a sorted order",
"ate sort handle_name comparison_function new_handle_name [extra ...]",
pwla_sort },
{ "filter", "create a duplicate handle with filtered contents",
"ate filter handle_name filter_function new_handle_name [extra ...]",
pwla_filter },
{ "make_key", "create an key handle linking strings to row indexes",
"ate make_key handle_name tag_function new_handle_name[extra ...]",
pwla_make_key },
{ "seek_key", "return key_handle row number of equal or greater key",
"ate seek_key handle_name target_value -p -s [-v value] [-t tally_name]",
pwla_seek_key }
};
/**
* @brief Calculated total of catalog implementation entries.
*/
int pwla_action_count = sizeof(pwla_actions) / sizeof(struct pwla_action_def);
/**
* @brief Show simple list of action names
* @param "alist" Stack-based simple linked list of argument values
* @return EXECUTION_SUCCESS or one of the failure codes
*/
int pwla_list_actions(ARG_LIST *alist)
{
struct pwla_action_def *ptr = pwla_actions;
struct pwla_action_def *end = ptr + pwla_action_count;
while (ptr < end)
{
printf("%s\n", ptr->name);
++ptr;
}
printf("\n");
return EXECUTION_SUCCESS;
}
/**
* @brief Show usage for one or all of the catalog entries
* @param "alist" Stack-based simple linked list of argument values
* @return EXECUTION_SUCCESS or one of the failure codes
*/
int pwla_show_action(ARG_LIST *alist)
{
const char *desired_action = NULL;
ARG_TARGET filter_targets[] = {
{ "action_name", AL_ARG, &desired_action },
{ NULL }
};
int retval;
if ((retval = process_word_list_args(filter_targets, alist, 0)))
goto early_exit;
struct pwla_action_def *ptr = pwla_actions;
struct pwla_action_def *end = ptr + pwla_action_count;
while (ptr < end)
{
if (!desired_action || 0 == strcmp(ptr->name, desired_action))
{
printf("\n%s: %s\n", ptr->name, ptr->desc);
printf(" %s\n", ptr->usage);
}
++ptr;
}
printf("\n");
early_exit:
return retval;
}