blob: f4d891772e658354d2f9a272a337b2ecc3c029d5 [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;
17
18 first = increment = 1;
19 switch (argc) {
20 case 4:
21 increment=atof(argv[2]);
22 case 3:
23 first=atof(argv[1]);
24 case 2:
25 last=atof(argv[argc -1]);
26 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 Landley2324a7c2006-03-22 17:11:44 +000032 if (first <= last ? increment > 0 : increment < 0) {
Rob Landley73a20f32006-02-23 19:54:48 +000033 for (i = first;
Rob Landley2324a7c2006-03-22 17:11:44 +000034 (first <= last) ? (i <= last) : (i >= last);
Rob Landley73a20f32006-02-23 19:54:48 +000035 i += increment)
36 {
37 printf("%g\n", i);
38 }
Glenn L McGrath82364bb2004-01-27 09:22:20 +000039 }
40
Glenn L McGrathefc6bf62004-07-23 06:43:29 +000041 return EXIT_SUCCESS;
Glenn L McGrath82364bb2004-01-27 09:22:20 +000042}