usage_pod.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2009 Denys Vlasenko.
  4. *
  5. * Licensed under GPLv2, see file LICENSE in this source tree.
  6. */
  7. #include <unistd.h>
  8. #include <stdint.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include "autoconf.h"
  13. #define SKIP_applet_main
  14. #define ALIGN1 /* nothing, just to placate applet_tables.h */
  15. #define ALIGN2 /* nothing, just to placate applet_tables.h */
  16. #include "applet_tables.h"
  17. /* Since we can't use platform.h, have to do this again by hand: */
  18. #if ENABLE_NOMMU
  19. # define BB_MMU 0
  20. # define USE_FOR_NOMMU(...) __VA_ARGS__
  21. # define USE_FOR_MMU(...)
  22. #else
  23. # define BB_MMU 1
  24. # define USE_FOR_NOMMU(...)
  25. # define USE_FOR_MMU(...) __VA_ARGS__
  26. #endif
  27. #include "usage.h"
  28. #define MAKE_USAGE(aname, usage) { aname, usage },
  29. static struct usage_data {
  30. const char *aname;
  31. const char *usage;
  32. } usage_array[] = {
  33. #include "applets.h"
  34. };
  35. static int compare_func(const void *a, const void *b)
  36. {
  37. const struct usage_data *ua = a;
  38. const struct usage_data *ub = b;
  39. return strcmp(ua->aname, ub->aname);
  40. }
  41. int main(void)
  42. {
  43. int col, len2;
  44. int i;
  45. int num_messages = sizeof(usage_array) / sizeof(usage_array[0]);
  46. if (num_messages == 0)
  47. return 0;
  48. qsort(usage_array,
  49. num_messages, sizeof(usage_array[0]),
  50. compare_func);
  51. col = 0;
  52. for (i = 0; i < num_messages; i++) {
  53. len2 = strlen(usage_array[i].aname) + 2;
  54. if (col >= 76 - len2) {
  55. printf(",\n");
  56. col = 0;
  57. }
  58. if (col == 0) {
  59. col = 6;
  60. printf("\t");
  61. } else {
  62. printf(", ");
  63. }
  64. printf(usage_array[i].aname);
  65. col += len2;
  66. }
  67. printf("\n\n");
  68. printf("=head1 COMMAND DESCRIPTIONS\n\n");
  69. printf("=over 4\n\n");
  70. for (i = 0; i < num_messages; i++) {
  71. if (usage_array[i].aname[0] >= 'a' && usage_array[i].aname[0] <= 'z'
  72. && usage_array[i].usage[0] != NOUSAGE_STR[0]
  73. ) {
  74. printf("=item B<%s>\n\n", usage_array[i].aname);
  75. if (usage_array[i].usage[0])
  76. printf("%s %s\n\n", usage_array[i].aname, usage_array[i].usage);
  77. else
  78. printf("%s\n\n", usage_array[i].aname);
  79. }
  80. }
  81. printf("=back\n\n");
  82. return 0;
  83. }
  84. /* TODO: we used to make options bold with B<> and output an example too:
  85. =item B<cat>
  86. cat [B<-u>] [FILE]...
  87. Concatenate FILE(s) and print them to stdout
  88. Options:
  89. -u Use unbuffered i/o (ignored)
  90. Example:
  91. $ cat /proc/uptime
  92. 110716.72 17.67
  93. */