This constructs a string that represents all the options set for either * the --info or --debug setting, skipping any implied options (by -v, etc.). * This is used both when conveying the user's options to the server, and * when the help output wants to tell the user what options are implied. */
| 352 | * This is used both when conveying the user's options to the server, and |
| 353 | * when the help output wants to tell the user what options are implied. */ |
| 354 | static char *make_output_option(struct output_struct *words, short *levels, uchar where) |
| 355 | { |
| 356 | char *str = words == info_words ? "--info=" : "--debug="; |
| 357 | int j, counts[MAX_OUT_LEVEL+1], pos, skipped = 0, len = 0, max = 0, lev = 0; |
| 358 | int word_count = words == info_words ? COUNT_INFO : COUNT_DEBUG; |
| 359 | char *buf; |
| 360 | |
| 361 | memset(counts, 0, sizeof counts); |
| 362 | |
| 363 | for (j = 0; words[j].name; j++) { |
| 364 | if (words[j].flag != j) { |
| 365 | rprintf(FERROR, "rsync: internal error on %s%s: %d != %d\n", |
| 366 | words == info_words ? "INFO_" : "DEBUG_", |
| 367 | words[j].name, words[j].flag, j); |
| 368 | exit_cleanup(RERR_UNSUPPORTED); |
| 369 | } |
| 370 | if (!(words[j].where & where)) |
| 371 | continue; |
| 372 | if (words[j].priority == DEFAULT_PRIORITY) { |
| 373 | /* Implied items don't need to be mentioned. */ |
| 374 | skipped++; |
| 375 | continue; |
| 376 | } |
| 377 | len += len ? 1 : strlen(str); |
| 378 | len += strlen(words[j].name); |
| 379 | len += levels[j] == 1 ? 0 : 1; |
| 380 | |
| 381 | if (words[j].priority == HELP_PRIORITY) |
| 382 | continue; /* no abbreviating for help */ |
| 383 | |
| 384 | assert(levels[j] <= MAX_OUT_LEVEL); |
| 385 | if (++counts[levels[j]] > max) { |
| 386 | /* Determine which level has the most items. */ |
| 387 | lev = levels[j]; |
| 388 | max = counts[lev]; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /* Sanity check the COUNT_* define against the length of the table. */ |
| 393 | if (j != word_count) { |
| 394 | rprintf(FERROR, "rsync: internal error: %s is wrong! (%d != %d)\n", |
| 395 | words == info_words ? "COUNT_INFO" : "COUNT_DEBUG", |
| 396 | j, word_count); |
| 397 | exit_cleanup(RERR_UNSUPPORTED); |
| 398 | } |
| 399 | |
| 400 | if (!len) |
| 401 | return NULL; |
| 402 | |
| 403 | len++; |
| 404 | buf = new_array(char, len); |
| 405 | pos = 0; |
| 406 | |
| 407 | if (skipped || max < 5) |
| 408 | lev = -1; |
| 409 | else { |
| 410 | if (lev == 0) |
| 411 | pos += snprintf(buf, len, "%sNONE", str); |
no test coverage detected