Lines 102-107
Link Here
|
102 |
INCREMENT is usually negative if FIRST is greater than LAST.\n\ |
102 |
INCREMENT is usually negative if FIRST is greater than LAST.\n\ |
103 |
When given, the FORMAT argument must contain exactly one of\n\ |
103 |
When given, the FORMAT argument must contain exactly one of\n\ |
104 |
the printf-style, floating point output formats %e, %f, %g\n\ |
104 |
the printf-style, floating point output formats %e, %f, %g\n\ |
|
|
105 |
or one of the printf-style, integer output formats %o, %x\n\ |
105 |
"), stdout); |
106 |
"), stdout); |
106 |
printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); |
107 |
printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); |
107 |
} |
108 |
} |
Lines 126-136
Link Here
|
126 |
} |
127 |
} |
127 |
|
128 |
|
128 |
/* Check whether the format string is valid for a single `double' |
129 |
/* Check whether the format string is valid for a single `double' |
129 |
argument. Return 0 if not, 1 if correct. */ |
130 |
argument. Return 0 if not, 1 if correct, 2 if a conversion |
|
|
131 |
to int is necessary. */ |
130 |
|
132 |
|
131 |
static int |
133 |
static int |
132 |
valid_format (const char *fmt) |
134 |
valid_format (const char *fmt) |
133 |
{ |
135 |
{ |
|
|
136 |
int end_return = 1; |
137 |
|
134 |
while (*fmt != '\0') |
138 |
while (*fmt != '\0') |
135 |
{ |
139 |
{ |
136 |
if (*fmt == '%') |
140 |
if (*fmt == '%') |
Lines 158-164
Link Here
|
158 |
} |
162 |
} |
159 |
|
163 |
|
160 |
if (!(*fmt == 'e' || *fmt == 'f' || *fmt == 'g')) |
164 |
if (!(*fmt == 'e' || *fmt == 'f' || *fmt == 'g')) |
161 |
return 0; |
165 |
{ |
|
|
166 |
end_return = 2; |
167 |
if (!(*fmt == 'o' || *fmt == 'x')) |
168 |
return 0; |
169 |
} |
162 |
|
170 |
|
163 |
fmt++; |
171 |
fmt++; |
164 |
while (*fmt != '\0') |
172 |
while (*fmt != '\0') |
Lines 173-185
Link Here
|
173 |
fmt++; |
181 |
fmt++; |
174 |
} |
182 |
} |
175 |
|
183 |
|
176 |
return 1; |
184 |
return end_return; |
177 |
} |
185 |
} |
178 |
|
186 |
|
179 |
/* Actually print the sequence of numbers in the specified range, with the |
187 |
/* Actually print the sequence of numbers in the specified range, with the |
180 |
given or default stepping and format. */ |
188 |
given or default stepping and format. */ |
181 |
static void |
189 |
static void |
182 |
print_numbers (const char *fmt) |
190 |
print_numbers (const char *fmt, int integerize) |
183 |
{ |
191 |
{ |
184 |
double i; |
192 |
double i; |
185 |
|
193 |
|
Lines 190-196
Link Here
|
190 |
break; |
198 |
break; |
191 |
if (i) |
199 |
if (i) |
192 |
fputs (separator, stdout); |
200 |
fputs (separator, stdout); |
193 |
printf (fmt, x); |
201 |
if (integerize) |
|
|
202 |
printf (fmt, (int) x); |
203 |
else |
204 |
printf (fmt, x); |
194 |
} |
205 |
} |
195 |
|
206 |
|
196 |
if (i) |
207 |
if (i) |
Lines 298-303
Link Here
|
298 |
main (int argc, char **argv) |
309 |
main (int argc, char **argv) |
299 |
{ |
310 |
{ |
300 |
int optc; |
311 |
int optc; |
|
|
312 |
int valid_return; |
301 |
int step_is_set; |
313 |
int step_is_set; |
302 |
|
314 |
|
303 |
/* The printf(3) format used for output. */ |
315 |
/* The printf(3) format used for output. */ |
Lines 383-389
Link Here
|
383 |
usage (EXIT_FAILURE); |
395 |
usage (EXIT_FAILURE); |
384 |
} |
396 |
} |
385 |
|
397 |
|
386 |
if (format_str && !valid_format (format_str)) |
398 |
if (format_str && !(valid_return = valid_format (format_str))) |
387 |
{ |
399 |
{ |
388 |
error (0, 0, _("invalid format string: `%s'"), format_str); |
400 |
error (0, 0, _("invalid format string: `%s'"), format_str); |
389 |
usage (EXIT_FAILURE); |
401 |
usage (EXIT_FAILURE); |
Lines 426-432
Link Here
|
426 |
format_str = "%g"; |
438 |
format_str = "%g"; |
427 |
} |
439 |
} |
428 |
|
440 |
|
429 |
print_numbers (format_str); |
441 |
print_numbers (format_str, valid_return - 1); |
430 |
|
442 |
|
431 |
exit (EXIT_SUCCESS); |
443 |
exit (EXIT_SUCCESS); |
432 |
} |
444 |
} |