diff options
Diffstat (limited to 'fref.lex')
-rw-r--r-- | fref.lex | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -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; |