Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. diff --git a/main.c b/main.c
  2. index 3f564e7..af8f178 100644
  3. --- a/main.c
  4. +++ b/main.c
  5. @@ -687,38 +687,63 @@ static void prepend_mocp_opts (poptContext ctx)
  6. }
  7. }
  8.  
  9. +static const struct poptOption specials[] = {POPT_AUTOHELP
  10. + POPT_AUTOALIAS
  11. + POPT_TABLEEND};
  12. +
  13. +/* Return true iff 'opt' is a POPT AutoHelp option. */
  14. +static inline bool is_autohelp (const struct poptOption *opt)
  15. +{
  16. + const struct poptOption *autohelp = &specials[0];
  17. +
  18. + return opt->argInfo == autohelp->argInfo && opt->arg == autohelp->arg;
  19. +}
  20. +
  21. +/* Return true iff 'opt' is a POPT AutoAlias option. */
  22. +static inline bool is_autoalias (const struct poptOption *opt)
  23. +{
  24. + const struct poptOption *autoalias = &specials[1];
  25. +
  26. + return opt->argInfo == autoalias->argInfo && opt->arg == autoalias->arg;
  27. +}
  28. +
  29. +/* Return true iff 'opt' is the POPT end-of-table marker. */
  30. +static inline bool is_tableend (const struct poptOption *opt)
  31. +{
  32. + const struct poptOption *tableend = &specials[2];
  33. +
  34. + return opt->longName == tableend->longName &&
  35. + opt->shortName == tableend->shortName &&
  36. + opt->arg == tableend->arg;
  37. +}
  38. +
  39. /* Return a copy of the POPT option table structure which is suitable
  40. * for rendering the POPT expansions of the command line. */
  41. #ifndef OPENWRT
  42. struct poptOption *clone_popt_options (struct poptOption *opts)
  43. {
  44. - size_t count, ix, iy = 0;
  45. + size_t tally, ix, iy = 0;
  46. struct poptOption *result;
  47. - const struct poptOption specials[] = {POPT_AUTOHELP
  48. - POPT_AUTOALIAS
  49. - POPT_TABLEEND};
  50.  
  51. assert (opts);
  52.  
  53. - for (count = 1;
  54. - memcmp (&opts[count - 1], &specials[2], sizeof (struct poptOption));
  55. - count += 1);
  56. + for (tally = 1; !is_tableend (&opts[tally - 1]); tally += 1);
  57.  
  58. - result = xcalloc (count, sizeof (struct poptOption));
  59. + result = xcalloc (tally, sizeof (struct poptOption));
  60.  
  61. - for (ix = 0; ix < count; ix += 1) {
  62. + for (ix = 0; ix < tally; ix += 1) {
  63. if (opts[ix].argInfo == POPT_ARG_CALLBACK)
  64. continue;
  65.  
  66. - if (!memcmp (&opts[ix], &specials[0], sizeof (struct poptOption)))
  67. + if (is_autohelp (&opts[ix]))
  68. continue;
  69.  
  70. - if (!memcmp (&opts[ix], &specials[1], sizeof (struct poptOption)))
  71. + if (is_autoalias (&opts[ix]))
  72. continue;
  73.  
  74. memcpy (&result[iy], &opts[ix], sizeof (struct poptOption));
  75.  
  76. - if (!memcmp (&opts[ix], &specials[2], sizeof (struct poptOption)))
  77. + if (is_tableend (&opts[ix]))
  78. continue;
  79.  
  80. if (opts[ix].argInfo == POPT_ARG_INCLUDE_TABLE) {
  81. @@ -757,11 +782,10 @@ struct poptOption *clone_popt_options (struct poptOption *opts)
  82. void free_popt_clone (struct poptOption *opts)
  83. {
  84. int ix;
  85. - const struct poptOption table_end = POPT_TABLEEND;
  86.  
  87. assert (opts);
  88.  
  89. - for (ix = 0; memcmp (&opts[ix], &table_end, sizeof (table_end)); ix += 1) {
  90. + for (ix = 0; !is_tableend (&opts[ix]); ix += 1) {
  91. if (opts[ix].argInfo == POPT_ARG_INCLUDE_TABLE)
  92. free_popt_clone (opts[ix].arg);
  93. }
  94. @@ -776,7 +800,6 @@ void free_popt_clone (struct poptOption *opts)
  95. struct poptOption *find_popt_option (struct poptOption *opts, int wanted)
  96. {
  97. int ix = 0;
  98. - const struct poptOption table_end = POPT_TABLEEND;
  99.  
  100. assert (opts);
  101. assert (LIMIT(wanted, popt_next_val));
  102. @@ -784,7 +807,7 @@ struct poptOption *find_popt_option (struct poptOption *opts, int wanted)
  103. while (1) {
  104. struct poptOption *result;
  105.  
  106. - if (!memcmp (&opts[ix], &table_end, sizeof (table_end)))
  107. + if (is_tableend (&opts[ix]))
  108. break;
  109.  
  110. assert (opts[ix].argInfo != POPT_ARG_CALLBACK);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement