| 135 | } |
| 136 | |
| 137 | static int compare_help(const jsmntok_t *const *a, |
| 138 | const jsmntok_t *const *b, |
| 139 | char *buffer) |
| 140 | { |
| 141 | const jsmntok_t *cat_a, *cat_b; |
| 142 | bool a_is_developer, b_is_developer; |
| 143 | int cmp; |
| 144 | |
| 145 | cat_a = json_get_member(buffer, *a, "category"); |
| 146 | cat_b = json_get_member(buffer, *b, "category"); |
| 147 | |
| 148 | /* Just in case it's an older lightningd! */ |
| 149 | if (!cat_a) |
| 150 | goto same_category; |
| 151 | |
| 152 | /* We always tweak "developer" category to last. */ |
| 153 | a_is_developer = json_tok_streq(buffer, cat_a, "developer"); |
| 154 | b_is_developer = json_tok_streq(buffer, cat_b, "developer"); |
| 155 | |
| 156 | if (a_is_developer && b_is_developer) |
| 157 | cmp = 0; |
| 158 | else if (a_is_developer) |
| 159 | cmp = 1; |
| 160 | else if (b_is_developer) |
| 161 | cmp = -1; |
| 162 | else |
| 163 | /* Otherwise we order category alphabetically. */ |
| 164 | cmp = compare_tok(cat_a, cat_b, buffer); |
| 165 | |
| 166 | if (cmp != 0) |
| 167 | return cmp; |
| 168 | |
| 169 | /* After category, we order by name */ |
| 170 | same_category: |
| 171 | return compare_tok(json_get_member(buffer, *a, "command"), |
| 172 | json_get_member(buffer, *b, "command"), |
| 173 | buffer); |
| 174 | } |
| 175 | |
| 176 | static void human_help(char *buffer, const jsmntok_t *result) |
| 177 | { |
nothing calls this directly
no test coverage detected