[hackers] [st] Remove strsep() call || Roberto E. Vargas Caballero

2015-03-20 Thread git
commit 288f80cb06b442ef0f55ea62bbceb3260338bf7a
Author: Roberto E. Vargas Caballero k...@shike2.com
Date:   Fri Mar 20 06:46:59 2015 +

Remove strsep() call

strsep() is not a POSIX function, and it means that every system
needs different defines to expose it. If the prototype of strsep
is not exposed then an ugly int/pointer is done and it might mean
a crash. The best solution?, to remove the strsep and make a custom
loop. If C programmers cannot do this kind of loops without calling
a library function, then maybe we should move all the suckless
software to Java.

diff --git a/config.mk b/config.mk
index 7ae510e..3026d87 100644
--- a/config.mk
+++ b/config.mk
@@ -19,7 +19,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil 
-lXext -lXft \
`pkg-config --libs freetype2`
 
 # flags
-CPPFLAGS = -DVERSION=\${VERSION}\ -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
+CPPFLAGS = -DVERSION=\${VERSION}\ -D_XOPEN_SOURCE=600
 CFLAGS += -g -std=c99 -pedantic -Wall -Wvariadic-macros -Os ${INCS} ${CPPFLAGS}
 LDFLAGS += -g ${LIBS}
 
diff --git a/st.c b/st.c
index 68dc2be..39d3fee 100644
--- a/st.c
+++ b/st.c
@@ -2272,12 +2272,23 @@ strhandle(void) {
 
 void
 strparse(void) {
+   int c;
char *p = strescseq.buf;
 
strescseq.narg = 0;
strescseq.buf[strescseq.len] = '\0';
-   while(p  strescseq.narg  STR_ARG_SIZ)
-   strescseq.args[strescseq.narg++] = strsep(p, ;);
+
+   if(*p == '\0')
+   return;
+
+   while(strescseq.narg  STR_ARG_SIZ) {
+   strescseq.args[strescseq.narg++] = p;
+   while((c = *p) != ';'  c != '\0')
+   ++p;
+   if(c == '\0')
+   return;
+   *p++ = '\0';
+   }
 }
 
 void



Re: [hackers] [st] Remove strsep() call || Roberto E. Vargas Caballero

2015-03-20 Thread Roberto E. Vargas Caballero
first your loop is wrong. See what happens with the string ;, how many
fields do you have there? 2, your code will return only 1. Second,
to use directly the pointer or a variable is only a style question, and don't
modify the simplicity of the loop.


Regards,




Re: [hackers] [st] Remove strsep() call || Roberto E. Vargas Caballero

2015-03-20 Thread Truls Becken
Hi, I think the loop is simpler without the int c variable.

Cheers,
Truls
---
 st.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/st.c b/st.c
index 39d3fee..9f29130 100644
--- a/st.c
+++ b/st.c
@@ -2272,20 +2272,16 @@ strhandle(void) {

 void
 strparse(void) {
-   int c;
char *p = strescseq.buf;

strescseq.narg = 0;
strescseq.buf[strescseq.len] = '\0';

-   if(*p == '\0')
-   return;
-
-   while(strescseq.narg  STR_ARG_SIZ) {
+   while(*p  strescseq.narg  STR_ARG_SIZ) {
strescseq.args[strescseq.narg++] = p;
-   while((c = *p) != ';'  c != '\0')
+   while(*p  *p != ';')
++p;
-   if(c == '\0')
+   if(!*p)
return;
*p++ = '\0';
}
--
1.8.4



Re: [hackers] [st] Remove strsep() call || Roberto E. Vargas Caballero

2015-03-20 Thread Truls Becken
Ah yes, I didn't think the piggybacked while(*p  part through, sorry!!

The variable elimination suggestion stands, although it's just a style
change like you said.

-Truls