+static int term_pre (char **src, const char *ct1, const char *ct2)
+{
+ char *s1, *s0 = *src;
+ char **map;
+
+ /* skip white space */
+ while (*s0)
+ {
+ if (ct1 && strchr (ct1, *s0))
+ break;
+ if (ct2 && strchr (ct2, *s0))
+ break;
+ s1 = s0;
+ map = map_chrs_input (&s1, strlen(s1));
+ if (**map != *CHR_SPACE)
+ break;
+ s0 = s1;
+ }
+ *src = s0;
+ return *s0;
+}
+
+static int term_100 (char **src, char *dst)
+{
+ char *s0, *s1, **map;
+ int i = 0;
+
+ if (!term_pre (src, NULL, NULL))
+ return 0;
+ s0 = *src;
+ while (*s0)
+ {
+ s1 = s0;
+ map = map_chrs_input (&s0, strlen(s0));
+ if (**map == *CHR_SPACE)
+ break;
+ while (s1 < s0)
+ {
+ if (!isalnum (*s1))
+ dst[i++] = '\\';
+ dst[i++] = *s1++;
+ }
+ }
+ dst[i] = '\0';
+ *src = s0;
+ return i;
+}
+
+static int term_101 (char **src, char *dst)
+{
+ char *s0, *s1, **map;
+ int i = 0;
+
+ if (!term_pre (src, "#", "#"))
+ return 0;
+ s0 = *src;
+ while (*s0)
+ {
+ if (*s0 == '#')
+ {
+ dst[i++] = '.';
+ dst[i++] = '*';
+ s0++;
+ }
+ else
+ {
+ s1 = s0;
+ map = map_chrs_input (&s0, strlen(s0));
+ if (**map == *CHR_SPACE)
+ break;
+ while (s1 < s0)
+ {
+ if (!isalnum (*s1))
+ dst[i++] = '\\';
+ dst[i++] = *s1++;
+ }
+ }
+ }
+ dst[i] = '\0';
+ *src = s0;
+ return i;
+}
+
+
+static int term_103 (char **src, char *dst, int *errors)
+{
+ int i = 0;
+ char *s0, *s1, **map;
+
+ if (!term_pre (src, "\\()[].*+?|", "("))
+ return 0;
+ s0 = *src;
+ if (errors && *s0 == '+' && s0[1] && s0[2] == '+' && s0[3] &&
+ isdigit (s0[1]))
+ {
+ *errors = s0[1] - '0';
+ s0 += 3;
+ if (*errors > 3)
+ *errors = 3;
+ }
+ while (*s0)
+ {
+ if (strchr ("\\()[].*+?|-", *s0))
+ dst[i++] = *s0++;
+ else
+ {
+ s1 = s0;
+ map = map_chrs_input (&s0, strlen(s0));
+ if (**map == *CHR_SPACE)
+ break;
+ while (s1 < s0)
+ {
+ if (!isalnum (*s1))
+ dst[i++] = '\\';
+ dst[i++] = *s1++;
+ }
+ }
+ }
+ dst[i] = '\0';
+ *src = s0;
+ return i;
+}
+
+static int term_102 (char **src, char *dst)
+{
+ return term_103 (src, dst, NULL);
+}
+