futher README tweaks

This commit is contained in:
NunoSempere 2023-09-15 12:09:49 +03:00
parent 910ba7ca53
commit 926eab1a9b

View File

@ -1,6 +1,6 @@
# wc: count words in <50 lines of C
The Unix utility wc counts words. You can make a version of it that solely counts words in 158 words and 44 lines of C. Or you can be like GNU and take 3615 words and 1034 lines to do something more complex.
The Unix utility wc counts words. You can make simple, non-POSIX compatible version of it that solely counts words in [158 words and 44 lines of C](https://git.nunosempere.com/personal/wc/src/branch/master/src/wc.c). Or you can be like GNU and take 3615 words and 1034 lines to do something more complex.
## Desiderata
@ -11,9 +11,9 @@ The Unix utility wc counts words. You can make a version of it that solely count
- Linux only.
- Small.
## Comparison with other versions of wc.
## Comparison with other versions of wc
The [version in wc/wc.c](./src/wc/c) in this repository sits at 44 lines. It decides to read from stdin if the number of arguments fed to it is otherwise zero, and uses the linux `read` function to read character by character. It doesn't have flags, instead, there are further utilities in the src/extra/ folder for counting characters and lines, sitting at 32 and 35 lines of code, respectively. This version also has little error checking.
The [version of wc.c](https://git.nunosempere.com/personal/wc/src/branch/master/src/wc.c) in this repository sits at 44 lines. It decides to read from stdin if the number of arguments fed to it is otherwise zero, and uses the linux `read` function to read character by character. It doesn't have flags, instead, there are further utilities in the src/extra/ folder for counting characters and lines, sitting at 32 and 35 lines of code, respectively. This version also has little error checking.
[Here](https://github.com/dspinellis/unix-history-repo/blob/Research-V7-Snapshot-Development/usr/src/cmd/wc.c) is a version of wc from UNIX V7, at 86 lines. It allows for counting characters, words and lines. I couldn't find a version in UNIX V6, so I'm guessing this is one of the earliest versions of this program. It decides to read from stdin if the number of arguments fed to it is zero, and reads character by character using the standard C `getc` function.
@ -74,34 +74,36 @@ Does one really need to spend 1k lines of C code to count characters, words and
I'm not sure that gratuitous incompatibility is so bad if it leads to utilities that are much simpler and easier to understand and inspect. That said, other projects aiming in this direction that I could find, like [tiny-core](https://github.com/keiranrowan/tiny-core/tree/master/src) or [zig-coreutils](https://github.com/leecannon/zig-coreutils) don't seem to be making much headway.
## Steps:
## To do
- [ ] Possible follow-up: Write simple versions for other coreutils. <https://git.busybox.net/busybox/tree/coreutils/>? Would be a really nice project.
- [ ] Get some simple version of this working on a DuskOS/CollapseOS machine?
- [ ] Or, generally find a minimalistic kernel that could use some simple coreutils.
- [ ] Add man pages?
- [ ] Pitch to lwn.net as an article?
- [ ] Come back to writting these in zig.
## Done or discarded
- [x] Look into how C utilities both read from stdin and from files.
- [x] Program first version of the utility
- [x] Compare with other implementations, see how they do it, after I've created my own version
- [x] Compare with gnu utils.
- [x] Compare with busybox implementation
- [ ] Compare with other projects: <https://github.com/leecannon/zig-coreutils>, <https://github.com/keiranrowan/tiny-core/tree/master>.
- [x] Compare with other versions
- [x] Compare with other projects: <https://github.com/leecannon/zig-coreutils>, <https://github.com/keiranrowan/tiny-core/tree/master>.
- [x] Install to ww, but check that ww is empty (installing to wc2 or smth would mean that you don't save that many keypresses vs wc -w)
- [x] Look specifically at how other versions do stuff.
- [x] Distinguish between reading from stdin and reading from a file
- If it doesn't have arguments, read from stdin.
- [x] If it doesn't have arguments, read from stdin.
- [x] Open files, read characters.
- [x] Write version that counts lines (lc)
- [x] Take into account what happens if file doesn't end in newline.
- [ ] Count EOF as word & line separator
- [ ] Document it
- [ ] ~~Count EOF as word & line separator~~
- [x] Document it
- [x] Document reading from user-inputed stdin (end with Ctrl+D)
- [ ] Possible follow-up: Write simple versions for other coreutils. <https://git.busybox.net/busybox/tree/coreutils/>? Would be a really nice project.
- Get it working on a DuskOS/CollapseOS machine? Or, find a minimalistic kernel that could use them?
- [x] add chc, or charcounter (cc is "c compiler")
- [x] Add licenses to historical versions before redistributing.
- [ ] Add man pages?
- [ ] Pitch to lwn.net as an article?
Discarded:
- ~~[ ] Could use zig? => Not for now~~
- ~~Maybe make some pull requests, if I'm doing something better? => doesn't seem like it~~
- ~~[ ] Write man files?~~
- [ ] ~~Could use zig? => Not for now~~
- [ ] ~~Maybe make some pull requests, if I'm doing something better? => doesn't seem like it~~
- [ ] ~~Write man files?~~