View Single Post
Old 08-15-2005, 06:48 PM  
mr_F
Member
 
Join Date: Jul 2005
Posts: 33
Default

Quote:
Originally Posted by oslike
Hi,
Does any1 of the brilliant scripters here have a suggestion how to read the log file backwards? and stop then when 10 new directories are found?

What tool do TCL scripters in here use for programming TCL ?
When I do it (for all my scripts that need to read this file) I do it like this:
-find out how many lines the users wants (ie: for site showlog 15 (one of my scripts) they want 15 lines)

-allocate an array of pointers that goes from 0 ~ the max # of results you want to output (hardcoded #, i use 1000)

-load each line, and allocate memory for the line to be stored, then when you get to line 16, deallocate line 1... when you load line 17, deallocate line 2. this way you only ever have 15 lines of text in memory. when you have no more lines to read, then you have hit the end, output the results that you have in memory.

-also, if you hit the end of your pointer array (that goes to 1000), just start back at zero, this is called a cyclic queue

some pseudocode/c-code would be

for (i=0; LINE_OF_TEXT_FOUND; i++)
{
if (i > RESULTS)
UNALLOCATE(i - RESULTS);

POINTER_ARRAY[i] = TEXT_LINE_CONTENT;


if (i > MAX_RESULTS)
i=0;
}

something like that. I don't know TCL, but that is the idea, teach yourself

Also, i suggest VIM for editing all code files www.vim.org
mr_F is offline   Reply With Quote