[hackers] [sbase] Fixing seq || David Galos

From: <git_AT_suckless.org>
Date: Mon, 01 Jul 2013 19:25:39 +0200

commit 563742500e0c5ece275a1e0d22c055bf92d9c75d
Author: David Galos <galosd83_AT_students.rowan.edu>
Date: Mon Jul 1 13:25:41 2013 -0400

    Fixing seq

diff --git a/seq.1 b/seq.1
index 8cd3421..b66371d 100644
--- a/seq.1
+++ b/seq.1
_AT_@ -10,7 +10,7 @@ seq \- print a sequence of numbers
 .IR separator ]
 .RI [ start
 .RI [ step ]]
-.RI end
+.IR end
 .SH DESCRIPTION
 .B seq
 will print a sequence of numbers from
_AT_@ -31,5 +31,6 @@ specifies the separator to print between output lines
 .TP
 .BI \-w
 tells seq to print out lines in equal width
-.TP
 
+.SH SEE ALSO
+.IR printf (3)
diff --git a/seq.c b/seq.c
index 20edaa5..6f91fd9 100644
--- a/seq.c
+++ b/seq.c
_AT_@ -14,8 +14,8 @@ static bool validfmt(const char *);
 static void
 usage(void)
 {
- eprintf("usage: %s [-f format] [-s sep] [-w width] first"
- " [inc [last]]
", argv0);
+ eprintf("usage: %s [-f fmt] [-s separator] [-w width] [start"
+ " [step]] end
", argv0);
 }
 
 int
_AT_@ -23,14 +23,15 @@ main(int argc, char *argv[])
 {
         const char *starts = "1", *steps = "1", *ends = "1", *sep = "
";
         bool wflag = false;
- char ftmp[BUFSIZ], *fmt = ftmp;
+ char *tmp, ftmp[BUFSIZ], *fmt = ftmp;
         double start, step, end, out, dir;
+ int left, right;
 
         ARGBEGIN {
         case 'f':
- if(!validfmt(EARGF(usage())))
- eprintf("%s: invalid format
", ARGF());
- fmt = ARGF();
+ if(!validfmt(tmp=EARGF(usage())))
+ eprintf("%s: invalid format
", tmp);
+ fmt = tmp;
                 break;
         case 's':
                 sep = EARGF(usage());
_AT_@ -44,13 +45,9 @@ main(int argc, char *argv[])
 
         switch(argc) {
         case 3:
- starts = argv[0];
- argv++;
- steps = argv[0];
- argv++;
- ends = argv[0];
- argv++;
- break;
+ steps = argv[1];
+ argv[1] = argv[2];
+ /* fallthrough */
         case 2:
                 starts = argv[0];
                 argv++;
_AT_@ -70,12 +67,12 @@ main(int argc, char *argv[])
                 return EXIT_FAILURE;
 
         if(fmt == ftmp) {
- int right = MAX(digitsright(starts),
+ right = MAX(digitsright(starts),
                             MAX(digitsright(ends),
                                 digitsright(steps)));
 
                 if(wflag) {
- int left = MAX(digitsleft(starts), digitsleft(ends));
+ left = MAX(digitsleft(starts), digitsleft(ends));
 
                         snprintf(ftmp, sizeof ftmp, "%%0%d.%df",
                                         right+left+(right != 0), right);
Received on Mon Jul 01 2013 - 19:25:39 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 01 2013 - 19:36:10 CEST