blob: e81a4660ad5e8d47750248761d1d3f02e12b9b70 [file] [log] [blame]
Glenn L McGrathefc6bf62004-07-23 06:43:29 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath82364bb2004-01-27 09:22:20 +00002/*
Glenn L McGrathefc6bf62004-07-23 06:43:29 +00003 * seq implementation for busybox
4 *
Rob Landley73a20f32006-02-23 19:54:48 +00005 * Copyright (C) 2004, Glenn McGrath
Glenn L McGrath82364bb2004-01-27 09:22:20 +00006 *
Rob Landley73a20f32006-02-23 19:54:48 +00007 * Licensed under the GPL v2, see the file LICENSE in this tarball.
Glenn L McGrath82364bb2004-01-27 09:22:20 +00008 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include "busybox.h"
13
Denis Vlasenko06af2162007-02-03 17:28:39 +000014int seq_main(int argc, char **argv);
Rob Landleydfba7412006-03-06 20:47:33 +000015int seq_main(int argc, char **argv)
Glenn L McGrath82364bb2004-01-27 09:22:20 +000016{
Rob Landley73a20f32006-02-23 19:54:48 +000017 double last, first, increment, i;
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000018
Rob Landley73a20f32006-02-23 19:54:48 +000019 first = increment = 1;
20 switch (argc) {
21 case 4:
Denis Vlasenkoce979602006-09-27 23:31:08 +000022 increment = atof(argv[2]);
Rob Landley73a20f32006-02-23 19:54:48 +000023 case 3:
Denis Vlasenkoce979602006-09-27 23:31:08 +000024 first = atof(argv[1]);
Rob Landley73a20f32006-02-23 19:54:48 +000025 case 2:
Denis Vlasenkoce979602006-09-27 23:31:08 +000026 last = atof(argv[argc-1]);
Rob Landley73a20f32006-02-23 19:54:48 +000027 break;
28 default:
29 bb_show_usage();
Glenn L McGrath82364bb2004-01-27 09:22:20 +000030 }
Glenn L McGrath82364bb2004-01-27 09:22:20 +000031
Glenn L McGrathefc6bf62004-07-23 06:43:29 +000032 /* You should note that this is pos-5.0.91 semantics, -- FK. */
Rob Landleyd5b94282006-04-27 22:36:32 +000033 for (i = first;
Denis Vlasenkoce979602006-09-27 23:31:08 +000034 (increment > 0 && i <= last) || (increment < 0 && i >=last);
35 i += increment)
Rob Landleyd5b94282006-04-27 22:36:32 +000036 {
37 printf("%g\n", i);
Glenn L McGrath82364bb2004-01-27 09:22:20 +000038 }
39
Glenn L McGrathefc6bf62004-07-23 06:43:29 +000040 return EXIT_SUCCESS;
Glenn L McGrath82364bb2004-01-27 09:22:20 +000041}