diff options
| author | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-01-06 00:48:21 +0000 |
|---|---|---|
| committer | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-01-06 00:48:21 +0000 |
| commit | 3becb0b7ea62ece4e15e11780b58a48385b6a7b9 (patch) | |
| tree | 3b3d8839cda2823021d7a969f77cc1e70b1efa9c | |
| parent | 4ad5c2a029a819366ec0076636a5f993c58cfe58 (diff) | |
| download | busybox-w32-3becb0b7ea62ece4e15e11780b58a48385b6a7b9.tar.gz busybox-w32-3becb0b7ea62ece4e15e11780b58a48385b6a7b9.tar.bz2 busybox-w32-3becb0b7ea62ece4e15e11780b58a48385b6a7b9.zip | |
i am busybox of borg. unix will be assimilated.
git-svn-id: svn://busybox.net/trunk/busybox@280 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | applets/busybox.c | 3 | ||||
| -rw-r--r-- | busybox.c | 3 | ||||
| -rw-r--r-- | busybox.def.h | 1 | ||||
| -rw-r--r-- | coreutils/uniq.c | 157 | ||||
| -rw-r--r-- | internal.h | 1 | ||||
| -rw-r--r-- | uniq.c | 157 |
6 files changed, 322 insertions, 0 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index a35306915..4a7feefd2 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
| @@ -225,6 +225,9 @@ static const struct Applet applets[] = { | |||
| 225 | #ifdef BB_UMOUNT //bin | 225 | #ifdef BB_UMOUNT //bin |
| 226 | {"umount", umount_main}, | 226 | {"umount", umount_main}, |
| 227 | #endif | 227 | #endif |
| 228 | #ifdef BB_UNIQ //bin | ||
| 229 | {"uniq", uniq_main}, | ||
| 230 | #endif | ||
| 228 | #ifdef BB_UPDATE //sbin | 231 | #ifdef BB_UPDATE //sbin |
| 229 | {"update", update_main}, | 232 | {"update", update_main}, |
| 230 | #endif | 233 | #endif |
| @@ -225,6 +225,9 @@ static const struct Applet applets[] = { | |||
| 225 | #ifdef BB_UMOUNT //bin | 225 | #ifdef BB_UMOUNT //bin |
| 226 | {"umount", umount_main}, | 226 | {"umount", umount_main}, |
| 227 | #endif | 227 | #endif |
| 228 | #ifdef BB_UNIQ //bin | ||
| 229 | {"uniq", uniq_main}, | ||
| 230 | #endif | ||
| 228 | #ifdef BB_UPDATE //sbin | 231 | #ifdef BB_UPDATE //sbin |
| 229 | {"update", update_main}, | 232 | {"update", update_main}, |
| 230 | #endif | 233 | #endif |
diff --git a/busybox.def.h b/busybox.def.h index 503410f1a..0e62ca781 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
| @@ -75,6 +75,7 @@ | |||
| 75 | #define BB_TOUCH | 75 | #define BB_TOUCH |
| 76 | #define BB_TRUE_FALSE | 76 | #define BB_TRUE_FALSE |
| 77 | #define BB_UMOUNT | 77 | #define BB_UMOUNT |
| 78 | #define BB_UNIQ | ||
| 78 | #define BB_UPDATE | 79 | #define BB_UPDATE |
| 79 | #define BB_UNAME | 80 | #define BB_UNAME |
| 80 | #define BB_GZIP | 81 | #define BB_GZIP |
diff --git a/coreutils/uniq.c b/coreutils/uniq.c new file mode 100644 index 000000000..7e78be390 --- /dev/null +++ b/coreutils/uniq.c | |||
| @@ -0,0 +1,157 @@ | |||
| 1 | /* | ||
| 2 | * Mini sort implementation for busybox | ||
| 3 | * | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999 by Lineo, inc. | ||
| 6 | * Written by John Beppu <beppu@lineo.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 21 | * | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include "internal.h" | ||
| 25 | #include <stdio.h> | ||
| 26 | |||
| 27 | static const char uniq_usage[] = | ||
| 28 | "haha\n" | ||
| 29 | ; | ||
| 30 | |||
| 31 | /* max chars in line */ | ||
| 32 | #define UNIQ_MAX 4096 | ||
| 33 | |||
| 34 | typedef void (Print)(FILE *, const char *); | ||
| 35 | |||
| 36 | typedef int (Decide)(const char *, const char *); | ||
| 37 | |||
| 38 | /* container for two lines to be compared */ | ||
| 39 | typedef struct { | ||
| 40 | char *a; | ||
| 41 | char *b; | ||
| 42 | int recurrence; | ||
| 43 | FILE *in; | ||
| 44 | FILE *out; | ||
| 45 | void *func; | ||
| 46 | } Subject; | ||
| 47 | |||
| 48 | /* set up all the variables of a uniq operation */ | ||
| 49 | static Subject * | ||
| 50 | subject_init(Subject *self, FILE *in, FILE *out, void *func) | ||
| 51 | { | ||
| 52 | self->a = NULL; | ||
| 53 | self->b = NULL; | ||
| 54 | self->in = in; | ||
| 55 | self->out = out; | ||
| 56 | self->func = func; | ||
| 57 | self->recurrence = 0; | ||
| 58 | return self; | ||
| 59 | } | ||
| 60 | |||
| 61 | /* point a and b to the appropriate lines; | ||
| 62 | * count the recurrences (if any) of a string; | ||
| 63 | */ | ||
| 64 | static Subject * | ||
| 65 | subject_next(Subject *self) | ||
| 66 | { | ||
| 67 | /* tmp line holders */ | ||
| 68 | static char line[2][UNIQ_MAX]; | ||
| 69 | static int alternator = 0; | ||
| 70 | |||
| 71 | if (fgets(line[alternator], UNIQ_MAX, self->in)) { | ||
| 72 | self->a = self->b; | ||
| 73 | self->b = line[alternator]; | ||
| 74 | alternator ^= 1; | ||
| 75 | return self; | ||
| 76 | } | ||
| 77 | |||
| 78 | return NULL; | ||
| 79 | } | ||
| 80 | |||
| 81 | static Subject * | ||
| 82 | subject_last(Subject *self) | ||
| 83 | { | ||
| 84 | self->a = self->b; | ||
| 85 | self->b = NULL; | ||
| 86 | return self; | ||
| 87 | } | ||
| 88 | |||
| 89 | static Subject * | ||
| 90 | subject_study(Subject *self) | ||
| 91 | { | ||
| 92 | if (self->a == NULL) { | ||
| 93 | return self; | ||
| 94 | } | ||
| 95 | if (self->b == NULL) { | ||
| 96 | fprintf(self->out, "%s", self->a); | ||
| 97 | return self; | ||
| 98 | } | ||
| 99 | if (strcmp(self->a, self->b) == 0) { | ||
| 100 | self->recurrence++; | ||
| 101 | } else { | ||
| 102 | fprintf(self->out, "%s", self->a); | ||
| 103 | self->recurrence = 0; | ||
| 104 | } | ||
| 105 | return self; | ||
| 106 | } | ||
| 107 | |||
| 108 | /* one variable is the decision algo */ | ||
| 109 | /* another variable is the printing algo */ | ||
| 110 | |||
| 111 | /* I don't think I have to have more than a 1 line memory | ||
| 112 | this is the one constant */ | ||
| 113 | |||
| 114 | /* it seems like GNU/uniq only takes one or two files as an option */ | ||
| 115 | |||
| 116 | /* ________________________________________________________________________ */ | ||
| 117 | int | ||
| 118 | uniq_main(int argc, char **argv) | ||
| 119 | { | ||
| 120 | int i; | ||
| 121 | char opt; | ||
| 122 | FILE *in, *out; | ||
| 123 | Subject s; | ||
| 124 | |||
| 125 | /* init */ | ||
| 126 | in = stdin; | ||
| 127 | out = stdout; | ||
| 128 | |||
| 129 | subject_init(&s, in, out, NULL); | ||
| 130 | while (subject_next(&s)) { | ||
| 131 | subject_study(&s); | ||
| 132 | } | ||
| 133 | subject_last(&s); | ||
| 134 | subject_study(&s); | ||
| 135 | exit(0); | ||
| 136 | |||
| 137 | /* XXX : finish the tedious stuff */ | ||
| 138 | |||
| 139 | /* parse argv[] */ | ||
| 140 | for (i = 1; i < argc; i++) { | ||
| 141 | if (argv[i][0] == '-') { | ||
| 142 | opt = argv[i][1]; | ||
| 143 | switch (opt) { | ||
| 144 | case 'h': | ||
| 145 | usage(uniq_usage); | ||
| 146 | default: | ||
| 147 | usage(uniq_usage); | ||
| 148 | } | ||
| 149 | } else { | ||
| 150 | break; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | exit(0); | ||
| 155 | } | ||
| 156 | |||
| 157 | /* $Id: uniq.c,v 1.1 2000/01/06 00:48:21 beppu Exp $ */ | ||
diff --git a/internal.h b/internal.h index cb042a32f..1b5c0bc92 100644 --- a/internal.h +++ b/internal.h | |||
| @@ -126,6 +126,7 @@ extern int tput_main(int argc, char** argv); | |||
| 126 | extern int true_main(int argc, char** argv); | 126 | extern int true_main(int argc, char** argv); |
| 127 | extern int tryopen_main(int argc, char** argv); | 127 | extern int tryopen_main(int argc, char** argv); |
| 128 | extern int umount_main(int argc, char** argv); | 128 | extern int umount_main(int argc, char** argv); |
| 129 | extern int uniq_main(int argc, char** argv); | ||
| 129 | extern int update_main(int argc, char** argv); | 130 | extern int update_main(int argc, char** argv); |
| 130 | extern int uname_main(int argc, char** argv); | 131 | extern int uname_main(int argc, char** argv); |
| 131 | extern int gunzip_main (int argc, char** argv); | 132 | extern int gunzip_main (int argc, char** argv); |
| @@ -0,0 +1,157 @@ | |||
| 1 | /* | ||
| 2 | * Mini sort implementation for busybox | ||
| 3 | * | ||
| 4 | * | ||
| 5 | * Copyright (C) 1999 by Lineo, inc. | ||
| 6 | * Written by John Beppu <beppu@lineo.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 21 | * | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include "internal.h" | ||
| 25 | #include <stdio.h> | ||
| 26 | |||
| 27 | static const char uniq_usage[] = | ||
| 28 | "haha\n" | ||
| 29 | ; | ||
| 30 | |||
| 31 | /* max chars in line */ | ||
| 32 | #define UNIQ_MAX 4096 | ||
| 33 | |||
| 34 | typedef void (Print)(FILE *, const char *); | ||
| 35 | |||
| 36 | typedef int (Decide)(const char *, const char *); | ||
| 37 | |||
| 38 | /* container for two lines to be compared */ | ||
| 39 | typedef struct { | ||
| 40 | char *a; | ||
| 41 | char *b; | ||
| 42 | int recurrence; | ||
| 43 | FILE *in; | ||
| 44 | FILE *out; | ||
| 45 | void *func; | ||
| 46 | } Subject; | ||
| 47 | |||
| 48 | /* set up all the variables of a uniq operation */ | ||
| 49 | static Subject * | ||
| 50 | subject_init(Subject *self, FILE *in, FILE *out, void *func) | ||
| 51 | { | ||
| 52 | self->a = NULL; | ||
| 53 | self->b = NULL; | ||
| 54 | self->in = in; | ||
| 55 | self->out = out; | ||
| 56 | self->func = func; | ||
| 57 | self->recurrence = 0; | ||
| 58 | return self; | ||
| 59 | } | ||
| 60 | |||
| 61 | /* point a and b to the appropriate lines; | ||
| 62 | * count the recurrences (if any) of a string; | ||
| 63 | */ | ||
| 64 | static Subject * | ||
| 65 | subject_next(Subject *self) | ||
| 66 | { | ||
| 67 | /* tmp line holders */ | ||
| 68 | static char line[2][UNIQ_MAX]; | ||
| 69 | static int alternator = 0; | ||
| 70 | |||
| 71 | if (fgets(line[alternator], UNIQ_MAX, self->in)) { | ||
| 72 | self->a = self->b; | ||
| 73 | self->b = line[alternator]; | ||
| 74 | alternator ^= 1; | ||
| 75 | return self; | ||
| 76 | } | ||
| 77 | |||
| 78 | return NULL; | ||
| 79 | } | ||
| 80 | |||
| 81 | static Subject * | ||
| 82 | subject_last(Subject *self) | ||
| 83 | { | ||
| 84 | self->a = self->b; | ||
| 85 | self->b = NULL; | ||
| 86 | return self; | ||
| 87 | } | ||
| 88 | |||
| 89 | static Subject * | ||
| 90 | subject_study(Subject *self) | ||
| 91 | { | ||
| 92 | if (self->a == NULL) { | ||
| 93 | return self; | ||
| 94 | } | ||
| 95 | if (self->b == NULL) { | ||
| 96 | fprintf(self->out, "%s", self->a); | ||
| 97 | return self; | ||
| 98 | } | ||
| 99 | if (strcmp(self->a, self->b) == 0) { | ||
| 100 | self->recurrence++; | ||
| 101 | } else { | ||
| 102 | fprintf(self->out, "%s", self->a); | ||
| 103 | self->recurrence = 0; | ||
| 104 | } | ||
| 105 | return self; | ||
| 106 | } | ||
| 107 | |||
| 108 | /* one variable is the decision algo */ | ||
| 109 | /* another variable is the printing algo */ | ||
| 110 | |||
| 111 | /* I don't think I have to have more than a 1 line memory | ||
| 112 | this is the one constant */ | ||
| 113 | |||
| 114 | /* it seems like GNU/uniq only takes one or two files as an option */ | ||
| 115 | |||
| 116 | /* ________________________________________________________________________ */ | ||
| 117 | int | ||
| 118 | uniq_main(int argc, char **argv) | ||
| 119 | { | ||
| 120 | int i; | ||
| 121 | char opt; | ||
| 122 | FILE *in, *out; | ||
| 123 | Subject s; | ||
| 124 | |||
| 125 | /* init */ | ||
| 126 | in = stdin; | ||
| 127 | out = stdout; | ||
| 128 | |||
| 129 | subject_init(&s, in, out, NULL); | ||
| 130 | while (subject_next(&s)) { | ||
| 131 | subject_study(&s); | ||
| 132 | } | ||
| 133 | subject_last(&s); | ||
| 134 | subject_study(&s); | ||
| 135 | exit(0); | ||
| 136 | |||
| 137 | /* XXX : finish the tedious stuff */ | ||
| 138 | |||
| 139 | /* parse argv[] */ | ||
| 140 | for (i = 1; i < argc; i++) { | ||
| 141 | if (argv[i][0] == '-') { | ||
| 142 | opt = argv[i][1]; | ||
| 143 | switch (opt) { | ||
| 144 | case 'h': | ||
| 145 | usage(uniq_usage); | ||
| 146 | default: | ||
| 147 | usage(uniq_usage); | ||
| 148 | } | ||
| 149 | } else { | ||
| 150 | break; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | exit(0); | ||
| 155 | } | ||
| 156 | |||
| 157 | /* $Id: uniq.c,v 1.1 2000/01/06 00:48:21 beppu Exp $ */ | ||
