Mercurial > hg > toybox
annotate toys/lsb/seq.c @ 1140:ef0bf6560071 draft
Forgot to set new pending entry to default n.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 08 Dec 2013 13:21:14 -0600 |
parents | 41b067739bd0 |
children |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
1 /* seq.c - Count from first to last, by increment. |
296 | 2 * |
3 * Copyright 2006 Rob Landley <rob@landley.net> | |
4 * | |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
5 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/seq.html |
296 | 6 |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
7 USE_SEQ(NEWTOY(seq, "<1>3?f:s:", TOYFLAG_USR|TOYFLAG_BIN)) |
296 | 8 |
9 config SEQ | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
10 bool "seq" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
11 depends on TOYBOX_FLOAT |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
12 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
13 help |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
14 usage: seq [-f fmt_str] [-s sep_str] [first] [increment] last |
296 | 15 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
16 Count from first to last, by increment. Omitted arguments default |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
17 to 1. Two arguments are used as first and last. Arguments can be |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
18 negative or floating point. |
760 | 19 |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
20 -f Use fmt_str as a floating point format string |
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
21 -s Use sep_str as separator, default is a newline character |
296 | 22 */ |
23 | |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
24 #define FOR_seq |
296 | 25 #include "toys.h" |
26 | |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
27 GLOBALS( |
760 | 28 char *sep; |
29 char *fmt; | |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
30 ) |
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
31 |
296 | 32 void seq_main(void) |
33 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
34 double first, increment, last, dd; |
760 | 35 char *sep_str = "\n"; |
36 char *fmt_str = "%g"; | |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
37 int output = 0; |
760 | 38 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
39 // Parse command line arguments, with appropriate defaults. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
40 // Note that any non-numeric arguments are treated as zero. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
41 first = increment = 1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
42 switch (toys.optc) { |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
43 case 3: increment = atof(toys.optargs[1]); |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
44 case 2: first = atof(*toys.optargs); |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
45 default: last = atof(toys.optargs[toys.optc-1]); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
46 } |
296 | 47 |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
48 if (toys.optflags & FLAG_f) fmt_str = TT.fmt; |
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
49 if (toys.optflags & FLAG_s) sep_str = TT.sep; |
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
50 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
51 // Yes, we're looping on a double. Yes rounding errors can accumulate if |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
52 // you use a non-integer increment. Deal with it. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
53 for (dd=first; (increment>0 && dd<=last) || (increment<0 && dd>=last); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
54 dd+=increment) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
55 { |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
56 if (dd != first) printf("%s", sep_str); |
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
57 printf(fmt_str, dd); |
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
58 output = 1; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
59 } |
759
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
60 |
143a9729fec8
Extend seq to support -f (format string) and -s (string separator) as requested by LSB
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
705
diff
changeset
|
61 if (output) printf("\n"); |
296 | 62 } |