}
static void
-export_value(struct list_head *matches, const char *prefix, const char *sep)
+export_value(struct list_head *matches, const char *prefix, const char *sep,
+ int limit)
{
int n, len;
int sc = 0, sl = strlen(sep);
list_for_each_entry(item, matches, list)
{
+ if (limit-- <= 0)
+ break;
+
switch (json_object_get_type(item->jsobj))
{
case json_type_object:
{
list_for_each_entry(item, matches, list)
{
+ if (limit-- <= 0)
+ break;
+
switch (json_object_get_type(item->jsobj))
{
case json_type_object:
}
static void
-export_type(struct list_head *matches, const char *prefix)
+export_type(struct list_head *matches, const char *prefix, int limit)
{
bool first = true;
struct match_item *item;
if (!first)
printf("\\ ");
+ if (limit-- <= 0)
+ break;
+
printf("%s", types[json_object_get_type(item->jsobj)]);
first = false;
}
}
static bool
-filter_json(int opt, struct json_object *jsobj, char *expr, const char *sep)
+filter_json(int opt, struct json_object *jsobj, char *expr, const char *sep,
+ int limit)
{
struct jp_state *state;
const char *prefix = NULL;
switch (opt)
{
case 't':
- export_type(&matches, prefix);
+ export_type(&matches, prefix, limit);
break;
default:
- export_value(&matches, prefix, sep);
+ export_value(&matches, prefix, sep, limit);
break;
}
int main(int argc, char **argv)
{
- int opt, rv = 0;
+ int opt, rv = 0, limit = 0x7FFFFFFF;
FILE *input = stdin;
struct json_object *jsobj = NULL;
const char *jserr = NULL, *source = NULL, *separator = " ";
- while ((opt = getopt(argc, argv, "i:s:e:t:F:q")) != -1)
+ while ((opt = getopt(argc, argv, "i:s:e:t:F:l:q")) != -1)
{
switch (opt)
{
separator = optarg;
break;
+ case 'l':
+ limit = atoi(optarg);
+ break;
+
case 't':
case 'e':
if (!jsobj)
}
}
- if (!filter_json(opt, jsobj, optarg, separator))
+ if (!filter_json(opt, jsobj, optarg, separator, limit))
rv = 1;
break;