aboutsummaryrefslogtreecommitdiffstats
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-24 02:20:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-24 02:20:10 +0000
commitacf7c0a6a045096335dc5626184b5d642f355466 (patch)
tree0a85d321952531f378984023c7929a5dfb073bda /ruby.c
parent3a41f293363dfd00c4e25dcbe416fef1e9091d46 (diff)
downloadruby-acf7c0a6a045096335dc5626184b5d642f355466.tar.gz
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
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/ruby.c b/ruby.c
index 6980e38522..cec83079be 100644
--- a/ruby.c
+++ b/ruby.c
@@ -131,6 +131,18 @@ static struct {
} 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)
{
/* This message really ought to be max 23 lines.
@@ -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)