[BusyBox] Patch for head,tail,sed
simon at lisa.de
simon at lisa.de
Wed May 29 11:12:03 UTC 2002
Hi, I'm not subscribed to this list.
I wrote a patch for busybox 0.60.2 for our company's (www.lisa.de)
private use. It's more or less dirty and adds the shortcut option
of "-12" instedad of "-n 12" style to head and tail. To sed it adds
the '!'-inversion of addresses.
It's half appliable to the current snapshot, too, but the sed code
was changed patch incompatible. It's easy to fix by hand, though.
mfg, simon .... fyi, it's simple, it's free, do whatever you want :-)
-------------- next part --------------
diff -Naur busybox-0.60.2/head.c busybox-0.60.2_lisa.1/head.c
--- busybox-0.60.2/head.c Mon Nov 19 23:34:17 2001
+++ busybox-0.60.2_lisa.1/head.c Wed May 29 16:41:24 2002
@@ -48,8 +48,21 @@
int need_headers, opt, len = 10, status = EXIT_SUCCESS;
/* parse argv[] */
- while ((opt = getopt(argc, argv, "n:")) > 0) {
+ while ((opt = getopt(argc, argv, "n:1::2::3::4::5::6::7::8::9::")) > 0) {
switch (opt) {
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ len = optarg ? atoi(optarg-1) : (opt - '0');
+ if (len <= 0)
+ show_usage();
+ break;
case 'n':
len = atoi(optarg);
if (len >= 1)
diff -Naur busybox-0.60.2/sed.c busybox-0.60.2_lisa.1/sed.c
--- busybox-0.60.2/sed.c Mon Nov 19 23:34:17 2001
+++ busybox-0.60.2_lisa.1/sed.c Wed May 29 16:46:56 2002
@@ -61,7 +61,8 @@
struct sed_cmd {
-
+ /* flag that show the inversion of the address given by '!' */
+ int invert;
/* GENERAL FIELDS */
char delimiter; /* The delimiter used to separate regexps */
@@ -180,11 +181,14 @@
sed_cmd->delimiter = '/';
if (isdigit(my_str[idx])) {
+ char keep;
do {
idx++;
} while (isdigit(my_str[idx]));
+ keep = my_str[idx];
my_str[idx] = 0;
*linenum = atoi(my_str);
+ my_str[idx] = keep;
}
else if (my_str[idx] == '$') {
*linenum = -1;
@@ -205,6 +209,13 @@
idx = -1;
}
+ if (idx >= 0 && my_str[idx] == '!') {
+ sed_cmd->invert = 1;
+ idx++;
+ } else {
+ sed_cmd->invert = 0;
+ }
+
free(my_str);
sed_cmd->delimiter = olddelimiter;
return idx;
@@ -655,7 +666,7 @@
/*
* entry point into sedding...
*/
- if (
+ int match = (
/* no range necessary */
(sed_cmds[i].beg_line == 0 && sed_cmds[i].end_line == 0 &&
sed_cmds[i].beg_match == NULL &&
@@ -666,7 +677,9 @@
(sed_cmds[i].beg_match && (regexec(sed_cmds[i].beg_match, line, 0, NULL, 0) == 0)) ||
/* we are currently within the beginning & ending address range */
still_in_range
- ) {
+ );
+
+ if (match ^ sed_cmds[i].invert) {
/*
* actual sedding
diff -Naur busybox-0.60.2/tail.c busybox-0.60.2_lisa.1/tail.c
--- busybox-0.60.2/tail.c Fri Oct 26 23:08:05 2001
+++ busybox-0.60.2_lisa.1/tail.c Wed May 29 16:41:24 2002
@@ -68,8 +68,19 @@
char *s, *start, *end, buf[BUFSIZ];
int i, opt;
- while ((opt = getopt(argc, argv, "c:fhn:q:s:v")) > 0) {
+ while ((opt = getopt(argc, argv, "c:fhn:q:s:v1::2::3::4::5::6::7::8::9::")) > 0) {
switch (opt) {
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ count = optarg ? atoi(optarg-1) : (opt - '0');
+ break;
case 'f':
follow = 1;
break;
More information about the busybox
mailing list