2 * Mini sort implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by John Beppu <beppu@lineo.com>
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.
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.
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
27 static const char uniq_usage[] =
31 /* max chars in line */
34 typedef void (Print)(FILE *, const char *);
36 typedef int (Decide)(const char *, const char *);
38 /* container for two lines to be compared */
48 /* set up all the variables of a uniq operation */
50 subject_init(Subject *self, FILE *in, FILE *out, void *func)
61 /* point a and b to the appropriate lines;
62 * count the recurrences (if any) of a string;
65 subject_next(Subject *self)
67 /* tmp line holders */
68 static char line[2][UNIQ_MAX];
69 static int alternator = 0;
71 if (fgets(line[alternator], UNIQ_MAX, self->in)) {
73 self->b = line[alternator];
82 subject_last(Subject *self)
90 subject_study(Subject *self)
92 if (self->a == NULL) {
95 if (self->b == NULL) {
96 fprintf(self->out, "%s", self->a);
99 if (strcmp(self->a, self->b) == 0) {
102 fprintf(self->out, "%s", self->a);
103 self->recurrence = 0;
108 /* one variable is the decision algo */
109 /* another variable is the printing algo */
111 /* I don't think I have to have more than a 1 line memory
112 this is the one constant */
114 /* it seems like GNU/uniq only takes one or two files as an option */
116 /* ________________________________________________________________________ */
118 uniq_main(int argc, char **argv)
129 subject_init(&s, in, out, NULL);
130 while (subject_next(&s)) {
137 /* XXX : finish the tedious stuff */
140 for (i = 1; i < argc; i++) {
141 if (argv[i][0] == '-') {
157 /* $Id: uniq.c,v 1.1 2000/01/06 00:48:21 beppu Exp $ */