ref: 42e5c24a2b0096f408dd975fa6b1027d4ac0a730
parent: 683c46181fcd524b56ad3ab41fe799566428209d
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Nov 13 13:06:58 EST 2014
tr: eos request to change end of sentence characters The eos request expects two arguments: .eos sentchars transchars In which sentchars is the list of sentence ending characters (.!?, by default) and transchars is the list of characters ignored for detecting the end of sentences ('"])*, by default). Without any arguments, the eos request disables detecting end of sentences.
--- a/roff.h
+++ b/roff.h
@@ -43,6 +43,7 @@
#define NCMAPS 512 /* number of character translations (.tr) */
#define NSSTR 32 /* number of nested sstr_push() calls */
#define NFIELDS 32 /* number of fields */
+#define NEOS 32 /* number of end of sentence characters */
#define MAXFRAC 100000 /* maximum value of the fractional part */
#define NCDEFS 128 /* number of character definitions (.char) */
#define NHYPHS 16384 /* hyphenation dictionary/patterns (.hw) */
@@ -277,6 +278,8 @@
void wb_fnszset(struct wb *wb, int fn, int sz, int m);
int wb_dashwid(struct wb *wb);
int c_dash(char *c);
+int c_eossent(char *s);
+int c_eostran(char *s);
/* character translation (.tr) */
void cmap_add(char *c1, char *c2);
--- a/tr.c
+++ b/tr.c
@@ -401,6 +401,48 @@
strcpy(c_hc, "\\%");
}
+/* sentence ending and their transparent characters */
+static char eos_sentc[NEOS][GNLEN] = { ".", "?", "!", };
+static int eos_sents = 3;
+static char eos_tranc[NEOS][GNLEN] = { "'", "\"", ")", "]", "*", };
+static int eos_trans = 5;
+
+static void tr_eos(char **args)
+{
+ eos_sents = 0;
+ eos_trans = 0;
+ if (args[1]) {
+ char *s = args[1];
+ while (s && charread(&s, eos_sentc[eos_sents]) >= 0)
+ if (eos_sents < NEOS - 1)
+ eos_sents++;
+ }
+ if (args[2]) {
+ char *s = args[2];
+ while (s && charread(&s, eos_tranc[eos_trans]) >= 0)
+ if (eos_trans < NEOS - 1)
+ eos_trans++;
+ }
+}
+
+int c_eossent(char *s)
+{
+ int i;
+ for (i = 0; i < eos_sents; i++)
+ if (!strcmp(eos_sentc[i], s))
+ return 1;
+ return 0;
+}
+
+int c_eostran(char *s)
+{
+ int i;
+ for (i = 0; i < eos_trans; i++)
+ if (!strcmp(eos_tranc[i], s))
+ return 1;
+ return 0;
+}
+
static void tr_nh(char **args)
{
n_hy = 0;
@@ -895,6 +937,7 @@
{"el", tr_el, mkargs_null},
{"em", tr_em},
{"eo", tr_eo},
+ {"eos", tr_eos},
{"ev", tr_ev},
{"ex", tr_ex},
{"fc", tr_fc},
--- a/wb.c
+++ b/wb.c
@@ -439,9 +439,9 @@
int wb_eos(struct wb *wb)
{
int i = wb->sub_n - 1;
- while (i > 0 && strchr("'\")]*", wb->sub_c[i][0]))
+ while (i > 0 && c_eostran(wb->sub_c[i]))
i--;
- return i >= 0 && strchr(".?!", wb->sub_c[i][0]);
+ return i >= 0 && c_eossent(wb->sub_c[i]);
}
void wb_wconf(struct wb *wb, int *ct, int *st, int *sb,