[dev] [sbase] [patch] Implement -m for who

2013-08-05 Thread sin
Hi,

Implemented -m for who.  No manpage update yet.

Thanks,
sin
>From ae65cd3af60fafd309a5c84c6c79a157354d4a02 Mon Sep 17 00:00:00 2001
From: sin 
Date: Mon, 5 Aug 2013 15:59:49 +0100
Subject: [PATCH] Implement -m for who

---
 who.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/who.c b/who.c
index ae969d6..3d0c5db 100644
--- a/who.c
+++ b/who.c
@@ -1,6 +1,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,8 +16,17 @@ main(int argc, char **argv)
FILE *ufp;
time_t t;
char timebuf[sizeof "-mm-dd hh:mm"];
+   bool mflag = false;
 
-   if(argc!=1)
+   ARGBEGIN {
+   case 'm':
+   mflag = true;
+   break;
+   default:
+   usage();
+   } ARGEND;
+
+   if (argc > 0)
usage();
 
if (!(ufp = fopen(_PATH_UTMP, "r"))) {
@@ -25,6 +35,9 @@ main(int argc, char **argv)
while(fread((char *)&usr, sizeof(usr), 1, ufp) == 1) {
if (!*usr.ut_name || !*usr.ut_line)
continue;
+   if (mflag && strcmp(usr.ut_line,
+   strrchr(ttyname(0), '/') + 1))
+   continue;
t = usr.ut_time;
strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", 
localtime(&t));
printf("%-8s %-12s %-16s\n", usr.ut_name, usr.ut_line, timebuf);
-- 
1.8.2.3



[dev] [sbase] [patch] No need to cast to (char *)

2013-08-05 Thread sin

>From 173b8b4b409bc1d0222f8cfe8a1275ef8a52a39f Mon Sep 17 00:00:00 2001
From: sin 
Date: Mon, 5 Aug 2013 16:04:49 +0100
Subject: [PATCH] No need to cast to (char *)

---
 who.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/who.c b/who.c
index 3d0c5db..aee4f76 100644
--- a/who.c
+++ b/who.c
@@ -32,7 +32,7 @@ main(int argc, char **argv)
if (!(ufp = fopen(_PATH_UTMP, "r"))) {
eprintf("fopen:");
}
-   while(fread((char *)&usr, sizeof(usr), 1, ufp) == 1) {
+   while(fread(&usr, sizeof(usr), 1, ufp) == 1) {
if (!*usr.ut_name || !*usr.ut_line)
continue;
if (mflag && strcmp(usr.ut_line,
-- 
1.8.2.3



[dev] [sbase] [patch] Ignore tilde in ut_line

2013-08-05 Thread sin

>From ee914584f00e32d7e63203fac76a549ba462a2ee Mon Sep 17 00:00:00 2001
From: sin 
Date: Mon, 5 Aug 2013 16:12:01 +0100
Subject: [PATCH] Ignore tilde in ut_line

---
 who.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/who.c b/who.c
index aee4f76..ec4accc 100644
--- a/who.c
+++ b/who.c
@@ -38,6 +38,8 @@ main(int argc, char **argv)
if (mflag && strcmp(usr.ut_line,
strrchr(ttyname(0), '/') + 1))
continue;
+   if (usr.ut_line[0] == '~')
+   continue;
t = usr.ut_time;
strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M", 
localtime(&t));
printf("%-8s %-12s %-16s\n", usr.ut_name, usr.ut_line, timebuf);
-- 
1.8.2.3



[dev] [sbase] [patch v2] Ignore tilde in ut_line

2013-08-05 Thread sin

>From 07206a797fbf4c88bd2f75581250f6cd5b642188 Mon Sep 17 00:00:00 2001
From: sin 
Date: Mon, 5 Aug 2013 16:12:01 +0100
Subject: [PATCH] Ignore tilde in ut_line

---
 who.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/who.c b/who.c
index aee4f76..92c7124 100644
--- a/who.c
+++ b/who.c
@@ -33,7 +33,8 @@ main(int argc, char **argv)
eprintf("fopen:");
}
while(fread(&usr, sizeof(usr), 1, ufp) == 1) {
-   if (!*usr.ut_name || !*usr.ut_line)
+   if (!*usr.ut_name || !*usr.ut_line ||
+   usr.ut_line[0] == '~')
continue;
if (mflag && strcmp(usr.ut_line,
strrchr(ttyname(0), '/') + 1))
@@ -51,4 +52,3 @@ usage(void)
 {
eprintf("usage: who\n");
 }
-
-- 
1.8.2.3



Re: [dev] [st][PATCH] unsigned function tdefcolor returns -1 on error

2013-08-05 Thread Eon S. Jeon
On Mon, 5 Aug 2013 08:18:38 +0200
"Roberto E. Vargas Caballero"  wrote:

> On Sun, Aug 04, 2013 at 08:54:35AM -0400, Eon S. Jeon wrote:
> > Hi
> > 
> > I found that tdefcolor returns -1 on error, while its return type is
> > unsigned long. At the same time, line 1724 and 1731 are checking the
> > positivity of its unsigned return value.
> > 
> 
> Good point, but I think is better change the type of tdefcolor
> instead. Could you amend the patch and send it again?
> 

Here it is.

diff --git a/st.c b/st.c
index 362de23..8aeb167 100644
--- a/st.c
+++ b/st.c
@@ -361,7 +361,7 @@ static void tsetdirtattr(int);
 static void tsetmode(bool, bool, int *, int);
 static void tfulldirt(void);
 static void techo(char *, int);
-static ulong tdefcolor(int *, int *, int);
+static long tdefcolor(int *, int *, int);
 static inline bool match(uint, uint);
 static void ttynew(void);
 static void ttyread(void);
@@ -1625,7 +1625,7 @@ tdeleteline(int n) {
tscrollup(term.c.y, n);
 }
 
-ulong
+long
 tdefcolor(int *attr, int *npar, int l) {
long idx = -1;
uint r, g, b;
@@ -1676,7 +1676,7 @@ tdefcolor(int *attr, int *npar, int l) {
 void
 tsetattr(int *attr, int l) {
int i;
-   ulong idx;
+   long idx;
 
for(i = 0; i < l; i++) {
switch(attr[i]) {