blob: f2b4706f22d4f4d5662900ab85855af49bc4c78f [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
Rob Landleydfba7412006-03-06 20:47:33 +000014int seq_main(int argc, char **argv)
Glenn L McGrath82364bb2004-01-27 09:22:20 +000015{
Rob Landley73a20f32006-02-23 19:54:48 +000016 double last, first, increment, i;
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000017
Rob Landley73a20f32006-02-23 19:54:48 +000018 first = increment = 1;
19 switch (argc) {
20 case 4:
Denis Vlasenkoce979602006-09-27 23:31:08 +000021 increment = atof(argv[2]);
Rob Landley73a20f32006-02-23 19:54:48 +000022 case 3:
Denis Vlasenkoce979602006-09-27 23:31:08 +000023 first = atof(argv[1]);
Rob Landley73a20f32006-02-23 19:54:48 +000024 case 2:
Denis Vlasenkoce979602006-09-27 23:31:08 +000025 last = atof(argv[argc-1]);
Rob Landley73a20f32006-02-23 19:54:48 +000026 break;
27 default:
28 bb_show_usage();
Glenn L McGrath82364bb2004-01-27 09:22:20 +000029 }
Glenn L McGrath82364bb2004-01-27 09:22:20 +000030
Glenn L McGrathefc6bf62004-07-23 06:43:29 +000031 /* You should note that this is pos-5.0.91 semantics, -- FK. */
Rob Landleyd5b94282006-04-27 22:36:32 +000032 for (i = first;
Denis Vlasenkoce979602006-09-27 23:31:08 +000033 (increment > 0 && i <= last) || (increment < 0 && i >=last);
34 i += increment)
Rob Landleyd5b94282006-04-27 22:36:32 +000035 {
36 printf("%g\n", i);
Glenn L McGrath82364bb2004-01-27 09:22:20 +000037 }
38
Glenn L McGrathefc6bf62004-07-23 06:43:29 +000039 return EXIT_SUCCESS;
Glenn L McGrath82364bb2004-01-27 09:22:20 +000040}