Re: [dev] sbase

2011-05-23 Thread Kamil Cholewiński
Hi,

had a sleepless night, so contributing sleep.c and sleep.1.

Thanks,
Kamil

On Mon, May 23, 2011 at 03:15:43AM +0100, Connor Lane Smith wrote:
 Hey all,
 
 I think it's about time we started a minimalist, statically linked set
 of core utilities. The BSD family are bloated, and the GNU monstrous.
 Some of us seem to be resorting to using those from Plan 9, which were
 designed for another operating system and exist on Unix through a
 compatibility shim.
 
 So, in a glorious demonstration of NIH syndrome, let's make our own!
 I'm unsure exactly which utilities we should include (suggestions on a
 comprehensive set?), but in terms of functionality a good rule of
 thumb is to only include flags present in both POSIX and Plan 9, thus
 making a sweet little subset. There are exceptions to this, like grep
 -q and ls -a, but it's a useful guideline.
 
 I've written a handful so far (basename, cat, echo, false, grep, tee,
 touch, true, wc), which I've attached. Each tool is between 6 and 88
 SLOC, and compiles with musl into a static binary between 13K and 45K
 in size. The manual pages are nice and short, too.
 
 If anyone else wants to contribute a tool written in the same style
 they are most welcome. I'd like to set up an hg repo soon, but I'm
 quite busy with exams atm.
 
 Thanks,
 cls


.TH SLEEP 1 sbase\-VERSION
.SH NAME
sleep \- wait for a specified amount of time
.SH SYNOPSIS
.B sleep
.RI SECONDS
.SH DESCRIPTION
Wait until SECONDS have elapsed.
/* See LICENSE file for copyright and license details. */
#include stdio.h
#include stdlib.h
#include unistd.h
#include util.h

int
main(int argc, char *argv[])
{
	int seconds;

	if (argc != 2)
		eprintf(usage: %s SECONDS\n, argv[0]);
	else {
		seconds = atoi(argv[1]);
		while (0 != (seconds = sleep(seconds)));
	}
	return EXIT_SUCCESS;
}


Re: [dev] sbase

2011-05-23 Thread Mate Nagy
Hi,
On Mon, May 23, 2011 at 03:15:43AM +0100, Connor Lane Smith wrote:
 I think it's about time we started a minimalist, statically linked set
 of core utilities. The BSD family are bloated, and the GNU monstrous.
 Some of us seem to be resorting to using those from Plan 9, which were
 designed for another operating system and exist on Unix through a
 compatibility shim.
please, please don't take this as a troll - it's just a personal
feeling... but I do feel that the suckless project is at its best when
it produces fantastically useful minimalistic software like dwm.

These days it seems a moronic, unproductive crusade on features and
rewriting completely serviceable utilities to be much worse is more popular.

Best regards,
 Mate



Re: [dev] sbase

2011-05-23 Thread Anselm R Garbe
On 23 May 2011 10:16, Mate Nagy mn...@port70.net wrote:
 On Mon, May 23, 2011 at 03:15:43AM +0100, Connor Lane Smith wrote:
 I think it's about time we started a minimalist, statically linked set
 of core utilities. The BSD family are bloated, and the GNU monstrous.
 Some of us seem to be resorting to using those from Plan 9, which were
 designed for another operating system and exist on Unix through a
 compatibility shim.
 please, please don't take this as a troll - it's just a personal
 feeling... but I do feel that the suckless project is at its best when
 it produces fantastically useful minimalistic software like dwm.

 These days it seems a moronic, unproductive crusade on features and
 rewriting completely serviceable utilities to be much worse is more popular.

I agree. Nevertheless, the effort already undertaken should at least
be preserved in a sbase repository which I asked Connor to set up.

For 9base the main purpose is mk and rc (and the assumptions of mk to
rely on a rc shell) -- it will be hard to pointless to rewrite those
for the sake of 9base.

Cheers,
Anselm




 Best regards,
  Mate





Re: [dev] sbase

2011-05-23 Thread Connor Lane Smith
Hey,

On 23 May 2011 04:36, Noah Birnel nbir...@gmail.com wrote:
 Your Makefile, though, is GNU-dependant.

Really, which part? It seems to work with NetBSD make.

On 23 May 2011 09:16, Mate Nagy mn...@port70.net wrote:
 please, please don't take this as a troll - it's just a personal
 feeling... but I do feel that the suckless project is at its best when
 it produces fantastically useful minimalistic software like dwm.

 These days it seems a moronic, unproductive crusade on features and
 rewriting completely serviceable utilities to be much worse is more popular.

I completely understand the sentiment. Just the other day on #suckless
I was saying, the reason why dwm and dmenu are so good is they bring
something new in terms of usability. Things like surf do not, they
just have fewer features.

So where does this fit in? Okay, this is basically my computing
tactic: simplifying my operating system to the point where I can
actually understand what on Earth is going on. When I use a system
like Ubuntu and Gnome, when shit breaks I have no idea what went
wrong, and I tend to end up reinstalling everything. When I use a
system like Debian and dwm, when shit breaks I say, ohhh, and fix
it, and it takes a couple of seconds. (X is an exception.) The simpler
the internals, the easier it is to use, not because of anything on the
surface -- though the manuals are rather easier to read -- but because
you can clearly visualise the mechanisms inside whatever tools you are
using.

So I hope that explains my view on the subject. I agree that dwm and
friends are suckless at its best, but this sort of paring is
necessary to build on my relationship with my computer as a whole: I
don't understand how it all works, so instead of spending the next
decade creating a mental image of the system, I'll just make my own,
thus bringing its complexity within the boundaries of my own ken. (Is
that a pun? I don't know.) I don't know how others live with the
complexity of their system, but I suspect it involves Perl and
duct-tape. :p

On 23 May 2011 09:42, Szabolcs Nagy n...@port70.net wrote:
 scripts will break

Yeah, when I started out I wanted to make it entirely POSIX, but once
I saw the flaggishness of the POSIX standard I decided I'd just make a
compromise. This will begin as a supplement to, rather than a
replacement for, standard utilities, and maybe we can get to a point
where a static distro like Stali can use only them. I don't know about
you, but I could genuinely live without autoconf on my laptop.

Thanks,
cls



Re: [dev] sbase

2011-05-23 Thread Connor Lane Smith
On 23 May 2011 03:33, Bryan Bennett bbenn...@gmail.com wrote:
 I would suggest first re-writing the ones that 9Base has listed. It seems
 a relatively exhaustive list and - with our case of NIH - we don't want to
 be using anything from another OS entirely, now do we ;)

Some of them, certainly, but we don't need to rewrite everything 9base
provides, like sam and mk. My hope is we can find a sufficiently
minimalist Unix shell, editor, and so on. If not, I suppose we can
write them after the smaller things. We'll see how it goes.

2011/5/23 Kamil Cholewiński harry6...@gmail.com:
 had a sleepless night, so contributing sleep.c and sleep.1.

Thanks Kamil, I'll add them when I create a repo.

cls



Re: [dev] sbase

2011-05-23 Thread ilf

On 05-23 05:37, Jens Staal wrote:
For fun, I have been trying to replace GNU with 
Busybox: https://wiki.archlinux.org/index.php/Base2busybox 
Heirloom: https://wiki.archlinux.org/index.php/Base2heirloom 
Plan9port: https://wiki.archlinux.org/index.php/Base2plan9


Very interesting.
Tried these, too? http://www.fefe.de/embutils/

--
ilf

Über 80 Millionen Deutsche benutzen keine Konsole. Klick dich nicht weg!
-- Eine Initiative des Bundesamtes für Tastaturbenutzung


signature.asc
Description: Digital signature


Re: [dev] sbase

2011-05-23 Thread Jens Staal
2011/5/23 ilf i...@zeromail.org:
 On 05-23 05:37, Jens Staal wrote:

 For fun, I have been trying to replace GNU with Busybox:
 https://wiki.archlinux.org/index.php/Base2busybox Heirloom:
 https://wiki.archlinux.org/index.php/Base2heirloom Plan9port:
 https://wiki.archlinux.org/index.php/Base2plan9

 Very interesting.
 Tried these, too? http://www.fefe.de/embutils/

 --
 ilf

 Über 80 Millionen Deutsche benutzen keine Konsole. Klick dich nicht weg!
                -- Eine Initiative des Bundesamtes für Tastaturbenutzung


Thanks!

I had never seen those before. I will check them out and see if I can
do something fun with them :)



Re: [dev] sbase

2011-05-23 Thread Bryan Bennett
Connor - Sorry. I meant the ones that were useful to the 'cause'.
On an initial read through of that page, I saw sam but missed mk
 rc.

Bryan



Re: [dev] sbase

2011-05-23 Thread Noah Birnel
On Mon, May 23, 2011 at 11:05:55AM +0100, Connor Lane Smith wrote:
 
 On 23 May 2011 04:36, Noah Birnel nbir...@gmail.com wrote:
  Your Makefile, though, is GNU-dependant.
 
 Really, which part? It seems to work with NetBSD make.
 
On FreeBSD, make does 
CC -c util.c
and nothing else.
make clean works as expected.

Had to run GNU make to get the actual programs. Sorry I'm ignorant of
what freebsd is not getting, or why.

-Noah

 



[dev] [lsx] Assume cwd if no arguments are given.

2011-05-23 Thread Petr Sabata
This makes lsx a bit more usable.

Signed-off-by: Petr Sabata psab...@redhat.com
---
 lsx.c |   38 +++---
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/lsx.c b/lsx.c
index 5060b9c..7fa5e35 100644
--- a/lsx.c
+++ b/lsx.c
@@ -8,28 +8,36 @@
 #include unistd.h
 #include sys/stat.h
 
-int
-main(int argc, char *argv[]) {
-   int i;
+void
+lsx(char *dirpath) {
struct dirent *dp;
struct stat s;
DIR *dir;
 
+   if((dir = opendir(dirpath))) {
+   fchdir(dirfd(dir));
+   do
+   if((dp = readdir(dir))
+(stat(dp-d_name, s) != -1)
+S_ISREG (s.st_mode)
+!access(dp-d_name, X_OK))
+   puts(dp-d_name);
+   while(dp);
+   closedir(dir);
+   }
+}
+
+int
+main(int argc, char *argv[]) {
+   int i;
+
if((argc  1)  !strncmp(argv[1], -v, 3)) {
fputs(lsx-VERSION, (C)opyright MMVI Anselm R. Garbe\n, 
stdout);
exit(EXIT_SUCCESS);
}
-   for(i = 0; i  argc; i++)
-   if((dir = opendir(argv[i]))) {
-   fchdir(dirfd(dir));
-   do
-   if((dp = readdir(dir))
-(stat(dp-d_name, s) != -1)
-S_ISREG (s.st_mode)
-!access(dp-d_name, X_OK))
-   puts(dp-d_name);
-   while(dp);
-   closedir(dir);
-   }
+   if (argc == 1)
+   lsx(.);
+   for(i = 1; i  argc; i++)
+   lsx(argv[i]);
return 0;
 }
-- 
1.7.4.4




Re: [dev] sbase

2011-05-23 Thread Kurt H Maier
On Mon, May 23, 2011 at 4:42 AM, Szabolcs Nagy n...@port70.net wrote:
 scripts will break

 (eg autoconf generated scripts depend on all sort of flags
 and lot of software uses autoconf..)

if you want gnu coreutils, you know where to find it.


-- 
# Kurt H Maier



Re: [dev] sbase

2011-05-23 Thread Rob
I have a gripe about the fread() business - I have to hit ^D twice
before eof is reported - the first ^D causes fread() to return non-zero,
with text I entered previously, the second ^D causes fread() to return 0.
Probably not a major problem but here's a patch if anyone's interested.

Also rm.c
I don't think it has any problems with symlinks, but I accept no
responsibility for your lost home directory, anime collection or
childhood memories.  I've never ever found a use for -f, it's just a
pain having rm prompt me, so I've assumed an always present -f. Stick it
in if you're going for posix or whatever though.

One more thing, we're not bothering with the -- flag, are we?

 but I'm quite busy with exams atm.
UK, right? Up late coding even with exams, I'm impressed.

Finally, I have an editor in the works, unfinished, but I plan to show
you lot at some point though/vapourware.

Cheers,
Rob.


fread.diff
Description: plain/text
/* See LICENSE file for copyright and license details. */
#include stdio.h
#include stdlib.h
#include string.h
#include errno.h
#include unistd.h
#include sys/types.h
#include dirent.h
#include util.h

int rflag = 0;

void rm(const char *);

int
main(int argc, char *argv[])
{
	int i;

	if(argc == 1)
		eprintf(usage: %s [-r] files...\n, argv[0]);

	for(i = 1; i  argc; i++) {
		if(!strcmp(argv[i], -r))
			rflag = 1;
		else
			rm(argv[i]);
	}
	return EXIT_SUCCESS;
}

void rm(const char *path)
{
	if(remove(path) == -1){
		if(errno == ENOTEMPTY  rflag){
			DIR *d = opendir(path);
			struct dirent *ent;
			char prev[BUFSIZ];

			if(!getcwd(prev, sizeof prev))
eprintf(getcwd:);
			if(chdir(path))
eprintf(chdir %s:, path);

			while((ent = readdir(d)))
if(strcmp(ent-d_name, ..)  strcmp(ent-d_name, .))
	rm(ent-d_name);

			closedir(d);
			if(chdir(prev) == -1)
eprintf(chdir %s:, prev);

			if(remove(path) == -1)
eprintf(remove %s:, path);
		}else
			eprintf(remove %s:, path);
	}
}


rm.1
Description: Binary data


Re: [dev] sbase

2011-05-23 Thread Bjartur Thorlacius
On 5/23/11, Rob robpill...@gmail.com wrote:
 One more thing, we're not bothering with the -- flag, are we?
We should, if only for the sake of portable scripts. We may not need
or want full POSIX, but we should at least support general conventions
used by properly written scripts.

 Finally, I have an editor in the works, unfinished, but I plan to show
 you lot at some point though/vapourware.
Interesting. More details, or show me the code. What's novel about him?



Re: [dev] sbase

2011-05-23 Thread pancake
Maybe you are interested in:

http://hg.youterm.com/smash

On 23/05/2011, at 21:08, Bjartur Thorlacius svartma...@gmail.com wrote:

 On 5/23/11, Rob robpill...@gmail.com wrote:
 One more thing, we're not bothering with the -- flag, are we?
 We should, if only for the sake of portable scripts. We may not need
 or want full POSIX, but we should at least support general conventions
 used by properly written scripts.
 
 Finally, I have an editor in the works, unfinished, but I plan to show
 you lot at some point though/vapourware.
 Interesting. More details, or show me the code. What's novel about him?
 



Re: [dev] sbase

2011-05-23 Thread Kurt H Maier
On Mon, May 23, 2011 at 3:08 PM, Bjartur Thorlacius
svartma...@gmail.com wrote:
 On 5/23/11, Rob robpill...@gmail.com wrote:
 One more thing, we're not bothering with the -- flag, are we?
 We should, if only for the sake of portable scripts. We may not need
 or want full POSIX, but we should at least support general conventions
 used by properly written scripts.

POSIX flags never start with --.

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
-- 
# Kurt H Maier



Re: [dev] sbase

2011-05-23 Thread Robert Ransom
On Mon, 23 May 2011 16:27:16 -0400
Kurt H Maier karmaf...@gmail.com wrote:

 On Mon, May 23, 2011 at 3:08 PM, Bjartur Thorlacius
 svartma...@gmail.com wrote:
  On 5/23/11, Rob robpill...@gmail.com wrote:
  One more thing, we're not bothering with the -- flag, are we?
  We should, if only for the sake of portable scripts. We may not need
  or want full POSIX, but we should at least support general conventions
  used by properly written scripts.
 
 POSIX flags never start with --.
 
 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

The point of the “--” ‘flag’ is to tell the program to not interpret
following arguments as options.


Robert Ransom


signature.asc
Description: PGP signature


Re: [dev] sbase

2011-05-23 Thread Kurt H Maier
On Mon, May 23, 2011 at 4:31 PM, Robert Ransom rransom.8...@gmail.com wrote:
 The point of the “--” ‘flag’ is to tell the program to not interpret
 following arguments as options.

Sorry, I assumed he was talking about --long-options.  I use -- pretty
regularly and will probably wind up patching it in if it's missing.


-- 
# Kurt H Maier



Re: [dev] sbase

2011-05-23 Thread Connor Lane Smith
On 23 May 2011 23:51, Kurt H Maier karmaf...@gmail.com wrote:
 Sorry, I assumed he was talking about --long-options.  I use -- pretty
 regularly and will probably wind up patching it in if it's missing.

In a moment of uncharacteristic pragmatism, I've decided for these
tools it's probably best to use getopt. Not using it works well for
dwm and dmenu, but .. yeah. So -- is now supported, as are grouped
flags, etc.

cls



Re: [dev] sbase

2011-05-23 Thread Connor Lane Smith
On 23 May 2011 19:53, Rob robpill...@gmail.com wrote:
 I have a gripe about the fread() business - I have to hit ^D twice
 before eof is reported - the first ^D causes fread() to return non-zero,
 with text I entered previously, the second ^D causes fread() to return 0.
 Probably not a major problem but here's a patch if anyone's interested.

I wonder why this behaves differently to read(). Any ideas?

 Also rm.c

Thanks. I've modified it slightly to avoid having to get the cwd,
since that opens a can of worms. (In short, POSIX makes it literally
impossible ensure that you've got the entire path.)

 I've never ever found a use for -f, it's just a
 pain having rm prompt me, so I've assumed an always present -f. Stick it
 in if you're going for posix or whatever though.

I agree, though I've added -f as a null flag, so it's ignored but
doesn't cause an error either, since scripts quite sensibly use -f.

 UK, right? Up late coding even with exams, I'm impressed.

I can't help it, I think I code obsessively. :p

 Finally, I have an editor in the works, unfinished, but I plan to show
 you lot at some point though/vapourware.

Looking forward to it. imo we need a new editor...

Thanks,
cls



Re: [dev] sbase

2011-05-23 Thread Kurt H Maier
On Mon, May 23, 2011 at 8:58 PM, Connor Lane Smith c...@lubutu.com wrote:
 Looking forward to it. imo we need a new editor...

I like this:
http://www.stabie-soft.com/sre/re.html

it's no sam, but for short one-off edits (or even as a pager) I like it.
-- 
# Kurt H Maier