blob: 01d71f256b9bc4df5c0105f6c773a933f6e252bd [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
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000010#include "libbb.h"
Glenn L McGrath82364bb2004-01-27 09:22:20 +000011
Denis Vlasenko99912ca2007-04-10 15:43:37 +000012/* This is a NOFORK applet. Be very careful! */
13
14
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000015int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Rob Landleydfba7412006-03-06 20:47:33 +000016int seq_main(int argc, char **argv)
Glenn L McGrath82364bb2004-01-27 09:22:20 +000017{
Denis Vlasenko99912ca2007-04-10 15:43:37 +000018 double last, increment, i;
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000019
Denis Vlasenko99912ca2007-04-10 15:43:37 +000020 i = increment = 1;
Rob Landley73a20f32006-02-23 19:54:48 +000021 switch (argc) {
22 case 4:
Denis Vlasenkoce979602006-09-27 23:31:08 +000023 increment = atof(argv[2]);
Rob Landley73a20f32006-02-23 19:54:48 +000024 case 3:
Denis Vlasenko99912ca2007-04-10 15:43:37 +000025 i = atof(argv[1]);
Rob Landley73a20f32006-02-23 19:54:48 +000026 case 2:
Denis Vlasenkoce979602006-09-27 23:31:08 +000027 last = atof(argv[argc-1]);
Rob Landley73a20f32006-02-23 19:54:48 +000028 break;
29 default:
30 bb_show_usage();
Glenn L McGrath82364bb2004-01-27 09:22:20 +000031 }
Glenn L McGrath82364bb2004-01-27 09:22:20 +000032
Glenn L McGrathefc6bf62004-07-23 06:43:29 +000033 /* You should note that this is pos-5.0.91 semantics, -- FK. */
Denis Vlasenko99912ca2007-04-10 15:43:37 +000034 while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) {
Rob Landleyd5b94282006-04-27 22:36:32 +000035 printf("%g\n", i);
Denis Vlasenko99912ca2007-04-10 15:43:37 +000036 i += increment;
Glenn L McGrath82364bb2004-01-27 09:22:20 +000037 }
38
Denis Vlasenko99912ca2007-04-10 15:43:37 +000039 return fflush(stdout);
Glenn L McGrath82364bb2004-01-27 09:22:20 +000040}