/****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2010,2011 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 *
/*
* tic.c --- Main program for terminfo compiler
* by Eric S. Raymond
+ * and Thomas E Dickey
*
*/
#include <dump_entry.h>
#include <transform.h>
-MODULE_ID("$Id: tic.c,v 1.146 2010/10/02 22:45:40 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.156 2011/11/27 01:32:06 tom Exp $")
const char *_nc_progname = "tic";
1\
a\
C\
+D\
c\
f\
G\
g\
I\
+K\
L\
N\
r\
#if NCURSES_XNAMES
" -a retain commented-out capabilities (sets -x also)",
#endif
+ " -K translate entries to termcap source form with BSD syntax",
" -C translate entries to termcap source form",
+ " -D print list of tic's database locations (first must be writable)",
" -c check only, validate input without compiling or translating",
" -e<names> translate/compile only entries named by comma-separated list",
" -f format complex strings for readability",
}
_nc_set_type(_nc_first_name(ep->tterm.term_names));
- _nc_curr_line = ep->startline;
+ _nc_curr_line = (int) ep->startline;
_nc_write_entry(&ep->tterm);
}
static char *
stripped(char *src)
{
+ char *dst = 0;
+
while (isspace(UChar(*src)))
src++;
+
if (*src != '\0') {
- char *dst;
size_t len;
- if ((dst = strdup(src)) == NULL)
+ if ((dst = strdup(src)) == NULL) {
failed("strdup");
-
- assert(dst != 0);
-
- len = strlen(dst);
- while (--len != 0 && isspace(UChar(dst[len])))
- dst[len] = '\0';
- return dst;
+ } else {
+ len = strlen(dst);
+ while (--len != 0 && isspace(UChar(dst[len])))
+ dst[len] = '\0';
+ }
}
- return 0;
+ return dst;
}
static FILE *
return result;
}
+/*
+ * Show the databases that tic knows about. The location to which it writes is
+ * always the first one. If that is not writable, then tic errors out before
+ * reaching this function.
+ */
+static void
+show_databases(void)
+{
+ DBDIRS state;
+ int offset;
+ const char *path;
+
+ _nc_first_db(&state, &offset);
+ while ((path = _nc_next_db(&state, &offset)) != 0) {
+ printf("%s\n", path);
+ }
+ _nc_last_db();
+}
+
int
main(int argc, char *argv[])
{
char my_tmpname[PATH_MAX];
- int v_opt = -1, debug_level;
+ int v_opt = -1;
+ unsigned debug_level;
int smart_defaults = TRUE;
char *termcap;
ENTRY *qp;
int sortmode = S_TERMINFO; /* sort_mode */
int width = 60;
+ int height = 65535;
bool formatted = FALSE; /* reformat complex strings? */
bool literal = FALSE; /* suppress post-processing? */
int numbers = 0; /* format "%'char'" to/from "%{number}" */
#if NCURSES_XNAMES
use_extended_names(FALSE);
#endif
+ _nc_strict_bsd = 0;
/*
* Processing arguments is a little complicated, since someone made a
* be optional.
*/
while ((this_opt = getopt(argc, argv,
- "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) {
+ "0123456789CDIKLNR:TUVace:fGgo:rstvwx")) != -1) {
if (isdigit(this_opt)) {
switch (last_opt) {
case 'v':
width = (width * 10) + (this_opt - '0');
break;
default:
- if (this_opt != '1')
+ switch (this_opt) {
+ case '0':
+ last_opt = this_opt;
+ width = 65535;
+ height = 1;
+ break;
+ case '1':
+ last_opt = this_opt;
+ width = 0;
+ break;
+ default:
usage();
- last_opt = this_opt;
- width = 0;
+ }
}
continue;
}
switch (this_opt) {
+ case 'K':
+ _nc_strict_bsd = 1;
+ /* the initial version of -K in 20110730 fell-thru here, but the
+ * same flag is useful when reading sources -TD
+ */
+ break;
case 'C':
capdump = TRUE;
outform = F_TERMCAP;
sortmode = S_TERMCAP;
break;
+ case 'D':
+ _nc_set_writedir(outdir);
+ show_databases();
+ ExitProgram(EXIT_SUCCESS);
+ break;
case 'I':
infodump = TRUE;
outform = F_TERMINFO;
last_opt = this_opt;
}
- debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
+ debug_level = (unsigned) ((v_opt > 0) ? v_opt : (v_opt == 0));
set_trace_level(debug_level);
if (_nc_tracing) {
smart_defaults
? outform
: F_LITERAL,
- sortmode, width, debug_level, formatted);
+ sortmode, width, height, debug_level, formatted);
else if (capdump)
dump_init(tversion,
outform,
- sortmode, width, debug_level, FALSE);
+ sortmode, width, height, debug_level, FALSE);
/* parse entries out of the source file */
_nc_set_source(source_file);
for_entry_list(qp) {
if (matches(namelst, qp->tterm.term_names)) {
- int j = qp->cend - qp->cstart;
+ long j = qp->cend - qp->cstart;
int len = 0;
/* this is in case infotocap() generates warnings */
repair_acsc(&qp->tterm);
dump_entry(&qp->tterm, suppress_untranslatable,
limited, numbers, NULL);
- for (j = 0; j < (int) qp->nuses; j++)
+ for (j = 0; j < (long) qp->nuses; j++)
dump_uses(qp->uses[j].name, !capdump);
len = show_entry();
if (debug_level != 0 && !limited)
return result;
}
-static int
+static long
keypad_index(const char *string)
{
char *test;
const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
int ch;
- int result = -1;
+ long result = -1;
if ((ch = keypad_final(string)) != '\0') {
test = strchr(list, ch);
if (test != 0)
- result = (test - list);
+ result = (long) (test - list);
}
return result;
}
VALID_STRING(key_c1) &&
VALID_STRING(key_c3)) {
char final[MAX_KP + 1];
- int list[MAX_KP];
+ long list[MAX_KP];
int increase = 0;
int j, k, kk;
- int last;
- int test;
+ long last;
+ long test;
final[0] = keypad_final(key_a1);
final[1] = keypad_final(key_a3);
if (_nc_tracing >= DEBUG_LEVEL(level)) {
char my_name[256];
_nc_get_type(my_name);
- fprintf(stderr, "\"%s\", line %d, '%s' ",
+ _tracef("\"%s\", line %d, '%s'",
_nc_get_source(),
_nc_curr_line, my_name);
}
for (j = 0; j < NUM_STRINGS(tp); j++) {
char *a = tp->Strings[j];
if (VALID_STRING(a))
- check_params(tp, ExtStrname(tp, j, strnames), a);
+ check_params(tp, ExtStrname(tp, (int) j, strnames), a);
}
check_acs(tp);