From 024bd1eb3df9865781113c6d57c9fc715e8f9a99 Mon Sep 17 00:00:00 2001
From: Christophe CURIS <[email protected]>
Date: Sat, 23 Jun 2012 19:49:52 +0200
Subject: [PATCH 10/10] Remove dependency to CPP: removed stuff related to CPP
 calls

Now that the built-in parser has support for all the feature of CPP
being used by WindowMaker's default menu, we can remove the stuff
related to calling CPP:
 - code for preparing and running CPP;
 - compile-time option to de-activate the call to CPP;
 - command-line option
---
 INSTALL-WMAKER    |    7 ++--
 Makefile.am       |    3 --
 configure.ac      |   27 ------------
 src/WindowMaker.h |    1 -
 src/funcs.h       |    4 --
 src/main.c        |   10 +----
 src/misc.c        |  118 -----------------------------------------------------
 src/rootmenu.c    |   71 +++-----------------------------
 src/wconfig.h.in  |    5 ---
 9 files changed, 12 insertions(+), 234 deletions(-)

diff --git a/INSTALL-WMAKER b/INSTALL-WMAKER
index 1c3f8e0..3dbf777 100644
--- a/INSTALL-WMAKER
+++ b/INSTALL-WMAKER
@@ -368,9 +368,10 @@ If you're not sure, try renaming ~/GNUstep to ~/GNUtmp and then run wmaker.inst
 
 == The root menu contains only 2 entries. ("XTerm" and "Exit...")
 
-* Window Maker is not finding cpp (the C preprocessor). If your cpp is
-not located in /lib/cpp, edit config.h and correct the path in
-CPP_PATH.
+* Window Maker could not read your menu definition file
+you should check wmaker's output for an error, it may be
+visible in the console or in the .xsession-errors file.
+
 
 == checking lex output file root... configure: error: cannot find output from true; giving up
 
diff --git a/Makefile.am b/Makefile.am
index c238d9c..f73e6cc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,9 +10,6 @@ config.h: config-paths.h
 
 config-paths.h: Makefile
 	@echo "Generating $@"
-	@echo '/* define to the path to cpp */' > $@
-	@echo '#define CPP_PATH "$(CPP_PATH)"' >> $@
-	@echo '' >> $@
 	@echo '/* gettext domain used for menu translations */' >> $@
 	@if test -z "$(menutextdomain)"; then \
 	  echo '/* #undef MENU_TEXTDOMAIN "$(menutextdomain)" */' >> $@; \
diff --git a/configure.ac b/configure.ac
index 0264eed..ddec730 100644
--- a/configure.ac
+++ b/configure.ac
@@ -215,33 +215,6 @@ dnl Check for inotify
 dnl =================
 AC_CHECK_HEADERS(sys/inotify.h, AC_DEFINE(HAVE_INOTIFY, 1, Check for inotify))
 
-dnl Check CPP
-dnl =========
-if test "x$CPP_PATH" = x; then
-    AC_PATH_PROG(CPP_PATH, cpp, notfound, 
-		$PATH:/lib:/usr/bin:/bin:/usr/lib:/usr/ccs/lib)
-fi
-
-dnl
-dnl Tell stupid Solaris cpp that the files it will process have C++ like syntax
-dnl RedHat 5.x is broken too, so it won't make a symlink from cpp to the
-dnl standard locations
-dnl
-if test "$CPP_PATH" = "/usr/ccs/lib/cpp" -o "$CPP_PATH" = "notfound" ; then
-    if test "$GCC" = "yes"; then
-	CPP_PATH="gcc -E -x c"
-    else 
-	if test "$CPP_PATH" = "/usr/ccs/lib/cpp"; then
-	    CPP_PATH="$CPP_PATH -B"
-	else
-	    echo "cpp, the C preprocessor was not found in your system."
-  	    echo "Create a symbolic link from it to /lib/cpp and rerun configure"
-  	    exit
-	fi
-    fi
-fi
-
-
 
 dnl Checks for header files.
 dnl =======================
diff --git a/src/WindowMaker.h b/src/WindowMaker.h
index 5388fdd..804695b 100644
--- a/src/WindowMaker.h
+++ b/src/WindowMaker.h
@@ -436,7 +436,6 @@ typedef struct WPreferences {
     struct {
         unsigned int nodock:1;	       /* don't display the dock */
         unsigned int noclip:1;         /* don't display the clip */
-        unsigned int nocpp:1;	       /* don't use cpp */
         unsigned int noupdates:1;      /* don't require ~/GNUstep (-static) */
         unsigned int noautolaunch:1;   /* don't autolaunch apps */
         unsigned int norestore:1;      /* don't restore session */
diff --git a/src/funcs.h b/src/funcs.h
index 74927b9..24c6c94 100644
--- a/src/funcs.h
+++ b/src/funcs.h
@@ -64,10 +64,6 @@ Pixmap LoadIcon(WScreen *scr, char *path, char *mask, int title_height);
 int calcIntersectionArea(int x1, int y1, int w1, int h1,
                          int x2, int y2, int w2, int h2);
 
-#ifdef USECPP
-char *MakeCPPArgs(char *path);
-#endif
-
 char * StrConcatDot(char *a, char *b);
 char * ExpandOptions(WScreen *scr, char *cmdline);
 char * ShrinkString(WMFont *font, char *string, int width);
diff --git a/src/main.c b/src/main.c
index 169f830..f492ac6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -491,9 +491,6 @@ static void print_help(void)
 	puts(_("The Window Maker window manager for the X window system"));
 	puts("");
 	puts(_(" -display host:dpy	display to use"));
-#ifdef USECPP
-	puts(_(" --no-cpp 		disable preprocessing of configuration files"));
-#endif
 	puts(_(" --no-dock		do not open the application Dock"));
 	puts(_(" --no-clip		do not open the workspace Clip"));
 	puts(_(" --no-autolaunch	do not autolaunch applications"));
@@ -679,12 +676,9 @@ static int real_main(int argc, char **argv)
 
 	if (argc > 1) {
 		for (i = 1; i < argc; i++) {
-#ifdef USECPP
 			if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
-				wPreferences.flags.nocpp = 1;
-			} else
-#endif
-			if (strcmp(argv[i], "--for-real") == 0) {
+				wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
+			} else if (strcmp(argv[i], "--for-real") == 0) {
 				wPreferences.flags.restarting = 0;
 			} else if (strcmp(argv[i], "--for-real=") == 0) {
 				wPreferences.flags.restarting = 1;
diff --git a/src/misc.c b/src/misc.c
index 3353a63..9922ea2 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -50,124 +50,6 @@
 /**** global variables *****/
 extern WPreferences wPreferences;
 
-#ifdef USECPP
-static void putdef(char *line, char *name, char *value)
-{
-	if (!value) {
-		wwarning(_("could not define value for %s for cpp"), name);
-		return;
-	}
-	strcat(line, name);
-	strcat(line, value);
-}
-
-static void putidef(char *line, char *name, int value)
-{
-	char tmp[64];
-	snprintf(tmp, sizeof(tmp), "%i", value);
-	strcat(line, name);
-	strcat(line, tmp);
-}
-
-static char *username(void)
-{
-	char *tmp;
-
-	tmp = getlogin();
-	if (!tmp) {
-		struct passwd *user;
-
-		user = getpwuid(getuid());
-		if (!user) {
-			werror(_("could not get password entry for UID %i"), getuid());
-			return NULL;
-		}
-		if (!user->pw_name) {
-			return NULL;
-		} else {
-			return user->pw_name;
-		}
-	}
-	return tmp;
-}
-
-char *MakeCPPArgs(char *path)
-{
-	char buffer[MAXLINE], *buf, *line;
-	Visual *visual;
-	char *tmp;
-
-	line = wmalloc(MAXLINE);
-	*line = 0;
-	if ((buf = getenv("HOSTNAME")) != NULL) {
-		if (buf[0] == '(') {
-			wwarning(_("your machine is misconfigured. HOSTNAME is set to %s"), buf);
-		} else
-			putdef(line, " -DHOST=", buf);
-	} else if ((buf = getenv("HOST")) != NULL) {
-		if (buf[0] == '(') {
-			wwarning(_("your machine is misconfigured. HOST is set to %s"), buf);
-		} else
-			putdef(line, " -DHOST=", buf);
-	}
-	buf = username();
-	if (buf)
-		putdef(line, " -DUSER=", buf);
-	putidef(line, " -DUID=", getuid());
-	buf = XDisplayName(DisplayString(dpy));
-	putdef(line, " -DDISPLAY=", buf);
-	putdef(line, " -DWM_VERSION=", VERSION);
-
-	visual = DefaultVisual(dpy, DefaultScreen(dpy));
-	putidef(line, " -DVISUAL=", visual->class);
-
-	putidef(line, " -DDEPTH=", DefaultDepth(dpy, DefaultScreen(dpy)));
-
-	putidef(line, " -DSCR_WIDTH=", WidthOfScreen(DefaultScreenOfDisplay(dpy)));
-	putidef(line, " -DSCR_HEIGHT=", HeightOfScreen(DefaultScreenOfDisplay(dpy)));
-
-	/* put the dir where the menu is being read from to the
-	 * search path */
-	if (path) {
-		tmp = wstrdup(path);
-		buf = strchr(tmp + 1, ' ');
-		if (buf) {
-			*buf = 0;
-		}
-		buf = strrchr(tmp, '/');
-		if (buf) {
-			*buf = 0;	/* trunc filename */
-			putdef(line, " -I", tmp);
-		}
-		wfree(tmp);
-	}
-
-	/* this should be done just once, but it works this way */
-	strcpy(buffer, DEF_CONFIG_PATHS);
-	buf = strtok(buffer, ":");
-
-	do {
-		char fullpath[MAXLINE];
-
-		if (buf[0] != '~') {
-			strcpy(fullpath, buf);
-		} else {
-			/* home is statically allocated. Don't free it! */
-			char *home = wgethomedir();
-
-			strcpy(fullpath, home);
-			strcat(fullpath, &(buf[1]));
-		}
-
-		putdef(line, " -I", fullpath);
-
-	} while ((buf = strtok(NULL, ":")) != NULL);
-
-#undef arg
-	return line;
-}
-#endif				/* USECPP */
-
 /* XFetchName Wrapper */
 Bool wFetchName(Display *dpy, Window win, char **winname)
 {
diff --git a/src/rootmenu.c b/src/rootmenu.c
index 7e1b2ea..addb23e 100644
--- a/src/rootmenu.c
+++ b/src/rootmenu.c
@@ -939,36 +939,11 @@ static WMenu *readMenuFile(WScreen * scr, char *file_name)
 	FILE *file = NULL;
 	WMenuParser parser;
 	char *command, *params, *shortcut, *title;
-	char cmd[MAXLINE];
-#ifdef USECPP
-	char *args;
-	int cpp = 0;
-#endif
-
-#ifdef USECPP
-	if (!wPreferences.flags.nocpp) {
-		args = MakeCPPArgs(file_name);
-		if (!args) {
-			wwarning(_("could not make arguments for menu file preprocessor"));
-		} else {
-			snprintf(cmd, sizeof(cmd), "%s %s %s", CPP_PATH, args, file_name);
-			wfree(args);
-			file = popen(cmd, "r");
-			if (!file) {
-				werror(_("%s:could not open/preprocess menu file"), file_name);
-			} else {
-				cpp = 1;
-			}
-		}
-	}
-#endif				/* USECPP */
 
+	file = fopen(file_name, "rb");
 	if (!file) {
-		file = fopen(file_name, "rb");
-		if (!file) {
-			werror(_("%s:could not open menu file"), file_name);
-			return NULL;
-		}
+		werror(_("%s:could not open menu file"), file_name);
+		return NULL;
 	}
 	parser = WMenuParserCreate(file_name, file, DEF_CONFIG_PATHS);
 	menu_parser_register_macros(parser);
@@ -998,17 +973,7 @@ static WMenu *readMenuFile(WScreen * scr, char *file_name)
 	}
 
 	WMenuParserDelete(parser);
-#ifdef USECPP
-	if (cpp) {
-		if (pclose(file) == -1) {
-			werror(_("error reading preprocessed menu data"));
-		}
-	} else {
-		fclose(file);
-	}
-#else
 	fclose(file);
-#endif
 
 	return menu;
 }
@@ -1023,11 +988,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name)
 	char *command, *params, *shortcut, *title;
 	char *filename;
 	char flat_file[MAXLINE];
-	char cmd[MAXLINE];
 	int i;
-#ifdef USECPP
-	char *args;
-#endif
 
 	flat_file[0] = '\0';
 
@@ -1037,30 +998,10 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name)
 	}
 	filename = flat_file + (flat_file[1] == '|' ? 2 : 1);
 
-#ifdef USECPP
-	if (!wPreferences.flags.nocpp) {
-		args = MakeCPPArgs(filename);
-		if (!args) {
-			wwarning(_("could not make arguments for menu file preprocessor"));
-		} else {
-			snprintf(cmd, sizeof(cmd), "%s | %s %s", filename, CPP_PATH, args);
-
-			wfree(args);
-			file = popen(cmd, "r");
-			if (!file) {
-				werror(_("%s:could not open/preprocess menu file"), filename);
-			}
-		}
-	}
-#endif				/* USECPP */
-
+	file = popen(filename, "rb");
 	if (!file) {
-		file = popen(filename, "rb");
-
-		if (!file) {
-			werror(_("%s:could not open menu file"), filename);
-			return NULL;
-		}
+		werror(_("%s:could not open menu file"), filename);
+		return NULL;
 	}
 	parser = WMenuParserCreate(flat_file, file, DEF_CONFIG_PATHS);
 	menu_parser_register_macros(parser);
diff --git a/src/wconfig.h.in b/src/wconfig.h.in
index 855d7df..4bda5e6 100644
--- a/src/wconfig.h.in
+++ b/src/wconfig.h.in
@@ -38,11 +38,6 @@
 /* If you want the application icon to be highlighted when it has the focus */
 #define NEWAPPICON
 
-/* undefine it if you don't want your config files to be preprocessed by cpp */
-#define USECPP
-
-/* #define CPP_PATH @CPP_PATH@ */
-
 /* support for XDND drop in the Dock. Experimental */
 /*#define XDND*/
 
-- 
1.7.10.4

Reply via email to