From 412941767e28efb61c63016858d7465a6e6d0539 Mon Sep 17 00:00:00 2001
From: Christophe CURIS <[email protected]>
Date: Sun, 8 Jul 2012 14:04:44 +0200
Subject: [PATCH 01/10] Remove dependency to CPP: Moving parser functions to a
 dedicated file

Due to the tasks to take in charge, the internal parser will grow in
size to support basic CPP feature, so it is a good idea to start by
moving the current functions into a dedicated file.
---
 WINGs/Makefile.am   |    1 +
 WINGs/WINGs/WUtil.h |    7 +++
 WINGs/menuparser.c  |  124 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/rootmenu.c      |   95 ---------------------------------------
 4 files changed, 132 insertions(+), 95 deletions(-)
 create mode 100644 WINGs/menuparser.c

diff --git a/WINGs/Makefile.am b/WINGs/Makefile.am
index 0c8f57f..831325f 100644
--- a/WINGs/Makefile.am
+++ b/WINGs/Makefile.am
@@ -71,6 +71,7 @@ libWUtil_la_SOURCES = 	\
 	handlers.c \
 	hashtable.c \
 	memory.c \
+	menuparser.c \
 	misc.c \
 	notification.c \
 	proplist.c \
diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h
index 4ba6662..e7f4fc0 100644
--- a/WINGs/WINGs/WUtil.h
+++ b/WINGs/WINGs/WUtil.h
@@ -866,6 +866,13 @@ void WMSetUDSearchList(WMUserDefaults *database, WMPropList *list);
 extern char *WMUserDefaultsDidChangeNotification;
 
 
+/* ---[ WINGs/menuparser.c ]---------------------------------------------- */
+
+
+char *getLine(void * file, const char *file_name);
+void separateline(char *line, char **title, char **command, char **parameter, char **shortcut);
+
+
 /*-------------------------------------------------------------------------*/
 
 /* Global variables */
diff --git a/WINGs/menuparser.c b/WINGs/menuparser.c
new file mode 100644
index 0000000..dcd0d36
--- /dev/null
+++ b/WINGs/menuparser.c
@@ -0,0 +1,124 @@
+/*
+ *  Window Maker window manager
+ *
+ *  Copyright (c) 1997-2003 Alfredo K. Kojima
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include "wconfig.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include <WINGs/WUtil.h>
+
+#define MAXLINE  1024
+
+
+char *getLine(void * file, const char *file_name)
+{
+	char linebuf[MAXLINE];
+	char *line = NULL, *result = NULL;
+	size_t len;
+	int done;
+
+again:
+	done = 0;
+	while (!done && fgets(linebuf, sizeof(linebuf), file) != NULL) {
+		line = wtrimspace(linebuf);
+		len = strlen(line);
+
+		/* allow line wrapping */
+		if (len > 0 && line[len - 1] == '\\') {
+			line[len - 1] = '\0';
+		} else {
+			done = 1;
+		}
+
+		if (result == NULL) {
+			result = line;
+		} else {
+			if (strlen(result) < MAXLINE) {
+				result = wstrappend(result, line);
+			}
+			wfree(line);
+		}
+	}
+	if (!done || ferror(file)) {
+		wfree(result);
+		result = NULL;
+	} else if (result != NULL && (result[0] == 0 || result[0] == '#' ||
+		   (result[0] == '/' && result[1] == '/'))) {
+		wfree(result);
+		result = NULL;
+		goto again;
+	} else if (result != NULL && strlen(result) >= MAXLINE) {
+		wwarning(_("%s:maximal line size exceeded in menu config: %s"),
+			 file_name, line);
+		wfree(result);
+		result = NULL;
+		goto again;
+	}
+
+	return result;
+}
+
+void separateline(char *line, char **title, char **command, char **parameter, char **shortcut)
+{
+	char *suffix, *next = line;
+
+	*title = NULL;
+	*command = NULL;
+	*parameter = NULL;
+	*shortcut = NULL;
+
+	/* get the title */
+	*title = wtokennext(line, &next);
+	if (next == NULL)
+		return;
+	line = next;
+
+	/* get the command or shortcut keyword */
+	*command = wtokennext(line, &next);
+	if (next == NULL)
+		return;
+	line = next;
+
+	if (*command != NULL && strcmp(*command, "SHORTCUT") == 0) {
+		/* get the shortcut */
+		*shortcut = wtokennext(line, &next);
+		if (next == NULL)
+			return;
+		line = next;
+
+		/* get the command */
+		*command = wtokennext(line, &next);
+		if (next == NULL)
+			return;
+		line = next;
+	}
+
+	/* get the parameters */
+	suffix = wtrimspace(line);
+
+	/* should we keep this weird old behavior? */
+	if (suffix[0] == '"') {
+		*parameter = wtokennext(suffix, &next);
+		wfree(suffix);
+	} else {
+		*parameter = suffix;
+	}
+}
diff --git a/src/rootmenu.c b/src/rootmenu.c
index 6c4bb2d..c0e7dde 100644
--- a/src/rootmenu.c
+++ b/src/rootmenu.c
@@ -891,101 +891,6 @@ static void freeline(char *title, char *command, char *parameter, char *shortcut
 	wfree(shortcut);
 }
 
-static void separateline(char *line, char **title, char **command, char **parameter, char **shortcut)
-{
-	char *suffix, *next = line;
-
-	*title = NULL;
-	*command = NULL;
-	*parameter = NULL;
-	*shortcut = NULL;
-
-	/* get the title */
-	*title = wtokennext(line, &next);
-	if (next == NULL)
-		return;
-	line = next;
-
-	/* get the command or shortcut keyword */
-	*command = wtokennext(line, &next);
-	if (next == NULL)
-		return;
-	line = next;
-
-	if (*command != NULL && strcmp(*command, "SHORTCUT") == 0) {
-		/* get the shortcut */
-		*shortcut = wtokennext(line, &next);
-		if (next == NULL)
-			return;
-		line = next;
-
-		/* get the command */
-		*command = wtokennext(line, &next);
-		if (next == NULL)
-			return;
-		line = next;
-	}
-
-	/* get the parameters */
-	suffix = wtrimspace(line);
-
-	/* should we keep this weird old behavior? */
-	if (suffix[0] == '"') {
-		*parameter = wtokennext(suffix, &next);
-		wfree(suffix);
-	} else {
-		*parameter = suffix;
-	}
-}
-
-static char *getLine(FILE * file, const char *file_name)
-{
-	char linebuf[MAXLINE];
-	char *line = NULL, *result = NULL;
-	size_t len;
-	int done;
-
-again:
-	done = 0;
-	while (!done && fgets(linebuf, sizeof(linebuf), file) != NULL) {
-		line = wtrimspace(linebuf);
-		len = strlen(line);
-
-		/* allow line wrapping */
-		if (len > 0 && line[len - 1] == '\\') {
-			line[len - 1] = '\0';
-		} else {
-			done = 1;
-		}
-
-		if (result == NULL) {
-			result = line;
-		} else {
-			if (strlen(result) < MAXLINE) {
-				result = wstrappend(result, line);
-			}
-			wfree(line);
-		}
-	}
-	if (!done || ferror(file)) {
-		wfree(result);
-		result = NULL;
-	} else if (result != NULL && (result[0] == 0 || result[0] == '#' ||
-		   (result[0] == '/' && result[1] == '/'))) {
-		wfree(result);
-		result = NULL;
-		goto again;
-	} else if (result != NULL && strlen(result) >= MAXLINE) {
-		wwarning(_("%s:maximal line size exceeded in menu config: %s"),
-			 file_name, line);
-		wfree(result);
-		result = NULL;
-		goto again;
-	}
-
-	return result;
-}
-
 static WMenu *parseCascade(WScreen * scr, WMenu * menu, FILE * file, char *file_name)
 {
 	char *line;
-- 
1.7.10.4

Reply via email to