display.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, 2009, Free Software
  3. Foundation, Inc.
  4. The GNU plotutils package is free software. You may redistribute it
  5. and/or modify it under the terms of the GNU General Public License as
  6. published by the Free Software foundation; either version 2, or (at your
  7. option) any later version.
  8. The GNU plotutils package is distributed in the hope that it will be
  9. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with the GNU plotutils package; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. /* This file contains the display_usage routine, which is used in
  17. user-level programs in the plotutils package. It prints program options
  18. and long options in a reasonably nice format.
  19. This file also contains the display_version routine. */
  20. #include "libcommon.h"
  21. #include "getopt.h"
  22. /* global array of long options, in program we're to be linked with */
  23. extern struct option long_options[];
  24. #define ARG_NONE 0
  25. #define ARG_REQUIRED 1
  26. #define ARG_OPTIONAL 2
  27. /* forward references */
  28. bool elementp (int item, const int *list);
  29. void display_usage (const char *progname, const int *omit_vals, const char *appendage, int info);
  30. void display_version (const char *progname, const char *written, const char *copyright);
  31. /* ARGS: list = null-terminated list of integers */
  32. bool
  33. elementp (int item, const int *list)
  34. {
  35. int list_item;
  36. while ((list_item = *list++) != 0)
  37. {
  38. if (item == list_item)
  39. return true;
  40. }
  41. return false;
  42. }
  43. /* final arg of display_usage below is 0/1/2, meaning:
  44. 0. Print no info on output formats, because it is not relevant.
  45. (This is used by `spline' and `ode'.)
  46. 1. Print info on output formats, specified by a `-T format' option,
  47. but not on the existence of a `--help-fonts' option, which returns
  48. info specific to the choice of an output format.
  49. (This is used by `hersheydemo', which has a -T option but
  50. no user-specified fonts.)
  51. 2. Print info on output formats, specified by a `-T format' option,
  52. and also on the existence of a `--help-fonts' option, which returns
  53. info on fonts that is specific to the choice of an output format.
  54. (This is used by `graph', `plot', 'tek2plot', `plotfont'.)
  55. */
  56. void
  57. display_usage (const char *progname, const int *omit_vals, const char *appendage, int info)
  58. {
  59. int i;
  60. int col = 0;
  61. fprintf (stdout, "Usage: %s", progname);
  62. col += (strlen (progname) + 7);
  63. for (i = 0; long_options[i].name; i++)
  64. {
  65. int option_len;
  66. if (elementp (long_options[i].val, omit_vals))
  67. continue;
  68. option_len = strlen (long_options[i].name);
  69. if (col >= 80 - (option_len + 16))
  70. {
  71. fputs ("\n\t", stdout);
  72. col = 8;
  73. }
  74. fprintf (stdout, " [--%s", long_options[i].name);
  75. col += (option_len + 4);
  76. if ((unsigned int)(long_options[i].val) < 256)
  77. {
  78. fprintf (stdout, " | -%c", long_options[i].val);
  79. col += 5;
  80. }
  81. if (long_options[i].has_arg == ARG_REQUIRED)
  82. {
  83. fputs (" arg]", stdout);
  84. col += 5;
  85. }
  86. else if (long_options[i].has_arg == ARG_OPTIONAL)
  87. {
  88. fputs (" [arg(s)]]", stdout);
  89. col += 10;
  90. }
  91. else
  92. {
  93. fputs ("]", stdout);
  94. col++;
  95. }
  96. }
  97. if (appendage != NULL)
  98. fputs (appendage, stdout);
  99. else
  100. fputs ("\n", stdout);
  101. if (info == 1)
  102. {
  103. fprintf (stdout, "\n\
  104. To specify an output format, type `%s -T \"format\"',\n\
  105. where \"format\" is one of:\n", progname);
  106. }
  107. else if (info == 2)
  108. {
  109. fprintf (stdout, "\n\
  110. To list available fonts, type `%s -T \"format\" --help-fonts',\n\
  111. where \"format\" is the output format, and is one of:\n", progname);
  112. }
  113. if (info == 1 || info == 2)
  114. {
  115. #ifdef INCLUDE_PNG_SUPPORT
  116. #ifndef X_DISPLAY_MISSING
  117. fprintf (stdout, "\
  118. X, png, pnm, or gif (bitmap formats), or\n\
  119. svg, ps, ai, cgm, fig, pcl, hpgl, regis, or tek (vector formats).\n");
  120. #else /* X_DISPLAY_MISSING */
  121. fprintf (stdout, "\
  122. png, pnm, or gif (bitmap formats), or\n\
  123. svg, ps, ai, cgm, fig, pcl, hpgl, regis, or tek (vector formats).\n");
  124. #endif /* X_DISPLAY_MISSING */
  125. #else /* not INCLUDE_PNG_SUPPORT */
  126. #ifndef X_DISPLAY_MISSING
  127. fprintf (stdout, "\
  128. X, pnm, or gif (bitmap formats), or\n\
  129. svg, ps, ai, cgm, fig, pcl, hpgl, regis, or tek (vector formats).\n");
  130. #else /* X_DISPLAY_MISSING */
  131. fprintf (stdout, "\
  132. pnm or gif (bitmap formats), or\n\
  133. svg, ps, ai, cgm, fig, pcl, hpgl, regis, or tek (vector formats).\n");
  134. #endif /* X_DISPLAY_MISSING */
  135. #endif
  136. fprintf (stdout, "\
  137. The default format is \"meta\", which is probably not what you want.\n");
  138. }
  139. if ((appendage != NULL) || info == 1 || info == 2)
  140. fputs ("\n", stdout);
  141. fprintf (stdout, "\
  142. Report bugs to %s.\n", PACKAGE_BUGREPORT);
  143. }
  144. void
  145. display_version (const char *progname, const char *written, const char *copyright)
  146. {
  147. fprintf (stdout, "%s (%s) %s\n",
  148. progname, PACKAGE_NAME, PACKAGE_VERSION);
  149. fprintf (stdout, "%s\n",
  150. copyright);
  151. fprintf (stdout, "%s",
  152. "This is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
  153. fprintf (stdout, "%s\n",
  154. written);
  155. }