/****************************************************************************
- * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <dump_entry.h>
-MODULE_ID("$Id: infocmp.c,v 1.108 2011/08/06 16:36:06 tom Exp $")
+MODULE_ID("$Id: infocmp.c,v 1.114 2012/03/11 00:10:57 tom Exp $")
#define L_CURL "{"
#define R_CURL "}"
{
char *bp;
- (void) strcpy(buf, ptr);
+ _nc_STRCPY(buf, ptr, NAMESIZE);
if ((bp = strchr(buf, '|')) != 0)
*bp = '\0';
{
switch (val) {
case ABSENT_NUMERIC:
- strcpy(buf, s_absent);
+ _nc_STRCPY(buf, s_absent, MAX_STRING);
break;
case CANCELLED_NUMERIC:
- strcpy(buf, s_cancel);
+ _nc_STRCPY(buf, s_cancel, MAX_STRING);
break;
default:
- sprintf(buf, "%d", val);
+ _nc_SPRINTF(buf, _nc_SLIMIT(MAX_STRING) "%d", val);
break;
}
}
/* display the value of a string capability */
{
if (val == ABSENT_STRING)
- strcpy(buf, s_absent);
+ _nc_STRCPY(buf, s_absent, MAX_STRING);
else if (val == CANCELLED_STRING)
- strcpy(buf, s_cancel);
+ _nc_STRCPY(buf, s_cancel, MAX_STRING);
else {
- sprintf(buf, "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val));
+ _nc_SPRINTF(buf, _nc_SLIMIT(MAX_STRING)
+ "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val));
}
}
size_t tlen = strlen(ap->from);
if (same_param(ap->from, ep, tlen)) {
- (void) strcat(dst, ap->to);
+ _nc_STRCAT(dst, ap->to, MAX_TERMINFO_LENGTH);
found = TRUE;
break;
}
}
if (!found)
- (void) strcat(dst, ep);
- (void) strcat(dst, ";");
+ _nc_STRCAT(dst, ep, MAX_TERMINFO_LENGTH);
+ _nc_STRCAT(dst, ";", MAX_TERMINFO_LENGTH);
} while
((ep = strtok((char *) 0, ";")));
&& (next = (size_t) csi + len)
&& ((sp[next] == 'h') || (sp[next] == 'l'))) {
- (void) strcpy(buf2, (sp[next] == 'h') ? "ECMA+" : "ECMA-");
+ _nc_STRCPY(buf2,
+ ((sp[next] == 'h')
+ ? "ECMA+"
+ : "ECMA-"),
+ sizeof(buf2));
(void) strncpy(buf3, sp + csi, len);
buf3[len] = '\0';
len += (size_t) csi + 1;
&& (next = (size_t) csi + 1 + len)
&& ((sp[next] == 'h') || (sp[next] == 'l'))) {
- (void) strcpy(buf2, (sp[next] == 'h') ? "DEC+" : "DEC-");
+ _nc_STRCPY(buf2,
+ ((sp[next] == 'h')
+ ? "DEC+"
+ : "DEC-"),
+ sizeof(buf2));
(void) strncpy(buf3, sp + csi + 1, len);
buf3[len] = '\0';
len += (size_t) csi + 2;
&& (next = (size_t) csi + len)
&& sp[next] == 'm') {
- (void) strcpy(buf2, "SGR:");
+ _nc_STRCPY(buf2, "SGR:", sizeof(buf2));
(void) strncpy(buf3, sp + csi, len);
buf3[len] = '\0';
len += (size_t) csi + 1;
&& (csi = skip_csi(sp)) != 0
&& sp[csi] == 'm') {
len = (size_t) csi + 1;
- (void) strcpy(buf2, "SGR:");
- strcat(buf2, ecma_highlights[0].to);
+ _nc_STRCPY(buf2, "SGR:", sizeof(buf2));
+ _nc_STRCAT(buf2, ecma_highlights[0].to, sizeof(buf2));
expansion = buf2;
}
expansion = "RSR";
len = 1;
} else {
- (void) sprintf(buf2, "1;%dr", tp_lines);
+ _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "1;%dr", tp_lines);
len = strlen(buf2);
if (strncmp(buf2, sp + csi, len) == 0)
expansion = "RSR";
/* now check for home-down */
if (!expansion
&& (csi = skip_csi(sp)) != 0) {
- (void) sprintf(buf2, "%d;1H", tp_lines);
+ _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "%d;1H", tp_lines);
len = strlen(buf2);
if (strncmp(buf2, sp + csi, len) == 0) {
expansion = "LL";
} else {
- (void) sprintf(buf2, "%dH", tp_lines);
+ _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "%dH", tp_lines);
len = strlen(buf2);
if (strncmp(buf2, sp + csi, len) == 0) {
expansion = "LL";
any_initializer(const char *fmt, const char *type)
{
static char *initializer;
+ static size_t need;
char *s;
- if (initializer == 0)
- initializer = (char *) malloc(strlen(entries->tterm.term_names) +
- strlen(type) + strlen(fmt));
+ if (initializer == 0) {
+ need = (strlen(entries->tterm.term_names)
+ + strlen(type)
+ + strlen(fmt));
+ initializer = (char *) malloc(need);
+ }
- (void) strcpy(initializer, entries->tterm.term_names);
+ _nc_STRCPY(initializer, entries->tterm.term_names, need);
for (s = initializer; *s != 0 && *s != '|'; s++) {
if (!isalnum(UChar(*s)))
*s = '_';
}
*s = 0;
- (void) sprintf(s, fmt, type);
+ _nc_SPRINTF(s, _nc_SLIMIT(need) fmt, type);
return initializer;
}
if (VALID_STRING(term->Strings[n])) {
tp = buf;
+#define TP_LIMIT ((MAX_STRING - 5) - (size_t)(tp - buf))
*tp++ = '"';
for (sp = term->Strings[n];
- *sp != 0 && (tp - buf) < MAX_STRING - 6;
+ *sp != 0 && TP_LIMIT > 2;
sp++) {
if (isascii(UChar(*sp))
&& isprint(UChar(*sp))
&& *sp != '"')
*tp++ = *sp;
else {
- (void) sprintf(tp, "\\%03o", UChar(*sp));
+ _nc_SPRINTF(tp, _nc_SLIMIT(TP_LIMIT) "\\%03o", UChar(*sp));
tp += 4;
}
}
str = "CANCELLED_NUMERIC";
break;
default:
- sprintf(buf, "%d", term->Numbers[n]);
+ _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) "%d", term->Numbers[n]);
str = buf;
break;
}
return terminal;
}
+/*
+ * Show the databases that infocmp knows about. The location to which it writes is
+ */
+static void
+show_databases(void)
+{
+ DBDIRS state;
+ int offset;
+ const char *path2;
+
+ _nc_first_db(&state, &offset);
+ while ((path2 = _nc_next_db(&state, &offset)) != 0) {
+ printf("%s\n", path2);
+ }
+ _nc_last_db();
+}
+
/***************************************************************************
*
* Main sequence
while ((c = getopt(argc,
argv,
- "01A:aB:CcdEeFfGgIiKLlnpqR:rs:TtUuVv:w:x")) != -1) {
+ "01A:aB:CcDdEeFfGgIiKLlnpqR:rs:TtUuVv:w:x")) != -1) {
switch (c) {
case '0':
mwidth = 65535;
sortmode = S_TERMCAP;
break;
+ case 'D':
+ show_databases();
+ ExitProgram(EXIT_SUCCESS);
+ break;
+
case 'c':
compare = C_COMMON;
break;
#else
#define LEAF_FMT "%02x"
#endif
- (void) sprintf(tfile[termcount], "%s/" LEAF_FMT "/%s",
- directory,
- UChar(*argv[optind]), argv[optind]);
+ _nc_SPRINTF(tfile[termcount],
+ _nc_SLIMIT(sizeof(path))
+ "%s/" LEAF_FMT "/%s",
+ directory,
+ UChar(*argv[optind]), argv[optind]);
if (itrace)
(void) fprintf(stderr,
"%s: reading entry %s from file %s\n",