sylpheedclaws/sylpheed-claws/src quote_fmt.c,1.8.2.6,1.8.2.7 quote_fmt_lex.l,1.8.2.2,1.8.2.3 quote_fmt_parse.y,1.22.2.20,1.22.2.21

[email protected]
Newsgroups gmane.mail.sylpheed.claws.cvs
Message-ID <[email protected]>
Update of /pack/anoncvs/sylpheedclaws/sylpheed-claws/src
In directory sunsite.dk:/tmp/cvs-serv10148/src

Modified Files:
      Tag: gtk2
	quote_fmt.c quote_fmt_lex.l quote_fmt_parse.y 
Log Message:
2006-06-12 [wwp]	2.3.0cvs2

	* src/quote_fmt.c
	* src/quote_fmt_lex.l
	* src/quote_fmt_parse.y
		extend the quote_fmt parser (templates and quotes):
		- allow limited sub-expressions in |p{} and |f{} expressions,
		- add !x{expr} (evaluate and insert 'expr' if 'x' is not set) and \! symbols,
		- implemented/fixed missing implementation of query_references and show_references,
		- completed, fixed contents and format of the symbols help dialog,
		- fix some compilation warnings.

Index: quote_fmt.c
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/quote_fmt.c,v
retrieving revision 1.8.2.6
retrieving revision 1.8.2.7
diff -u -d -r1.8.2.6 -r1.8.2.7
--- quote_fmt.c	2006/01/16 08:27:21	1.8.2.6
+++ quote_fmt.c	2006/06/12 15:59:21	1.8.2.7
@@ -37,7 +37,7 @@
  * When adding new lines, remember to put 2 strings for each line
  */
 static gchar *quote_desc_strings[] = {
-	"%D{fmt}",	N_("customized date format (see man strftime)"), /* date expression */
+	"%D{fmt}",	N_("customized date format (see 'man strftime')"), /* date expression */
 	"%d",		N_("Date"), /* date */
 	"%f",		N_("From"), /* from */
 	"%N",		N_("full name of sender"), /* full name */
@@ -55,18 +55,24 @@
 	"%m",		N_("message body without signature"), /* message with no signature */
 	"%q",		N_("quoted message body without signature"), /* quoted message with no signature */
 	"%X",		N_("cursor position"), /* X marks the cursor spot */
-	"",		NULL,
-	"?x{expr}",	N_("insert expr if x is set\nx is one of the characters above after %"),
-	"",		NULL,
 	"\\%", 		N_("literal %"),
 	"\\\\",		N_("literal backslash"),
 	"\\?",		N_("literal question mark"),
+	"\\!",		N_("literal exclamation mark"),
 	"\\|",		N_("literal pipe"),
 	"\\{",		N_("literal opening curly brace"),
 	"\\}",		N_("literal closing curly brace"),
+	"\\t", 		N_("tab"),
+	"\\n", 		N_("linefeed"),
 	"",		NULL,
-	"|f{file}",	N_("insert file"),
-	"|p{command}",  N_("insert program output"), /* insert program output */
+	"?x{expr}\n",	N_("insert expr if x is set\n(where x is one of the dfNFLIstcnri characters)"),
+	"!x{expr}\n",	N_("insert expr if x is not set\n(where x is one of the dfNFLIstcnri characters)"),
+	"|f{sub_expr}\n",	N_("insert file:\nsub_expr is evaluated as a filename to insert"), /* insert file */
+	"|p{sub_expr}\n\n",	N_("insert program output:\nsub_expr is evaluated as a command-line to get\nthe output from"), /* insert program output */
+	"",		NULL,
+	"terms definition:",	NULL,
+	"expr",			"text that can contain any of the symbols above",
+	"sub_expr\n",	"text that can contain any of the symbols above\nbut ?x{}, !x{}, |f{} and |p{}",
 	NULL,NULL
 };
 

Index: quote_fmt_lex.l
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/quote_fmt_lex.l,v
retrieving revision 1.8.2.2
retrieving revision 1.8.2.3
diff -u -d -r1.8.2.2 -r1.8.2.3
--- quote_fmt_lex.l	2005/02/18 12:26:14	1.8.2.2
+++ quote_fmt_lex.l	2006/06/12 15:59:21	1.8.2.3
@@ -72,12 +72,13 @@
 "\\t"|"\t" /* tab */ return SHOW_TAB;
 "\\n"|"\n" /* return */ return SHOW_EOL;
 "\\?" /* ? */ return SHOW_QUESTION_MARK;
+"\\!" return SHOW_EXCLAMATION_MARK;
 "\\|" return SHOW_PIPE;
 "\\{" return SHOW_OPARENT;
 "\\}" return SHOW_CPARENT;
 "?d" /* query date */ return QUERY_DATE;
 "?f" /* query from */ return QUERY_FROM;
-"?N"|"?F"|"?I" /* query from name */ return QUERY_FULLNAME;
+"?N"|"?F"|"?L"|"?I" /* query from name */ return QUERY_FULLNAME;
 "?s" /* query subject */ return QUERY_SUBJECT;
 "?t" /* query to */ return QUERY_TO;
 "?c" /* query cc */ return QUERY_CC;
@@ -86,6 +87,15 @@
 "?r" /* query references */ return QUERY_REFERENCES;
 "|f" /* insert file */ return INSERT_FILE;
 "|p" /* insert program output */ return INSERT_PROGRAMOUTPUT;
+"!d" /* query date */ return QUERY_NOT_DATE;
+"!f" /* query from */ return QUERY_NOT_FROM;
+"!N"|"!F"|"!L"|"!I" /* query from name */ return QUERY_NOT_FULLNAME;
+"!s" /* query subject */ return QUERY_NOT_SUBJECT;
+"!t" /* query to */ return QUERY_NOT_TO;
+"!c" /* query cc */ return QUERY_NOT_CC;
+"!n" /* query newsgroups */ return QUERY_NOT_NEWSGROUPS;
+"!i" /* query message-id */ return QUERY_MESSAGEID;
+"!r" /* query references */ return QUERY_REFERENCES;
 <S_DATE>"{" return OPARENT;
 <S_DATE>"}" { BEGIN S_NORMAL; return CPARENT; }
 <S_NORMAL>"{" return OPARENT;

Index: quote_fmt_parse.y
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/quote_fmt_parse.y,v
retrieving revision 1.22.2.20
retrieving revision 1.22.2.21
diff -u -d -r1.22.2.20 -r1.22.2.21
--- quote_fmt_parse.y	2006/03/26 17:12:11	1.22.2.20
+++ quote_fmt_parse.y	2006/06/12 15:59:21	1.22.2.21
@@ -47,14 +47,22 @@
 static gint maxsize = 0;
 static gint stacksize = 0;
 
-static gchar *buffer = NULL;
-static gint bufmax = 0;
-static gint bufsize = 0;
+typedef struct st_buffer
+{
+	gchar *buffer;
+	gint bufsize;
+	gint bufmax;
+} st_buffer;
+
+static struct st_buffer main_expr = { NULL, 0, 0 };
+static struct st_buffer sub_expr = { NULL, 0, 0 };
+static struct st_buffer* current = NULL;
+
 static const gchar *quote_str = NULL;
 static const gchar *body = NULL;
 static gint error = 0;
 
-static gint cursor_pos  = -1;
+static gint cursor_pos = -1;
 
 extern int quote_fmt_firsttime;
 
@@ -74,30 +82,47 @@
 static void remove_visibility(void)
 {
 	stacksize--;
+	if (stacksize < 0) {
+		g_warning("Error: visibility stack underflow\n");
+		stacksize = 0;
+	}
 }
 
 static void add_buffer(const gchar *s)
 {
 	gint len;
 
+	if (s == NULL)
+		return;
+
 	len = strlen(s);
-	if (bufsize + len + 1 > bufmax) {
-		if (bufmax == 0)
-			bufmax = 128;
-		while (bufsize + len + 1 > bufmax)
-			bufmax *= 2;
-		buffer = g_realloc(buffer, bufmax);
+	if (current->bufsize + len + 1 > current->bufmax) {
+		if (current->bufmax == 0)
+			current->bufmax = 128;
+		while (current->bufsize + len + 1 > current->bufmax)
+			current->bufmax *= 2;
+		current->buffer = g_realloc(current->buffer, current->bufmax);
 	}
-	strcpy(buffer + bufsize, s);
-	bufsize += len;
+	strcpy(current->buffer + current->bufsize, s);
+	current->bufsize += len;
+}
+
+static void clear_buffer(void)
+{
+	if (current->buffer)
+		*current->buffer = '\0';
+	current->bufsize = 0;
 }
 
 gchar *quote_fmt_get_buffer(void)
 {
+	if (current != &main_expr)
+		g_warning("Error: parser still in sub-expr mode\n");
+
 	if (error != 0)
 		return NULL;
 	else
-		return buffer;
+		return current->buffer;
 }
 
 gint quote_fmt_get_cursor_pos(void)
@@ -106,8 +131,8 @@
 }
 
 #define INSERT(buf) \
-	if (stacksize != 0 && visible[stacksize - 1]) \
-		add_buffer(buf)
+	if (stacksize != 0 && visible[stacksize - 1])\
+		add_buffer(buf); \
 
 #define INSERT_CHARACTER(chr) \
 	if (stacksize != 0 && visible[stacksize - 1]) { \
@@ -126,9 +151,10 @@
 	dry_run = my_dry_run;
 	stacksize = 0;
 	add_visibility(TRUE);
-	if (buffer != NULL)
-		*buffer = 0;
-	bufsize = 0;
+	main_expr.bufmax = 0;
+	sub_expr.bufmax = 0;
+	current = &main_expr;
+	clear_buffer();
 	error = 0;
         /*
          * force LEX initialization
@@ -243,14 +269,14 @@
 	if (!msginfo->fromname)
 		return;	
 	
-	p = strchr(msginfo->fromname, ',');
+	p = (guchar*)strchr(msginfo->fromname, ',');
 	if (p != NULL) {
 		/* fromname is like "Duck, Donald" */
 		p++;
 		while (*p && isspace(*p)) p++;
-		str = alloca(strlen(p) + 1);
+		str = alloca(strlen((char *)p) + 1);
 		if (str != NULL) {
-			strcpy(str, p);
+			strcpy(str, (char *)p);
 			INSERT(str);
 		}
 	} else {
@@ -258,7 +284,7 @@
 		str = alloca(strlen(msginfo->fromname) + 1);
 		if (str != NULL) {
 			strcpy(str, msginfo->fromname);
-			p = str;
+			p = (guchar *)str;
 			while (*p && !isspace(*p)) p++;
 			*p = '\0';
 			INSERT(str);
@@ -321,10 +347,10 @@
 	if (!msginfo->fromname) 
 		return;
 
-	p = msginfo->fromname;
+	p = (guchar *)msginfo->fromname;
 	cur = tmp;
 	while (*p) {
-		if (*p && g_utf8_validate(p, 1, NULL)) {
+		if (*p && g_utf8_validate((gchar *)p, 1, NULL)) {
 			*cur = toupper(*p);
 				cur++;
 			len++;
@@ -416,10 +442,13 @@
 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
-%token SHOW_EOL SHOW_QUESTION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
+%token SHOW_EOL SHOW_QUESTION_MARK SHOW_EXCLAMATION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
 %token QUERY_DATE QUERY_FROM
 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
+%token QUERY_NOT_DATE QUERY_NOT_FROM
+%token QUERY_NOT_FULLNAME QUERY_NOT_SUBJECT QUERY_NOT_TO QUERY_NOT_NEWSGROUPS
+%token QUERY_NOT_MESSAGEID QUERY_NOT_CC QUERY_NOT_REFERENCES
 %token INSERT_FILE INSERT_PROGRAMOUTPUT
 %token OPARENT CPARENT
 %token CHARACTER
@@ -435,20 +464,31 @@
 %%
 
 quote_fmt:
-	character_or_special_or_insert_or_query_list;
+	character_or_special_or_insert_or_query_list ;
 
+sub_expr:
+	character_or_special_list ;
+
 character_or_special_or_insert_or_query_list:
 	character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
 	| character_or_special_or_insert_or_query ;
 
+character_or_special_list:
+	character_or_special character_or_special_list
+	| character_or_special ;
+
 character_or_special_or_insert_or_query:
+	character_or_special
+	| query
+	| query_not
+	| insert ;
+
+character_or_special:
 	special
 	| character
 	{
 		INSERT_CHARACTER($1);
-	}
-	| query
-	| insert ;
+	};
 
 character:
 	CHARACTER
@@ -503,7 +543,7 @@
 		quote_fmt_show_first_name(msginfo);
 	}
 	| SHOW_LAST_NAME
-        {
+    {
 		quote_fmt_show_last_name(msginfo);
 	}
 	| SHOW_SENDER_INITIAL
@@ -536,9 +576,12 @@
 	}
 	| SHOW_REFERENCES
 	{
-                /* CLAWS: use in reply to header */
-		/* if (msginfo->references)
-			INSERT(msginfo->references); */
+		GSList *item;
+
+		INSERT(msginfo->inreplyto);
+		for (item = msginfo->references; item != NULL; item = g_slist_next(item))
+			if (item->data)
+				INSERT(item->data);
 	}
 	| SHOW_MESSAGE
 	{
@@ -572,6 +615,10 @@
 	{
 		INSERT("?");
 	}
+	| SHOW_EXCLAMATION_MARK
+	{
+		INSERT("!");
+	}
 	| SHOW_PIPE
 	{
 		INSERT("|");
@@ -586,7 +633,7 @@
 	}
 	| SET_CURSOR_POS
 	{
-		cursor_pos = bufsize;
+		cursor_pos = current->bufsize;
 	};
 
 query:
@@ -656,24 +703,123 @@
 	}
 	| QUERY_REFERENCES
 	{
-                /* CLAWS: use in-reply-to header */
-		/* add_visibility(msginfo->references != NULL); */
+		gboolean found;
+		GSList *item;
+
+		found = (msginfo->inreplyto != NULL);
+		for (item = msginfo->references; found == FALSE && item != NULL; item = g_slist_next(item))
+			if (item->data)
+				found = TRUE;
+		add_visibility(found == TRUE);
 	}
 	OPARENT quote_fmt CPARENT
 	{
 		remove_visibility();
 	};
 
+query_not:
+	QUERY_NOT_DATE
+	{
+		add_visibility(msginfo->date == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_FROM
+	{
+		add_visibility(msginfo->from == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_FULLNAME
+	{
+		add_visibility(msginfo->fromname == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_SUBJECT
+	{
+		add_visibility(msginfo->subject == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_TO
+	{
+		add_visibility(msginfo->to == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_NEWSGROUPS
+	{
+		add_visibility(msginfo->newsgroups == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_MESSAGEID
+	{
+		add_visibility(msginfo->msgid == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_CC
+	{
+		add_visibility(msginfo->cc == NULL);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	}
+	| QUERY_NOT_REFERENCES
+	{
+		gboolean found;
+		GSList *item;
+
+		found = (msginfo->inreplyto != NULL);
+		for (item = msginfo->references; found == FALSE && item != NULL; item = g_slist_next(item))
+			if (item->data)
+				found = TRUE;
+		add_visibility(found == FALSE);
+	}
+	OPARENT quote_fmt CPARENT
+	{
+		remove_visibility();
+	};
+
 insert:
-	INSERT_FILE OPARENT string CPARENT
+	INSERT_FILE
+	{
+		current = &sub_expr;
+		clear_buffer();
+	}
+	OPARENT sub_expr CPARENT
 	{
+		current = &main_expr;
 		if (!dry_run) {
-			quote_fmt_insert_file($3);
+			quote_fmt_insert_file(sub_expr.buffer);
 		}
 	}
-	| INSERT_PROGRAMOUTPUT OPARENT string CPARENT
+	| INSERT_PROGRAMOUTPUT
+	{
+		current = &sub_expr;
+		clear_buffer();
+	}
+	OPARENT sub_expr CPARENT
 	{
+		current = &main_expr;
 		if (!dry_run) {
-			quote_fmt_insert_program_output($3);
+			quote_fmt_insert_program_output(sub_expr.buffer);
 		}
 	};


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.