From 0a73709badcc1a51e03fe1598b45387bab22efbd Mon Sep 17 00:00:00 2001 From: Alfons Hoogervorst Date: Sat, 11 May 2002 23:33:22 +0000 Subject: [PATCH] allow quote / reply date & time format to be set using %D{format}. --- ChangeLog.claws | 11 ++++++ configure.in | 2 +- src/quote_fmt_lex.l | 78 +++++++++++++++++++++++++++++++++---------- src/quote_fmt_parse.y | 13 ++++++++ 4 files changed, 85 insertions(+), 19 deletions(-) diff --git a/ChangeLog.claws b/ChangeLog.claws index e6460136b..4aec4332a 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,14 @@ +2002-05-12 [alfons] 0.7.5claws18 + + * src/quote_fmt_lex.l + * src/quote_fmt_parse.y + allow quote / reply date & time format to be set using + %D{format}. format is a format string you'd pass to + strftime() (see man strftime, or the Display tab | + Date format setting). + + Currently %D converts the date to local time. + 2002-05-11 [paul] 0.7.5claws17 * sync with 0.7.5cvs19 (except src/prefs_folder_item.c) diff --git a/configure.in b/configure.in index 757b0d6b8..70a887463 100644 --- a/configure.in +++ b/configure.in @@ -8,7 +8,7 @@ MINOR_VERSION=7 MICRO_VERSION=5 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws17 +EXTRA_VERSION=claws18 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/quote_fmt_lex.l b/src/quote_fmt_lex.l index e1a083f6d..9855d22f0 100644 --- a/src/quote_fmt_lex.l +++ b/src/quote_fmt_lex.l @@ -6,24 +6,64 @@ %option prefix="quote_fmt" %option outfile="lex.yy.c" +%s S_NORMAL S_DATE + +%{ +/* + * see notes below. + */ +static int firsttime = 1; +%} + %% -"%d" /* date */ return SHOW_DATE; -"%f" /* from */ return SHOW_FROM; -"%N" /* full name */ return SHOW_FULLNAME; -"%F" /* first name */ return SHOW_FIRST_NAME; -"%L" /* last name */ return SHOW_LAST_NAME; -"%I" /* initial of sender */ return SHOW_SENDER_INITIAL; -"%s" /* subject */ return SHOW_SUBJECT; -"%t" /* to */ return SHOW_TO; -"%c" /* cc */ return SHOW_CC; -"%n" /* newsgroups */ return SHOW_NEWSGROUPS; -"%i" /* message-id */ return SHOW_MESSAGEID; -"%r" /* references */ return SHOW_REFERENCES; -"%M" /* message */ return SHOW_MESSAGE; -"%Q" /* quoted message */ return SHOW_QUOTED_MESSAGE; -"%m" /* message with no signature */ return SHOW_MESSAGE_NO_SIGNATURE; -"%q" /* quoted message with no signature */ return SHOW_QUOTED_MESSAGE_NO_SIGNATURE; +%{ +/* + * NOTES: + * this lex script used to use characters also in use + * by strftime() (which we want to use for custom + * time formats in replies and templates). to circumvent + * this we have to play a little bit with states. + * + * these are the characters we also want to use in the + * %D time customizer: + * + * %a %A %b %B %c %C %d %H %I %j %m %M %p %S %w %x %y %Y %Z + * + * you can use these characters too, but don't forget to + * prepend them with the state. + * + * also there is also work around for resetting the state + * (firsttime variable). this assumes that yylex() will + * always return to S_NORMAL after quote fmt parsing is + * done. + */ +%} + +%{ + if (firsttime) { + BEGIN S_NORMAL; + firsttime = 0; + } +%} + +"%c" /* cc */ return SHOW_CC; +"%d" /* date */ return SHOW_DATE; +"%D" /* date */ { BEGIN S_DATE; return SHOW_DATE_EXPR; } +"%f" /* from */ return SHOW_FROM; +"%F" /* first name */ return SHOW_FIRST_NAME; +"%i" /* message-id */ return SHOW_MESSAGEID; +"%I" /* initial of sender */ return SHOW_SENDER_INITIAL; +"%m" /* message with no signature */ return SHOW_MESSAGE_NO_SIGNATURE; +"%M" /* message */ return SHOW_MESSAGE; +"%n" /* newsgroups */ return SHOW_NEWSGROUPS; +"%N" /* full name */ return SHOW_FULLNAME; +"%L" /* last name */ return SHOW_LAST_NAME; +"%r" /* references */ return SHOW_REFERENCES; +"%s" /* subject */ return SHOW_SUBJECT; +"%t" /* to */ return SHOW_TO; +"%Q" /* quoted message */ return SHOW_QUOTED_MESSAGE; +"%q" /* quoted message with no signature */ return SHOW_QUOTED_MESSAGE_NO_SIGNATURE; "\\\%" /* % */ return SHOW_PERCENT; "\\\\" /* \ */ return SHOW_BACKSLASH; "\\t"|"\t" /* tab */ return SHOW_TAB; @@ -43,8 +83,10 @@ "?r" /* query references */ return QUERY_REFERENCES; "|f" /* insert file */ return INSERT_FILE; "|p" /* insert program output */ return INSERT_PROGRAMOUTPUT; -"{" return OPARENT; -"}" return CPARENT; +"{" return OPARENT; +"}" { BEGIN S_NORMAL; return CPARENT; } +"{" return OPARENT; +"}" return CPARENT; . { yylval.chr = yytext[0]; return CHARACTER; } %% diff --git a/src/quote_fmt_parse.y b/src/quote_fmt_parse.y index 59b8d0406..2f3ec9a43 100644 --- a/src/quote_fmt_parse.y +++ b/src/quote_fmt_parse.y @@ -143,6 +143,7 @@ static int isseparator(char ch) %token INSERT_FILE INSERT_PROGRAMOUTPUT %token OPARENT CPARENT %token CHARACTER +%token SHOW_DATE_EXPR %start quote_fmt @@ -191,6 +192,18 @@ special: if (msginfo->newsgroups) INSERT(msginfo->newsgroups); } + | SHOW_DATE_EXPR OPARENT string CPARENT + { + if (msginfo->date_t) { + char timef[128]; + struct tm *lt; + + if (NULL != (lt = localtime(&msginfo->date_t))) { + strftime(timef, sizeof timef, $3, lt); + INSERT(timef); + } + } + } | SHOW_DATE { if (msginfo->date) -- 2.25.1