seq.c 752 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 "libbb.h"
  10. /* This is a NOFORK applet. Be very careful! */
  11. int seq_main(int argc, char **argv);
  12. int seq_main(int argc, char **argv)
  13. {
  14. double last, increment, i;
  15. i = increment = 1;
  16. switch (argc) {
  17. case 4:
  18. increment = atof(argv[2]);
  19. case 3:
  20. i = 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. while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) {
  29. printf("%g\n", i);
  30. i += increment;
  31. }
  32. return fflush(stdout);
  33. }