X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftic.c;h=1b0aea85d24818ffe5ddc6238e482e29a7b4e856;hp=8e89095fc67637076289c15ec71b385d1adafd31;hb=cba932f979e14e49b63e06715e80f64d9ffe6e5e;hpb=da5e7c6148aa378da9d8da09be73e0ddd3995c6f diff --git a/progs/tic.c b/progs/tic.c index 8e89095f..1b0aea85 100644 --- a/progs/tic.c +++ b/progs/tic.c @@ -35,6 +35,7 @@ /* * tic.c --- Main program for terminfo compiler * by Eric S. Raymond + * and Thomas E Dickey * */ @@ -44,7 +45,7 @@ #include #include -MODULE_ID("$Id: tic.c,v 1.147 2011/02/12 18:39:08 tom Exp $") +MODULE_ID("$Id: tic.c,v 1.156 2011/11/27 01:32:06 tom Exp $") const char *_nc_progname = "tic"; @@ -69,11 +70,13 @@ static const char usage_string[] = "\ 1\ a\ C\ +D\ c\ f\ G\ g\ I\ +K\ L\ N\ r\ @@ -133,7 +136,9 @@ usage(void) #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 translate/compile only entries named by comma-separated list", " -f format complex strings for readability", @@ -221,7 +226,7 @@ write_it(ENTRY * ep) } _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); } @@ -339,23 +344,23 @@ put_translate(int c) 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 * @@ -471,11 +476,31 @@ open_tempfile(char *name) 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; @@ -486,6 +511,7 @@ main(int argc, char *argv[]) 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}" */ @@ -513,6 +539,7 @@ main(int argc, char *argv[]) #if NCURSES_XNAMES use_extended_names(FALSE); #endif + _nc_strict_bsd = 0; /* * Processing arguments is a little complicated, since someone made a @@ -520,7 +547,7 @@ main(int argc, char *argv[]) * 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': @@ -530,19 +557,39 @@ main(int argc, char *argv[]) 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; @@ -618,7 +665,7 @@ main(int argc, char *argv[]) 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) { @@ -695,11 +742,11 @@ main(int argc, char *argv[]) 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); @@ -750,7 +797,7 @@ main(int argc, char *argv[]) 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 */ @@ -767,7 +814,7 @@ main(int argc, char *argv[]) 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) @@ -915,18 +962,18 @@ keypad_final(const char *string) 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; } @@ -1097,11 +1144,11 @@ check_keypad(TERMTYPE *tp) 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); @@ -1592,7 +1639,7 @@ check_termtype(TERMTYPE *tp, bool literal) 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);