summaryrefslogtreecommitdiff
path: root/usr.bin/seq
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
commit98e0ffaefb0f241cda3a72395d3be04192ae0d47 (patch)
tree55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /usr.bin/seq
parentb17ff922d4072ae132ece458f5b5d74a236880ac (diff)
parente81032ad243db32b8fd615b2d55ee94b9f6a5b6a (diff)
downloadsrc-test-98e0ffaefb0f241cda3a72395d3be04192ae0d47.tar.gz
src-test-98e0ffaefb0f241cda3a72395d3be04192ae0d47.zip
Merge sync of head
Notes
Notes: svn path=/projects/bmake/; revision=283595
Diffstat (limited to 'usr.bin/seq')
-rw-r--r--usr.bin/seq/Makefile4
-rw-r--r--usr.bin/seq/seq.19
-rw-r--r--usr.bin/seq/seq.c75
3 files changed, 55 insertions, 33 deletions
diff --git a/usr.bin/seq/Makefile b/usr.bin/seq/Makefile
index 58b16aea7b059..bb3c2959a062b 100644
--- a/usr.bin/seq/Makefile
+++ b/usr.bin/seq/Makefile
@@ -2,7 +2,7 @@
# $FreeBSD$
PROG= seq
-DPADD= ${LIBM}
-LDADD= -lm
+
+LIBADD= m
.include <bsd.prog.mk>
diff --git a/usr.bin/seq/seq.1 b/usr.bin/seq/seq.1
index 1ac977e8d9051..12dd1841982d3 100644
--- a/usr.bin/seq/seq.1
+++ b/usr.bin/seq/seq.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: seq.1,v 1.6 2008/11/26 15:03:47 ginsbach Exp $
+.\" $NetBSD: seq.1,v 1.8 2013/04/07 17:37:45 jdf Exp $
.\"
.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 19, 2010
+.Dd September 10, 2013
.Dt SEQ 1
.Os
.Sh NAME
@@ -59,7 +59,7 @@ as possible, in increments of
When
.Ar first
is larger than
-.Ar last
+.Ar last ,
the default
.Ar incr
is -1.
@@ -79,8 +79,11 @@ style
.Ar format
to print each number.
Only the
+.Cm A ,
+.Cm a ,
.Cm E ,
.Cm e ,
+.Cm F ,
.Cm f ,
.Cm G ,
.Cm g ,
diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c
index e0777431e808b..6d715e1d42ae6 100644
--- a/usr.bin/seq/seq.c
+++ b/usr.bin/seq/seq.c
@@ -1,4 +1,4 @@
-/* $NetBSD: seq.c,v 1.5 2008/07/21 14:19:26 lukem Exp $ */
+/* $NetBSD: seq.c,v 1.7 2010/05/27 08:40:19 dholland Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -158,6 +158,8 @@ main(int argc, char *argv[])
if (!valid_format(fmt))
errx(1, "invalid format string: `%s'", fmt);
fmt = unescape(fmt);
+ if (!valid_format(fmt))
+ errx(1, "invalid format string");
/*
* XXX to be bug for bug compatible with Plan 9 add a
* newline if none found at the end of the format string.
@@ -225,39 +227,56 @@ numeric(const char *s)
static int
valid_format(const char *fmt)
{
- int conversions = 0;
+ unsigned conversions = 0;
while (*fmt != '\0') {
/* scan for conversions */
- if (*fmt != '\0' && *fmt != '%') {
- do {
- fmt++;
- } while (*fmt != '\0' && *fmt != '%');
+ if (*fmt != '%') {
+ fmt++;
+ continue;
}
- /* scan a conversion */
- if (*fmt != '\0') {
- do {
- fmt++;
+ fmt++;
- /* ok %% */
- if (*fmt == '%') {
- fmt++;
- break;
- }
- /* valid conversions */
- if (strchr("eEfgG", *fmt) &&
- conversions++ < 1) {
- fmt++;
- break;
- }
- /* flags, width and precision */
- if (isdigit((unsigned char)*fmt) ||
- strchr("+- 0#.", *fmt))
- continue;
+ /* allow %% but not things like %10% */
+ if (*fmt == '%') {
+ fmt++;
+ continue;
+ }
- /* oops! bad conversion format! */
- return (0);
- } while (*fmt != '\0');
+ /* flags */
+ while (*fmt != '\0' && strchr("#0- +'", *fmt)) {
+ fmt++;
+ }
+
+ /* field width */
+ while (*fmt != '\0' && strchr("0123456789", *fmt)) {
+ fmt++;
+ }
+
+ /* precision */
+ if (*fmt == '.') {
+ fmt++;
+ while (*fmt != '\0' && strchr("0123456789", *fmt)) {
+ fmt++;
+ }
+ }
+
+ /* conversion */
+ switch (*fmt) {
+ case 'A':
+ case 'a':
+ case 'E':
+ case 'e':
+ case 'F':
+ case 'f':
+ case 'G':
+ case 'g':
+ /* floating point formats are accepted */
+ conversions++;
+ break;
+ default:
+ /* anything else is not */
+ return 0;
}
}