X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftty%2Fhashmap.c;h=9b60df62d5cfbd1941f38c933cd4da544c35e65e;hp=7ff356b645502719e5d75f61ad2d4914a2649a81;hb=6209b84e2f9cc5a53527760499be2cba5fc4e95c;hpb=f70db18a0c3c6a828d8a5999be37239f01c9d98a diff --git a/ncurses/tty/hashmap.c b/ncurses/tty/hashmap.c index 7ff356b6..9b60df62 100644 --- a/ncurses/tty/hashmap.c +++ b/ncurses/tty/hashmap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 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 * @@ -70,7 +70,7 @@ AUTHOR #include #include /* for back_color_erase */ -MODULE_ID("$Id: hashmap.c,v 1.50 2006/12/30 22:19:58 tom Exp $") +MODULE_ID("$Id: hashmap.c,v 1.56 2007/10/13 18:47:25 Miroslav.Lichvar Exp $") #ifdef HASHDEBUG @@ -81,7 +81,8 @@ MODULE_ID("$Id: hashmap.c,v 1.50 2006/12/30 22:19:58 tom Exp $") # define screen_lines MAXLINES # define TEXTWIDTH 1 int oldnums[MAXLINES], reallines[MAXLINES]; -static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; +static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH]; +static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH]; # define OLDNUM(n) oldnums[n] # define OLDTEXT(n) oldtext[n] # define NEWTEXT(m) newtext[m] @@ -130,8 +131,8 @@ update_cost(NCURSES_CH_T * from, NCURSES_CH_T * to) int cost = 0; int i; - for (i = TEXTWIDTH; i > 0; i--) - if (!(CharEq(*from++, *to++))) + for (i = TEXTWIDTH; i > 0; i--, from++, to++) + if (!(CharEq(*from, *to))) cost++; return cost; @@ -147,8 +148,8 @@ update_cost_from_blank(NCURSES_CH_T * to) if (back_color_erase) SetPair(blank, GetPair(stdscr->_nc_bkgd)); - for (i = TEXTWIDTH; i > 0; i--) - if (!(CharEq(blank, *to++))) + for (i = TEXTWIDTH; i > 0; i--, to++) + if (!(CharEq(blank, *to))) cost++; return cost; @@ -446,11 +447,14 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) char line[BUFSIZ], *st; int n; - SP = typeCalloc(SCREEN, 1); + if (setupterm(NULL, fileno(stdout), (int *) 0) == ERR) + return EXIT_FAILURE; + (void) _nc_alloc_screen(); + for (n = 0; n < screen_lines; n++) { reallines[n] = n; oldnums[n] = _NEWINDEX; - oldtext[n][0] = newtext[n][0] = '.'; + CharOf(oldtext[n][0]) = CharOf(newtext[n][0]) = '.'; } if (isatty(fileno(stdin))) @@ -462,7 +466,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) for (;;) { /* grab a test command */ if (fgets(line, sizeof(line), stdin) == (char *) NULL) - exit(EXIT_SUCCESS); + break; switch (line[0]) { case '#': /* comment */ @@ -484,22 +488,22 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) case 'n': /* use following letters as text of new lines */ for (n = 0; n < screen_lines; n++) - newtext[n][0] = '.'; + CharOf(newtext[n][0]) = '.'; for (n = 0; n < screen_lines; n++) if (line[n + 1] == '\n') break; else - newtext[n][0] = line[n + 1]; + CharOf(newtext[n][0]) = line[n + 1]; break; case 'o': /* use following letters as text of old lines */ for (n = 0; n < screen_lines; n++) - oldtext[n][0] = '.'; + CharOf(oldtext[n][0]) = '.'; for (n = 0; n < screen_lines; n++) if (line[n + 1] == '\n') break; else - oldtext[n][0] = line[n + 1]; + CharOf(oldtext[n][0]) = line[n + 1]; break; case 'd': /* dump state of test arrays */ @@ -508,12 +512,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) #endif (void) fputs("Old lines: [", stdout); for (n = 0; n < screen_lines; n++) - putchar(oldtext[n][0]); + putchar(CharOf(oldtext[n][0])); putchar(']'); putchar('\n'); (void) fputs("New lines: [", stdout); for (n = 0; n < screen_lines; n++) - putchar(newtext[n][0]); + putchar(CharOf(newtext[n][0])); putchar(']'); putchar('\n'); break; @@ -527,12 +531,17 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) _nc_scroll_optimize(); (void) fputs("Done.\n", stderr); break; + default: case '?': usage(); break; } } +#if NO_LEAKS + _nc_free_and_exit(EXIT_SUCCESS); +#else return EXIT_SUCCESS; +#endif } #endif /* HASHDEBUG */