2 Copyright © 2013 Alastair Stuart
4 This program is open source software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #include <stdlib.h> // atoi()
20 #define VERSION "0.01"
29 void seq(char* first
, char* increment
, char* last
)
31 unsigned int width
= 0;
37 for (int i
= atoi(first
); i
<= atoi(last
); i
+=atoi(increment
))
39 printf("%0*d%s", width
, i
, sep
);
47 int main(int argc
, char* argv
[])
52 fprintf(stderr
, "%s: missing operand\n"
53 "Run '%s --help' for usage.\n",
61 for (arg
= 1; arg
< argc
; arg
++)
63 if (strcmp(argv
[arg
], "-s") == 0) {
65 arg
++; // don't parse separator as a flag
66 } else if (strcmp(argv
[arg
], "-t") == 0) {
68 arg
++; // don't parse terminator as a flag
69 } else if (strcmp(argv
[arg
], "-w") == 0 || strcmp(argv
[arg
], "--equal-width") == 0) {
71 } else if (strcmp(argv
[arg
], "-h") == 0 || strcmp(argv
[arg
], "--help") == 0) {
72 printf("Usage: %s [first] [last]\n", argv
[0]);
74 "If [first] is omitted, it is assumed to be 1.\n");
76 } else if (strcmp(argv
[arg
], "-v") == 0 || strcmp(argv
[arg
], "--version") == 0) {
77 printf("seq (mutos) v"VERSION
"\n");
84 int args_left
= argc
- arg
;
89 fprintf(stderr
, "%s: too few arguments\n",
93 seq("1", "1", argv
[arg
]);
96 seq(argv
[arg
], "1", argv
[arg
+1]);
99 seq(argv
[arg
], argv
[arg
+1], argv
[arg
+2]);
102 fprintf(stderr
, "%s: too many arguments\n",