Go Back   FlashFXP Forums > > > >

! Other Scripts Support Support for all other scripts...

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-13-2005, 11:04 AM   #1
oslike
Member
 
Join Date: Dec 2003
Posts: 90
Default how to read a file backwards?

Hi,

i am trying to write my own TCL "site new" script. I am reading the ioftpd.log which takes quite a long time.

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 ? I am using Notepad atm

Chears

os-like
oslike is offline   Reply With Quote
Old 08-15-2005, 06:48 PM   #2
mr_F
Member
FlashFXP Beta Tester
ioFTPD Foundation User
 
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
Reply

Tags
backwards, file, read, scripters, tcl

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:25 AM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)