From 5101937aad7336c927af766909a0c794f198c59d Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 7 Jun 2009 19:32:16 -0400 Subject: snapshot of project "lynx", label v2-8-7pre_5b --- src/LYHistory.c | 70 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 28 deletions(-) (limited to 'src/LYHistory.c') diff --git a/src/LYHistory.c b/src/LYHistory.c index 8c88b753..28494879 100644 --- a/src/LYHistory.c +++ b/src/LYHistory.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYHistory.c,v 1.73 2009/01/01 23:22:12 tom Exp $ + * $LynxId: LYHistory.c,v 1.75 2009/06/07 16:57:43 tom Exp $ */ #include #include @@ -344,7 +344,8 @@ void LYAllocHistory(int entries) int save = size_history; size_history = (entries + 2) * 2; - want = (unsigned) size_history * sizeof(*history); + want = (unsigned) size_history *sizeof(*history); + if (history == 0) { history = (HistInfo *) malloc(want); } else { @@ -955,16 +956,22 @@ int LYShowVisitedLinks(char **newfile) #ifndef STATUSBUFSIZE #define STATUSBUFSIZE 40 #endif -static char *buffstack[STATUSBUFSIZE]; + +int status_buf_size = STATUSBUFSIZE; + +static char **buffstack; static int topOfStack = 0; #ifdef LY_FIND_LEAKS static void free_messages_stack(void) { - topOfStack = STATUSBUFSIZE; + if (buffstack != 0) { + topOfStack = status_buf_size; - while (--topOfStack >= 0) { - FREE(buffstack[topOfStack]); + while (--topOfStack >= 0) { + FREE(buffstack[topOfStack]); + } + FREE(buffstack); } } #endif @@ -974,13 +981,16 @@ static void to_stack(char *str) /* * Cycle buffer: */ - if (topOfStack >= STATUSBUFSIZE) { + if (topOfStack >= status_buf_size) { topOfStack = 0; } /* * Register string. */ + if (buffstack == 0) + buffstack = typecallocn(char *, status_buf_size); + FREE(buffstack[topOfStack]); buffstack[topOfStack] = str; topOfStack++; @@ -990,7 +1000,7 @@ static void to_stack(char *str) atexit(free_messages_stack); } #endif - if (topOfStack >= STATUSBUFSIZE) { + if (topOfStack >= status_buf_size) { topOfStack = 0; } } @@ -1006,22 +1016,24 @@ void LYstatusline_messages_on_exit(char **buf) { int i; - StrAllocCat(*buf, "\n"); - /* print messages in chronological order: - * probably a single message but let's do it. - */ - i = topOfStack - 1; - while (++i < STATUSBUFSIZE) { - if (buffstack[i] != NULL) { - StrAllocCat(*buf, buffstack[i]); - StrAllocCat(*buf, "\n"); + if (buffstack != 0) { + StrAllocCat(*buf, "\n"); + /* print messages in chronological order: + * probably a single message but let's do it. + */ + i = topOfStack - 1; + while (++i < status_buf_size) { + if (buffstack[i] != NULL) { + StrAllocCat(*buf, buffstack[i]); + StrAllocCat(*buf, "\n"); + } } - } - i = -1; - while (++i < topOfStack) { - if (buffstack[i] != NULL) { - StrAllocCat(*buf, buffstack[i]); - StrAllocCat(*buf, "\n"); + i = -1; + while (++i < topOfStack) { + if (buffstack[i] != NULL) { + StrAllocCat(*buf, buffstack[i]); + StrAllocCat(*buf, "\n"); + } } } } @@ -1072,10 +1084,12 @@ static int LYLoadMESSAGES(const char *arg GCC_UNUSED, int i; char *temp = NULL; - i = STATUSBUFSIZE; - while (--i >= 0) { - if (buffstack[i] != NULL) - nummsg++; + if (buffstack != 0) { + i = status_buf_size; + while (--i >= 0) { + if (buffstack[i] != NULL) + nummsg++; + } } /* @@ -1121,7 +1135,7 @@ static int LYLoadMESSAGES(const char *arg GCC_UNUSED, PUTS(buf); } } - i = STATUSBUFSIZE; + i = status_buf_size; while (--i >= topOfStack) { if (buffstack[i] != NULL) { StrAllocCopy(temp, buffstack[i]); -- cgit 1.4.1-2-gfad0