[BusyBox] seq

Thijs ten Hoeve i_are_weasel at hotmail.com
Thu Dec 20 16:09:12 UTC 2001


I needed the tool seq so I wrote a little bit of code and inserted into 
busybox. I never really learned c, so you probably find the code ugly, but 
it works for me and it might be useful to you so here is my seq.c:

/* vi: set sw=4 ts=4: */
/*
* Mini seq implementation for busybox
*
* Copyright (C) 2000  Thijs ten Hoeve <i_are_weasel at hotmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "busybox.h"
int seq_main(int argc, char **argv)
{
        float start, step, end, i;
        int ret=1;
        if(argc == 2){
                start=step=1;
                ret+= sscanf(argv[1], "%f", &end);
        } else if(argc == 3){
                step=1;
                ret+= sscanf(argv[1], "%f", &start);
                ret+= sscanf(argv[2], "%f", &end);
        } else if(argc == 4){
                ret+= sscanf(argv[1], "%f", &start);
                ret+= sscanf(argv[2], "%f", &step);
                ret+= sscanf(argv[3], "%f", &end);
        } else {
                show_usage();
                return EXIT_FAILURE;
        }
        if(ret < argc){
                show_usage();
                return EXIT_FAILURE;
        }
        if(start > end){
                step=abs(step);
                for(i=start; i >= end; i -= step)
                        printf("%F\n", i);
                return EXIT_SUCCESS;
        }
        for(i=start; i <= end; i += step)
                        printf("%F\n", i);
                return EXIT_SUCCESS;
}



usage.h diff -U 2:

--- busybox-0.60.2/usage.h      Sat Oct 27 01:08:05 2001
+++ busybox-0.60.2-seq/usage.h  Tue Dec 18 21:34:56 2001
@@ -1360,4 +1360,15 @@
#define setkeycodes_example_usage \
        "$ setkeycodes e030 127\n"
+#define seq_trivial_usage \
+       "[START] [STEP] END"
+#define seq_full_usage\
+       "Prints a sequence of numbers to standaard output.\n" \
+       "It prints the numbers from START to END by STEP.\n" \
+       "By default START and END are 1.\n"
+#define seq_example_usage \
+       "$seq 1 3\n" \
+       "1\n" \
+       "2\n" \
+       "3\n"

#define lash_trivial_usage \

applets.h diff:

--- busybox-0.60.2/applets.h    Sat Oct 27 01:08:04 2001
+++ busybox-0.60.2-seq/applets.h        Tue Dec 18 21:20:58 2001
@@ -354,4 +354,7 @@
        APPLET(setkeycodes, setkeycodes_main, _BB_DIR_USR_BIN)
#endif
+#ifdef BB_SEQ
+       APPLET(seq, seq_main, _BB_DIR_USR_BIN)
+#endif
#if defined(BB_FEATURE_SH_IS_ASH) && defined(BB_ASH)
        APPLET_NOUSAGE("sh", ash_main, _BB_DIR_BIN)

config.h:
--- busybox-0.60.2/Config.h     Sun Oct 28 06:14:46 2001
+++ busybox-0.60.2-seq/Config.h Thu Dec 20 22:46:37 2001
@@ -106,4 +106,5 @@
#define BB_SED
//#define BB_SETKEYCODES
+#define BB_SEQ
#define BB_SLEEP
#define BB_SORT

Use it if you like :)


_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com





More information about the busybox mailing list