[hackers] [PATCH 2/2] Add OpenBSD support to config.mk

2018-03-09 Thread Lucas Gabriel Vuotto
Signed-off-by: Lucas Gabriel Vuotto <l...@nanashi.co>
---
 config.mk | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/config.mk b/config.mk
index 3a71529..29caa84 100644
--- a/config.mk
+++ b/config.mk
@@ -7,9 +7,18 @@ VERSION = 0.6
 PREFIX = /usr/local
 MANPREFIX = ${PREFIX}/share/man
 
+X11INC = /usr/X11R6/include
+X11LIB = /usr/X11R6/lib
+
+# freetype
+FREETYPELIBS = -lfontconfig -lXft
+FREETYPEINC = /usr/include/freetype2
+# OpenBSD (uncomment)
+#FREETYPEINC = ${X11INC}/freetype2
+
 # includes and libs
-INCS = -I. -I/usr/include -I/usr/include/freetype2
-LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft
+INCS = -I. -I/usr/include -I$(X11INC) -I${FREETYPEINC}
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${FREETYPELIBS}
 
 # flags
 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
-- 
2.16.0




[hackers] [PATCH 1/2] Embed dmenu in tabbed own window

2018-03-09 Thread Lucas Gabriel Vuotto
Signed-off-by: Lucas Gabriel Vuotto <l...@nanashi.co>
---
 config.def.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.def.h b/config.def.h
index 2d23049..defa426 100644
--- a/config.def.h
+++ b/config.def.h
@@ -27,7 +27,7 @@ static Bool npisrelative  = False;
 .v = (char *[]){ "/bin/sh", "-c", \
 "prop=\"`xwininfo -children -id $1 | grep '^ 0x' |" \
 "sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@' |" 
\
-"xargs -0 printf %b | dmenu -l 10`\" &&" \
+"xargs -0 printf %b | dmenu -l 10 -w $1`\" &&" \
 "xprop -id $1 -f $0 8s -set $0 \"$prop\"", \
 p, winid, NULL \
 } \
-- 
2.16.0




Re: [hackers] [surf] modal browsing

2017-09-03 Thread Lucas Gabriel Vuotto
Hello ssd,

Patches should be inlined, as it's easier to reply to chunks.

One chunk assigns .b field of Arg union, which doesn't exists and is never used 
in the patch. It should assign .i instead. The rest of the patch reads ok.

As for opinions, I'm not a fan of modal modes, so I think it would work better 
as a patch in the wiki and not in mainline.

Cheers.

On 09/02/17 20:59, ssd wrote:
> Hi,
> 
> modal browsing hasn't been first class citizen in surf. but given the
> recent activity in adding features and webkit2 may be there is a
> slightly better chance now.
> 
> attached is another rewrite of the modal browsing patch.
> 
> I find particularly appealing the fact that when implemented in the
> browser code, it is independent of the JS loading policy. (AFAIR there
> are alternative implementations as plug-ins which can be adapted and used
> in .surf/script.js.) 
> 
> what the patch provides:
> 
> - command line switch to enable modes
> - the default behaviour is unchanged
> - when enabled, modes resemble 2 vi inspired modes: "insert mode" and "normal 
> mode"
>   - insert mode is equivalent to the default behaviour
>   - in normal mode, the MODKEY is assumed pressed, i.e. the bindings are
> active without pressing MODKEY.
> 
> in addition:
> 
> - the patch shifts around some default bindings in config.def.h to make
>   the new functionality more consistent.
> 
> cheers
> --s
> 



Re: [hackers] [scron] [PATCH 3/3] Keep existing crontab entries if loading new entries fails

2017-07-11 Thread Lucas Gabriel Vuotto
I like the idea of this patch. There're two little details marked below.

> @@ -391,7 +379,7 @@ freecte(struct ctabentry *cte, int nfields)
>  }
>  
>  static void
> -unloadentries(void)
> +unloadentries(struct ctabentry *ctab)

Shadowing variables is error prone. In this case, this will happen if the first 
patch is merged, to which I oppose, given that there is nothing wrong with 
queue.h macros.

> @@ -492,14 +483,6 @@ loadentries(void)
>  }
>  
>  static void
> -reloadentries(void)
> -{
> - unloadentries();
> - if (loadentries() < 0)
> - logwarn("warning: discarding old crontab entries\n");
> -}
> -
> -static void>  sighandler(int sig)
>  {
>   switch (sig) {

Somehow, the sysadmin should be informed that loadentries failed. Either keep 
reloadentries or log the failure in main.



Re: [hackers] [farbfeld] Mark explicit dependency on requisites for BIN || Laslo Hunhold

2017-04-02 Thread Lucas Gabriel Vuotto

Hi Laslo

On 02/04/17 13:16, Laslo Hunhold wrote:

On Sat, 1 Apr 2017 00:49:15 -0300
Lucas Gabriel Vuotto <lvuott...@gmail.com> wrote:

Hey Lucas,


-.o: $(REQ:=.o)
-   $(CC) $(LDFLAGS) $($*-LDFLAGS) -o $@ $< $(REQ:=.o)
+$(BIN): $(REQ:=.o)

 $(BIN:=.o): config.mk $(HDR) $(REQ:=.h)

+.o: $(REQ:=.o)
+   $(CC) $(LDFLAGS) $($*-LDFLAGS) -o $@ $< $(REQ:=.o)


This is a recipe for the file `.o'. I'm certain that you don't want
to do that.


No, this is not a recipe for the file ".o". This is a single suffix
rule for transforming objects into binaries.
Now, I know this is not the most beautiful solution, but in this case
every binary should include the requisite-objects, as every binary is
using util.h in one way or another.
I am certain that I want to do that.



From [0], extended description, inference rules:

«The application shall ensure that the target portion is a valid target 
name (see Target Rules) of the form .s2 or .s1.s2 (where .s1 and .s2 are 
suffixes that have been given as prerequisites of the .SUFFIXES special 
target and s1 and s2 do not contain any  or  characters.) 
If there is only one  in the target, it is a single-suffix 
inference rule. Targets with two periods are double-suffix inference 
rules. Inference rules can have only one target before the .


The application shall ensure that the makefile does not specify 
prerequisites for inference rules; no characters other than white space 
shall follow the  in the first line, except when creating the 
empty rule, described below. Prerequisites are inferred, as described 
below.»



Also, expanding macros inside macros produces undefined results. The
proposed patch by Quentin is correct solution [0].

[0]: http://lists.suckless.org/hackers/1703/14849.html


Okay, first off. Please tell me where my Makefile is broken
feature-wise. I'm struggling to find the problem.


I never said it was broken feature-wise; it's only non-compliant.


Keep in mind, that for explicit single suffix rules make is smart
enough to include the .o in the dependency tree. There's no need to
list it explicitly.



That's right.


Secondly, where in my Makefile am I triggering undefined results? Are
you talking about "$($*-LDFLAGS)"? As you know, I'd love to know.



I'm talking about $($*-LDFLAGS). From [0], extended description, macros:

«Macros can appear anywhere in the makefile. Macro expansions using the 
forms $(string1) or ${ string1} shall be replaced by string2, as 
follows: [...] The parentheses or braces are optional if string1 is a 
single character. The macro $$ shall be replaced by the single character 
'$'. If string1 in a macro expansion contains a macro expansion, the 
results are unspecified.»



Beside that, you're overriding CC in config.mk with a non-standard
binary and compiling against c89 for some reason. That goes against
the idea of making the Makefile POSIX imo.


It's a convenience you'll find in every suckless Makefile and even
beyond that. It's common to provide a command within the Makefile, or
in this case the config.mk, to override the standard C compiler.
"cc" is actually common in Unix systems and points at the default C
compiler.
If you run make with a envvar-prefix "CC=..." it will respect that.



No, it won't. In order to override a macro *defined* in the makefile 
with an environment variable, make must be invoked with the `-e` flag. 
Even more correct is to call `make CC=...`, as macros defined in the 
command line override everything. All that defined is in [0], extended 
description, macros.



The code is ANSI C (C89, C90 call it however you like), which is why I
point it out here to the compiler. There's nothing wrong with that.
What's your point?



I don't see a reason for wasting time making the Makefile POSIX 
compliant but not the full build chain.



I suggest you either do as Hiltjo says and revert everything or make
the build system completely POSIX. Right now, it's an ugly hybrid.


Except from your remark about the undefined behaviour which I'm very
interested to see what you mean, the Makefile as is seems to be POSIX
compliant to me. I hope you can help me in case I am wrong about it.

With best regards

Laslo Hunhold



I hope this mail makes things clearer to you.

Cheers.

[0]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html

-- lv.



Re: [hackers] [farbfeld] Mark explicit dependency on requisites for BIN || Laslo Hunhold

2017-03-31 Thread Lucas Gabriel Vuotto

Hi,

On 30/03/17 04:29, g...@suckless.org wrote:

commit d0ce307972fbc95073666e92043fc7012ffbefdf
Author: Laslo Hunhold 
AuthorDate: Thu Mar 30 09:29:06 2017 +0200
Commit: Laslo Hunhold 
CommitDate: Thu Mar 30 09:29:06 2017 +0200

Mark explicit dependency on requisites for BIN

diff --git a/Makefile b/Makefile
index e1e954d..1f7446f 100644
--- a/Makefile
+++ b/Makefile
@@ -13,11 +13,13 @@ MAN5 = farbfeld.5

 all: $(BIN)

-.o: $(REQ:=.o)
-   $(CC) $(LDFLAGS) $($*-LDFLAGS) -o $@ $< $(REQ:=.o)
+$(BIN): $(REQ:=.o)

 $(BIN:=.o): config.mk $(HDR) $(REQ:=.h)

+.o: $(REQ:=.o)
+   $(CC) $(LDFLAGS) $($*-LDFLAGS) -o $@ $< $(REQ:=.o)


This is a recipe for the file `.o'. I'm certain that you don't want to 
do that.


Also, expanding macros inside macros produces undefined results. The 
proposed patch by Quentin is correct solution [0].



+
 clean:
rm -f $(BIN) $(BIN:=.o) $(REQ:=.o)




Beside that, you're overriding CC in config.mk with a non-standard 
binary and compiling against c89 for some reason. That goes against the 
idea of making the Makefile POSIX imo.


I suggest you either do as Hiltjo says and revert everything or make the 
build system completely POSIX. Right now, it's an ugly hybrid.


Cheers.

--

[0]: http://lists.suckless.org/hackers/1703/14849.html

-- lv.



[hackers] [scc] [PATCH v2] Remove MAKEFLAGS use

2016-06-15 Thread Lucas Gabriel Vuotto
Per posix, "[...] Before the makefile(s) are read, all of the make utility
command line options (except -f and -p) and make utility command line macro
definitions (except any for the MAKEFLAGS macro), not already included in the
MAKEFLAGS macro, shall be added to the MAKEFLAGS macro [...]", so there is no
need to use MAKEFLAGS at all in this cases.

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 Makefile  | 10 +-
 cc1/Makefile  |  2 +-
 cc2/Makefile  |  2 +-
 driver/posix/Makefile |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 48b5282..7148f69 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ ARCHS = z80 i386-sysv amd64-sysv qbe
 all:
for i in $(DIRS); \
do \
-   (cd $$i && $(MAKE) -e -$(MAKEFLAGS)); \
+   (cd $$i && $(MAKE) -e); \
done
cp -f cc1/cc1 bin/cc1
cp -f cc2/cc2 bin/cc2
@@ -19,14 +19,14 @@ all:
 multi:
for i in $(ARCHS); \
do \
-   $(MAKE) -$(MAKEFLAGS) $$i || exit; \
+   $(MAKE) $$i || exit; \
done
 
 $(ARCHS):
for i in cc1 cc2; \
do \
(cd $$i; \
-   ARCH=$@ $(MAKE) -e -$(MAKEFLAGS) clean; \
+   ARCH=$@ $(MAKE) -e clean; \
ARCH=$@ $(MAKE) -e $$i || exit); \
done
ln -f cc1/cc1 bin/cc1-$@
@@ -49,13 +49,13 @@ uninstall:
 clean:
for i in $(DIRS); \
do \
-   (cd $$i && $(MAKE) -$(MAKEFLAGS) $@ || exit); \
+   (cd $$i && $(MAKE) $@ || exit); \
done
 
 multi-clean:
for i in $(ARCHS); \
do \
-   ARCH=$$i $(MAKE) -e -$(MAKEFLAGS) clean || exit; \
+   ARCH=$$i $(MAKE) -e clean || exit; \
done
 
 distclean: multi-clean
diff --git a/cc1/Makefile b/cc1/Makefile
index 1cfc5c3..80e5470 100644
--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -14,7 +14,7 @@ all: cc1
 $(OBJS): cc1.h ../inc/cc.h ../inc/sizes.h arch/$(ARCH)/arch.h
 
 ../lib/libcc.a:
-   cd ../lib && $(MAKE) -e -$(MAKEFLAGS)
+   cd ../lib && $(MAKE) -e
 
 cc1: $(OBJS) ../lib/libcc.a
$(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@
diff --git a/cc2/Makefile b/cc2/Makefile
index 62e58d0..c6ed72e 100644
--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -21,7 +21,7 @@ main.o: error.h
 $(OBJS): cc2.h ../inc/sizes.h
 
 ../lib/libcc.a:
-   cd ../lib && $(MAKE) -e -$(MAKEFLAGS)
+   cd ../lib && $(MAKE) -e
 
 cc2: $(OBJS) ../lib/libcc.a
$(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@
diff --git a/driver/posix/Makefile b/driver/posix/Makefile
index 5012890..91b1532 100644
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
@@ -10,7 +10,7 @@ all: scc
 $(OBJS): ../../inc/cc.h
 
 ../../lib/libcc.a:
-   cd ../../lib && $(MAKE) -e -$(MAKEFLAGS)
+   cd ../../lib && $(MAKE) -e
 
 scc: $(OBJS) ../../lib/libcc.a
$(CC) $(SCC_LDFLAGS) $(OBJS) ../../lib/libcc.a -o $@
-- 
2.7.3




[hackers] [scc] [PATCH] Fix MAKEFLAGS use

2016-06-15 Thread Lucas Gabriel Vuotto
POSIX says that MAKEFLAGS can have flags in both 'ers' and '-e -r -s' format, so
the previous approach might not work if the second format is used, or if
MAKEFLAGS is empty.

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 Makefile  | 10 +-
 cc1/Makefile  |  2 +-
 cc2/Makefile  |  2 +-
 driver/posix/Makefile |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 48b5282..c0163bb 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ ARCHS = z80 i386-sysv amd64-sysv qbe
 all:
for i in $(DIRS); \
do \
-   (cd $$i && $(MAKE) -e -$(MAKEFLAGS)); \
+   (cd $$i && MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) -e); \
done
cp -f cc1/cc1 bin/cc1
cp -f cc2/cc2 bin/cc2
@@ -19,14 +19,14 @@ all:
 multi:
for i in $(ARCHS); \
do \
-   $(MAKE) -$(MAKEFLAGS) $$i || exit; \
+   MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) $$i || exit; \
done
 
 $(ARCHS):
for i in cc1 cc2; \
do \
(cd $$i; \
-   ARCH=$@ $(MAKE) -e -$(MAKEFLAGS) clean; \
+   ARCH=$@ MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) -e clean; \
ARCH=$@ $(MAKE) -e $$i || exit); \
done
ln -f cc1/cc1 bin/cc1-$@
@@ -49,13 +49,13 @@ uninstall:
 clean:
for i in $(DIRS); \
do \
-   (cd $$i && $(MAKE) -$(MAKEFLAGS) $@ || exit); \
+   (cd $$i && MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) $@ || exit); \
done
 
 multi-clean:
for i in $(ARCHS); \
do \
-   ARCH=$$i $(MAKE) -e -$(MAKEFLAGS) clean || exit; \
+   ARCH=$$i MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) -e clean || exit; \
done
 
 distclean: multi-clean
diff --git a/cc1/Makefile b/cc1/Makefile
index 1cfc5c3..c31382c 100644
--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -14,7 +14,7 @@ all: cc1
 $(OBJS): cc1.h ../inc/cc.h ../inc/sizes.h arch/$(ARCH)/arch.h
 
 ../lib/libcc.a:
-   cd ../lib && $(MAKE) -e -$(MAKEFLAGS)
+   cd ../lib && MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) -e
 
 cc1: $(OBJS) ../lib/libcc.a
$(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@
diff --git a/cc2/Makefile b/cc2/Makefile
index 62e58d0..394f4a2 100644
--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -21,7 +21,7 @@ main.o: error.h
 $(OBJS): cc2.h ../inc/sizes.h
 
 ../lib/libcc.a:
-   cd ../lib && $(MAKE) -e -$(MAKEFLAGS)
+   cd ../lib && MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) -e
 
 cc2: $(OBJS) ../lib/libcc.a
$(CC) $(SCC_LDFLAGS) $(OBJS) ../lib/libcc.a -o $@
diff --git a/driver/posix/Makefile b/driver/posix/Makefile
index 5012890..05b4ff2 100644
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
@@ -10,7 +10,7 @@ all: scc
 $(OBJS): ../../inc/cc.h
 
 ../../lib/libcc.a:
-   cd ../../lib && $(MAKE) -e -$(MAKEFLAGS)
+   cd ../../lib && MAKEFLAGS="$(MAKEFLAGS)" $(MAKE) -e
 
 scc: $(OBJS) ../../lib/libcc.a
$(CC) $(SCC_LDFLAGS) $(OBJS) ../../lib/libcc.a -o $@
-- 
2.7.3




[hackers] [PATCH 1/2] Import libterminfo

2016-05-22 Thread Lucas Gabriel Vuotto
Modified source from https://gitlab.com/lv/damned.git

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 Makefile |   24 +-
 libterminfo/Makefile |   10 +
 libterminfo/mkcaps.h.awk |   22 +
 libterminfo/mkcapsutil.h.awk |   42 ++
 libterminfo/ncurses-5.9/Caps | 1258 ++
 libterminfo/terminfo.c   |  178 ++
 libterminfo/tparse.c |  614 +
 terminfo.h   |   32 ++
 util.h   |2 +
 9 files changed, 2179 insertions(+), 3 deletions(-)
 create mode 100644 libterminfo/Makefile
 create mode 100644 libterminfo/mkcaps.h.awk
 create mode 100644 libterminfo/mkcapsutil.h.awk
 create mode 100644 libterminfo/ncurses-5.9/Caps
 create mode 100644 libterminfo/terminfo.c
 create mode 100644 libterminfo/tparse.c
 create mode 100644 terminfo.h

diff --git a/Makefile b/Makefile
index 453607c..c639d69 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ HDR = \
queue.h  \
reboot.h \
rtc.h\
+   terminfo.h   \
text.h   \
util.h
 
@@ -34,7 +35,16 @@ LIBUTILSRC = \
libutil/strtonum.c   \
libutil/tty.c
 
-LIB = $(LIBUTIL)
+LIBTERMINFO = libterminfo.a
+LIBTERMINFOSRC = \
+   libterminfo/terminfo.c \
+   libterminfo/tparse.c
+LIBTERMINFOGENHDR = \
+   libterminfo/damned-caps.h \
+   libterminfo/damned-capsutil.h \
+   libterminfo/capstbl.h
+
+LIB = $(LIBTERMINFO) $(LIBUTIL)
 
 BIN = \
chvt  \
@@ -144,7 +154,8 @@ MAN8 = \
umount.8
 
 LIBUTILOBJ = $(LIBUTILSRC:.c=.o)
-OBJ = $(BIN:=.o) $(LIBUTILOBJ)
+LIBTERMINFOOBJ = $(LIBTERMINFOSRC:.c=.o)
+OBJ = $(BIN:=.o) $(LIBUTILOBJ) $(LIBTERMINFOOBJ)
 SRC = $(BIN:=.c)
 
 all: $(BIN)
@@ -166,6 +177,13 @@ $(LIBUTIL): $(LIBUTILOBJ)
$(AR) rc $@ $?
$(RANLIB) $@
 
+$(LIBTERMINFOGENHDR):
+   cd libterminfo && $(MAKE) $(MAKEFLAGS)
+
+$(LIBTERMINFO): $(LIBTERMINFOGENHDR) $(LIBTERMINFOOBJ)
+   $(AR) rc $@ $?
+   $(RANLIB) $@
+
 install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
@@ -221,7 +239,7 @@ ubase-box-install: ubase-box
cd $(DESTDIR)$(MANPREFIX)/man8 && chmod 644 $(MAN8)
 
 clean:
-   rm -f $(BIN) $(OBJ) $(LIB) ubase-box ubase-$(VERSION).tar.gz
+   rm -f $(BIN) $(OBJ) $(LIB) $(LIBTERMINFOGENHDR) ubase-box 
ubase-$(VERSION).tar.gz
 
 .PHONY:
all install uninstall dist ubase-box ubase-box-install clean
diff --git a/libterminfo/Makefile b/libterminfo/Makefile
new file mode 100644
index 000..0fff6ab
--- /dev/null
+++ b/libterminfo/Makefile
@@ -0,0 +1,10 @@
+all: damned-caps.h damned-capsutil.h
+
+damned-caps.h: mkcaps.h.awk
+   rm -f $@
+   awk -f $< -v caps=1 ncurses-5.9/Caps >>$@
+   awk -f $< -v caps=0 ncurses-5.9/Caps >>$@
+
+damned-capsutil.h: mkcapsutil.h.awk
+   rm -f $@
+   awk -f $< ncurses-5.9/Caps >$@
diff --git a/libterminfo/mkcaps.h.awk b/libterminfo/mkcaps.h.awk
new file mode 100644
index 000..77d1bde
--- /dev/null
+++ b/libterminfo/mkcaps.h.awk
@@ -0,0 +1,22 @@
+#!/usr/bin/env awk
+
+BEGIN {
+   print "typedef enum {"
+}
+
+/^# %%-STOP-HERE-%%$/ { exit }
+/^#/ { next }
+caps {
+   print "\tTI_" $2 ","
+}
+!caps && $1 != $2 {
+   print "\tTI_" $1 " = TI_" $2 ","
+}
+
+END {
+   if (caps) {
+   print "} Capname;"
+   } else {
+   print "} Capvarname;"
+   }
+}
diff --git a/libterminfo/mkcapsutil.h.awk b/libterminfo/mkcapsutil.h.awk
new file mode 100644
index 000..0d75205
--- /dev/null
+++ b/libterminfo/mkcapsutil.h.awk
@@ -0,0 +1,42 @@
+#!/usr/bin/env awk
+
+BEGIN {
+   fbool = ""
+   lbool = ""
+   fnum  = ""
+   lnum  = ""
+   fstr  = ""
+   lstr  = ""
+}
+
+/^# %%-STOP-HERE-%%$/ { exit }
+/^#/ { next }
+{
+   if ($3 == "bool") {
+   if (fbool == "") {
+   fbool = $2
+   print "#define FIRSTBOOL TI_" fbool
+   }
+   lbool = $2
+   }
+   if ($3 == "num") {
+   if (fnum == "") {
+   fnum = $2
+   print "#define LASTBOOL  TI_" lbool
+   print "#define FIRSTNUM  TI_" fnum
+   }
+   lnum = $2
+   }
+   if ($3 == "str") {
+   if (fstr == "") {
+   fstr = $2
+   print "#define LASTNUM   TI_" lnum
+   print "#define FIRSTSTR  TI_" fstr
+   }
+   lstr = $2
+   }
+}
+
+END {
+   print "#define LASTSTR   TI_" lstr

[hackers][ubase][tput] tput(1)

2016-05-22 Thread Lucas Gabriel Vuotto
Hello suckless,

attached you will find two patches, one implementing a basic library for dealing
with terminfo capabilities and another implementing the tput command using that
library. The library itself is part of a bigger library from me, damned [0], for
TUI creation.

The library is work in progress, so it can be a little sucky or bloated at times
(after all, the terminal's world sucks), plus it may have some bugs. Found a lot
implementing tput and there are already plans for doing some things better. Any
feedback or suggestions are welcome.

It lacks a manpage. I might do one in the following weeks, but if there is any
candidate to do it, he/she will be welcome.

Hope it's useful for you guys, keep rockin'.

Cheers.

--

[0]: https://gitlab.com/lv/damned.git


-- lv.




[hackers] [PATCH 2/2] Add tput(1)

2016-05-22 Thread Lucas Gabriel Vuotto
Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 Makefile|   1 +
 TODO|   2 +-
 libterminfo/Makefile|   6 +-
 libterminfo/mkcapstbl.h.awk |  19 +++
 tput.c  | 134 
 5 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 libterminfo/mkcapstbl.h.awk
 create mode 100644 tput.c

diff --git a/Makefile b/Makefile
index c639d69..54b02ad 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,7 @@ BIN = \
swapon\
switch_root   \
sysctl\
+   tput  \
truncate  \
umount\
unshare   \
diff --git a/TODO b/TODO
index 21f5c20..3ef3e31 100644
--- a/TODO
+++ b/TODO
@@ -26,7 +26,6 @@ setcap
 tabs
 taskset
 top
-tput
 vmstat
 
 Misc
@@ -34,3 +33,4 @@ Misc
 
 Beautify passwd(1).
 last(1) manpage.
+tput(1) manpage.
diff --git a/libterminfo/Makefile b/libterminfo/Makefile
index 0fff6ab..ad55688 100644
--- a/libterminfo/Makefile
+++ b/libterminfo/Makefile
@@ -1,4 +1,4 @@
-all: damned-caps.h damned-capsutil.h
+all: damned-caps.h damned-capsutil.h capstbl.h
 
 damned-caps.h: mkcaps.h.awk
rm -f $@
@@ -8,3 +8,7 @@ damned-caps.h: mkcaps.h.awk
 damned-capsutil.h: mkcapsutil.h.awk
rm -f $@
awk -f $< ncurses-5.9/Caps >$@
+
+capstbl.h: mkcapstbl.h.awk
+   rm -f $@
+   awk -f $< ncurses-5.9/Caps >$@
diff --git a/libterminfo/mkcapstbl.h.awk b/libterminfo/mkcapstbl.h.awk
new file mode 100644
index 000..57925ca
--- /dev/null
+++ b/libterminfo/mkcapstbl.h.awk
@@ -0,0 +1,19 @@
+#!/usr/bin/env awk
+
+BEGIN {
+   print "static struct {"
+   print "\tconst char *name;"
+   print "\tconst char *varname;"
+   print "\tCapname cn;"
+   print "} tbl[] = {"
+}
+
+/^# %%-STOP-HERE-%%$/ { exit }
+/^#/ { next }
+{
+   print "\t{ \"" $2 "\", \"" $1 "\", TI_" $2 " },"
+}
+
+END {
+   print "};"
+}
diff --git a/tput.c b/tput.c
new file mode 100644
index 000..21e96de
--- /dev/null
+++ b/tput.c
@@ -0,0 +1,134 @@
+/* See LICENSE file for copyright and license details. */
+#include 
+#include 
+#include 
+
+#include "terminfo.h"
+#include "util.h"
+
+/* needs libterminfo/caps.h, included from terminfo.h */
+#include "libterminfo/capstbl.h"
+
+static char *dummyargs[] = { NULL };
+static char *params[9];
+
+static int
+docap(int cap, char **p)
+{
+   char *o;
+   size_t l;
+   int i, r = 0;
+
+   for (i = 0; p[i]; i++)
+   params[i] = p[i];
+   for (; i < 9; i++);
+   params[i] = NULL;
+
+   o = tparse(cap,
+  params[0], params[1], params[2],
+  params[3], params[4], params[5],
+  params[6], params[7], params[8]);
+   if (!o)
+   return -2;
+   l = strlen(o);
+   if (fwrite(o, sizeof(char), l, stdout) != l)
+   r = -1;
+   free(o);
+
+   return r;
+}
+
+static void
+doclear(void)
+{
+   docap(TI_clear, dummyargs);
+}
+
+static void
+doinit(void)
+{
+   /* TODO: do something about iprog and if */
+   docap(TI_is1, dummyargs);
+   docap(TI_is2, dummyargs);
+   docap(TI_mgc, dummyargs);
+   docap(TI_smgl, dummyargs);
+   docap(TI_smgr, dummyargs);
+   docap(TI_tbc, dummyargs);
+   docap(TI_hts, dummyargs);
+   docap(TI_is3, dummyargs);
+}
+
+static void
+doreset(void)
+{
+   if (docap(TI_rs1, dummyargs) < 0)
+   docap(TI_is1, dummyargs);
+   if (docap(TI_rs2, dummyargs) < 0)
+   docap(TI_is2, dummyargs);
+   docap(TI_mgc, dummyargs);
+   docap(TI_smgl, dummyargs);
+   docap(TI_smgr, dummyargs);
+   docap(TI_tbc, dummyargs);
+   docap(TI_hts, dummyargs);
+   if (docap(TI_rs3, dummyargs) < 0)
+   docap(TI_is3, dummyargs);
+}
+
+static void
+usage(void)
+{
+   eprintf("usage: %s [-T term] <clear|init|reset|cap> [capargs...]\n", 
argv0);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+   char *term = NULL;
+   int cap = -1, i;
+
+   ARGBEGIN {
+   case 'T':
+   term = EARGF(usage());
+   if (setenv("TERM", term, 1) < 0)
+   eprintf("couldn't change terminal type\n", argv0);
+   break;
+   default:
+   usage();
+   } ARGEND;
+
+   if (argc == 0)
+   usage();
+
+   if (setupterminfo() < 0)
+   enprintf(3, "couldn't init terminfo\n");
+
+   if (!strcmp("clear", *argv)) {
+   doclear();
+   return 0;
+   } else if (!strcmp("init", *argv)) {
+   doinit();
+   re

[hackers] [scc][cc2-qbe][PATCH] Fix typo in variable name

2016-04-13 Thread Lucas Gabriel Vuotto




-- lv.
>From 45ca336d96e496c4a431c758868ff802190d5adb Mon Sep 17 00:00:00 2001
From: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
Date: Wed, 13 Apr 2016 10:46:38 -0300
Subject: [PATCH] Fix typo in variable name

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 cc2/arch/qbe/cgen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index e01e716..2882be5 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -156,7 +156,7 @@ sethi(Node *np)
 	if (np->address > 10)
 		return np;
 	if (lp)
-		rp->complex = lp->complex;
+		np->complex = lp->complex;
 	if (rp) {
 		int d = np->complex - rp->complex;
 
-- 
1.9.1



Re: [hackers] [sbase][PATCH] Add nologin(8) (from ubase) and simplify it

2016-04-04 Thread Lucas Gabriel Vuotto



On 04/04/16 08:22, Mattias Andrée wrote:

Signed-off-by: Mattias Andrée 
---
 Makefile | 124 +++
 config.def.h |   1 +
 nologin.8|  21 ++
 nologin.c|  19 +
 4 files changed, 158 insertions(+), 7 deletions(-)
 create mode 100644 config.def.h
 create mode 100644 nologin.8
 create mode 100644 nologin.c

diff --git a/Makefile b/Makefile
index 6b2bfdf..5e611ee 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ include config.mk
 HDR =\
arg.h\
compat.h\
+   config.h\
crypt.h\
fs.h\
md5.h\
@@ -129,6 +130,7 @@ BIN =\
nice\
nl\
nohup\
+   nologin\
od\
pathchk\
paste\
@@ -179,11 +181,109 @@ BIN =\
xinstall\
yes

+MAN1 =\
+   basename.1\
+   cal.1\
+   cat.1\
+   chgrp.1\
+   chmod.1\
+   chown.1\
+   chroot.1\
+   cksum.1\
+   cmp.1\
+   cols.1\
+   comm.1\
+   cp.1\
+   cron.1\
+   cut.1\
+   date.1\
+   dirname.1\
+   du.1\
+   echo.1\
+   ed.1\
+   env.1\
+   expand.1\
+   expr.1\
+   false.1\
+   find.1\
+   flock.1\
+   fold.1\
+   getconf.1\
+   grep.1\
+   head.1\
+   join.1\
+   hostname.1\
+   kill.1\
+   link.1\
+   ln.1\
+   logger.1\
+   logname.1\
+   ls.1\
+   md5sum.1\
+   mkdir.1\
+   mkfifo.1\
+   mktemp.1\
+   mv.1\
+   nice.1\
+   nl.1\
+   nohup.1\
+   od.1\
+   pathchk.1\
+   paste.1\
+   printenv.1\
+   printf.1\
+   pwd.1\
+   readlink.1\
+   renice.1\
+   rm.1\
+   rmdir.1\
+   sed.1\
+   seq.1\
+   setsid.1\
+   sha1sum.1\
+   sha224sum.1\
+   sha256sum.1\
+   sha384sum.1\
+   sha512sum.1\
+   sha512-224sum.1\
+   sha512-256sum.1\
+   sleep.1\
+   sort.1\
+   split.1\
+   sponge.1\
+   strings.1\
+   sync.1\
+   tail.1\
+   tar.1\
+   tee.1\
+   test.1\
+   tftp.1\
+   time.1\
+   touch.1\
+   tr.1\
+   true.1\
+   tsort.1\
+   tty.1\
+   uname.1\
+   unexpand.1\
+   uniq.1\
+   unlink.1\
+   uudecode.1\
+   uuencode.1\
+   wc.1\
+   which.1\
+   whoami.1\
+   xargs.1\
+   xinstall.1\
+   yes.1
+
+MAN8 =\
+   nologin.8
+
 LIBUTFOBJ = $(LIBUTFSRC:.c=.o)
 LIBUTILOBJ = $(LIBUTILSRC:.c=.o)
 OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ)
 SRC = $(BIN:=.c)
-MAN = $(BIN:=.1)

 all: $(BIN)

@@ -191,6 +291,9 @@ $(BIN): $(LIB) $(@:=.o)

 $(OBJ): $(HDR) config.mk

+config.h:
+   cp config.def.h $@
+
 .o:
$(CC) $(LDFLAGS) -o $@ $< $(LIB)

@@ -216,17 +319,21 @@ install: all
cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN)
mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
-   for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > 
$(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
-   cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
+   mkdir -p $(DESTDIR)$(MANPREFIX)/man8
+   for m in $(MAN1); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > 
$(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
+   for m in $(MAN8); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > 
$(DESTDIR)$(MANPREFIX)/man8/"$$m"; done
+   cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN1)
+   cd $(DESTDIR)$(MANPREFIX)/man8 && chmod 644 $(MAN8)
mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 
$(DESTDIR)$(MANPREFIX)/man1/install.1

 uninstall:
cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) [ install
-   cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN)
+   cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN1)
+   cd $(DESTDIR)$(MANPREFIX)/man8 && rm -f $(MAN8)

 dist: clean
mkdir -p sbase-$(VERSION)
-   cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN) libutf 
libutil $(HDR) sbase-$(VERSION)
+   cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN1) $(MAN8) 
libutf libutil $(HDR) config.def.h sbase-$(VERSION)
tar -cf sbase-$(VERSION).tar sbase-$(VERSION)
gzip sbase-$(VERSION).tar
rm -rf sbase-$(VERSION)
@@ -261,8 +368,11 @@ sbase-box-install: sbase-box
ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/[
mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
-   for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > 
$(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
-   cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
+   mkdir -p $(DESTDIR)$(MANPREFIX)/man8
+   for m in $(MAN1); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > 
$(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
+   for m in $(MAN8); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < 

[hackers][ubase][PATCH] arg.h: fixed argv checks order

2016-02-22 Thread Lucas Gabriel Vuotto
This prevents accessing to a potentially out-of-bounds memory section.

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 arg.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arg.h b/arg.h
index 4df77a7..aeab52a 100644
--- a/arg.h
+++ b/arg.h
@@ -10,8 +10,8 @@ extern char *argv0;
 
 /* use main(int argc, char *argv[]) */
 #define ARGBEGIN   for (argv0 = *argv, argv++, argc--;\
-   argv[0] && argv[0][1]\
-   && argv[0][0] == '-';\
+   argv[0] && argv[0][0] == '-'\
+   && argv[0][1];\
argc--, argv++) {\
char argc_;\
char **argv_;\
-- 
2.4.10




[hackers][sbase][PATCH] arg.h: fixed argv checks order

2016-02-19 Thread Lucas Gabriel Vuotto

Hello,

this is a small fix for arg.h where it's possible to perform an 
out-of-boundary memory access in argv's internal string. In particular, 
this is a fix for sbase's arg.h, but I've also seen it in st repo, and I 
suppose that this "bug" is present in all suckless' repo which uses arg.h .


Cheers.


-- lv.
>From 439ba086ea3163f91088deff5a87a6b46009c1ba Mon Sep 17 00:00:00 2001
From: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
Date: Fri, 19 Feb 2016 15:59:49 -0300
Subject: [hackers][sbase][PATCH] arg.h: fixed argv checks order
To: hackers@suckless.org

This prevents accessing to a potentially out-of-bounds memory section.

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 arg.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arg.h b/arg.h
index de6ce94..0b23c53 100644
--- a/arg.h
+++ b/arg.h
@@ -10,8 +10,8 @@ extern char *argv0;
 
 /* use main(int argc, char *argv[]) */
 #define ARGBEGIN	for (argv0 = *argv, argv++, argc--;\
-	argv[0] && argv[0][1]\
-	&& argv[0][0] == '-';\
+	argv[0] && argv[0][0] == '-'\
+	&& argv[0][1];\
 	argc--, argv++) {\
 char argc_;\
 char **argv_;\
-- 
1.9.1



[hackers] [tabbed][PATCH] Xft support

2016-02-13 Thread Lucas Gabriel Vuotto

Hello,

I rebased the xft patch for tabbed from the wiki to the current HEAD. I 
was on my way to push it to the wiki again, but I wondered why it 
haven't been merged to mainstream. Is there a reason for not doing it?


Cheers.


-- lv.
diff --git a/config.def.h b/config.def.h
index 9facec5..989992c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,7 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 
 /* appearance */
-static const char font[]= "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*";
+static const char font[]= "monospace:size=9";
 static const char* normbgcolor  = "#22";
 static const char* normfgcolor  = "#cc";
 static const char* selbgcolor   = "#55";
diff --git a/config.mk b/config.mk
index 441b2de..3a71529 100644
--- a/config.mk
+++ b/config.mk
@@ -8,8 +8,8 @@ PREFIX = /usr/local
 MANPREFIX = ${PREFIX}/share/man
 
 # includes and libs
-INCS = -I. -I/usr/include
-LIBS = -L/usr/lib -lc -lX11
+INCS = -I. -I/usr/include -I/usr/include/freetype2
+LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft
 
 # flags
 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
diff --git a/tabbed.c b/tabbed.c
index eafbec8..a9050ae 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "arg.h"
 
@@ -64,17 +65,16 @@ typedef struct {
 
 typedef struct {
int x, y, w, h;
-   unsigned long norm[ColLast];
-   unsigned long sel[ColLast];
-   unsigned long urg[ColLast];
+   XftColor norm[ColLast];
+   XftColor sel[ColLast];
+   XftColor urg[ColLast];
Drawable drawable;
GC gc;
struct {
int ascent;
int descent;
int height;
-   XFontSet set;
-   XFontStruct *xfont;
+   XftFont *xfont;
} font;
 } DC; /* draw context */
 
@@ -96,7 +96,7 @@ static void createnotify(const XEvent *e);
 static void destroynotify(const XEvent *e);
 static void die(const char *errstr, ...);
 static void drawbar(void);
-static void drawtext(const char *text, unsigned long col[ColLast]);
+static void drawtext(const char *text, XftColor col[ColLast]);
 static void *ecalloc(size_t n, size_t size);
 static void *erealloc(void *o, size_t size);
 static void expose(const XEvent *e);
@@ -107,7 +107,7 @@ static void focusurgent(const Arg *arg);
 static void fullscreen(const Arg *arg);
 static char *getatom(int a);
 static int getclient(Window w);
-static unsigned long getcolor(const char *colstr);
+static XftColor getcolor(const char *colstr);
 static int getfirsttab(void);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void initfont(const char *fontstr);
@@ -223,11 +223,6 @@ cleanup(void)
free(clients);
clients = NULL;
 
-   if (dc.font.set)
-   XFreeFontSet(dpy, dc.font.set);
-   else
-   XFreeFont(dpy, dc.font.xfont);
-
XFreePixmap(dpy, dc.drawable);
XFreeGC(dpy, dc.gc);
XDestroyWindow(dpy, win);
@@ -314,7 +309,7 @@ die(const char *errstr, ...)
 void
 drawbar(void)
 {
-   unsigned long *col;
+   XftColor *col;
int c, cc, fc, width;
char *name = NULL;
 
@@ -367,13 +362,14 @@ drawbar(void)
 }
 
 void
-drawtext(const char *text, unsigned long col[ColLast])
+drawtext(const char *text, XftColor col[ColLast])
 {
int i, j, x, y, h, len, olen;
char buf[256];
+   XftDraw *d;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
 
-   XSetForeground(dpy, dc.gc, col[ColBG]);
+   XSetForeground(dpy, dc.gc, col[ColBG].pixel);
XFillRectangles(dpy, dc.drawable, dc.gc, , 1);
if (!text)
return;
@@ -397,12 +393,9 @@ drawtext(const char *text, unsigned long col[ColLast])
;
}
 
-   XSetForeground(dpy, dc.gc, col[ColFG]);
-   if (dc.font.set)
-   XmbDrawString(dpy, dc.drawable, dc.font.set,
- dc.gc, x, y, buf, len);
-   else
-   XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
+   d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), 
DefaultColormap(dpy, screen));
+   XftDrawStringUtf8(d, [ColFG], dc.font.xfont, x, y, (XftChar8 *) 
buf, len);
+   XftDrawDestroy(d);
 }
 
 void *
@@ -560,16 +553,15 @@ getclient(Window w)
return -1;
 }
 
-unsigned long
+XftColor
 getcolor(const char *colstr)
 {
-   Colormap cmap = DefaultColormap(dpy, screen);
-   XColor color;
+   XftColor color;
 
-   if (!XAllocNamedColor(dpy, cmap, colstr, , ))
+   if (!XftColorAllocName(dpy, DefaultVisual(dpy, screen), 
DefaultColormap(dpy, screen), colstr, ))
die("%s: cannot allocate color '%s'\n", argv0, colstr);
 
-   return color.pixel;
+   return color;
 }
 
 int
@@ -621,42 +613,12 @@ gettextprop(Window w, Atom atom, char *text, unsigned int 
size)
 void
 initfont(const char *fontstr)
 {
-   char *def, 

Re: [hackers][tabbed][PATCH] Added xft support

2016-02-13 Thread Lucas Gabriel Vuotto

I forgot tabbed in the subject :p

On 13/02/16 18:42, Lucas Gabriel Vuotto wrote:

Based on xft tabbed patch from the wiki.

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 config.def.h |  2 +-
 config.mk|  4 +--
 tabbed.c | 99 +---
 3 files changed, 30 insertions(+), 75 deletions(-)

diff --git a/config.def.h b/config.def.h
index 9facec5..989992c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,7 +1,7 @@
 /* See LICENSE file for copyright and license details. */

 /* appearance */
-static const char font[]= "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*";
+static const char font[]= "monospace:size=9";
 static const char* normbgcolor  = "#22";
 static const char* normfgcolor  = "#cc";
 static const char* selbgcolor   = "#55";
diff --git a/config.mk b/config.mk
index 441b2de..3a71529 100644
--- a/config.mk
+++ b/config.mk
@@ -8,8 +8,8 @@ PREFIX = /usr/local
 MANPREFIX = ${PREFIX}/share/man

 # includes and libs
-INCS = -I. -I/usr/include
-LIBS = -L/usr/lib -lc -lX11
+INCS = -I. -I/usr/include -I/usr/include/freetype2
+LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft

 # flags
 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
diff --git a/tabbed.c b/tabbed.c
index eafbec8..a9050ae 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 

 #include "arg.h"

@@ -64,17 +65,16 @@ typedef struct {

 typedef struct {
int x, y, w, h;
-   unsigned long norm[ColLast];
-   unsigned long sel[ColLast];
-   unsigned long urg[ColLast];
+   XftColor norm[ColLast];
+   XftColor sel[ColLast];
+   XftColor urg[ColLast];
Drawable drawable;
GC gc;
struct {
int ascent;
int descent;
int height;
-   XFontSet set;
-   XFontStruct *xfont;
+   XftFont *xfont;
} font;
 } DC; /* draw context */

@@ -96,7 +96,7 @@ static void createnotify(const XEvent *e);
 static void destroynotify(const XEvent *e);
 static void die(const char *errstr, ...);
 static void drawbar(void);
-static void drawtext(const char *text, unsigned long col[ColLast]);
+static void drawtext(const char *text, XftColor col[ColLast]);
 static void *ecalloc(size_t n, size_t size);
 static void *erealloc(void *o, size_t size);
 static void expose(const XEvent *e);
@@ -107,7 +107,7 @@ static void focusurgent(const Arg *arg);
 static void fullscreen(const Arg *arg);
 static char *getatom(int a);
 static int getclient(Window w);
-static unsigned long getcolor(const char *colstr);
+static XftColor getcolor(const char *colstr);
 static int getfirsttab(void);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void initfont(const char *fontstr);
@@ -223,11 +223,6 @@ cleanup(void)
free(clients);
clients = NULL;

-   if (dc.font.set)
-   XFreeFontSet(dpy, dc.font.set);
-   else
-   XFreeFont(dpy, dc.font.xfont);
-
XFreePixmap(dpy, dc.drawable);
XFreeGC(dpy, dc.gc);
XDestroyWindow(dpy, win);
@@ -314,7 +309,7 @@ die(const char *errstr, ...)
 void
 drawbar(void)
 {
-   unsigned long *col;
+   XftColor *col;
int c, cc, fc, width;
char *name = NULL;

@@ -367,13 +362,14 @@ drawbar(void)
 }

 void
-drawtext(const char *text, unsigned long col[ColLast])
+drawtext(const char *text, XftColor col[ColLast])
 {
int i, j, x, y, h, len, olen;
char buf[256];
+   XftDraw *d;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };

-   XSetForeground(dpy, dc.gc, col[ColBG]);
+   XSetForeground(dpy, dc.gc, col[ColBG].pixel);
XFillRectangles(dpy, dc.drawable, dc.gc, , 1);
if (!text)
return;
@@ -397,12 +393,9 @@ drawtext(const char *text, unsigned long col[ColLast])
;
}

-   XSetForeground(dpy, dc.gc, col[ColFG]);
-   if (dc.font.set)
-   XmbDrawString(dpy, dc.drawable, dc.font.set,
- dc.gc, x, y, buf, len);
-   else
-   XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
+   d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), 
DefaultColormap(dpy, screen));
+   XftDrawStringUtf8(d, [ColFG], dc.font.xfont, x, y, (XftChar8 *) 
buf, len);
+   XftDrawDestroy(d);
 }

 void *
@@ -560,16 +553,15 @@ getclient(Window w)
return -1;
 }

-unsigned long
+XftColor
 getcolor(const char *colstr)
 {
-   Colormap cmap = DefaultColormap(dpy, screen);
-   XColor color;
+   XftColor color;

-   if (!XAllocNamedColor(dpy, cmap, colstr, , ))
+   if (!XftColorAllocName(dpy, DefaultVisual(dpy, screen), 
DefaultColormap(dpy, screen), colstr, ))
die("%s: cannot allocate color '%s'\n", argv0, colstr);

- 

[hackers] [PATCH] Added xft support

2016-02-13 Thread Lucas Gabriel Vuotto
Based on xft tabbed patch from the wiki.

Signed-off-by: Lucas Gabriel Vuotto <l.vuott...@gmail.com>
---
 config.def.h |  2 +-
 config.mk|  4 +--
 tabbed.c | 99 +---
 3 files changed, 30 insertions(+), 75 deletions(-)

diff --git a/config.def.h b/config.def.h
index 9facec5..989992c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,7 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 
 /* appearance */
-static const char font[]= "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*";
+static const char font[]= "monospace:size=9";
 static const char* normbgcolor  = "#22";
 static const char* normfgcolor  = "#cc";
 static const char* selbgcolor   = "#55";
diff --git a/config.mk b/config.mk
index 441b2de..3a71529 100644
--- a/config.mk
+++ b/config.mk
@@ -8,8 +8,8 @@ PREFIX = /usr/local
 MANPREFIX = ${PREFIX}/share/man
 
 # includes and libs
-INCS = -I. -I/usr/include
-LIBS = -L/usr/lib -lc -lX11
+INCS = -I. -I/usr/include -I/usr/include/freetype2
+LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft
 
 # flags
 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
diff --git a/tabbed.c b/tabbed.c
index eafbec8..a9050ae 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "arg.h"
 
@@ -64,17 +65,16 @@ typedef struct {
 
 typedef struct {
int x, y, w, h;
-   unsigned long norm[ColLast];
-   unsigned long sel[ColLast];
-   unsigned long urg[ColLast];
+   XftColor norm[ColLast];
+   XftColor sel[ColLast];
+   XftColor urg[ColLast];
Drawable drawable;
GC gc;
struct {
int ascent;
int descent;
int height;
-   XFontSet set;
-   XFontStruct *xfont;
+   XftFont *xfont;
} font;
 } DC; /* draw context */
 
@@ -96,7 +96,7 @@ static void createnotify(const XEvent *e);
 static void destroynotify(const XEvent *e);
 static void die(const char *errstr, ...);
 static void drawbar(void);
-static void drawtext(const char *text, unsigned long col[ColLast]);
+static void drawtext(const char *text, XftColor col[ColLast]);
 static void *ecalloc(size_t n, size_t size);
 static void *erealloc(void *o, size_t size);
 static void expose(const XEvent *e);
@@ -107,7 +107,7 @@ static void focusurgent(const Arg *arg);
 static void fullscreen(const Arg *arg);
 static char *getatom(int a);
 static int getclient(Window w);
-static unsigned long getcolor(const char *colstr);
+static XftColor getcolor(const char *colstr);
 static int getfirsttab(void);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void initfont(const char *fontstr);
@@ -223,11 +223,6 @@ cleanup(void)
free(clients);
clients = NULL;
 
-   if (dc.font.set)
-   XFreeFontSet(dpy, dc.font.set);
-   else
-   XFreeFont(dpy, dc.font.xfont);
-
XFreePixmap(dpy, dc.drawable);
XFreeGC(dpy, dc.gc);
XDestroyWindow(dpy, win);
@@ -314,7 +309,7 @@ die(const char *errstr, ...)
 void
 drawbar(void)
 {
-   unsigned long *col;
+   XftColor *col;
int c, cc, fc, width;
char *name = NULL;
 
@@ -367,13 +362,14 @@ drawbar(void)
 }
 
 void
-drawtext(const char *text, unsigned long col[ColLast])
+drawtext(const char *text, XftColor col[ColLast])
 {
int i, j, x, y, h, len, olen;
char buf[256];
+   XftDraw *d;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
 
-   XSetForeground(dpy, dc.gc, col[ColBG]);
+   XSetForeground(dpy, dc.gc, col[ColBG].pixel);
XFillRectangles(dpy, dc.drawable, dc.gc, , 1);
if (!text)
return;
@@ -397,12 +393,9 @@ drawtext(const char *text, unsigned long col[ColLast])
;
}
 
-   XSetForeground(dpy, dc.gc, col[ColFG]);
-   if (dc.font.set)
-   XmbDrawString(dpy, dc.drawable, dc.font.set,
- dc.gc, x, y, buf, len);
-   else
-   XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
+   d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), 
DefaultColormap(dpy, screen));
+   XftDrawStringUtf8(d, [ColFG], dc.font.xfont, x, y, (XftChar8 *) 
buf, len);
+   XftDrawDestroy(d);
 }
 
 void *
@@ -560,16 +553,15 @@ getclient(Window w)
return -1;
 }
 
-unsigned long
+XftColor
 getcolor(const char *colstr)
 {
-   Colormap cmap = DefaultColormap(dpy, screen);
-   XColor color;
+   XftColor color;
 
-   if (!XAllocNamedColor(dpy, cmap, colstr, , ))
+   if (!XftColorAllocName(dpy, DefaultVisual(dpy, screen), 
DefaultColormap(dpy, screen), colstr, ))
die("%s: cannot allocate color '%s'\n", argv0, colstr);
 
-   return color.pixel;
+   return color;
 }
 
 int
@@ -621,42 +613,