summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-26 05:21:02 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-26 05:21:02 +0000
commitc8fdb5638952993dcfe7950e4e2513811e8e9137 (patch)
tree197600c59963c14836a1ee12338484a56ab41269
parent8a8fbb87f70dbfbcee4d64b3d82831e2ccc6a587 (diff)
downloadbusybox-w32-c8fdb5638952993dcfe7950e4e2513811e8e9137.tar.gz
busybox-w32-c8fdb5638952993dcfe7950e4e2513811e8e9137.tar.bz2
busybox-w32-c8fdb5638952993dcfe7950e4e2513811e8e9137.zip
Stuf
-rw-r--r--coreutils/uname.c165
-rw-r--r--regexp.h49
-rw-r--r--uname.c165
3 files changed, 379 insertions, 0 deletions
diff --git a/coreutils/uname.c b/coreutils/uname.c
new file mode 100644
index 000000000..b54deb345
--- /dev/null
+++ b/coreutils/uname.c
@@ -0,0 +1,165 @@
1/* uname -- print system information
2 Copyright (C) 1989-1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18/* Option Example
19
20 -s, --sysname SunOS
21 -n, --nodename rocky8
22 -r, --release 4.0
23 -v, --version
24 -m, --machine sun
25 -a, --all SunOS rocky8 4.0 sun
26
27 The default behavior is equivalent to `-s'.
28
29 David MacKenzie <djm@gnu.ai.mit.edu> */
30
31/* Busyboxed by Erik Andersen */
32
33#include "internal.h"
34#include <stdio.h>
35#include <sys/types.h>
36#include <sys/utsname.h>
37
38#if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
39# include <sys/systeminfo.h>
40#endif
41
42
43static const char uname_usage[] =
44 "uname [OPTION]...\n"
45 "Print certain system information. With no OPTION, same as -s.\n"
46 "\t-a\tprint all information\n"
47 "\t-m\tthe machine (hardware) type\n"
48 "\t-n\tprint the machine's network node hostname\n"
49 "\t-r\tprint the operating system release\n"
50 "\t-s\tprint the operating system name\n"
51 "\t-p\tprint the host processor type\n"
52 "\t-v\tprint the operating system version\n";
53
54
55static void print_element(unsigned int mask, char *element);
56
57/* Values that are bitwise or'd into `toprint'. */
58/* Operating system name. */
59#define PRINT_SYSNAME 1
60
61/* Node name on a communications network. */
62#define PRINT_NODENAME 2
63
64/* Operating system release. */
65#define PRINT_RELEASE 4
66
67/* Operating system version. */
68#define PRINT_VERSION 8
69
70/* Machine hardware name. */
71#define PRINT_MACHINE 16
72
73 /* Host processor type. */
74#define PRINT_PROCESSOR 32
75
76/* Mask indicating which elements of the name to print. */
77static unsigned char toprint;
78
79
80int uname_main(int argc, char **argv)
81{
82 struct utsname name;
83 char processor[256];
84#if defined(__sparc__) && defined(__linux__)
85 char *fake_sparc = getenv("FAKE_SPARC");
86#endif
87
88 toprint = 0;
89
90 /* Parse any options */
91 //fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
92 while (--argc > 0 && **(++argv) == '-') {
93 while (*(++(*argv))) {
94 switch (**argv) {
95 case 's':
96 toprint |= PRINT_SYSNAME;
97 break;
98 case 'n':
99 toprint |= PRINT_NODENAME;
100 break;
101 case 'r':
102 toprint |= PRINT_RELEASE;
103 break;
104 case 'v':
105 toprint |= PRINT_VERSION;
106 break;
107 case 'm':
108 toprint |= PRINT_MACHINE;
109 break;
110 case 'p':
111 toprint |= PRINT_PROCESSOR;
112 break;
113 case 'a':
114 toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
115 PRINT_PROCESSOR | PRINT_VERSION |
116 PRINT_MACHINE);
117 break;
118 default:
119 usage(uname_usage);
120 }
121 }
122 }
123
124 if (toprint == 0)
125 toprint = PRINT_SYSNAME;
126
127 if (uname(&name) == -1)
128 perror("cannot get system name");
129
130#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
131 if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
132 perror("cannot get processor type");
133}
134
135#else
136 strcpy(processor, "unknown");
137#endif
138
139#if defined(__sparc__) && defined(__linux__)
140 if (fake_sparc != NULL
141 && (fake_sparc[0] == 'y'
142 || fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
143#endif
144
145 print_element(PRINT_SYSNAME, name.sysname);
146 print_element(PRINT_NODENAME, name.nodename);
147 print_element(PRINT_RELEASE, name.release);
148 print_element(PRINT_VERSION, name.version);
149 print_element(PRINT_MACHINE, name.machine);
150 print_element(PRINT_PROCESSOR, processor);
151
152 exit(TRUE);
153}
154
155/* If the name element set in MASK is selected for printing in `toprint',
156 print ELEMENT; then print a space unless it is the last element to
157 be printed, in which case print a newline. */
158
159static void print_element(unsigned int mask, char *element)
160{
161 if (toprint & mask) {
162 toprint &= ~mask;
163 printf("%s%c", element, toprint ? ' ' : '\n');
164 }
165}
diff --git a/regexp.h b/regexp.h
new file mode 100644
index 000000000..1e324e155
--- /dev/null
+++ b/regexp.h
@@ -0,0 +1,49 @@
1/*
2 * Busybox regexp header file
3 *
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
20 * Permission has been granted to redistribute this code under the GPL.
21 *
22 */
23#ifndef _REGEXP_H_
24#define _REGEXP_H_
25
26
27
28
29#define NSUBEXP 10
30typedef struct regexp {
31 char *startp[NSUBEXP];
32 char *endp[NSUBEXP];
33 int minlen; /* length of shortest possible match */
34 char first; /* first character, if known; else \0 */
35 char bol; /* boolean: must start at beginning of line? */
36 char program[1]; /* Unwarranted chumminess with compiler. */
37} regexp;
38
39
40
41extern regexp *regcomp(char* text);
42extern int regexec(struct regexp* re, char* str, int bol, int ignoreCase);
43extern void regsub(struct regexp* re, char* src, char* dst);
44
45extern int find_match(char *haystack, char *needle, int ignoreCase);
46
47#endif
48
49
diff --git a/uname.c b/uname.c
new file mode 100644
index 000000000..b54deb345
--- /dev/null
+++ b/uname.c
@@ -0,0 +1,165 @@
1/* uname -- print system information
2 Copyright (C) 1989-1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18/* Option Example
19
20 -s, --sysname SunOS
21 -n, --nodename rocky8
22 -r, --release 4.0
23 -v, --version
24 -m, --machine sun
25 -a, --all SunOS rocky8 4.0 sun
26
27 The default behavior is equivalent to `-s'.
28
29 David MacKenzie <djm@gnu.ai.mit.edu> */
30
31/* Busyboxed by Erik Andersen */
32
33#include "internal.h"
34#include <stdio.h>
35#include <sys/types.h>
36#include <sys/utsname.h>
37
38#if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
39# include <sys/systeminfo.h>
40#endif
41
42
43static const char uname_usage[] =
44 "uname [OPTION]...\n"
45 "Print certain system information. With no OPTION, same as -s.\n"
46 "\t-a\tprint all information\n"
47 "\t-m\tthe machine (hardware) type\n"
48 "\t-n\tprint the machine's network node hostname\n"
49 "\t-r\tprint the operating system release\n"
50 "\t-s\tprint the operating system name\n"
51 "\t-p\tprint the host processor type\n"
52 "\t-v\tprint the operating system version\n";
53
54
55static void print_element(unsigned int mask, char *element);
56
57/* Values that are bitwise or'd into `toprint'. */
58/* Operating system name. */
59#define PRINT_SYSNAME 1
60
61/* Node name on a communications network. */
62#define PRINT_NODENAME 2
63
64/* Operating system release. */
65#define PRINT_RELEASE 4
66
67/* Operating system version. */
68#define PRINT_VERSION 8
69
70/* Machine hardware name. */
71#define PRINT_MACHINE 16
72
73 /* Host processor type. */
74#define PRINT_PROCESSOR 32
75
76/* Mask indicating which elements of the name to print. */
77static unsigned char toprint;
78
79
80int uname_main(int argc, char **argv)
81{
82 struct utsname name;
83 char processor[256];
84#if defined(__sparc__) && defined(__linux__)
85 char *fake_sparc = getenv("FAKE_SPARC");
86#endif
87
88 toprint = 0;
89
90 /* Parse any options */
91 //fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
92 while (--argc > 0 && **(++argv) == '-') {
93 while (*(++(*argv))) {
94 switch (**argv) {
95 case 's':
96 toprint |= PRINT_SYSNAME;
97 break;
98 case 'n':
99 toprint |= PRINT_NODENAME;
100 break;
101 case 'r':
102 toprint |= PRINT_RELEASE;
103 break;
104 case 'v':
105 toprint |= PRINT_VERSION;
106 break;
107 case 'm':
108 toprint |= PRINT_MACHINE;
109 break;
110 case 'p':
111 toprint |= PRINT_PROCESSOR;
112 break;
113 case 'a':
114 toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
115 PRINT_PROCESSOR | PRINT_VERSION |
116 PRINT_MACHINE);
117 break;
118 default:
119 usage(uname_usage);
120 }
121 }
122 }
123
124 if (toprint == 0)
125 toprint = PRINT_SYSNAME;
126
127 if (uname(&name) == -1)
128 perror("cannot get system name");
129
130#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
131 if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
132 perror("cannot get processor type");
133}
134
135#else
136 strcpy(processor, "unknown");
137#endif
138
139#if defined(__sparc__) && defined(__linux__)
140 if (fake_sparc != NULL
141 && (fake_sparc[0] == 'y'
142 || fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
143#endif
144
145 print_element(PRINT_SYSNAME, name.sysname);
146 print_element(PRINT_NODENAME, name.nodename);
147 print_element(PRINT_RELEASE, name.release);
148 print_element(PRINT_VERSION, name.version);
149 print_element(PRINT_MACHINE, name.machine);
150 print_element(PRINT_PROCESSOR, processor);
151
152 exit(TRUE);
153}
154
155/* If the name element set in MASK is selected for printing in `toprint',
156 print ELEMENT; then print a space unless it is the last element to
157 be printed, in which case print a newline. */
158
159static void print_element(unsigned int mask, char *element)
160{
161 if (toprint & mask) {
162 toprint &= ~mask;
163 printf("%s%c", element, toprint ? ' ' : '\n');
164 }
165}