Re: Trying to compile cwm on Linux

2008-08-01 Thread Martin Toft
On Thu, Jul 24, 2008 at 10:35:36PM +0200, Martin Toft wrote:
 On Thu, Jul 24, 2008 at 02:20:22PM -0600, Theo de Raadt wrote:
  +#define strlcpy(dst, src, size) (strncpy((dst), (src), (size) - 1))
  +#define strlcat(dst, src, size) (strncat((dst), (src), (size) - 1))
  
  That is utterly and completely wrong.  
 
 Yep, I'm a noob when it comes to these kinds of things. I'll look into
 it.

And so I did. Travelling and other work delayed me though.

The result: http://martintoft.dk/?p=cwm

Martin



Re: Trying to compile cwm on Linux

2008-07-24 Thread Martin Toft
On Wed, Jul 23, 2008 at 10:55:01PM +0200, Martin Toft wrote:
 I'm trying to compile cwm (/usr/xenocara/app/cwm) on Linux, as I would
 like to use this very supreme window manager on all my non-OpenBSD
 systems as well. The version of cwm that I'm working with is from
 yesterday's -current (23rd of July, 2008). The Linux distribution is
 Ubuntu Feisty.
[..]

oga@ and jsg@ pointed me to byacc - thanks! There is some yacc specific
constructs in cwm's parser that bison doesn't support.

To address the mail from [EMAIL PROTECTED]: I think this _is_
OpenBSD related (opposed to Linux related), as there might be other
OpenBSD users, like me, who want to use cwm on their non-OpenBSD boxes
as well, and Linux-only users hardly know about the cwm in OpenBSD.

The following is an attempt to make a simple guide.


OpenBSD's cwm window manager on Ubuntu Linux


1. Install the following packages:

   byacclibxext-dev
   libexpat1-devlibxft-dev
   libfontconfig1-dev   libxrender-dev
   libxau-dev   xlibs-dev
   libxdmcp-dev zlib1g-dev

   You might also need to install cvs and xterm (xterm is the default
   terminal for cwm to start when one types ctrl+alt+enter).

2. Pick an anonymous CVS server close to you:
   http://www.openbsd.org/anoncvs.html#CVSROOT

3. Checkout cwm as of July 24, 2008:

   $ export CVSROOT=(what you picked in step 2)
   $ cvs -q -d$CVSROOT checkout -D 2008-07-24 xenocara/app/cwm
   U xenocara/app/cwm/LICENSE
   U xenocara/app/cwm/Makefile
   [..]
   U xenocara/app/cwm/xmalloc.c
   U xenocara/app/cwm/xutil.c
   $ cd xenocara/app/cwm

4. Patch the source using cwm-linux.patch (attached inline further
   down):

   $ patch  cwm-linux.patch
   patching file calmwm.c
   patching file calmwm.h
   patching file conf.c
   patching file headers.h
   patching file kbfunc.c
   patching file parse.y

5. Generate the parser using byacc:

   $ byacc -d parse.y 
   $ mv y.tab.c parse.c

6. Compile and link:

   $ for i in *.c; do gcc -I /usr/include/freetype2 -c $i; done
   $ gcc -lXft -lXrender -lX11 -lXau -lXdmcp -lXext -lfontconfig -lexpat 
-lfreetype -lz -o cwm *.o

7. Enjoy:

   $ ls -l cwm
   -rwxr-xr-x 1 mt mt 83963 2008-07-24 21:21 cwm


Corrections and flames are most welcome :-)

Martin


cwm-linux.patch:

--- calmwm.c.orig   2008-07-23 15:25:38.0 +0200
+++ calmwm.c2008-07-23 15:25:51.0 +0200
@@ -317,7 +317,7 @@
errno = save_errno;
 }
 
-__dead void
+void
 usage(void)
 {
extern char *__progname;
--- calmwm.h.orig   2008-07-23 15:25:30.0 +0200
+++ calmwm.h2008-07-23 15:25:45.0 +0200
@@ -312,7 +312,7 @@
 voidx_setup(void);
 char   *x_screenname(int);
 voidx_setupscreen(struct screen_ctx *, u_int);
-__dead void usage(void);
+voidusage(void);
 
 struct client_ctx  *client_find(Window);
 voidclient_setup(void);
--- conf.c.orig 2008-07-24 18:20:14.0 +0200
+++ conf.c  2008-07-24 18:37:49.0 +0200
@@ -464,9 +464,9 @@
if (strchr(name, '-') == NULL)
substring = name;
 
-   current_binding-button = strtonum(substring, 1, 3, errstr);
-   if (errstr)
-   warnx(number of buttons is %s: %s, errstr, substring);
+   current_binding-button = strtoll(substring, NULL, 10);
+   if (errno || current_binding-button  1 || current_binding-button  3)
+   warn(invalid number or out of range: %s, substring);
 
conf_mouseunbind(c, current_binding);
 
--- headers.h.orig  2008-07-24 16:52:46.0 +0200
+++ headers.h   2008-07-24 19:08:23.0 +0200
@@ -52,4 +52,8 @@
 
 #include err.h
 
+#define strlcpy(dst, src, size) (strncpy((dst), (src), (size) - 1))
+#define strlcat(dst, src, size) (strncat((dst), (src), (size) - 1))
+#define TAILQ_END(head) NULL
+
 #endif /* _CALMWM_HEADERS_H_ */
--- kbfunc.c.orig   2008-07-24 19:04:56.0 +0200
+++ kbfunc.c2008-07-24 19:04:15.0 +0200
@@ -345,7 +345,7 @@
FILE*fp;
char*buf, *lbuf, *p, *home;
char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN];
-   char cmd[256];
+   char cmd[256], buffer[1024];
int  l;
size_t   len;
 
@@ -361,7 +361,9 @@
 
TAILQ_INIT(menuq);
lbuf = NULL;
-   while ((buf = fgetln(fp, len))) {
+   while (!feof(fp)) {
+   buf = fgets(buffer, sizeof(buffer), fp);
+   len = strlen(buf);
if (buf[len - 1] == '\n')
buf[len - 1] = '\0';
else {
--- parse.y.orig2008-07-23 15:44:14.0 +0200
+++ parse.y 2008-07-24 18:31:47.0 +0200
@@ -379,11 +379,9 @@
const char *errstr = NULL;
 
*p = '\0';
-   

Re: Trying to compile cwm on Linux

2008-07-24 Thread Theo de Raadt
+#define strlcpy(dst, src, size) (strncpy((dst), (src), (size) - 1))
+#define strlcat(dst, src, size) (strncat((dst), (src), (size) - 1))

That is utterly and completely wrong.  



Re: Trying to compile cwm on Linux

2008-07-24 Thread Pierre-Yves Ritschard
 6. Compile and link:
 
$ for i in *.c; do gcc -I /usr/include/freetype2 -c $i; done
$ gcc -lXft -lXrender -lX11 -lXau -lXdmcp -lXext -lfontconfig -lexpat 
 -lfreetype -lz -o cwm *.o
 

Most linux distributions carry a pmake package which provides the
a bsd.prog.mk and thus support for the Makefiles distributed with
OpenBSD source code. It can come in handy.



Re: Trying to compile cwm on Linux

2008-07-24 Thread Marc Espie
On Thu, Jul 24, 2008 at 10:01:50PM +0200, Martin Toft wrote:
 +#define strlcpy(dst, src, size) (strncpy((dst), (src), (size) - 1))
 +#define strlcat(dst, src, size) (strncat((dst), (src), (size) - 1))

To be a bit more specific than Theo, don't believe idiots like Ulrich
Drepper.

There's a *reason* for strlcpy and strlcat.
strncpy and strncat are bogus. They're almost never the solution.

Accept no substitute.

On any lesser system (and that's mostly linux these days), you must ship
a copy of strlcat and strlcpy.

Fortunately the source code for these is small!

And it's free! 
nice licence! 
no obnoxious GPL!



Re: Trying to compile cwm on Linux

2008-07-24 Thread Martin Toft
On Thu, Jul 24, 2008 at 02:20:22PM -0600, Theo de Raadt wrote:
 +#define strlcpy(dst, src, size) (strncpy((dst), (src), (size) - 1))
 +#define strlcat(dst, src, size) (strncat((dst), (src), (size) - 1))
 
 That is utterly and completely wrong.  

Yep, I'm a noob when it comes to these kinds of things. I'll look into
it.



Re: Trying to compile cwm on Linux

2008-07-24 Thread Miod Vallat
 +#define strlcpy(dst, src, size) (strncpy((dst), (src), (size) - 1))
 +#define strlcat(dst, src, size) (strncat((dst), (src), (size) - 1))

strlcpy() and strlcat() return size_t. strncpy() and strncat() return
char *. These #define do not take care of this (among other things).