aboutsummaryrefslogtreecommitdiff
path: root/fref.lex
diff options
context:
space:
mode:
Diffstat (limited to 'fref.lex')
-rw-r--r--fref.lex21
1 files changed, 18 insertions, 3 deletions
diff --git a/fref.lex b/fref.lex
index 5a35bd4..2b0861d 100644
--- a/fref.lex
+++ b/fref.lex
@@ -164,7 +164,7 @@ entry()
/* Print date. */
if(!pf(" (%).\n", e.da) && e.a){
- if(e.au[i][strlen(e.au[i])-1] != '.')
+ if(!strpbrk(e.au[i]+strlen(e.au[i])-1, ".,?!"))
pf(".");
pf("\n");
}
@@ -273,13 +273,14 @@ gettrans(char *lg)
* This function interpolates any number of strings into a formatted
* string, which is printed only if all interpolated strings are non-empty.
* Interpolation points are marked by % or *. If a string is interpolated
- * using %, the function empties it after printing it.
+ * using %, the function empties it after printing it. Additionally, the
+ * function tries not to repeat punctuation after %.
*/
int
pf(char *fmt, ...)
{
char *buf, *p, **fs;
- int i, n, sz;
+ int i, n, punct, sz;
va_list ap;
/* Count interpolated strings. */
@@ -303,19 +304,33 @@ pf(char *fmt, ...)
}
va_end(ap);
+ /* Keep track of prior punctuation. */
+ punct = 0;
+
/* Print formatted string. */
for(i = 0; *fmt; fmt++)
switch(*fmt){
case '%':
+ p = fs[i]+strlen(fs[i])-1;
+ punct = strpbrk(p, ".,?!") ? 1 : 0;
printf("%s", fs[i]);
fs[i][0] = 0;
i++;
break;
case '*':
+ punct = 0;
printf("%s", fs[i]);
i++;
break;
+ case '.':
+ case ',':
+ case '?':
+ case '!':
+ if(punct && punct--)
+ break;
+ /* FALLTHROUGH */
default:
+ punct = 0;
putchar(*fmt);
}
return 1;