Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1101d23604 | ||
|
|
eef658068b | ||
|
|
2e397341d9 | ||
|
|
262dd039eb | ||
|
|
3fe7f9f20b | ||
|
|
a3e57ca700 | ||
|
|
f13df3752c | ||
|
|
9a8195cc03 | ||
|
|
b9167cb67f | ||
|
|
632bb57135 | ||
|
|
c366050a23 | ||
|
|
f29f797f54 | ||
|
|
0a64de9b4f | ||
|
|
229dd2b905 | ||
|
|
5d68857b9c | ||
|
|
a6c752201e | ||
|
|
91e581fa04 | ||
|
|
5a50def0f4 | ||
|
|
6e703034f4 | ||
|
|
26702fe191 | ||
|
|
e5b6c7dd9c | ||
|
|
4fd10fc73b | ||
|
|
200be97e36 | ||
|
|
5a728cfdfe | ||
|
|
3becdfc316 | ||
|
|
53642b066c | ||
|
|
9057b6a918 | ||
|
|
ab01ed12bd | ||
|
|
5e1189e187 | ||
|
|
95c1c1e05f | ||
|
|
d5ba77d03e | ||
|
|
50ed0676ad | ||
|
|
cbd6628c8c | ||
|
|
9cf3bfa7c1 | ||
|
|
b4f8606c05 | ||
|
|
08e7f75ba2 | ||
|
|
f17792ca9b | ||
|
|
61677feff7 | ||
|
|
62dc17a3b1 | ||
|
|
f0657d3229 | ||
|
|
a2685735b1 | ||
|
|
f3b3d17060 | ||
|
|
0817d1372c | ||
|
|
84e09e4437 | ||
|
|
ecd512453c | ||
|
|
5dd853ad2a | ||
|
|
6a34b539db | ||
|
|
825aead68b | ||
|
|
93d6513d93 | ||
|
|
7a4b719486 | ||
|
|
6bd3602988 | ||
|
|
c0dac18d6d | ||
|
|
e9fee653dc | ||
|
|
d4bc1fcad8 | ||
|
|
5661fe078e | ||
|
|
cbb0a4b40d | ||
|
|
b99ca13261 | ||
|
|
68a9ea4208 | ||
|
|
183da4ade1 | ||
|
|
983b51b17b | ||
|
|
3364d78b18 | ||
|
|
6acaa40f27 | ||
|
|
deea048bec | ||
|
|
1ad302ac90 | ||
|
|
e454fb68a3 | ||
|
|
298854f029 | ||
|
|
ec5bd90916 | ||
|
|
016ffe9307 | ||
|
|
0d068a2067 | ||
|
|
c053e41fa0 | ||
|
|
42094cdad5 | ||
|
|
1dbe340eba | ||
|
|
c7c634bd88 | ||
|
|
6c41c44898 | ||
|
|
531bcb6826 | ||
|
|
6273f655c8 | ||
|
|
161220c498 | ||
|
|
13456d1fcd | ||
|
|
d75af99529 | ||
|
|
a967e3c8f0 | ||
|
|
ce91732416 | ||
|
|
3522eb1ab3 | ||
|
|
269bba2514 | ||
|
|
47d3bb3b6d | ||
|
|
54969a1f64 | ||
|
|
692a4502b0 | ||
|
|
2ac2fae728 | ||
|
|
cbd0d625c7 | ||
|
|
06249f24f3 | ||
|
|
ea6b67de65 | ||
|
|
246cc6dddd | ||
|
|
e916d24805 | ||
|
|
9c5c29d442 | ||
|
|
65fc1c70f7 | ||
|
|
fb002d0df0 | ||
|
|
66be5e7e29 | ||
|
|
6437170cb3 | ||
|
|
029011b9ee | ||
|
|
7c4b2f3fe5 | ||
|
|
a51ecdd9e4 | ||
|
|
5b911ddd57 | ||
|
|
dc75a739ac | ||
|
|
f7c49ef2d1 | ||
|
|
3b9522f2af | ||
|
|
6e769df47d | ||
|
|
d07ee46919 | ||
|
|
fa4718efcf | ||
|
|
42387e4964 | ||
|
|
27fdd081ef | ||
|
|
e272915e1f | ||
|
|
bf5f009862 | ||
|
|
08c965a0a1 | ||
|
|
5e2b96345c | ||
|
|
9ffdaa647e | ||
|
|
5e1b2ca116 | ||
|
|
fa376f8034 | ||
|
|
c1dc5d9473 | ||
|
|
91f3df3c45 | ||
|
|
4d0543138e | ||
|
|
fb1793f03c | ||
|
|
07f5604046 | ||
|
|
d7ce5e7802 | ||
|
|
e132f4b09e | ||
|
|
e49d5ecbbe | ||
|
|
c0bf817bbc | ||
|
|
d0480c26ab | ||
|
|
31cf8e0056 | ||
|
|
79ac30da83 | ||
|
|
d7cd21aed5 | ||
|
|
fac10d7c59 | ||
|
|
50bc101b7d | ||
|
|
b332e779e6 | ||
|
|
04e97024e7 | ||
|
|
a6d0dbc86f | ||
|
|
8e759aa31f | ||
|
|
d7a44c76fe | ||
|
|
ce5b466bcc | ||
|
|
ccc7488615 | ||
|
|
de7965ca7e | ||
|
|
5cbdd712f5 | ||
|
|
3fe39dce5d | ||
|
|
bf3a838aac | ||
|
|
5509af7073 | ||
|
|
9bc7e89fc1 | ||
|
|
a4a8fd05f4 | ||
|
|
06936df164 | ||
|
|
de552874d2 | ||
|
|
f4acea8cf5 | ||
|
|
b2660c703d | ||
|
|
8ad12e32c8 | ||
|
|
4581b4cdd9 | ||
|
|
08fe43d3f9 | ||
|
|
a2f69e5485 | ||
|
|
46a4e76243 | ||
|
|
3a1b6be7d8 | ||
|
|
05100cd477 |
No files matched your search
@@ -1,8 +1,8 @@
|
||||
List of the authors of code contained in busybox.
|
||||
List of the authors of code contained in BusyBox.
|
||||
|
||||
If you should be listed here, or the description of
|
||||
what you have done needs more detail, or is incorect,
|
||||
_please_ let me know.
|
||||
If you have code in BusyBox, you should be listed here. If you should be
|
||||
listed, or the description of what you have done needs more detail, or is
|
||||
incorect, _please_ let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
@@ -16,7 +16,7 @@ Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
du, head, tee
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
@@ -28,6 +28,9 @@ Dave Cinege <dcinege@psychosis.com>
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
dirname, tr
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
@@ -37,4 +40,5 @@ Charles P. Wright <cpwright@villagenet.com>
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
@@ -1,49 +1,233 @@
|
||||
0.43
|
||||
* Major update to the provided documentation.
|
||||
* Busybox now includes a shell! It currently costs 7.5 k (plus an
|
||||
additional 2.5 k if you compile in command line editing). Handles
|
||||
job control, has the usual set of builtins, and does everything
|
||||
except for handling programming statements (if, while, etc...)
|
||||
* Busybox can now work perfectly when /proc is disabled, thereby
|
||||
saving a bunch of memory (kernel /proc support is not thin). This
|
||||
is done by making use of some nice kernel patches I wrote up to
|
||||
support the features that busybox requires and that /proc usually
|
||||
provides. To enable this, turn on BB_FEATURE_USE_DEVPS_PATCH and
|
||||
patch your kernel with the devps patch in the kernel-patches/
|
||||
directory.
|
||||
* Wrote basename, dirname, killall, and uptime.
|
||||
* tar has been completely rewritten by me. Both tar creation and
|
||||
extraction are now well behaved. Costs 7.6k with all optional
|
||||
tar features enabled, and 5k for just tar extraction support.
|
||||
* Added freeramdisk, which will free up all memory associated
|
||||
with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it>
|
||||
and then adjusted a bit by me.
|
||||
* Added tr from John Lombardo <john@deltanet.com>
|
||||
* Added echo and test (from me).
|
||||
* Added usleep contributed by Nicolas Pitre <nico@cam.org>
|
||||
* BusyBox's bss size has been majorly reduced (was 384668, is now 28740).
|
||||
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
|
||||
- When `tail' fails to open a file it now exits.
|
||||
- When `syslogd' is given the `-n' option it should still use
|
||||
fork() for running klogd.
|
||||
* nslookup types are now changed to u_int32_t (instead of uint32_t)
|
||||
changed per a patch from Pascal Bellard <pascal.bellard@ascend.com>
|
||||
* Fixed "du" so it gives the same answers as GNU "du" (busybox du used
|
||||
to count hard-linked files more then once). Many thanks to
|
||||
Friedrich Vedder <fwv@myrtle.lahn.de> for the fix.
|
||||
* Removed /proc dependancies for init and free (while maintaining
|
||||
exactly the same functionality). /proc takes up 90k of kernel
|
||||
space, so it is nice to avoid using it at all costs.
|
||||
* init no longer tries to mount /proc (unless there is less the 1 meg
|
||||
free). Use of /proc (or not) is policy that should be set up in
|
||||
/etc/fstab (or in hardcoded scripts), not in init.
|
||||
* Fixed rebooting when init runs as an initrd.
|
||||
* Fixes and updates from Karl M. Hegbloom <karlheg@debian.org>
|
||||
- update.c rewritten to look more like update-2.11
|
||||
- moveed the inode hash out of du.c and into utility.c to make
|
||||
it a common resource that can be used by other apps.
|
||||
- cp_mv.c now checks inodes to see if a source and dest are
|
||||
the same, and prints an error (instead of endlessly looping).
|
||||
- mv now attempts to do a rename, and will fall back to doing
|
||||
a copy only if the rename fails.
|
||||
- Syslogd now supports multiple concurrent connections
|
||||
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
|
||||
- Fixes to sort. Removed "-g", fixed and added "-r"
|
||||
- Fixes to the makefile for handling "strip"
|
||||
* An initial telnet implementation was added by
|
||||
Randolph Chung <tausq@debian.org>.
|
||||
* Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e")
|
||||
* ps now supports BB_FEATURE_AUTOWIDTH, and can adjust its width
|
||||
to match the terminal (defaults to width=79 when this is off).
|
||||
* ps now accepts (and ignores) all options except for "--help" (which
|
||||
as would be expected displays help).
|
||||
* Fixed mount'ing loop devices when the filesystem type was not
|
||||
specified. It used to revert to non-loop after the first try.
|
||||
* all mallocs now use xmalloc (and so are OOM error safe), and
|
||||
the common error handling saves a few bytes. Thanks to
|
||||
Bob Tinsley <bob@earthrise.demon.co.uk> for the patch.
|
||||
* Fix "+" parsing bug in date, from "Merle F. McClelland" <mfm@cts.com>.
|
||||
* Fix symlink following bug in chmod -R and friends.
|
||||
* Now allows SYSV style 'chown foo:bar' in addition to 'chown foo.bar'
|
||||
* Fixed a bug in the busybox globbing routine such that 'find /dir -name [i]'
|
||||
no longer segfaults.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
|
||||
0.42
|
||||
|
||||
* Fairly massive restructuring of umount.c to deal with remounting
|
||||
busy devices read-only. Adds a -r option to control that; it is
|
||||
optionally compiled in with BB_FEATURE_REMOUNT
|
||||
* Added a bunch of functions to mtab.c to interact with the
|
||||
{get,set,end}mntent interface; as it turns out, those functions do
|
||||
not appear to be re-entrant, and that causes a lot of problems with
|
||||
the way umount was originally written.
|
||||
* Makes init send TERM and KILL (instead of HUP and KILL) on reboot
|
||||
to be more consistent with sysvinit
|
||||
* Changes to init.c to use the new -r option to umount. Also increased
|
||||
the sleep time between the time the TERM and KILL signals are sent
|
||||
|
||||
- Randolph Chung
|
||||
|
||||
|
||||
* cp.c, mv.c: removed, replaced by cp_mv.c which has been
|
||||
extensively rewritten from the original cp.c.
|
||||
* Fixed cp and mv so if the source and destination are a the
|
||||
same directory it will print an error and continue.
|
||||
* Also added a warning message to the `mv' usage string saying that
|
||||
this is not GNU mv, and it will break hard links. cp also breaks
|
||||
hard links.
|
||||
* ln.c: implemented `-n' switch, no-deref symlinks.
|
||||
* include<sys/param.h>: and use PATH_MAX everywhere. busybox: File
|
||||
* name buffer overrun guards to prevent future crashes.
|
||||
- Always check exit status.
|
||||
- Purge all use of `creat()', replace with `open()'.
|
||||
* utility.c
|
||||
- recursiveAction was overriding the value of followLinks thus
|
||||
ignoring it.
|
||||
- isDirectory now takes a followLinks boolean, updated all callers
|
||||
- copyFile had the followLinks logic reversed.
|
||||
* messages.c: New file. Put common error message strings all in
|
||||
one place in an attempt to shrink the binary a little.
|
||||
|
||||
-Karl M. Hegbloom
|
||||
|
||||
|
||||
* changed fsck_minix.c to reduce its .bss size significantly
|
||||
-beppu -piptigger
|
||||
* Made tar creation support in busybox tar optional. You no longer
|
||||
* _have_ to put a "-" in front of tar options. Tar could inadvertently
|
||||
* change permissions and ownership on
|
||||
certain directories pointed to by symlinks.
|
||||
* Made grep and grep -h do the right thing wrt printing
|
||||
the file name (it failed to print files names in many cases).
|
||||
* Fix a namespace aliasing problem wereby if du was built in, the
|
||||
symlink for both du and dutmp would be installed, or then rm was
|
||||
built in, the symlinks for both rm and rmmod would be installed.
|
||||
* Added a closelog() to init.c after loging -- fix thanks to
|
||||
Taketoshi Sano <kgh12351@nifty.ne.jp>
|
||||
* Rewrote and simplified logger. Added the "-t" option, and made it
|
||||
behave itself a bit better.
|
||||
* Optional support contributed by Ben Collins <bcollins@debian.org>
|
||||
for the kernel init chroot patch by Werner Almesberger, which
|
||||
allows init to chroot to a new device, and umount the old one.
|
||||
* Fixed bug that wouldn't let one chown a symlink -- it would
|
||||
always dereference before. -beppu
|
||||
* Fixed a bug where init could have reference already freed memory.
|
||||
Found and fixed by Taketoshi Sano <kgh12351@nifty.ne.jp>
|
||||
* Several contributions from Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||
* Added (and documented) "-n" option for head
|
||||
* Cleanup for a number of usage messages -- also
|
||||
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||
* Cosmetic fix to busybox.c (Don't print a comma at the
|
||||
end of line if there are no more application names).
|
||||
* Fixed a stupid bug in "head" option handling ("head -n"
|
||||
would segfault).
|
||||
* Moved commonly used functions "xmalloc()" and "exit()"
|
||||
to utility.c (with proper #ifdef's).
|
||||
* Created a tiny tail implementation, removing -c, -q, -v, and making
|
||||
tail -f work only with a single file. This reduced tail from 6k to
|
||||
2.4k. The bigger/more featured tail can still be had by disabling
|
||||
BB_FEATURE_SIMPLE_TAIL in busybox.defs.h
|
||||
* Ping now falls back to doing the right thing if /etc/protocols
|
||||
turns up missing.
|
||||
* Fixed mount and umount. Previously they could leak loop device
|
||||
allocations, causing the system to quickly run out. Fix for umount
|
||||
by Ben Collins <bcollins@debian.org>, and mount was fixed by me.
|
||||
* ls formatting on eight charactor user names fixed by
|
||||
Randolph Chung <tausq@debian.org>.
|
||||
* cp could, when copying symlinks, change permissions of the
|
||||
files pointed to by the symlinks.
|
||||
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
|
||||
- `chown' with 1 argument displayed the error incorrectly
|
||||
- `fdflush', `length' and `printf' crashed if run without arguments
|
||||
- `fdflush' tried to flush itself using *argv
|
||||
- added "skip" and "seek" to dd.
|
||||
- ls no longer messus up output when combining files and
|
||||
directories on the command line
|
||||
* swapoff -a was not working. Now it is.
|
||||
* init did not cleanly unmount filesystems on reboot. Now it does.
|
||||
* "sed -ne s/foo/bar/" worked but "sed -n -e s/foo/bar/" didn't.
|
||||
Now both work.
|
||||
* Some architectures (PowerPc) assume chars are unsigned, so they could
|
||||
not distinguish between EOF and '\0xFF' in sed. Sed now uses ints.
|
||||
* Began converting error handling to use some common routines
|
||||
in utility.c
|
||||
* syslogd now has better message handling and ignores SIGHUP.
|
||||
* install.sh had a bug preventing installation to the specified
|
||||
target directory. Fix from Gilbert Coville <gilbert@mvista.com>
|
||||
* You can now spefify alternative strip commands -- change
|
||||
also from Gilbert Coville.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
0.41
|
||||
* New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed
|
||||
by Edward Betts <edward@debian.org>
|
||||
* Fixed a bug in both cp and mv preventing 'cp foo/README bar'
|
||||
type commands (file in a directory to another directory)
|
||||
from working.
|
||||
type commands (file in a directory to another directory) from
|
||||
working.
|
||||
* Fixed a logger bug that caused garbage to be written to the syslog
|
||||
(unless you used busybox syslog, which hid the bug). Thanks
|
||||
to Alex Holden <alex@linuxhacker.org> for the fix.
|
||||
* /bin/true and /bin/false were echoing a blank line when run. Now fixed.
|
||||
(unless you used busybox syslog, which hid the bug). Thanks to
|
||||
Alex Holden <alex@linuxhacker.org> for the fix.
|
||||
* /bin/true and /bin/false were echoing a blank line when run.
|
||||
Now fixed.
|
||||
* mkdir -p would print an error when asked to mkdir an existing dir
|
||||
with no interveining subdirectories.
|
||||
* Fixed "syslogd -O" so that it works.
|
||||
* Added -o loop option for mount, and support in umount for loop
|
||||
* Fixed "syslogd -O" so that it works. Added -o loop option for mount,
|
||||
* and support in umount for loop
|
||||
devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins
|
||||
<bcollins@debian.org>
|
||||
* Several fixes from Marco Pantaleoni <panta@prosa.it>
|
||||
* compile in fullWrite() not only if BB_TAR is defined, but also
|
||||
* Several fixes from Marco Pantaleoni <panta@prosa.it> compile in
|
||||
* fullWrite() not only if BB_TAR is defined, but also
|
||||
if BB_CP or BB_MV are (fullWrite() is referenced by copyFile())
|
||||
* add some compiler optimizations to further reduce executable size
|
||||
(as a side note, on my machines the largest code is generated by
|
||||
gcc 2.95.2 with -Os ! The smallest by plain gcc 2.7.2.3 with -O2
|
||||
-m386 ...)
|
||||
* Compile no longer fails if busybox.def.h defines BB_FEATURE_LINUXRC
|
||||
but not BB_INIT. (init_main used to be referenced, but not compiled)
|
||||
(as a side note, on my machines the largest code is generated
|
||||
by gcc 2.95.2 with -Os ! The smallest by plain gcc 2.7.2.3 with
|
||||
-O2 -m386 ...)
|
||||
* Compile now won't fail if busybox.def.h defines
|
||||
BB_FEATURE_LINUXRC but not BB_INIT. (init_main used to be
|
||||
referenced, but not compiled)
|
||||
* Fixed a bug in setting TERM for serial console support. TERM now
|
||||
defaults to "ansi" for serial consoles.
|
||||
* Fixed a bug in handling the CONSOLE env. variable for serial consoles.
|
||||
* Fixed a bug in handling the CONSOLE env. variable for serial
|
||||
* consoles.
|
||||
|
||||
-Erik Andersen, Jan 15, 2000
|
||||
|
||||
0.40
|
||||
* New Apps: sort, uniq. -beppu
|
||||
* New Apps: lsmod, rmmod -erik
|
||||
* New Apps: fbset contributed by Randolph Chung <tausq@debian.org>.
|
||||
* New App:: loadacm contributed by Peter Novodvorsky <petya@logic.ru>
|
||||
* New Apps: sort, uniq. -beppu New Apps: lsmod, rmmod -erik New Apps:
|
||||
* fbset contributed by Randolph Chung <tausq@debian.org>. New App::
|
||||
* loadacm contributed by Peter Novodvorsky <petya@logic.ru>
|
||||
for loading application character maps for Unicode fonts.
|
||||
* Major init re-work. init now supports inittab (slightly different
|
||||
but similar to sysvinit), allowing me to get all the policy out
|
||||
of init and into the conf file. It works just fine without inittab
|
||||
but similar to sysvinit), allowing me to get all the policy out of
|
||||
init and into the conf file. It works just fine without inittab
|
||||
being present, but if you dont like the defautl behavior you can
|
||||
now do something about it. Init is much cleaner as a result.
|
||||
* Fixed an bug in syslogd causing it to stop after 20 minutes. -erik
|
||||
* Fixed an embarrasing segfault in head -beppu
|
||||
* Fixed the embarrasing failure of 'logger -p'. -erik
|
||||
* Added the -s option to du -beppu
|
||||
* Fixed an embarrasing segfault in head -beppu Fixed the embarrasing
|
||||
* failure of 'logger -p'. -erik Added the -s option to du -beppu
|
||||
* Re-worked the source tree a bit so it will compile under glibc 2.0.7
|
||||
with the 2.0.x Linux kernel.
|
||||
* Added 'grep -q' thanks to a patch from "Konstantin Boldyshev"
|
||||
@@ -53,19 +237,19 @@
|
||||
* Fixed a bug where tar would set, and then clear SGID and SUID bits.
|
||||
* Fixed a bug where tar would not set the user and group on device
|
||||
special files.
|
||||
* Fixed a bug where tar would not restore the time to files.
|
||||
* Fixed a major security problem with tar -- it changed ownership
|
||||
* Fixed a bug where tar would not restore the time to files. Fixed a
|
||||
* major security problem with tar -- it changed ownership
|
||||
of any file pointed to by a symlink to 777 (like say libc....)
|
||||
Ouch!!!
|
||||
* cp and mv were very broken when moving directories. I have rewritten
|
||||
them so they should now work as expected.
|
||||
* sed now supports addresses (numeric or regexp, with negation) and
|
||||
has an append command, thanks to Marco Pantaleoni <panta@prosa.it>
|
||||
* Fixed dmesg. It wasn't parsing its options (-n or -s) properly.
|
||||
* Fixed dmesg. It wasn't parsing its options (-n or -s) properly.
|
||||
* Some cosmetic fixes to ls output formatting to make it behave more
|
||||
like GNU ls.
|
||||
* Fixed a stupid segfault in kill.
|
||||
* Several fixes from Friedrich Vedder <fwv@myrtle.lahn.de>:
|
||||
* Fixed a stupid segfault in kill. Several fixes from Friedrich Vedder
|
||||
* <fwv@myrtle.lahn.de>:
|
||||
- Added gunzip -t, removed gunzip.c dead code,
|
||||
- fixed several typos
|
||||
- Glibc 2.0.7 and libc5 compile fixes
|
||||
@@ -77,25 +261,27 @@
|
||||
0.39
|
||||
* New Apps: ping, hostname, and mkfifo contributed by Randolph Chung
|
||||
<tausq@debian.org>. 3 items off the TODO list!
|
||||
* I wrote free (just calls "cat /proc/meminfo").
|
||||
* Added tail, based on tail from GNU textutils-1.19, but adjusted
|
||||
to suit my evil purposes. Costs 6k. I'll make it smaller sometime.
|
||||
* I wrote free (just calls "cat /proc/meminfo"). Added tail, based on
|
||||
* tail from GNU textutils-1.19, but adjusted
|
||||
to suit my evil purposes. Costs 6k. I'll make it smaller
|
||||
sometime.
|
||||
* on reboot, init called 'umount -a -n', which caused errors
|
||||
when BB_MTAB was not enabled. Changed to 'umount -a',
|
||||
which does the right thing.
|
||||
when BB_MTAB was not enabled. Changed to 'umount -a', which does
|
||||
the right thing.
|
||||
* init will now try to run /sbin/getty if it is present (for easy
|
||||
integration with the about-to-be-released tinylogin.)
|
||||
* kill now behaves itself properly, added 'kill -l' to list signals
|
||||
* 'ls -l' was failing on long directories, since my_getid was leaking
|
||||
* kill now behaves itself properly, added 'kill -l' to list signals 'ls
|
||||
* -l' was failing on long directories, since my_getid was leaking
|
||||
one file descriptor per file. Oops.
|
||||
* Fixed rebooting from init. I'd accidently left some debugging code in
|
||||
* Fixed rebooting from init. I'd accidently left some debugging code
|
||||
* in
|
||||
which blocked reboots.
|
||||
* Fixed reboot, halt (and added poweroff) such that they handle it when
|
||||
init is not at PID 1 (like when running in an initrd).
|
||||
* Added a prelinary du implementation. Some parameter parsing
|
||||
stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>)
|
||||
* Implemented tee. -beppu
|
||||
* Implemented head. -beppu
|
||||
stuff still needs to be added. -beppu (John Beppu
|
||||
<beppu@lineo.com>)
|
||||
* Implemented tee. -beppu Implemented head. -beppu
|
||||
|
||||
-Erik Andersen, Dec 10, 1999
|
||||
|
||||
@@ -103,7 +289,8 @@
|
||||
* Fixed a segfault in 'umount -a' when a badly formed /etc/fstab
|
||||
file existed.
|
||||
* df will not exit on error, but will stat all mounted filesystems.
|
||||
* Fixed tar so uid/gid/permissions on extracted tarballs will be correct.
|
||||
* Fixed tar so uid/gid/permissions on extracted tarballs will be
|
||||
correct.
|
||||
* Fixed find -name so it properly uses shell wildcard patterns
|
||||
(i.e. `*', `?', and `[]') instead of regular expressions, which
|
||||
was causing some confusing and unexpected behavior.
|
||||
@@ -121,20 +308,25 @@
|
||||
0.37
|
||||
* Wrote a micro syslogd, and a logger util (to log things to the syslog
|
||||
from the command line or scripts) With both compiled in, costs 4k.
|
||||
* Fixed 'make install' so symlinks are installed in their proper locations.
|
||||
* Changed the build system slightly so that features can now be enabled
|
||||
or disabled from the busybox.defs.h header file, without trying to
|
||||
compile in a source file named after that featue (unless that file exists).
|
||||
* Several options are now moved into busybox.defs.h
|
||||
* Now 'rm -R' and 'rm -r' both work.
|
||||
* dd now properly handles input beyond 1 block from stdin.
|
||||
* Fixed a bug where tar unpacked everything a directories. Moved some code
|
||||
from createPath into mkdir where it belonged, thereby making tar work properly.
|
||||
* Fixed an off-by-one bug in cat. Given a list of file it wouldn't cat out the
|
||||
* Fixed 'make install' so symlinks are installed in their proper
|
||||
* locations. Changed the build system slightly so that features can
|
||||
* now be enabled
|
||||
or disabled from the busybox.defs.h header file, without trying to
|
||||
compile in a source file named after that featue (unless that file
|
||||
exists).
|
||||
* Several options are now moved into busybox.defs.h Now 'rm -R' and 'rm
|
||||
* -r' both work. dd now properly handles input beyond 1 block from
|
||||
* stdin. Fixed a bug where tar unpacked everything a directories.
|
||||
* Moved some code
|
||||
from createPath into mkdir where it belonged, thereby making tar
|
||||
work properly.
|
||||
* Fixed an off-by-one bug in cat. Given a list of file it wouldn't cat
|
||||
* out the
|
||||
last file in the list.
|
||||
* Fixed 'ls -ln' so numeric group/uid are presented properly, and fixed 'ls -l'
|
||||
so when uid/gid is not in /etc/{passwd,group} the numeric group/uid are
|
||||
presented properly.
|
||||
* Fixed 'ls -ln' so numeric group/uid are presented properly, and fixed
|
||||
* 'ls -l'
|
||||
so when uid/gid is not in /etc/{passwd,group} the numeric group/uid
|
||||
are presented properly.
|
||||
* Also added a TODO.
|
||||
|
||||
|
||||
@@ -143,46 +335,53 @@
|
||||
0.36
|
||||
* fixed dd so it properly defaults to stdin and stdout when no
|
||||
if= and of= are set (fix thanks to Eric Delaunay).
|
||||
* Don't try to close the file descriptor of a pipein tar. (fix also from
|
||||
* Don't try to close the file descriptor of a pipein tar. (fix also
|
||||
* from
|
||||
Eric Delaunay).
|
||||
* Made createPath be quiet (again thanks to Eric Delaunay).
|
||||
* If BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
|
||||
* Made createPath be quiet (again thanks to Eric Delaunay). If
|
||||
* BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
|
||||
command you define it as will be run if the init script exits.
|
||||
* Updated install.sh to make it more robust (thanks to Adam Di Carlo)
|
||||
* NFS support added to mount by Eric Delaunay. It costs 10k when compiled
|
||||
* NFS support added to mount by Eric Delaunay. It costs 10k when
|
||||
* compiled
|
||||
in, but that is still a big win for those that use NFS.
|
||||
* Made 'rm -f' be silent for non-existant files (thanks to Eric Delaunay).
|
||||
* changed zcat.c to gunzip.c. It now obeys the principle of least surprise
|
||||
and acts as god intended gunzip and zcat to act. They answer --help and
|
||||
obey the '-c' flag.
|
||||
* Fixed a bug in mv which caused it to not move files when the destination
|
||||
* Made 'rm -f' be silent for non-existant files (thanks to Eric
|
||||
* Delaunay). changed zcat.c to gunzip.c. It now obeys the principle
|
||||
* of least surprise
|
||||
and acts as god intended gunzip and zcat to act. They answer
|
||||
--help and obey the '-c' flag.
|
||||
* Fixed a bug in mv which caused it to not move files when the
|
||||
* destination
|
||||
was a directory.
|
||||
* Fixed a decimal-instead-of-octal bug causing mkdir to make directories
|
||||
* Fixed a decimal-instead-of-octal bug causing mkdir to make
|
||||
* directories
|
||||
with very wrong permissions.
|
||||
* chmod would overwrite file permissions instead of modifying them.
|
||||
Now it properly modifies permissions.
|
||||
* Init now sends warnings destined for the console to /dev/console to ensure
|
||||
they show up on whatever the active console it. Otherwise important
|
||||
messages (for example that the system is rebooting) were not seen when
|
||||
switched to a different VT.
|
||||
* Init now sends warnings destined for the console to /dev/console to
|
||||
* ensure
|
||||
they show up on whatever the active console it. Otherwise
|
||||
important messages (for example that the system is rebooting) were
|
||||
not seen when switched to a different VT.
|
||||
|
||||
-Erik Andersen, Nov 17, 1999
|
||||
|
||||
0.35
|
||||
* gzip now obeys the principle of least surprise and acts like god intended
|
||||
(i.e. it accepts a file name, answers --help, and obeys the '-c' flag
|
||||
and only then outputs to stdout).
|
||||
* gzip now obeys the principle of least surprise and acts like god
|
||||
* intended
|
||||
(i.e. it accepts a file name, answers --help, and obeys the '-c'
|
||||
flag and only then outputs to stdout).
|
||||
* Fixed more.c to compile autowidth on sparc and set initial winsize
|
||||
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric Delaunay.
|
||||
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric
|
||||
Delaunay.
|
||||
* Fixed tar so it now works as expected (it had TRUE/FALSE backwards)
|
||||
* tar now accepts --help
|
||||
* chmod, chown, and chgrp usage now works
|
||||
* General usage (i.e. --help) cleanups for most apps
|
||||
* umount now parses options correctly
|
||||
* tar can now unpack tarballs containing device special files,
|
||||
sockets, and fifos (though it can't pack them up) thanks
|
||||
to Matt Porter. Creating archives containing these is still
|
||||
left to the interested student.
|
||||
* tar now accepts --help chmod, chown, and chgrp usage now works
|
||||
* General usage (i.e. --help) cleanups for most apps umount now parses
|
||||
* options correctly tar can now unpack tarballs containing device
|
||||
* special files,
|
||||
sockets, and fifos (though it can't pack them up) thanks to Matt
|
||||
Porter. Creating archives containing these is still left to the
|
||||
interested student.
|
||||
* fixed up the license in more.c to properly point to Bruce Perens.
|
||||
|
||||
-Erik Andersen, Nov 11, 1999
|
||||
@@ -192,17 +391,17 @@
|
||||
Patch thanks to Eric Delaunay
|
||||
* init now properly handles sparc serial consoles and does a
|
||||
better job of finding the real console device rather than using
|
||||
/dev/console which doesn't support job control. Patch also
|
||||
thanks to Eric Delaunay.
|
||||
/dev/console which doesn't support job control. Patch also thanks
|
||||
to Eric Delaunay.
|
||||
* more started to read from stdin after the last file was finished, and
|
||||
options were not parsed correctly (fix thanks to Eric Delaunay).
|
||||
* more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on.
|
||||
* rm wouldn't remove a symlink unless the symlink was valid. This was
|
||||
a side effect of the busybox 0.32 recursiveAction() fix. Things
|
||||
a side effect of the busybox 0.32 recursiveAction() fix. Things
|
||||
should now work correctly.
|
||||
* grep wouldn't grep stdin. Now it does.
|
||||
* sed wouldn't sed stdin. Now it does.
|
||||
* sed was appending a \n to the end of lines with replacements.
|
||||
* grep wouldn't grep stdin. Now it does. sed wouldn't sed stdin. Now
|
||||
* it does. sed was appending a \n to the end of lines with
|
||||
* replacements.
|
||||
Now it doesn't do that.
|
||||
* ls -l now bypasses libc6 nss when displaying user/group names.
|
||||
Now uses my_getpwuid and my_getgrgid.
|
||||
@@ -223,45 +422,45 @@
|
||||
|
||||
0.32
|
||||
* More changes -- many thanks to Lineo for paying me to work on
|
||||
busybox. If you have any problems please let me know ASAP
|
||||
at andersen@lineo.com or andersee@debian.org
|
||||
busybox. If you have any problems please let me know ASAP at
|
||||
andersen@lineo.com or andersee@debian.org
|
||||
* usage() now prints the BusyBox version. This will help folks
|
||||
realize that they are not in Kansas anymore.
|
||||
* Fixed mkdir -m option so that it works.
|
||||
* kill segfaulted w/o any arguments. Now it doesn't do that.
|
||||
* kill wasn't properly accepting signal names. It does now.
|
||||
* Added new apps chvt and deallocvt (I should probably add open)
|
||||
* Major rewrite of init.c. Code is now readable by mere mortals IMHO.
|
||||
* Wrote sed -- weighs only 1.8k (5.8k with full regular expressions!).
|
||||
* Fixed a stupid seg-fault in sync
|
||||
* Fixed mount -- mount -a failed to parse and apply mount options
|
||||
* Fixed umount -n (patch thanks to Matthew Grant <grantma@anathoth.gen.nz>)
|
||||
* umount -a no longer umounts /proc
|
||||
* Added BB_MTAB, allowing (at the cost of ~1.5k and the need for a rw /etc)
|
||||
folks to use a real /etc/mtab file instead of a symlink to /proc/mounts.
|
||||
mount, and umount will add/remove entries and df will now use /etc/mtab
|
||||
if BB_MTAB is defined.
|
||||
* Fixed mkdir -m option so that it works. kill segfaulted w/o any
|
||||
* arguments. Now it doesn't do that. kill wasn't properly accepting
|
||||
* signal names. It does now. Added new apps chvt and deallocvt (I
|
||||
* should probably add open) Major rewrite of init.c. Code is now
|
||||
* readable by mere mortals IMHO. Wrote sed -- weighs only 1.8k (5.8k
|
||||
* with full regular expressions!). Fixed a stupid seg-fault in sync
|
||||
* Fixed mount -- mount -a failed to parse and apply mount options Fixed
|
||||
* umount -n (patch thanks to Matthew Grant <grantma@anathoth.gen.nz>)
|
||||
* umount -a no longer umounts /proc Added BB_MTAB, allowing (at the
|
||||
* cost of ~1.5k and the need for a rw /etc)
|
||||
folks to use a real /etc/mtab file instead of a symlink to
|
||||
/proc/mounts. mount, and umount will add/remove entries and df
|
||||
will now use /etc/mtab if BB_MTAB is defined.
|
||||
* Fixed a nice bug in recursiveAction() which caused it to infinitely
|
||||
hunt through /proc/../fd/* creating new file descriptors if it
|
||||
followed the /dev/fd link over to /proc. recursiveAction() now
|
||||
lstat's the file when followLinks==FALSE so it won't follow links
|
||||
as the name suggests. Fix thanks to Matt Porter <porter@debian.org>.
|
||||
followed the /dev/fd link over to /proc. recursiveAction() now
|
||||
lstat's the file when followLinks==FALSE so it won't follow links
|
||||
as the name suggests. Fix thanks to Matt Porter
|
||||
<porter@debian.org>.
|
||||
|
||||
|
||||
-Erik Andersen, Nov 4, 1999
|
||||
|
||||
0.31
|
||||
* I added a changelog for version 0.30.
|
||||
* adjusted find internals to make it smaller, and removed
|
||||
* I added a changelog for version 0.30. adjusted find internals to
|
||||
* make it smaller, and removed
|
||||
some redundancy.
|
||||
* Fixed a segfault in ps when /etc/passwd or /etc/group
|
||||
are absent. Now will warn you and carry on.
|
||||
* Added in optional _real_ regular expression support (to be
|
||||
the basis for a future sed utility). When compiled in
|
||||
it adds 3.9k, but makes grep much more capable.
|
||||
the basis for a future sed utility). When compiled in it adds
|
||||
3.9k, but makes grep much more capable.
|
||||
* Checked out using nftw(3) for recursive stuff, but unfortunatly
|
||||
it wasn't supported before GNU libc 2.1, and some folks use
|
||||
glibc 2.0.7 since it is much smaller than that latest and greatest.
|
||||
it wasn't supported before GNU libc 2.1, and some folks use glibc
|
||||
2.0.7 since it is much smaller than that latest and greatest.
|
||||
|
||||
-Erik Andersen, Oct 21, 1999
|
||||
|
||||
@@ -275,8 +474,8 @@
|
||||
* busybox can now invoke apps in two ways: via symlinks to the
|
||||
busybox binary, and as 'busybox [function] [arguments]...'
|
||||
* When invoked as busybox, the list of currently compiled in
|
||||
functions is printed out (no this is not bloat -- the list
|
||||
has to be there anyway to map invocation name to function).
|
||||
functions is printed out (no this is not bloat -- the list has
|
||||
to be there anyway to map invocation name to function).
|
||||
* busybox no longer parses command lines for apps or displays their
|
||||
usage info. Each app gets to handle (or not handle) this for
|
||||
itself.
|
||||
@@ -287,9 +486,9 @@
|
||||
* All shared code now lives in utility.c, and is properly
|
||||
ifdef'ed to be only included for those apps requiring it.
|
||||
* Eliminated struct FileInfo (the basis of monadic, dyadic, etc)
|
||||
so now each app has the function prototype of (da-dum):
|
||||
extern int foo_main(int argc, char** argv);
|
||||
which speeds integration of new apps.
|
||||
so now each app has the function prototype of (da-dum): extern
|
||||
int foo_main(int argc, char** argv); which speeds integration
|
||||
of new apps.
|
||||
* Adjusted the Makefile to make it easier to
|
||||
{en|dis}able debugging.
|
||||
* Changed default compiler optimization to -Os
|
||||
@@ -298,39 +497,43 @@
|
||||
App Changes:
|
||||
* To cope with the new app function prototype and the removal of
|
||||
monadic, dyadic, etc, the following apps were re-written:
|
||||
* cat - Works same as always.
|
||||
* chgrp, chmod, chown - rewrite. Combined into a single
|
||||
source file. Absorbed patches from Enrique Zanardi <ezanard@debian.org>
|
||||
that removes the dependency on libc6 libnss* libraries.
|
||||
* cat - Works same as always. chgrp, chmod, chown -
|
||||
* rewrite. Combined into a single
|
||||
source file. Absorbed patches from Enrique Zanardi
|
||||
<ezanard@debian.org> that removes the dependency on
|
||||
libc6 libnss* libraries.
|
||||
* cp - Can now do 'cp -a' can can copy devices,
|
||||
pipes, symlinks, as well as recursive or non-recursive dir copies.
|
||||
* fdflush - adjusted to remove dependancy on struct FileInfo.
|
||||
* find - Now includes some basic regexp matching
|
||||
pipes, symlinks, as well as recursive or non-recursive
|
||||
dir copies.
|
||||
* fdflush - adjusted to remove dependancy on struct
|
||||
* FileInfo. find - Now includes some basic regexp matching
|
||||
which will be the basic of a future mini-sed.
|
||||
* ln - Same functionality.
|
||||
* mkdir - Added -p flag to feature set.
|
||||
* mv - rewrite.
|
||||
* rm - Added -f flag to feature set.
|
||||
* rmdir - Same functionality.
|
||||
* swapon, swapoff - Combined into a single binary. No longer
|
||||
uses /etc/swaps. swap{on|off} -a uses /etc/fstab instead.
|
||||
* touch - Same functionality.
|
||||
* date - adjusted with a patch from Matthew Grant <grantma@anathoth.gen.nz>
|
||||
to accomodate glibc timezone support. I then ripped out GNU getopt.
|
||||
* mkswap -- new version merged from util-linux. Can now make >128Meg swaps.
|
||||
* Replaced the old and star, unstar, and tarcat with the tar
|
||||
implementation from sash. Now tar behaves as god intended
|
||||
it to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
|
||||
* dd -- rewritten. Can with with files, stdin, stdout.
|
||||
* Added the following new apps:
|
||||
* loadfont -- added from debian boot floppies
|
||||
* chroot -- added based on a patch from Paolo Molaro <lupus@lettere.unipd.it>
|
||||
* grep -- I just wrote it. Only matches simple strings
|
||||
* ps -- I just wrote it. Has _no_ options at all, but works.
|
||||
* fsck_minix, mkfs_minix -- added from util-linux, but I ripped out
|
||||
* ln - Same functionality. mkdir - Added -p flag to
|
||||
* feature set. mv - rewrite. rm - Added -f flag to
|
||||
* feature set. rmdir - Same functionality. swapon,
|
||||
* swapoff - Combined into a single binary. No longer
|
||||
uses /etc/swaps. swap{on|off} -a uses /etc/fstab
|
||||
instead.
|
||||
* touch - Same functionality. date - adjusted with a patch
|
||||
* from Matthew Grant <grantma@anathoth.gen.nz>
|
||||
to accomodate glibc timezone support. I then ripped out GNU
|
||||
getopt.
|
||||
* mkswap -- new version merged from util-linux. Can now make
|
||||
>128Meg swaps.
|
||||
* Replaced the old and star, unstar, and tarcat with the tar
|
||||
implementation from sash. Now tar behaves as god intended it
|
||||
to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
|
||||
* dd -- rewritten. Can with with files, stdin, stdout. Added the
|
||||
* following new apps: loadfont -- added from debian boot floppies
|
||||
* chroot -- added based on a patch from Paolo Molaro
|
||||
* <lupus@lettere.unipd.it> grep -- I just wrote it. Only matches
|
||||
* simple strings ps -- I just wrote it. Has _no_ options at all,
|
||||
* but works. fsck_minix, mkfs_minix -- added from util-linux, but
|
||||
* I ripped out
|
||||
internationalization and such to make them smaller.
|
||||
* sfdisk -- Added from util-linux (minus internationalization and such).
|
||||
* Probably some other changes that I forgot to document...
|
||||
* sfdisk -- Added from util-linux (minus
|
||||
* internationalization and such). Probably some other
|
||||
* changes that I forgot to document...
|
||||
|
||||
-Erik Andersen, Oct 20, 1999
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2000 Erik Andersen <andersee@debian.org>
|
||||
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@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
|
||||
@@ -15,115 +18,125 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
PROG := busybox
|
||||
VERSION := 0.43
|
||||
BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
|
||||
export VERSION
|
||||
|
||||
PROG=busybox
|
||||
VERSION=0.41
|
||||
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
||||
# Set the following to `true' to make a debuggable build.
|
||||
# Leave this set to `false' for production use.
|
||||
# eg: `make DODEBUG=true tests'
|
||||
DODEBUG = false
|
||||
|
||||
# Comment out the following to make a debuggable build
|
||||
# Leave this off for production use.
|
||||
DODEBUG=false
|
||||
# If you want a static binary, turn this on. I can't think
|
||||
# of many situations where anybody would ever want it static,
|
||||
# but...
|
||||
DOSTATIC=false
|
||||
# If you want a static binary, turn this on.
|
||||
DOSTATIC = false
|
||||
|
||||
#This will choke on a non-debian system
|
||||
ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
|
||||
# This will choke on a non-debian system
|
||||
ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
|
||||
|
||||
GCCMAJVERSION=$(shell $(CC) --version | sed -n "s/^\([^\.]*\).*/\1/p" )
|
||||
GCCMINVERSION=$(shell $(CC) --version | sed -n "s/^[^\.]*\.\([^\.]*\)[\.].*/\1/p" )
|
||||
GCCEGCS=$(shell $(CC) --version | sed -n "s/.*\(egcs\).*/\1/p" )
|
||||
CC = gcc
|
||||
|
||||
GCCSUPPORTSOPTSIZE=$(shell \
|
||||
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
|
||||
if ( test $(GCCMINVERSION) -ge 66 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
else \
|
||||
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
|
||||
GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
|
||||
|
||||
|
||||
GCCSUPPORTSOPTSIZE = $(shell \
|
||||
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
|
||||
if ( test $(GCCMINVERSION) -ge 66 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
else \
|
||||
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
fi; )
|
||||
|
||||
GCCISEGCS=$(shell \
|
||||
if ( test "x$(GCCEGCS)" == "xegcs" ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; )
|
||||
|
||||
EGCSEXTREMEFLAGS = -m386 -mcpu=i386 -march=i386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
|
||||
GCCEXTREMEFLAGS = -m386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
|
||||
|
||||
ifeq ($(GCCISEGCS), true)
|
||||
EXTREMEFLAGS = $(EGCSEXTREMEFLAGS)
|
||||
else
|
||||
EXTREMEFLAGS = $(GCCEXTREMEFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(GCCSUPPORTSOPTSIZE), true)
|
||||
OPTIMIZATION=-Os $(EXTREMEFLAGS)
|
||||
OPTIMIZATION = -Os
|
||||
else
|
||||
OPTIMIZATION=-O2 $(EXTREMEFLAGS)
|
||||
OPTIMIZATION = -O2
|
||||
endif
|
||||
|
||||
# Allow alternative stripping tools to be used...
|
||||
ifndef $(STRIPTOOL)
|
||||
STRIPTOOL = strip
|
||||
endif
|
||||
|
||||
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS+=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
|
||||
STRIP=
|
||||
LDFLAGS=
|
||||
CFLAGS += -Wall -g -D_GNU_SOURCE
|
||||
LDFLAGS =
|
||||
STRIP =
|
||||
else
|
||||
CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS= -s
|
||||
STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS = -s
|
||||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
|
||||
#Only staticly link when _not_ debugging
|
||||
ifeq ($(DOSTATIC),true)
|
||||
LDFLAGS+= --static
|
||||
LDFLAGS += --static
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
ifndef $(PREFIX)
|
||||
PREFIX=`pwd`/_install
|
||||
PREFIX = `pwd`/_install
|
||||
endif
|
||||
|
||||
LIBRARIES=
|
||||
OBJECTS=$(shell ./busybox.sh)
|
||||
CFLAGS+= -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
|
||||
LIBRARIES =
|
||||
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
|
||||
CFLAGS += -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
|
||||
ifdef BB_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT}
|
||||
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
|
||||
endif
|
||||
|
||||
all: busybox busybox.links
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
|
||||
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
|
||||
$(STRIP)
|
||||
|
||||
busybox.links:
|
||||
$(MAKE) -C docs
|
||||
|
||||
busybox.links: busybox.def.h
|
||||
- ./busybox.mkll | sort >$@
|
||||
|
||||
regexp.o nfsmount.o: %.o: %.h
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
|
||||
|
||||
test tests:
|
||||
cd tests && $(MAKE) all
|
||||
|
||||
clean:
|
||||
- rm -f $(PROG) busybox.links *~ *.o core
|
||||
- rm -f busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
- cd tests && $(MAKE) clean
|
||||
|
||||
distclean: clean
|
||||
- rm -f $(PROG)
|
||||
|
||||
$(OBJECTS): busybox.def.h internal.h Makefile
|
||||
- rm -f busybox
|
||||
- cd tests && $(MAKE) distclean
|
||||
|
||||
install: busybox busybox.links
|
||||
./install.sh $(PREFIX)
|
||||
|
||||
dist: release
|
||||
|
||||
release: distclean
|
||||
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/scripts/CVS busybox-$(VERSION)/docs/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
|
||||
|
||||
|
||||
dist release: distclean
|
||||
$(MAKE) -C docs
|
||||
cd ..; \
|
||||
rm -rf busybox-$(VERSION); \
|
||||
cp -a busybox busybox-$(VERSION); \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type d \
|
||||
-name CVS \
|
||||
-print \
|
||||
| xargs rm -rf; \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type f \
|
||||
-name .cvsignore \
|
||||
-print \
|
||||
| xargs rm -f; \
|
||||
\
|
||||
tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
|
||||
@@ -7,17 +7,17 @@ an editor such as "elvis-tiny" or "ae", and you have a working system.
|
||||
Busybox was begun to support the Debian Rescue/Install disks, but it
|
||||
also makes an excellent environment for any small or embedded system.
|
||||
|
||||
As of version 0.20 there is a version number. : ) Also as of version
|
||||
0.20, BB is now modularized to easily allow you to build of only the
|
||||
BB parts you need, thereby reducing binary size. To turn off unwanted
|
||||
Busybox components, simply edit the file busybox.def.h and comment out
|
||||
the parts you do not need using C++ style (//) comments.
|
||||
As of version 0.20 there is a version number. : ) Also as of version 0.20, BB
|
||||
is now modularized to easily allow you to build only the BB parts you need,
|
||||
thereby reducing binary size. To turn off unwanted Busybox components, simply
|
||||
edit the file busybox.def.h and comment out the parts you do not need using C++
|
||||
style (//) comments.
|
||||
|
||||
After the build is complete a busybox.links file is generated which is
|
||||
then used by 'make install' to create symlinks to the busybox binary
|
||||
for all compiled in functions. By default, 'make install' will place
|
||||
the symlink forest into `pwd`/_install unless you have defined the
|
||||
PREFIX environment variable.
|
||||
PREFIX environment variable (i.e. make PREFIX="/tmp/foo" install)
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
|
||||
@@ -15,14 +15,400 @@ around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
-----------
|
||||
|
||||
* Allow tar to create archives with sockets, devices, and other special files
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/nslookup/netstat
|
||||
* traceroute/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* killall
|
||||
* stty
|
||||
* tr
|
||||
* expr (maybe?) (ash builtin?)
|
||||
* cut
|
||||
* expr
|
||||
* wget (or whatever I call it)
|
||||
* tftp
|
||||
* ftp
|
||||
|
||||
|
||||
-----------------------
|
||||
|
||||
Add a compile option to turn off all the compiled in help
|
||||
and usage information. Some folks don't need or want it...
|
||||
|
||||
-----------------------
|
||||
|
||||
Compile with debugging on, run 'nm --size-sort ./busybox'
|
||||
and then start with the biggest things and make them smaller...
|
||||
|
||||
-----------------------
|
||||
|
||||
busybox.defs.h is too big and hard to follow.
|
||||
|
||||
Perhaps I need to add a better build system (like the Linux kernel?)
|
||||
|
||||
-----------------------
|
||||
|
||||
Feature request:
|
||||
|
||||
/bin/busybox --install -s which makes all links to commands that it
|
||||
can support (an optionnal -s should be used for symbolic links instead
|
||||
of hard links).
|
||||
|
||||
-----------------------
|
||||
|
||||
|
||||
> Have you ever thought of doig network logging in busybox syslogd ? It
|
||||
> would quite make sense on embedded systems... :)
|
||||
|
||||
So far I had not considered it. Basically, you wish to have
|
||||
messages from the embedded box logged to a remote network
|
||||
syslog box, right? I can see that this would be useful.
|
||||
I'll add this to the TODO list,
|
||||
|
||||
|
||||
-----------------------
|
||||
|
||||
|
||||
I think that the add_inode &c in utility.c needs to also stow the
|
||||
st_dev field, and that du.c should NOT call `reset_inode_list'
|
||||
because there can be hard links from inside one argv/ to inside
|
||||
another argv/. du.c probably ought to have an -x switch like GNU du
|
||||
does also...
|
||||
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
|
||||
Date: Fri, 25 Feb 2000 08:23:12 +0000 (GMT)
|
||||
From: Riley Williams <rhw@MemAlpha.CX>
|
||||
X-Sender: rhw@moo.cus.org.uk
|
||||
To: almesber@lrc.di.epfl.ch
|
||||
Cc: "Albert D. Cahalan" <acahalan@cs.uml.edu>,
|
||||
Linux Kernel <linux-kernel@vger.rutgers.edu>
|
||||
Subject: Re: What /proc should contain [was: /proc/driver/microcode]
|
||||
In-Reply-To: <20000224165245.A29790@lrc.di.epfl.ch>
|
||||
Message-ID: <Pine.LNX.4.21.0002250806220.8741-100000@moo.cus.org.uk>
|
||||
Sender: owner-linux-kernel@vger.rutgers.edu
|
||||
Precedence: bulk
|
||||
|
||||
Hi there.
|
||||
|
||||
>> Nope, most /proc access is does via programs written in C.
|
||||
|
||||
> That varies a lot from file to file. E.g. I haven't seen any
|
||||
> programs that are specificly designed to read /proc/atm/* yet,
|
||||
> and I know of only one (fuser) that reads /proc/mounts,
|
||||
> extracting only partial information (just to pick two examples
|
||||
> that I'm quite familiar with).
|
||||
|
||||
As a point of reference, here's a slightly tweaked analysis of the
|
||||
programs on the system I'm reading your mail on. Basically, I ran the
|
||||
following script...
|
||||
|
||||
Q> #!/bin/bash
|
||||
Q> function use() {
|
||||
Q> for Z in $* ; do
|
||||
Q> strings $Z | grep /proc | sed "s=^=$Z ="
|
||||
Q> done
|
||||
Q> }
|
||||
Q> use /{,s}bin/* /usr/{,s}bin/* | sort -u | tee proc-usage
|
||||
|
||||
...and then went through it removing comments and print format
|
||||
strings. Replace /proc with /dev and you'd soon have an equivalent
|
||||
list for that - although I can report that such is MUCH larger...
|
||||
|
||||
There are three programs therein that refer to /proc/mounts ...
|
||||
|
||||
/bin/mount
|
||||
/bin/umount
|
||||
/usr/bin/eject
|
||||
|
||||
...and, as you stated, none that refer to /proc/atm on this system.
|
||||
However, as this is a RedHat Linux 5.0 based system, that's not
|
||||
necessarily an up to date reference thereto...
|
||||
|
||||
Here's the list anyway...
|
||||
|
||||
/bin/kill /proc/%d/cmdline
|
||||
/bin/kill /proc/%d/stat
|
||||
|
||||
/bin/mount /proc/devices
|
||||
/bin/mount /proc/filesystems
|
||||
/bin/mount /proc/mounts
|
||||
|
||||
/bin/netstat /proc/net
|
||||
/bin/netstat /proc/net/appletalk
|
||||
/bin/netstat /proc/net/ax25
|
||||
/bin/netstat /proc/net/ax25_route
|
||||
/bin/netstat /proc/net/dev
|
||||
/bin/netstat /proc/net/ip_masquerade
|
||||
/bin/netstat /proc/net/ipx
|
||||
/bin/netstat /proc/net/ipx_route
|
||||
/bin/netstat /proc/net/netstat
|
||||
/bin/netstat /proc/net/nr
|
||||
/bin/netstat /proc/net/nr_neigh
|
||||
/bin/netstat /proc/net/nr_nodes
|
||||
/bin/netstat /proc/net/raw
|
||||
/bin/netstat /proc/net/route
|
||||
/bin/netstat /proc/net/rt_cache
|
||||
/bin/netstat /proc/net/snmp
|
||||
/bin/netstat /proc/net/tcp
|
||||
/bin/netstat /proc/net/udp
|
||||
/bin/netstat /proc/net/unix
|
||||
|
||||
/bin/umount /proc/devices
|
||||
/bin/umount /proc/mounts
|
||||
|
||||
/sbin/arp /proc/net/appletalk
|
||||
/sbin/arp /proc/net/arp
|
||||
/sbin/arp /proc/net/ax25
|
||||
/sbin/arp /proc/net/ipx
|
||||
/sbin/arp /proc/net/nr
|
||||
/sbin/arp /proc/net/unix
|
||||
|
||||
/sbin/cardctl /proc/devices
|
||||
|
||||
/sbin/cardmgr /proc/devices
|
||||
|
||||
/sbin/fdisk /proc/ide/%s/media
|
||||
/sbin/fdisk /proc/scsi/scsi
|
||||
|
||||
/sbin/getty /proc/version
|
||||
|
||||
/sbin/ifconfig /proc/net
|
||||
/sbin/ifconfig /proc/net/appletalk
|
||||
/sbin/ifconfig /proc/net/ax25
|
||||
/sbin/ifconfig /proc/net/dev
|
||||
/sbin/ifconfig /proc/net/ipx
|
||||
/sbin/ifconfig /proc/net/nr
|
||||
/sbin/ifconfig /proc/net/unix
|
||||
|
||||
/sbin/ifup /proc/sys/kernel/modprobe
|
||||
|
||||
/sbin/ipchains /proc/net/ip_fwchains
|
||||
/sbin/ipchains /proc/net/ip_fwnames
|
||||
/sbin/ipchains /proc/net/ip_masquerade
|
||||
/sbin/ipchains /proc/sys/net/ipv4/ip_forward
|
||||
|
||||
/sbin/ipmaddr /proc/net/dev_mcast
|
||||
/sbin/ipmaddr /proc/net/igmp
|
||||
/sbin/ipmaddr /proc/net/igmp6
|
||||
|
||||
/sbin/iptunnel /proc/net/dev
|
||||
|
||||
/sbin/killall5 /proc/%s/cmdline
|
||||
/sbin/killall5 /proc/%s/exe
|
||||
/sbin/killall5 /proc/%s/stat
|
||||
/sbin/killall5 /proc/version
|
||||
|
||||
/sbin/klogd /proc/kmsg
|
||||
|
||||
/sbin/lsmod /proc/modules
|
||||
|
||||
/sbin/modprobe /proc/modules
|
||||
|
||||
/sbin/pidof /proc/%s/cmdline
|
||||
/sbin/pidof /proc/%s/exe
|
||||
/sbin/pidof /proc/%s/stat
|
||||
/sbin/pidof /proc/version
|
||||
|
||||
/sbin/probe /proc/pci
|
||||
|
||||
/sbin/rarp /proc/net/ax25
|
||||
/sbin/rarp /proc/net/nr
|
||||
/sbin/rarp /proc/net/rarp
|
||||
|
||||
/sbin/rmmod /proc/modules
|
||||
|
||||
/sbin/rmmod.static /proc/modules
|
||||
|
||||
/sbin/route /proc/net/appletalk
|
||||
/sbin/route /proc/net/ax25
|
||||
/sbin/route /proc/net/ax25_route
|
||||
/sbin/route /proc/net/ipx
|
||||
/sbin/route /proc/net/ipx_route
|
||||
/sbin/route /proc/net/nr
|
||||
/sbin/route /proc/net/nr_neigh
|
||||
/sbin/route /proc/net/nr_nodes
|
||||
/sbin/route /proc/net/route
|
||||
/sbin/route /proc/net/rt_cache
|
||||
/sbin/route /proc/net/unix
|
||||
|
||||
/sbin/scsi_info /proc/scsi
|
||||
/sbin/scsi_info /proc/scsi/%s
|
||||
/sbin/scsi_info /proc/scsi/scsi
|
||||
|
||||
/sbin/slattach /proc/net/ax25
|
||||
/sbin/slattach /proc/net/nr
|
||||
|
||||
/sbin/swapoff /proc/swaps
|
||||
|
||||
/sbin/swapon /proc/swaps
|
||||
|
||||
/sbin/uugetty /proc/version
|
||||
|
||||
/usr/bin/dig /proc/
|
||||
/usr/bin/dig /proc/interrupts
|
||||
/usr/bin/dig /proc/meminfo
|
||||
/usr/bin/dig /proc/rtc
|
||||
/usr/bin/dig /proc/self/status
|
||||
/usr/bin/dig /proc/stat
|
||||
|
||||
/usr/bin/dnsquery /proc/
|
||||
/usr/bin/dnsquery /proc/interrupts
|
||||
/usr/bin/dnsquery /proc/meminfo
|
||||
/usr/bin/dnsquery /proc/rtc
|
||||
/usr/bin/dnsquery /proc/self/status
|
||||
/usr/bin/dnsquery /proc/stat
|
||||
|
||||
/usr/bin/eject /proc/mounts
|
||||
|
||||
/usr/bin/emacs /proc/loadavg
|
||||
|
||||
/usr/bin/fetchmail /proc/net/dev
|
||||
|
||||
/usr/bin/free /proc/meminfo
|
||||
|
||||
/usr/bin/gmake /proc/loadavg
|
||||
|
||||
/usr/bin/gpm-root /proc/loadavg
|
||||
/usr/bin/gpm-root /proc/meminfo
|
||||
|
||||
/usr/bin/host /proc/
|
||||
/usr/bin/host /proc/interrupts
|
||||
/usr/bin/host /proc/meminfo
|
||||
/usr/bin/host /proc/rtc
|
||||
/usr/bin/host /proc/self/status
|
||||
/usr/bin/host /proc/stat
|
||||
|
||||
/usr/bin/hoststat /proc/loadavg
|
||||
|
||||
/usr/bin/hwdiag /proc/cpuinfo
|
||||
/usr/bin/hwdiag /proc/pci
|
||||
/usr/bin/hwdiag /proc/scsi/scsi
|
||||
/usr/bin/hwdiag /proc/version
|
||||
|
||||
/usr/bin/lsdev /proc/dma
|
||||
/usr/bin/lsdev /proc/interrupts
|
||||
/usr/bin/lsdev /proc/ioports
|
||||
|
||||
/usr/bin/mailq /proc/loadavg
|
||||
|
||||
/usr/bin/make /proc/loadavg
|
||||
|
||||
/usr/bin/mcookie /proc/loadavg
|
||||
/usr/bin/mcookie /proc/stat
|
||||
|
||||
/usr/bin/newaliases /proc/loadavg
|
||||
|
||||
/usr/bin/nslookup /proc/
|
||||
/usr/bin/nslookup /proc/interrupts
|
||||
/usr/bin/nslookup /proc/meminfo
|
||||
/usr/bin/nslookup /proc/rtc
|
||||
/usr/bin/nslookup /proc/self/status
|
||||
/usr/bin/nslookup /proc/stat
|
||||
|
||||
/usr/bin/nsupdate /proc/
|
||||
/usr/bin/nsupdate /proc/interrupts
|
||||
/usr/bin/nsupdate /proc/meminfo
|
||||
/usr/bin/nsupdate /proc/rtc
|
||||
/usr/bin/nsupdate /proc/self/status
|
||||
/usr/bin/nsupdate /proc/stat
|
||||
|
||||
/usr/bin/pgp /proc/version
|
||||
/usr/bin/pgpe /proc/version
|
||||
/usr/bin/pgpk /proc/version
|
||||
/usr/bin/pgps /proc/version
|
||||
/usr/bin/pgpv /proc/version
|
||||
|
||||
/usr/bin/procinfo /proc/cmdline
|
||||
/usr/bin/procinfo /proc/devices
|
||||
/usr/bin/procinfo /proc/dma
|
||||
/usr/bin/procinfo /proc/filesystems
|
||||
/usr/bin/procinfo /proc/interrupts
|
||||
/usr/bin/procinfo /proc/loadavg
|
||||
/usr/bin/procinfo /proc/meminfo
|
||||
/usr/bin/procinfo /proc/modules
|
||||
/usr/bin/procinfo /proc/stat
|
||||
/usr/bin/procinfo /proc/uptime
|
||||
/usr/bin/procinfo /proc/version
|
||||
|
||||
/usr/bin/purgestat /proc/loadavg
|
||||
|
||||
/usr/bin/screen /proc/loadavg
|
||||
|
||||
/usr/bin/strace /proc/%d/stat
|
||||
|
||||
/usr/bin/top /proc/cpuinfo
|
||||
/usr/bin/top /proc/meminfo
|
||||
/usr/bin/top /proc/stat
|
||||
|
||||
/usr/bin/vmstat /proc/%s/stat
|
||||
/usr/bin/vmstat /proc/meminfo
|
||||
/usr/bin/vmstat /proc/stat
|
||||
|
||||
/usr/sbin/atd /proc/loadavg
|
||||
|
||||
/usr/sbin/dnskeygen /proc/
|
||||
/usr/sbin/dnskeygen /proc/interrupts
|
||||
/usr/sbin/dnskeygen /proc/meminfo
|
||||
/usr/sbin/dnskeygen /proc/rtc
|
||||
/usr/sbin/dnskeygen /proc/self/status
|
||||
/usr/sbin/dnskeygen /proc/stat
|
||||
|
||||
/usr/sbin/fuser /proc/%d/stat
|
||||
/usr/sbin/fuser /proc/net/%s
|
||||
/usr/sbin/fuser /proc/net/unix
|
||||
|
||||
/usr/sbin/in.identd /proc/net/tcp
|
||||
|
||||
/usr/sbin/irpd /proc/
|
||||
/usr/sbin/irpd /proc/interrupts
|
||||
/usr/sbin/irpd /proc/meminfo
|
||||
/usr/sbin/irpd /proc/rtc
|
||||
/usr/sbin/irpd /proc/self/status
|
||||
/usr/sbin/irpd /proc/stat
|
||||
|
||||
/usr/sbin/named /proc/
|
||||
/usr/sbin/named /proc/interrupts
|
||||
/usr/sbin/named /proc/meminfo
|
||||
/usr/sbin/named /proc/rtc
|
||||
/usr/sbin/named /proc/self/status
|
||||
/usr/sbin/named /proc/stat
|
||||
|
||||
/usr/sbin/named-xfer /proc/
|
||||
/usr/sbin/named-xfer /proc/interrupts
|
||||
/usr/sbin/named-xfer /proc/meminfo
|
||||
/usr/sbin/named-xfer /proc/rtc
|
||||
/usr/sbin/named-xfer /proc/self/status
|
||||
/usr/sbin/named-xfer /proc/stat
|
||||
|
||||
/usr/sbin/readprofile /proc/profile
|
||||
|
||||
/usr/sbin/rwhod /proc/loadavg
|
||||
/usr/sbin/rwhod /proc/uptime
|
||||
|
||||
/usr/sbin/sendmail /proc/loadavg
|
||||
|
||||
/usr/sbin/setconsole /proc/openprom/options
|
||||
/usr/sbin/setconsole /proc/openprom/options/${console}-mode
|
||||
/usr/sbin/setconsole /proc/openprom/options/input-device
|
||||
/usr/sbin/setconsole /proc/openprom/options/output-device
|
||||
|
||||
Best wishes from Riley.
|
||||
|
||||
* Copyright (C) 1999, Memory Alpha Systems.
|
||||
* All rights and wrongs reserved.
|
||||
|
||||
+----------------------------------------------------------------------+
|
||||
| There is something frustrating about the quality and speed of Linux |
|
||||
| development, ie., the quality is too high and the speed is too high, |
|
||||
| in other words, I can implement this XXXX feature, but I bet someone |
|
||||
| else has already done so and is just about to release their patch. |
|
||||
+----------------------------------------------------------------------+
|
||||
* http://www.memalpha.cx/Linux/Kernel/
|
||||
|
||||
|
||||
-
|
||||
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
|
||||
the body of a message to majordomo@vger.rutgers.edu
|
||||
Please read the FAQ at http://www.tux.org/lkml/
|
||||
|
||||
+296
-227
@@ -1,12 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
@@ -16,328 +13,400 @@ static int been_there_done_that = 0;
|
||||
* replacement may be in order
|
||||
*/
|
||||
#if 0
|
||||
void exit (int status) __attribute__ ((noreturn));
|
||||
void exit (int status) { _exit(status); };
|
||||
void abort (void) __attribute__ ((__noreturn__));
|
||||
void abort (void) { _exit(0); };
|
||||
int atexit (void (*__func) (void)) { _exit(0); };
|
||||
void exit(int status) __attribute__ ((noreturn));
|
||||
void exit(int status)
|
||||
{
|
||||
_exit(status);
|
||||
};
|
||||
void abort(void) __attribute__ ((__noreturn__));
|
||||
void abort(void)
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
int atexit(void (*__func) (void))
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#ifdef BB_BUSYBOX
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CP //bin
|
||||
{"cp", cp_main},
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MV //bin
|
||||
{"mv", mv_main},
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#ifdef BB_MATH
|
||||
{"math", math_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#ifdef BB_MNC
|
||||
{"mnc", mnc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
char *s;
|
||||
char *name;
|
||||
const struct Applet *a = applets;
|
||||
|
||||
while (*s != '\0') {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit (busybox_main(argc, argv));
|
||||
|
||||
*argv = name;
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit(busybox_main(argc, argv));
|
||||
}
|
||||
|
||||
|
||||
int busybox_main(int argc, char **argv)
|
||||
{
|
||||
int col=0;
|
||||
argc--;
|
||||
argv++;
|
||||
int col = 0;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
while (a->name != 0) {
|
||||
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
|
||||
if (col>60) {
|
||||
fprintf(stderr, ",\n");
|
||||
col=0;
|
||||
}
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
|
||||
(a++)->name);
|
||||
if (col > 60 && a->name != 0) {
|
||||
fprintf(stderr, ",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+11
-7
@@ -1,15 +1,19 @@
|
||||
#!/bin/sh
|
||||
#Make busybox links list file
|
||||
# Make busybox links list file.
|
||||
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||
for j in $i; do
|
||||
if [ -z $j ] ; then
|
||||
continue;
|
||||
fi;
|
||||
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
|
||||
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
|
||||
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
|
||||
done;
|
||||
done
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
# I added in the extra "ls" so only source files that
|
||||
# actually exist will show up in the compile list.
|
||||
ls -1 ` \
|
||||
gcc -E -dM busybox.def.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
+2
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
if [ "$1" = "" ]; then
|
||||
echo "No installation directory, aborting."
|
||||
exit 1;
|
||||
fi
|
||||
@@ -15,6 +15,7 @@ for i in $h ; do
|
||||
ln -fs /bin/busybox $1$i
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
mkdir -p $1/bin
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
+1237
-1247
File diff suppressed because it is too large.
Load diff
+1574
-1468
File diff suppressed because it is too large.
Load diff
+910
-1156
File diff suppressed because it is too large.
Load diff
+45
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 basename_main(int argc, char **argv)
|
||||
{
|
||||
char* s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
@@ -16,328 +13,400 @@ static int been_there_done_that = 0;
|
||||
* replacement may be in order
|
||||
*/
|
||||
#if 0
|
||||
void exit (int status) __attribute__ ((noreturn));
|
||||
void exit (int status) { _exit(status); };
|
||||
void abort (void) __attribute__ ((__noreturn__));
|
||||
void abort (void) { _exit(0); };
|
||||
int atexit (void (*__func) (void)) { _exit(0); };
|
||||
void exit(int status) __attribute__ ((noreturn));
|
||||
void exit(int status)
|
||||
{
|
||||
_exit(status);
|
||||
};
|
||||
void abort(void) __attribute__ ((__noreturn__));
|
||||
void abort(void)
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
int atexit(void (*__func) (void))
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#ifdef BB_BUSYBOX
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CP //bin
|
||||
{"cp", cp_main},
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MV //bin
|
||||
{"mv", mv_main},
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#ifdef BB_MATH
|
||||
{"math", math_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#ifdef BB_MNC
|
||||
{"mnc", mnc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
char *s;
|
||||
char *name;
|
||||
const struct Applet *a = applets;
|
||||
|
||||
while (*s != '\0') {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit (busybox_main(argc, argv));
|
||||
|
||||
*argv = name;
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit(busybox_main(argc, argv));
|
||||
}
|
||||
|
||||
|
||||
int busybox_main(int argc, char **argv)
|
||||
{
|
||||
int col=0;
|
||||
argc--;
|
||||
argv++;
|
||||
int col = 0;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
while (a->name != 0) {
|
||||
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
|
||||
if (col>60) {
|
||||
fprintf(stderr, ",\n");
|
||||
col=0;
|
||||
}
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
|
||||
(a++)->name);
|
||||
if (col > 60 && a->name != 0) {
|
||||
fprintf(stderr, ",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+140
-33
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
@@ -6,72 +7,75 @@
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
#define BB_BUSYBOX
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
#define BB_CHROOT
|
||||
#define BB_CHVT
|
||||
#define BB_CLEAR
|
||||
#define BB_CP
|
||||
#define BB_CP_MV
|
||||
#define BB_DATE
|
||||
#define BB_DD
|
||||
#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
//#define BB_DUTMP
|
||||
#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_ECHO
|
||||
#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FREERAMDISK
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
//#define BB_HALT
|
||||
#define BB_HALT
|
||||
#define BB_HEAD
|
||||
//#define BB_HOSTID
|
||||
#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
#define BB_INIT
|
||||
// Don't turn BB_INSMOD on. It doesn't work.
|
||||
// Don't bother turning BB_INSMOD on. It doesn't work yet.
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LENGTH
|
||||
#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
//#define BB_LOADKMAP
|
||||
//#define BB_LOGGER
|
||||
#define BB_LOADACM
|
||||
#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
#define BB_LOGNAME
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
#define BB_MAKEDEVS
|
||||
#define BB_MKFS_MINIX
|
||||
//#define BB_MATH
|
||||
#define BB_MATH
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
#define BB_MKFIFO
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MNC
|
||||
#define BB_MNC
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
#define BB_NFSMOUNT
|
||||
//#define BB_MT
|
||||
//#define BB_MTAB
|
||||
#define BB_MV
|
||||
#define BB_MT
|
||||
#define BB_NSLOOKUP
|
||||
#define BB_PING
|
||||
#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
#define BB_REBOOT
|
||||
#define BB_REGEXP
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
#define BB_RMMOD
|
||||
#define BB_SED
|
||||
//#define BB_SFDISK
|
||||
#define BB_SFDISK
|
||||
#define BB_SH
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
#define BB_SWAPONOFF
|
||||
@@ -80,9 +84,15 @@
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
#define BB_TEE
|
||||
#define BB_TEST
|
||||
// Don't bother turning BB_TELNET on. It doesn't work properly yet.
|
||||
//#define BB_TELNET
|
||||
#define BB_TOUCH
|
||||
#define BB_TR
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
#define BB_UPTIME
|
||||
#define BB_USLEEP
|
||||
#define BB_WC
|
||||
#define BB_WHOAMI
|
||||
#define BB_UMOUNT
|
||||
@@ -94,21 +104,35 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
// Don't turn BB_UTILITY off. It contains support code
|
||||
// that compiles to 0 if everything else if turned off.
|
||||
#define BB_UTILITY
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, devmtab,
|
||||
// etc kernel drivers, thereby eliminating the need for
|
||||
// the /proc filesystem and thereby saving lots and lots
|
||||
// memory for more important things.
|
||||
// You can't use this and USE_PROCFS at the same time...
|
||||
// (BTW, I emailed Linus and this patch will not be going into the stock kernel)
|
||||
//#define BB_FEATURE_USE_DEVPS_PATCH
|
||||
//
|
||||
// enable features that use the /proc filesystem (apps that
|
||||
// break without this will tell you on compile)...
|
||||
// You can't use this and BB_FEATURE_USE_DEVPS_PATCH
|
||||
// at the same time...
|
||||
#define BB_FEATURE_USE_PROCFS
|
||||
//
|
||||
// Enable full regular expressions. This adds about
|
||||
// 4k. When this is off, things that would normally
|
||||
// use regualr expressions (like grep) will just use
|
||||
// normal strings.
|
||||
#define BB_FEATURE_FULL_REGULAR_EXPRESSIONS
|
||||
//
|
||||
// Use only simple command help
|
||||
#define BB_FEATURE_TRIVIAL_HELP
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
@@ -116,23 +140,106 @@
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames (bypasses libc6 NSS) for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
//#define BB_SIMPLE_PING
|
||||
////
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
//#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
//
|
||||
// Allow init to permenently chroot, and umount the old root fs
|
||||
// just like an initrd does. Requires a kernel patch by Werner Almesberger.
|
||||
// ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz
|
||||
//#define BB_FEATURE_INIT_CHROOT
|
||||
//
|
||||
//Make sure nothing is printed to the console on boot
|
||||
#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
//Simple tail implementation (2k vs 6k for the full one). Still
|
||||
//provides 'tail -f' support -- but for only one file at a time.
|
||||
#define BB_FEATURE_SIMPLE_TAIL
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for remounting filesystems
|
||||
#define BB_FEATURE_REMOUNT
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
// Enable support for "--exclude" for excluding files
|
||||
#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
//// Enable reverse sort
|
||||
#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
// Enable command line editing in the shell
|
||||
#define BB_FEATURE_SH_COMMAND_EDITING
|
||||
//
|
||||
// Enable tab completion in the shell (not yet
|
||||
// working very well -- so don't turn this on)
|
||||
//#define BB_FEATURE_SH_TAB_COMPLETION
|
||||
//
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------
|
||||
// Nothing beyond this point should ever be touched by
|
||||
// mere mortals so leave this stuff alone.
|
||||
//
|
||||
#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
#define BB_MTAB
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_FULL_REGULAR_EXPRESSIONS && (defined BB_SED || defined BB_GREP )
|
||||
#define BB_REGEXP
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_SH_COMMAND_EDITING && defined BB_SH
|
||||
#define BB_CMDEDIT
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_KILLALL
|
||||
#ifndef BB_KILL
|
||||
#define BB_KILL
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
#ifndef BB_INIT
|
||||
#define BB_INIT
|
||||
#define BB_LINUXRC
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_GZIP
|
||||
#ifndef BB_GUNZIP
|
||||
#define BB_GUNZIP
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
+11
-7
@@ -1,15 +1,19 @@
|
||||
#!/bin/sh
|
||||
#Make busybox links list file
|
||||
# Make busybox links list file.
|
||||
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||
for j in $i; do
|
||||
if [ -z $j ] ; then
|
||||
continue;
|
||||
fi;
|
||||
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
|
||||
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
|
||||
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
|
||||
done;
|
||||
done
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
# I added in the extra "ls" so only source files that
|
||||
# actually exist will show up in the compile list.
|
||||
ls -1 ` \
|
||||
gcc -E -dM busybox.def.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.41
|
||||
Version: 0.43
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini Cat implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -24,36 +25,45 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static void print_file( FILE *file)
|
||||
static void print_file(FILE * file)
|
||||
{
|
||||
int c;
|
||||
while ((c = getc(file)) != EOF)
|
||||
putc(c, stdout);
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
int c;
|
||||
|
||||
while ((c = getc(file)) != EOF)
|
||||
putc(c, stdout);
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
extern int cat_main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
FILE *file;
|
||||
|
||||
if (argc==1) {
|
||||
print_file( stdin);
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage ("cat [file ...]\n");
|
||||
}
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv) ) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
if (argc == 1) {
|
||||
print_file(stdin);
|
||||
exit(TRUE);
|
||||
}
|
||||
print_file( file);
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [file ...]\n");
|
||||
}
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv)) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+132
-97
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini chown/chmod/chgrp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -21,17 +22,21 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_option
|
||||
#include "messages.c"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static uid_t uid=-1;
|
||||
static gid_t gid=-1;
|
||||
static uid_t uid = -1;
|
||||
static gid_t gid = -1;
|
||||
static int whichApp;
|
||||
static char* invocationName=NULL;
|
||||
static char* theMode=NULL;
|
||||
static char *invocationName = NULL;
|
||||
static char *theMode = NULL;
|
||||
|
||||
|
||||
#define CHGRP_APP 1
|
||||
@@ -39,117 +44,147 @@ static char* theMode=NULL;
|
||||
#define CHMOD_APP 3
|
||||
|
||||
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
|
||||
"Change the group membership of each FILE to GROUP.\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chown_usage[] = "chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
|
||||
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chmod_usage[] = "chmod [-R] MODE[,MODE]... FILE...\n\n"
|
||||
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
"one or more of the letters rwxst.\n\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
|
||||
"Change the group membership of each FILE to GROUP.\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chown_usage[] =
|
||||
"chown [OPTION]... OWNER[<.|:>[GROUP] FILE...\n\n"
|
||||
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chmod_usage[] =
|
||||
"chmod [-R] MODE[,MODE]... FILE...\n\n"
|
||||
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
|
||||
"one or more of the letters rwxst.\n\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
switch (whichApp) {
|
||||
switch (whichApp) {
|
||||
case CHGRP_APP:
|
||||
case CHOWN_APP:
|
||||
if (chown(fileName, (whichApp==CHOWN_APP)? uid : statbuf->st_uid,
|
||||
(gid==-1)? statbuf->st_gid : gid) == 0) {
|
||||
return( TRUE);
|
||||
}
|
||||
break;
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
if (lchown
|
||||
(fileName, (whichApp == CHOWN_APP) ? uid : statbuf->st_uid,
|
||||
(gid == -1) ? statbuf->st_gid : gid) == 0)
|
||||
#else
|
||||
if (chown
|
||||
(fileName, (whichApp == CHOWN_APP) ? uid : statbuf->st_uid,
|
||||
(gid == -1) ? statbuf->st_gid : gid) == 0)
|
||||
#endif
|
||||
{
|
||||
return (TRUE);
|
||||
}
|
||||
break;
|
||||
case CHMOD_APP:
|
||||
/* Parse the specified modes */
|
||||
if ( parse_mode(theMode, &(statbuf->st_mode)) == FALSE ) {
|
||||
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, theMode);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (chmod(fileName, statbuf->st_mode) == 0)
|
||||
return( TRUE);
|
||||
break;
|
||||
}
|
||||
perror(fileName);
|
||||
return( FALSE);
|
||||
/* Parse the specified modes */
|
||||
if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) {
|
||||
fatalError( "%s: unknown mode: %s\n", invocationName, theMode);
|
||||
}
|
||||
if (chmod(fileName, statbuf->st_mode) == 0)
|
||||
return (TRUE);
|
||||
break;
|
||||
}
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
{
|
||||
int recursiveFlag=FALSE;
|
||||
char *groupName;
|
||||
const char *appUsage;
|
||||
int recursiveFlag = FALSE;
|
||||
char *groupName;
|
||||
char *p;
|
||||
const char *appUsage;
|
||||
|
||||
whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
|
||||
whichApp = (strcmp(*argv, "chown") == 0)?
|
||||
CHOWN_APP : (strcmp(*argv, "chmod") == 0)?
|
||||
CHMOD_APP : CHGRP_APP;
|
||||
|
||||
appUsage = (whichApp==CHOWN_APP)? chown_usage : (whichApp==CHMOD_APP)? chmod_usage : chgrp_usage;
|
||||
appUsage = (whichApp == CHOWN_APP)?
|
||||
chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage;
|
||||
|
||||
if (argc < 2)
|
||||
usage( appUsage);
|
||||
invocationName=*argv;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv)) switch (**argv) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option: %c\n", **argv);
|
||||
usage( appUsage);
|
||||
}
|
||||
if (argc < 2)
|
||||
usage(appUsage);
|
||||
invocationName = *argv;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if ( whichApp == CHMOD_APP ) {
|
||||
theMode=*argv;
|
||||
} else {
|
||||
|
||||
/* Find the selected group */
|
||||
if ( whichApp==CHGRP_APP ) {
|
||||
groupName = *argv;
|
||||
gid = my_getgrnam(groupName);
|
||||
if (gid == -1)
|
||||
goto bad_group;
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, invalid_option, invocationName, **argv);
|
||||
usage(appUsage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (whichApp == CHMOD_APP) {
|
||||
theMode = *argv;
|
||||
} else {
|
||||
groupName = strchr(*argv, '.');
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = my_getgrnam(groupName);
|
||||
if (gid == -1)
|
||||
goto bad_group;
|
||||
} else
|
||||
gid = -1;
|
||||
|
||||
/* Find the selected group */
|
||||
if (whichApp == CHGRP_APP) {
|
||||
groupName = *argv;
|
||||
gid = strtoul(groupName, &p, 10); /* maybe it's already numeric */
|
||||
if (groupName == p)
|
||||
gid = my_getgrnam(groupName);
|
||||
if (gid == -1)
|
||||
goto bad_group;
|
||||
} else {
|
||||
groupName = strchr(*argv, '.');
|
||||
if (groupName == NULL)
|
||||
groupName = strchr(*argv, ':');
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = strtoul(groupName, &p, 10);
|
||||
if (groupName == p)
|
||||
gid = my_getgrnam(groupName);
|
||||
if (gid == -1)
|
||||
goto bad_group;
|
||||
} else
|
||||
gid = -1;
|
||||
}
|
||||
|
||||
|
||||
/* Find the selected user (if appropriate) */
|
||||
if (whichApp == CHOWN_APP) {
|
||||
uid = strtoul(*argv, &p, 10); /* if numeric ... */
|
||||
if (*argv == p)
|
||||
uid = my_getpwnam(*argv);
|
||||
if (uid == -1) {
|
||||
fatalError( "%s: unknown user name: %s\n",
|
||||
invocationName, *argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Find the selected user (if appropriate) */
|
||||
if (whichApp==CHOWN_APP) {
|
||||
uid = my_getpwnam(*argv);
|
||||
if (uid == -1) {
|
||||
fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Ok, ready to do the deed now */
|
||||
if (argc <= 1) {
|
||||
fatalError( "%s: too few arguments\n", invocationName);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
if (argc <= 1) {
|
||||
fprintf(stderr, "%s: too few arguments", invocationName);
|
||||
exit( FALSE);
|
||||
}
|
||||
while (argc-- > 1) {
|
||||
if (recursiveAction( *(++argv), recursiveFlag, TRUE, FALSE, fileAction, fileAction)==FALSE)
|
||||
exit( FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
while (argc-- > 1) {
|
||||
if (recursiveAction (*(++argv), recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE)
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
bad_group:
|
||||
fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName);
|
||||
exit( FALSE);
|
||||
bad_group:
|
||||
fatalError( "%s: unknown group name: %s\n", invocationName, groupName);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,39 +29,48 @@
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if ( (argc < 2) || (**(argv+1) == '-') ) {
|
||||
usage( chroot_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(chroot_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (chroot (*argv) || (chdir ("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
}
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
execvp (*argv, argv);
|
||||
}
|
||||
else {
|
||||
char *prog;
|
||||
prog = getenv ("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp (prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
char *prog;
|
||||
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* chvt.c - aeb - 940227 - Change virtual terminal
|
||||
*
|
||||
@@ -13,24 +14,32 @@
|
||||
|
||||
extern int getfd(void);
|
||||
|
||||
int
|
||||
chvt_main(int argc, char** argv)
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
int fd, num;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd,VT_ACTIVATE,num)) {
|
||||
perror("VT_ACTIVATE");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (ioctl(fd,VT_WAITACTIVE,num)) {
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit( TRUE);
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd, VT_ACTIVATE, num)) {
|
||||
perror("VT_ACTIVATE");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (ioctl(fd, VT_WAITACTIVE, num)) {
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -25,9 +26,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
extern int
|
||||
clear_main(int argc, char** argv)
|
||||
extern int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,651 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Termios command line History and Editting, originally
|
||||
* intended for NetBSD sh (ash)
|
||||
* Copyright (c) 1999
|
||||
* Main code: Adam Rogoyski <rogoyski@cs.utexas.edu>
|
||||
* Etc: Dave Cinege <dcinege@psychosis.com>
|
||||
* Majorly adjusted/re-written for busybox:
|
||||
* Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* You may use this code as you wish, so long as the original author(s)
|
||||
* are attributed in any redistributions of the source code.
|
||||
* This code is 'as is' with no warranty.
|
||||
* This code may safely be consumed by a BSD or GPL license.
|
||||
*
|
||||
* v 0.5 19990328 Initial release
|
||||
*
|
||||
* Future plans: Simple file and path name completion. (like BASH)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Usage and Known bugs:
|
||||
Terminal key codes are not extensive, and more will probably
|
||||
need to be added. This version was created on Debian GNU/Linux 2.x.
|
||||
Delete, Backspace, Home, End, and the arrow keys were tested
|
||||
to work in an Xterm and console. Ctrl-A also works as Home.
|
||||
Ctrl-E also works as End. The binary size increase is <3K.
|
||||
|
||||
Editting will not display correctly for lines greater then the
|
||||
terminal width. (more then one line.) However, history will.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termio.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#define MAX_HISTORY 15 /* Maximum length of the linked list for the command line history */
|
||||
|
||||
#define ESC 27
|
||||
#define DEL 127
|
||||
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
|
||||
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
|
||||
|
||||
static struct history *his_front = NULL; /* First element in command line list */
|
||||
static struct history *his_end = NULL; /* Last element in command line list */
|
||||
static struct termio old_term, new_term; /* Current termio and the previous termio before starting ash */
|
||||
|
||||
static int cmdedit_termw = 80; /* actual terminal width */
|
||||
static int cmdedit_scroll = 27; /* width of EOL scrolling region */
|
||||
static int history_counter = 0; /* Number of commands in history list */
|
||||
static int reset_term = 0; /* Set to true if the terminal needs to be reset upon exit */
|
||||
|
||||
struct history {
|
||||
char *s;
|
||||
struct history *p;
|
||||
struct history *n;
|
||||
};
|
||||
|
||||
#define xwrite write
|
||||
|
||||
void
|
||||
cmdedit_setwidth(int w)
|
||||
{
|
||||
if (w > 20) {
|
||||
cmdedit_termw = w;
|
||||
cmdedit_scroll = w / 3;
|
||||
} else {
|
||||
errorMsg("\n*** Error: minimum screen width is 21\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cmdedit_reset_term(void)
|
||||
{
|
||||
if (reset_term)
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(fileno(stdin), TCSETA, (void *) &old_term);
|
||||
}
|
||||
|
||||
void clean_up_and_die(int sig)
|
||||
{
|
||||
cmdedit_reset_term();
|
||||
fprintf(stdout, "\n");
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* Go to HOME position */
|
||||
void input_home(int outputFd, int *cursor)
|
||||
{
|
||||
while (*cursor > 0) {
|
||||
xwrite(outputFd, "\b", 1);
|
||||
--*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Go to END position */
|
||||
void input_end(int outputFd, int *cursor, int len)
|
||||
{
|
||||
while (*cursor < len) {
|
||||
xwrite(outputFd, "\033[C", 3);
|
||||
++*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the char in back of the cursor */
|
||||
void input_backspace(char* command, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\b \b", 3);
|
||||
--*cursor;
|
||||
memmove(command + *cursor, command + *cursor + 1,
|
||||
BUFSIZ - *cursor + 1);
|
||||
|
||||
for (j = *cursor; j < (BUFSIZ - 1); j++) {
|
||||
if (!*(command + j))
|
||||
break;
|
||||
else
|
||||
xwrite(outputFd, (command + j), 1);
|
||||
}
|
||||
|
||||
xwrite(outputFd, " \b", 2);
|
||||
|
||||
while (j-- > *cursor)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
|
||||
--*len;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the char in front of the cursor */
|
||||
void input_delete(char* command, int outputFd, int cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
if (cursor == *len)
|
||||
return;
|
||||
|
||||
memmove(command + cursor, command + cursor + 1,
|
||||
BUFSIZ - cursor - 1);
|
||||
for (j = cursor; j < (BUFSIZ - 1); j++) {
|
||||
if (!*(command + j))
|
||||
break;
|
||||
else
|
||||
xwrite(outputFd, (command + j), 1);
|
||||
}
|
||||
|
||||
xwrite(outputFd, " \b", 2);
|
||||
|
||||
while (j-- > cursor)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
--*len;
|
||||
}
|
||||
|
||||
/* Move forward one charactor */
|
||||
void input_forward(int outputFd, int *cursor, int len)
|
||||
{
|
||||
if (*cursor < len) {
|
||||
xwrite(outputFd, "\033[C", 3);
|
||||
++*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move back one charactor */
|
||||
void input_backward(int outputFd, int *cursor)
|
||||
{
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\033[D", 3);
|
||||
--*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_SH_TAB_COMPLETION
|
||||
char** username_tab_completion(char* command, int *num_matches)
|
||||
{
|
||||
char **matches = (char **) NULL;
|
||||
*num_matches=0;
|
||||
fprintf(stderr, "\nin username_tab_completion\n");
|
||||
return (matches);
|
||||
}
|
||||
|
||||
#include <dirent.h>
|
||||
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
|
||||
{
|
||||
char *dirName;
|
||||
char **matches = (char **) NULL;
|
||||
DIR *dir;
|
||||
struct dirent *next;
|
||||
|
||||
matches = malloc( sizeof(char*)*50);
|
||||
|
||||
/* Stick a wildcard onto the command, for later use */
|
||||
strcat( command, "*");
|
||||
|
||||
/* Now wall the current directory */
|
||||
dirName = get_current_dir_name();
|
||||
dir = opendir(dirName);
|
||||
if (!dir) {
|
||||
/* Don't print an error, just shut up and return */
|
||||
*num_matches=0;
|
||||
return (matches);
|
||||
}
|
||||
while ((next = readdir(dir)) != NULL) {
|
||||
|
||||
/* Some quick sanity checks */
|
||||
if ((strcmp(next->d_name, "..") == 0)
|
||||
|| (strcmp(next->d_name, ".") == 0)) {
|
||||
continue;
|
||||
}
|
||||
/* See if this matches */
|
||||
if (check_wildcard_match(next->d_name, command) == TRUE) {
|
||||
/* Cool, found a match. Add it to the list */
|
||||
matches[*num_matches] = malloc(strlen(next->d_name)+1);
|
||||
strcpy( matches[*num_matches], next->d_name);
|
||||
++*num_matches;
|
||||
//matches = realloc( matches, sizeof(char*)*(*num_matches));
|
||||
}
|
||||
}
|
||||
|
||||
return (matches);
|
||||
}
|
||||
|
||||
void input_tab(char* command, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
/* Do TAB completion */
|
||||
static int num_matches=0;
|
||||
static char **matches = (char **) NULL;
|
||||
int pos = cursor;
|
||||
|
||||
|
||||
if (lastWasTab == FALSE) {
|
||||
char *tmp, *tmp1, *matchBuf;
|
||||
|
||||
/* For now, we will not bother with trying to distinguish
|
||||
* whether the cursor is in/at a command extression -- we
|
||||
* will always try all possable matches. If you don't like
|
||||
* that then feel free to fix it.
|
||||
*/
|
||||
|
||||
/* Make a local copy of the string -- up
|
||||
* to the position of the cursor */
|
||||
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
strncpy(matchBuf, command, cursor);
|
||||
tmp=matchBuf;
|
||||
|
||||
/* skip past any command seperator tokens */
|
||||
while (*tmp && (tmp1=strpbrk(tmp, ";|&{(`")) != NULL) {
|
||||
tmp=++tmp1;
|
||||
/* skip any leading white space */
|
||||
while (*tmp && isspace(*tmp))
|
||||
++tmp;
|
||||
}
|
||||
|
||||
/* skip any leading white space */
|
||||
while (*tmp && isspace(*tmp))
|
||||
++tmp;
|
||||
|
||||
/* Free up any memory already allocated */
|
||||
if (matches) {
|
||||
free(matches);
|
||||
matches = (char **) NULL;
|
||||
}
|
||||
|
||||
/* If the word starts with `~' and there is no slash in the word,
|
||||
* then try completing this word as a username. */
|
||||
|
||||
/* FIXME -- this check is broken! */
|
||||
if (*tmp == '~' && !strchr(tmp, '/'))
|
||||
matches = username_tab_completion(tmp, &num_matches);
|
||||
|
||||
/* Try to match any executable in our path and everything
|
||||
* in the current working directory that matches. */
|
||||
if (!matches)
|
||||
matches = exe_n_cwd_tab_completion(tmp, &num_matches);
|
||||
|
||||
/* Don't leak memory */
|
||||
free( matchBuf);
|
||||
|
||||
/* Did we find exactly one match? */
|
||||
if (matches && num_matches==1) {
|
||||
/* write out the matched command */
|
||||
strncpy(command+pos, matches[0]+pos, strlen(matches[0])-pos);
|
||||
len=strlen(command);
|
||||
cursor=len;
|
||||
xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Ok -- the last char was a TAB. Since they
|
||||
* just hit TAB again, print a list of all the
|
||||
* available choices... */
|
||||
if ( matches && num_matches>0 ) {
|
||||
int i, col;
|
||||
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
/* Print the list of matches */
|
||||
for (i=0,col=0; i<num_matches; i++) {
|
||||
char foo[17];
|
||||
sprintf(foo, "%-14s ", matches[i]);
|
||||
col += xwrite(outputFd, foo, strlen(foo));
|
||||
if (col > 60 && matches[i+1] != NULL) {
|
||||
xwrite(outputFd, "\n", 1);
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
/* Rewrite the prompt */
|
||||
xwrite(outputFd, prompt, strlen(prompt));
|
||||
/* Rewrite the command */
|
||||
xwrite(outputFd, command, len);
|
||||
/* Put the cursor back to where it used to be */
|
||||
for (cursor=len; cursor > pos; cursor--)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void get_previous_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->p;
|
||||
}
|
||||
|
||||
void get_next_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->n;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is used to grab a character buffer
|
||||
* from the input file descriptor and allows you to
|
||||
* a string with full command editing (sortof like
|
||||
* a mini readline).
|
||||
*
|
||||
* The following standard commands are not implemented:
|
||||
* ESC-b -- Move back one word
|
||||
* ESC-f -- Move forward one word
|
||||
* ESC-d -- Delete back one word
|
||||
* ESC-h -- Delete forward one word
|
||||
* CTL-t -- Transpose two characters
|
||||
*
|
||||
* Furthermore, the "vi" command editing keys are not implemented.
|
||||
*
|
||||
* TODO: implement TAB command completion. :)
|
||||
*/
|
||||
extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
{
|
||||
|
||||
int inputFd=fileno(stdin);
|
||||
int outputFd=fileno(stdout);
|
||||
int nr = 0;
|
||||
int len = 0;
|
||||
int j = 0;
|
||||
int cursor = 0;
|
||||
int break_out = 0;
|
||||
int ret = 0;
|
||||
int lastWasTab = FALSE;
|
||||
char c = 0;
|
||||
struct history *hp = his_end;
|
||||
|
||||
memset(command, 0, sizeof(command));
|
||||
if (!reset_term) {
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(inputFd, TCGETA, (void *) &old_term);
|
||||
memcpy(&new_term, &old_term, sizeof(struct termio));
|
||||
|
||||
new_term.c_cc[VMIN] = 1;
|
||||
new_term.c_cc[VTIME] = 0;
|
||||
new_term.c_lflag &= ~ICANON; /* unbuffered input */
|
||||
new_term.c_lflag &= ~ECHO;
|
||||
reset_term = 1;
|
||||
ioctl(inputFd, TCSETA, (void *) &new_term);
|
||||
} else {
|
||||
ioctl(inputFd, TCSETA, (void *) &new_term);
|
||||
}
|
||||
|
||||
memset(command, 0, BUFSIZ);
|
||||
|
||||
while (1) {
|
||||
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
/* Enter */
|
||||
*(command + len++ + 1) = c;
|
||||
xwrite(outputFd, &c, 1);
|
||||
break_out = 1;
|
||||
break;
|
||||
case 1:
|
||||
/* Control-a -- Beginning of line */
|
||||
input_home(outputFd, &cursor);
|
||||
case 2:
|
||||
/* Control-b -- Move back one character */
|
||||
input_backward(outputFd, &cursor);
|
||||
break;
|
||||
case 4:
|
||||
/* Control-d -- Delete one character, or exit
|
||||
* if the len=0 and no chars to delete */
|
||||
if (len == 0) {
|
||||
xwrite(outputFd, "exit", 4);
|
||||
clean_up_and_die(0);
|
||||
} else {
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
/* Control-e -- End of line */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
case 6:
|
||||
/* Control-f -- Move forward one character */
|
||||
input_forward(outputFd, &cursor, len);
|
||||
break;
|
||||
case '\b':
|
||||
case DEL:
|
||||
/* control-h and DEL */
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
break;
|
||||
case '\t':
|
||||
#ifdef BB_FEATURE_SH_TAB_COMPLETION
|
||||
input_tab(command, outputFd, &cursor, &len);
|
||||
#endif
|
||||
break;
|
||||
case 14:
|
||||
/* Control-n -- Get next command in history */
|
||||
if (hp && hp->n && hp->n->s) {
|
||||
get_next_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
/* Control-p -- Get previous command from history */
|
||||
if (hp && hp->p) {
|
||||
get_previous_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case ESC:{
|
||||
/* escape sequence follows */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
if (c == '[') { /* 91 */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
switch (c) {
|
||||
case 'A':
|
||||
/* Up Arrow -- Get previous command from history */
|
||||
if (hp && hp->p) {
|
||||
get_previous_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
/* Down Arrow -- Get next command in history */
|
||||
if (hp && hp->n && hp->n->s) {
|
||||
get_next_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Rewrite the line with the selected history item */
|
||||
rewrite_line:
|
||||
/* erase old command from command line */
|
||||
len = strlen(command)-strlen(hp->s);
|
||||
while (len>0)
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
input_home(outputFd, &cursor);
|
||||
|
||||
/* write new command */
|
||||
strcpy(command, hp->s);
|
||||
len = strlen(hp->s);
|
||||
xwrite(outputFd, command, len);
|
||||
cursor = len;
|
||||
break;
|
||||
case 'C':
|
||||
/* Right Arrow -- Move forward one character */
|
||||
input_forward(outputFd, &cursor, len);
|
||||
break;
|
||||
case 'D':
|
||||
/* Left Arrow -- Move back one character */
|
||||
input_backward(outputFd, &cursor);
|
||||
break;
|
||||
case '3':
|
||||
/* Delete */
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
break;
|
||||
case '1':
|
||||
/* Home (Ctrl-A) */
|
||||
input_home(outputFd, &cursor);
|
||||
break;
|
||||
case '4':
|
||||
/* End (Ctrl-E) */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
default:
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
if (c == '1' || c == '3' || c == '4')
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return; /* read 126 (~) */
|
||||
}
|
||||
if (c == 'O') {
|
||||
/* 79 */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
switch (c) {
|
||||
case 'H':
|
||||
/* Home (xterm) */
|
||||
input_home(outputFd, &cursor);
|
||||
break;
|
||||
case 'F':
|
||||
/* End (xterm) */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
default:
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
}
|
||||
c = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
default: /* If it's regular input, do the normal thing */
|
||||
|
||||
if (!isprint(c)) { /* Skip non-printable characters */
|
||||
break;
|
||||
}
|
||||
|
||||
if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */
|
||||
break;
|
||||
|
||||
len++;
|
||||
|
||||
if (cursor == (len - 1)) { /* Append if at the end of the line */
|
||||
*(command + cursor) = c;
|
||||
} else { /* Insert otherwise */
|
||||
memmove(command + cursor + 1, command + cursor,
|
||||
len - cursor - 1);
|
||||
|
||||
*(command + cursor) = c;
|
||||
|
||||
for (j = cursor; j < len; j++)
|
||||
xwrite(outputFd, command + j, 1);
|
||||
for (; j > cursor; j--)
|
||||
xwrite(outputFd, "\033[D", 3);
|
||||
}
|
||||
|
||||
cursor++;
|
||||
xwrite(outputFd, &c, 1);
|
||||
break;
|
||||
}
|
||||
if (c == '\t')
|
||||
lastWasTab = TRUE;
|
||||
else
|
||||
lastWasTab = FALSE;
|
||||
|
||||
if (break_out) /* Enter is the command terminator, no more input. */
|
||||
break;
|
||||
}
|
||||
|
||||
nr = len + 1;
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(inputFd, TCSETA, (void *) &old_term);
|
||||
reset_term = 0;
|
||||
|
||||
|
||||
/* Handle command history log */
|
||||
if (*(command)) {
|
||||
|
||||
struct history *h = his_end;
|
||||
|
||||
if (!h) {
|
||||
/* No previous history */
|
||||
h = his_front = malloc(sizeof(struct history));
|
||||
h->n = malloc(sizeof(struct history));
|
||||
|
||||
h->p = NULL;
|
||||
h->s = strdup(command);
|
||||
h->n->p = h;
|
||||
h->n->n = NULL;
|
||||
h->n->s = NULL;
|
||||
his_end = h->n;
|
||||
history_counter++;
|
||||
} else {
|
||||
/* Add a new history command */
|
||||
h->n = malloc(sizeof(struct history));
|
||||
|
||||
h->n->p = h;
|
||||
h->n->n = NULL;
|
||||
h->n->s = NULL;
|
||||
h->s = strdup(command);
|
||||
his_end = h->n;
|
||||
|
||||
/* After max history, remove the oldest command */
|
||||
if (history_counter >= MAX_HISTORY) {
|
||||
|
||||
struct history *p = his_front->n;
|
||||
|
||||
p->p = NULL;
|
||||
free(his_front->s);
|
||||
free(his_front);
|
||||
his_front = p;
|
||||
} else {
|
||||
history_counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
extern void cmdedit_init(void)
|
||||
{
|
||||
atexit(cmdedit_reset_term);
|
||||
signal(SIGINT, clean_up_and_die);
|
||||
signal(SIGQUIT, clean_up_and_die);
|
||||
signal(SIGTERM, clean_up_and_die);
|
||||
}
|
||||
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef GETLINE_H
|
||||
#define GETLINE_H
|
||||
|
||||
/* unix systems can #define POSIX to use termios, otherwise
|
||||
* the bsd or sysv interface will be used
|
||||
*/
|
||||
|
||||
#ifdef __STDC__
|
||||
#include <stddef.h>
|
||||
|
||||
typedef size_t (*cmdedit_strwidth_proc)(char *);
|
||||
|
||||
void cmdedit_read_input(char* promptStr, char* command); /* read a line of input */
|
||||
void cmdedit_setwidth(int); /* specify width of screen */
|
||||
void cmdedit_histadd(char *); /* adds entries to hist */
|
||||
void cmdedit_strwidth(cmdedit_strwidth_proc); /* to bind cmdedit_strlen */
|
||||
|
||||
extern int (*cmdedit_in_hook)(char *);
|
||||
extern int (*cmdedit_out_hook)(char *);
|
||||
extern int (*cmdedit_tab_hook)(char *, int, int *);
|
||||
|
||||
#else /* not __STDC__ */
|
||||
|
||||
void cmdedit_read_input(char* promptStr, char* command);
|
||||
void cmdedit_setwidth();
|
||||
void cmdedit_histadd();
|
||||
void cmdedit_strwidth();
|
||||
|
||||
extern int (*cmdedit_in_hook)();
|
||||
extern int (*cmdedit_out_hook)();
|
||||
extern int (*cmdedit_tab_hook)();
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#endif /* GETLINE_H */
|
||||
+26
-17
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* chvt.c - aeb - 940227 - Change virtual terminal
|
||||
*
|
||||
@@ -13,24 +14,32 @@
|
||||
|
||||
extern int getfd(void);
|
||||
|
||||
int
|
||||
chvt_main(int argc, char** argv)
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
int fd, num;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd,VT_ACTIVATE,num)) {
|
||||
perror("VT_ACTIVATE");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (ioctl(fd,VT_WAITACTIVE,num)) {
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit( TRUE);
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd, VT_ACTIVATE, num)) {
|
||||
perror("VT_ACTIVATE");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (ioctl(fd, VT_WAITACTIVE, num)) {
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -25,9 +26,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
extern int
|
||||
clear_main(int argc, char** argv)
|
||||
extern int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
+34
-32
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
||||
* Renamed deallocvt.
|
||||
@@ -13,38 +14,39 @@
|
||||
extern int getfd(void);
|
||||
char *progname;
|
||||
|
||||
int
|
||||
deallocvt_main(int argc, char *argv[]) {
|
||||
int fd, num, i;
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
int fd, num, i;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd,VT_DISALLOCATE,0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
|
||||
else
|
||||
if (ioctl(fd,VT_DISALLOCATE,num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
|
||||
progname);
|
||||
else if (ioctl(fd, VT_DISALLOCATE, num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
+316
-344
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Derived from
|
||||
* mapscrn.c - version 0.92
|
||||
@@ -6,6 +7,7 @@
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
@@ -20,123 +22,125 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
|
||||
static const char loadacm_usage[] = "loadacm\n\n"
|
||||
"Loads an acm from standard input.\n";
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
static long int ctoi(unsigned char *s, int *is_unicode);
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[]);
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int* is_unicode);
|
||||
unicode utf8_to_ucs2 (char* buf);
|
||||
int screen_map_load(int fd, FILE *fp);
|
||||
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
|
||||
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
|
||||
unicode utf8_to_ucs2(char *buf);
|
||||
int screen_map_load(int fd, FILE * fp);
|
||||
|
||||
int loadacm_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin))
|
||||
{
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return 0;
|
||||
int fd;
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadacm_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin)) {
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
int screen_map_load(int fd, FILE *fp)
|
||||
int screen_map_load(int fd, FILE * fp)
|
||||
{
|
||||
struct stat stbuf;
|
||||
unicode wbuf[E_TABSZ];
|
||||
unsigned char buf[E_TABSZ];
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
struct stat stbuf;
|
||||
unicode wbuf[E_TABSZ];
|
||||
unsigned char buf[E_TABSZ];
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
if (!(parse_failed = (-1 == uni_screen_map_read_ascii(fp,wbuf,&is_unicode))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) /* test for binary UTF map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "16bit screen-map MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed reading binary 16bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
|
||||
perror("Cannot read [new] map from file"), exit(1);
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
if (!
|
||||
(parse_failed =
|
||||
(-1 == uni_screen_map_read_ascii(fp, wbuf, &is_unicode)))
|
||||
|| (S_ISREG(stbuf.st_mode) && (stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) { /* test for binary UTF map by size */
|
||||
if (parse_failed) {
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
fprintf(stderr,
|
||||
"16bit screen-map MUST be a regular file.\n"),
|
||||
exit(1);
|
||||
else
|
||||
perror("fseek failed reading binary 16bit screen-map"),
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
|
||||
perror("Cannot read [new] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
|
||||
/* same if it was binary, ie. if parse_failed */
|
||||
if (parse_failed || is_unicode) {
|
||||
if (ioctl(fd, PIO_UNISCRNMAP, wbuf))
|
||||
perror("PIO_UNISCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
|
||||
/* same if it was binary, ie. if parse_failed */
|
||||
if (parse_failed || is_unicode)
|
||||
{
|
||||
if (ioctl(fd,PIO_UNISCRNMAP,wbuf))
|
||||
perror("PIO_UNISCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
/* rewind... */
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
fprintf(stderr,
|
||||
"Assuming 8bit screen-map - MUST be a regular file.\n"),
|
||||
exit(1);
|
||||
else
|
||||
perror("fseek failed assuming 8bit screen-map"), exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* rewind... */
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "Assuming 8bit screen-map - MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed assuming 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
/* ... and try an old 8-bit screen-map */
|
||||
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp,buf))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == E_TABSZ))) /* test for binary old 8-bit map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
/* should not - it succedeed above */
|
||||
fprintf (stderr, "fseek() returned ESPIPE !\n"), exit (1);
|
||||
else
|
||||
perror ("fseek for binary 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(buf,E_TABSZ,1,fp) != 1)
|
||||
perror("Cannot read [old] map from file"), exit(1);
|
||||
/* ... and try an old 8-bit screen-map */
|
||||
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp, buf))) ||
|
||||
(S_ISREG(stbuf.st_mode) && (stbuf.st_size == E_TABSZ))) { /* test for binary old 8-bit map by size */
|
||||
if (parse_failed) {
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
/* should not - it succedeed above */
|
||||
fprintf(stderr, "fseek() returned ESPIPE !\n"),
|
||||
exit(1);
|
||||
else
|
||||
perror("fseek for binary 8bit screen-map"), exit(1);
|
||||
}
|
||||
|
||||
if (fread(buf, E_TABSZ, 1, fp) != 1)
|
||||
perror("Cannot read [old] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ioctl(fd, PIO_SCRNMAP, buf))
|
||||
perror("PIO_SCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ioctl(fd,PIO_SCRNMAP,buf))
|
||||
perror("PIO_SCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,116 +153,111 @@ int screen_map_load(int fd, FILE *fp)
|
||||
*
|
||||
* FIXME: ignores everything after second word
|
||||
*/
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int *is_unicode)
|
||||
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
|
||||
{
|
||||
char buffer[256]; /* line buffer reading file */
|
||||
char *p, *q; /* 1st + 2nd words in line */
|
||||
int in, on; /* the same, as numbers */
|
||||
int tmp_is_unicode; /* tmp for is_unicode calculation */
|
||||
int i; /* loop index - result holder */
|
||||
int ret_code = 0; /* return code */
|
||||
sigset_t sigset, old_sigset;
|
||||
|
||||
assert (is_unicode);
|
||||
|
||||
*is_unicode = 0;
|
||||
|
||||
/* first 128 codes defaults to ASCII */
|
||||
for (i=0; i<128; i++) buf[i] = i;
|
||||
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
|
||||
for ( ; i<E_TABSZ; i++) buf[i] = 0xfffd;
|
||||
|
||||
/* block SIGCHLD */
|
||||
sigemptyset (&sigset);
|
||||
sigaddset (&sigset, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigset, &old_sigset);
|
||||
char buffer[256]; /* line buffer reading file */
|
||||
char *p, *q; /* 1st + 2nd words in line */
|
||||
int in, on; /* the same, as numbers */
|
||||
int tmp_is_unicode; /* tmp for is_unicode calculation */
|
||||
int i; /* loop index - result holder */
|
||||
int ret_code = 0; /* return code */
|
||||
sigset_t sigset, old_sigset;
|
||||
|
||||
do
|
||||
{
|
||||
if (NULL == fgets(buffer, sizeof(buffer),fp))
|
||||
{
|
||||
if (feof (fp))
|
||||
break;
|
||||
else
|
||||
{
|
||||
perror ("uni_screen_map_read_ascii() can't read line");
|
||||
exit (2);
|
||||
}
|
||||
assert(is_unicode);
|
||||
|
||||
*is_unicode = 0;
|
||||
|
||||
/* first 128 codes defaults to ASCII */
|
||||
for (i = 0; i < 128; i++)
|
||||
buf[i] = i;
|
||||
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
|
||||
for (; i < E_TABSZ; i++)
|
||||
buf[i] = 0xfffd;
|
||||
|
||||
/* block SIGCHLD */
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
|
||||
|
||||
do {
|
||||
if (NULL == fgets(buffer, sizeof(buffer), fp)) {
|
||||
if (feof(fp))
|
||||
break;
|
||||
else {
|
||||
perror("uni_screen_map_read_ascii() can't read line");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* get "charset-relative charcode", stripping leading spaces */
|
||||
p = strtok(buffer, " \t\n");
|
||||
|
||||
/* skip empty lines and comments */
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
/* get unicode mapping */
|
||||
q = strtok(NULL, " \t\n");
|
||||
if (q) {
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255) {
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
on = ctoi(q, &tmp_is_unicode);
|
||||
if (in < 0 && on > 65535) {
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
*is_unicode |= tmp_is_unicode;
|
||||
buf[in] = on;
|
||||
} else {
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get "charset-relative charcode", stripping leading spaces */
|
||||
p = strtok(buffer," \t\n");
|
||||
while (1); /* terminated by break on feof() */
|
||||
|
||||
/* skip empty lines and comments */
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
/* restore sig mask */
|
||||
sigprocmask(SIG_SETMASK, &old_sigset, NULL);
|
||||
|
||||
/* get unicode mapping */
|
||||
q = strtok(NULL," \t\n");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
on = ctoi(q, &tmp_is_unicode);
|
||||
if (in < 0 && on > 65535)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
*is_unicode |= tmp_is_unicode;
|
||||
buf[in] = on;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1); /* terminated by break on feof() */
|
||||
|
||||
/* restore sig mask */
|
||||
sigprocmask (SIG_SETMASK, &old_sigset, NULL);
|
||||
|
||||
return ret_code;
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
|
||||
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
|
||||
{
|
||||
char buffer[256];
|
||||
int in, on;
|
||||
char *p, *q;
|
||||
|
||||
for (in=0; in<256; in++) buf[in]=in;
|
||||
|
||||
while (fgets(buffer,sizeof(buffer)-1,fp))
|
||||
{
|
||||
p = strtok(buffer," \t\n");
|
||||
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
char buffer[256];
|
||||
int in, on;
|
||||
char *p, *q;
|
||||
|
||||
q = strtok(NULL," \t\n#");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255) return -1;
|
||||
|
||||
on = ctoi(q, NULL);
|
||||
if (in < 0 && on > 255) return -1;
|
||||
|
||||
buf[in] = on;
|
||||
for (in = 0; in < 256; in++)
|
||||
buf[in] = in;
|
||||
|
||||
while (fgets(buffer, sizeof(buffer) - 1, fp)) {
|
||||
p = strtok(buffer, " \t\n");
|
||||
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
q = strtok(NULL, " \t\n#");
|
||||
if (q) {
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255)
|
||||
return -1;
|
||||
|
||||
on = ctoi(q, NULL);
|
||||
if (in < 0 && on > 255)
|
||||
return -1;
|
||||
|
||||
buf[in] = on;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
return(0);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@@ -270,172 +269,145 @@ int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
|
||||
*
|
||||
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
|
||||
*/
|
||||
long int ctoi(unsigned char *s, int *is_unicode)
|
||||
long int ctoi(unsigned char *s, int *is_unicode)
|
||||
{
|
||||
int i;
|
||||
size_t ls;
|
||||
|
||||
ls = strlen(s);
|
||||
if (is_unicode) *is_unicode = 0;
|
||||
|
||||
/* hex-specified UCS2 */
|
||||
if ((strncmp(s,"U+",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
{
|
||||
sscanf(s+2,"%x",&i);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
int i;
|
||||
size_t ls;
|
||||
|
||||
/* hex-specified byte */
|
||||
else if ((ls <= 4) && (strncmp(s,"0x",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
sscanf(s+2,"%x",&i);
|
||||
ls = strlen(s);
|
||||
if (is_unicode)
|
||||
*is_unicode = 0;
|
||||
|
||||
/* oct-specified number (byte) */
|
||||
else if ((*s == '0') &&
|
||||
(strspn(s,"01234567") == ls))
|
||||
sscanf(s,"%o",&i);
|
||||
|
||||
/* dec-specified number (byte) */
|
||||
else if (strspn(s,"0123456789") == ls)
|
||||
sscanf(s,"%d",&i);
|
||||
|
||||
/* single-byte quoted char */
|
||||
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
|
||||
i=s[1];
|
||||
|
||||
/* multi-byte UTF8 quoted char */
|
||||
else if ((s[0] == '\'') && (s[ls-1] == '\''))
|
||||
{
|
||||
s[ls-1] = 0; /* ensure we'll not "parse UTF too far" */
|
||||
i = utf8_to_ucs2(s+1);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
|
||||
return(i);
|
||||
/* hex-specified UCS2 */
|
||||
if ((strncmp(s, "U+", 2) == 0) &&
|
||||
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2)) {
|
||||
sscanf(s + 2, "%x", &i);
|
||||
if (is_unicode)
|
||||
*is_unicode = 1;
|
||||
}
|
||||
|
||||
/* hex-specified byte */
|
||||
else if ((ls <= 4) && (strncmp(s, "0x", 2) == 0) &&
|
||||
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2))
|
||||
sscanf(s + 2, "%x", &i);
|
||||
|
||||
/* oct-specified number (byte) */
|
||||
else if ((*s == '0') && (strspn(s, "01234567") == ls))
|
||||
sscanf(s, "%o", &i);
|
||||
|
||||
/* dec-specified number (byte) */
|
||||
else if (strspn(s, "0123456789") == ls)
|
||||
sscanf(s, "%d", &i);
|
||||
|
||||
/* single-byte quoted char */
|
||||
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
|
||||
i = s[1];
|
||||
|
||||
/* multi-byte UTF8 quoted char */
|
||||
else if ((s[0] == '\'') && (s[ls - 1] == '\'')) {
|
||||
s[ls - 1] = 0; /* ensure we'll not "parse UTF too far" */
|
||||
i = utf8_to_ucs2(s + 1);
|
||||
if (is_unicode)
|
||||
*is_unicode = 1;
|
||||
} else
|
||||
return (-1);
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
|
||||
void saveoldmap(int fd, char *omfil)
|
||||
void saveoldmap(int fd, char *omfil)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[E_TABSZ];
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
unicode xbuf[E_TABSZ];
|
||||
int is_old_map = 0;
|
||||
|
||||
if (ioctl(fd,GIO_UNISCRNMAP,xbuf))
|
||||
{
|
||||
perror("GIO_UNISCRNMAP ioctl error");
|
||||
#endif
|
||||
if (ioctl(fd,GIO_SCRNMAP,buf))
|
||||
{
|
||||
perror("GIO_SCRNMAP ioctl error");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
is_old_map = 1;
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(omfil, "w")) == NULL)
|
||||
{
|
||||
perror(omfil);
|
||||
exit(1);
|
||||
}
|
||||
FILE *fp;
|
||||
char buf[E_TABSZ];
|
||||
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
if (is_old_map)
|
||||
{
|
||||
unicode xbuf[E_TABSZ];
|
||||
int is_old_map = 0;
|
||||
|
||||
if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) {
|
||||
perror("GIO_UNISCRNMAP ioctl error");
|
||||
#endif
|
||||
if (fwrite(buf,E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
if (ioctl(fd, GIO_SCRNMAP, buf)) {
|
||||
perror("GIO_SCRNMAP ioctl error");
|
||||
exit(1);
|
||||
} else
|
||||
is_old_map = 1;
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(omfil, "w")) == NULL) {
|
||||
perror(omfil);
|
||||
exit(1);
|
||||
}
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
else
|
||||
if (fwrite(xbuf, sizeof(unicode) * E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
if (is_old_map) {
|
||||
#endif
|
||||
if (fwrite(buf, E_TABSZ, 1, fp) != 1) {
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
} else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) {
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
fclose(fp);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
unicode utf8_to_ucs2 (char* buf)
|
||||
unicode utf8_to_ucs2(char *buf)
|
||||
{
|
||||
int utf_count = 0;
|
||||
long utf_char;
|
||||
unicode tc;
|
||||
unsigned char c;
|
||||
int utf_count = 0;
|
||||
long utf_char = 0;
|
||||
unicode tc = 0;
|
||||
unsigned char c;
|
||||
|
||||
do
|
||||
{
|
||||
c = *buf;
|
||||
buf++;
|
||||
do {
|
||||
c = *buf;
|
||||
buf++;
|
||||
|
||||
/* if byte should be part of multi-byte sequence */
|
||||
if(c & 0x80)
|
||||
{
|
||||
/* if we have already started to parse a UTF8 sequence */
|
||||
if (utf_count > 0 && (c & 0xc0) == 0x80)
|
||||
{
|
||||
utf_char = (utf_char << 6) | (c & 0x3f);
|
||||
utf_count--;
|
||||
if (utf_count == 0)
|
||||
tc = utf_char;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else /* Possibly 1st char of a UTF8 sequence */
|
||||
{
|
||||
if ((c & 0xe0) == 0xc0)
|
||||
{
|
||||
utf_count = 1;
|
||||
utf_char = (c & 0x1f);
|
||||
}
|
||||
else if ((c & 0xf0) == 0xe0)
|
||||
{
|
||||
utf_count = 2;
|
||||
utf_char = (c & 0x0f);
|
||||
}
|
||||
else if ((c & 0xf8) == 0xf0)
|
||||
{
|
||||
utf_count = 3;
|
||||
utf_char = (c & 0x07);
|
||||
}
|
||||
else if ((c & 0xfc) == 0xf8)
|
||||
{
|
||||
utf_count = 4;
|
||||
utf_char = (c & 0x03);
|
||||
}
|
||||
else if ((c & 0xfe) == 0xfc)
|
||||
{
|
||||
utf_count = 5;
|
||||
utf_char = (c & 0x01);
|
||||
}
|
||||
else
|
||||
utf_count = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else /* not part of multi-byte sequence - treat as ASCII
|
||||
* this makes incomplete sequences to be ignored
|
||||
*/
|
||||
{
|
||||
tc = c;
|
||||
utf_count = 0;
|
||||
}
|
||||
}
|
||||
while (utf_count);
|
||||
/* if byte should be part of multi-byte sequence */
|
||||
if (c & 0x80) {
|
||||
/* if we have already started to parse a UTF8 sequence */
|
||||
if (utf_count > 0 && (c & 0xc0) == 0x80) {
|
||||
utf_char = (utf_char << 6) | (c & 0x3f);
|
||||
utf_count--;
|
||||
if (utf_count == 0)
|
||||
tc = utf_char;
|
||||
else
|
||||
continue;
|
||||
} else { /* Possibly 1st char of a UTF8 sequence */
|
||||
|
||||
return tc;
|
||||
if ((c & 0xe0) == 0xc0) {
|
||||
utf_count = 1;
|
||||
utf_char = (c & 0x1f);
|
||||
} else if ((c & 0xf0) == 0xe0) {
|
||||
utf_count = 2;
|
||||
utf_char = (c & 0x0f);
|
||||
} else if ((c & 0xf8) == 0xf0) {
|
||||
utf_count = 3;
|
||||
utf_char = (c & 0x07);
|
||||
} else if ((c & 0xfc) == 0xf8) {
|
||||
utf_count = 4;
|
||||
utf_char = (c & 0x03);
|
||||
} else if ((c & 0xfe) == 0xfc) {
|
||||
utf_count = 5;
|
||||
utf_char = (c & 0x01);
|
||||
} else
|
||||
utf_count = 0;
|
||||
continue;
|
||||
}
|
||||
} else { /* not part of multi-byte sequence - treat as ASCII
|
||||
* this makes incomplete sequences to be ignored
|
||||
*/
|
||||
tc = c;
|
||||
utf_count = 0;
|
||||
}
|
||||
}
|
||||
while (utf_count);
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
||||
+104
-100
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* loadfont.c - Eugene Crosser & Andries Brouwer
|
||||
*
|
||||
@@ -29,73 +30,74 @@
|
||||
#define PSF_MAXMODE 0x03
|
||||
#define PSF_SEPARATOR 0xFFFF
|
||||
|
||||
static const char loadfont_usage[] = "loadfont\n"
|
||||
"\n"
|
||||
"\tLoad a console font from standard input.\n"
|
||||
"\n";
|
||||
static const char loadfont_usage[] = "loadfont\n\n"
|
||||
"Loads a console font from standard input.\n";
|
||||
|
||||
struct psf_header
|
||||
{
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
unsigned char mode; /* PSF font mode */
|
||||
unsigned char charsize; /* Character size */
|
||||
struct psf_header {
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
unsigned char mode; /* PSF font mode */
|
||||
unsigned char charsize; /* Character size */
|
||||
};
|
||||
|
||||
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
|
||||
|
||||
static void loadnewfont(int fd);
|
||||
|
||||
extern int
|
||||
loadfont_main(int argc, char **argv)
|
||||
extern int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadfont_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
loadnewfont(fd);
|
||||
|
||||
return 0;
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
do_loadfont(int fd, char *inbuf, int unit, int fontsize) {
|
||||
static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
|
||||
{
|
||||
char buf[16384];
|
||||
int i;
|
||||
|
||||
memset(buf,0,sizeof(buf));
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (unit < 1 || unit > 32) {
|
||||
fprintf(stderr, "Bad character size %d\n", unit);
|
||||
exit(1);
|
||||
fprintf(stderr, "Bad character size %d\n", unit);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (i = 0; i < fontsize; i++)
|
||||
memcpy(buf+(32*i), inbuf+(unit*i), unit);
|
||||
memcpy(buf + (32 * i), inbuf + (unit * i), unit);
|
||||
|
||||
#if defined( PIO_FONTX ) && !defined( __sparc__ )
|
||||
{
|
||||
struct consolefontdesc cfd;
|
||||
struct consolefontdesc cfd;
|
||||
|
||||
cfd.charcount = fontsize;
|
||||
cfd.charheight = unit;
|
||||
cfd.chardata = buf;
|
||||
cfd.charcount = fontsize;
|
||||
cfd.charheight = unit;
|
||||
cfd.chardata = buf;
|
||||
|
||||
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
|
||||
return; /* success */
|
||||
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
|
||||
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
|
||||
return; /* success */
|
||||
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
|
||||
}
|
||||
#endif
|
||||
if (ioctl(fd, PIO_FONT, buf)) {
|
||||
perror("PIO_FONT ioctl error");
|
||||
exit(1);
|
||||
perror("PIO_FONT ioctl error");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
|
||||
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
{
|
||||
struct unimapinit advice;
|
||||
struct unimapdesc ud;
|
||||
struct unipair *up;
|
||||
@@ -103,23 +105,24 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
|
||||
int glyph;
|
||||
u_short unicode;
|
||||
|
||||
maxct = tailsz; /* more than enough */
|
||||
maxct = tailsz; /* more than enough */
|
||||
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
|
||||
|
||||
if (!up) {
|
||||
fprintf(stderr, "Out of memory?\n");
|
||||
exit(1);
|
||||
fprintf(stderr, "Out of memory?\n");
|
||||
exit(1);
|
||||
}
|
||||
for (glyph = 0; glyph < fontsize; glyph++) {
|
||||
while (tailsz >= 2) {
|
||||
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
|
||||
tailsz -= 2;
|
||||
inbuf += 2;
|
||||
if (unicode == PSF_SEPARATOR)
|
||||
break;
|
||||
up[ct].unicode = unicode;
|
||||
up[ct].fontpos = glyph;
|
||||
ct++;
|
||||
}
|
||||
while (tailsz >= 2) {
|
||||
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
|
||||
tailsz -= 2;
|
||||
inbuf += 2;
|
||||
if (unicode == PSF_SEPARATOR)
|
||||
break;
|
||||
up[ct].unicode = unicode;
|
||||
up[ct].fontpos = glyph;
|
||||
ct++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
|
||||
@@ -128,33 +131,33 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
|
||||
advice.advised_hashsize = 0;
|
||||
advice.advised_hashstep = 0;
|
||||
advice.advised_hashlevel = 0;
|
||||
if(ioctl(fd, PIO_UNIMAPCLR, &advice)) {
|
||||
if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
|
||||
#ifdef ENOIOCTLCMD
|
||||
if (errno == ENOIOCTLCMD) {
|
||||
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
|
||||
fprintf(stderr, "No Unicode mapping table loaded.\n");
|
||||
} else
|
||||
if (errno == ENOIOCTLCMD) {
|
||||
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
|
||||
fprintf(stderr, "No Unicode mapping table loaded.\n");
|
||||
} else
|
||||
#endif
|
||||
perror("PIO_UNIMAPCLR");
|
||||
exit(1);
|
||||
perror("PIO_UNIMAPCLR");
|
||||
exit(1);
|
||||
}
|
||||
ud.entry_ct = ct;
|
||||
ud.entries = up;
|
||||
if(ioctl(fd, PIO_UNIMAP, &ud)) {
|
||||
if (ioctl(fd, PIO_UNIMAP, &ud)) {
|
||||
#if 0
|
||||
if (errno == ENOMEM) {
|
||||
/* change advice parameters */
|
||||
}
|
||||
if (errno == ENOMEM) {
|
||||
/* change advice parameters */
|
||||
}
|
||||
#endif
|
||||
perror("PIO_UNIMAP");
|
||||
exit(1);
|
||||
perror("PIO_UNIMAP");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
loadnewfont(int fd) {
|
||||
static void loadnewfont(int fd)
|
||||
{
|
||||
int unit;
|
||||
char inbuf[32768]; /* primitive */
|
||||
char inbuf[32768]; /* primitive */
|
||||
int inputlth, offset;
|
||||
|
||||
/*
|
||||
@@ -178,57 +181,58 @@ loadnewfont(int fd) {
|
||||
|
||||
/* test for psf first */
|
||||
{
|
||||
struct psf_header psfhdr;
|
||||
int fontsize;
|
||||
int hastable;
|
||||
int head0, head;
|
||||
struct psf_header psfhdr;
|
||||
int fontsize;
|
||||
int hastable;
|
||||
int head0, head;
|
||||
|
||||
if (inputlth < sizeof(struct psf_header))
|
||||
goto no_psf;
|
||||
if (inputlth < sizeof(struct psf_header))
|
||||
goto no_psf;
|
||||
|
||||
psfhdr = * (struct psf_header *) &inbuf[0];
|
||||
psfhdr = *(struct psf_header *) &inbuf[0];
|
||||
|
||||
if (!PSF_MAGIC_OK(psfhdr))
|
||||
goto no_psf;
|
||||
if (!PSF_MAGIC_OK(psfhdr))
|
||||
goto no_psf;
|
||||
|
||||
if (psfhdr.mode > PSF_MAXMODE) {
|
||||
fprintf(stderr, "Unsupported psf file mode\n");
|
||||
exit(1);
|
||||
}
|
||||
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
|
||||
if (psfhdr.mode > PSF_MAXMODE) {
|
||||
fprintf(stderr, "Unsupported psf file mode\n");
|
||||
exit(1);
|
||||
}
|
||||
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
|
||||
#if !defined( PIO_FONTX ) || defined( __sparc__ )
|
||||
if (fontsize != 256) {
|
||||
fprintf(stderr, "Only fontsize 256 supported\n");
|
||||
exit(1);
|
||||
}
|
||||
if (fontsize != 256) {
|
||||
fprintf(stderr, "Only fontsize 256 supported\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
hastable = (psfhdr.mode & PSF_MODEHASTAB);
|
||||
unit = psfhdr.charsize;
|
||||
head0 = sizeof(struct psf_header);
|
||||
head = head0 + fontsize*unit;
|
||||
if (head > inputlth || (!hastable && head != inputlth)) {
|
||||
fprintf(stderr, "Input file: bad length\n");
|
||||
exit(1);
|
||||
}
|
||||
do_loadfont(fd, inbuf + head0, unit, fontsize);
|
||||
if (hastable)
|
||||
do_loadtable(fd, inbuf + head, inputlth-head, fontsize);
|
||||
return;
|
||||
hastable = (psfhdr.mode & PSF_MODEHASTAB);
|
||||
unit = psfhdr.charsize;
|
||||
head0 = sizeof(struct psf_header);
|
||||
|
||||
head = head0 + fontsize * unit;
|
||||
if (head > inputlth || (!hastable && head != inputlth)) {
|
||||
fprintf(stderr, "Input file: bad length\n");
|
||||
exit(1);
|
||||
}
|
||||
do_loadfont(fd, inbuf + head0, unit, fontsize);
|
||||
if (hastable)
|
||||
do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
|
||||
return;
|
||||
}
|
||||
no_psf:
|
||||
no_psf:
|
||||
|
||||
/* file with three code pages? */
|
||||
if (inputlth == 9780) {
|
||||
offset = 40;
|
||||
unit = 16;
|
||||
offset = 40;
|
||||
unit = 16;
|
||||
} else {
|
||||
/* bare font */
|
||||
if (inputlth & 0377) {
|
||||
fprintf(stderr, "Bad input file size\n");
|
||||
exit(1);
|
||||
}
|
||||
offset = 0;
|
||||
unit = inputlth/256;
|
||||
/* bare font */
|
||||
if (inputlth & 0377) {
|
||||
fprintf(stderr, "Bad input file size\n");
|
||||
exit(1);
|
||||
}
|
||||
offset = 0;
|
||||
unit = inputlth / 256;
|
||||
}
|
||||
do_loadfont(fd, inbuf+offset, unit, 256);
|
||||
do_loadfont(fd, inbuf + offset, unit, 256);
|
||||
}
|
||||
+60
-54
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini loadkmap implementation for busybox
|
||||
*
|
||||
@@ -28,62 +29,67 @@
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
"\n"
|
||||
"\tLoad a binary keyboard translation table from standard input.\n"
|
||||
"\n";
|
||||
static const char loadkmap_usage[] = "loadkmap\n\n"
|
||||
"Loads a binary keyboard translation table from standard input.\n";
|
||||
|
||||
|
||||
int
|
||||
loadkmap_main(int argc, char * * argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
u_short *ibuff;
|
||||
int i,j,fd,readsz,pos,ibuffsz=NR_KEYS * sizeof(u_short);
|
||||
char flags[MAX_NR_KEYMAPS],magic[]="bkeymap",buff[7];
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
u_short *ibuff;
|
||||
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7];
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
read(0,buff,7);
|
||||
if (0 != strncmp(buff,magic,7)) {
|
||||
fprintf(stderr, "This is not a valid binary keymap.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( MAX_NR_KEYMAPS != read(0,flags,MAX_NR_KEYMAPS) ) {
|
||||
fprintf(stderr, "Error reading keymap flags: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ibuff=(u_short *) malloc(ibuffsz);
|
||||
if (!ibuff) {
|
||||
fprintf(stderr, "Out of memory.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(i=0; i<MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i]==1){
|
||||
pos=0;
|
||||
while (pos < ibuffsz) {
|
||||
if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) {
|
||||
fprintf(stderr, "Error reading keymap: %s\n",
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
pos += readsz;
|
||||
}
|
||||
for(j=0; j<NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
ke.kb_value = ibuff[j];
|
||||
ioctl(fd, KDSKBENT, &ke);
|
||||
}
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadkmap_usage);
|
||||
}
|
||||
}
|
||||
close (fd);
|
||||
return 0;
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
read(0, buff, 7);
|
||||
if (0 != strncmp(buff, magic, 7)) {
|
||||
fprintf(stderr, "This is not a valid binary keymap.\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
|
||||
fprintf(stderr, "Error reading keymap flags: %s\n",
|
||||
strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
ibuff = (u_short *) malloc(ibuffsz);
|
||||
if (!ibuff) {
|
||||
fprintf(stderr, "Out of memory.\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
pos = 0;
|
||||
while (pos < ibuffsz) {
|
||||
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
|
||||
< 0) {
|
||||
fprintf(stderr, "Error reading keymap: %s\n",
|
||||
strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
pos += readsz;
|
||||
}
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
ke.kb_value = ibuff[j];
|
||||
ioctl(fd, KDSKBENT, &ke);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Don't bother to close files. Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 basename_main(int argc, char **argv)
|
||||
{
|
||||
char* s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
+36
-26
@@ -1,7 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini Cat implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -24,36 +25,45 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static void print_file( FILE *file)
|
||||
static void print_file(FILE * file)
|
||||
{
|
||||
int c;
|
||||
while ((c = getc(file)) != EOF)
|
||||
putc(c, stdout);
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
int c;
|
||||
|
||||
while ((c = getc(file)) != EOF)
|
||||
putc(c, stdout);
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
extern int cat_main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
FILE *file;
|
||||
|
||||
if (argc==1) {
|
||||
print_file( stdin);
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage ("cat [file ...]\n");
|
||||
}
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv) ) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
if (argc == 1) {
|
||||
print_file(stdin);
|
||||
exit(TRUE);
|
||||
}
|
||||
print_file( file);
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [file ...]\n");
|
||||
}
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv)) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+38
-28
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,39 +29,48 @@
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if ( (argc < 2) || (**(argv+1) == '-') ) {
|
||||
usage( chroot_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(chroot_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (chroot (*argv) || (chdir ("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
}
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
execvp (*argv, argv);
|
||||
}
|
||||
else {
|
||||
char *prog;
|
||||
prog = getenv ("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp (prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
char *prog;
|
||||
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
-127
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Mini cp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
|
||||
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
static int followLinks = FALSE;
|
||||
static int preserveFlag = FALSE;
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
char* newsrcName = NULL;
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
if (recursiveFlag!=TRUE ) {
|
||||
fprintf(stderr, "cp: %s: omitting directory\n", srcName);
|
||||
return( TRUE);
|
||||
}
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
newsrcName = strrchr(srcName, '/');
|
||||
if (newsrcName && *newsrcName != '\0')
|
||||
strcat(newdestName, newsrcName);
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
|
||||
extern int cp_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
followLinks = TRUE;
|
||||
preserveFlag = TRUE;
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'd':
|
||||
followLinks = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
preserveFlag = TRUE;
|
||||
break;
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
destName = argv[argc - 1];
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
+219
-230
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini date implementation for busybox
|
||||
*
|
||||
@@ -20,6 +21,10 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_date
|
||||
#define bb_need_memory_exhausted
|
||||
#include "messages.c"
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
@@ -34,12 +39,13 @@
|
||||
an RFC 822 complient date output for shell scripting
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
@@ -47,241 +53,224 @@ static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
|
||||
/* Default input handling to save suprising some people */
|
||||
|
||||
struct tm *
|
||||
date_conv_time(struct tm *tm_time, const char *t_string) {
|
||||
int nr;
|
||||
struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
int nr;
|
||||
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min),
|
||||
&(tm_time->tm_year));
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
|
||||
if(nr < 4 || nr > 5) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (nr < 4 || nr > 5) {
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if(tm_time->tm_year >= 1900)
|
||||
tm_time->tm_year -= 1900;
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
return(tm_time);
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time->tm_year >= 1900)
|
||||
tm_time->tm_year -= 1900;
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
return (tm_time);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* The new stuff for LRP */
|
||||
|
||||
struct tm *
|
||||
date_conv_ftime(struct tm *tm_time, const char *t_string) {
|
||||
struct tm itm_time, jtm_time, ktm_time, \
|
||||
ltm_time, mtm_time, ntm_time;
|
||||
|
||||
itm_time = *tm_time;
|
||||
jtm_time = *tm_time;
|
||||
ktm_time = *tm_time;
|
||||
ltm_time = *tm_time;
|
||||
mtm_time = *tm_time;
|
||||
ntm_time = *tm_time;
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if(sscanf(t_string, "%d:%d:%d",
|
||||
&itm_time.tm_hour,
|
||||
&itm_time.tm_min,
|
||||
&itm_time.tm_sec) == 3 ) {
|
||||
|
||||
*tm_time = itm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d:%d",
|
||||
&jtm_time.tm_hour,
|
||||
&jtm_time.tm_min) == 2) {
|
||||
|
||||
*tm_time = jtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&ktm_time.tm_mon,
|
||||
&ktm_time.tm_mday,
|
||||
&ktm_time.tm_hour,
|
||||
&ktm_time.tm_min,
|
||||
&ktm_time.tm_sec) == 5) {
|
||||
|
||||
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ktm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d",
|
||||
<m_time.tm_mon,
|
||||
<m_time.tm_mday,
|
||||
<m_time.tm_hour,
|
||||
<m_time.tm_min) == 4) {
|
||||
|
||||
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ltm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&mtm_time.tm_year,
|
||||
&mtm_time.tm_mon,
|
||||
&mtm_time.tm_mday,
|
||||
&mtm_time.tm_hour,
|
||||
&mtm_time.tm_min,
|
||||
&mtm_time.tm_sec) == 6) {
|
||||
|
||||
mtm_time.tm_year -= 1900; /* Adjust years */
|
||||
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = mtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&ntm_time.tm_year,
|
||||
&ntm_time.tm_mon,
|
||||
&ntm_time.tm_mday,
|
||||
&ntm_time.tm_hour,
|
||||
&ntm_time.tm_min) == 5) {
|
||||
ntm_time.tm_year -= 1900; /* Adjust years */
|
||||
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ntm_time;
|
||||
return(tm_time);
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
|
||||
exit( FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
date_main(int argc, char * * argv)
|
||||
struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i>0 && *++(*argv)) switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv ("TZ=UTC0") != 0) {
|
||||
fprintf(stderr,"date: memory exhausted\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case '-':
|
||||
usage ( date_usage);
|
||||
}
|
||||
} else {
|
||||
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
|
||||
date_fmt=*argv;
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str=*argv;
|
||||
} else {
|
||||
usage ( date_usage);
|
||||
}
|
||||
struct tm itm_time, jtm_time, ktm_time, ltm_time, mtm_time, ntm_time;
|
||||
|
||||
itm_time = *tm_time;
|
||||
jtm_time = *tm_time;
|
||||
ktm_time = *tm_time;
|
||||
ltm_time = *tm_time;
|
||||
mtm_time = *tm_time;
|
||||
ntm_time = *tm_time;
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if (sscanf(t_string, "%d:%d:%d",
|
||||
&itm_time.tm_hour, &itm_time.tm_min, &itm_time.tm_sec) == 3) {
|
||||
|
||||
*tm_time = itm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d:%d",
|
||||
&jtm_time.tm_hour, &jtm_time.tm_min) == 2) {
|
||||
|
||||
*tm_time = jtm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&ktm_time.tm_mon,
|
||||
&ktm_time.tm_mday,
|
||||
&ktm_time.tm_hour,
|
||||
&ktm_time.tm_min, &ktm_time.tm_sec) == 5) {
|
||||
|
||||
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ktm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d",
|
||||
<m_time.tm_mon,
|
||||
<m_time.tm_mday,
|
||||
<m_time.tm_hour, <m_time.tm_min) == 4) {
|
||||
|
||||
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ltm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&mtm_time.tm_year,
|
||||
&mtm_time.tm_mon,
|
||||
&mtm_time.tm_mday,
|
||||
&mtm_time.tm_hour,
|
||||
&mtm_time.tm_min, &mtm_time.tm_sec) == 6) {
|
||||
|
||||
mtm_time.tm_year -= 1900; /* Adjust years */
|
||||
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = mtm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&ntm_time.tm_year,
|
||||
&ntm_time.tm_mon,
|
||||
&ntm_time.tm_mday,
|
||||
&ntm_time.tm_hour, &ntm_time.tm_min) == 5) {
|
||||
ntm_time.tm_year -= 1900; /* Adjust years */
|
||||
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ntm_time;
|
||||
return (tm_time);
|
||||
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight!*/
|
||||
if(date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if(date_str != NULL) {
|
||||
|
||||
if(strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
date_conv_time(&tm_time, date_str);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0 ) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", date_str);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
/* if setting time, set it */
|
||||
if(set_time) {
|
||||
if( stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
if(date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %_d %b %Y %H:%M:%S GMT"
|
||||
: "%a, %_d %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
} else if ( *date_fmt == '\0' ) {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf ("\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
/* Handle special conversions */
|
||||
|
||||
if( strncmp( date_fmt, "%f", 2) == 0 ) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit( TRUE);
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
|
||||
int date_main(int argc, char **argv)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i > 0 && *++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
} else {
|
||||
usage(date_usage);
|
||||
}
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight! */
|
||||
if (date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if (date_str != NULL) {
|
||||
|
||||
if (strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
date_conv_time(&tm_time, date_str);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fatalError("date: can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
if (date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %_d %b %Y %H:%M:%S GMT"
|
||||
: "%a, %_d %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
} else if (*date_fmt == '\0') {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf("\n");
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* Handle special conversions */
|
||||
|
||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit(TRUE);
|
||||
|
||||
}
|
||||
+147
-136
@@ -1,13 +1,14 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999, 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code taken from sash.
|
||||
*
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
* Based in part on code taken from sash.
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
* Permission to distribute this code under the GPL has been granted.
|
||||
*
|
||||
@@ -40,155 +41,165 @@ typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stout\n"
|
||||
"\tbs=n\tread and write N BYTES at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
//"\tskip=n\tskip n input blocks\n"
|
||||
"\n"
|
||||
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
|
||||
"dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stdout\n"
|
||||
"\tbs=n\tread and write n bytes at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
"\tskip=n\tskip n input blocks\n"
|
||||
"\tseek=n\tskip n output blocks\n"
|
||||
|
||||
"\n"
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
|
||||
|
||||
|
||||
|
||||
extern int dd_main (int argc, char **argv)
|
||||
extern int dd_main(int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
size_t blockSize = 512;
|
||||
//uintmax_t skipBlocks = 0;
|
||||
uintmax_t count = (uintmax_t)-1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
long blockSize = 512;
|
||||
uintmax_t skipBlocks = 0;
|
||||
uintmax_t seekBlocks = 0;
|
||||
uintmax_t count = (uintmax_t) - 1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc) {
|
||||
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
|
||||
inFile=((strchr(*argv, '='))+1);
|
||||
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
|
||||
outFile=((strchr(*argv, '='))+1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum ((strchr(*argv, '='))+1);
|
||||
if (count <= 0) {
|
||||
fprintf (stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum ((strchr(*argv, '='))+1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf (stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = atoi( *argv);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
goto usage;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc (blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf (stderr, "Cannot allocate buffer\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Parse any options */
|
||||
while (argc) {
|
||||
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
|
||||
inFile = ((strchr(*argv, '=')) + 1);
|
||||
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
|
||||
outFile = ((strchr(*argv, '=')) + 1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum((strchr(*argv, '=')) + 1);
|
||||
if (count <= 0) {
|
||||
fprintf(stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum((strchr(*argv, '=')) + 1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf(stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf(stderr, "Bad skip value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
} else if (strncmp(*argv, "seek", 4) == 0) {
|
||||
seekBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (seekBlocks <= 0) {
|
||||
fprintf(stderr, "Bad seek value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open (inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror (inFile);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = creat (outFile, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror (outFile);
|
||||
close (inFd);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utilitity.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read (inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror (inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write (outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror (outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open(inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* free(buf); */
|
||||
fatalError( inFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror (inFile);
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* close(inFd);
|
||||
free(buf); */
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
lseek(outFd, seekBlocks * blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utility.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read(inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror(inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write(outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror(outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
}
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
close (inFd);
|
||||
close (outFd);
|
||||
free (buf);
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit( TRUE);
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf("%ld+%d records out\n", (long) (outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit(TRUE);
|
||||
usage:
|
||||
|
||||
usage( dd_usage);
|
||||
usage(dd_usage);
|
||||
}
|
||||
|
||||
|
||||
+72
-63
@@ -1,7 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
@@ -26,84 +27,92 @@
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
static const char df_usage[] = "df [filesystem ...]\n\n"
|
||||
"Print the filesystem space used and space available.\n";
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
static int df(char *device, const char *mountPoint)
|
||||
{
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab* fstabItem;
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (s.f_blocks > 0) {
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp (device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile ("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return FALSE;
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
|
||||
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
|
||||
blocks_percent_used, mountPoint);
|
||||
|
||||
}
|
||||
if (s.f_blocks > 0) {
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
find_real_root_device_name( device);
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
|
||||
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
|
||||
blocks_percent_used, mountPoint);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern int df_main(int argc, char **argv)
|
||||
{
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
|
||||
0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
exit( FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
exit( status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
if (**(argv + 1) == '-') {
|
||||
usage(df_usage);
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
exit(FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
exit(status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit(TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
|
||||
mountTable = setmntent(mtab_file, "r");
|
||||
if (mountTable == 0) {
|
||||
perror(mtab_file);
|
||||
exit(FALSE);
|
||||
mountTable = setmntent(mtab_file, "r");
|
||||
if (mountTable == 0) {
|
||||
perror(mtab_file);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 dirname_main(int argc, char **argv)
|
||||
{
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
while (s && *s == '/') {
|
||||
*s = '\0';
|
||||
s=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
exit(TRUE);
|
||||
}
|
||||
+137
-88
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini du 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
|
||||
@@ -22,122 +23,170 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_name_too_long
|
||||
#include "messages.c"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#if 0
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
typedef void (Display)(size_t, char *);
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n\n"
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
;
|
||||
"du [OPTION]... [FILE]...\n\n"
|
||||
"Summarize disk space used for each FILE and/or directory.\n"
|
||||
"Disk space is printed in units of 1024 bytes.\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tcount sizes many times if hard linked\n"
|
||||
"\t-s\tdisplay only a total for each argument\n";
|
||||
|
||||
static int du_depth = 0;
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
|
||||
static Display *print;
|
||||
static Display *print;
|
||||
|
||||
static void
|
||||
print_normal(size_t size, char *filename)
|
||||
static void print_normal(long size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
|
||||
fprintf(stdout, "%ld\t%s\n", size, filename);
|
||||
}
|
||||
|
||||
static void
|
||||
print_summary(size_t size, char *filename)
|
||||
static void print_summary(long size, char *filename)
|
||||
{
|
||||
if (du_depth == 1) {
|
||||
print_normal(size, filename);
|
||||
}
|
||||
if (du_depth == 1) {
|
||||
print_normal(size, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static size_t
|
||||
du(char *filename)
|
||||
static long du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
size_t sum;
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
int len;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) { return 0; }
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[512];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ( (strcmp(name, "..") == 0)
|
||||
|| (strcmp(name, ".") == 0))
|
||||
{ continue; }
|
||||
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
sum += du(newfile);
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
printf("du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
|
||||
du_depth++;
|
||||
sum = (statbuf.st_blocks >> 1);
|
||||
|
||||
/* Don't add in stuff pointed to by symbolic links */
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) {
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(filename);
|
||||
if (filename[len - 1] == '/')
|
||||
filename[--len] = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[PATH_MAX + 1];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ((strcmp(name, "..") == 0)
|
||||
|| (strcmp(name, ".") == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len + strlen(name) + 1 > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
|
||||
sum += du(newfile);
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
|
||||
/* Add files with hard links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
}
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
|
||||
int
|
||||
du_main(int argc, char **argv)
|
||||
int du_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
int i;
|
||||
char opt;
|
||||
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'h':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
}
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '-':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
long sum;
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
int sum;
|
||||
for ( ; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); }
|
||||
for (; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if (sum && isDirectory(argv[i], FALSE, NULL)) {
|
||||
print_normal(sum, argv[i]);
|
||||
}
|
||||
reset_ino_dev_hashtable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.8 1999/12/17 18:44:15 erik Exp $ */
|
||||
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,137 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* echo implementation for busybox
|
||||
*
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char uname_usage[] =
|
||||
"echo [-neE] [ARG ...]\n\n"
|
||||
"Prints the specified ARGs to stdout\n\n"
|
||||
"Options:\n"
|
||||
"\t-n\tsuppress trailing newline\n"
|
||||
"\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
|
||||
"\t-E\tdisable interpretation of backslash-escaped characters\n";
|
||||
|
||||
extern int
|
||||
echo_main(int argc, char** argv)
|
||||
{
|
||||
register char **ap;
|
||||
register char *p;
|
||||
register char c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
|
||||
ap = argv;
|
||||
if (argc)
|
||||
ap++;
|
||||
while ((p = *ap) != NULL && *p == '-') {
|
||||
if (strcmp(p, "-n")==0) {
|
||||
nflag = 1;
|
||||
} else if (strcmp(p, "-e")==0) {
|
||||
eflag = 1;
|
||||
} else if (strcmp(p, "-E")==0) {
|
||||
eflag = 0;
|
||||
}
|
||||
else if (strncmp(p, "--", 2)==0) {
|
||||
usage( uname_usage);
|
||||
}
|
||||
else break;
|
||||
ap++;
|
||||
}
|
||||
while ((p = *ap++) != NULL) {
|
||||
while ((c = *p++) != '\0') {
|
||||
if (c == '\\' && eflag) {
|
||||
switch (c = *p++) {
|
||||
case 'a': c = '\007'; break;
|
||||
case 'b': c = '\b'; break;
|
||||
case 'c': exit( 0); /* exit */
|
||||
case 'f': c = '\f'; break;
|
||||
case 'n': c = '\n'; break;
|
||||
case 'r': c = '\r'; break;
|
||||
case 't': c = '\t'; break;
|
||||
case 'v': c = '\v'; break;
|
||||
case '\\': break; /* c = '\\' */
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
c -= '0';
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
break;
|
||||
default:
|
||||
p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
if (*ap)
|
||||
putchar(' ');
|
||||
}
|
||||
if (! nflag)
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
exit( 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Kenneth Almquist.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
|
||||
+69
-63
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini head 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
|
||||
@@ -26,81 +27,86 @@
|
||||
#include <stdio.h>
|
||||
|
||||
const char head_usage[] =
|
||||
"Usage: head [FILE]...\n\n"
|
||||
"Print first 10 lines of each FILE to standard output.\n"
|
||||
"With more than one FILE, precede each with a header giving the\n"
|
||||
"file name. With no FILE, or when FILE is -, read standard input.\n";
|
||||
"head [OPTION] [FILE]...\n\n"
|
||||
"Print first 10 lines of each FILE to standard output.\n"
|
||||
"With more than one FILE, precede each with a header giving the\n"
|
||||
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
|
||||
|
||||
int
|
||||
head(int len, FILE *src)
|
||||
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
|
||||
|
||||
int head(int len, FILE * src)
|
||||
{
|
||||
int i;
|
||||
char buffer[1024];
|
||||
int i;
|
||||
char buffer[1024];
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
fgets(buffer, 1024, src);
|
||||
if (feof(src)) { break; }
|
||||
fputs(buffer, stdout);
|
||||
}
|
||||
return 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
fgets(buffer, 1024, src);
|
||||
if (feof(src)) {
|
||||
break;
|
||||
}
|
||||
fputs(buffer, stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* BusyBoxed head(1) */
|
||||
int
|
||||
head_main(int argc, char **argv)
|
||||
int head_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
char opt;
|
||||
int len = 10;
|
||||
char opt;
|
||||
int len = 10, tmplen, i;
|
||||
|
||||
/* 1st option is potentially special */
|
||||
if ((argc > 1) && (argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
int tmplen = atoi(&argv[1][1]);
|
||||
if (tmplen) { len = tmplen; }
|
||||
i = 2;
|
||||
}
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
tmplen = 0;
|
||||
if (++i < argc)
|
||||
tmplen = atoi(argv[i]);
|
||||
if (tmplen < 1)
|
||||
usage(head_usage);
|
||||
len = tmplen;
|
||||
break;
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(head_usage);
|
||||
default:
|
||||
fprintf(stderr, "head: invalid option -- %c\n", opt);
|
||||
usage(head_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get rest of argv[] or stdin if nothing's left */
|
||||
if (i >= argc) {
|
||||
head(len, stdin);
|
||||
|
||||
/* parse argv[] */
|
||||
for ( ; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(head_usage);
|
||||
default:
|
||||
fprintf(stderr, "head: invalid option -- %c\n", opt);
|
||||
usage(head_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int need_headers = ((argc - i) > 1);
|
||||
|
||||
/* get rest of argv[] or stdin if nothing's left */
|
||||
if (i >= argc) {
|
||||
head(len, stdin);
|
||||
for (; i < argc; i++) {
|
||||
FILE *src;
|
||||
|
||||
} else {
|
||||
int need_headers = ((argc - i) > 1);
|
||||
for ( ; i < argc; i++) {
|
||||
FILE *src;
|
||||
src = fopen(argv[i], "r");
|
||||
if (!src) {
|
||||
fprintf(stderr,"head: %s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
/* emulating GNU behaviour */
|
||||
if (need_headers) {
|
||||
fprintf(stdout, "==> %s <==\n", argv[i]);
|
||||
src = fopen(argv[i], "r");
|
||||
if (!src) {
|
||||
fprintf(stderr, "head: %s: %s\n", argv[i],
|
||||
strerror(errno));
|
||||
} else {
|
||||
/* emulating GNU behaviour */
|
||||
if (need_headers) {
|
||||
fprintf(stdout, "==> %s <==\n", argv[i]);
|
||||
}
|
||||
head(len, src);
|
||||
if (i < argc - 1) {
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
head(len, src);
|
||||
if (i < argc - 1) {
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.4 1999/12/17 18:52:06 erik Exp $ */
|
||||
/* $Id: head.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
|
||||
+5
-3
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini hostid implementation for busybox
|
||||
*
|
||||
@@ -22,7 +23,8 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int hostid_main(int argc, char **argv) {
|
||||
printf ("%lx\n", gethostid());
|
||||
exit( TRUE);
|
||||
extern int hostid_main(int argc, char **argv)
|
||||
{
|
||||
printf("%lx\n", gethostid());
|
||||
exit(TRUE);
|
||||
}
|
||||
+7
-7
@@ -1,14 +1,14 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int
|
||||
length_main(int argc, char * * argv)
|
||||
extern int length_main(int argc, char **argv)
|
||||
{
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage("length string\n");
|
||||
}
|
||||
printf("%d\n", strlen(argv[1]));
|
||||
return( TRUE);
|
||||
if (argc != 2 || **(argv + 1) == '-') {
|
||||
usage("length string\n");
|
||||
}
|
||||
printf("%d\n", strlen(argv[1]));
|
||||
return (TRUE);
|
||||
}
|
||||
+97
-55
@@ -1,8 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ln implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -22,74 +22,116 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_name_too_long
|
||||
#define bb_need_not_a_directory
|
||||
#include "messages.c"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
static const char ln_usage[] =
|
||||
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
|
||||
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
"\t-f\tremove existing destination files\n";
|
||||
|
||||
"\t-f\tremove existing destination files\n"
|
||||
"\t-n\tno dereference symlinks - treat like normal file\n";
|
||||
|
||||
static int symlinkFlag = FALSE;
|
||||
static int removeoldFlag = FALSE;
|
||||
|
||||
static int followLinks = TRUE;
|
||||
|
||||
extern int ln_main(int argc, char **argv)
|
||||
{
|
||||
int status;
|
||||
static char* linkName;
|
||||
char *linkName;
|
||||
int linkIntoDirFlag;
|
||||
|
||||
if (argc < 3) {
|
||||
usage (ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
symlinkFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
removeoldFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage (ln_usage);
|
||||
}
|
||||
if (argc < 3) {
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
linkName = argv[argc - 1];
|
||||
|
||||
if ((argc > 3) && !(isDirectory(linkName))) {
|
||||
fprintf(stderr, "%s: not a directory\n", linkName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- >= 2) {
|
||||
if (removeoldFlag==TRUE ) {
|
||||
status = ( unlink(linkName) && errno != ENOENT );
|
||||
if ( status != 0 ) {
|
||||
perror(linkName);
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
symlinkFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
removeoldFlag = TRUE;
|
||||
break;
|
||||
case 'n':
|
||||
followLinks = FALSE;
|
||||
break;
|
||||
default:
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if ( symlinkFlag==TRUE)
|
||||
status = symlink(*argv, linkName);
|
||||
else
|
||||
status = link(*argv, linkName);
|
||||
if ( status != 0 ) {
|
||||
perror(linkName);
|
||||
exit( FALSE);
|
||||
|
||||
linkName = argv[argc - 1];
|
||||
|
||||
if (strlen(linkName) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
|
||||
|
||||
if ((argc > 3) && !linkIntoDirFlag) {
|
||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
while (argc-- >= 2) {
|
||||
char srcName[PATH_MAX + 1];
|
||||
int nChars, status;
|
||||
|
||||
if (strlen(*argv) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (followLinks == FALSE) {
|
||||
strcpy(srcName, *argv);
|
||||
} else {
|
||||
/* Warning! This can silently truncate if > PATH_MAX, but
|
||||
I don't think that there can be one > PATH_MAX anyway. */
|
||||
nChars = readlink(*argv, srcName, PATH_MAX);
|
||||
srcName[nChars] = '\0';
|
||||
}
|
||||
|
||||
if (removeoldFlag == TRUE) {
|
||||
status = (unlink(linkName) && errno != ENOENT);
|
||||
if (status != 0) {
|
||||
perror(linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (symlinkFlag == TRUE)
|
||||
status = symlink(*argv, linkName);
|
||||
else
|
||||
status = link(*argv, linkName);
|
||||
if (status != 0) {
|
||||
perror(linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
}
|
||||
exit TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+13
-9
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini logname implementation for busybox
|
||||
*
|
||||
@@ -23,18 +24,21 @@
|
||||
#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) {
|
||||
"Print the name of the current user.\n";
|
||||
|
||||
extern int logname_main(int argc, char **argv)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
if (argc > 1) usage (logname_usage);
|
||||
if (argc > 1)
|
||||
usage(logname_usage);
|
||||
|
||||
cp = getlogin ();
|
||||
cp = getlogin();
|
||||
if (cp) {
|
||||
puts (cp);
|
||||
exit (TRUE);
|
||||
}
|
||||
fprintf (stderr, "%s: no login name\n", argv[0]);
|
||||
exit (FALSE);
|
||||
puts(cp);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "%s: no login name\n", argv[0]);
|
||||
exit(FALSE);
|
||||
}
|
||||
+217
-147
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* tiny-ls.c version 0.1.0: A minimalist 'ls'
|
||||
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
|
||||
@@ -28,10 +29,10 @@
|
||||
* it more portable.
|
||||
*
|
||||
* KNOWN BUGS:
|
||||
* 1. messy output if you mix files and directories on the command line
|
||||
* 2. ls -l of a directory doesn't give "total <blocks>" header
|
||||
* 3. ls of a symlink to a directory doesn't list directory contents
|
||||
* 4. hidden files can make column width too large
|
||||
* 1. ls -l of a directory doesn't give "total <blocks>" header
|
||||
* 2. ls of a symlink to a directory doesn't list directory contents
|
||||
* 3. hidden files can make column width too large
|
||||
*
|
||||
* NON-OPTIMAL BEHAVIOUR:
|
||||
* 1. autowidth reads directories twice
|
||||
* 2. if you do a short directory listing without filetype characters
|
||||
@@ -40,18 +41,18 @@
|
||||
* 1. requires lstat (BSD) - how do you do it without?
|
||||
*/
|
||||
|
||||
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
|
||||
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
|
||||
#define COLUMN_GAP 2 /* includes the file type char, if present */
|
||||
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
|
||||
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
|
||||
#define COLUMN_GAP 2 /* includes the file type char, if present */
|
||||
#define HAS_REWINDDIR
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
# include <linux/types.h>
|
||||
# include <linux/types.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
@@ -69,37 +70,38 @@
|
||||
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
|
||||
#endif
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
#define FMT_ROWS 3 /* print across rows */
|
||||
#define FMT_COLUMNS 3 /* fill columns (same, since we don't sort) */
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
#define FMT_ROWS 3 /* print across rows */
|
||||
#define FMT_COLUMNS 3 /* fill columns (same, since we don't sort) */
|
||||
|
||||
#define TIME_MOD 0
|
||||
#define TIME_CHANGE 1
|
||||
#define TIME_ACCESS 2
|
||||
|
||||
#define DISP_FTYPE 1 /* show character for file type */
|
||||
#define DISP_EXEC 2 /* show '*' if regular executable file */
|
||||
#define DISP_HIDDEN 4 /* show files starting . (except . and ..) */
|
||||
#define DISP_DOT 8 /* show . and .. */
|
||||
#define DISP_NUMERIC 16 /* numeric uid and gid */
|
||||
#define DISP_FULLTIME 32 /* show extended time display */
|
||||
#define DIR_NOLIST 64 /* show directory as itself, not contents */
|
||||
#define DISP_DIRNAME 128 /* show directory name (for internal use) */
|
||||
#define DIR_RECURSE 256 /* -R (not yet implemented) */
|
||||
#define DISP_FTYPE 1 /* show character for file type */
|
||||
#define DISP_EXEC 2 /* show '*' if regular executable file */
|
||||
#define DISP_HIDDEN 4 /* show files starting . (except . and ..) */
|
||||
#define DISP_DOT 8 /* show . and .. */
|
||||
#define DISP_NUMERIC 16 /* numeric uid and gid */
|
||||
#define DISP_FULLTIME 32 /* show extended time display */
|
||||
#define DIR_NOLIST 64 /* show directory as itself, not contents */
|
||||
#define DISP_DIRNAME 128 /* show directory name (for internal use) */
|
||||
|
||||
static unsigned char display_fmt = FMT_AUTO;
|
||||
static unsigned short opts = 0;
|
||||
static unsigned short column = 0;
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
static unsigned char display_fmt = FMT_AUTO;
|
||||
static unsigned short opts = 0;
|
||||
static unsigned short column = 0;
|
||||
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
static unsigned short terminal_width = 0, column_width = 0;
|
||||
static unsigned short terminal_width = 0;
|
||||
static unsigned short column_width = 0;
|
||||
static unsigned short toplevel_column_width = 0;
|
||||
#else
|
||||
#define terminal_width TERMINAL_WIDTH
|
||||
#define column_width COLUMN_WIDTH
|
||||
@@ -113,13 +115,14 @@ static unsigned char time_fmt = TIME_MOD;
|
||||
|
||||
static void writenum(long val, short minwidth)
|
||||
{
|
||||
char scratch[128];
|
||||
char scratch[128];
|
||||
|
||||
char *p = scratch + sizeof(scratch);
|
||||
short len = 0;
|
||||
short neg = (val < 0);
|
||||
|
||||
if (neg) val = -val;
|
||||
|
||||
if (neg)
|
||||
val = -val;
|
||||
do
|
||||
*--p = (val % 10) + '0', len++, val /= 10;
|
||||
while (val);
|
||||
@@ -142,8 +145,9 @@ static void newline(void)
|
||||
static void tab(short col)
|
||||
{
|
||||
static const char spaces[] = " ";
|
||||
#define nspaces ((sizeof spaces)-1) /* null terminator! */
|
||||
|
||||
|
||||
#define nspaces ((sizeof spaces)-1) /* null terminator! */
|
||||
|
||||
short n = col - column;
|
||||
|
||||
if (n > 0) {
|
||||
@@ -155,7 +159,7 @@ static void tab(short col)
|
||||
/* must be 1...(sizeof spaces) left */
|
||||
wr(spaces, n);
|
||||
}
|
||||
#undef nspaces
|
||||
#undef nspaces
|
||||
}
|
||||
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
@@ -163,8 +167,8 @@ static char append_char(mode_t mode)
|
||||
{
|
||||
if (!(opts & DISP_FTYPE))
|
||||
return '\0';
|
||||
if ((opts & DISP_EXEC) && S_ISREG(mode) && (mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
|
||||
return '*';
|
||||
if ((opts & DISP_EXEC) && S_ISREG(mode)
|
||||
&& (mode & (S_IXUSR | S_IXGRP | S_IXOTH))) return '*';
|
||||
return APPCHAR(mode);
|
||||
}
|
||||
#endif
|
||||
@@ -176,89 +180,93 @@ static char append_char(mode_t mode)
|
||||
**
|
||||
**/
|
||||
|
||||
static void list_single(const char *name, struct stat *info, const char *fullname)
|
||||
static void list_single(const char *name, struct stat *info,
|
||||
const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX];
|
||||
char scratch[PATH_MAX + 1];
|
||||
short len = strlen(name);
|
||||
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
char append = append_char(info->st_mode);
|
||||
#endif
|
||||
|
||||
|
||||
if (display_fmt == FMT_LONG) {
|
||||
mode_t mode = info->st_mode;
|
||||
mode_t mode = info->st_mode;
|
||||
|
||||
newline();
|
||||
wr(modeString(mode), 10);
|
||||
column=10;
|
||||
writenum((long)info->st_nlink,(short)5);
|
||||
column = 10;
|
||||
writenum((long) info->st_nlink, (short) 5);
|
||||
fputs(" ", stdout);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
memset(scratch, 0, sizeof(scratch));
|
||||
my_getpwuid(scratch, info->st_uid);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else {
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(scratch, stdout);
|
||||
if (strlen(scratch) <= 8)
|
||||
wr(" ", 9 - strlen(scratch));
|
||||
} else {
|
||||
writenum((long) info->st_uid, (short) 8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
writenum((long) info->st_uid, (short) 8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
memset(scratch, 0, sizeof(scratch));
|
||||
my_getgrgid(scratch, info->st_gid);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
fputs(scratch, stdout);
|
||||
if (strlen(scratch) <= 8)
|
||||
wr(" ", 8 - strlen(scratch));
|
||||
} else
|
||||
writenum((long) info->st_gid, (short) 8);
|
||||
} else
|
||||
#endif
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
writenum((long) info->st_gid, (short) 8);
|
||||
//tab(26);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
writenum((long) MAJOR(info->st_rdev), (short) 3);
|
||||
fputs(", ", stdout);
|
||||
writenum((long)MINOR(info->st_rdev),(short)3);
|
||||
}
|
||||
else
|
||||
writenum((long)info->st_size,(short)8);
|
||||
writenum((long) MINOR(info->st_rdev), (short) 3);
|
||||
} else
|
||||
writenum((long) info->st_size, (short) 8);
|
||||
fputs(" ", stdout);
|
||||
//tab(32);
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
{
|
||||
time_t cal;
|
||||
char *string;
|
||||
|
||||
switch(time_fmt) {
|
||||
|
||||
switch (time_fmt) {
|
||||
case TIME_CHANGE:
|
||||
cal=info->st_ctime; break;
|
||||
cal = info->st_ctime;
|
||||
break;
|
||||
case TIME_ACCESS:
|
||||
cal=info->st_atime; break;
|
||||
cal = info->st_atime;
|
||||
break;
|
||||
default:
|
||||
cal=info->st_mtime; break;
|
||||
cal = info->st_mtime;
|
||||
break;
|
||||
}
|
||||
string=ctime(&cal);
|
||||
string = ctime(&cal);
|
||||
if (opts & DISP_FULLTIME)
|
||||
wr(string,24);
|
||||
wr(string, 24);
|
||||
else {
|
||||
time_t age = time(NULL) - cal;
|
||||
wr(string+4,7); /* mmm_dd_ */
|
||||
if(age < 3600L*24*365/2 && age > -15*60)
|
||||
|
||||
wr(string + 4, 7); /* mmm_dd_ */
|
||||
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60)
|
||||
/* hh:mm if less than 6 months old */
|
||||
wr(string+11,5);
|
||||
wr(string + 11, 5);
|
||||
else
|
||||
/* _yyyy otherwise */
|
||||
wr(string+19,5);
|
||||
wr(string + 19, 5);
|
||||
}
|
||||
wr(" ", 1);
|
||||
}
|
||||
@@ -269,7 +277,8 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
if (S_ISLNK(mode)) {
|
||||
wr(" -> ", 4);
|
||||
len = readlink(fullname, scratch, sizeof scratch);
|
||||
if (len > 0) fwrite(scratch, 1, len, stdout);
|
||||
if (len > 0)
|
||||
fwrite(scratch, 1, len, stdout);
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
/* show type of destination */
|
||||
if (opts & DISP_FTYPE) {
|
||||
@@ -287,18 +296,17 @@ static void list_single(const char *name, struct stat *info, const char *fullnam
|
||||
#endif
|
||||
} else {
|
||||
static short nexttab = 0;
|
||||
|
||||
|
||||
/* sort out column alignment */
|
||||
if (column == 0)
|
||||
; /* nothing to do */
|
||||
if (column == 0); /* nothing to do */
|
||||
else if (display_fmt == FMT_SINGLE)
|
||||
newline();
|
||||
else {
|
||||
if (nexttab + column_width > terminal_width
|
||||
#ifndef BB_FEATURE_AUTOWIDTH
|
||||
|| nexttab + len >= terminal_width
|
||||
|| nexttab + len >= terminal_width
|
||||
#endif
|
||||
)
|
||||
)
|
||||
newline();
|
||||
else
|
||||
tab(nexttab);
|
||||
@@ -336,32 +344,36 @@ static int list_item(const char *name)
|
||||
struct stat info;
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char fullname[MAXNAMLEN+1], *fnend;
|
||||
|
||||
char fullname[MAXNAMLEN + 1], *fnend;
|
||||
|
||||
if (lstat(name, &info))
|
||||
goto listerr;
|
||||
|
||||
if (!S_ISDIR(info.st_mode) ||
|
||||
(opts & DIR_NOLIST)) {
|
||||
|
||||
if (!S_ISDIR(info.st_mode) || (opts & DIR_NOLIST)) {
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
column_width = toplevel_column_width;
|
||||
#endif
|
||||
list_single(name, &info, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Otherwise, it's a directory we want to list the contents of */
|
||||
|
||||
if (opts & DISP_DIRNAME) { /* identify the directory */
|
||||
if (opts & DISP_DIRNAME) { /* identify the directory */
|
||||
if (column)
|
||||
wr("\n\n", 2), column = 0;
|
||||
wr(name, strlen(name));
|
||||
wr(":\n", 2);
|
||||
}
|
||||
|
||||
|
||||
dir = opendir(name);
|
||||
if (!dir) goto listerr;
|
||||
if (!dir)
|
||||
goto listerr;
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
column_width = 0;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
short w = strlen(entry->d_name);
|
||||
|
||||
if (column_width < w)
|
||||
column_width = w;
|
||||
}
|
||||
@@ -370,39 +382,49 @@ static int list_item(const char *name)
|
||||
#else
|
||||
closedir(dir);
|
||||
dir = opendir(name);
|
||||
if (!dir) goto listerr;
|
||||
if (!dir)
|
||||
goto listerr;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* List the contents */
|
||||
|
||||
strcpy(fullname,name); /* *** ignore '.' by itself */
|
||||
fnend=fullname+strlen(fullname);
|
||||
|
||||
strcpy(fullname, name); /* *** ignore '.' by itself */
|
||||
fnend = fullname + strlen(fullname);
|
||||
if (fnend[-1] != '/')
|
||||
*fnend++ = '/';
|
||||
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
const char *en=entry->d_name;
|
||||
const char *en = entry->d_name;
|
||||
|
||||
if (en[0] == '.') {
|
||||
if (!en[1] || (en[1] == '.' && !en[2])) { /* . or .. */
|
||||
if (!en[1] || (en[1] == '.' && !en[2])) { /* . or .. */
|
||||
if (!(opts & DISP_DOT))
|
||||
continue;
|
||||
}
|
||||
else if (!(opts & DISP_HIDDEN))
|
||||
} else if (!(opts & DISP_HIDDEN))
|
||||
continue;
|
||||
}
|
||||
/* FIXME: avoid stat if not required */
|
||||
strcpy(fnend, entry->d_name);
|
||||
if (lstat(fullname, &info))
|
||||
goto direrr; /* (shouldn't fail) */
|
||||
goto direrr; /* (shouldn't fail) */
|
||||
list_single(entry->d_name, &info, fullname);
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
if (opts & DISP_DIRNAME) { /* separate the directory */
|
||||
if (column) {
|
||||
wr("\n", 1);
|
||||
}
|
||||
wr("\n", 1);
|
||||
column = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
direrr:
|
||||
closedir(dir);
|
||||
listerr:
|
||||
direrr:
|
||||
closedir(dir);
|
||||
listerr:
|
||||
newline();
|
||||
perror(name);
|
||||
return 1;
|
||||
@@ -427,55 +449,102 @@ static const char ls_usage[] = "ls [-1a"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"F"
|
||||
#endif
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
"R"
|
||||
"] [filenames...]\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tdo not hide entries starting with .\n"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-c\twith -l: show ctime (the time of last\n"
|
||||
"\t\tmodification of file status information)\n"
|
||||
#endif
|
||||
"] [filenames...]\n";
|
||||
"\t-d\tlist directory entries instead of contents\n"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-e\tlist both full date and full time\n"
|
||||
#endif
|
||||
"\t-l\tuse a long listing format\n"
|
||||
"\t-n\tlist numeric UIDs and GIDs instead of names\n"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"\t-p\tappend indicator (one of /=@|) to entries\n"
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-u\twith -l: show access time (the time of last\n"
|
||||
"\t\taccess of the file)\n"
|
||||
#endif
|
||||
"\t-x\tlist entries by lines instead of by columns\n"
|
||||
"\t-A\tdo not list implied . and ..\n"
|
||||
"\t-C\tlist entries by columns\n"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"\t-F\tappend indicator (one of */=@|) to entries\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int
|
||||
ls_main(int argc, char * * argv)
|
||||
extern int ls_main(int argc, char **argv)
|
||||
{
|
||||
int argi=1, i;
|
||||
|
||||
int argi = 1, i;
|
||||
|
||||
/* process options */
|
||||
while (argi < argc && argv[argi][0] == '-') {
|
||||
const char *p = &argv[argi][1];
|
||||
|
||||
if (!*p) goto print_usage_message; /* "-" by itself not allowed */
|
||||
|
||||
if (!*p)
|
||||
goto print_usage_message; /* "-" by itself not allowed */
|
||||
if (*p == '-') {
|
||||
if (!p[1]) { /* "--" forces end of options */
|
||||
if (!p[1]) { /* "--" forces end of options */
|
||||
argi++;
|
||||
break;
|
||||
}
|
||||
/* it's a long option name - we don't support them */
|
||||
goto print_usage_message;
|
||||
}
|
||||
|
||||
|
||||
while (*p)
|
||||
switch (*p++) {
|
||||
case 'l': display_fmt = FMT_LONG; break;
|
||||
case '1': display_fmt = FMT_SINGLE; break;
|
||||
case 'x': display_fmt = FMT_ROWS; break;
|
||||
case 'C': display_fmt = FMT_COLUMNS; break;
|
||||
case 'l':
|
||||
display_fmt = FMT_LONG;
|
||||
break;
|
||||
case '1':
|
||||
display_fmt = FMT_SINGLE;
|
||||
break;
|
||||
case 'x':
|
||||
display_fmt = FMT_ROWS;
|
||||
break;
|
||||
case 'C':
|
||||
display_fmt = FMT_COLUMNS;
|
||||
break;
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
case 'p': opts |= DISP_FTYPE; break;
|
||||
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
|
||||
#endif
|
||||
case 'A': opts |= DISP_HIDDEN; break;
|
||||
case 'a': opts |= DISP_HIDDEN|DISP_DOT; break;
|
||||
case 'n': opts |= DISP_NUMERIC; break;
|
||||
case 'd': opts |= DIR_NOLIST; break;
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
case 'R': opts |= DIR_RECURSE; break;
|
||||
case 'p':
|
||||
opts |= DISP_FTYPE;
|
||||
break;
|
||||
case 'F':
|
||||
opts |= DISP_FTYPE | DISP_EXEC;
|
||||
break;
|
||||
#endif
|
||||
case 'A':
|
||||
opts |= DISP_HIDDEN;
|
||||
break;
|
||||
case 'a':
|
||||
opts |= DISP_HIDDEN | DISP_DOT;
|
||||
break;
|
||||
case 'n':
|
||||
opts |= DISP_NUMERIC;
|
||||
break;
|
||||
case 'd':
|
||||
opts |= DIR_NOLIST;
|
||||
break;
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
case 'u': time_fmt = TIME_ACCESS; break;
|
||||
case 'c': time_fmt = TIME_CHANGE; break;
|
||||
case 'e': opts |= DISP_FULLTIME; break;
|
||||
case 'u':
|
||||
time_fmt = TIME_ACCESS;
|
||||
break;
|
||||
case 'c':
|
||||
time_fmt = TIME_CHANGE;
|
||||
break;
|
||||
case 'e':
|
||||
opts |= DISP_FULLTIME;
|
||||
break;
|
||||
#endif
|
||||
default: goto print_usage_message;
|
||||
default:
|
||||
goto print_usage_message;
|
||||
}
|
||||
|
||||
|
||||
argi++;
|
||||
}
|
||||
|
||||
@@ -483,29 +552,30 @@ ls_main(int argc, char * * argv)
|
||||
if (display_fmt == FMT_AUTO)
|
||||
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
|
||||
if (argi < argc - 1)
|
||||
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
|
||||
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
/* could add a -w option and/or TIOCGWINSZ call */
|
||||
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;
|
||||
|
||||
if (terminal_width < 1)
|
||||
terminal_width = TERMINAL_WIDTH;
|
||||
|
||||
for (i = argi; i < argc; i++) {
|
||||
int len = strlen(argv[i]);
|
||||
if (column_width < len)
|
||||
column_width = len;
|
||||
|
||||
if (toplevel_column_width < len)
|
||||
toplevel_column_width = len;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* process files specified, or current directory if none */
|
||||
i=0;
|
||||
i = 0;
|
||||
if (argi == argc)
|
||||
i = list_item(".");
|
||||
while (argi < argc)
|
||||
i |= list_item(argv[argi++]);
|
||||
newline();
|
||||
exit( i);
|
||||
exit(i);
|
||||
|
||||
print_usage_message:
|
||||
usage (ls_usage);
|
||||
exit( FALSE);
|
||||
print_usage_message:
|
||||
usage(ls_usage);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
+74
-67
@@ -1,8 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini mkdir implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -22,15 +22,21 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
|
||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||
"\t-p\tno error if existing, make parent directories as needed\n";
|
||||
static const char mkdir_usage[] =
|
||||
"mkdir [OPTION] DIRECTORY...\n\n"
|
||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||
"\t-p\tno error if existing, make parent directories as needed\n";
|
||||
|
||||
|
||||
static int parentFlag = FALSE;
|
||||
@@ -39,69 +45,70 @@ static mode_t mode = 0777;
|
||||
|
||||
extern int mkdir_main(int argc, char **argv)
|
||||
{
|
||||
int i=FALSE;
|
||||
argc--;
|
||||
argv++;
|
||||
int i = FALSE;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 0 && **argv == '-') {
|
||||
while (i==FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'm':
|
||||
if (--argc == 0)
|
||||
usage( mkdir_usage);
|
||||
/* Find the specified modes */
|
||||
mode = 0;
|
||||
if ( parse_mode(*(++argv), &mode) == FALSE ) {
|
||||
fprintf(stderr, "Unknown mode: %s\n", *argv);
|
||||
exit( FALSE);
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 0 && **argv == '-') {
|
||||
while (i == FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'm':
|
||||
if (--argc == 0)
|
||||
usage(mkdir_usage);
|
||||
/* Find the specified modes */
|
||||
mode = 0;
|
||||
if (parse_mode(*(++argv), &mode) == FALSE) {
|
||||
fprintf(stderr, "Unknown mode: %s\n", *argv);
|
||||
exit FALSE;
|
||||
}
|
||||
/* Set the umask for this process so it doesn't
|
||||
* screw up whatever the user just entered. */
|
||||
umask(0);
|
||||
i = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
parentFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(mkdir_usage);
|
||||
}
|
||||
}
|
||||
/* Set the umask for this process so it doesn't
|
||||
* screw up whatever the user just entered. */
|
||||
umask(0);
|
||||
i=TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
parentFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage( mkdir_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
if (argc < 1) {
|
||||
usage( mkdir_usage);
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
int status;
|
||||
struct stat statBuf;
|
||||
char buf[NAME_MAX];
|
||||
|
||||
strcpy (buf, *argv);
|
||||
status=stat(buf, &statBuf);
|
||||
if (parentFlag == FALSE && status != -1 && status != ENOENT ) {
|
||||
fprintf(stderr, "%s: File exists\n", buf);
|
||||
exit( FALSE);
|
||||
if (argc < 1) {
|
||||
usage(mkdir_usage);
|
||||
}
|
||||
if (parentFlag == TRUE) {
|
||||
strcat( buf, "/");
|
||||
createPath(buf, mode);
|
||||
|
||||
while (argc > 0) {
|
||||
int status;
|
||||
struct stat statBuf;
|
||||
char buf[PATH_MAX + 1];
|
||||
|
||||
if (strlen(*argv) > PATH_MAX - 1) {
|
||||
fprintf(stderr, name_too_long, "mkdir");
|
||||
exit FALSE;
|
||||
}
|
||||
strcpy(buf, *argv);
|
||||
status = stat(buf, &statBuf);
|
||||
if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
|
||||
fprintf(stderr, "%s: File exists\n", buf);
|
||||
exit FALSE;
|
||||
}
|
||||
if (parentFlag == TRUE) {
|
||||
strcat(buf, "/");
|
||||
createPath(buf, mode);
|
||||
} else {
|
||||
if (mkdir(buf, mode) != 0 && parentFlag == FALSE) {
|
||||
perror(buf);
|
||||
exit FALSE;
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else {
|
||||
if (mkdir (buf, mode) != 0 && parentFlag == FALSE) {
|
||||
perror(buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
exit TRUE;
|
||||
}
|
||||
|
||||
|
||||
+36
-28
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini mkfifo implementation for busybox
|
||||
*
|
||||
@@ -26,36 +27,43 @@
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
|
||||
"Create the named fifo\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
|
||||
"Creates a named pipe (identical to 'mknod name p')\n\n"
|
||||
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n";
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
mode_t mode = 0666;
|
||||
argc--;
|
||||
argv++;
|
||||
char *thisarg;
|
||||
mode_t mode = 0666;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-') usage(mkfifo_usage);
|
||||
thisarg = *argv; thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--; argv++;
|
||||
parse_mode(*argv, &mode);
|
||||
break;
|
||||
default:
|
||||
usage (mkfifo_usage);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
if (argc < 1) usage (mkfifo_usage);
|
||||
if (mkfifo(*argv, mode) < 0) {
|
||||
perror("mkfifo");
|
||||
exit(255);
|
||||
} else {
|
||||
exit(TRUE);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-')
|
||||
usage(mkfifo_usage);
|
||||
thisarg = *argv;
|
||||
thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--;
|
||||
argv++;
|
||||
parse_mode(*argv, &mode);
|
||||
break;
|
||||
default:
|
||||
usage(mkfifo_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc < 1)
|
||||
usage(mkfifo_usage);
|
||||
if (mkfifo(*argv, mode) < 0) {
|
||||
perror("mkfifo");
|
||||
exit(255);
|
||||
} else {
|
||||
exit(TRUE);
|
||||
}
|
||||
}
|
||||
+49
-25
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini mknod implementation for busybox
|
||||
*
|
||||
@@ -27,23 +28,47 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\n\n"
|
||||
"TYPEs include:\n"
|
||||
"\tb:\tMake a block (buffered) device.\n"
|
||||
"\tc or u:\tMake a character (un-buffered) device.\n"
|
||||
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
|
||||
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n\n"
|
||||
"Create a special file (block, character, or pipe).\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the special file using the specified mode (default a=rw)\n\n"
|
||||
"TYPEs include:\n"
|
||||
"\tb:\tMake a block (buffered) device.\n"
|
||||
"\tc or u:\tMake a character (un-buffered) device.\n"
|
||||
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n";
|
||||
|
||||
int
|
||||
mknod_main(int argc, char** argv)
|
||||
int mknod_main(int argc, char **argv)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
dev_t dev = 0;
|
||||
char *thisarg;
|
||||
mode_t mode = 0;
|
||||
mode_t perm = 0666;
|
||||
dev_t dev = 0;
|
||||
|
||||
if ( argc != 5 || **(argv+1) == '-' ) {
|
||||
usage (mknod_usage);
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-')
|
||||
break;
|
||||
thisarg = *argv;
|
||||
thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--;
|
||||
argv++;
|
||||
parse_mode(*argv, &perm);
|
||||
break;
|
||||
default:
|
||||
usage(mknod_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
switch(argv[2][0]) {
|
||||
if (argc != 4 && argc != 2) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
switch (argv[1][0]) {
|
||||
case 'c':
|
||||
case 'u':
|
||||
mode = S_IFCHR;
|
||||
@@ -53,23 +78,22 @@ mknod_main(int argc, char** argv)
|
||||
break;
|
||||
case 'p':
|
||||
mode = S_IFIFO;
|
||||
if (argc!=2) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage (mknod_usage);
|
||||
usage(mknod_usage);
|
||||
}
|
||||
|
||||
if ( mode == S_IFCHR || mode == S_IFBLK ) {
|
||||
dev = (atoi(argv[3]) << 8) | atoi(argv[4]);
|
||||
if ( argc != 5 ) {
|
||||
usage (mknod_usage);
|
||||
}
|
||||
if (mode == S_IFCHR || mode == S_IFBLK) {
|
||||
dev = (atoi(argv[2]) << 8) | atoi(argv[1]);
|
||||
}
|
||||
|
||||
mode |= 0666;
|
||||
mode |= perm;
|
||||
|
||||
if ( mknod(argv[1], mode, dev) != 0 ) {
|
||||
perror(argv[1]);
|
||||
return( FALSE);
|
||||
}
|
||||
return( TRUE);
|
||||
if (mknod(argv[0], mode, dev) != 0)
|
||||
fatalError("%s: %s\n", argv[0], strerror(errno));
|
||||
exit (TRUE);
|
||||
}
|
||||
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Mini mv implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
|
||||
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||
|
||||
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
char* newsrcName = NULL;
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
newsrcName = strrchr(srcName, '/');
|
||||
if (newsrcName && *newsrcName != '\0')
|
||||
strcat(newdestName, newsrcName);
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, TRUE, TRUE));
|
||||
}
|
||||
|
||||
static int rmfileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (unlink( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
static int rmdirAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (rmdir( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
|
||||
extern int mv_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
usage (mv_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
destName = argv[argc - 1];
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, TRUE, TRUE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
if (recursiveAction(srcName, TRUE, TRUE, TRUE,
|
||||
rmfileAction, rmdirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
+279
-329
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* printf - format and print data
|
||||
Copyright (C) 90, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
|
||||
|
||||
@@ -42,7 +43,7 @@
|
||||
to convert all of the given arguments.
|
||||
|
||||
David MacKenzie <djm@gnu.ai.mit.edu> */
|
||||
|
||||
|
||||
|
||||
// 19990508 Busy Boxed! Dave Cinege
|
||||
|
||||
@@ -84,11 +85,11 @@
|
||||
#if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
||||
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
#endif
|
||||
#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
||||
#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
||||
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
||||
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
||||
#endif
|
||||
#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
||||
#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
||||
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
||||
#endif
|
||||
|
||||
@@ -121,409 +122,358 @@
|
||||
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
|
||||
#define octtobin(c) ((c) - '0')
|
||||
|
||||
char *xmalloc ();
|
||||
static double xstrtod __P((char *s));
|
||||
static int print_esc __P((char *escstart));
|
||||
static int print_formatted __P((char *format, int argc, char **argv));
|
||||
static long xstrtol __P((char *s));
|
||||
static unsigned long xstrtoul __P((char *s));
|
||||
static void print_direc
|
||||
__P(
|
||||
|
||||
static double xstrtod __P ((char *s));
|
||||
static int print_esc __P ((char *escstart));
|
||||
static int print_formatted __P ((char *format, int argc, char **argv));
|
||||
static long xstrtol __P ((char *s));
|
||||
static unsigned long xstrtoul __P ((char *s));
|
||||
static void print_direc __P ((char *start, size_t length, int field_width, int precision, char *argument));
|
||||
static void print_esc_char __P ((int c));
|
||||
static void print_esc_string __P ((char *str));
|
||||
static void verify __P ((char *s, char *end));
|
||||
(char *start, size_t length, int field_width, int precision,
|
||||
char *argument));
|
||||
static void print_esc_char __P((int c));
|
||||
static void print_esc_string __P((char *str));
|
||||
static void verify __P((char *s, char *end));
|
||||
|
||||
/* The value to return to the calling program. */
|
||||
static int exit_status;
|
||||
|
||||
static const char printf_usage[] = "printf format [argument...]\n";
|
||||
static const char printf_usage[] = "printf format [argument...]\n\nFormats and prints the given data.\n";
|
||||
|
||||
int
|
||||
printf_main(int argc, char** argv)
|
||||
int printf_main(int argc, char **argv)
|
||||
{
|
||||
char *format;
|
||||
int args_used;
|
||||
char *format;
|
||||
int args_used;
|
||||
|
||||
exit_status = 0;
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage (printf_usage);
|
||||
}
|
||||
exit_status = 0;
|
||||
if (argc <= 1 || **(argv + 1) == '-') {
|
||||
usage(printf_usage);
|
||||
}
|
||||
|
||||
format = argv[1];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
format = argv[1];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
|
||||
do
|
||||
{
|
||||
args_used = print_formatted (format, argc, argv);
|
||||
argc -= args_used;
|
||||
argv += args_used;
|
||||
}
|
||||
while (args_used > 0 && argc > 0);
|
||||
do {
|
||||
args_used = print_formatted(format, argc, argv);
|
||||
argc -= args_used;
|
||||
argv += args_used;
|
||||
}
|
||||
while (args_used > 0 && argc > 0);
|
||||
|
||||
/*
|
||||
if (argc > 0)
|
||||
fprintf(stderr, "excess args ignored");
|
||||
*/
|
||||
|
||||
exit (exit_status);
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
|
||||
arguments to any `%' directives.
|
||||
Return the number of elements of ARGV used. */
|
||||
|
||||
static int
|
||||
print_formatted (char *format, int argc, char **argv)
|
||||
static int print_formatted(char *format, int argc, char **argv)
|
||||
{
|
||||
int save_argc = argc; /* Preserve original value. */
|
||||
char *f; /* Pointer into `format'. */
|
||||
char *direc_start; /* Start of % directive. */
|
||||
size_t direc_length; /* Length of % directive. */
|
||||
int field_width; /* Arg to first '*', or -1 if none. */
|
||||
int precision; /* Arg to second '*', or -1 if none. */
|
||||
int save_argc = argc; /* Preserve original value. */
|
||||
char *f; /* Pointer into `format'. */
|
||||
char *direc_start; /* Start of % directive. */
|
||||
size_t direc_length; /* Length of % directive. */
|
||||
int field_width; /* Arg to first '*', or -1 if none. */
|
||||
int precision; /* Arg to second '*', or -1 if none. */
|
||||
|
||||
for (f = format; *f; ++f)
|
||||
{
|
||||
switch (*f)
|
||||
{
|
||||
case '%':
|
||||
direc_start = f++;
|
||||
direc_length = 1;
|
||||
field_width = precision = -1;
|
||||
if (*f == '%')
|
||||
{
|
||||
putchar ('%');
|
||||
break;
|
||||
}
|
||||
if (*f == 'b')
|
||||
{
|
||||
if (argc > 0)
|
||||
{
|
||||
print_esc_string (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (strchr ("-+ #", *f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
field_width = xstrtoul (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
field_width = 0;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '.')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
precision = xstrtoul (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
precision = 0;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
if (*f == 'l' || *f == 'L' || *f == 'h')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
/*
|
||||
if (!strchr ("diouxXfeEgGcs", *f))
|
||||
fprintf(stderr, "%%%c: invalid directive", *f);
|
||||
*/
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
print_direc (direc_start, direc_length, field_width,
|
||||
precision, *argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
print_direc (direc_start, direc_length, field_width,
|
||||
precision, "");
|
||||
break;
|
||||
for (f = format; *f; ++f) {
|
||||
switch (*f) {
|
||||
case '%':
|
||||
direc_start = f++;
|
||||
direc_length = 1;
|
||||
field_width = precision = -1;
|
||||
if (*f == '%') {
|
||||
putchar('%');
|
||||
break;
|
||||
}
|
||||
if (*f == 'b') {
|
||||
if (argc > 0) {
|
||||
print_esc_string(*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (strchr("-+ #", *f)) {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '*') {
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0) {
|
||||
field_width = xstrtoul(*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
} else
|
||||
field_width = 0;
|
||||
} else
|
||||
while (ISDIGIT(*f)) {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '.') {
|
||||
++f;
|
||||
++direc_length;
|
||||
if (*f == '*') {
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0) {
|
||||
precision = xstrtoul(*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
} else
|
||||
precision = 0;
|
||||
} else
|
||||
while (ISDIGIT(*f)) {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
if (*f == 'l' || *f == 'L' || *f == 'h') {
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
/*
|
||||
if (!strchr ("diouxXfeEgGcs", *f))
|
||||
fprintf(stderr, "%%%c: invalid directive", *f);
|
||||
*/
|
||||
++direc_length;
|
||||
if (argc > 0) {
|
||||
print_direc(direc_start, direc_length, field_width,
|
||||
precision, *argv);
|
||||
++argv;
|
||||
--argc;
|
||||
} else
|
||||
print_direc(direc_start, direc_length, field_width,
|
||||
precision, "");
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
f += print_esc (f);
|
||||
break;
|
||||
case '\\':
|
||||
f += print_esc(f);
|
||||
break;
|
||||
|
||||
default:
|
||||
putchar (*f);
|
||||
default:
|
||||
putchar(*f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return save_argc - argc;
|
||||
return save_argc - argc;
|
||||
}
|
||||
|
||||
/* Print a \ escape sequence starting at ESCSTART.
|
||||
Return the number of characters in the escape sequence
|
||||
besides the backslash. */
|
||||
|
||||
static int
|
||||
print_esc (char *escstart)
|
||||
static int print_esc(char *escstart)
|
||||
{
|
||||
register char *p = escstart + 1;
|
||||
int esc_value = 0; /* Value of \nnn escape. */
|
||||
int esc_length; /* Length of \nnn escape. */
|
||||
register char *p = escstart + 1;
|
||||
int esc_value = 0; /* Value of \nnn escape. */
|
||||
int esc_length; /* Length of \nnn escape. */
|
||||
|
||||
/* \0ooo and \xhhh escapes have maximum length of 3 chars. */
|
||||
if (*p == 'x')
|
||||
{
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && ISXDIGIT (*p);
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hextobin (*p);
|
||||
/* \0ooo and \xhhh escapes have maximum length of 3 chars. */
|
||||
if (*p == 'x') {
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && ISXDIGIT(*p); ++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hextobin(*p);
|
||||
/* if (esc_length == 0)
|
||||
fprintf(stderr, "missing hex in esc");
|
||||
*/
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (*p == '0')
|
||||
{
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && isodigit (*p);
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octtobin (*p);
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (strchr ("\"\\abcfnrtv", *p))
|
||||
print_esc_char (*p++);
|
||||
putchar(esc_value);
|
||||
} else if (*p == '0') {
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && isodigit(*p); ++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octtobin(*p);
|
||||
putchar(esc_value);
|
||||
} else if (strchr("\"\\abcfnrtv", *p))
|
||||
print_esc_char(*p++);
|
||||
/* else
|
||||
fprintf(stderr, "\\%c: invalid esc", *p);
|
||||
*/
|
||||
return p - escstart - 1;
|
||||
return p - escstart - 1;
|
||||
}
|
||||
|
||||
/* Output a single-character \ escape. */
|
||||
|
||||
static void
|
||||
print_esc_char (int c)
|
||||
static void print_esc_char(int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'a': /* Alert. */
|
||||
putchar (7);
|
||||
break;
|
||||
case 'b': /* Backspace. */
|
||||
putchar (8);
|
||||
break;
|
||||
case 'c': /* Cancel the rest of the output. */
|
||||
exit (0);
|
||||
break;
|
||||
case 'f': /* Form feed. */
|
||||
putchar (12);
|
||||
break;
|
||||
case 'n': /* New line. */
|
||||
putchar (10);
|
||||
break;
|
||||
case 'r': /* Carriage return. */
|
||||
putchar (13);
|
||||
break;
|
||||
case 't': /* Horizontal tab. */
|
||||
putchar (9);
|
||||
break;
|
||||
case 'v': /* Vertical tab. */
|
||||
putchar (11);
|
||||
break;
|
||||
default:
|
||||
putchar (c);
|
||||
break;
|
||||
}
|
||||
switch (c) {
|
||||
case 'a': /* Alert. */
|
||||
putchar(7);
|
||||
break;
|
||||
case 'b': /* Backspace. */
|
||||
putchar(8);
|
||||
break;
|
||||
case 'c': /* Cancel the rest of the output. */
|
||||
exit(0);
|
||||
break;
|
||||
case 'f': /* Form feed. */
|
||||
putchar(12);
|
||||
break;
|
||||
case 'n': /* New line. */
|
||||
putchar(10);
|
||||
break;
|
||||
case 'r': /* Carriage return. */
|
||||
putchar(13);
|
||||
break;
|
||||
case 't': /* Horizontal tab. */
|
||||
putchar(9);
|
||||
break;
|
||||
case 'v': /* Vertical tab. */
|
||||
putchar(11);
|
||||
break;
|
||||
default:
|
||||
putchar(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print string STR, evaluating \ escapes. */
|
||||
|
||||
static void
|
||||
print_esc_string (char *str)
|
||||
static void print_esc_string(char *str)
|
||||
{
|
||||
for (; *str; str++)
|
||||
if (*str == '\\')
|
||||
str += print_esc (str);
|
||||
else
|
||||
putchar (*str);
|
||||
for (; *str; str++)
|
||||
if (*str == '\\')
|
||||
str += print_esc(str);
|
||||
else
|
||||
putchar(*str);
|
||||
}
|
||||
|
||||
static void
|
||||
print_direc (char *start, size_t length, int field_width, int precision, char *argument)
|
||||
print_direc(char *start, size_t length, int field_width, int precision,
|
||||
char *argument)
|
||||
{
|
||||
char *p; /* Null-terminated copy of % directive. */
|
||||
char *p; /* Null-terminated copy of % directive. */
|
||||
|
||||
p = xmalloc ((unsigned) (length + 1));
|
||||
strncpy (p, start, length);
|
||||
p[length] = 0;
|
||||
p = xmalloc((unsigned) (length + 1));
|
||||
strncpy(p, start, length);
|
||||
p[length] = 0;
|
||||
|
||||
switch (p[length - 1])
|
||||
{
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, xstrtol (argument));
|
||||
else
|
||||
printf (p, precision, xstrtol (argument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, xstrtol (argument));
|
||||
else
|
||||
printf (p, field_width, precision, xstrtol (argument));
|
||||
}
|
||||
break;
|
||||
switch (p[length - 1]) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, xstrtol(argument));
|
||||
else
|
||||
printf(p, precision, xstrtol(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, xstrtol(argument));
|
||||
else
|
||||
printf(p, field_width, precision, xstrtol(argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, xstrtoul (argument));
|
||||
else
|
||||
printf (p, precision, xstrtoul (argument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, xstrtoul (argument));
|
||||
else
|
||||
printf (p, field_width, precision, xstrtoul (argument));
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, xstrtoul(argument));
|
||||
else
|
||||
printf(p, precision, xstrtoul(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, xstrtoul(argument));
|
||||
else
|
||||
printf(p, field_width, precision, xstrtoul(argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, xstrtod (argument));
|
||||
else
|
||||
printf (p, precision, xstrtod (argument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, xstrtod (argument));
|
||||
else
|
||||
printf (p, field_width, precision, xstrtod (argument));
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, xstrtod(argument));
|
||||
else
|
||||
printf(p, precision, xstrtod(argument));
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, xstrtod(argument));
|
||||
else
|
||||
printf(p, field_width, precision, xstrtod(argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf (p, *argument);
|
||||
break;
|
||||
case 'c':
|
||||
printf(p, *argument);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, argument);
|
||||
else
|
||||
printf (p, precision, argument);
|
||||
case 's':
|
||||
if (field_width < 0) {
|
||||
if (precision < 0)
|
||||
printf(p, argument);
|
||||
else
|
||||
printf(p, precision, argument);
|
||||
} else {
|
||||
if (precision < 0)
|
||||
printf(p, field_width, argument);
|
||||
else
|
||||
printf(p, field_width, precision, argument);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, argument);
|
||||
else
|
||||
printf (p, field_width, precision, argument);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
free (p);
|
||||
free(p);
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
xstrtoul (char *s)
|
||||
static unsigned long xstrtoul(char *s)
|
||||
{
|
||||
char *end;
|
||||
unsigned long val;
|
||||
char *end;
|
||||
unsigned long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoul (s, &end, 0);
|
||||
verify (s, end);
|
||||
return val;
|
||||
errno = 0;
|
||||
val = strtoul(s, &end, 0);
|
||||
verify(s, end);
|
||||
return val;
|
||||
}
|
||||
|
||||
static long
|
||||
xstrtol (char *s)
|
||||
static long xstrtol(char *s)
|
||||
{
|
||||
char *end;
|
||||
long val;
|
||||
char *end;
|
||||
long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtol (s, &end, 0);
|
||||
verify (s, end);
|
||||
return val;
|
||||
errno = 0;
|
||||
val = strtol(s, &end, 0);
|
||||
verify(s, end);
|
||||
return val;
|
||||
}
|
||||
|
||||
static double
|
||||
xstrtod (char *s)
|
||||
static double xstrtod(char *s)
|
||||
{
|
||||
char *end;
|
||||
double val;
|
||||
char *end;
|
||||
double val;
|
||||
|
||||
errno = 0;
|
||||
val = strtod (s, &end);
|
||||
verify (s, end);
|
||||
return val;
|
||||
errno = 0;
|
||||
val = strtod(s, &end);
|
||||
verify(s, end);
|
||||
return val;
|
||||
}
|
||||
|
||||
static void
|
||||
verify (char *s, char *end)
|
||||
static void verify(char *s, char *end)
|
||||
{
|
||||
if (errno)
|
||||
{
|
||||
fprintf(stderr, "%s", s);
|
||||
exit_status = 1;
|
||||
}
|
||||
else if (*end)
|
||||
{
|
||||
/*
|
||||
if (s == end)
|
||||
fprintf(stderr, "%s: expected numeric", s);
|
||||
else
|
||||
fprintf(stderr, "%s: not completely converted", s);
|
||||
*/
|
||||
exit_status = 1;
|
||||
}
|
||||
if (errno) {
|
||||
fprintf(stderr, "%s", s);
|
||||
exit_status = 1;
|
||||
} else if (*end) {
|
||||
/*
|
||||
if (s == end)
|
||||
fprintf(stderr, "%s: expected numeric", s);
|
||||
else
|
||||
fprintf(stderr, "%s: not completely converted", s);
|
||||
*/
|
||||
exit_status = 1;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini pwd implementation for busybox
|
||||
*
|
||||
@@ -23,17 +24,17 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
extern int
|
||||
pwd_main(int argc, char * * argv)
|
||||
extern int pwd_main(int argc, char **argv)
|
||||
{
|
||||
char buf[NAME_MAX];
|
||||
char buf[PATH_MAX + 1];
|
||||
|
||||
if ( getcwd(buf, sizeof(buf)) == NULL ) {
|
||||
if (getcwd(buf, sizeof(buf)) == NULL) {
|
||||
perror("get working directory");
|
||||
exit( FALSE);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
printf("%s\n", buf);
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
+53
-51
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini rm implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,11 +29,12 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
|
||||
"Remove (unlink) the FILE(s).\n\n"
|
||||
"Options:\n"
|
||||
"\t-f\t\tremove existing destinations, never prompt\n"
|
||||
"\t-r or -R\tremove the contents of directories recursively\n";
|
||||
static const char *rm_usage = "rm [OPTION]... FILE...\n\n"
|
||||
"Remove (unlink) the FILE(s).\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-f\t\tremove existing destinations, never prompt\n"
|
||||
"\t-r or -R\tremove the contents of directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
@@ -40,63 +42,63 @@ static int forceFlag = FALSE;
|
||||
static const char *srcName;
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (unlink( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
if (unlink(fileName) < 0) {
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static int dirAction(const char *fileName, struct stat* statbuf)
|
||||
static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (rmdir( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
if (rmdir(fileName) < 0) {
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
extern int rm_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statbuf;
|
||||
struct stat statbuf;
|
||||
|
||||
if (argc < 2) {
|
||||
usage( rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage( rm_usage);
|
||||
}
|
||||
if (argc < 2) {
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
srcName = *(argv++);
|
||||
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
|
||||
/* do not reports errors for non-existent files if -f, just skip them */
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else {
|
||||
if (recursiveAction( srcName, recursiveFlag, FALSE,
|
||||
TRUE, fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
srcName = *(argv++);
|
||||
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0
|
||||
&& errno == ENOENT) {
|
||||
/* do not reports errors for non-existent files if -f, just skip them */
|
||||
} else {
|
||||
if (recursiveAction(srcName, recursiveFlag, FALSE,
|
||||
TRUE, fileAction, dirAction, NULL) == FALSE) {
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
+13
-11
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini rmdir implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,15 +29,16 @@
|
||||
|
||||
extern int rmdir_main(int argc, char **argv)
|
||||
{
|
||||
if ( argc==1 || **(argv+1) == '-' ) {
|
||||
usage( "rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
|
||||
}
|
||||
|
||||
while (--argc > 0) {
|
||||
if ( rmdir(*(++argv)) == -1 ) {
|
||||
fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
if (argc == 1 || **(argv + 1) == '-') {
|
||||
usage
|
||||
("rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
|
||||
}
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
while (--argc > 0) {
|
||||
if (rmdir(*(++argv)) == -1) {
|
||||
fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
+9
-10
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini sleep implementation for busybox
|
||||
*
|
||||
@@ -23,19 +24,17 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char sleep_usage[] = "sleep N\n\n"
|
||||
"Pause for N seconds.\n";
|
||||
const char sleep_usage[] = "sleep N\n\n" "Pause for N seconds.\n";
|
||||
|
||||
extern int
|
||||
sleep_main(int argc, char * * argv)
|
||||
extern int sleep_main(int argc, char **argv)
|
||||
{
|
||||
if ( (argc < 2) || (**(argv+1) == '-') ) {
|
||||
usage( sleep_usage );
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(sleep_usage);
|
||||
}
|
||||
|
||||
if ( sleep(atoi(*(++argv))) != 0 ) {
|
||||
perror( "sleep");
|
||||
exit (FALSE);
|
||||
if (sleep(atoi(*(++argv))) != 0) {
|
||||
perror("sleep");
|
||||
exit(FALSE);
|
||||
} else
|
||||
exit (TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
+187
-196
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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
|
||||
@@ -28,29 +29,37 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char sort_usage[] =
|
||||
"Usage: sort [OPTION]... [FILE]...\n\n"
|
||||
;
|
||||
static const char sort_usage[] = "sort [-n]"
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
" [-r]"
|
||||
#endif
|
||||
" [FILE]...\n\nSorts lines of text in the specified files\n";
|
||||
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
|
||||
static int reverse = 0;
|
||||
#else
|
||||
#define APPLY_REVERSE(x) (x)
|
||||
#endif
|
||||
|
||||
/* typedefs _______________________________________________________________ */
|
||||
|
||||
/* line node */
|
||||
typedef struct Line {
|
||||
char *data; /* line data */
|
||||
struct Line *next; /* pointer to next line node */
|
||||
char *data; /* line data */
|
||||
struct Line *next; /* pointer to next line node */
|
||||
} Line;
|
||||
|
||||
/* singly-linked list of lines */
|
||||
typedef struct {
|
||||
int len; /* number of Lines */
|
||||
Line **sorted; /* array fed to qsort */
|
||||
|
||||
Line *head; /* head of List */
|
||||
Line *current; /* current Line */
|
||||
int len; /* number of Lines */
|
||||
Line **sorted; /* array fed to qsort */
|
||||
Line *head; /* head of List */
|
||||
Line *current; /* current Line */
|
||||
} List;
|
||||
|
||||
/* comparison function */
|
||||
typedef int (Compare)(const void *, const void *);
|
||||
typedef int (Compare) (const void *, const void *);
|
||||
|
||||
|
||||
/* methods ________________________________________________________________ */
|
||||
@@ -58,255 +67,237 @@ typedef int (Compare)(const void *, const void *);
|
||||
static const int max = 1024;
|
||||
|
||||
/* mallocate Line */
|
||||
static Line *
|
||||
line_alloc()
|
||||
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;
|
||||
Line *self;
|
||||
self = malloc(1 * sizeof(Line));
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Construct Line from FILE* */
|
||||
static Line *
|
||||
line_newFromFile(FILE *src)
|
||||
static Line *line_newFromFile(FILE * src)
|
||||
{
|
||||
char buffer[max];
|
||||
Line *self;
|
||||
Line *self;
|
||||
char *cstring = NULL;
|
||||
|
||||
if (fgets(buffer, max, src)) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) { return NULL; }
|
||||
line_init(self, buffer);
|
||||
return self;
|
||||
}
|
||||
return NULL;
|
||||
if ((cstring = cstring_lineFromFile(src))) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
self->data = cstring;
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Line destructor */
|
||||
static Line *
|
||||
line_release(Line *self)
|
||||
static Line *line_release(Line * self)
|
||||
{
|
||||
if (self->data) {
|
||||
free(self->data);
|
||||
free(self);
|
||||
}
|
||||
return self;
|
||||
if (self->data) {
|
||||
free(self->data);
|
||||
free(self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/* Comparison */
|
||||
|
||||
/* ascii order */
|
||||
static int
|
||||
compare_ascii(const void *a, const void *b)
|
||||
static int compare_ascii(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
|
||||
return strcmp(x->data, y->data);
|
||||
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
|
||||
return APPLY_REVERSE(strcmp(x->data, y->data));
|
||||
}
|
||||
|
||||
/* numeric order */
|
||||
static int
|
||||
compare_numeric(const void *a, const void *b)
|
||||
static int compare_numeric(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
int xint, yint;
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
int xint, yint;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
xint = strtoul(x->data, NULL, 10);
|
||||
yint = strtoul(y->data, NULL, 10);
|
||||
xint = strtoul(x->data, NULL, 10);
|
||||
yint = strtoul(y->data, NULL, 10);
|
||||
|
||||
return (xint - yint);
|
||||
return APPLY_REVERSE(xint - yint);
|
||||
}
|
||||
|
||||
|
||||
/* List */
|
||||
|
||||
/* */
|
||||
static List *
|
||||
list_init(List *self)
|
||||
static List *list_init(List * self)
|
||||
{
|
||||
self->len = 0;
|
||||
self->sorted = NULL;
|
||||
self->head = NULL;
|
||||
self->current = NULL;
|
||||
return self;
|
||||
self->len = 0;
|
||||
self->sorted = NULL;
|
||||
self->head = NULL;
|
||||
self->current = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* for simplicity, the List gains ownership of the line */
|
||||
static List *
|
||||
list_insert(List *self, Line *line)
|
||||
static List *list_insert(List * self, Line * line)
|
||||
{
|
||||
if (line == NULL) { return NULL; }
|
||||
if (line == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* first insertion */
|
||||
if (self->head == NULL) {
|
||||
self->head = line;
|
||||
self->current = line;
|
||||
/* first insertion */
|
||||
if (self->head == NULL) {
|
||||
self->head = line;
|
||||
self->current = line;
|
||||
|
||||
/* all subsequent insertions */
|
||||
} else {
|
||||
self->current->next = line;
|
||||
self->current = line;
|
||||
}
|
||||
self->len++;
|
||||
return self;
|
||||
/* all subsequent insertions */
|
||||
} else {
|
||||
self->current->next = line;
|
||||
self->current = line;
|
||||
}
|
||||
self->len++;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* order the list according to compare() */
|
||||
static List *
|
||||
list_sort(List *self, Compare *compare)
|
||||
static List *list_sort(List * self, Compare * compare)
|
||||
{
|
||||
int i;
|
||||
Line *line;
|
||||
int i;
|
||||
Line *line;
|
||||
|
||||
/* mallocate array of Line*s */
|
||||
self->sorted = (Line **) malloc(self->len * sizeof(Line*));
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
/* mallocate array of Line*s */
|
||||
self->sorted = (Line **) malloc(self->len * sizeof(Line *));
|
||||
if (self->sorted == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* fill array w/ List's contents */
|
||||
i = 0;
|
||||
line = self->head;
|
||||
while (line) {
|
||||
self->sorted[i++] = line;
|
||||
line = line->next;
|
||||
}
|
||||
/* fill array w/ List's contents */
|
||||
i = 0;
|
||||
line = self->head;
|
||||
while (line) {
|
||||
self->sorted[i++] = line;
|
||||
line = line->next;
|
||||
}
|
||||
|
||||
/* apply qsort */
|
||||
qsort(self->sorted, self->len, sizeof(Line*), compare);
|
||||
return self;
|
||||
/* apply qsort */
|
||||
qsort(self->sorted, self->len, sizeof(Line *), compare);
|
||||
return self;
|
||||
}
|
||||
|
||||
/* precondition: list must be sorted */
|
||||
static List *
|
||||
list_writeToFile(List *self, FILE* dst)
|
||||
static List *list_writeToFile(List * self, FILE * dst)
|
||||
{
|
||||
int i;
|
||||
Line **line = self->sorted;
|
||||
int i;
|
||||
Line **line = self->sorted;
|
||||
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
for (i = 0; i < self->len; i++) {
|
||||
fprintf(dst, "%s", line[i]->data);
|
||||
}
|
||||
return self;
|
||||
if (self->sorted == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < self->len; i++) {
|
||||
fprintf(dst, "%s", line[i]->data);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/* deallocate */
|
||||
static void
|
||||
list_release(List *self)
|
||||
static void list_release(List * self)
|
||||
{
|
||||
Line *i;
|
||||
Line *die;
|
||||
Line *i;
|
||||
Line *die;
|
||||
|
||||
i = self->head;
|
||||
while (i) {
|
||||
die = i;
|
||||
i = die->next;
|
||||
line_release(die);
|
||||
}
|
||||
i = self->head;
|
||||
while (i) {
|
||||
die = i;
|
||||
i = die->next;
|
||||
line_release(die);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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)
|
||||
int sort_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
List list;
|
||||
Line *l;
|
||||
Compare *compare;
|
||||
int i;
|
||||
char opt;
|
||||
List list;
|
||||
Line *l;
|
||||
Compare *compare;
|
||||
|
||||
/* init */
|
||||
compare = compare_ascii;
|
||||
list_init(&list);
|
||||
/* init */
|
||||
compare = compare_ascii;
|
||||
list_init(&list);
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'g':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'h':
|
||||
usage(sort_usage);
|
||||
break;
|
||||
case 'n':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'r':
|
||||
/* reverse */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
}
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
usage(sort_usage);
|
||||
break;
|
||||
case 'n':
|
||||
/* numeric comparison */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
case 'r':
|
||||
/* reverse */
|
||||
reverse = 1;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* this could be factored better */
|
||||
|
||||
/* work w/ stdin */
|
||||
if (i >= argc) {
|
||||
while ((l = line_newFromFile(stdin))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
|
||||
/* work w/ what's left in argv[] */
|
||||
} else {
|
||||
break;
|
||||
FILE *src;
|
||||
|
||||
for (; i < argc; i++) {
|
||||
src = fopen(argv[i], "r");
|
||||
if (src == NULL) {
|
||||
break;
|
||||
}
|
||||
while ((l = line_newFromFile(src))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
fclose(src);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
}
|
||||
}
|
||||
|
||||
/* this could be factored better */
|
||||
|
||||
/* work w/ stdin */
|
||||
if (i >= argc) {
|
||||
while ( (l = line_newFromFile(stdin))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
|
||||
/* work w/ what's left in argv[] */
|
||||
} else {
|
||||
FILE *src;
|
||||
|
||||
for ( ; i < argc; i++) {
|
||||
src = fopen(argv[i], "r");
|
||||
if (src == NULL) { break; }
|
||||
while ( (l = line_newFromFile(src))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
fclose(src);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.8 1999/12/23 22:46:10 beppu Exp $ */
|
||||
/* $Id: sort.c,v 1.15 2000/04/17 04:22:09 beppu Exp $ */
|
||||
+6
-7
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini sync implementation for busybox
|
||||
*
|
||||
@@ -23,12 +24,10 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int
|
||||
sync_main(int argc, char * * argv)
|
||||
extern int sync_main(int argc, char **argv)
|
||||
{
|
||||
if ( argc>1 && **(argv+1) == '-' ) {
|
||||
usage( "sync\n\nWrite all buffered filesystem blocks to disk.\n");
|
||||
}
|
||||
exit( sync());
|
||||
if (argc > 1 && **(argv + 1) == '-') {
|
||||
usage("sync\n\nWrite all buffered filesystem blocks to disk.\n");
|
||||
}
|
||||
exit(sync());
|
||||
}
|
||||
|
||||
+953
-643
File diff suppressed because it is too large.
Load diff
+73
-65
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini tee 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
|
||||
@@ -22,105 +23,112 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const char tee_usage[] =
|
||||
"tee [OPTION]... [FILE]...\n\n"
|
||||
"Copy standard input to each FILE, and also to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tappend to the given FILEs, do not overwrite\n"
|
||||
"tee [OPTION]... [FILE]...\n\n"
|
||||
"Copy standard input to each FILE, and also to standard output.\n\n"
|
||||
"Options:\n" "\t-a\tappend to the given FILEs, do not overwrite\n"
|
||||
#if 0
|
||||
"\t-i\tignore interrupt signals\n"
|
||||
"\t-i\tignore interrupt signals\n"
|
||||
#endif
|
||||
;
|
||||
;
|
||||
|
||||
|
||||
/* FileList _______________________________________________________________ */
|
||||
|
||||
#define FL_MAX 1024
|
||||
static FILE *FileList[FL_MAX];
|
||||
static int FL_end;
|
||||
static FILE **FileList;
|
||||
static int FL_end;
|
||||
|
||||
typedef void (FL_Function) (FILE * file, char c);
|
||||
|
||||
typedef void (FL_Function)(FILE *file, char c);
|
||||
|
||||
|
||||
/* apply a function to everything in FileList */
|
||||
static void
|
||||
FL_apply(FL_Function *f, char c)
|
||||
static void FL_apply(FL_Function * f, char c)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i <= FL_end; i++) {
|
||||
f(FileList[i], c);
|
||||
}
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= FL_end; i++) {
|
||||
f(FileList[i], c);
|
||||
}
|
||||
}
|
||||
|
||||
/* FL_Function for writing to files*/
|
||||
static void
|
||||
tee_fwrite(FILE *file, char c)
|
||||
static void tee_fwrite(FILE * file, char c)
|
||||
{
|
||||
fputc(c, file);
|
||||
fputc(c, file);
|
||||
}
|
||||
|
||||
/* FL_Function for closing files */
|
||||
static void
|
||||
tee_fclose(FILE *file, char c)
|
||||
static void tee_fclose(FILE * file, char c)
|
||||
{
|
||||
fclose(file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
|
||||
/* BusyBoxed tee(1) */
|
||||
int
|
||||
tee_main(int argc, char **argv)
|
||||
int tee_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
char opt;
|
||||
char opt_fopen[2] = "w";
|
||||
FILE *file;
|
||||
int i;
|
||||
char c;
|
||||
char opt;
|
||||
char opt_fopen[2] = "w";
|
||||
FILE *file;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
opt_fopen[0] = 'a';
|
||||
break;
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
opt_fopen[0] = 'a';
|
||||
break;
|
||||
#if 0
|
||||
case 'i':
|
||||
fprintf(stderr, "ignore interrupt not implemented\n");
|
||||
break;
|
||||
case 'i':
|
||||
fprintf(stderr, "ignore interrupt not implemented\n");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage(tee_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
default:
|
||||
usage(tee_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* init FILE pointers */
|
||||
FL_end = 0;
|
||||
FileList[0] = stdout;
|
||||
for ( ; i < argc; i++) {
|
||||
/* add a file to FileList */
|
||||
file = fopen(argv[i], opt_fopen);
|
||||
if (!file) { continue; }
|
||||
if (FL_end < FL_MAX) {
|
||||
FileList[++FL_end] = file;
|
||||
/* init FILE pointers */
|
||||
FileList = calloc(FL_MAX, sizeof(FILE*));
|
||||
if (!FileList) {
|
||||
fprintf(stderr, "tee: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
FL_end = 0;
|
||||
FileList[0] = stdout;
|
||||
for (; i < argc; i++) {
|
||||
/* add a file to FileList */
|
||||
file = fopen(argv[i], opt_fopen);
|
||||
if (!file) {
|
||||
continue;
|
||||
}
|
||||
if (FL_end < FL_MAX) {
|
||||
FileList[++FL_end] = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* read and redirect */
|
||||
while ((c = (char) getchar()) && (!feof(stdin))) {
|
||||
FL_apply(tee_fwrite, c);
|
||||
}
|
||||
/* read and redirect */
|
||||
while ((c = (char) getchar()) && (!feof(stdin))) {
|
||||
FL_apply(tee_fwrite, c);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
FL_apply(tee_fclose, 0);
|
||||
exit(0);
|
||||
/* clean up */
|
||||
FL_apply(tee_fclose, 0);
|
||||
/* Don't bother to close files Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* free(FileList); */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */
|
||||
/* $Id: tee.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
|
||||
@@ -0,0 +1,589 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* test implementation for busybox
|
||||
*
|
||||
* Copyright (c) by a whole pile of folks:
|
||||
*
|
||||
* test(1); version 7-like -- author Erik Baalbergen
|
||||
* modified by Eric Gisin to be used as built-in.
|
||||
* modified by Arnold Robbins to add SVR3 compatibility
|
||||
* (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
|
||||
* modified by J.T. Conklin for NetBSD.
|
||||
* modified by Herbert Xu to be used as built-in in ash.
|
||||
* modified by Erik Andersen <andersee@debian.org> to be used
|
||||
* in busybox.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Original copyright notice states:
|
||||
* "This program is in the Public Domain."
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* test(1) accepts the following grammar:
|
||||
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
||||
aexpr ::= nexpr | nexpr "-a" aexpr ;
|
||||
nexpr ::= primary | "!" primary
|
||||
primary ::= unary-operator operand
|
||||
| operand binary-operator operand
|
||||
| operand
|
||||
| "(" oexpr ")"
|
||||
;
|
||||
unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
|
||||
"-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
|
||||
|
||||
binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
|
||||
"-nt"|"-ot"|"-ef";
|
||||
operand ::= <any legal UNIX file name>
|
||||
*/
|
||||
|
||||
enum token {
|
||||
EOI,
|
||||
FILRD,
|
||||
FILWR,
|
||||
FILEX,
|
||||
FILEXIST,
|
||||
FILREG,
|
||||
FILDIR,
|
||||
FILCDEV,
|
||||
FILBDEV,
|
||||
FILFIFO,
|
||||
FILSOCK,
|
||||
FILSYM,
|
||||
FILGZ,
|
||||
FILTT,
|
||||
FILSUID,
|
||||
FILSGID,
|
||||
FILSTCK,
|
||||
FILNT,
|
||||
FILOT,
|
||||
FILEQ,
|
||||
FILUID,
|
||||
FILGID,
|
||||
STREZ,
|
||||
STRNZ,
|
||||
STREQ,
|
||||
STRNE,
|
||||
STRLT,
|
||||
STRGT,
|
||||
INTEQ,
|
||||
INTNE,
|
||||
INTGE,
|
||||
INTGT,
|
||||
INTLE,
|
||||
INTLT,
|
||||
UNOT,
|
||||
BAND,
|
||||
BOR,
|
||||
LPAREN,
|
||||
RPAREN,
|
||||
OPERAND
|
||||
};
|
||||
|
||||
enum token_types {
|
||||
UNOP,
|
||||
BINOP,
|
||||
BUNOP,
|
||||
BBINOP,
|
||||
PAREN
|
||||
};
|
||||
|
||||
struct t_op {
|
||||
const char *op_text;
|
||||
short op_num, op_type;
|
||||
} const ops [] = {
|
||||
{"-r", FILRD, UNOP},
|
||||
{"-w", FILWR, UNOP},
|
||||
{"-x", FILEX, UNOP},
|
||||
{"-e", FILEXIST,UNOP},
|
||||
{"-f", FILREG, UNOP},
|
||||
{"-d", FILDIR, UNOP},
|
||||
{"-c", FILCDEV,UNOP},
|
||||
{"-b", FILBDEV,UNOP},
|
||||
{"-p", FILFIFO,UNOP},
|
||||
{"-u", FILSUID,UNOP},
|
||||
{"-g", FILSGID,UNOP},
|
||||
{"-k", FILSTCK,UNOP},
|
||||
{"-s", FILGZ, UNOP},
|
||||
{"-t", FILTT, UNOP},
|
||||
{"-z", STREZ, UNOP},
|
||||
{"-n", STRNZ, UNOP},
|
||||
{"-h", FILSYM, UNOP}, /* for backwards compat */
|
||||
{"-O", FILUID, UNOP},
|
||||
{"-G", FILGID, UNOP},
|
||||
{"-L", FILSYM, UNOP},
|
||||
{"-S", FILSOCK,UNOP},
|
||||
{"=", STREQ, BINOP},
|
||||
{"!=", STRNE, BINOP},
|
||||
{"<", STRLT, BINOP},
|
||||
{">", STRGT, BINOP},
|
||||
{"-eq", INTEQ, BINOP},
|
||||
{"-ne", INTNE, BINOP},
|
||||
{"-ge", INTGE, BINOP},
|
||||
{"-gt", INTGT, BINOP},
|
||||
{"-le", INTLE, BINOP},
|
||||
{"-lt", INTLT, BINOP},
|
||||
{"-nt", FILNT, BINOP},
|
||||
{"-ot", FILOT, BINOP},
|
||||
{"-ef", FILEQ, BINOP},
|
||||
{"!", UNOT, BUNOP},
|
||||
{"-a", BAND, BBINOP},
|
||||
{"-o", BOR, BBINOP},
|
||||
{"(", LPAREN, PAREN},
|
||||
{")", RPAREN, PAREN},
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
char **t_wp;
|
||||
struct t_op const *t_wp_op;
|
||||
static gid_t *group_array = NULL;
|
||||
static int ngroups;
|
||||
|
||||
static enum token t_lex();
|
||||
static int oexpr();
|
||||
static int aexpr();
|
||||
static int nexpr();
|
||||
static int binop();
|
||||
static int primary();
|
||||
static int filstat();
|
||||
static int getn();
|
||||
static int newerf();
|
||||
static int olderf();
|
||||
static int equalf();
|
||||
static void syntax();
|
||||
static int test_eaccess();
|
||||
static int is_a_group_member();
|
||||
static void initialize_group_array();
|
||||
|
||||
extern int
|
||||
test_main(int argc, char** argv)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (strcmp(argv[0], "[") == 0) {
|
||||
if (strcmp(argv[--argc], "]"))
|
||||
fatalError("missing ]");
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
if (strcmp(argv[1], "--help") == 0) {
|
||||
usage("test EXPRESSION\n"
|
||||
"or [ EXPRESSION ]\n\n"
|
||||
"Checks file types and compares values returning an exit\n"
|
||||
"code determined by the value of EXPRESSION.\n");
|
||||
}
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
switch (argc) {
|
||||
case 1:
|
||||
exit( 1);
|
||||
case 2:
|
||||
exit (*argv[1] == '\0');
|
||||
case 3:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
exit (!(*argv[2] == '\0'));
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (argv[1][0] != '!' || argv[1][1] != '\0') {
|
||||
if (t_lex(argv[2]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[1];
|
||||
exit (binop() == 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
if (t_lex(argv[3]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[2];
|
||||
exit (!(binop() == 0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
t_wp = &argv[1];
|
||||
res = !oexpr(t_lex(*t_wp));
|
||||
|
||||
if (*t_wp != NULL && *++t_wp != NULL)
|
||||
syntax(*t_wp, "unknown operand");
|
||||
|
||||
exit( res);
|
||||
}
|
||||
|
||||
static void
|
||||
syntax(op, msg)
|
||||
char *op;
|
||||
char *msg;
|
||||
{
|
||||
if (op && *op)
|
||||
fatalError("%s: %s", op, msg);
|
||||
else
|
||||
fatalError("%s", msg);
|
||||
}
|
||||
|
||||
static int
|
||||
oexpr(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
res = aexpr(n);
|
||||
if (t_lex(*++t_wp) == BOR)
|
||||
return oexpr(t_lex(*++t_wp)) || res;
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
aexpr(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
res = nexpr(n);
|
||||
if (t_lex(*++t_wp) == BAND)
|
||||
return aexpr(t_lex(*++t_wp)) && res;
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
nexpr(n)
|
||||
enum token n; /* token */
|
||||
{
|
||||
if (n == UNOT)
|
||||
return !nexpr(t_lex(*++t_wp));
|
||||
return primary(n);
|
||||
}
|
||||
|
||||
static int
|
||||
primary(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
if (n == EOI)
|
||||
syntax(NULL, "argument expected");
|
||||
if (n == LPAREN) {
|
||||
res = oexpr(t_lex(*++t_wp));
|
||||
if (t_lex(*++t_wp) != RPAREN)
|
||||
syntax(NULL, "closing paren expected");
|
||||
return res;
|
||||
}
|
||||
if (t_wp_op && t_wp_op->op_type == UNOP) {
|
||||
/* unary expression */
|
||||
if (*++t_wp == NULL)
|
||||
syntax(t_wp_op->op_text, "argument expected");
|
||||
switch (n) {
|
||||
case STREZ:
|
||||
return strlen(*t_wp) == 0;
|
||||
case STRNZ:
|
||||
return strlen(*t_wp) != 0;
|
||||
case FILTT:
|
||||
return isatty(getn(*t_wp));
|
||||
default:
|
||||
return filstat(*t_wp, n);
|
||||
}
|
||||
}
|
||||
|
||||
if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
return binop();
|
||||
}
|
||||
|
||||
return strlen(*t_wp) > 0;
|
||||
}
|
||||
|
||||
static int
|
||||
binop()
|
||||
{
|
||||
const char *opnd1, *opnd2;
|
||||
struct t_op const *op;
|
||||
|
||||
opnd1 = *t_wp;
|
||||
(void) t_lex(*++t_wp);
|
||||
op = t_wp_op;
|
||||
|
||||
if ((opnd2 = *++t_wp) == (char *)0)
|
||||
syntax(op->op_text, "argument expected");
|
||||
|
||||
switch (op->op_num) {
|
||||
case STREQ:
|
||||
return strcmp(opnd1, opnd2) == 0;
|
||||
case STRNE:
|
||||
return strcmp(opnd1, opnd2) != 0;
|
||||
case STRLT:
|
||||
return strcmp(opnd1, opnd2) < 0;
|
||||
case STRGT:
|
||||
return strcmp(opnd1, opnd2) > 0;
|
||||
case INTEQ:
|
||||
return getn(opnd1) == getn(opnd2);
|
||||
case INTNE:
|
||||
return getn(opnd1) != getn(opnd2);
|
||||
case INTGE:
|
||||
return getn(opnd1) >= getn(opnd2);
|
||||
case INTGT:
|
||||
return getn(opnd1) > getn(opnd2);
|
||||
case INTLE:
|
||||
return getn(opnd1) <= getn(opnd2);
|
||||
case INTLT:
|
||||
return getn(opnd1) < getn(opnd2);
|
||||
case FILNT:
|
||||
return newerf (opnd1, opnd2);
|
||||
case FILOT:
|
||||
return olderf (opnd1, opnd2);
|
||||
case FILEQ:
|
||||
return equalf (opnd1, opnd2);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
filstat(nm, mode)
|
||||
char *nm;
|
||||
enum token mode;
|
||||
{
|
||||
struct stat s;
|
||||
int i;
|
||||
|
||||
if (mode == FILSYM) {
|
||||
#ifdef S_IFLNK
|
||||
if (lstat(nm, &s) == 0) {
|
||||
i = S_IFLNK;
|
||||
goto filetype;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (stat(nm, &s) != 0)
|
||||
return 0;
|
||||
|
||||
switch (mode) {
|
||||
case FILRD:
|
||||
return test_eaccess(nm, R_OK) == 0;
|
||||
case FILWR:
|
||||
return test_eaccess(nm, W_OK) == 0;
|
||||
case FILEX:
|
||||
return test_eaccess(nm, X_OK) == 0;
|
||||
case FILEXIST:
|
||||
return 1;
|
||||
case FILREG:
|
||||
i = S_IFREG;
|
||||
goto filetype;
|
||||
case FILDIR:
|
||||
i = S_IFDIR;
|
||||
goto filetype;
|
||||
case FILCDEV:
|
||||
i = S_IFCHR;
|
||||
goto filetype;
|
||||
case FILBDEV:
|
||||
i = S_IFBLK;
|
||||
goto filetype;
|
||||
case FILFIFO:
|
||||
#ifdef S_IFIFO
|
||||
i = S_IFIFO;
|
||||
goto filetype;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
case FILSOCK:
|
||||
#ifdef S_IFSOCK
|
||||
i = S_IFSOCK;
|
||||
goto filetype;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
case FILSUID:
|
||||
i = S_ISUID;
|
||||
goto filebit;
|
||||
case FILSGID:
|
||||
i = S_ISGID;
|
||||
goto filebit;
|
||||
case FILSTCK:
|
||||
i = S_ISVTX;
|
||||
goto filebit;
|
||||
case FILGZ:
|
||||
return s.st_size > 0L;
|
||||
case FILUID:
|
||||
return s.st_uid == geteuid();
|
||||
case FILGID:
|
||||
return s.st_gid == getegid();
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
filetype:
|
||||
return ((s.st_mode & S_IFMT) == i);
|
||||
|
||||
filebit:
|
||||
return ((s.st_mode & i) != 0);
|
||||
}
|
||||
|
||||
static enum token
|
||||
t_lex(s)
|
||||
char *s;
|
||||
{
|
||||
struct t_op const *op = ops;
|
||||
|
||||
if (s == 0) {
|
||||
t_wp_op = (struct t_op *)0;
|
||||
return EOI;
|
||||
}
|
||||
while (op->op_text) {
|
||||
if (strcmp(s, op->op_text) == 0) {
|
||||
t_wp_op = op;
|
||||
return op->op_num;
|
||||
}
|
||||
op++;
|
||||
}
|
||||
t_wp_op = (struct t_op *)0;
|
||||
return OPERAND;
|
||||
}
|
||||
|
||||
/* atoi with error detection */
|
||||
static int
|
||||
getn(s)
|
||||
char *s;
|
||||
{
|
||||
char *p;
|
||||
long r;
|
||||
|
||||
errno = 0;
|
||||
r = strtol(s, &p, 10);
|
||||
|
||||
if (errno != 0)
|
||||
fatalError("%s: out of range", s);
|
||||
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
|
||||
if (*p)
|
||||
fatalError("%s: bad number", s);
|
||||
|
||||
return (int) r;
|
||||
}
|
||||
|
||||
static int
|
||||
newerf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime > b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
olderf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime < b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
equalf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_dev == b2.st_dev &&
|
||||
b1.st_ino == b2.st_ino);
|
||||
}
|
||||
|
||||
/* Do the same thing access(2) does, but use the effective uid and gid,
|
||||
and don't make the mistake of telling root that any file is
|
||||
executable. */
|
||||
static int
|
||||
test_eaccess (path, mode)
|
||||
char *path;
|
||||
int mode;
|
||||
{
|
||||
struct stat st;
|
||||
int euid = geteuid();
|
||||
|
||||
if (stat (path, &st) < 0)
|
||||
return (-1);
|
||||
|
||||
if (euid == 0) {
|
||||
/* Root can read or write any file. */
|
||||
if (mode != X_OK)
|
||||
return (0);
|
||||
|
||||
/* Root can execute any file that has any one of the execute
|
||||
bits set. */
|
||||
if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (st.st_uid == euid) /* owner */
|
||||
mode <<= 6;
|
||||
else if (is_a_group_member (st.st_gid))
|
||||
mode <<= 3;
|
||||
|
||||
if (st.st_mode & mode)
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_group_array ()
|
||||
{
|
||||
ngroups = getgroups(0, NULL);
|
||||
if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
|
||||
fatalError("Out of space");
|
||||
|
||||
getgroups(ngroups, group_array);
|
||||
}
|
||||
|
||||
/* Return non-zero if GID is one that we have in our groups list. */
|
||||
static int
|
||||
is_a_group_member (gid)
|
||||
gid_t gid;
|
||||
{
|
||||
register int i;
|
||||
|
||||
/* Short-circuit if possible, maybe saving a call to getgroups(). */
|
||||
if (gid == getgid() || gid == getegid())
|
||||
return (1);
|
||||
|
||||
if (ngroups == 0)
|
||||
initialize_group_array ();
|
||||
|
||||
/* Search through the list looking for GID. */
|
||||
for (i = 0; i < ngroups; i++)
|
||||
if (gid == group_array[i])
|
||||
return (1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
+38
-43
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini touch implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -31,56 +32,50 @@
|
||||
|
||||
|
||||
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
|
||||
"Update the last-modified date on the given file[s].\n";
|
||||
|
||||
"Update the last-modified date on the given file[s].\n";
|
||||
|
||||
|
||||
|
||||
extern int
|
||||
touch_main(int argc, char **argv)
|
||||
extern int touch_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int create=TRUE;
|
||||
int fd;
|
||||
int create = TRUE;
|
||||
|
||||
if (argc < 2) {
|
||||
usage( touch_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv)) switch (**argv) {
|
||||
case 'c':
|
||||
create = FALSE;
|
||||
break;
|
||||
default:
|
||||
usage( touch_usage);
|
||||
exit( FALSE);
|
||||
if (argc < 2) {
|
||||
usage(touch_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
fd = open (*argv, (create==FALSE)? O_RDWR : O_RDWR | O_CREAT, 0644);
|
||||
if (fd < 0 ) {
|
||||
if (create==FALSE && errno == ENOENT)
|
||||
exit( TRUE);
|
||||
else {
|
||||
perror("touch");
|
||||
exit( FALSE);
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
create = FALSE;
|
||||
break;
|
||||
default:
|
||||
usage(touch_usage);
|
||||
exit(FALSE);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
}
|
||||
close( fd);
|
||||
if (utime (*argv, NULL)) {
|
||||
perror("touch");
|
||||
exit( FALSE);
|
||||
}
|
||||
else
|
||||
exit( TRUE);
|
||||
|
||||
fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT, 0644);
|
||||
if (fd < 0) {
|
||||
if (create == FALSE && errno == ENOENT)
|
||||
exit(TRUE);
|
||||
else {
|
||||
perror("touch");
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (utime(*argv, NULL)) {
|
||||
perror("touch");
|
||||
exit(FALSE);
|
||||
} else
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+574
@@ -0,0 +1,574 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static const char copyright[] = "@(#) Copyright (c) 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
|
||||
"$Id: tr.c,v 1.4 2000/04/17 16:44:46 erik Exp $";
|
||||
#endif /* not lint */
|
||||
#endif /* #if 0 */
|
||||
|
||||
#include "internal.h"
|
||||
#include <locale.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
enum { STRING1, STRING2 } which;
|
||||
enum { EOS, INFINITE, NORMAL, RANGE, SEQUENCE, SET } state;
|
||||
int cnt; /* character count */
|
||||
int lastch; /* last character */
|
||||
int equiv[2]; /* equivalence set */
|
||||
int *set; /* set of characters */
|
||||
char *str; /* user's string */
|
||||
} STR;
|
||||
|
||||
#include <limits.h>
|
||||
#define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */
|
||||
#define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */
|
||||
|
||||
static int next __P((STR *));
|
||||
|
||||
static int string1[NCHARS] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ASCII */
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
}, string2[NCHARS];
|
||||
|
||||
STR s1 = { STRING1, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
|
||||
STR s2 = { STRING2, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
|
||||
|
||||
static void setup(string, arg, str, cflag)
|
||||
int *string;
|
||||
char *arg;
|
||||
STR *str;
|
||||
int cflag;
|
||||
{
|
||||
register int cnt, *p;
|
||||
|
||||
str->str = arg;
|
||||
bzero(string, NCHARS * sizeof(int));
|
||||
|
||||
while (next(str))
|
||||
string[str->lastch] = 1;
|
||||
if (cflag)
|
||||
for (p = string, cnt = NCHARS; cnt--; ++p)
|
||||
*p = !*p;
|
||||
}
|
||||
|
||||
static void tr_usage()
|
||||
{
|
||||
usage( "\ttr [-cdsu] string1 [string2]\n\n"
|
||||
"Translate, squeeze, and/or delete characters from standard\n"
|
||||
"input, writing to standard output.\n");
|
||||
}
|
||||
|
||||
|
||||
extern int tr_main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int ch, cnt, lastch, *p;
|
||||
int cflag, dflag, sflag, isstring2;
|
||||
|
||||
(void) setlocale(LC_CTYPE, "");
|
||||
|
||||
cflag = dflag = sflag = 0;
|
||||
while ((ch = getopt(argc, argv, "cdsu")) != -1)
|
||||
switch ((char) ch) {
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
break;
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
case 'u':
|
||||
setbuf(stdout, (char *) NULL);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
tr_usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
default:
|
||||
tr_usage();
|
||||
/* NOTREACHED */
|
||||
case 1:
|
||||
isstring2 = 0;
|
||||
break;
|
||||
case 2:
|
||||
isstring2 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -ds [-c] string1 string2
|
||||
* Delete all characters (or complemented characters) in string1.
|
||||
* Squeeze all characters in string2.
|
||||
*/
|
||||
if (dflag && sflag) {
|
||||
if (!isstring2)
|
||||
tr_usage();
|
||||
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
setup(string2, argv[1], &s2, 0);
|
||||
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;)
|
||||
if (!string1[ch] && (!string2[ch] || lastch != ch)) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -d [-c] string1
|
||||
* Delete all characters (or complemented characters) in string1.
|
||||
*/
|
||||
if (dflag) {
|
||||
if (isstring2)
|
||||
tr_usage();
|
||||
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
|
||||
while ((ch = getchar()) != EOF)
|
||||
if (!string1[ch])
|
||||
(void) putchar(ch);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -s [-c] string1
|
||||
* Squeeze all characters (or complemented characters) in string1.
|
||||
*/
|
||||
if (sflag && !isstring2) {
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;)
|
||||
if (!string1[ch] || lastch != ch) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr [-cs] string1 string2
|
||||
* Replace all characters (or complemented characters) in string1 with
|
||||
* the character in the same position in string2. If the -s option is
|
||||
* specified, squeeze all the characters in string2.
|
||||
*/
|
||||
if (!isstring2)
|
||||
tr_usage();
|
||||
|
||||
s1.str = argv[0];
|
||||
s2.str = argv[1];
|
||||
|
||||
if (cflag)
|
||||
for (cnt = NCHARS, p = string1; cnt--;)
|
||||
*p++ = OOBCH;
|
||||
|
||||
if (!next(&s2))
|
||||
errx(1, "empty string2");
|
||||
|
||||
/* If string2 runs out of characters, use the last one specified. */
|
||||
if (sflag)
|
||||
while (next(&s1)) {
|
||||
string1[s1.lastch] = ch = s2.lastch;
|
||||
string2[ch] = 1;
|
||||
(void) next(&s2);
|
||||
} else
|
||||
while (next(&s1)) {
|
||||
string1[s1.lastch] = ch = s2.lastch;
|
||||
(void) next(&s2);
|
||||
}
|
||||
|
||||
if (cflag)
|
||||
for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
|
||||
*p = *p == OOBCH ? ch : cnt;
|
||||
|
||||
if (sflag)
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;) {
|
||||
ch = string1[ch];
|
||||
if (!string2[ch] || lastch != ch) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
}
|
||||
} else
|
||||
while ((ch = getchar()) != EOF)
|
||||
(void) putchar(string1[ch]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int backslash __P((STR *));
|
||||
static int bracket __P((STR *));
|
||||
static int c_class __P((const void *, const void *));
|
||||
static void genclass __P((STR *));
|
||||
static void genequiv __P((STR *));
|
||||
static int genrange __P((STR *));
|
||||
static void genseq __P((STR *));
|
||||
|
||||
static int next(s)
|
||||
register STR *s;
|
||||
{
|
||||
register int ch;
|
||||
|
||||
switch (s->state) {
|
||||
case EOS:
|
||||
return (0);
|
||||
case INFINITE:
|
||||
return (1);
|
||||
case NORMAL:
|
||||
switch (ch = (u_char) * s->str) {
|
||||
case '\0':
|
||||
s->state = EOS;
|
||||
return (0);
|
||||
case '\\':
|
||||
s->lastch = backslash(s);
|
||||
break;
|
||||
case '[':
|
||||
if (bracket(s))
|
||||
return (next(s));
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
++s->str;
|
||||
s->lastch = ch;
|
||||
break;
|
||||
}
|
||||
|
||||
/* We can start a range at any time. */
|
||||
if (s->str[0] == '-' && genrange(s))
|
||||
return (next(s));
|
||||
return (1);
|
||||
case RANGE:
|
||||
if (s->cnt-- == 0) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
++s->lastch;
|
||||
return (1);
|
||||
case SEQUENCE:
|
||||
if (s->cnt-- == 0) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
return (1);
|
||||
case SET:
|
||||
if ((s->lastch = s->set[s->cnt++]) == OOBCH) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int bracket(s)
|
||||
register STR *s;
|
||||
{
|
||||
register char *p;
|
||||
|
||||
switch (s->str[1]) {
|
||||
case ':': /* "[:class:]" */
|
||||
if ((p = strstr(s->str + 2, ":]")) == NULL)
|
||||
return (0);
|
||||
*p = '\0';
|
||||
s->str += 2;
|
||||
genclass(s);
|
||||
s->str = p + 2;
|
||||
return (1);
|
||||
case '=': /* "[=equiv=]" */
|
||||
if ((p = strstr(s->str + 2, "=]")) == NULL)
|
||||
return (0);
|
||||
s->str += 2;
|
||||
genequiv(s);
|
||||
return (1);
|
||||
default: /* "[\###*n]" or "[#*n]" */
|
||||
if ((p = strpbrk(s->str + 2, "*]")) == NULL)
|
||||
return (0);
|
||||
if (p[0] != '*' || index(p, ']') == NULL)
|
||||
return (0);
|
||||
s->str += 1;
|
||||
genseq(s);
|
||||
return (1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int (*func) __P((int));
|
||||
int *set;
|
||||
} CLASS;
|
||||
|
||||
static CLASS classes[] = {
|
||||
#undef isalnum
|
||||
{"alnum", isalnum,},
|
||||
#undef isalpha
|
||||
{"alpha", isalpha,},
|
||||
/*#undef isblank
|
||||
{ "blank", isblank, },*/
|
||||
#undef iscntrl
|
||||
{"cntrl", iscntrl,},
|
||||
#undef isdigit
|
||||
{"digit", isdigit,},
|
||||
#undef isgraph
|
||||
{"graph", isgraph,},
|
||||
#undef islower
|
||||
{"lower", islower,},
|
||||
#undef isprint
|
||||
{"print", isprint,},
|
||||
#undef ispunct
|
||||
{"punct", ispunct,},
|
||||
#undef isspace
|
||||
{"space", isspace,},
|
||||
#undef isupper
|
||||
{"upper", isupper,},
|
||||
#undef isxdigit
|
||||
{"xdigit", isxdigit,},
|
||||
};
|
||||
|
||||
static void genclass(s)
|
||||
STR *s;
|
||||
{
|
||||
register int cnt, (*func) __P((int));
|
||||
CLASS *cp, tmp;
|
||||
int *p;
|
||||
|
||||
tmp.name = s->str;
|
||||
if ((cp = (CLASS *) bsearch(&tmp, classes, sizeof(classes) /
|
||||
sizeof(CLASS), sizeof(CLASS),
|
||||
c_class)) == NULL) errx(1,
|
||||
"unknown class %s",
|
||||
s->str);
|
||||
|
||||
cp->set = p = xmalloc((NCHARS + 1) * sizeof(int));
|
||||
bzero(p, (NCHARS + 1) * sizeof(int));
|
||||
|
||||
for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt)
|
||||
if ((func) (cnt))
|
||||
*p++ = cnt;
|
||||
*p = OOBCH;
|
||||
|
||||
s->cnt = 0;
|
||||
s->state = SET;
|
||||
s->set = cp->set;
|
||||
}
|
||||
|
||||
static int c_class(a, b)
|
||||
const void *a, *b;
|
||||
{
|
||||
return (strcmp(((CLASS *) a)->name, ((CLASS *) b)->name));
|
||||
}
|
||||
|
||||
/*
|
||||
* English doesn't have any equivalence classes, so for now
|
||||
* we just syntax check and grab the character.
|
||||
*/
|
||||
static void genequiv(s)
|
||||
STR *s;
|
||||
{
|
||||
if (*s->str == '\\') {
|
||||
s->equiv[0] = backslash(s);
|
||||
if (*s->str != '=')
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
} else {
|
||||
s->equiv[0] = s->str[0];
|
||||
if (s->str[1] != '=')
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
}
|
||||
s->str += 2;
|
||||
s->cnt = 0;
|
||||
s->state = SET;
|
||||
s->set = s->equiv;
|
||||
}
|
||||
|
||||
static int genrange(s)
|
||||
STR *s;
|
||||
{
|
||||
int stopval;
|
||||
char *savestart;
|
||||
|
||||
savestart = s->str;
|
||||
stopval = *++s->str == '\\' ? backslash(s) : (u_char) * s->str++;
|
||||
if (stopval < (u_char) s->lastch) {
|
||||
s->str = savestart;
|
||||
return (0);
|
||||
}
|
||||
s->cnt = stopval - s->lastch + 1;
|
||||
s->state = RANGE;
|
||||
--s->lastch;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void genseq(s)
|
||||
STR *s;
|
||||
{
|
||||
char *ep;
|
||||
|
||||
if (s->which == STRING1)
|
||||
errx(1, "sequences only valid in string2");
|
||||
|
||||
if (*s->str == '\\')
|
||||
s->lastch = backslash(s);
|
||||
else
|
||||
s->lastch = *s->str++;
|
||||
if (*s->str != '*')
|
||||
errx(1, "misplaced sequence asterisk");
|
||||
|
||||
switch (*++s->str) {
|
||||
case '\\':
|
||||
s->cnt = backslash(s);
|
||||
break;
|
||||
case ']':
|
||||
s->cnt = 0;
|
||||
++s->str;
|
||||
break;
|
||||
default:
|
||||
if (isdigit((u_char) * s->str)) {
|
||||
s->cnt = strtol(s->str, &ep, 0);
|
||||
if (*ep == ']') {
|
||||
s->str = ep + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
errx(1, "illegal sequence count");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
s->state = s->cnt ? SEQUENCE : INFINITE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate \??? into a character. Up to 3 octal digits, if no digits either
|
||||
* an escape code or a literal character.
|
||||
*/
|
||||
static int backslash(s)
|
||||
register STR *s;
|
||||
{
|
||||
register int ch, cnt, val;
|
||||
|
||||
for (cnt = val = 0;;) {
|
||||
ch = (u_char) * ++s->str;
|
||||
if (!isascii(ch) || !isdigit(ch))
|
||||
break;
|
||||
val = val * 8 + ch - '0';
|
||||
if (++cnt == 3) {
|
||||
++s->str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cnt)
|
||||
return (val);
|
||||
if (ch != '\0')
|
||||
++s->str;
|
||||
switch (ch) {
|
||||
case 'a': /* escape characters */
|
||||
return ('\7');
|
||||
case 'b':
|
||||
return ('\b');
|
||||
case 'f':
|
||||
return ('\f');
|
||||
case 'n':
|
||||
return ('\n');
|
||||
case 'r':
|
||||
return ('\r');
|
||||
case 't':
|
||||
return ('\t');
|
||||
case 'v':
|
||||
return ('\13');
|
||||
case '\0': /* \" -> \ */
|
||||
s->state = EOS;
|
||||
return ('\\');
|
||||
default: /* \x" -> x */
|
||||
return (ch);
|
||||
}
|
||||
}
|
||||
+15
-10
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini tty implementation for busybox
|
||||
*
|
||||
@@ -24,19 +25,23 @@
|
||||
#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";
|
||||
"Print the file name of the terminal connected to standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tprint nothing, only return an exit status\n";
|
||||
|
||||
extern int tty_main(int argc, char **argv) {
|
||||
extern int tty_main(int argc, char **argv)
|
||||
{
|
||||
char *tty;
|
||||
|
||||
if (argc > 1) {
|
||||
if (argv[1][0] != '-' || argv[1][1] != 's') usage (tty_usage);
|
||||
if (argv[1][0] != '-' || argv[1][1] != 's')
|
||||
usage(tty_usage);
|
||||
} else {
|
||||
tty = ttyname(0);
|
||||
if (tty)
|
||||
puts(tty);
|
||||
else
|
||||
puts("not a tty");
|
||||
}
|
||||
else {
|
||||
tty = ttyname (0);
|
||||
if (tty) puts (tty);
|
||||
else puts ("not a tty");
|
||||
}
|
||||
exit (isatty (0) ? TRUE : FALSE);
|
||||
exit(isatty(0) ? TRUE : FALSE);
|
||||
}
|
||||
+73
-67
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* uname -- print system information
|
||||
Copyright (C) 1989-1999 Free Software Foundation, Inc.
|
||||
|
||||
@@ -41,16 +42,20 @@
|
||||
|
||||
|
||||
static const char uname_usage[] =
|
||||
"uname [OPTION]...\n\n"
|
||||
"Print certain system information. With no OPTION, same as -s.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tprint all information\n"
|
||||
"\t-m\tthe machine (hardware) type\n"
|
||||
"\t-n\tprint the machine's network node hostname\n"
|
||||
"\t-r\tprint the operating system release\n"
|
||||
"\t-s\tprint the operating system name\n"
|
||||
"\t-p\tprint the host processor type\n"
|
||||
"\t-v\tprint the operating system version\n";
|
||||
"uname [OPTION]...\n\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Print certain system information. With no OPTION, same as -s.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tprint all information\n"
|
||||
"\t-m\tthe machine (hardware) type\n"
|
||||
"\t-n\tprint the machine's network node hostname\n"
|
||||
"\t-r\tprint the operating system release\n"
|
||||
"\t-s\tprint the operating system name\n"
|
||||
|
||||
"\t-p\tprint the host processor type\n"
|
||||
"\t-v\tprint the operating system version\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static void print_element(unsigned int mask, char *element);
|
||||
@@ -80,77 +85,78 @@ static unsigned char toprint;
|
||||
|
||||
int uname_main(int argc, char **argv)
|
||||
{
|
||||
struct utsname name;
|
||||
char processor[256];
|
||||
struct utsname name;
|
||||
char processor[256];
|
||||
|
||||
#if defined(__sparc__) && defined(__linux__)
|
||||
char *fake_sparc = getenv("FAKE_SPARC");
|
||||
char *fake_sparc = getenv("FAKE_SPARC");
|
||||
#endif
|
||||
|
||||
toprint = 0;
|
||||
toprint = 0;
|
||||
|
||||
/* Parse any options */
|
||||
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
toprint |= PRINT_SYSNAME;
|
||||
break;
|
||||
case 'n':
|
||||
toprint |= PRINT_NODENAME;
|
||||
break;
|
||||
case 'r':
|
||||
toprint |= PRINT_RELEASE;
|
||||
break;
|
||||
case 'v':
|
||||
toprint |= PRINT_VERSION;
|
||||
break;
|
||||
case 'm':
|
||||
toprint |= PRINT_MACHINE;
|
||||
break;
|
||||
case 'p':
|
||||
toprint |= PRINT_PROCESSOR;
|
||||
break;
|
||||
case 'a':
|
||||
toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
|
||||
PRINT_PROCESSOR | PRINT_VERSION |
|
||||
PRINT_MACHINE);
|
||||
break;
|
||||
default:
|
||||
usage(uname_usage);
|
||||
}
|
||||
/* Parse any options */
|
||||
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
toprint |= PRINT_SYSNAME;
|
||||
break;
|
||||
case 'n':
|
||||
toprint |= PRINT_NODENAME;
|
||||
break;
|
||||
case 'r':
|
||||
toprint |= PRINT_RELEASE;
|
||||
break;
|
||||
case 'v':
|
||||
toprint |= PRINT_VERSION;
|
||||
break;
|
||||
case 'm':
|
||||
toprint |= PRINT_MACHINE;
|
||||
break;
|
||||
case 'p':
|
||||
toprint |= PRINT_PROCESSOR;
|
||||
break;
|
||||
case 'a':
|
||||
toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
|
||||
PRINT_PROCESSOR | PRINT_VERSION |
|
||||
PRINT_MACHINE);
|
||||
break;
|
||||
default:
|
||||
usage(uname_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toprint == 0)
|
||||
toprint = PRINT_SYSNAME;
|
||||
if (toprint == 0)
|
||||
toprint = PRINT_SYSNAME;
|
||||
|
||||
if (uname(&name) == -1)
|
||||
perror("cannot get system name");
|
||||
if (uname(&name) == -1)
|
||||
perror("cannot get system name");
|
||||
|
||||
#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
|
||||
if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
|
||||
perror("cannot get processor type");
|
||||
if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
|
||||
perror("cannot get processor type");
|
||||
}
|
||||
|
||||
#else
|
||||
strcpy(processor, "unknown");
|
||||
strcpy(processor, "unknown");
|
||||
#endif
|
||||
|
||||
#if defined(__sparc__) && defined(__linux__)
|
||||
if (fake_sparc != NULL
|
||||
&& (fake_sparc[0] == 'y'
|
||||
|| fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
|
||||
if (fake_sparc != NULL
|
||||
&& (fake_sparc[0] == 'y'
|
||||
|| fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
|
||||
#endif
|
||||
|
||||
print_element(PRINT_SYSNAME, name.sysname);
|
||||
print_element(PRINT_NODENAME, name.nodename);
|
||||
print_element(PRINT_RELEASE, name.release);
|
||||
print_element(PRINT_VERSION, name.version);
|
||||
print_element(PRINT_MACHINE, name.machine);
|
||||
print_element(PRINT_PROCESSOR, processor);
|
||||
print_element(PRINT_SYSNAME, name.sysname);
|
||||
print_element(PRINT_NODENAME, name.nodename);
|
||||
print_element(PRINT_RELEASE, name.release);
|
||||
print_element(PRINT_VERSION, name.version);
|
||||
print_element(PRINT_MACHINE, name.machine);
|
||||
print_element(PRINT_PROCESSOR, processor);
|
||||
|
||||
exit(TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* If the name element set in MASK is selected for printing in `toprint',
|
||||
@@ -159,8 +165,8 @@ int uname_main(int argc, char **argv)
|
||||
|
||||
static void print_element(unsigned int mask, char *element)
|
||||
{
|
||||
if (toprint & mask) {
|
||||
toprint &= ~mask;
|
||||
printf("%s%c", element, toprint ? ' ' : '\n');
|
||||
}
|
||||
if (toprint & mask) {
|
||||
toprint &= ~mask;
|
||||
printf("%s%c", element, toprint ? ' ' : '\n');
|
||||
}
|
||||
}
|
||||
+106
-115
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini uniq 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
|
||||
@@ -27,119 +28,110 @@
|
||||
#include <errno.h>
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"Usage: uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||
"standard input), writing to OUTPUT (or standard output).\n"
|
||||
"\n"
|
||||
"\t-h\tdisplay this help and exit\n"
|
||||
"\n"
|
||||
"A field is a run of whitespace, then non-whitespace characters.\n"
|
||||
"Fields are skipped before chars.\n"
|
||||
;
|
||||
"uniq [OPTION]... [INPUT [OUTPUT]]\n\n"
|
||||
"Discard all but one of successive identical lines from INPUT\n"
|
||||
"(or standard input), writing to OUTPUT (or standard output).\n";
|
||||
|
||||
/* max chars in line */
|
||||
#define UNIQ_MAX 4096
|
||||
|
||||
typedef void (Print)(FILE *, const char *);
|
||||
typedef void (Print) (FILE *, const char *);
|
||||
|
||||
typedef int (Decide)(const char *, const char *);
|
||||
typedef int (Decide) (const char *, const char *);
|
||||
|
||||
/* container for two lines to be compared */
|
||||
typedef struct {
|
||||
char *a;
|
||||
char *b;
|
||||
int recurrence;
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
void *func;
|
||||
char *a;
|
||||
char *b;
|
||||
int recurrence;
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
void *func;
|
||||
} Subject;
|
||||
|
||||
/* set up all the variables of a uniq operation */
|
||||
static Subject *
|
||||
subject_init(Subject *self, FILE *in, FILE *out, void *func)
|
||||
static Subject *subject_init(Subject * self, FILE * in, FILE * out,
|
||||
void *func)
|
||||
{
|
||||
self->a = NULL;
|
||||
self->b = NULL;
|
||||
self->in = in;
|
||||
self->out = out;
|
||||
self->func = func;
|
||||
self->recurrence = 0;
|
||||
return self;
|
||||
self->a = NULL;
|
||||
self->b = NULL;
|
||||
self->in = in;
|
||||
self->out = out;
|
||||
self->func = func;
|
||||
self->recurrence = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* point a and b to the appropriate lines;
|
||||
* count the recurrences (if any) of a string;
|
||||
*/
|
||||
static Subject *
|
||||
subject_next(Subject *self)
|
||||
static Subject *subject_next(Subject * self)
|
||||
{
|
||||
/* tmp line holders */
|
||||
static char line[2][UNIQ_MAX];
|
||||
static int alternator = 0;
|
||||
/* tmp line holders */
|
||||
static char line[2][UNIQ_MAX];
|
||||
static int alternator = 0;
|
||||
|
||||
if (fgets(line[alternator], UNIQ_MAX, self->in)) {
|
||||
if (fgets(line[alternator], UNIQ_MAX, self->in)) {
|
||||
self->a = self->b;
|
||||
self->b = line[alternator];
|
||||
alternator ^= 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Subject *subject_last(Subject * self)
|
||||
{
|
||||
self->a = self->b;
|
||||
self->b = line[alternator];
|
||||
alternator ^= 1;
|
||||
self->b = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_last(Subject *self)
|
||||
static Subject *subject_study(Subject * self)
|
||||
{
|
||||
self->a = self->b;
|
||||
self->b = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_study(Subject *self)
|
||||
{
|
||||
if (self->a == NULL) {
|
||||
if (self->a == NULL) {
|
||||
return self;
|
||||
}
|
||||
if (self->b == NULL) {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
return self;
|
||||
}
|
||||
if (strcmp(self->a, self->b) == 0) {
|
||||
self->recurrence++;
|
||||
} else {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
self->recurrence = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
if (self->b == NULL) {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
return self;
|
||||
}
|
||||
if (strcmp(self->a, self->b) == 0) {
|
||||
self->recurrence++;
|
||||
} else {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
self->recurrence = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static int
|
||||
set_file_pointers(int schema, FILE **in, FILE **out, char **argv)
|
||||
set_file_pointers(int schema, FILE ** in, FILE ** out, char **argv)
|
||||
{
|
||||
switch (schema) {
|
||||
switch (schema) {
|
||||
case 0:
|
||||
*in = stdin;
|
||||
*out = stdout;
|
||||
break;
|
||||
*in = stdin;
|
||||
*out = stdout;
|
||||
break;
|
||||
case 1:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = stdout;
|
||||
break;
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = stdout;
|
||||
break;
|
||||
case 2:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = fopen(argv[1], "w");
|
||||
break;
|
||||
}
|
||||
if (*in == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[0], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if (*out == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[1], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = fopen(argv[1], "w");
|
||||
break;
|
||||
}
|
||||
if (*in == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[0], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if (*out == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[1], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,45 +144,44 @@ set_file_pointers(int schema, FILE **in, FILE **out, char **argv)
|
||||
/* it seems like GNU/uniq only takes one or two files as an option */
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
int
|
||||
uniq_main(int argc, char **argv)
|
||||
int uniq_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
FILE *in, *out;
|
||||
Subject s;
|
||||
int i;
|
||||
char opt;
|
||||
FILE *in, *out;
|
||||
Subject s;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(uniq_usage);
|
||||
default:
|
||||
usage(uniq_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(uniq_usage);
|
||||
default:
|
||||
usage(uniq_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 0 src: stdin; dst: stdout */
|
||||
/* 1 src: file; dst: stdout */
|
||||
/* 2 src: file; dst: file */
|
||||
if (set_file_pointers((argc - 1), &in, &out, &argv[i])) {
|
||||
exit(1);
|
||||
}
|
||||
/* 0 src: stdin; dst: stdout */
|
||||
/* 1 src: file; dst: stdout */
|
||||
/* 2 src: file; dst: file */
|
||||
if (set_file_pointers((argc - 1), &in, &out, &argv[i])) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
subject_init(&s, in, out, NULL);
|
||||
while (subject_next(&s)) {
|
||||
subject_init(&s, in, out, NULL);
|
||||
while (subject_next(&s)) {
|
||||
subject_study(&s);
|
||||
}
|
||||
subject_last(&s);
|
||||
subject_study(&s);
|
||||
}
|
||||
subject_last(&s);
|
||||
subject_study(&s);
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.4 2000/01/07 01:57:32 beppu Exp $ */
|
||||
/* $Id: uniq.c,v 1.9 2000/04/17 16:16:10 erik Exp $ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini usleep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char usleep_usage[] = "usleep N\n\n" "Pause for N microseconds.\n";
|
||||
|
||||
extern int usleep_main(int argc, char **argv)
|
||||
{
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(usleep_usage);
|
||||
}
|
||||
|
||||
usleep(atoi(*(++argv))); /* return void */
|
||||
exit(TRUE);
|
||||
}
|
||||
+67
-62
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini wc implementation for busybox
|
||||
*
|
||||
@@ -23,79 +24,83 @@
|
||||
#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";
|
||||
"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\n"
|
||||
"Options:\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-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) {
|
||||
void print_counts(int lines, int words, int chars, int length,
|
||||
const char *name)
|
||||
{
|
||||
char const *space = "";
|
||||
|
||||
if (print_lines) {
|
||||
printf ("%7d", lines);
|
||||
printf("%7d", lines);
|
||||
space = " ";
|
||||
}
|
||||
if (print_words) {
|
||||
printf ("%s%7d", space, words);
|
||||
printf("%s%7d", space, words);
|
||||
space = " ";
|
||||
}
|
||||
if (print_chars) {
|
||||
printf ("%s%7d", space, chars);
|
||||
printf("%s%7d", space, chars);
|
||||
space = " ";
|
||||
}
|
||||
if (print_length)
|
||||
printf ("%s%7d", space, length);
|
||||
printf("%s%7d", space, length);
|
||||
if (*name)
|
||||
printf (" %s", name);
|
||||
putchar ('\n');
|
||||
printf(" %s", name);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void wc_file(FILE *file, const char *name)
|
||||
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;
|
||||
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);
|
||||
print_counts(lines, words, chars, length, name);
|
||||
total_lines += lines;
|
||||
total_words += words;
|
||||
total_chars += chars;
|
||||
@@ -105,28 +110,30 @@ static void wc_file(FILE *file, const char *name)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int wc_main(int argc, char **argv) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,16 +143,14 @@ int wc_main(int argc, char **argv) {
|
||||
if (argc == 0) {
|
||||
wc_file(stdin, "");
|
||||
exit(TRUE);
|
||||
}
|
||||
else if (argc == 1) {
|
||||
} else if (argc == 1) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
wc_file(file, *argv);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
@@ -155,8 +160,8 @@ int wc_main(int argc, char **argv) {
|
||||
wc_file(file, *argv);
|
||||
argv++;
|
||||
}
|
||||
print_counts (total_lines, total_words, total_chars,
|
||||
max_length, "total");
|
||||
print_counts(total_lines, total_words, total_chars,
|
||||
max_length, "total");
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
+14
-11
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini whoami implementation for busybox
|
||||
*
|
||||
@@ -24,21 +25,23 @@
|
||||
#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";
|
||||
"Prints the user name associated with the current effective user id.\n";
|
||||
|
||||
extern int whoami_main(int argc, char **argv) {
|
||||
extern int whoami_main(int argc, char **argv)
|
||||
{
|
||||
struct passwd *pw;
|
||||
uid_t uid;
|
||||
|
||||
if (argc > 1) usage (whoami_usage);
|
||||
if (argc > 1)
|
||||
usage(whoami_usage);
|
||||
|
||||
uid = geteuid ();
|
||||
pw = getpwuid (uid);
|
||||
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);
|
||||
puts(pw->pw_name);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "%s: cannot find username for UID %u\n", argv[0],
|
||||
(unsigned) uid);
|
||||
exit(FALSE);
|
||||
}
|
||||
+16
-6
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini yes implementation for busybox
|
||||
*
|
||||
@@ -22,19 +23,28 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int yes_main(int argc, char **argv) {
|
||||
extern int yes_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
if (argc == 1)
|
||||
|
||||
if (argc >=1 && *argv[1]=='-') {
|
||||
usage("yes [OPTION]... [STRING]...\n\n"
|
||||
"Repeatedly outputs a line with all specified STRING(s), or `y'.\n");
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
while (1)
|
||||
if (puts ("y") == EOF) {
|
||||
perror ("yes");
|
||||
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");
|
||||
if (fputs(argv[i], stdout) == EOF
|
||||
|| putchar(i == argc - 1 ? '\n' : ' ') == EOF) {
|
||||
perror("yes");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Mini cp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
|
||||
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
static int followLinks = FALSE;
|
||||
static int preserveFlag = FALSE;
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
char* newsrcName = NULL;
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
if (recursiveFlag!=TRUE ) {
|
||||
fprintf(stderr, "cp: %s: omitting directory\n", srcName);
|
||||
return( TRUE);
|
||||
}
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
newsrcName = strrchr(srcName, '/');
|
||||
if (newsrcName && *newsrcName != '\0')
|
||||
strcat(newdestName, newsrcName);
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
|
||||
extern int cp_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
followLinks = TRUE;
|
||||
preserveFlag = TRUE;
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'd':
|
||||
followLinks = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
preserveFlag = TRUE;
|
||||
break;
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
destName = argv[argc - 1];
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini `cp' and `mv' implementation for BusyBox.
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* Copyright (C) 2000 by BitterSweet Enterprises, LLC. (GPL)
|
||||
* Extensively modified and rewritten by Karl M. Hegbloom <karlheg@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"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_name_too_long
|
||||
#define bb_need_omitting_directory
|
||||
#define bb_need_not_a_directory
|
||||
#include "messages.c"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/param.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define is_cp 0
|
||||
#define is_mv 1
|
||||
static int dz_i; /* index into cp_mv_usage */
|
||||
static const char *dz; /* dollar zero, .bss */
|
||||
static const char *cp_mv_usage[] = /* .rodata */
|
||||
{
|
||||
"cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n",
|
||||
"mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
|
||||
};
|
||||
|
||||
static int recursiveFlag;
|
||||
static int followLinks;
|
||||
static int preserveFlag;
|
||||
|
||||
static const char *baseSrcName;
|
||||
static int srcDirFlag;
|
||||
static struct stat srcStatBuf;
|
||||
|
||||
static char baseDestName[PATH_MAX + 1];
|
||||
static size_t baseDestLen;
|
||||
static int destDirFlag;
|
||||
static struct stat destStatBuf;
|
||||
|
||||
static jmp_buf catch;
|
||||
static volatile int mv_Action_first_time;
|
||||
|
||||
static void name_too_long__exit (void) __attribute__((noreturn));
|
||||
|
||||
static
|
||||
void name_too_long__exit (void)
|
||||
{
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
fill_baseDest_buf(char *_buf, size_t * _buflen) {
|
||||
const char *srcBasename;
|
||||
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
|
||||
srcBasename = baseSrcName;
|
||||
if (_buf[*_buflen - 1] != '/') {
|
||||
if (++(*_buflen) > PATH_MAX)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, "/");
|
||||
}
|
||||
}
|
||||
if (*_buflen + strlen(srcBasename) > PATH_MAX)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, srcBasename);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
char destName[PATH_MAX + 1];
|
||||
size_t destLen;
|
||||
const char *srcBasename;
|
||||
char *name;
|
||||
|
||||
strcpy(destName, baseDestName);
|
||||
destLen = strlen(destName);
|
||||
|
||||
if (srcDirFlag == TRUE) {
|
||||
if (recursiveFlag == FALSE) {
|
||||
fprintf(stderr, omitting_directory, dz, baseSrcName);
|
||||
return TRUE;
|
||||
}
|
||||
srcBasename = (strstr(fileName, baseSrcName)
|
||||
+ strlen(baseSrcName));
|
||||
|
||||
if (destLen + strlen(srcBasename) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
return FALSE;
|
||||
}
|
||||
strcat(destName, srcBasename);
|
||||
}
|
||||
else if (destDirFlag == TRUE) {
|
||||
fill_baseDest_buf(&destName[0], &destLen);
|
||||
}
|
||||
else {
|
||||
srcBasename = baseSrcName;
|
||||
}
|
||||
if (mv_Action_first_time && (dz_i == is_mv)) {
|
||||
mv_Action_first_time = errno = 0;
|
||||
if (rename(fileName, destName) < 0 && errno != EXDEV) {
|
||||
fprintf(stderr, "%s: rename(%s, %s): %s\n",
|
||||
dz, fileName, destName, strerror(errno));
|
||||
goto do_copyFile; /* Try anyway... */
|
||||
}
|
||||
else if (errno == EXDEV)
|
||||
goto do_copyFile;
|
||||
else
|
||||
longjmp(catch, 1); /* succeeded with rename() */
|
||||
}
|
||||
do_copyFile:
|
||||
if (preserveFlag == TRUE && statbuf->st_nlink > 1) {
|
||||
if (is_in_ino_dev_hashtable(statbuf, &name)) {
|
||||
if (link(name, destName) < 0) {
|
||||
fprintf(stderr, "%s: link(%s, %s): %s\n",
|
||||
dz, name, destName, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(statbuf, destName);
|
||||
}
|
||||
}
|
||||
return copyFile(fileName, destName, preserveFlag, followLinks);
|
||||
}
|
||||
|
||||
static int
|
||||
rm_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
int status = TRUE;
|
||||
|
||||
if (S_ISDIR(statbuf->st_mode)) {
|
||||
if (rmdir(fileName) < 0) {
|
||||
fprintf(stderr, "%s: rmdir(%s): %s\n", dz, fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
} else if (unlink(fileName) < 0) {
|
||||
fprintf(stderr, "%s: unlink(%s): %s\n", dz, fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
extern int cp_mv_main(int argc, char **argv)
|
||||
{
|
||||
dz = *argv; /* already basename'd by busybox.c:main */
|
||||
if (*dz == 'c' && *(dz + 1) == 'p')
|
||||
dz_i = is_cp;
|
||||
else
|
||||
dz_i = is_mv;
|
||||
if (argc < 3)
|
||||
usage(cp_mv_usage[dz_i]);
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (dz_i == is_cp) {
|
||||
recursiveFlag = preserveFlag = FALSE;
|
||||
followLinks = TRUE;
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
followLinks = FALSE;
|
||||
preserveFlag = TRUE;
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'd':
|
||||
followLinks = FALSE;
|
||||
break;
|
||||
case 'p':
|
||||
preserveFlag = TRUE;
|
||||
break;
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(cp_mv_usage[is_cp]);
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
} else { /* (dz_i == is_mv) */
|
||||
recursiveFlag = preserveFlag = TRUE;
|
||||
followLinks = FALSE;
|
||||
}
|
||||
|
||||
if (strlen(argv[argc - 1]) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
goto exit_false;
|
||||
}
|
||||
strcpy(baseDestName, argv[argc - 1]);
|
||||
baseDestLen = strlen(baseDestName);
|
||||
if (baseDestLen == 0)
|
||||
goto exit_false;
|
||||
|
||||
destDirFlag = isDirectory(baseDestName, TRUE, &destStatBuf);
|
||||
if ((argc > 3) && destDirFlag == FALSE) {
|
||||
fprintf(stderr, not_a_directory, "cp", baseDestName);
|
||||
goto exit_false;
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
size_t srcLen;
|
||||
volatile int flags_memo;
|
||||
int status;
|
||||
|
||||
baseSrcName = *(argv++);
|
||||
|
||||
if ((srcLen = strlen(baseSrcName)) > PATH_MAX)
|
||||
name_too_long__exit();
|
||||
|
||||
if (srcLen == 0) continue; /* "" */
|
||||
|
||||
srcDirFlag = isDirectory(baseSrcName, followLinks, &srcStatBuf);
|
||||
|
||||
if ((flags_memo = (recursiveFlag == TRUE &&
|
||||
srcDirFlag == TRUE && destDirFlag == TRUE))) {
|
||||
|
||||
struct stat sb;
|
||||
int state = 0;
|
||||
char *pushd, *d, *p;
|
||||
|
||||
if ((pushd = getcwd(NULL, PATH_MAX + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if (chdir(baseDestName) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if ((d = getcwd(NULL, PATH_MAX + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
while (!state && *d != '\0') {
|
||||
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
|
||||
fprintf(stderr, "%s: stat(%s) :%s\n", dz, d, strerror(errno));
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
if ((sb.st_ino == srcStatBuf.st_ino) &&
|
||||
(sb.st_dev == srcStatBuf.st_dev)) {
|
||||
fprintf(stderr,
|
||||
"%s: Cannot %s `%s' "
|
||||
"into a subdirectory of itself, `%s/%s'\n",
|
||||
dz, dz, baseSrcName, baseDestName, baseSrcName);
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
if ((p = strrchr(d, '/')) != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
if (chdir(pushd) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, pushd, strerror(errno));
|
||||
free(pushd);
|
||||
free(d);
|
||||
continue;
|
||||
}
|
||||
free(pushd);
|
||||
free(d);
|
||||
if (state < 0)
|
||||
continue;
|
||||
else
|
||||
fill_baseDest_buf(baseDestName, &baseDestLen);
|
||||
}
|
||||
status = setjmp(catch);
|
||||
if (status == 0) {
|
||||
mv_Action_first_time = 1;
|
||||
if (recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, FALSE,
|
||||
cp_mv_Action, cp_mv_Action, NULL) == FALSE) goto exit_false;
|
||||
if (dz_i == is_mv &&
|
||||
recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, TRUE,
|
||||
rm_Action, rm_Action, NULL) == FALSE) goto exit_false;
|
||||
}
|
||||
if (flags_memo)
|
||||
*(baseDestName + baseDestLen) = '\0';
|
||||
}
|
||||
// exit_true:
|
||||
exit TRUE;
|
||||
exit_false:
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini date implementation for busybox
|
||||
*
|
||||
@@ -20,6 +21,10 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_date
|
||||
#define bb_need_memory_exhausted
|
||||
#include "messages.c"
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
@@ -34,12 +39,13 @@
|
||||
an RFC 822 complient date output for shell scripting
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
@@ -47,241 +53,224 @@ static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
|
||||
/* Default input handling to save suprising some people */
|
||||
|
||||
struct tm *
|
||||
date_conv_time(struct tm *tm_time, const char *t_string) {
|
||||
int nr;
|
||||
struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
int nr;
|
||||
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min),
|
||||
&(tm_time->tm_year));
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
|
||||
if(nr < 4 || nr > 5) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (nr < 4 || nr > 5) {
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if(tm_time->tm_year >= 1900)
|
||||
tm_time->tm_year -= 1900;
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
return(tm_time);
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time->tm_year >= 1900)
|
||||
tm_time->tm_year -= 1900;
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
return (tm_time);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* The new stuff for LRP */
|
||||
|
||||
struct tm *
|
||||
date_conv_ftime(struct tm *tm_time, const char *t_string) {
|
||||
struct tm itm_time, jtm_time, ktm_time, \
|
||||
ltm_time, mtm_time, ntm_time;
|
||||
|
||||
itm_time = *tm_time;
|
||||
jtm_time = *tm_time;
|
||||
ktm_time = *tm_time;
|
||||
ltm_time = *tm_time;
|
||||
mtm_time = *tm_time;
|
||||
ntm_time = *tm_time;
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if(sscanf(t_string, "%d:%d:%d",
|
||||
&itm_time.tm_hour,
|
||||
&itm_time.tm_min,
|
||||
&itm_time.tm_sec) == 3 ) {
|
||||
|
||||
*tm_time = itm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d:%d",
|
||||
&jtm_time.tm_hour,
|
||||
&jtm_time.tm_min) == 2) {
|
||||
|
||||
*tm_time = jtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&ktm_time.tm_mon,
|
||||
&ktm_time.tm_mday,
|
||||
&ktm_time.tm_hour,
|
||||
&ktm_time.tm_min,
|
||||
&ktm_time.tm_sec) == 5) {
|
||||
|
||||
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ktm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d",
|
||||
<m_time.tm_mon,
|
||||
<m_time.tm_mday,
|
||||
<m_time.tm_hour,
|
||||
<m_time.tm_min) == 4) {
|
||||
|
||||
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ltm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&mtm_time.tm_year,
|
||||
&mtm_time.tm_mon,
|
||||
&mtm_time.tm_mday,
|
||||
&mtm_time.tm_hour,
|
||||
&mtm_time.tm_min,
|
||||
&mtm_time.tm_sec) == 6) {
|
||||
|
||||
mtm_time.tm_year -= 1900; /* Adjust years */
|
||||
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = mtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&ntm_time.tm_year,
|
||||
&ntm_time.tm_mon,
|
||||
&ntm_time.tm_mday,
|
||||
&ntm_time.tm_hour,
|
||||
&ntm_time.tm_min) == 5) {
|
||||
ntm_time.tm_year -= 1900; /* Adjust years */
|
||||
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ntm_time;
|
||||
return(tm_time);
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
|
||||
exit( FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
date_main(int argc, char * * argv)
|
||||
struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i>0 && *++(*argv)) switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv ("TZ=UTC0") != 0) {
|
||||
fprintf(stderr,"date: memory exhausted\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case '-':
|
||||
usage ( date_usage);
|
||||
}
|
||||
} else {
|
||||
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
|
||||
date_fmt=*argv;
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str=*argv;
|
||||
} else {
|
||||
usage ( date_usage);
|
||||
}
|
||||
struct tm itm_time, jtm_time, ktm_time, ltm_time, mtm_time, ntm_time;
|
||||
|
||||
itm_time = *tm_time;
|
||||
jtm_time = *tm_time;
|
||||
ktm_time = *tm_time;
|
||||
ltm_time = *tm_time;
|
||||
mtm_time = *tm_time;
|
||||
ntm_time = *tm_time;
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if (sscanf(t_string, "%d:%d:%d",
|
||||
&itm_time.tm_hour, &itm_time.tm_min, &itm_time.tm_sec) == 3) {
|
||||
|
||||
*tm_time = itm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d:%d",
|
||||
&jtm_time.tm_hour, &jtm_time.tm_min) == 2) {
|
||||
|
||||
*tm_time = jtm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&ktm_time.tm_mon,
|
||||
&ktm_time.tm_mday,
|
||||
&ktm_time.tm_hour,
|
||||
&ktm_time.tm_min, &ktm_time.tm_sec) == 5) {
|
||||
|
||||
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ktm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d",
|
||||
<m_time.tm_mon,
|
||||
<m_time.tm_mday,
|
||||
<m_time.tm_hour, <m_time.tm_min) == 4) {
|
||||
|
||||
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ltm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&mtm_time.tm_year,
|
||||
&mtm_time.tm_mon,
|
||||
&mtm_time.tm_mday,
|
||||
&mtm_time.tm_hour,
|
||||
&mtm_time.tm_min, &mtm_time.tm_sec) == 6) {
|
||||
|
||||
mtm_time.tm_year -= 1900; /* Adjust years */
|
||||
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = mtm_time;
|
||||
return (tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&ntm_time.tm_year,
|
||||
&ntm_time.tm_mon,
|
||||
&ntm_time.tm_mday,
|
||||
&ntm_time.tm_hour, &ntm_time.tm_min) == 5) {
|
||||
ntm_time.tm_year -= 1900; /* Adjust years */
|
||||
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ntm_time;
|
||||
return (tm_time);
|
||||
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight!*/
|
||||
if(date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if(date_str != NULL) {
|
||||
|
||||
if(strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
date_conv_time(&tm_time, date_str);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0 ) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", date_str);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
/* if setting time, set it */
|
||||
if(set_time) {
|
||||
if( stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
if(date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %_d %b %Y %H:%M:%S GMT"
|
||||
: "%a, %_d %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
} else if ( *date_fmt == '\0' ) {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf ("\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
/* Handle special conversions */
|
||||
|
||||
if( strncmp( date_fmt, "%f", 2) == 0 ) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit( TRUE);
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
|
||||
int date_main(int argc, char **argv)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i > 0 && *++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
} else {
|
||||
usage(date_usage);
|
||||
}
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight! */
|
||||
if (date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if (date_str != NULL) {
|
||||
|
||||
if (strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
date_conv_time(&tm_time, date_str);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fatalError("date: can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
if (date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %_d %b %Y %H:%M:%S GMT"
|
||||
: "%a, %_d %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
} else if (*date_fmt == '\0') {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf("\n");
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* Handle special conversions */
|
||||
|
||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit(TRUE);
|
||||
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999, 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code taken from sash.
|
||||
*
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
* Based in part on code taken from sash.
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
* Permission to distribute this code under the GPL has been granted.
|
||||
*
|
||||
@@ -40,155 +41,165 @@ typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stout\n"
|
||||
"\tbs=n\tread and write N BYTES at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
//"\tskip=n\tskip n input blocks\n"
|
||||
"\n"
|
||||
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
|
||||
"dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stdout\n"
|
||||
"\tbs=n\tread and write n bytes at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
"\tskip=n\tskip n input blocks\n"
|
||||
"\tseek=n\tskip n output blocks\n"
|
||||
|
||||
"\n"
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
|
||||
|
||||
|
||||
|
||||
extern int dd_main (int argc, char **argv)
|
||||
extern int dd_main(int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
size_t blockSize = 512;
|
||||
//uintmax_t skipBlocks = 0;
|
||||
uintmax_t count = (uintmax_t)-1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
long blockSize = 512;
|
||||
uintmax_t skipBlocks = 0;
|
||||
uintmax_t seekBlocks = 0;
|
||||
uintmax_t count = (uintmax_t) - 1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc) {
|
||||
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
|
||||
inFile=((strchr(*argv, '='))+1);
|
||||
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
|
||||
outFile=((strchr(*argv, '='))+1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum ((strchr(*argv, '='))+1);
|
||||
if (count <= 0) {
|
||||
fprintf (stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum ((strchr(*argv, '='))+1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf (stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = atoi( *argv);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
goto usage;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc (blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf (stderr, "Cannot allocate buffer\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Parse any options */
|
||||
while (argc) {
|
||||
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
|
||||
inFile = ((strchr(*argv, '=')) + 1);
|
||||
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
|
||||
outFile = ((strchr(*argv, '=')) + 1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum((strchr(*argv, '=')) + 1);
|
||||
if (count <= 0) {
|
||||
fprintf(stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum((strchr(*argv, '=')) + 1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf(stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf(stderr, "Bad skip value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
} else if (strncmp(*argv, "seek", 4) == 0) {
|
||||
seekBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (seekBlocks <= 0) {
|
||||
fprintf(stderr, "Bad seek value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open (inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror (inFile);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = creat (outFile, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror (outFile);
|
||||
close (inFd);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utilitity.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read (inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror (inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write (outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror (outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open(inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* free(buf); */
|
||||
fatalError( inFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror (inFile);
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* close(inFd);
|
||||
free(buf); */
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
lseek(outFd, seekBlocks * blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utility.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read(inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror(inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write(outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror(outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
}
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
close (inFd);
|
||||
close (outFd);
|
||||
free (buf);
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit( TRUE);
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf("%ld+%d records out\n", (long) (outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit(TRUE);
|
||||
usage:
|
||||
|
||||
usage( dd_usage);
|
||||
usage(dd_usage);
|
||||
}
|
||||
|
||||
|
||||
+34
-32
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
||||
* Renamed deallocvt.
|
||||
@@ -13,38 +14,39 @@
|
||||
extern int getfd(void);
|
||||
char *progname;
|
||||
|
||||
int
|
||||
deallocvt_main(int argc, char *argv[]) {
|
||||
int fd, num, i;
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
int fd, num, i;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd,VT_DISALLOCATE,0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
|
||||
else
|
||||
if (ioctl(fd,VT_DISALLOCATE,num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
|
||||
progname);
|
||||
else if (ioctl(fd, VT_DISALLOCATE, num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# define.sh - creates an include file full of #defines
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# define.sh POSIX_ME_HARDER ...
|
||||
#
|
||||
# <GPL>
|
||||
|
||||
for i ; do
|
||||
case $1 in
|
||||
!!*!!)
|
||||
echo "// #define" `echo $1 | sed 's/^!!\(.*\)!!$/\1/'`
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "#define $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# </GPL>
|
||||
@@ -1,7 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
@@ -26,84 +27,92 @@
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
static const char df_usage[] = "df [filesystem ...]\n\n"
|
||||
"Print the filesystem space used and space available.\n";
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
static int df(char *device, const char *mountPoint)
|
||||
{
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab* fstabItem;
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (s.f_blocks > 0) {
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp (device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile ("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return FALSE;
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
|
||||
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
|
||||
blocks_percent_used, mountPoint);
|
||||
|
||||
}
|
||||
if (s.f_blocks > 0) {
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
find_real_root_device_name( device);
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
|
||||
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
|
||||
blocks_percent_used, mountPoint);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern int df_main(int argc, char **argv)
|
||||
{
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
|
||||
0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
exit( FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
exit( status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
if (**(argv + 1) == '-') {
|
||||
usage(df_usage);
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
exit(FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
exit(status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit(TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
|
||||
mountTable = setmntent(mtab_file, "r");
|
||||
if (mountTable == 0) {
|
||||
perror(mtab_file);
|
||||
exit(FALSE);
|
||||
mountTable = setmntent(mtab_file, "r");
|
||||
if (mountTable == 0) {
|
||||
perror(mtab_file);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
exit( TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@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 dirname_main(int argc, char **argv)
|
||||
{
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [file ...]\n");
|
||||
}
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
while (s && *s == '/') {
|
||||
*s = '\0';
|
||||
s=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* dmesg.c -- Print out the contents of the kernel ring buffer
|
||||
* Created: Sat Oct 9 16:19:47 1993
|
||||
* Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
|
||||
@@ -24,8 +25,8 @@
|
||||
|
||||
#ifndef __alpha__
|
||||
# define __NR_klogctl __NR_syslog
|
||||
static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
|
||||
#else /* __alpha__ */
|
||||
static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
|
||||
#else /* __alpha__ */
|
||||
#define klogctl syslog
|
||||
#endif
|
||||
|
||||
@@ -35,90 +36,91 @@
|
||||
|
||||
static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
|
||||
|
||||
int dmesg_main( int argc, char** argv )
|
||||
int dmesg_main(int argc, char **argv)
|
||||
{
|
||||
char *buf;
|
||||
int bufsize=8196;
|
||||
int i;
|
||||
int n;
|
||||
int level = 0;
|
||||
int lastc;
|
||||
int cmd = 3;
|
||||
int stopDoingThat;
|
||||
char *buf;
|
||||
int bufsize = 8196;
|
||||
int i;
|
||||
int n;
|
||||
int level = 0;
|
||||
int lastc;
|
||||
int cmd = 3;
|
||||
int stopDoingThat;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc && **argv == '-') {
|
||||
stopDoingThat = FALSE;
|
||||
while (stopDoingThat == FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
break;
|
||||
case 'n':
|
||||
cmd = 8;
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
level = atoi (*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
bufsize = atoi (*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
default:
|
||||
goto end;
|
||||
}
|
||||
/* Parse any options */
|
||||
while (argc && **argv == '-') {
|
||||
stopDoingThat = FALSE;
|
||||
while (stopDoingThat == FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
break;
|
||||
case 'n':
|
||||
cmd = 8;
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
level = atoi(*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
bufsize = atoi(*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
default:
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (cmd == 8) {
|
||||
n = klogctl( cmd, NULL, level );
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
exit( TRUE );
|
||||
}
|
||||
if (argc > 1) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (bufsize < 4096) bufsize = 4096;
|
||||
buf = (char*)malloc(bufsize);
|
||||
n = klogctl( cmd, buf, bufsize );
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
if (cmd == 8) {
|
||||
n = klogctl(cmd, NULL, level);
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
lastc = '\n';
|
||||
for (i = 0; i < n; i++) {
|
||||
if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
|
||||
i++;
|
||||
while (buf[i] >= '0' && buf[i] <= '9')
|
||||
i++;
|
||||
if (buf[i] == '>')
|
||||
i++;
|
||||
}
|
||||
lastc = buf[i];
|
||||
putchar( lastc );
|
||||
}
|
||||
if (lastc != '\n')
|
||||
putchar( '\n' );
|
||||
exit( TRUE);
|
||||
end:
|
||||
usage( dmesg_usage);
|
||||
exit (FALSE);
|
||||
klogctl_error:
|
||||
perror( "klogctl" );
|
||||
exit( FALSE );
|
||||
if (bufsize < 4096)
|
||||
bufsize = 4096;
|
||||
buf = (char *) xmalloc(bufsize);
|
||||
n = klogctl(cmd, buf, bufsize);
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
|
||||
lastc = '\n';
|
||||
for (i = 0; i < n; i++) {
|
||||
if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
|
||||
i++;
|
||||
while (buf[i] >= '0' && buf[i] <= '9')
|
||||
i++;
|
||||
if (buf[i] == '>')
|
||||
i++;
|
||||
}
|
||||
lastc = buf[i];
|
||||
putchar(lastc);
|
||||
}
|
||||
if (lastc != '\n')
|
||||
putchar('\n');
|
||||
exit(TRUE);
|
||||
end:
|
||||
usage(dmesg_usage);
|
||||
exit(FALSE);
|
||||
klogctl_error:
|
||||
perror("klogctl");
|
||||
exit(FALSE);
|
||||
|
||||
}
|
||||
-1025
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
# busybox/docs/Makefile - Create the documentation
|
||||
# ------------------------
|
||||
# Copyright (C) 2000 Erik Andersen <andersee@debian.org> GPL
|
||||
|
||||
all: clean doc
|
||||
|
||||
doc:
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
pod2html busybox.pod > ../BusyBox.html
|
||||
@rm pod2html-*
|
||||
pod2man --center=BusyBox --release="version $(VERSION)" busybox.pod > ../BusyBox.1
|
||||
pod2text busybox.pod > ../BusyBox.txt
|
||||
@rm -f pod2html*
|
||||
|
||||
clean:
|
||||
@rm -f ../BusyBox.html ../BusyBox.1 ../BusyBox.txt pod2html*
|
||||
|
||||
distclean: clean
|
||||
|
||||
+1806
File diff suppressed because it is too large.
Load diff
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini du 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
|
||||
@@ -22,122 +23,170 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_name_too_long
|
||||
#include "messages.c"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#if 0
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
typedef void (Display)(size_t, char *);
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n\n"
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
;
|
||||
"du [OPTION]... [FILE]...\n\n"
|
||||
"Summarize disk space used for each FILE and/or directory.\n"
|
||||
"Disk space is printed in units of 1024 bytes.\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tcount sizes many times if hard linked\n"
|
||||
"\t-s\tdisplay only a total for each argument\n";
|
||||
|
||||
static int du_depth = 0;
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
|
||||
static Display *print;
|
||||
static Display *print;
|
||||
|
||||
static void
|
||||
print_normal(size_t size, char *filename)
|
||||
static void print_normal(long size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
|
||||
fprintf(stdout, "%ld\t%s\n", size, filename);
|
||||
}
|
||||
|
||||
static void
|
||||
print_summary(size_t size, char *filename)
|
||||
static void print_summary(long size, char *filename)
|
||||
{
|
||||
if (du_depth == 1) {
|
||||
print_normal(size, filename);
|
||||
}
|
||||
if (du_depth == 1) {
|
||||
print_normal(size, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static size_t
|
||||
du(char *filename)
|
||||
static long du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
size_t sum;
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
int len;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) { return 0; }
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[512];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ( (strcmp(name, "..") == 0)
|
||||
|| (strcmp(name, ".") == 0))
|
||||
{ continue; }
|
||||
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
sum += du(newfile);
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
printf("du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
|
||||
du_depth++;
|
||||
sum = (statbuf.st_blocks >> 1);
|
||||
|
||||
/* Don't add in stuff pointed to by symbolic links */
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) {
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(filename);
|
||||
if (filename[len - 1] == '/')
|
||||
filename[--len] = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[PATH_MAX + 1];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ((strcmp(name, "..") == 0)
|
||||
|| (strcmp(name, ".") == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len + strlen(name) + 1 > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
|
||||
sum += du(newfile);
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
|
||||
/* Add files with hard links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
}
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
|
||||
int
|
||||
du_main(int argc, char **argv)
|
||||
int du_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
int i;
|
||||
char opt;
|
||||
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'h':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
}
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '-':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
long sum;
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
int sum;
|
||||
for ( ; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); }
|
||||
for (; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if (sum && isDirectory(argv[i], FALSE, NULL)) {
|
||||
print_normal(sum, argv[i]);
|
||||
}
|
||||
reset_ino_dev_hashtable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.8 1999/12/17 18:44:15 erik Exp $ */
|
||||
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
|
||||
*
|
||||
@@ -12,40 +13,41 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <utmp.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
|
||||
static const char dutmp_usage[] = "dutmp\n"
|
||||
"\n"
|
||||
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
|
||||
"\tdutmp /var/run/utmp\n";
|
||||
static const char dutmp_usage[] = "dutmp [FILE]\n\n"
|
||||
"Dump utmp file format (pipe delimited) from FILE\n"
|
||||
"or stdin to stdout. (i.e. 'dutmp /var/run/utmp')\n";
|
||||
|
||||
extern int dutmp_main (int argc, char **argv)
|
||||
extern int dutmp_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
FILE *f = stdin;
|
||||
struct utmp ut;
|
||||
FILE *f;
|
||||
struct utmp ut;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage( dutmp_usage);
|
||||
}
|
||||
if (argc<2) {
|
||||
f = stdin;
|
||||
} else if (*argv[1] == '-' ) {
|
||||
usage(dutmp_usage);
|
||||
} else {
|
||||
f = fopen(argv[1], "r");
|
||||
if (f == NULL) {
|
||||
fatalError(io_error, argv[1], strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if ( **(++argv) == 0 ) {
|
||||
f = fopen (*(++argv), "r");
|
||||
if (f < 0 ) {
|
||||
perror (*argv);
|
||||
exit (FALSE);
|
||||
}
|
||||
}
|
||||
while (fread(&ut, sizeof(struct utmp), 1, f)) {
|
||||
printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
|
||||
ut.ut_type, ut.ut_pid, ut.ut_line,
|
||||
ut.ut_id, ut.ut_user, ut.ut_host,
|
||||
ut.ut_exit.e_termination, ut.ut_exit.e_exit,
|
||||
ut.ut_session,
|
||||
ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
|
||||
}
|
||||
|
||||
while (fread (&ut, 1, sizeof (struct utmp), f)) {
|
||||
// printf("%d:%d:%s:%s:%s:%s:%d:%d:%ld:%ld:%ld:%x\n",
|
||||
printf ("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
|
||||
ut.ut_type, ut.ut_pid, ut.ut_line,
|
||||
ut.ut_id, ut.ut_user, ut.ut_host,
|
||||
ut.ut_exit.e_termination, ut.ut_exit.e_exit,
|
||||
ut.ut_session,
|
||||
ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
|
||||
}
|
||||
|
||||
exit (TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* echo implementation for busybox
|
||||
*
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char uname_usage[] =
|
||||
"echo [-neE] [ARG ...]\n\n"
|
||||
"Prints the specified ARGs to stdout\n\n"
|
||||
"Options:\n"
|
||||
"\t-n\tsuppress trailing newline\n"
|
||||
"\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
|
||||
"\t-E\tdisable interpretation of backslash-escaped characters\n";
|
||||
|
||||
extern int
|
||||
echo_main(int argc, char** argv)
|
||||
{
|
||||
register char **ap;
|
||||
register char *p;
|
||||
register char c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
|
||||
ap = argv;
|
||||
if (argc)
|
||||
ap++;
|
||||
while ((p = *ap) != NULL && *p == '-') {
|
||||
if (strcmp(p, "-n")==0) {
|
||||
nflag = 1;
|
||||
} else if (strcmp(p, "-e")==0) {
|
||||
eflag = 1;
|
||||
} else if (strcmp(p, "-E")==0) {
|
||||
eflag = 0;
|
||||
}
|
||||
else if (strncmp(p, "--", 2)==0) {
|
||||
usage( uname_usage);
|
||||
}
|
||||
else break;
|
||||
ap++;
|
||||
}
|
||||
while ((p = *ap++) != NULL) {
|
||||
while ((c = *p++) != '\0') {
|
||||
if (c == '\\' && eflag) {
|
||||
switch (c = *p++) {
|
||||
case 'a': c = '\007'; break;
|
||||
case 'b': c = '\b'; break;
|
||||
case 'c': exit( 0); /* exit */
|
||||
case 'f': c = '\f'; break;
|
||||
case 'n': c = '\n'; break;
|
||||
case 'r': c = '\r'; break;
|
||||
case 't': c = '\t'; break;
|
||||
case 'v': c = '\v'; break;
|
||||
case '\\': break; /* c = '\\' */
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
c -= '0';
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
if (*p >= '0' && *p <= '7')
|
||||
c = c * 8 + (*p++ - '0');
|
||||
break;
|
||||
default:
|
||||
p--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
if (*ap)
|
||||
putchar(' ');
|
||||
}
|
||||
if (! nflag)
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
exit( 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Kenneth Almquist.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
|
||||
+270
-266
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini sed implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* Modifications for addresses and append command have been
|
||||
@@ -37,27 +38,27 @@
|
||||
#include <ctype.h>
|
||||
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] -e script [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t'ADDR [!] COMMAND'\n\n"
|
||||
"\twhere address ADDR can be:\n"
|
||||
"\t NUMBER Match specified line number\n"
|
||||
"\t $ Match last line\n"
|
||||
"\t /REGEXP/ Match specified regexp\n"
|
||||
"\t (! inverts the meaning of the match)\n\n"
|
||||
"\tand COMMAND can be:\n"
|
||||
"\t s/regexp/replacement/[igp]\n"
|
||||
"\t which attempt to match regexp against the pattern space\n"
|
||||
"\t and if successful replaces the matched portion with replacement.\n\n"
|
||||
"\t aTEXT\n"
|
||||
"\t which appends TEXT after the pattern space\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
"sed [-n] -e script [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t'ADDR [!] COMMAND'\n\n"
|
||||
"\twhere address ADDR can be:\n"
|
||||
"\t NUMBER Match specified line number\n"
|
||||
"\t $ Match last line\n"
|
||||
"\t /REGEXP/ Match specified regexp\n"
|
||||
"\t (! inverts the meaning of the match)\n\n"
|
||||
"\tand COMMAND can be:\n"
|
||||
"\t s/regexp/replacement/[igp]\n"
|
||||
"\t which attempt to match regexp against the pattern space\n"
|
||||
"\t and if successful replaces the matched portion with replacement.\n\n"
|
||||
"\t aTEXT\n"
|
||||
"\t which appends TEXT after the pattern space\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
#endif
|
||||
|
||||
/* Flags & variables */
|
||||
@@ -76,276 +77,279 @@ static int negated = 0;
|
||||
|
||||
static inline int at_last(FILE * fp)
|
||||
{
|
||||
int res = 0;
|
||||
int res = 0;
|
||||
|
||||
if (feof(fp))
|
||||
return 1;
|
||||
else {
|
||||
char ch;
|
||||
if ((ch = fgetc(fp)) == EOF)
|
||||
res++;
|
||||
ungetc(ch, fp);
|
||||
}
|
||||
return res;
|
||||
if (feof(fp))
|
||||
return 1;
|
||||
else {
|
||||
int ch;
|
||||
|
||||
if ((ch = fgetc(fp)) == EOF)
|
||||
res++;
|
||||
ungetc(ch, fp);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void do_sed_repl(FILE * fp, char *needle, char *newNeedle,
|
||||
int ignoreCase, int printFlag, int quietFlag)
|
||||
int ignoreCase, int printFlag, int quietFlag)
|
||||
{
|
||||
int foundOne = FALSE;
|
||||
char haystack[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
int foundOne = FALSE;
|
||||
char haystack[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
|
||||
while (fgets(haystack, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(haystack, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
while (fgets(haystack, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(haystack, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (doit) {
|
||||
foundOne =
|
||||
replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
|
||||
if (foundOne == TRUE && printFlag == TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (doit) {
|
||||
foundOne =
|
||||
replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
|
||||
if (foundOne == TRUE && printFlag == TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
static void do_sed_append(FILE * fp, char *appendline, int quietFlag)
|
||||
{
|
||||
char buffer[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
char buffer[BUFSIZE];
|
||||
int line = 1, doit;
|
||||
|
||||
while (fgets(buffer, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(buffer, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, buffer);
|
||||
}
|
||||
if (doit) {
|
||||
fputs(appendline, stdout);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
while (fgets(buffer, BUFSIZE - 1, fp)) {
|
||||
doit = 0;
|
||||
if (addr_pattern) {
|
||||
doit = !find_match(buffer, addr_pattern, FALSE);
|
||||
} else if (addr_line == NO_LINE)
|
||||
doit = 1;
|
||||
else if (addr_line == LAST_LINE) {
|
||||
if (at_last(fp))
|
||||
doit = 1;
|
||||
} else {
|
||||
if (line == addr_line)
|
||||
doit = 1;
|
||||
}
|
||||
if (negated)
|
||||
doit = 1 - doit;
|
||||
if (quietFlag == FALSE) {
|
||||
fprintf(stdout, buffer);
|
||||
}
|
||||
if (doit) {
|
||||
fputs(appendline, stdout);
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle = NULL, *newNeedle = NULL;
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase = FALSE;
|
||||
int printFlag = FALSE;
|
||||
int quietFlag = FALSE;
|
||||
int stopNow;
|
||||
char *line_s = NULL, saved;
|
||||
char *appendline = NULL;
|
||||
char *pos;
|
||||
sed_function sed_f = f_none;
|
||||
FILE *fp;
|
||||
char *needle = NULL, *newNeedle = NULL;
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase = FALSE;
|
||||
int printFlag = FALSE;
|
||||
int quietFlag = FALSE;
|
||||
int stopNow;
|
||||
char *line_s = NULL, saved;
|
||||
char *appendline = NULL;
|
||||
char *pos;
|
||||
sed_function sed_f = f_none;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow = FALSE;
|
||||
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp + 1) == 0 && --argc < 0) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*++cp != 's')
|
||||
cp = *argv++;
|
||||
|
||||
/* Read address if present */
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '$') {
|
||||
addr_line = LAST_LINE;
|
||||
cp++;
|
||||
} else {
|
||||
if (isdigit(*cp)) { /* LINE ADDRESS */
|
||||
line_s = cp;
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
if (cp > line_s) {
|
||||
/* numeric line */
|
||||
saved = *cp;
|
||||
*cp = '\0';
|
||||
addr_line = atoi(line_s);
|
||||
*cp = saved;
|
||||
}
|
||||
} else if (*cp == '/') { /* PATTERN ADDRESS */
|
||||
pos = addr_pattern = cp + 1;
|
||||
pos = strchr(pos, '/');
|
||||
if (!pos)
|
||||
usage(sed_usage);
|
||||
*pos = '\0';
|
||||
cp = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '!') {
|
||||
negated++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
/* Read command */
|
||||
|
||||
SKIPSPACES(cp);
|
||||
switch (*cp) {
|
||||
case 's': /* REPLACE */
|
||||
if (strlen(cp) <= 3 || *(cp + 1) != '/')
|
||||
break;
|
||||
sed_f = f_replace;
|
||||
|
||||
pos = needle = cp + 2;
|
||||
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
newNeedle = ++pos;
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
if (pos + 2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag = TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
cp = pos;
|
||||
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
|
||||
break;
|
||||
|
||||
case 'a': /* APPEND */
|
||||
if (strlen(cp) < 2)
|
||||
break;
|
||||
sed_f = f_append;
|
||||
appendline = ++cp;
|
||||
/* fprintf(stderr, "append '%s'\n", appendline); */
|
||||
break;
|
||||
}
|
||||
|
||||
stopNow = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
|
||||
while (argc > 1) {
|
||||
if (**argv != '-')
|
||||
usage(sed_usage);
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
stopNow = FALSE;
|
||||
|
||||
while (*++cp && stopNow == FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp + 1) == 0 && --argc < 0) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*++cp != 's')
|
||||
cp = *argv++;
|
||||
|
||||
/* Read address if present */
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '$') {
|
||||
addr_line = LAST_LINE;
|
||||
cp++;
|
||||
} else {
|
||||
if (isdigit(*cp)) { /* LINE ADDRESS */
|
||||
line_s = cp;
|
||||
while (isdigit(*cp))
|
||||
cp++;
|
||||
if (cp > line_s) {
|
||||
/* numeric line */
|
||||
saved = *cp;
|
||||
*cp = '\0';
|
||||
addr_line = atoi(line_s);
|
||||
*cp = saved;
|
||||
}
|
||||
} else if (*cp == '/') { /* PATTERN ADDRESS */
|
||||
pos = addr_pattern = cp + 1;
|
||||
pos = strchr(pos, '/');
|
||||
if (!pos)
|
||||
usage(sed_usage);
|
||||
*pos = '\0';
|
||||
cp = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
SKIPSPACES(cp);
|
||||
if (*cp == '!') {
|
||||
negated++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
/* Read command */
|
||||
|
||||
SKIPSPACES(cp);
|
||||
switch (*cp) {
|
||||
case 's': /* REPLACE */
|
||||
if (strlen(cp) <= 3 || *(cp + 1) != '/')
|
||||
break;
|
||||
sed_f = f_replace;
|
||||
|
||||
pos = needle = cp + 2;
|
||||
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
newNeedle = ++pos;
|
||||
for (;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos == NULL) {
|
||||
usage(sed_usage);
|
||||
}
|
||||
if (*(pos - 1) == '\\') {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*pos = 0;
|
||||
if (pos + 2 != 0) {
|
||||
while (*++pos) {
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
printFlag = TRUE;
|
||||
break;
|
||||
case 'g':
|
||||
break;
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
cp = pos;
|
||||
/* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */
|
||||
break;
|
||||
|
||||
case 'a': /* APPEND */
|
||||
if (strlen(cp) < 2)
|
||||
break;
|
||||
sed_f = f_append;
|
||||
appendline = ++cp;
|
||||
/* fprintf(stderr, "append '%s'\n", appendline); */
|
||||
break;
|
||||
}
|
||||
|
||||
stopNow = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(stdin, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(stdin, appendline, quietFlag);
|
||||
break;
|
||||
if (argc == 0) {
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(stdin, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(stdin, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen(name, "r");
|
||||
if (fp == NULL) {
|
||||
perror(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(fp, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(fp, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror(fp))
|
||||
perror(name);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen(name, "r");
|
||||
if (fp == NULL) {
|
||||
perror(name);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (sed_f) {
|
||||
case f_none:
|
||||
break;
|
||||
case f_replace:
|
||||
do_sed_repl(fp, needle, newNeedle, ignoreCase, printFlag,
|
||||
quietFlag);
|
||||
break;
|
||||
case f_append:
|
||||
do_sed_append(fp, appendline, quietFlag);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror(fp))
|
||||
perror(name);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
exit(TRUE);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.41
|
||||
Version: 0.43
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
|
||||
+5
-3
@@ -23,7 +23,8 @@
|
||||
#
|
||||
# <runlevels>: The runlevels field is completely ignored.
|
||||
#
|
||||
# <action>: Valid actions include: sysinit, respawn, askfirst, wait, and once.
|
||||
# <action>: Valid actions include: sysinit, respawn, askfirst, wait, once,
|
||||
# and ctrlaltdel.
|
||||
#
|
||||
# Note: askfirst acts just like respawn, but before running the specified
|
||||
# process it displays the line "Please press Enter to activate this
|
||||
@@ -70,6 +71,7 @@ tty5::respawn:/sbin/getty 38400 tty5
|
||||
# Example how to put a getty on a modem line.
|
||||
#ttyS2::respawn:/sbin/getty -x0 -s 57600 ttyS2
|
||||
|
||||
# Not currently supported, but may be sometime in the future...
|
||||
#::ctrlaltdel:/sbin/reboot
|
||||
# Stuff to do before rebooting
|
||||
::ctrlaltdel:/bin/umount -a -r > /dev/null 2>&1
|
||||
::ctrlaltdel:/sbin/swapoff -a > /dev/null 2>&1
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
From alan@lxorguk.ukuu.org.uk Thu Apr 13 08:07:22 2000
|
||||
Return-Path: <alan@lxorguk.ukuu.org.uk>
|
||||
Delivered-To: andersen@dillweed.dsl.xmission.com
|
||||
Received: from localhost (dillweed.dsl.xmission.com [10.0.0.1])
|
||||
by dillweed.dsl.xmission.com (Postfix) with ESMTP id 1D57A11A4F5
|
||||
for <andersen@dillweed.dsl.xmission.com>; Thu, 13 Apr 2000 08:07:22 -0600 (MDT)
|
||||
Envelope-to: andersen@xmission.com
|
||||
Received: from mail.xmission.com
|
||||
by localhost with IMAP (fetchmail-5.3.3)
|
||||
for andersen@dillweed.dsl.xmission.com (single-drop); Thu, 13 Apr 2000 08:07:22 -0600 (MDT)
|
||||
Received: from [194.168.151.1] (helo=the-village.bc.nu)
|
||||
by mail.xmission.com with esmtp (Exim 3.03 #3)
|
||||
id 12fhQk-0002OZ-00
|
||||
for andersen@xmission.com; Thu, 13 Apr 2000 05:05:03 -0600
|
||||
Received: from alan by the-village.bc.nu with local (Exim 2.12 #1)
|
||||
id 12fhQ9-0002nD-00
|
||||
for andersen@xmission.com; Thu, 13 Apr 2000 12:04:25 +0100
|
||||
Subject: Re: kernel ps drivers [Was: vm locking question]
|
||||
To: andersen@xmission.com
|
||||
Date: Thu, 13 Apr 2000 12:04:23 +0100 (BST)
|
||||
In-Reply-To: <20000412224130.A2748@xmission.com> from "Erik Andersen" at Apr 12, 2000 10:41:30 PM
|
||||
X-Mailer: ELM [version 2.5 PL1]
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=us-ascii
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Message-Id: <E12fhQ9-0002nD-00@the-village.bc.nu>
|
||||
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
|
||||
Status: RO
|
||||
X-Status: A
|
||||
Content-Length: 242
|
||||
Lines: 6
|
||||
|
||||
> On the subject of ps, would you be willing to accept my /dev/ps
|
||||
> patch into the kernel? If no, any suggestions on what should
|
||||
> be done differently (if anything) to make it worthy of inclusion?
|
||||
|
||||
For 2.2.x no, for 2.3.x ask Linus not me
|
||||
|
||||
|
||||
From torvalds@transmeta.com Thu Apr 13 09:18:16 2000
|
||||
Return-Path: <torvalds@transmeta.com>
|
||||
Delivered-To: andersen@dillweed.dsl.xmission.com
|
||||
Received: from localhost (dillweed.dsl.xmission.com [10.0.0.1])
|
||||
by dillweed.dsl.xmission.com (Postfix) with ESMTP id 3776411A3DF
|
||||
for <andersen@dillweed.dsl.xmission.com>; Thu, 13 Apr 2000 09:18:16 -0600 (MDT)
|
||||
Envelope-to: andersen@xmission.com
|
||||
Received: from mail.xmission.com
|
||||
by localhost with IMAP (fetchmail-5.3.3)
|
||||
for andersen@dillweed.dsl.xmission.com (single-drop); Thu, 13 Apr 2000 09:18:16 -0600 (MDT)
|
||||
Received: from [209.10.217.66] (helo=neon-gw.transmeta.com)
|
||||
by mail.xmission.com with esmtp (Exim 3.03 #3)
|
||||
id 12flK2-0004dd-00
|
||||
for andersen@xmission.com; Thu, 13 Apr 2000 09:14:22 -0600
|
||||
Received: (from root@localhost)
|
||||
by neon-gw.transmeta.com (8.9.3/8.9.3) id IAA18635;
|
||||
Thu, 13 Apr 2000 08:10:51 -0700
|
||||
Received: from mailhost.transmeta.com(10.1.1.15) by neon-gw.transmeta.com via smap (V2.1)
|
||||
id xma018629; Thu, 13 Apr 00 08:10:25 -0700
|
||||
Received: from penguin.transmeta.com (root@penguin.transmeta.com [10.1.2.202])
|
||||
by deepthought.transmeta.com (8.9.3/8.9.3) with ESMTP id IAA12264;
|
||||
Thu, 13 Apr 2000 08:13:53 -0700 (PDT)
|
||||
Received: from localhost (torvalds@localhost) by penguin.transmeta.com (8.9.3/8.7.3) with ESMTP id IAA02051; Thu, 13 Apr 2000 08:13:53 -0700
|
||||
X-Authentication-Warning: penguin.transmeta.com: torvalds owned process doing -bs
|
||||
Date: Thu, 13 Apr 2000 08:13:53 -0700 (PDT)
|
||||
From: Linus Torvalds <torvalds@transmeta.com>
|
||||
To: Erik Andersen <andersen@xmission.com>
|
||||
Cc: Alan Cox <alan@redhat.com>
|
||||
Subject: Re: kernel ps drivers [Was: vm locking question]
|
||||
In-Reply-To: <20000413083127.A976@xmission.com>
|
||||
Message-ID: <Pine.LNX.4.10.10004130812170.2000-100000@penguin.transmeta.com>
|
||||
MIME-Version: 1.0
|
||||
Content-Type: TEXT/PLAIN; charset=US-ASCII
|
||||
Status: RO
|
||||
Content-Length: 659
|
||||
Lines: 16
|
||||
|
||||
|
||||
|
||||
On Thu, 13 Apr 2000, Erik Andersen wrote:
|
||||
>
|
||||
> For 2.3.x would you be willing to accept my /dev/ps driver into the kernel?
|
||||
> (Assuming I remove the /dev/modules driver (since it was pointed out that there
|
||||
> is a perfectly good syscall providing that interface). If no, is there anything
|
||||
> that could be done differently (if anything) to make it worthy of inclusion?
|
||||
|
||||
I do dislike /dev/ps mightily. If the problem is that /proc is too large,
|
||||
then the right solution is to just clean up /proc. Which is getting done.
|
||||
And yes, /proc will be larger than /dev/ps, but I still find that
|
||||
preferable to having two incompatible ways to do the same thing.
|
||||
|
||||
Linus
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini fbset implementation for busybox
|
||||
*
|
||||
@@ -48,7 +49,7 @@
|
||||
#define OPT_READMODE (1 << 2)
|
||||
|
||||
#define CMD_HELP 0
|
||||
#define CMD_FB 1
|
||||
#define CMD_FB 1
|
||||
#define CMD_DB 2
|
||||
#define CMD_GEOMETRY 3
|
||||
#define CMD_TIMING 4
|
||||
@@ -61,7 +62,7 @@
|
||||
#define CMD_ALL 11
|
||||
#define CMD_INFO 12
|
||||
|
||||
#ifdef BB_FBSET_FANCY
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
#define CMD_XRES 13
|
||||
#define CMD_YRES 14
|
||||
#define CMD_VXRES 15
|
||||
@@ -87,213 +88,242 @@
|
||||
static unsigned int g_options = 0;
|
||||
|
||||
struct cmdoptions_t {
|
||||
char *name;
|
||||
unsigned char param_count;
|
||||
unsigned char code;
|
||||
char *name;
|
||||
unsigned char param_count;
|
||||
unsigned char code;
|
||||
} g_cmdoptions[] = {
|
||||
{ "-h", 0, CMD_HELP },
|
||||
{ "-fb", 1, CMD_FB },
|
||||
{ "-db", 1, CMD_DB },
|
||||
{ "-a", 0, CMD_ALL },
|
||||
{ "-i", 0, CMD_INFO },
|
||||
{ "-g", 5, CMD_GEOMETRY },
|
||||
{ "-t", 7, CMD_TIMING },
|
||||
{ "-accel", 1, CMD_ACCEL },
|
||||
{ "-hsync", 1, CMD_HSYNC },
|
||||
{ "-vsync", 1, CMD_VSYNC },
|
||||
{ "-laced", 1, CMD_LACED },
|
||||
{ "-double", 1, CMD_DOUBLE },
|
||||
|
||||
#ifdef BB_FBSET_FANCY
|
||||
{ "--help", 0, CMD_HELP },
|
||||
{ "-all", 0, CMD_ALL },
|
||||
{ "-xres", 1, CMD_XRES },
|
||||
{ "-yres", 1, CMD_YRES },
|
||||
{ "-vxres", 1, CMD_VXRES },
|
||||
{ "-vyres", 1, CMD_VYRES },
|
||||
{ "-depth", 1, CMD_DEPTH },
|
||||
{ "-match", 0, CMD_MATCH },
|
||||
{ "--geometry", 5, CMD_GEOMETRY },
|
||||
|
||||
{ "-pixclock", 1, CMD_PIXCLOCK },
|
||||
{ "-left", 1, CMD_LEFT },
|
||||
{ "-right", 1, CMD_RIGHT },
|
||||
{ "-upper", 1, CMD_UPPER },
|
||||
{ "-lower", 1, CMD_LOWER },
|
||||
{ "-hslen", 1, CMD_HSLEN },
|
||||
{ "-vslen", 1, CMD_VSLEN },
|
||||
{ "--timings", 7, CMD_TIMING },
|
||||
|
||||
{ "-csync", 1, CMD_CSYNC },
|
||||
{ "-gsync", 1, CMD_GSYNC },
|
||||
{ "-extsync", 1, CMD_EXTSYNC },
|
||||
{ "-bcast", 1, CMD_BCAST },
|
||||
{ "-rgba", 1, CMD_RGBA },
|
||||
{ "-step", 1, CMD_STEP },
|
||||
{ "-move", 1, CMD_MOVE },
|
||||
{
|
||||
"-h", 0, CMD_HELP}, {
|
||||
"-fb", 1, CMD_FB}, {
|
||||
"-db", 1, CMD_DB}, {
|
||||
"-a", 0, CMD_ALL}, {
|
||||
"-i", 0, CMD_INFO}, {
|
||||
"-g", 5, CMD_GEOMETRY}, {
|
||||
"-t", 7, CMD_TIMING}, {
|
||||
"-accel", 1, CMD_ACCEL}, {
|
||||
"-hsync", 1, CMD_HSYNC}, {
|
||||
"-vsync", 1, CMD_VSYNC}, {
|
||||
"-laced", 1, CMD_LACED}, {
|
||||
"-double", 1, CMD_DOUBLE}, {
|
||||
"--help", 0, CMD_HELP}, {
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
"--help", 0, CMD_HELP}, {
|
||||
"-all", 0, CMD_ALL}, {
|
||||
"-xres", 1, CMD_XRES}, {
|
||||
"-yres", 1, CMD_YRES}, {
|
||||
"-vxres", 1, CMD_VXRES}, {
|
||||
"-vyres", 1, CMD_VYRES}, {
|
||||
"-depth", 1, CMD_DEPTH}, {
|
||||
"-match", 0, CMD_MATCH}, {
|
||||
"--geometry", 5, CMD_GEOMETRY}, {
|
||||
"-pixclock", 1, CMD_PIXCLOCK}, {
|
||||
"-left", 1, CMD_LEFT}, {
|
||||
"-right", 1, CMD_RIGHT}, {
|
||||
"-upper", 1, CMD_UPPER}, {
|
||||
"-lower", 1, CMD_LOWER}, {
|
||||
"-hslen", 1, CMD_HSLEN}, {
|
||||
"-vslen", 1, CMD_VSLEN}, {
|
||||
"--timings", 7, CMD_TIMING}, {
|
||||
"-csync", 1, CMD_CSYNC}, {
|
||||
"-gsync", 1, CMD_GSYNC}, {
|
||||
"-extsync", 1, CMD_EXTSYNC}, {
|
||||
"-bcast", 1, CMD_BCAST}, {
|
||||
"-rgba", 1, CMD_RGBA}, {
|
||||
"-step", 1, CMD_STEP}, {
|
||||
"-move", 1, CMD_MOVE}, {
|
||||
#endif
|
||||
{ 0, 0, 0 }
|
||||
0, 0, 0}
|
||||
};
|
||||
|
||||
static int readmode(struct fb_var_screeninfo *base, const char *fn,
|
||||
const char *mode)
|
||||
const char *mode)
|
||||
{
|
||||
#ifdef BB_FBSET_READMODE
|
||||
FILE *f;
|
||||
char buf[256];
|
||||
char *p = buf;
|
||||
|
||||
if ((f = fopen(fn, "r")) == NULL) PERROR("readmode(fopen)");
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
|
||||
p += 5;
|
||||
if ((p = strstr(buf, mode))) {
|
||||
p += strlen(mode);
|
||||
if (!isspace(*p) && (*p != 0) && (*p != '"') && (*p != '\r')
|
||||
&& (*p != '\n')) continue; /* almost, but not quite */
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if (!strstr(buf, "endmode")) return 1;
|
||||
FILE *f;
|
||||
char buf[256];
|
||||
char *p = buf;
|
||||
|
||||
if ((f = fopen(fn, "r")) == NULL)
|
||||
PERROR("readmode(fopen)");
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
|
||||
p += 5;
|
||||
if ((p = strstr(buf, mode))) {
|
||||
p += strlen(mode);
|
||||
if (!isspace(*p) && (*p != 0) && (*p != '"')
|
||||
&& (*p != '\r') && (*p != '\n'))
|
||||
continue; /* almost, but not quite */
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if (!strstr(buf, "endmode"))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
fprintf(stderr, "W: mode reading was disabled on this copy of fbset; ignoring request\n");
|
||||
errorMsg( "mode reading not compiled in\n");
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setmode(struct fb_var_screeninfo *base,
|
||||
struct fb_var_screeninfo *set)
|
||||
static void setmode(struct fb_var_screeninfo *base,
|
||||
struct fb_var_screeninfo *set)
|
||||
{
|
||||
if ((int)set->xres > 0) base->xres = set->xres;
|
||||
if ((int)set->yres > 0) base->yres = set->yres;
|
||||
if ((int)set->xres_virtual > 0) base->xres_virtual = set->xres_virtual;
|
||||
if ((int)set->yres_virtual > 0) base->yres_virtual = set->yres_virtual;
|
||||
if ((int)set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel;
|
||||
if ((int) set->xres > 0)
|
||||
base->xres = set->xres;
|
||||
if ((int) set->yres > 0)
|
||||
base->yres = set->yres;
|
||||
if ((int) set->xres_virtual > 0)
|
||||
base->xres_virtual = set->xres_virtual;
|
||||
if ((int) set->yres_virtual > 0)
|
||||
base->yres_virtual = set->yres_virtual;
|
||||
if ((int) set->bits_per_pixel > 0)
|
||||
base->bits_per_pixel = set->bits_per_pixel;
|
||||
}
|
||||
|
||||
static void showmode(struct fb_var_screeninfo *v)
|
||||
{
|
||||
double drate = 0, hrate = 0, vrate = 0;
|
||||
if (v->pixclock) {
|
||||
drate = 1e12 / v->pixclock;
|
||||
hrate = drate / (v->left_margin+v->xres+v->right_margin+v->hsync_len);
|
||||
vrate = hrate / (v->upper_margin+v->yres+v->lower_margin+v->vsync_len);
|
||||
}
|
||||
printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int)(vrate+0.5));
|
||||
#ifdef BB_FBSET_FANCY
|
||||
printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate/1e6, hrate/1e3,
|
||||
vrate);
|
||||
double drate = 0, hrate = 0, vrate = 0;
|
||||
|
||||
if (v->pixclock) {
|
||||
drate = 1e12 / v->pixclock;
|
||||
hrate =
|
||||
drate / (v->left_margin + v->xres + v->right_margin +
|
||||
v->hsync_len);
|
||||
vrate =
|
||||
hrate / (v->upper_margin + v->yres + v->lower_margin +
|
||||
v->vsync_len);
|
||||
}
|
||||
printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5));
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6,
|
||||
hrate / 1e3, vrate);
|
||||
#endif
|
||||
printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
|
||||
v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
|
||||
printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
|
||||
v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
|
||||
printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
|
||||
v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
|
||||
v->vsync_len);
|
||||
printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
|
||||
printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
|
||||
v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
|
||||
v->vsync_len);
|
||||
printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
|
||||
#else
|
||||
printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock, v->left_margin,
|
||||
v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
|
||||
v->vsync_len);
|
||||
printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock,
|
||||
v->left_margin, v->right_margin, v->upper_margin,
|
||||
v->lower_margin, v->hsync_len, v->vsync_len);
|
||||
#endif
|
||||
printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length, v->red.offset,
|
||||
v->green.length, v->green.offset, v->blue.length, v->blue.offset,
|
||||
v->transp.length, v->transp.offset);
|
||||
printf("endmode\n");
|
||||
printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
|
||||
v->red.offset, v->green.length, v->green.offset, v->blue.length,
|
||||
v->blue.offset, v->transp.length, v->transp.offset);
|
||||
printf("endmode\n\n");
|
||||
}
|
||||
|
||||
static void fbset_usage(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
#ifndef STANDALONE
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
#endif
|
||||
fprintf(stderr, "Usage: fbset [options] [mode]\n");
|
||||
fprintf(stderr, "\tThe following options are recognized:\n");
|
||||
for (i = 0; g_cmdoptions[i].name; i++)
|
||||
fprintf(stderr, "\t\t%s\n", g_cmdoptions[i].name);
|
||||
exit(-1);
|
||||
fprintf(stderr, "Usage: fbset [options] [mode]\n\n");
|
||||
fprintf(stderr, "Show and modify frame buffer device settings\n\n");
|
||||
fprintf(stderr, "The following options are recognized:\n");
|
||||
for (i = 0; g_cmdoptions[i].name; i++)
|
||||
fprintf(stderr, "\t%s\n", g_cmdoptions[i].name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
#ifdef STANDALONE
|
||||
int main(int argc, char **argv)
|
||||
#else
|
||||
#else
|
||||
extern int fbset_main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
struct fb_var_screeninfo var, varset;
|
||||
int fh, i;
|
||||
char *fbdev = DEFAULTFBDEV;
|
||||
char *modefile = DEFAULTFBMODE;
|
||||
char *thisarg, *mode = NULL;
|
||||
struct fb_var_screeninfo var, varset;
|
||||
int fh, i;
|
||||
char *fbdev = DEFAULTFBDEV;
|
||||
char *modefile = DEFAULTFBMODE;
|
||||
char *thisarg, *mode = NULL;
|
||||
|
||||
memset(&varset, 0xFF, sizeof(varset));
|
||||
|
||||
/* parse cmd args.... why do they have to make things so difficult? */
|
||||
argv++; argc--;
|
||||
for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
|
||||
for (i = 0; g_cmdoptions[i].name; i++) {
|
||||
if (!strcmp(thisarg, g_cmdoptions[i].name)) {
|
||||
if (argc - 1 < g_cmdoptions[i].param_count) fbset_usage();
|
||||
switch (g_cmdoptions[i].code) {
|
||||
case CMD_HELP: fbset_usage();
|
||||
case CMD_FB: fbdev = argv[1]; break;
|
||||
case CMD_DB: modefile = argv[1]; break;
|
||||
case CMD_GEOMETRY:
|
||||
varset.xres = strtoul(argv[1],0,0);
|
||||
varset.yres = strtoul(argv[2],0,0);
|
||||
varset.xres_virtual = strtoul(argv[3],0,0);
|
||||
varset.yres_virtual = strtoul(argv[4],0,0);
|
||||
varset.bits_per_pixel = strtoul(argv[5],0,0);
|
||||
break;
|
||||
case CMD_TIMING:
|
||||
varset.pixclock = strtoul(argv[1],0,0);
|
||||
varset.left_margin = strtoul(argv[2],0,0);
|
||||
varset.right_margin = strtoul(argv[3],0,0);
|
||||
varset.upper_margin = strtoul(argv[4],0,0);
|
||||
varset.lower_margin = strtoul(argv[5],0,0);
|
||||
varset.hsync_len = strtoul(argv[6],0,0);
|
||||
varset.vsync_len = strtoul(argv[7],0,0);
|
||||
break;
|
||||
#ifdef BB_FBSET_FANCY
|
||||
case CMD_XRES: varset.xres = strtoul(argv[1],0,0); break;
|
||||
case CMD_YRES: varset.yres = strtoul(argv[1],0,0); break;
|
||||
memset(&varset, 0xFF, sizeof(varset));
|
||||
|
||||
/* parse cmd args.... why do they have to make things so difficult? */
|
||||
argv++;
|
||||
argc--;
|
||||
for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
|
||||
for (i = 0; g_cmdoptions[i].name; i++) {
|
||||
if (!strcmp(thisarg, g_cmdoptions[i].name)) {
|
||||
if (argc - 1 < g_cmdoptions[i].param_count)
|
||||
fbset_usage();
|
||||
switch (g_cmdoptions[i].code) {
|
||||
case CMD_HELP:
|
||||
fbset_usage();
|
||||
case CMD_FB:
|
||||
fbdev = argv[1];
|
||||
break;
|
||||
case CMD_DB:
|
||||
modefile = argv[1];
|
||||
break;
|
||||
case CMD_GEOMETRY:
|
||||
varset.xres = strtoul(argv[1], 0, 0);
|
||||
varset.yres = strtoul(argv[2], 0, 0);
|
||||
varset.xres_virtual = strtoul(argv[3], 0, 0);
|
||||
varset.yres_virtual = strtoul(argv[4], 0, 0);
|
||||
varset.bits_per_pixel = strtoul(argv[5], 0, 0);
|
||||
break;
|
||||
case CMD_TIMING:
|
||||
varset.pixclock = strtoul(argv[1], 0, 0);
|
||||
varset.left_margin = strtoul(argv[2], 0, 0);
|
||||
varset.right_margin = strtoul(argv[3], 0, 0);
|
||||
varset.upper_margin = strtoul(argv[4], 0, 0);
|
||||
varset.lower_margin = strtoul(argv[5], 0, 0);
|
||||
varset.hsync_len = strtoul(argv[6], 0, 0);
|
||||
varset.vsync_len = strtoul(argv[7], 0, 0);
|
||||
break;
|
||||
#ifdef BB_FEATURE_FBSET_FANCY
|
||||
case CMD_XRES:
|
||||
varset.xres = strtoul(argv[1], 0, 0);
|
||||
break;
|
||||
case CMD_YRES:
|
||||
varset.yres = strtoul(argv[1], 0, 0);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
argc -= g_cmdoptions[i].param_count;
|
||||
argv += g_cmdoptions[i].param_count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!g_cmdoptions[i].name) {
|
||||
if (argc == 1) {
|
||||
mode = *argv;
|
||||
g_options |= OPT_READMODE;
|
||||
} else {
|
||||
fbset_usage();
|
||||
}
|
||||
}
|
||||
argc -= g_cmdoptions[i].param_count;
|
||||
argv += g_cmdoptions[i].param_count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!g_cmdoptions[i].name) {
|
||||
if (argc == 1) {
|
||||
mode = *argv;
|
||||
g_options |= OPT_READMODE;
|
||||
} else {
|
||||
fbset_usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((fh = open(fbdev, O_RDONLY)) < 0) PERROR("fbset(open)");
|
||||
if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) PERROR("fbset(ioctl)");
|
||||
if (g_options & OPT_READMODE) {
|
||||
if (!readmode(&var, modefile, mode)) {
|
||||
fprintf(stderr, "Unknown video mode `%s'\n", mode);
|
||||
exit(1);
|
||||
if ((fh = open(fbdev, O_RDONLY)) < 0)
|
||||
PERROR("fbset(open)");
|
||||
if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
|
||||
PERROR("fbset(ioctl)");
|
||||
if (g_options & OPT_READMODE) {
|
||||
if (!readmode(&var, modefile, mode)) {
|
||||
fprintf(stderr, "Unknown video mode `%s'\n", mode);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setmode(&var, &varset);
|
||||
if (g_options & OPT_CHANGE)
|
||||
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) PERROR("fbset(ioctl)");
|
||||
showmode(&var);
|
||||
close(fh);
|
||||
|
||||
return(TRUE);
|
||||
setmode(&var, &varset);
|
||||
if (g_options & OPT_CHANGE)
|
||||
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
|
||||
PERROR("fbset(ioctl)");
|
||||
showmode(&var);
|
||||
/* Don't close the file, as exiting will take care of that */
|
||||
/* close(fh); */
|
||||
|
||||
exit (TRUE);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini fdflush implementation for busybox
|
||||
*
|
||||
@@ -29,24 +30,27 @@
|
||||
|
||||
extern int fdflush_main(int argc, char **argv)
|
||||
{
|
||||
int value;
|
||||
int fd;
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage( "fdflush device\n");
|
||||
}
|
||||
int value;
|
||||
int fd;
|
||||
|
||||
fd = open(*argv, 0);
|
||||
if ( fd < 0 ) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
if (argc <= 1 || **(++argv) == '-') {
|
||||
usage("fdflush device\n\nForce floppy disk drive to detect disk change\n");
|
||||
}
|
||||
|
||||
value = ioctl(fd, FDFLUSH, 0);
|
||||
close(fd);
|
||||
fd = open(*argv, 0);
|
||||
if (fd < 0) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
if ( value ) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
exit (TRUE);
|
||||
value = ioctl(fd, FDFLUSH, 0);
|
||||
/* Don't bother closing. Exit does
|
||||
* that, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
|
||||
if (value) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini find implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,92 +29,89 @@
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
static char* pattern=NULL;
|
||||
static char* directory=".";
|
||||
static int dereferenceFlag=FALSE;
|
||||
static char *pattern = NULL;
|
||||
static char *directory = ".";
|
||||
static int dereferenceFlag = FALSE;
|
||||
|
||||
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\n\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of find matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of find matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\t\tprint the full file name followed by a newline to stdout.\n";
|
||||
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (pattern==NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else {
|
||||
char* tmp = strrchr( fileName, '/');
|
||||
if (tmp == NULL)
|
||||
tmp = (char*)fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
}
|
||||
return( TRUE);
|
||||
if (pattern == NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else {
|
||||
char *tmp = strrchr(fileName, '/');
|
||||
|
||||
if (tmp == NULL)
|
||||
tmp = (char *) fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
int find_main(int argc, char **argv)
|
||||
{
|
||||
/* peel off the "find" */
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if ( argc > 0 && **argv != '-') {
|
||||
directory=*argv;
|
||||
/* peel off the "find" */
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 0 && **argv == '-') {
|
||||
int stopit=FALSE;
|
||||
while (*++(*argv) && stopit==FALSE) switch (**argv) {
|
||||
case 'f':
|
||||
if (strcmp(*argv, "follow")==0) {
|
||||
argc--;
|
||||
argv++;
|
||||
dereferenceFlag=TRUE;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (strcmp(*argv, "name")==0) {
|
||||
if (argc-- > 1) {
|
||||
pattern=*(++argv);
|
||||
stopit=-TRUE;
|
||||
} else {
|
||||
usage (find_usage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
/* Ignore all long options */
|
||||
break;
|
||||
default:
|
||||
usage (find_usage);
|
||||
if (argc > 0 && **argv != '-') {
|
||||
directory = *argv;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc-- > 1)
|
||||
argv++;
|
||||
if (**argv != '-')
|
||||
break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (recursiveAction(directory, TRUE, FALSE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Parse any options */
|
||||
while (argc > 0 && **argv == '-') {
|
||||
int stopit = FALSE;
|
||||
|
||||
exit(TRUE);
|
||||
while (*++(*argv) && stopit == FALSE)
|
||||
switch (**argv) {
|
||||
case 'f':
|
||||
if (strcmp(*argv, "follow") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
dereferenceFlag = TRUE;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (strcmp(*argv, "name") == 0) {
|
||||
if (argc-- > 1) {
|
||||
pattern = *(++argv);
|
||||
stopit = TRUE;
|
||||
} else {
|
||||
usage(find_usage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
/* Ignore all long options */
|
||||
break;
|
||||
default:
|
||||
usage(find_usage);
|
||||
}
|
||||
if (argc-- > 1)
|
||||
argv++;
|
||||
if (**argv != '-')
|
||||
break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (recursiveAction(directory, TRUE, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
exit(TRUE);
|
||||
}
|
||||
+72
-74
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini find implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,92 +29,89 @@
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
static char* pattern=NULL;
|
||||
static char* directory=".";
|
||||
static int dereferenceFlag=FALSE;
|
||||
static char *pattern = NULL;
|
||||
static char *directory = ".";
|
||||
static int dereferenceFlag = FALSE;
|
||||
|
||||
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\n\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of find matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of find matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\t\tprint the full file name followed by a newline to stdout.\n";
|
||||
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (pattern==NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else {
|
||||
char* tmp = strrchr( fileName, '/');
|
||||
if (tmp == NULL)
|
||||
tmp = (char*)fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
}
|
||||
return( TRUE);
|
||||
if (pattern == NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else {
|
||||
char *tmp = strrchr(fileName, '/');
|
||||
|
||||
if (tmp == NULL)
|
||||
tmp = (char *) fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
int find_main(int argc, char **argv)
|
||||
{
|
||||
/* peel off the "find" */
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if ( argc > 0 && **argv != '-') {
|
||||
directory=*argv;
|
||||
/* peel off the "find" */
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 0 && **argv == '-') {
|
||||
int stopit=FALSE;
|
||||
while (*++(*argv) && stopit==FALSE) switch (**argv) {
|
||||
case 'f':
|
||||
if (strcmp(*argv, "follow")==0) {
|
||||
argc--;
|
||||
argv++;
|
||||
dereferenceFlag=TRUE;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (strcmp(*argv, "name")==0) {
|
||||
if (argc-- > 1) {
|
||||
pattern=*(++argv);
|
||||
stopit=-TRUE;
|
||||
} else {
|
||||
usage (find_usage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
/* Ignore all long options */
|
||||
break;
|
||||
default:
|
||||
usage (find_usage);
|
||||
if (argc > 0 && **argv != '-') {
|
||||
directory = *argv;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc-- > 1)
|
||||
argv++;
|
||||
if (**argv != '-')
|
||||
break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (recursiveAction(directory, TRUE, FALSE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Parse any options */
|
||||
while (argc > 0 && **argv == '-') {
|
||||
int stopit = FALSE;
|
||||
|
||||
exit(TRUE);
|
||||
while (*++(*argv) && stopit == FALSE)
|
||||
switch (**argv) {
|
||||
case 'f':
|
||||
if (strcmp(*argv, "follow") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
dereferenceFlag = TRUE;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (strcmp(*argv, "name") == 0) {
|
||||
if (argc-- > 1) {
|
||||
pattern = *(++argv);
|
||||
stopit = TRUE;
|
||||
} else {
|
||||
usage(find_usage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
/* Ignore all long options */
|
||||
break;
|
||||
default:
|
||||
usage(find_usage);
|
||||
}
|
||||
if (argc-- > 1)
|
||||
argv++;
|
||||
if (**argv != '-')
|
||||
break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (recursiveAction(directory, TRUE, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
exit(TRUE);
|
||||
}
|
||||
+96
-93
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini grep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -40,123 +41,125 @@
|
||||
#include <ctype.h>
|
||||
|
||||
static const char grep_usage[] =
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
|
||||
"Search for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n"
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
|
||||
"Search for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
static int match = FALSE, beQuiet = FALSE;
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
||||
int ignoreCase, int tellLine)
|
||||
{
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
while (fgets(haystack, sizeof(haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen(haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", fileName);
|
||||
if (*cp != '\n')
|
||||
fprintf(stderr, "%s: Line too long\n", fileName);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s:", fileName);
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName == TRUE)
|
||||
printf("%s:", fileName);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
if (tellLine == TRUE)
|
||||
printf("%ld:", line);
|
||||
|
||||
if (beQuiet==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
if (beQuiet == FALSE)
|
||||
fputs(haystack, stdout);
|
||||
|
||||
match = TRUE;
|
||||
match = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int grep_main (int argc, char **argv)
|
||||
extern int grep_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *cp;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName=FALSE;
|
||||
int ignoreCase=FALSE;
|
||||
int tellLine=FALSE;
|
||||
FILE *fp;
|
||||
char *cp;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName = TRUE;
|
||||
int ignoreCase = TRUE;
|
||||
int tellLine = FALSE;
|
||||
|
||||
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
usage(grep_usage);
|
||||
}
|
||||
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
|
||||
while (*++cp)
|
||||
switch (*cp) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = TRUE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
tellLine = TRUE;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
usage(grep_usage);
|
||||
}
|
||||
}
|
||||
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
if (argc==0) {
|
||||
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen (fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror (fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (fileName);
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
exit(match);
|
||||
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
|
||||
while (*++cp)
|
||||
switch (*cp) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
tellLine = TRUE;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(grep_usage);
|
||||
}
|
||||
}
|
||||
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
if (argc == 0) {
|
||||
do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
/* Never print the filename for just one file */
|
||||
if (argc == 1)
|
||||
tellName = FALSE;
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen(fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror(fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror(fp))
|
||||
perror(fileName);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
exit(match);
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini free implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -22,14 +23,33 @@
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
#define DIVISOR 1024
|
||||
extern int free_main(int argc, char **argv)
|
||||
{
|
||||
char* cmd[] = { "cat", "/proc/meminfo", "\0" };
|
||||
exit(cat_main( 3, cmd));
|
||||
struct sysinfo info;
|
||||
sysinfo(&info);
|
||||
info.totalram/=DIVISOR;
|
||||
info.freeram/=DIVISOR;
|
||||
info.totalswap/=DIVISOR;
|
||||
info.freeswap/=DIVISOR;
|
||||
info.sharedram/=DIVISOR;
|
||||
info.bufferram/=DIVISOR;
|
||||
|
||||
|
||||
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
|
||||
"shared", "buffers");
|
||||
|
||||
printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram,
|
||||
info.totalram-info.freeram, info.freeram,
|
||||
info.sharedram, info.bufferram);
|
||||
|
||||
printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap,
|
||||
info.totalswap-info.freeswap, info.freeswap);
|
||||
|
||||
printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap,
|
||||
(info.totalram-info.freeram)+(info.totalswap-info.freeswap),
|
||||
info.freeram+info.freeswap);
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* freeramdisk implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it>
|
||||
* Adjusted a bit by Erik Andersen <andersee@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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static const char freeramdisk_usage[] =
|
||||
"freeramdisk DEVICE\n\n"
|
||||
"Free all memory used by the specified ramdisk.\n";
|
||||
|
||||
extern int
|
||||
freeramdisk_main(int argc, char **argv)
|
||||
{
|
||||
char rname[256] = "/dev/ram";
|
||||
int f;
|
||||
|
||||
if (argc < 2 || ( argv[1] && *argv[1] == '-')) {
|
||||
usage(freeramdisk_usage);
|
||||
}
|
||||
|
||||
if (argc >1)
|
||||
strcpy(rname, argv[1]);
|
||||
|
||||
if ((f = open(rname, O_RDWR)) == -1) {
|
||||
fatalError( "freeramdisk: cannot open %s: %s\n", rname, strerror(errno));
|
||||
}
|
||||
if (ioctl(f, BLKFLSBUF) < 0) {
|
||||
fatalError( "freeramdisk: failed ioctl on %s: %s\n", rname, strerror(errno));
|
||||
}
|
||||
/* Don't bother closing. Exit does
|
||||
* that, so we can save a few bytes */
|
||||
/* close(f); */
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
|
||||
+406
-368
File diff suppressed because it is too large.
Load diff
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini grep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -40,123 +41,125 @@
|
||||
#include <ctype.h>
|
||||
|
||||
static const char grep_usage[] =
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
|
||||
"Search for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n"
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
|
||||
"Search for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n"
|
||||
"\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
static int match = FALSE, beQuiet = FALSE;
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
|
||||
int ignoreCase, int tellLine)
|
||||
{
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
while (fgets(haystack, sizeof(haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen(haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", fileName);
|
||||
if (*cp != '\n')
|
||||
fprintf(stderr, "%s: Line too long\n", fileName);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s:", fileName);
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName == TRUE)
|
||||
printf("%s:", fileName);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
if (tellLine == TRUE)
|
||||
printf("%ld:", line);
|
||||
|
||||
if (beQuiet==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
if (beQuiet == FALSE)
|
||||
fputs(haystack, stdout);
|
||||
|
||||
match = TRUE;
|
||||
match = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int grep_main (int argc, char **argv)
|
||||
extern int grep_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *cp;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName=FALSE;
|
||||
int ignoreCase=FALSE;
|
||||
int tellLine=FALSE;
|
||||
FILE *fp;
|
||||
char *cp;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName = TRUE;
|
||||
int ignoreCase = TRUE;
|
||||
int tellLine = FALSE;
|
||||
|
||||
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
usage(grep_usage);
|
||||
}
|
||||
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
|
||||
while (*++cp)
|
||||
switch (*cp) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = TRUE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
tellLine = TRUE;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
argv++;
|
||||
if (argc < 1) {
|
||||
usage(grep_usage);
|
||||
}
|
||||
}
|
||||
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
if (argc==0) {
|
||||
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen (fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror (fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (fileName);
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
exit(match);
|
||||
|
||||
if (**argv == '-') {
|
||||
argc--;
|
||||
cp = *argv++;
|
||||
|
||||
while (*++cp)
|
||||
switch (*cp) {
|
||||
case 'i':
|
||||
ignoreCase = TRUE;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
tellLine = TRUE;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
beQuiet = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(grep_usage);
|
||||
}
|
||||
}
|
||||
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
if (argc == 0) {
|
||||
do_grep(stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
/* Never print the filename for just one file */
|
||||
if (argc == 1)
|
||||
tellName = FALSE;
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen(fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror(fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep(fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror(fp))
|
||||
perror(fileName);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
exit(match);
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
|
||||
|
||||
Loaded 100 of 219 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user