* Mini sort implementation for busybox
*
*
- * Copyright (C) 1999 by Lineo, inc.
+ * Copyright (C) 1999,2000 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
#ifdef BB_FEATURE_SORT_REVERSE
" [-r]"
#endif
-" [FILE]...\n\n";
+" [FILE]...\n\nSorts lines of text in the specified files\n";
#ifdef BB_FEATURE_SORT_REVERSE
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
typedef struct {
int len; /* number of Lines */
Line **sorted; /* array fed to qsort */
-
Line *head; /* head of List */
Line *current; /* current Line */
} List;
static Line *line_alloc()
{
Line *self;
-
self = malloc(1 * sizeof(Line));
return self;
}
-/* Initialize Line with string */
-static Line *line_init(Line * self, const char *string)
-{
- self->data = malloc((strlen(string) + 1) * sizeof(char));
-
- if (self->data == NULL) {
- return NULL;
- }
- strcpy(self->data, string);
- self->next = NULL;
- return self;
-}
-
/* Construct Line from FILE* */
static Line *line_newFromFile(FILE * src)
{
- char buffer[max];
Line *self;
+ char *cstring = NULL;
- if (fgets(buffer, max, src)) {
+ if ((cstring = cstring_lineFromFile(src))) {
self = line_alloc();
if (self == NULL) {
return NULL;
}
- line_init(self, buffer);
+ self->data = cstring;
+ self->next = NULL;
return self;
}
return NULL;
self->head = line;
self->current = line;
- /* all subsequent insertions */
+ /* all subsequent insertions */
} else {
self->current->next = line;
self->current = line;
}
-/*
- * I need a list
- * to insert lines into
- * then I need to sort this list
- * and finally print it
- */
int sort_main(int argc, char **argv)
{
exit(0);
}
-/* $Id: sort.c,v 1.12 2000/03/04 21:19:32 erik Exp $ */
+/* $Id: sort.c,v 1.15 2000/04/17 04:22:09 beppu Exp $ */