mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ruby.c: show_usage_line
* ruby.c (show_usage_line): extract function to print one usage line. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3de8b4bed1
commit
e28addcf5b
1 changed files with 15 additions and 9 deletions
24
ruby.c
24
ruby.c
|
@ -130,6 +130,18 @@ static struct {
|
|||
char **argv;
|
||||
} origarg;
|
||||
|
||||
static void
|
||||
show_usage_line(const char *str, unsigned int namelen, unsigned int secondlen, int help)
|
||||
{
|
||||
const unsigned int w = 16;
|
||||
const int wrap = help && namelen + secondlen - 2 > w;
|
||||
printf(" %.*s%-*.*s%-*s%s\n", namelen-1, str,
|
||||
(wrap ? 0 : w - namelen + 1),
|
||||
(help ? secondlen-1 : 0), str + namelen,
|
||||
(wrap ? w + 3 : 0), (wrap ? "\n" : ""),
|
||||
str + namelen + secondlen);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(const char *name, int help)
|
||||
{
|
||||
|
@ -182,15 +194,9 @@ usage(const char *name, int help)
|
|||
M("gems", "", "rubygems (default: "DEFAULT_RUBYGEMS_ENABLED")"),
|
||||
M("rubyopt", "", "RUBYOPT environment variable (default: enabled)"),
|
||||
};
|
||||
int i, w = 16, num = numberof(usage_msg) - (help ? 1 : 0);
|
||||
#define SHOW(m) do { \
|
||||
int wrap = help && (m).namelen + (m).secondlen - 2 > w; \
|
||||
printf(" %.*s%-*.*s%-*s%s\n", (m).namelen-1, (m).str, \
|
||||
(wrap ? 0 : w - (m).namelen + 1), \
|
||||
(help ? (m).secondlen-1 : 0), (m).str + (m).namelen, \
|
||||
(wrap ? w + 3 : 0), (wrap ? "\n" : ""), \
|
||||
(m).str + (m).namelen + (m).secondlen); \
|
||||
} while (0)
|
||||
int i;
|
||||
const int num = numberof(usage_msg) - (help ? 1 : 0);
|
||||
#define SHOW(m) show_usage_line((m).str, (m).namelen, (m).secondlen, help)
|
||||
|
||||
printf("Usage: %s [switches] [--] [programfile] [arguments]\n", name);
|
||||
for (i = 0; i < num; ++i)
|
||||
|
|
Loading…
Reference in a new issue