summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorErik Andersen2000-01-15 22:28:50 +0000
committerErik Andersen2000-01-15 22:28:50 +0000
commit3163821967821518cfa4c4315f775ec5301bb023 (patch)
treefe0c764cb41cc3ea86c3dcd270e48fa6a1abebcd /coreutils
parentb7cc49d992ed9a5a59261096012e0b4a811bb7f4 (diff)
downloadbusybox-3163821967821518cfa4c4315f775ec5301bb023.zip
busybox-3163821967821518cfa4c4315f775ec5301bb023.tar.gz
Sync up busybox with the latest and greatest. This is not stuff for
the Embedix release. -Erik
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/hostid.c28
-rw-r--r--coreutils/logname.c40
-rw-r--r--coreutils/tty.c42
-rw-r--r--coreutils/wc.c162
-rw-r--r--coreutils/whoami.c44
-rw-r--r--coreutils/yes.c41
6 files changed, 357 insertions, 0 deletions
diff --git a/coreutils/hostid.c b/coreutils/hostid.c
new file mode 100644
index 0000000..f8d5862
--- /dev/null
+++ b/coreutils/hostid.c
@@ -0,0 +1,28 @@
+/*
+ * Mini hostid implementation for busybox
+ *
+ * Copyright (C) 2000 Edward Betts <edward@debian.org>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <stdio.h>
+
+extern int hostid_main(int argc, char **argv) {
+ printf ("%lx\n", gethostid());
+ exit( TRUE);
+}
diff --git a/coreutils/logname.c b/coreutils/logname.c
new file mode 100644
index 0000000..5c8275a
--- /dev/null
+++ b/coreutils/logname.c
@@ -0,0 +1,40 @@
+/*
+ * Mini logname implementation for busybox
+ *
+ * Copyright (C) 2000 Edward Betts <edward@debian.org>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <stdio.h>
+
+static const char logname_usage[] = "logname\n\n"
+"Print the name of the current user.\n";
+
+extern int logname_main(int argc, char **argv) {
+ char *cp;
+
+ if (argc > 1) usage (logname_usage);
+
+ cp = getlogin ();
+ if (cp) {
+ puts (cp);
+ exit (TRUE);
+ }
+ fprintf (stderr, "%s: no login name\n", argv[0]);
+ exit (FALSE);
+}
diff --git a/coreutils/tty.c b/coreutils/tty.c
new file mode 100644
index 0000000..83abaff
--- /dev/null
+++ b/coreutils/tty.c
@@ -0,0 +1,42 @@
+/*
+ * Mini tty implementation for busybox
+ *
+ * Copyright (C) 2000 Edward Betts <edward@debian.org>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <stdio.h>
+#include <sys/types.h>
+
+static const char tty_usage[] = "tty\n\n"
+"Print the file name of the terminal connected to standard input.\n"
+"\t-s\tprint nothing, only return an exit status\n";
+
+extern int tty_main(int argc, char **argv) {
+ char *tty;
+
+ if (argc > 1) {
+ if (argv[1][0] != '-' || argv[1][1] != 's') usage (tty_usage);
+ }
+ else {
+ tty = ttyname (0);
+ if (tty) puts (tty);
+ else puts ("not a tty");
+ }
+ exit (isatty (0) ? TRUE : FALSE);
+}
diff --git a/coreutils/wc.c b/coreutils/wc.c
new file mode 100644
index 0000000..a1e2fca
--- /dev/null
+++ b/coreutils/wc.c
@@ -0,0 +1,162 @@
+/*
+ * Mini wc implementation for busybox
+ *
+ * by Edward Betts <edward@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <stdio.h>
+
+static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
+"Print line, word, and byte counts for each FILE, and a total line if\n"
+"more than one FILE is specified. With no FILE, read standard input.\n"
+"\t-c\tprint the byte counts\n"
+"\t-l\tprint the newline counts\n"
+"\t-L\tprint the length of the longest line\n"
+"\t-L\tprint the length of the longest line\n"
+"\t-w\tprint the word counts\n";
+
+static int total_lines, total_words, total_chars, max_length;
+static int print_lines, print_words, print_chars, print_length;
+
+void print_counts (int lines, int words, int chars, int length,
+ const char *name) {
+ char const *space = "";
+ if (print_lines) {
+ printf ("%7d", lines);
+ space = " ";
+ }
+ if (print_words) {
+ printf ("%s%7d", space, words);
+ space = " ";
+ }
+ if (print_chars) {
+ printf ("%s%7d", space, chars);
+ space = " ";
+ }
+ if (print_length)
+ printf ("%s%7d", space, length);
+ if (*name)
+ printf (" %s", name);
+ putchar ('\n');
+}
+
+static void wc_file(FILE *file, const char *name)
+{
+ int lines, words, chars, length;
+ int in_word = 0, linepos = 0;
+ int c;
+ lines = words = chars = length = 0;
+ while ((c = getc(file)) != EOF) {
+ chars++;
+ switch (c) {
+ case '\n':
+ lines++;
+ case '\r':
+ case '\f':
+ if (linepos > length)
+ length = linepos;
+ linepos = 0;
+ goto word_separator;
+ case '\t':
+ linepos += 8 - (linepos % 8);
+ goto word_separator;
+ case ' ':
+ linepos++;
+ case '\v':
+ word_separator:
+ if (in_word) {
+ in_word = 0;
+ words++;
+ }
+ break;
+ default:
+ linepos++;
+ in_word = 1;
+ break;
+ }
+ }
+ if (linepos > length)
+ length = linepos;
+ if (in_word)
+ words++;
+ print_counts (lines, words, chars, length, name);
+ total_lines += lines;
+ total_words += words;
+ total_chars += chars;
+ if (length > max_length)
+ max_length = length;
+ fclose(file);
+ fflush(stdout);
+}
+
+int wc_main(int argc, char **argv) {
+ FILE *file;
+ total_lines = total_words = total_chars = max_length = 0;
+ print_lines = print_words = print_chars = print_length = 0;
+
+ while (--argc && **(++argv) == '-') {
+ while (*++(*argv))
+ switch (**argv) {
+ case 'c':
+ print_chars = 1;
+ break;
+ case 'l':
+ print_lines = 1;
+ break;
+ case 'L':
+ print_length = 1;
+ break;
+ case 'w':
+ print_words = 1;
+ break;
+ default:
+ usage (wc_usage);
+ }
+ }
+
+ if (!print_lines && !print_words && !print_chars && !print_length)
+ print_lines = print_words = print_chars = 1;
+
+ if (argc == 0) {
+ wc_file(stdin, "");
+ exit(TRUE);
+ }
+ else if (argc == 1) {
+ file = fopen(*argv, "r");
+ if (file == NULL) {
+ perror(*argv);
+ exit(FALSE);
+ }
+ wc_file(file, *argv);
+ }
+ else {
+ while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
+ file = fopen(*argv, "r");
+ if (file == NULL) {
+ perror(*argv);
+ exit(FALSE);
+ }
+ wc_file(file, *argv);
+ argv++;
+ }
+ print_counts (total_lines, total_words, total_chars,
+ max_length, "total");
+ }
+ exit(TRUE);
+}
diff --git a/coreutils/whoami.c b/coreutils/whoami.c
new file mode 100644
index 0000000..7fd5d01
--- /dev/null
+++ b/coreutils/whoami.c
@@ -0,0 +1,44 @@
+/*
+ * Mini whoami implementation for busybox
+ *
+ * Copyright (C) 2000 Edward Betts <edward@debian.org>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <stdio.h>
+#include <pwd.h>
+
+static const char whoami_usage[] = "whoami\n\n"
+"Print the user name associated with the current effective user id.\n"
+"Same as id -un.\n";
+
+extern int whoami_main(int argc, char **argv) {
+ struct passwd *pw;
+ uid_t uid;
+
+ if (argc > 1) usage (whoami_usage);
+
+ uid = geteuid ();
+ pw = getpwuid (uid);
+ if (pw) {
+ puts (pw->pw_name);
+ exit (TRUE);
+ }
+ fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid);
+ exit (FALSE);
+}
diff --git a/coreutils/yes.c b/coreutils/yes.c
new file mode 100644
index 0000000..96d6257
--- /dev/null
+++ b/coreutils/yes.c
@@ -0,0 +1,41 @@
+/*
+ * Mini yes implementation for busybox
+ *
+ * Copyright (C) 2000 Edward Betts <edward@debian.org>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "internal.h"
+#include <stdio.h>
+
+extern int yes_main(int argc, char **argv) {
+ int i;
+ if (argc == 1)
+ while (1)
+ if (puts ("y") == EOF) {
+ perror ("yes");
+ exit(FALSE);
+ }
+
+ while (1)
+ for (i = 1; i < argc; i++)
+ if (fputs (argv[i], stdout) == EOF || putchar (i == argc - 1 ? '\n' : ' ') == EOF) {
+ perror ("yes");
+ exit(FALSE);
+ }
+ exit(TRUE);
+}