aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-21 14:44:47 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-21 14:44:47 +0200
commit619f7eab8fa93116e66d839d057a276e54a59085 (patch)
treeb7b29affb351bb177cdc3099ee9b18d4903a6d1b
parentd2390f71937a1ef1d2b01d58029e7e92fdbbe8fb (diff)
downloadfref-619f7eab8fa93116e66d839d057a276e54a59085.tar.gz
pf: Try not to repeat puncuation after %
-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;