seq.c 730 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * seq implementation for busybox
  4. *
  5. * Copyright (C) 2004, Glenn McGrath
  6. *
  7. * Licensed under the GPL v2, see the file LICENSE in this tarball.
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "busybox.h"
  12. int seq_main(int argc, char **argv)
  13. {
  14. double last, first, increment, i;
  15. first = increment = 1;
  16. switch (argc) {
  17. case 4:
  18. increment = atof(argv[2]);
  19. case 3:
  20. first = atof(argv[1]);
  21. case 2:
  22. last = atof(argv[argc-1]);
  23. break;
  24. default:
  25. bb_show_usage();
  26. }
  27. /* You should note that this is pos-5.0.91 semantics, -- FK. */
  28. for (i = first;
  29. (increment > 0 && i <= last) || (increment < 0 && i >=last);
  30. i += increment)
  31. {
  32. printf("%g\n", i);
  33. }
  34. return EXIT_SUCCESS;
  35. }