X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fwrite_entry.c;h=e0a72670e8c6c225d9bf21afb6e76cefe1c4ae22;hp=b76a109d67a664472dad6845fd5d8084741c5e7c;hb=a20e6eb464be80b9cd8cae7ce925d27fe9c209ed;hpb=e2e9c09c48b19b24979cafb2d4864f538b5ddd1c diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c index b76a109d..e0a72670 100644 --- a/ncurses/tinfo/write_entry.c +++ b/ncurses/tinfo/write_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. * + * Copyright (c) 1998-2015,2017 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 * @@ -47,15 +47,17 @@ #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.95 2016/09/10 20:22:42 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.99 2017/04/09 23:35:01 tom Exp $") static int total_written; +static int total_parts; +static int total_size; static int make_db_root(const char *); #if !USE_HASHED_DB static void -write_file(char *filename, TERMTYPE *tp) +write_file(char *filename, TERMTYPE2 *tp) { char buffer[MAX_ENTRY_SIZE]; unsigned limit = sizeof(buffer); @@ -246,7 +248,7 @@ _nc_set_writedir(const char *dir) */ NCURSES_EXPORT(void) -_nc_write_entry(TERMTYPE *const tp) +_nc_write_entry(TERMTYPE2 *const tp) { #if USE_HASHED_DB @@ -342,6 +344,8 @@ _nc_write_entry(TERMTYPE *const tp) sizeof(buffer) - 1); data.size = name_size + 1; + total_size += data.size; + total_parts++; _nc_db_put(capdb, &key, &data); while (*other_names != '\0') { @@ -356,6 +360,8 @@ _nc_write_entry(TERMTYPE *const tp) key.data = ptr; key.size = strlen(ptr); + total_size += data.size; + total_parts++; _nc_db_put(capdb, &key, &data); } } @@ -443,7 +449,7 @@ _nc_write_entry(TERMTYPE *const tp) _nc_STRNCPY(symlinkname, first_name, MY_SIZE); } else { _nc_STRCPY(symlinkname, "../", sizeof(symlinkname)); - _nc_STRNCPY(symlinkname + 3, first_name, MY_SIZE - 3); + _nc_STRNCPY(symlinkname + 3, filename, MY_SIZE - 3); } symlinkname[MY_SIZE] = '\0'; #endif /* USE_SYMLINKS */ @@ -559,12 +565,34 @@ convert_shorts(unsigned char *buf, short *Numbers, size_t count) } } +#if NCURSES_EXT_NUMBERS +static void +convert_numbers(unsigned char *buf, NCURSES_INT2 *Numbers, size_t count) +{ + size_t i; + for (i = 0; i < count; i++) { + if (Numbers[i] == ABSENT_NUMERIC) { /* HI/LO won't work */ + buf[2 * i] = buf[2 * i + 1] = 0377; + } else if (Numbers[i] == CANCELLED_NUMERIC) { /* HI/LO won't work */ + buf[2 * i] = 0376; + buf[2 * i + 1] = 0377; + } else { + LITTLE_ENDIAN(buf + 2 * i, Numbers[i]); + TRACE_OUT(("put Numbers[%u]=%d", (unsigned) i, Numbers[i])); + } + } +} + +#else +#define convert_numbers(buf,vec,len) convert_shorts(buf,vec,len) +#endif + #define even_boundary(value) \ ((value) % 2 != 0 && Write(&zero, sizeof(char), 1) != 1) #if NCURSES_XNAMES static unsigned -extended_Booleans(TERMTYPE *tp) +extended_Booleans(TERMTYPE2 *tp) { unsigned result = 0; unsigned i; @@ -577,7 +605,7 @@ extended_Booleans(TERMTYPE *tp) } static unsigned -extended_Numbers(TERMTYPE *tp) +extended_Numbers(TERMTYPE2 *tp) { unsigned result = 0; unsigned i; @@ -590,7 +618,7 @@ extended_Numbers(TERMTYPE *tp) } static unsigned -extended_Strings(TERMTYPE *tp) +extended_Strings(TERMTYPE2 *tp) { unsigned short result = 0; unsigned short i; @@ -607,7 +635,7 @@ extended_Strings(TERMTYPE *tp) * clause - discard the unneeded data. */ static bool -extended_object(TERMTYPE *tp) +extended_object(TERMTYPE2 *tp) { bool result = FALSE; @@ -621,7 +649,7 @@ extended_object(TERMTYPE *tp) #endif NCURSES_EXPORT(int) -_nc_write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) +_nc_write_object(TERMTYPE2 *tp, char *buffer, unsigned *offset, unsigned limit) { char *namelist; size_t namelen, boolmax, nummax, strmax; @@ -699,7 +727,7 @@ _nc_write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) TRACE_OUT(("Numerics begin at %04x", *offset)); /* the numerics */ - convert_shorts(buf, tp->Numbers, nummax); + convert_numbers(buf, tp->Numbers, nummax); if (Write(buf, 2, nummax) != nummax) return (ERR); @@ -762,7 +790,7 @@ _nc_write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) TRACE_OUT(("WRITE %d numbers @%d", tp->ext_Numbers, *offset)); if (tp->ext_Numbers) { - convert_shorts(buf, tp->Numbers + NUMCOUNT, (size_t) tp->ext_Numbers); + convert_numbers(buf, tp->Numbers + NUMCOUNT, (size_t) tp->ext_Numbers); if (Write(buf, 2, tp->ext_Numbers) != tp->ext_Numbers) return (ERR); } @@ -802,6 +830,8 @@ _nc_write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) #endif /* NCURSES_XNAMES */ total_written++; + total_parts++; + total_size = total_size + (int) (*offset + 1); return (OK); } @@ -811,5 +841,7 @@ _nc_write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) NCURSES_EXPORT(int) _nc_tic_written(void) { + TR(TRACE_DATABASE, ("_nc_tic_written %d entries, %d parts, %d size", + total_written, total_parts, total_size)); return total_written; }