You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
4.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* source: xiohelp.c */
  2. /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
  3. /* Published under the GNU General Public License V.2, see file COPYING */
  4. /* this file contains the source for the help function */
  5. #include "xiosysincludes.h"
  6. #include "xioopen.h"
  7. #include "xiohelp.h"
  8. #if WITH_HELP
  9. /* keep consistent with xioopts.h:enum e_types ! */
  10. static const char *optiontypenames[] = {
  11. "CONST", "BIN", "BOOL", "BYTE",
  12. "INT", "LONG", "STRING", "PTRDIFF",
  13. "SHORT", "SIZE_T", "SOCKADDR", "UNSIGNED-INT",
  14. "UNSIGNED-LONG","UNSIGNED-SHORT","MODE_T", "GID_T",
  15. "UID_T", "INT[3]", "STRUCT-TIMEVAL", "STRUCT-TIMESPEC",
  16. "DOUBLE", "STRING-NULL", "LONG-LONG", "OFF_T",
  17. "OFF64_T", "INT:INT", "INT:INTP", "INT:BIN",
  18. "INT:STRING", "INT:INT:INT", "INT:INT:BIN", "INT:INT:STRING",
  19. "IP4NAME",
  20. #if HAVE_STRUCT_LINGER
  21. "STRUCT-LINGER",
  22. #endif
  23. #if HAVE_STRUCT_IP_MREQN
  24. "STRUCT-IP_MREQN",
  25. #elif HAVE_STRUCT_IP_MREQ
  26. "STRUCT-IP_MREQ",
  27. #endif
  28. } ;
  29. /* keep consistent with xioopts.h:#define GROUP_* ! */
  30. static const char *addressgroupnames[] = {
  31. "FD", "FIFO", "CHR", "BLK",
  32. "REG", "SOCKET", "READLINE", "undef",
  33. "NAMED", "OPEN", "EXEC", "FORK",
  34. "LISTEN", "DEVICE", "CHILD", "RETRY",
  35. "TERMIOS", "RANGE", "PTY", "PARENT",
  36. "UNIX", "IP4", "IP6", "INTERFACE",
  37. "UDP", "TCP", "SOCKS4", "OPENSSL",
  38. "PROCESS", "APPL", "HTTP", "SCTP"
  39. } ;
  40. /* keep consistent with xioopts.h:enum ephase ! */
  41. static char *optionphasenames[] = {
  42. "ALL", "INIT", "EARLY",
  43. "PREOPEN", "OPEN", "PASTOPEN",
  44. "PRESOCKET", "SOCKET", "PASTSOCKET",
  45. "PREBIGEN", "BIGEN", "PASTBIGEN",
  46. "FD",
  47. "PREBIND", "BIND", "PASTBIND",
  48. "PRELISTEN", "LISTEN", "PASTLISTEN",
  49. "PRECONNECT", "CONNECT", "PASTCONNECT",
  50. "PREACCEPT", "ACCEPT", "PASTACCEPT",
  51. "CONNECTED",
  52. "PREFORK", "FORK", "PASTFORK",
  53. "LATE", "LATE2",
  54. "PREEXEC", "EXEC", "SPECIFIC",
  55. NULL
  56. } ;
  57. /* print a line about a single option */
  58. static int xiohelp_option(FILE *of, const struct optname *on, const char *name) {
  59. int j;
  60. unsigned int groups;
  61. bool occurred;
  62. fprintf(of, " %s\tgroups=", name);
  63. groups = on->desc->group; occurred = false;
  64. for (j = 0; j < 32; ++j) {
  65. if (groups & 1) {
  66. if (occurred) { fputc(',', of); }
  67. fprintf(of, "%s", addressgroupnames[j]);
  68. occurred = true;
  69. }
  70. groups >>= 1;
  71. }
  72. fprintf(of, "\tphase=%s", optionphasenames[on->desc->phase]);
  73. fprintf(of, "\ttype=%s", optiontypenames[on->desc->type]);
  74. fputc('\n', of);
  75. return 0;
  76. }
  77. int xioopenhelp(FILE *of,
  78. int level /* 0..only addresses, 1..and options */
  79. ) {
  80. const struct addrname *an;
  81. const struct optname *on;
  82. int i, j;
  83. unsigned int groups;
  84. bool occurred;
  85. fputs(" bi-address:\n", of);
  86. fputs(" pipe[,<opts>]\tgroups=FD,FIFO\n", of);
  87. if (level == 2) {
  88. fputs(" echo is an alias for pipe\n", of);
  89. fputs(" fifo is an alias for pipe\n", of);
  90. }
  91. fputs(" <single-address>!!<single-address>\n", of);
  92. fputs(" <single-address>\n", of);
  93. fputs(" single-address:\n", of);
  94. fputs(" <address-head>[,<opts>]\n", of);
  95. fputs(" address-head:\n", of);
  96. an = &addressnames[0];
  97. i = 0;
  98. while (addressnames[i].name) {
  99. if (!strcmp(an->name, an->desc->defname)) {
  100. /* it is a canonical address name */
  101. fprintf(of, " %s", an->name);
  102. if (an->desc->syntax) {
  103. fputs(an->desc->syntax, of); }
  104. fputs("\tgroups=", of);
  105. groups = an->desc->groups; occurred = false;
  106. for (j = 0; j < 32; ++j) {
  107. if (groups & 1) {
  108. if (occurred) { fputc(',', of); }
  109. fprintf(of, "%s", addressgroupnames[j]);
  110. occurred = true;
  111. }
  112. groups >>= 1;
  113. }
  114. fputc('\n', of);
  115. } else if (level == 2) {
  116. fprintf(of, " %s is an alias name for %s\n", an->name, an->desc->defname);
  117. }
  118. ++an; ++i;
  119. }
  120. if (level == 2) {
  121. fputs(" <num> is a short form for fd:<num>\n", of);
  122. fputs(" <filename> is a short form for gopen:<filename>\n", of);
  123. }
  124. if (level <= 0) return 0;
  125. fputs(" opts:\n", of);
  126. fputs(" <opt>{,<opts>}:\n", of);
  127. fputs(" opt:\n", of);
  128. on = optionnames;
  129. while (on->name != NULL) {
  130. if (on->desc->nickname!= NULL
  131. && !strcmp(on->name, on->desc->nickname)) {
  132. if (level == 2) {
  133. fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname);
  134. } else {
  135. xiohelp_option(of, on, on->name);
  136. }
  137. } else if (on->desc->nickname == NULL &&
  138. !strcmp(on->name, on->desc->defname)) {
  139. xiohelp_option(of, on, on->name);
  140. } else if (level == 2) {
  141. if (!strcmp(on->name, on->desc->defname)) {
  142. xiohelp_option(of, on, on->name);
  143. } else {
  144. fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname);
  145. }
  146. }
  147. ++on;
  148. }
  149. fflush(of);
  150. return 0;
  151. }
  152. #endif /* WITH_HELP */