aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Beppu <beppu@lbox.org>1999-12-21 20:00:35 +0000
committerJohn Beppu <beppu@lbox.org>1999-12-21 20:00:35 +0000
commitc0ca473af9a5afd17fd6dd916bb6008a036efb20 (patch)
treefe673f507d41ac5e35e3537acb0bf41c9183f971
parent3fe2ecf0d92b5ff8984513d0a99f6152b61ea998 (diff)
downloadbusybox-w32-c0ca473af9a5afd17fd6dd916bb6008a036efb20.tar.gz
busybox-w32-c0ca473af9a5afd17fd6dd916bb6008a036efb20.tar.bz2
busybox-w32-c0ca473af9a5afd17fd6dd916bb6008a036efb20.zip
this is my work in progress.
-rw-r--r--coreutils/sort.c127
-rw-r--r--sort.c127
2 files changed, 254 insertions, 0 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c
new file mode 100644
index 000000000..4ab673b4d
--- /dev/null
+++ b/coreutils/sort.c
@@ -0,0 +1,127 @@
1/*
2 * Mini find 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 <sys/types.h>
26#include <fcntl.h>
27#include <dirent.h>
28#include <stdio.h>
29#include <errno.h>
30
31static const char sort_usage[] =
32"Usage: sort [OPTION]... [FILE]...\n\n"
33;
34
35
36/* line node */
37typedef struct {
38 char *data; /* line data */
39 struct Line *next; /* pointer to next line node */
40} Line;
41
42/* singly-linked list of lines */
43typedef struct {
44 int len; /* number of Lines */
45 Line *line; /* array fed to qsort */
46 Line *head; /* head of List */
47} List;
48
49
50/* Line methods */
51
52static const int max = 1024;
53
54static Line *
55line_new()
56{
57 char buffer[max];
58}
59
60
61/* Comparison */
62
63static int
64compare_ascii(const void *, const void *);
65
66static int
67compare_numeric(const void *, const void *);
68
69
70/* List */
71
72static void
73list_insert();
74
75static void
76list_sort();
77
78static void
79list_print();
80
81
82
83/*
84 * I need a list
85 * to insert lines into
86 * then I need to sort this list
87 * and finally print it
88 */
89
90int
91sort_main(int argc, char **argv)
92{
93 int i;
94 char opt;
95
96 /* default behaviour */
97
98 /* parse argv[] */
99 for (i = 1; i < argc; i++) {
100 if (argv[i][0] == '-') {
101 opt = argv[i][1];
102 switch (opt) {
103 case 'h':
104 usage(sort_usage);
105 break;
106 default:
107 fprintf(stderr, "sort: invalid option -- %c\n", opt);
108 usage(sort_usage);
109 }
110 } else {
111 break;
112 }
113 }
114
115 /* go through remaining args (if any) */
116 if (i >= argc) {
117
118 } else {
119 for ( ; i < argc; i++) {
120 }
121 }
122
123 exit(0);
124}
125
126/* $Date: 1999/12/21 20:00:35 $ */
127/* $Id: sort.c,v 1.1 1999/12/21 20:00:35 beppu Exp $ */
diff --git a/sort.c b/sort.c
new file mode 100644
index 000000000..4ab673b4d
--- /dev/null
+++ b/sort.c
@@ -0,0 +1,127 @@
1/*
2 * Mini find 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 <sys/types.h>
26#include <fcntl.h>
27#include <dirent.h>
28#include <stdio.h>
29#include <errno.h>
30
31static const char sort_usage[] =
32"Usage: sort [OPTION]... [FILE]...\n\n"
33;
34
35
36/* line node */
37typedef struct {
38 char *data; /* line data */
39 struct Line *next; /* pointer to next line node */
40} Line;
41
42/* singly-linked list of lines */
43typedef struct {
44 int len; /* number of Lines */
45 Line *line; /* array fed to qsort */
46 Line *head; /* head of List */
47} List;
48
49
50/* Line methods */
51
52static const int max = 1024;
53
54static Line *
55line_new()
56{
57 char buffer[max];
58}
59
60
61/* Comparison */
62
63static int
64compare_ascii(const void *, const void *);
65
66static int
67compare_numeric(const void *, const void *);
68
69
70/* List */
71
72static void
73list_insert();
74
75static void
76list_sort();
77
78static void
79list_print();
80
81
82
83/*
84 * I need a list
85 * to insert lines into
86 * then I need to sort this list
87 * and finally print it
88 */
89
90int
91sort_main(int argc, char **argv)
92{
93 int i;
94 char opt;
95
96 /* default behaviour */
97
98 /* parse argv[] */
99 for (i = 1; i < argc; i++) {
100 if (argv[i][0] == '-') {
101 opt = argv[i][1];
102 switch (opt) {
103 case 'h':
104 usage(sort_usage);
105 break;
106 default:
107 fprintf(stderr, "sort: invalid option -- %c\n", opt);
108 usage(sort_usage);
109 }
110 } else {
111 break;
112 }
113 }
114
115 /* go through remaining args (if any) */
116 if (i >= argc) {
117
118 } else {
119 for ( ; i < argc; i++) {
120 }
121 }
122
123 exit(0);
124}
125
126/* $Date: 1999/12/21 20:00:35 $ */
127/* $Id: sort.c,v 1.1 1999/12/21 20:00:35 beppu Exp $ */