static void dump_string(char *val, char *buf) /* display the value of a string capability */ { if (val == ABSENT_STRING) strcpy(buf, s_absent); else if (val == CANCELLED_STRING) strcpy(buf, s_cancel); else { sprintf(buf, "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val)); } }
static void dump_string(char *val, char *buf) /* display the value of a string capability */ { if (val == ABSENT_STRING) _nc_STRCPY(buf, s_absent, MAX_STRING); else if (val == CANCELLED_STRING) _nc_STRCPY(buf, s_cancel, MAX_STRING); else { _nc_SPRINTF(buf, _nc_SLIMIT(MAX_STRING) "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val)); } }
static void analyze_string(const char *name, const char *cap, TERMTYPE * tp) { char buf[MAX_TERMINFO_LENGTH]; char buf2[MAX_TERMINFO_LENGTH]; const char *sp, *ep; const assoc *ap; if (cap == ABSENT_STRING || cap == CANCELLED_STRING) return; (void) printf("%s: ", name); buf[0] = '\0'; for (sp = cap; *sp; sp++) { int i; size_t len = 0; const char *expansion = 0; /* first, check other capabilities in this entry */ for (i = 0; i < STRCOUNT; i++) { char *cp = tp->Strings[i]; /* don't use soft-key capabilities */ if (strnames[i][0] == 'k' && strnames[i][0] == 'f') continue; if (cp != ABSENT_STRING && cp != CANCELLED_STRING && cp[0] && cp != cap) { len = strlen(cp); (void) strncpy(buf2, sp, len); buf2[len] = '\0'; if (_nc_capcmp(cp, buf2)) continue; #define ISRS(s) (!strncmp((s), "is", 2) || !strncmp((s), "rs", 2)) /* * Theoretically we just passed the test for translation * (equality once the padding is stripped). However, there * are a few more hoops that need to be jumped so that * identical pairs of initialization and reset strings * don't just refer to each other. */ if (ISRS(name) || ISRS(strnames[i])) if (cap < cp) continue; #undef ISRS expansion = strnames[i]; break; } } /* now check the standard capabilities */ if (!expansion) for (ap = std_caps; ap->from; ap++) { len = strlen(ap->from); if (strncmp(ap->from, sp, len) == 0) { expansion = ap->to; break; } } /* now check for private-mode sequences */ if (!expansion && sp[0] == '\033' && sp[1] == '[' && sp[2] == '?' && (len = strspn(sp + 3, "0123456789;")) && ((sp[3 + len] == 'h') || (sp[3 + len] == 'l'))) { char buf3[MAX_TERMINFO_LENGTH]; (void) strcpy(buf2, (sp[3 + len] == 'h') ? "DEC+" : "DEC-"); (void) strncpy(buf3, sp + 3, len); len += 4; buf3[len] = '\0'; ep = strtok(buf3, ";"); do { bool found = FALSE; for (ap = private_modes; ap->from; ap++) { size_t tlen = strlen(ap->from); if (strncmp(ap->from, ep, tlen) == 0) { (void) strcat(buf2, ap->to); found = TRUE; break; } } if (!found) (void) strcat(buf2, ep); (void) strcat(buf2, ";"); } while ((ep = strtok((char *) 0, ";"))); buf2[strlen(buf2) - 1] = '\0'; expansion = buf2; } /* now check for ECMA highlight sequences */ if (!expansion && sp[0] == '\033' && sp[1] == '[' && (len = strspn(sp + 2, "0123456789;")) && sp[2 + len] == 'm') { char buf3[MAX_TERMINFO_LENGTH]; (void) strcpy(buf2, "SGR:"); (void) strncpy(buf3, sp + 2, len); len += 3; buf3[len] = '\0'; ep = strtok(buf3, ";"); do { bool found = FALSE; for (ap = ecma_highlights; ap->from; ap++) { size_t tlen = strlen(ap->from); if (strncmp(ap->from, ep, tlen) == 0) { (void) strcat(buf2, ap->to); found = TRUE; break; } } if (!found) (void) strcat(buf2, ep); (void) strcat(buf2, ";"); } while ((ep = strtok((char *) 0, ";"))); buf2[strlen(buf2) - 1] = '\0'; expansion = buf2; } /* now check for scroll region reset */ if (!expansion) { (void) sprintf(buf2, "\033[1;%dr", tp->Numbers[2]); len = strlen(buf2); if (strncmp(buf2, sp, len) == 0) expansion = "RSR"; } /* now check for home-down */ if (!expansion) { (void) sprintf(buf2, "\033[%d;1H", tp->Numbers[2]); len = strlen(buf2); if (strncmp(buf2, sp, len) == 0) expansion = "LL"; } /* now look at the expansion we got, if any */ if (expansion) { (void) sprintf(buf + strlen(buf), "{%s}", expansion); sp += len - 1; continue; } else { /* couldn't match anything */ buf2[0] = *sp; buf2[1] = '\0'; (void) strcat(buf, TIC_EXPAND(buf2)); } } (void) printf("%s\n", buf); }
static void compare_predicate(int type, int idx, const char *name) /* predicate function to use for entry difference reports */ { register ENTRY *e1 = &entries[0]; register ENTRY *e2 = &entries[1]; char buf1[MAX_STRING], buf2[MAX_STRING]; int b1, b2; int n1, n2; char *s1, *s2; switch (type) { case CMP_BOOLEAN: b1 = e1->tterm.Booleans[idx]; b2 = e2->tterm.Booleans[idx]; switch (compare) { case C_DIFFERENCE: if (!(b1 == ABSENT_BOOLEAN && b2 == ABSENT_BOOLEAN) && b1 != b2) (void) printf("\t%s: %s%s%s.\n", name, dump_boolean(b1), bool_sep, dump_boolean(b2)); break; case C_COMMON: if (b1 == b2 && b1 != ABSENT_BOOLEAN) (void) printf("\t%s= %s.\n", name, dump_boolean(b1)); break; case C_NAND: if (b1 == ABSENT_BOOLEAN && b2 == ABSENT_BOOLEAN) (void) printf("\t!%s.\n", name); break; } break; case CMP_NUMBER: n1 = e1->tterm.Numbers[idx]; n2 = e2->tterm.Numbers[idx]; dump_numeric(n1, buf1); dump_numeric(n2, buf2); switch (compare) { case C_DIFFERENCE: if (!((n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC)) && n1 != n2) (void) printf("\t%s: %s, %s.\n", name, buf1, buf2); break; case C_COMMON: if (n1 != ABSENT_NUMERIC && n2 != ABSENT_NUMERIC && n1 == n2) (void) printf("\t%s= %s.\n", name, buf1); break; case C_NAND: if (n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC) (void) printf("\t!%s.\n", name); break; } break; case CMP_STRING: s1 = e1->tterm.Strings[idx]; s2 = e2->tterm.Strings[idx]; switch (compare) { case C_DIFFERENCE: if (capcmp(idx, s1, s2)) { dump_string(s1, buf1); dump_string(s2, buf2); if (strcmp(buf1, buf2)) (void) printf("\t%s: %s, %s.\n", name, buf1, buf2); } break; case C_COMMON: if (s1 && s2 && !capcmp(idx, s1, s2)) (void) printf("\t%s= '%s'.\n", name, TIC_EXPAND(s1)); break; case C_NAND: if (!s1 && !s2) (void) printf("\t!%s.\n", name); break; } break; case CMP_USE: /* unlike the other modes, this compares *all* use entries */ switch (compare) { case C_DIFFERENCE: if (!useeq(e1, e2)) { (void) fputs("\tuse: ", stdout); print_uses(e1, stdout); fputs(", ", stdout); print_uses(e2, stdout); fputs(".\n", stdout); } break; case C_COMMON: if (e1->nuses && e2->nuses && useeq(e1, e2)) { (void) fputs("\tuse: ", stdout); print_uses(e1, stdout); fputs(".\n", stdout); } break; case C_NAND: if (!e1->nuses && !e2->nuses) (void) printf("\t!use.\n"); break; } } }
static void analyze_string(const char *name, const char *cap, TERMTYPE *tp) { char buf[MAX_TERMINFO_LENGTH]; char buf2[MAX_TERMINFO_LENGTH]; const char *sp; const assoc *ap; int tp_lines = tp->Numbers[2]; if (cap == ABSENT_STRING || cap == CANCELLED_STRING) return; (void) printf("%s: ", name); buf[0] = '\0'; for (sp = cap; *sp; sp++) { int i; int csi; size_t len = 0; size_t next; const char *expansion = 0; char buf3[MAX_TERMINFO_LENGTH]; /* first, check other capabilities in this entry */ for (i = 0; i < STRCOUNT; i++) { char *cp = tp->Strings[i]; /* don't use soft-key capabilities */ if (strnames[i][0] == 'k' && strnames[i][0] == 'f') continue; if (cp != ABSENT_STRING && cp != CANCELLED_STRING && cp[0] && cp != cap) { len = strlen(cp); (void) strncpy(buf2, sp, len); buf2[len] = '\0'; if (_nc_capcmp(cp, buf2)) continue; #define ISRS(s) (!strncmp((s), "is", 2) || !strncmp((s), "rs", 2)) /* * Theoretically we just passed the test for translation * (equality once the padding is stripped). However, there * are a few more hoops that need to be jumped so that * identical pairs of initialization and reset strings * don't just refer to each other. */ if (ISRS(name) || ISRS(strnames[i])) if (cap < cp) continue; #undef ISRS expansion = strnames[i]; break; } } /* now check the standard capabilities */ if (!expansion) { csi = skip_csi(sp); for (ap = std_caps; ap->from; ap++) { size_t adj = csi ? 2 : 0; len = strlen(ap->from); if (csi && skip_csi(ap->from) != csi) continue; if (len > adj && strncmp(ap->from + adj, sp + csi, len - adj) == 0) { expansion = ap->to; len -= adj; len += csi; break; } } } /* now check for standard-mode sequences */ if (!expansion && (csi = skip_csi(sp)) != 0 && (len = strspn(sp + csi, "0123456789;")) && (next = csi + len) && ((sp[next] == 'h') || (sp[next] == 'l'))) { (void) strcpy(buf2, (sp[next] == 'h') ? "ECMA+" : "ECMA-"); (void) strncpy(buf3, sp + csi, len); buf3[len] = '\0'; len += csi + 1; expansion = lookup_params(std_modes, buf2, buf3); } /* now check for private-mode sequences */ if (!expansion && (csi = skip_csi(sp)) != 0 && sp[csi] == '?' && (len = strspn(sp + csi + 1, "0123456789;")) && (next = csi + 1 + len) && ((sp[next] == 'h') || (sp[next] == 'l'))) { (void) strcpy(buf2, (sp[next] == 'h') ? "DEC+" : "DEC-"); (void) strncpy(buf3, sp + csi + 1, len); buf3[len] = '\0'; len += csi + 2; expansion = lookup_params(private_modes, buf2, buf3); } /* now check for ECMA highlight sequences */ if (!expansion && (csi = skip_csi(sp)) != 0 && (len = strspn(sp + csi, "0123456789;")) != 0 && (next = csi + len) && sp[next] == 'm') { (void) strcpy(buf2, "SGR:"); (void) strncpy(buf3, sp + csi, len); buf3[len] = '\0'; len += csi + 1; expansion = lookup_params(ecma_highlights, buf2, buf3); } if (!expansion && (csi = skip_csi(sp)) != 0 && sp[csi] == 'm') { len = csi + 1; (void) strcpy(buf2, "SGR:"); strcat(buf2, ecma_highlights[0].to); expansion = buf2; } /* now check for scroll region reset */ if (!expansion && (csi = skip_csi(sp)) != 0) { if (sp[csi] == 'r') { expansion = "RSR"; len = 1; } else { (void) sprintf(buf2, "1;%dr", tp_lines); len = strlen(buf2); if (strncmp(buf2, sp + csi, len) == 0) expansion = "RSR"; } len += csi; } /* now check for home-down */ if (!expansion && (csi = skip_csi(sp)) != 0) { (void) sprintf(buf2, "%d;1H", tp_lines); len = strlen(buf2); if (strncmp(buf2, sp + csi, len) == 0) { expansion = "LL"; } else { (void) sprintf(buf2, "%dH", tp_lines); len = strlen(buf2); if (strncmp(buf2, sp + csi, len) == 0) { expansion = "LL"; } } len += csi; } /* now look at the expansion we got, if any */ if (expansion) { (void) sprintf(buf + strlen(buf), "{%s}", expansion); sp += len - 1; continue; } else { /* couldn't match anything */ buf2[0] = *sp; buf2[1] = '\0'; (void) strcat(buf, TIC_EXPAND(buf2)); } } (void) printf("%s\n", buf); }