diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-11-03 21:59:54 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-11-03 21:59:54 +0000 |
commit | 3d1926495798ef8bc2629d53a1c081dc320225a7 (patch) | |
tree | 686411f909e534ce7211edbd457fb551d5630bc6 /usr.bin/tic | |
parent | 6b34e0bdfb3771372d8b5bf3dd6b5bb423e17923 (diff) |
updated from ncurses-4.2-981017
Diffstat (limited to 'usr.bin/tic')
-rw-r--r-- | usr.bin/tic/captoinfo.1tbl | 6 | ||||
-rw-r--r-- | usr.bin/tic/dump_entry.c | 37 | ||||
-rw-r--r-- | usr.bin/tic/dump_entry.h | 6 | ||||
-rw-r--r-- | usr.bin/tic/progs.priv.h | 2 | ||||
-rw-r--r-- | usr.bin/tic/tic.c | 149 |
5 files changed, 153 insertions, 47 deletions
diff --git a/usr.bin/tic/captoinfo.1tbl b/usr.bin/tic/captoinfo.1tbl index f43a5f01297..ba050b28c09 100644 --- a/usr.bin/tic/captoinfo.1tbl +++ b/usr.bin/tic/captoinfo.1tbl @@ -1,4 +1,5 @@ -.\" $OpenBSD: captoinfo.1tbl,v 1.2 1998/07/24 19:52:55 millert Exp $ +'\" t +.\" $OpenBSD: captoinfo.1tbl,v 1.3 1998/11/03 21:59:53 millert Exp $ .\" .\"*************************************************************************** .\" Copyright (c) 1998 Free Software Foundation, Inc. * @@ -28,8 +29,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: captoinfo.1m,v 1.10 1998/03/11 21:12:53 juergen Exp $ -'\" t +.\" $From: captoinfo.1m,v 1.11 1998/08/27 21:21:04 Rick.Ohnemus Exp $ .TH captoinfo 1 "" .ds n 5 .ds d /usr/share/terminfo diff --git a/usr.bin/tic/dump_entry.c b/usr.bin/tic/dump_entry.c index 87cc5c87706..7b547fd40a5 100644 --- a/usr.bin/tic/dump_entry.c +++ b/usr.bin/tic/dump_entry.c @@ -1,3 +1,5 @@ +/* $OpenBSD: dump_entry.c,v 1.2 1998/11/03 21:59:53 millert Exp $ */ + /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * * * @@ -38,10 +40,12 @@ #include <termsort.c> /* this C file is generated */ #include <parametrized.h> /* so is this */ -MODULE_ID("$Id: dump_entry.c,v 1.1 1998/07/27 03:26:10 millert Exp $") +MODULE_ID("$From: dump_entry.c,v 1.29 1998/09/26 13:15:00 tom Exp $") #define INDENT 8 +#define DISCARD(string) string = ABSENT_STRING + static int tversion; /* terminfo version */ static int outform; /* output format to use */ static int sortmode; /* sort mode to use */ @@ -451,7 +455,8 @@ static char * fmt_complex(char *dst, char *src, int level) int fmt_entry(TERMTYPE *tterm, int (*pred)(int type, int idx), bool suppress_untranslatable, - bool infodump) + bool infodump, + bool numbers) { int i, j; char buffer[MAX_TERMINFO_LENGTH]; @@ -557,6 +562,7 @@ bool outcount = 0; * them to be output as defined and empty. */ if (outform==F_TERMCAP) + { #undef CUR #define CUR tterm-> if (insert_character || parm_ich) @@ -576,6 +582,17 @@ bool outcount = 0; } } + if (init_3string != 0 + && termcap_reset != 0 + && !strcmp(init_3string, termcap_reset)) + DISCARD(init_3string); + + if (reset_2string != 0 + && termcap_reset != 0 + && !strcmp(reset_2string, termcap_reset)) + DISCARD(reset_2string); + } + predval = pred(STRING, i); buffer[0] = '\0'; if (predval != FAIL) { @@ -586,7 +603,7 @@ bool outcount = 0; sprintf(buffer, "%s@", str_names[i]); else if (outform == F_TERMCAP || outform == F_TCONVERR) { - char *srccap = _nc_tic_expand(tterm->Strings[i], FALSE); + char *srccap = _nc_tic_expand(tterm->Strings[i], FALSE, numbers); char *cv = _nc_infotocap(str_names[i], srccap, parametrized[i]); if (cv == 0) @@ -604,7 +621,7 @@ bool outcount = 0; } else { - char *src = _nc_tic_expand(tterm->Strings[i], outform==F_TERMINFO); + char *src = _nc_tic_expand(tterm->Strings[i], outform==F_TERMINFO, numbers); sprintf(buffer, "%s=", str_names[i]); if (pretty && outform==F_TERMINFO) fmt_complex(buffer + strlen(buffer), src, 1); @@ -663,7 +680,7 @@ bool outcount = 0; if (box_ok) { (void) strcpy(buffer, "box1="); - (void) strcat(buffer, _nc_tic_expand(boxchars, outform==F_TERMINFO)); + (void) strcat(buffer, _nc_tic_expand(boxchars, outform==F_TERMINFO, numbers)); WRAP_CONCAT; } } @@ -708,7 +725,7 @@ bool outcount = 0; return(infodump ? len : termcap_length(outbuf)); } -int dump_entry(TERMTYPE *tterm, bool limited, int (*pred)(int type, int idx)) +int dump_entry(TERMTYPE *tterm, bool limited, bool numbers, int (*pred)(int type, int idx)) /* dump a single entry */ { int len, critlen; @@ -729,11 +746,11 @@ int dump_entry(TERMTYPE *tterm, bool limited, int (*pred)(int type, int idx)) infodump = TRUE; } - if (((len = fmt_entry(tterm, pred, FALSE, infodump)) > critlen) && limited) + if (((len = fmt_entry(tterm, pred, FALSE, infodump, numbers)) > critlen) && limited) { (void) printf("# (untranslatable capabilities removed to fit entry within %d bytes)\n", critlen); - if ((len = fmt_entry(tterm, pred, TRUE, infodump)) > critlen) + if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { /* * We pick on sgr because it's a nice long string capability that @@ -743,7 +760,7 @@ int dump_entry(TERMTYPE *tterm, bool limited, int (*pred)(int type, int idx)) set_attributes = ABSENT_STRING; (void) printf("# (sgr removed to fit entry within %d bytes)\n", critlen); - if ((len = fmt_entry(tterm, pred, TRUE, infodump)) > critlen) + if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { int oldversion = tversion; @@ -751,7 +768,7 @@ int dump_entry(TERMTYPE *tterm, bool limited, int (*pred)(int type, int idx)) (void) printf("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n", critlen); - if ((len = fmt_entry(tterm, pred, TRUE, infodump)) > critlen) + if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { (void) fprintf(stderr, "warning: %s entry is %d bytes long\n", diff --git a/usr.bin/tic/dump_entry.h b/usr.bin/tic/dump_entry.h index 105ef5af537..5a15274a1a7 100644 --- a/usr.bin/tic/dump_entry.h +++ b/usr.bin/tic/dump_entry.h @@ -1,4 +1,4 @@ -/* $OpenBSD: */ +/* $OpenBSD: dump_entry.h,v 1.2 1998/11/03 21:59:53 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -54,8 +54,8 @@ extern NCURSES_CONST char *nametrans(const char *); extern void dump_init(const char *, int, int, int, int, bool); -extern int fmt_entry(TERMTYPE *, int (*)(int, int), bool, bool); -extern int dump_entry(TERMTYPE *, bool, int (*)(int, int)); +extern int fmt_entry(TERMTYPE *, int (*)(int, int), bool, bool, bool); +extern int dump_entry(TERMTYPE *, bool, bool, int (*)(int, int)); extern int dump_uses(const char *, bool); extern void compare_entry(void (*)(int, int, const char *)); diff --git a/usr.bin/tic/progs.priv.h b/usr.bin/tic/progs.priv.h index b53fcf32190..b2b059d0f7c 100644 --- a/usr.bin/tic/progs.priv.h +++ b/usr.bin/tic/progs.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: progs.priv.h,v 1.1 1998/07/27 03:26:11 millert Exp $ */ +/* $OpenBSD: progs.priv.h,v 1.2 1998/11/03 21:59:53 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * diff --git a/usr.bin/tic/tic.c b/usr.bin/tic/tic.c index a2861ba712e..206fc9497df 100644 --- a/usr.bin/tic/tic.c +++ b/usr.bin/tic/tic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tic.c,v 1.1 1998/07/24 19:37:35 millert Exp $ */ +/* $OpenBSD: tic.c,v 1.2 1998/11/03 21:59:53 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -44,15 +44,31 @@ #include <dump_entry.h> #include <term_entry.h> -MODULE_ID("$From: tic.c,v 1.30 1998/03/28 20:04:11 tom Exp $") +MODULE_ID("$From: tic.c,v 1.38 1998/10/18 00:27:14 tom Exp $") const char *_nc_progname = "tic"; static FILE *log_fp; +static FILE *tmp_fp; static bool showsummary = FALSE; +static const char *to_remove; static const char usage_string[] = "[-h] [-v[n]] [-e names] [-CILNRTcfrsw1] source-file\n"; +static void cleanup(void) +{ + fclose(tmp_fp); + if (to_remove != 0) + remove(to_remove); +} + +static void failed(const char *msg) +{ + perror(msg); + cleanup(); + exit(EXIT_FAILURE); +} + static void usage(void) { static const char *const tbl[] = { @@ -66,6 +82,7 @@ static void usage(void) " -T remove size-restrictions on compiled description", " -c check only, validate input without compiling or translating", " -f format complex strings for readability", + " -g format %'char' to %{number}", " -e<names> translate/compile only entries named by comma-separated list", " -o<dir> set output directory for compiled entry writes", " -r force resolution of all use entries in source translation", @@ -84,6 +101,59 @@ static void usage(void) exit(EXIT_FAILURE); } +#define L_BRACE '{' +#define R_BRACE '}' +#define S_QUOTE '\''; + +static void write_it(ENTRY *ep) +{ + unsigned n; + int ch; + char *s, *d, *t; + char result[MAX_ENTRY_SIZE]; + + /* + * Look for strings that contain %{number}, convert them to %'char', + * which is shorter and runs a little faster. + */ + for (n = 0; n < STRCOUNT; n++) { + s = ep->tterm.Strings[n]; + if (VALID_STRING(s) + && strchr(s, L_BRACE) != 0) { + d = result; + t = s; + while ((ch = *t++) != 0) { + *d++ = ch; + if (ch == '\\') { + *d++ = *t++; + } else if ((ch == '%') + && (*t == L_BRACE)) { + char *v = 0; + long value = strtol(t+1, &v, 0); + if (v != 0 + && *v == R_BRACE + && value > 0 + && value != '\\' /* FIXME */ + && value < 127 + && isprint((int)value)) { + *d++ = S_QUOTE; + *d++ = (int)value; + *d++ = S_QUOTE; + t = (v + 1); + } + } + } + *d = 0; + if (strlen(result) < strlen(s)) + strcpy(s, result); + } + } + + _nc_set_type(_nc_first_name(ep->tterm.term_names)); + _nc_curr_line = ep->startline; + _nc_write_entry(&ep->tterm); +} + static bool immedhook(ENTRY *ep) /* write out entries with no use capabilities immediately to save storage */ { @@ -125,9 +195,7 @@ static bool immedhook(ENTRY *ep) { int oldline = _nc_curr_line; - _nc_set_type(_nc_first_name(ep->tterm.term_names)); - _nc_curr_line = ep->startline; - _nc_write_entry(&ep->tterm); + write_it(ep); _nc_curr_line = oldline; free(ep->tterm.str_table); return(TRUE); @@ -220,15 +288,16 @@ static const char **make_namelist(char *src) const char **dst = 0; char *s, *base; - size_t pass, n, nn; + unsigned pass, n, nn; char buffer[BUFSIZ]; - if (strchr(src, '/') != 0) { /* a filename */ + if (src == 0) { + /* EMPTY */; + } else if (strchr(src, '/') != 0) { /* a filename */ FILE *fp = fopen(src, "r"); - if (fp == 0) { - perror(src); - exit(EXIT_FAILURE); - } + if (fp == 0) + failed(src); + for (pass = 1; pass <= 2; pass++) { nn = 0; while (fgets(buffer, sizeof(buffer), fp) != 0) { @@ -297,6 +366,7 @@ static bool matches(const char **needle, const char *haystack) int main (int argc, char *argv[]) { +char my_tmpname[PATH_MAX]; int v_opt = -1, debug_level; int smart_defaults = TRUE; char *termcap; @@ -307,8 +377,10 @@ int this_opt, last_opt = '?'; int outform = F_TERMINFO; /* output format */ int sortmode = S_TERMINFO; /* sort_mode */ +int fd; int width = 60; bool formatted = FALSE; /* reformat complex strings? */ +bool numbers = TRUE; /* format "%'char'" to "%{number}" */ bool infodump = FALSE; /* running as captoinfo? */ bool capdump = FALSE; /* running as infotocap? */ bool forceresolve = FALSE; /* force resolution */ @@ -334,7 +406,7 @@ bool check_only = FALSE; * design decision to allow the numeric values for -w, -v options to * be optional. */ - while ((this_opt = getopt(argc, argv, "0123456789CILNR:TVce:fo:rsvw")) != EOF) { + while ((this_opt = getopt(argc, argv, "0123456789CILNR:TVce:fgo:rsvw")) != EOF) { if (isdigit(this_opt)) { switch (last_opt) { case 'v': @@ -388,6 +460,9 @@ bool check_only = FALSE; case 'f': formatted = TRUE; break; + case 'g': + numbers = FALSE; + break; case 'o': outdir = optarg; break; @@ -425,11 +500,22 @@ bool check_only = FALSE; } else { if (infodump == TRUE) { /* captoinfo's no-argument case */ - source_file = "/etc/termcap"; - if ((termcap = getenv("TERMCAP")) != NULL) { + source_file = "/usr/share/misc/termcap"; + if ((termcap = getenv("TERMCAP")) != 0 + && (namelst = make_namelist(getenv("TERM"))) != 0) { if (access(termcap, F_OK) == 0) { /* file exists */ source_file = termcap; + } else + if (strcpy(my_tmpname, "/tmp/tic.XXXXXXXX") + && (fd = mkstemp(my_tmpname)) != -1 + && (tmp_fp = fdopen(fd, "w")) != 0) { + fprintf(tmp_fp, "%s\n", termcap); + fclose(tmp_fp); + tmp_fp = fopen(source_file, "r"); + to_remove = source_file; + } else { + failed("mkstemp"); } } } else { @@ -439,11 +525,13 @@ bool check_only = FALSE; _nc_progname, _nc_progname, usage_string); + cleanup(); return EXIT_FAILURE; } } - if (freopen(source_file, "r", stdin) == NULL) { + if (tmp_fp == 0 + && (tmp_fp = fopen(source_file, "r")) == 0) { fprintf (stderr, "%s: Can't open %s\n", _nc_progname, source_file); return EXIT_FAILURE; } @@ -465,14 +553,17 @@ bool check_only = FALSE; if (!(check_only || infodump || capdump)) _nc_set_writedir(outdir); #endif /* HAVE_BIG_CORE */ - _nc_read_entry_source(stdin, (char *)NULL, + _nc_read_entry_source(tmp_fp, (char *)NULL, !smart_defaults, FALSE, (check_only || infodump || capdump) ? NULLHOOK : immedhook); /* do use resolution */ - if (check_only || (!infodump && !capdump) || forceresolve) - if (!_nc_resolve_uses() && !check_only) + if (check_only || (!infodump && !capdump) || forceresolve) { + if (!_nc_resolve_uses() && !check_only) { + cleanup(); return EXIT_FAILURE; + } + } #ifndef HAVE_BIG_CORE /* @@ -489,6 +580,7 @@ bool check_only = FALSE; { (void) fprintf(stderr, "Sorry, -e can't be used without -I or -C\n"); + cleanup(); return EXIT_FAILURE; } #endif /* HAVE_BIG_CORE */ @@ -500,7 +592,7 @@ bool check_only = FALSE; { if (matches(namelst, qp->tterm.term_names)) { - int len = fmt_entry(&qp->tterm, NULL, TRUE, infodump); + int len = fmt_entry(&qp->tterm, NULL, TRUE, infodump, numbers); if (len>(infodump?MAX_TERMINFO_LENGTH:MAX_TERMCAP_LENGTH)) (void) fprintf(stderr, @@ -519,11 +611,7 @@ bool check_only = FALSE; _nc_set_writedir(outdir); for_entry_list(qp) if (matches(namelst, qp->tterm.term_names)) - { - _nc_set_type(_nc_first_name(qp->tterm.term_names)); - _nc_curr_line = qp->startline; - _nc_write_entry(&qp->tterm); - } + write_it(qp); } else { @@ -539,14 +627,14 @@ bool check_only = FALSE; /* this is in case infotocap() generates warnings */ _nc_set_type(_nc_first_name(qp->tterm.term_names)); - (void) fseek(stdin, qp->cstart, SEEK_SET); + (void) fseek(tmp_fp, qp->cstart, SEEK_SET); while (j-- ) if (infodump) - (void) putchar(getchar()); + (void) putchar(fgetc(tmp_fp)); else - put_translate(getchar()); + put_translate(fgetc(tmp_fp)); - len = dump_entry(&qp->tterm, limited, NULL); + len = dump_entry(&qp->tterm, limited, numbers, NULL); for (j = 0; j < qp->nuses; j++) len += dump_uses((char *)(qp->uses[j].parent), infodump); (void) putchar('\n'); @@ -559,8 +647,8 @@ bool check_only = FALSE; bool in_comment = FALSE; bool trailing_comment = FALSE; - (void) fseek(stdin, _nc_tail->cend, SEEK_SET); - while ((c = getchar()) != EOF) + (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET); + while ((c = fgetc(tmp_fp)) != EOF) { if (oldc == '\n') { if (c == '#') { @@ -592,5 +680,6 @@ bool check_only = FALSE; else fprintf(log_fp, "No entries written\n"); } + cleanup(); return(EXIT_SUCCESS); } |